Merge origin/master into turtle/fork-name-suffix-5f3435925211

Co-authored-by: imccyu <[email protected]>
This commit is contained in:
Turtleandimccyu committed 2026-11-04 14:16:25 +08:00
commit 4731be7515
3956 files changed
+149568 -54303

No files matched your search

@@ -73,8 +73,6 @@ export interface SessionSnapshot {
readonly running: boolean
readonly subagent: {
readonly address: SubagentAddress
/** Absent until the direct-parent catalog resolves. */
readonly parentAvailable?: boolean
} | null
readonly removed: boolean
readonly openState: OpenState
@@ -147,12 +147,7 @@ export class SessionManager {
throw new Error(`sessions.retain: unknown session ${id}`)
}
if (address !== undefined) this.addresses.set(id, address)
this.sessions.get(id)?.configureSubagent(
address,
address === undefined
? undefined
: this.agentAvailable(address.parentSessionId),
)
this.sessions.get(id)?.configureSubagent(address)
return id
}
@@ -276,14 +271,8 @@ export class SessionManager {
private createSession(sessionId: SessionId): Session {
const address = this.addresses.get(sessionId)
const parentAvailable = address === undefined
? undefined
: this.agentAvailable(address.parentSessionId)
return new Session(sessionId, this.remote, {
...(address === undefined ? {} : {
address,
...parentAvailable === undefined ? {} : { parentAvailable },
}),
...(address === undefined ? {} : { address }),
// The sender's local first-send flip mirrors into the list row so the
// session surfaces (lists filter on blank) before any host frame lands.
onEngaged: (engaged) => {
@@ -400,18 +389,6 @@ export class SessionManager {
return operation
}
private agentAvailable(sessionId: SessionId): boolean | undefined {
return this.summaries.find(summary => summary.sessionId === sessionId)?.agentAvailable
?? (this.listPhase === 'ready' ? false : undefined)
}
private updateParentAvailability(): void {
for (const [childId, address] of this.addresses) {
const available = this.agentAvailable(address.parentSessionId)
if (available !== undefined) this.sessions.get(childId)?.handleSubagentParentAvailable(available)
}
}
// ---- List API ----
/** Full refresh via session.list (single-flight within one Host generation). */
@@ -446,7 +423,7 @@ export class SessionManager {
for (const sessionId of this.engagedSessions) this.pruneEngagement(sessionId, retained)
this.listState = 'idle'
this.listPhase = 'ready'
this.updateParentAvailability()
// Resident Sessions and list rows share one display blank, reconciled with the metadata projection.
for (const s of this.summaries) {
const session = this.sessions.get(s.sessionId)
@@ -599,7 +576,6 @@ export class SessionManager {
*/
private mergeSummary(summary: SessionSummary): void {
this.recordMutation({ kind: 'upsert', summary })
this.updateParentAvailability()
}
/** Apply immediately and retain for replay when a list response is in flight. */
@@ -642,15 +618,17 @@ export class SessionManager {
// ---- Live control and Host-event sinks ----
/**
* Apply a complete control baseline or one later replacement frame.
* @param frame - baseline or live control replacement from Session Controller.
* Apply a complete control baseline or one later per-event projection frame.
* @param frame - baseline or live per-event projection change from Session Controller.
*/
handleControlFrame(frame: SessionControlFrame): void {
if (frame.type === 'baseline') {
this.replaceControlBaseline(frame.value)
return
}
this.projectionStore(frame.sessionId).apply(frame.key, frame.value, SessionSeq(frame.seq))
const store = this.projectionStore(frame.sessionId)
const seq = SessionSeq(frame.seq)
for (const change of frame.changes) store.apply(change.key, change.val, seq)
this.notifier.markDirty()
}
@@ -719,11 +697,6 @@ export class SessionManager {
this.projectionInflight.get(sessionId)?.controller.abort()
this.projectionInflight.delete(sessionId)
this.projectionLoads.delete(sessionId)
for (const [childId, address] of this.addresses) {
if (address.parentSessionId === sessionId) {
this.sessions.get(childId)?.handleSubagentParentAvailable(false)
}
}
}
/**
@@ -734,7 +707,6 @@ export class SessionManager {
handleSessionStatus(sessionId: SessionId, running: boolean): void {
if (!this.disposed && running) this.engagedSessions.add(sessionId)
this.recordMutation({ kind: 'status', sessionId, running, agentAvailable: true })
this.updateParentAvailability()
this.sessions.get(sessionId)?.handleRunning(running)
}
@@ -30,10 +30,8 @@ export interface SessionSubagentsRemote {
request: SubagentPromptRequest,
signal?: AbortSignal,
): Promise<RemoteResult<SubagentPromptReceipt>>
interruptByParent(
interruptByUser(
childSessionId: SessionId,
parentSessionId: SessionId,
mode: 'continuable',
): Promise<RemoteResult<SubagentInterruptReceipt>>
}
@@ -71,8 +71,6 @@ interface PendingHistory {
export interface SessionOptions {
/** Catalog-discovered address selecting non-activating subagent transport. */
address?: SubagentAddress
/** Whether the exact direct parent Agent is available in Host summaries; absent until known. */
parentAvailable?: boolean
/**
* Publish each accepted prompt to the Manager, including after this Session
* object is replaced. Acceptance converts display state, but does not
@@ -113,7 +111,6 @@ export class Session implements SessionFace {
private readonly assistantStream = new ClientAssistantStream()
private running = false
private address: SubagentAddress | undefined
private parentAvailable: boolean | undefined
/**
* Sticky send marker, private input of the composerPhase derivation: set
* when the Host accepts a prompt, never reset — the blank → engaging edge of
@@ -193,7 +190,6 @@ export class Session implements SessionFace {
) {
this.projections = options.projections ?? new ProjectionValueStore()
this.address = options.address
this.parentAvailable = options.parentAvailable
this.notifier = new Notifier(() => {
this.snapshotCache = this.buildSnapshot()
})
@@ -294,9 +290,7 @@ export class Session implements SessionFace {
const routedContent = content as Exclude<PromptContentPart, { readonly type: 'file' }>[]
const routed = await this.remote.subagents.prompt({
requestId: requestId ?? randomUUID() as SessionRequestId,
parentSessionId: this.address.parentSessionId,
childSessionId: this.address.childSessionId,
mode: 'continuable',
delivery: mode,
content: routedContent,
clientTimeZone: resolvedClientTimeZone(),
@@ -363,18 +357,14 @@ export class Session implements SessionFace {
/**
* Stop the active turn while the Host preserves pending inbox work; failures
* land in promptError (same error-strip display slot). A subagent address
* routes through `subagents.interruptByParent`, whose durable parent-address
* authority works without a live parent Agent.
* routes through `subagents.interruptByUser`, authorized on the target Session
* without requiring a live parent Agent.
* @returns the cancel result.
*/
async cancel(): Promise<RemoteResult<{ accepted: true }>> {
const address = this.address
const result = address !== undefined
? await this.remote.subagents.interruptByParent(
address.childSessionId,
address.parentSessionId,
'continuable',
)
? await this.remote.subagents.interruptByUser(address.childSessionId)
: await this.remote.session.cancel({ sessionId: this.sessionId })
if (!result.ok) {
this.promptError = { op: 'stop', error: result.error }
@@ -562,28 +552,16 @@ export class Session implements SessionFace {
* Install or clear the catalog-discovered transport address. A changed
* address rebuilds an already-open window through its new history route.
* @param address - direct parent/child address, or undefined for ordinary transport.
* @param parentAvailable - latest exact-parent availability hint, or undefined before a catalog read.
*/
configureSubagent(address: SubagentAddress | undefined, parentAvailable?: boolean): void {
configureSubagent(address: SubagentAddress | undefined): void {
const same = this.address?.parentSessionId === address?.parentSessionId
&& this.address?.childSessionId === address?.childSessionId
&& this.address?.mode === address?.mode
this.address = address
this.parentAvailable = parentAvailable
if (!same && this.openState !== 'cold') void this.resync()
else this.notifier.markDirty()
}
/**
* Update only the parent availability hint from a catalog refresh.
* @param available - whether the exact direct parent is live.
*/
handleSubagentParentAvailable(available: boolean): void {
if (this.parentAvailable === available) return
this.parentAvailable = available
this.notifier.markDirty()
}
/**
* Apply the Manager's effective display blank, further reconciled with the
* current `sessionListMetadata` projection. Local send attempts and current
@@ -934,7 +912,6 @@ export class Session implements SessionFace {
address: this.address.mode === 'unknown' && identity != null
? { ...this.address, mode: identity.mode }
: this.address,
...(this.parentAvailable === undefined ? {} : { parentAvailable: this.parentAvailable }),
},
removed: this.removed,
openState: this.openState,