@dsh-cc/acp 0.9.3-rc.4 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,34 @@
1
1
  // Vendored from @deepseek-ai/dsh-acp (packages/acp/acp/src/model-control.ts)
2
- // Source ref: c1b47e41fcd54d20a0f061df28683bfc29ee24e5 (deepseek-harness, MIT — see LICENSE-harness)
2
+ // Source ref: 2f97f60455605e915b8176d9170cae337bfedcc6 (deepseek-harness, MIT — see LICENSE-harness)
3
3
  // Copied 2026-10-09. Structural fixes flow from upstream during harness
4
4
  // migrations; CC-specific divergences must be recorded in DIVERGENCE.md.
5
5
  /** Standard ACP session configuration over one Agent's model selection. */
6
6
  import { installModelSelection } from '@deepseek-ai/dsh-agent';
7
7
  import { ReasoningEffortId } from '@deepseek-ai/dsh-llm';
8
+ // CC-only delta (D4c, harness-0.2.2 migration): an ACP config-set model change
9
+ // is an explicit USER write — notify moa exactly like the TUI `/model` path so
10
+ // arming disarms (or re-arms on the boot pair) consistently across entry points.
11
+ import { noteUserSelection } from '@dsh-cc/moa';
12
+ // CC-only delta (D4a): the co-located model-selection notice sanitizer.
8
13
  import { installModelSelectionSanitizer } from '@dsh-cc/moa/sanitizer';
9
14
  const MODEL_CONFIG_ID = 'model';
10
15
  const REASONING_CONFIG_ID = 'reasoning_effort';
11
16
  // DSH reasoning effort ids are non-empty, so the empty opaque ACP value is a disjoint provider-default choice.
12
17
  const PROVIDER_DEFAULT_REASONING_VALUE = '';
18
+ /**
19
+ * Compose one ACP session's model-control listeners in the unpublished Agent
20
+ * scope: the harness switch-notice listener plus, co-located immediately after
21
+ * it, the moa notice sanitizer (D4a / effective-model-truth §5.1 — the
22
+ * later-with-prepend registration makes the sanitizer the OUTERMOST
23
+ * `agent/pre-step` listener, publishing the frozen per-step selection before
24
+ * the inner chain runs). Same co-location rule as the TUI's
25
+ * `model-selection-wiring.ts`; side-effect-free when moa is unmounted.
26
+ * @param agentCtx - unpublished Agent scope that consumes this selection.
27
+ */
28
+ export function installModelControl(agentCtx) {
29
+ installModelSelection(agentCtx);
30
+ installModelSelectionSanitizer(agentCtx);
31
+ }
13
32
  /** Caller-correctable session configuration failure. */
14
33
  export class AcpModelConfigError extends Error {
15
34
  constructor(message) {
@@ -17,59 +36,19 @@ export class AcpModelConfigError extends Error {
17
36
  this.name = 'AcpModelConfigError';
18
37
  }
19
38
  }
20
- /** Project and mutate one Agent's provider/model/reasoning selection through ACP config options. */
39
+ /**
40
+ * Project and mutate one Agent's provider/model/reasoning selection through ACP
41
+ * config options. The Session's recorded model selection is the only state; a
42
+ * change applies from the Agent's next model step.
43
+ */
21
44
  export class AcpModelControl {
22
45
  llm;
23
- /** Scoped selection reference consumed by Agent request assembly. */
24
- selection;
46
+ model;
25
47
  tail = Promise.resolve();
26
- selected;
27
- turnSelection;
28
48
  hasResolvedState = false;
29
- constructor(llm, initial) {
49
+ constructor(llm, model) {
30
50
  this.llm = llm;
31
- this.selected = initial;
32
- const getCurrent = () => this.turnSelection?.selection ?? this.selected;
33
- const setCurrent = (value) => { this.selected = value; };
34
- this.selection = {
35
- get current() { return getCurrent(); },
36
- set current(value) { setCurrent(value); },
37
- assembled: undefined,
38
- };
39
- }
40
- /**
41
- * Install request/prompt consistency listeners in the unpublished Agent scope.
42
- * @param agentCtx - Agent scope that consumes this selection.
43
- */
44
- install(agentCtx) {
45
- installModelSelection(agentCtx, this.selection);
46
- // Co-located sanitizer (effective-model-truth §5.1): later-with-prepend →
47
- // outermost agent/pre-step listener; drops phantom model-selection notices
48
- // while moa overlays the boot selection.
49
- installModelSelectionSanitizer(agentCtx, this.selection);
50
- }
51
- /**
52
- * Snapshot the selection attached to the next accepted ACP prompt.
53
- * @returns a detached future selection, or undefined when listeners supply the route.
54
- */
55
- snapshot() {
56
- return this.selected === undefined ? undefined : { ...this.selected };
57
- }
58
- /**
59
- * Pin one admitted ACP message's selection for every step in its turn.
60
- * @param turn - admitted Agent turn.
61
- * @param selection - exact prompt-admission selection.
62
- */
63
- pinTurn(turn, selection) {
64
- this.turnSelection = { turn, selection: { ...selection } };
65
- }
66
- /**
67
- * Release only the exact completed turn's routing override.
68
- * @param turn - completed Agent turn.
69
- */
70
- releaseTurn(turn) {
71
- if (this.turnSelection?.turn === turn)
72
- this.turnSelection = undefined;
51
+ this.model = model;
73
52
  }
74
53
  /**
75
54
  * Return the complete standard config-option state after prior mutations settle.
@@ -90,7 +69,7 @@ export class AcpModelControl {
90
69
  return this.serialize(async () => {
91
70
  if (typeof value !== 'string')
92
71
  throw new AcpModelConfigError(`${configId} requires a select value`);
93
- const current = this.selected;
72
+ const current = this.model.current();
94
73
  if (current === undefined)
95
74
  throw new AcpModelConfigError('this session has no model selection');
96
75
  if (configId === MODEL_CONFIG_ID) {
@@ -99,7 +78,9 @@ export class AcpModelControl {
99
78
  if (selected === undefined)
100
79
  throw new AcpModelConfigError(`unknown model option: ${value}`);
101
80
  await this.resolveSelection(selected, signal);
102
- this.selected = selected;
81
+ this.model.select(selected);
82
+ // D4c: notify moa with the exact recorded write (provider/model pair).
83
+ noteUserSelection(selected);
103
84
  }
104
85
  else if (configId === REASONING_CONFIG_ID) {
105
86
  const info = await this.llm.resolveModelInfo(current.provider, current.model, signal);
@@ -109,11 +90,16 @@ export class AcpModelControl {
109
90
  || (!providerDefault && !info.reasoning.efforts.some(effort => effort.id === value))) {
110
91
  throw new AcpModelConfigError(`unknown reasoning effort for ${current.provider}/${current.model}: ${value}`);
111
92
  }
112
- this.selected = await this.resolveSelection({
93
+ const effortSelection = await this.resolveSelection({
113
94
  provider: current.provider,
114
95
  model: current.model,
115
96
  ...providerDefault ? {} : { reasoningEffort: ReasoningEffortId(value) },
116
97
  }, signal);
98
+ this.model.select(effortSelection);
99
+ // D4c: an effort change is a USER write carrying the current pair too
100
+ // (the driver's `/effort` path does the same — stale effort otherwise
101
+ // survives a FailOpenServe restore).
102
+ noteUserSelection(effortSelection);
117
103
  }
118
104
  else {
119
105
  throw new AcpModelConfigError(`unknown session config option: ${configId}`);
@@ -129,7 +115,7 @@ export class AcpModelControl {
129
115
  }
130
116
  /** Build detached model choices and the dependent reasoning option. */
131
117
  async state(signal) {
132
- const selected = this.selected;
118
+ const selected = this.model.current();
133
119
  if (selected === undefined)
134
120
  return { choices: new Map(), options: [] };
135
121
  let resolved;
@@ -1 +1 @@
1
- {"version":3,"file":"model-control.js","sourceRoot":"","sources":["../src/model-control.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,qGAAqG;AACrG,wEAAwE;AACxE,yEAAyE;AACzE,2EAA2E;AAI3E,OAAO,EAAE,qBAAqB,EAA+C,MAAM,wBAAwB,CAAA;AAC3G,OAAO,EAAE,iBAAiB,EAAuC,MAAM,sBAAsB,CAAA;AAC7F,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAA;AAEtE,MAAM,eAAe,GAAG,OAAO,CAAA;AAC/B,MAAM,mBAAmB,GAAG,kBAAkB,CAAA;AAC9C,+GAA+G;AAC/G,MAAM,gCAAgC,GAAG,EAAE,CAAA;AAY3C,wDAAwD;AACxD,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;AAED,oGAAoG;AACpG,MAAM,OAAO,eAAe;IASP;IARnB,qEAAqE;IAC5D,SAAS,CAAmB;IAC7B,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;IACxB,QAAQ,CAA4B;IACpC,aAAa,CAAyD;IACtE,gBAAgB,GAAG,KAAK,CAAA;IAEhC,YACmB,GAAe,EAChC,OAAmC;QADlB,QAAG,GAAH,GAAG,CAAY;QAGhC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,MAAM,UAAU,GAAG,GAA+B,EAAE,CAAC,IAAI,CAAC,aAAa,EAAE,SAAS,IAAI,IAAI,C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AAiB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QACnF,OAAO;YACL,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,GAAG,QAAQ,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,QAAQ,CAAC,eAAe,EAAE;SAC/F,CAAA;IACH,CAAC;CACF;AAED,kEAAkE;AAClE,SAAS,UAAU,CAAC,QAAgB,EAAE,KAAa;IACjD,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAA;AAC1C,CAAC"}
package/lib/session.d.ts CHANGED
@@ -1,27 +1,25 @@
1
1
  /** One standard ACP session's Agent, configuration, prompt, update, and teardown lifecycle. */
2
2
  import type { Context } from '@deepseek-ai/cordis';
3
3
  import { type McpServer, type PromptRequest, type PromptResponse, type SessionConfigOption, type SessionNotification } from '@agentclientprotocol/sdk';
4
- import type { Agent, AgentOptions, ModelSelection } from '@deepseek-ai/dsh-agent';
4
+ import type { Agent, AgentOptions, AgentStatus } from '@deepseek-ai/dsh-agent';
5
5
  import { type UserMessage } from '@deepseek-ai/dsh-llm';
6
6
  import { type Session, type SessionEvent, type SessionId } from '@deepseek-ai/dsh-session';
7
- /** The preset-registry seam composed into every ACP session (§5.2). */
8
- export interface AcpPresetsService {
9
- mount(agentCtx: Context, presetId?: string): Promise<unknown>;
10
- /** Compose a preset into a published agent, appending `agent-preset/selected`. */
11
- select(agent: Agent, presetId: string): Promise<string>;
12
- /** The preset a live agent already uses, if bound. */
13
- composedPreset(ctx: Context): string | undefined;
14
- }
15
7
  /** Inputs shared by fresh and resumed ACP session construction. */
16
8
  interface AcpSessionBuildOptions {
17
9
  cwd: string;
18
10
  mcpServers: readonly McpServer[];
19
11
  agentOptions: AgentOptions;
20
- fallbackSelection: ModelSelection | undefined;
21
- presets: AcpPresetsService;
22
12
  signal: AbortSignal;
23
13
  notify: (notification: SessionNotification) => Promise<void>;
24
14
  }
15
+ /** The preset-registry seam composed into every ACP session (§5.2). */
16
+ export interface AcpPresetsService {
17
+ mount(agentCtx: Context, presetId?: string): Promise<unknown>;
18
+ /** Compose a preset into a published agent, appending `agent-preset/selected`. */
19
+ select(agent: Agent, presetId: string): Promise<string>;
20
+ /** The preset a live agent already uses, if bound. */
21
+ composedPreset(ctx: Context): string | undefined;
22
+ }
25
23
  /** Fresh ACP session construction inputs. */
26
24
  export interface CreateAcpSessionOptions extends AcpSessionBuildOptions {
27
25
  sessionId: SessionId;
@@ -33,9 +31,9 @@ export interface ResumeAcpSessionOptions extends AcpSessionBuildOptions {
33
31
  sessionId: SessionId;
34
32
  }
35
33
  /**
36
- * Per-session ACP module. It owns the unpublished Agent composition, selected
37
- * route, one-prompt admission slot, ordered standard updates, and memoized
38
- * quiescent teardown.
34
+ * Per-session ACP module. It owns the unpublished Agent composition, model
35
+ * configuration view, one-prompt admission slot, ordered standard updates,
36
+ * and memoized quiescent teardown.
39
37
  */
40
38
  export declare class AcpSession {
41
39
  private readonly ctx;
@@ -46,7 +44,6 @@ export declare class AcpSession {
46
44
  private outputTail;
47
45
  private inflight;
48
46
  private closing;
49
- private readonly pendingSelections;
50
47
  private constructor();
51
48
  private readonly disposeAgent;
52
49
  /**
@@ -58,8 +55,10 @@ export declare class AcpSession {
58
55
  static create(ctx: Context, options: CreateAcpSessionOptions): Promise<AcpSession>;
59
56
  /**
60
57
  * Restore a persisted Agent and compose the request's fresh MCP connections.
58
+ * The Session's recorded model selection survives; deployment options supply
59
+ * the route only when the Session records neither a selection nor a request.
61
60
  * @param ctx - ACP plugin context with Agent, LLM, and persistence services.
62
- * @param options - persisted identity, workspace, fallback route, MCP, and notifier.
61
+ * @param options - persisted identity, workspace, initial route, MCP, and notifier.
63
62
  * @returns the restored per-session module.
64
63
  */
65
64
  static resume(ctx: Context, options: ResumeAcpSessionOptions): Promise<AcpSession>;
@@ -82,7 +81,7 @@ export declare class AcpSession {
82
81
  */
83
82
  configOptions(signal?: AbortSignal): Promise<SessionConfigOption[]>;
84
83
  /**
85
- * Apply one standard configuration option to later ACP turns.
84
+ * Apply one standard configuration option from the next model step.
86
85
  * @param configId - advertised standard option id.
87
86
  * @param value - selected standard option value.
88
87
  * @param signal - optional request cancellation.
@@ -92,7 +91,7 @@ export declare class AcpSession {
92
91
  /** Resolve topology state off-chain, then serialize its notification without blocking execution updates. */
93
92
  topologyChanged(): void;
94
93
  /**
95
- * Admit, enqueue, and settle one prompt at whole-Agent quiescence.
94
+ * Admit one prompt and settle after the root, descendants, and updates finish.
96
95
  * @param params - standard ACP prompt request for this session.
97
96
  * @param imageEnabled - connection capability advertised at initialization.
98
97
  * @param requestSignal - JSON-RPC request cancellation signal.
@@ -108,17 +107,21 @@ export declare class AcpSession {
108
107
  */
109
108
  onSessionEvent(session: Session, event: SessionEvent): void;
110
109
  /**
111
- * Correlate an accepted user message with its Agent turn and pinned route.
110
+ * Correlate an accepted user message with its Agent turn.
112
111
  * @param message - claimed durable inbox message.
113
112
  * @param turn - allocated Agent turn.
114
113
  */
115
114
  onInboxClaimed(message: UserMessage, turn: number): void;
116
115
  /**
117
116
  * Correlate an Agent interval failure with the active ACP prompt.
118
- * @param turn - failed turn number.
119
117
  * @param error - original same-process failure.
120
118
  */
121
- onAgentError(turn: number, error: unknown): void;
119
+ onAgentError(error: unknown): void;
120
+ /**
121
+ * Complete cancelled activity without following a later root driver.
122
+ * @param status - the emitted transition, which may precede a reentrant wake.
123
+ */
124
+ onAgentStatus(status: AgentStatus): void;
122
125
  /** Await every update queued before this call. */
123
126
  drainUpdates(): Promise<void>;
124
127
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAIA,+FAA+F;AAE/F,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAEL,KAAK,SAAS,EAC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deepseek-harness, MIT — see LICENSE-harness)
2
+ // Source ref: 2f97f60455605e915b8176d9170cae337bfedcc6 (deepseek-harness, MIT — see LICENSE-harness)
3
3
  // Copied 2026-10-09. Structural fixes flow from upstream during harness
4
4
  // migrations; CC-specific divergences must be recorded in DIVERGENCE.md.
5
5
  /** One standard ACP session's Agent, configuration, prompt, update, and teardown lifecycle. */
6
6
  import { RequestError, } from '@agentclientprotocol/sdk';
7
+ // CC-only deltas (D4a/D4b): the model-control install helper (switch notice +
8
+ // co-located notice sanitizer) and the moa pre-admission routing hook. Both are
9
+ // side-effect-free when moa is unmounted (the sanitizer's runtime-state
10
+ // accessors are inert, the router's admission entry is absent), so a moa-less
11
+ // deployment is byte-equivalent.
12
+ import { routeBeforeAdmission } from '@dsh-cc/moa';
13
+ import { awaitQuiescence, noteAgentError, requestPromptCancellation, settleCancelledOnStatus } from "./cancellation-status.js";
7
14
  import { createUserMessage, errorChain } from '@deepseek-ai/dsh-llm';
8
15
  import { AcpContentError, admitAcpPrompt } from "./content.js";
9
16
  import { turnEndToStopReason } from "./codec.js";
10
17
  import { mountAcpMcpServers } from "./mcp.js";
11
- import { AcpModelControl } from "./model-control.js";
18
+ import { AcpModelControl, installModelControl } from "./model-control.js";
12
19
  import { assistantUpdates, toolCallUpdate, toolResultUpdate } from "./updates.js";
13
20
  /** Standard invalid-parameter failure with protocol-safe detail. */
14
21
  function invalidParams(detail) {
@@ -18,22 +25,22 @@ function invalidParams(detail) {
18
25
  function internalError(detail) {
19
26
  return RequestError.internalError(undefined, detail);
20
27
  }
21
- /** Restore the latest logged route before falling back to deployment config. */
22
- function selectionFor(logged, fallback) {
23
- return logged === undefined
24
- ? fallback
25
- : {
26
- provider: logged.config.provider,
27
- model: logged.config.model,
28
- ...logged.config.reasoningEffort === undefined || logged.adapterDefaults?.reasoningEffort === true
29
- ? {}
30
- : { reasoningEffort: logged.config.reasoningEffort },
31
- };
28
+ /**
29
+ * Install switch notices and mount the requested MCP clients in the unpublished Agent scope.
30
+ * @param agentCtx - unpublished Agent scope.
31
+ * @param options - workspace and MCP servers requested for the session.
32
+ */
33
+ async function composeAgent(agentCtx, options) {
34
+ // CC-only delta (D4a): the model-control install is a co-located helper —
35
+ // the harness switch-notice listener plus the moa notice sanitizer — so the
36
+ // §5.1 co-location rule lives next to the selection seam it guards.
37
+ installModelControl(agentCtx);
38
+ await mountAcpMcpServers(agentCtx, options.mcpServers, options.cwd);
32
39
  }
33
40
  /**
34
- * Per-session ACP module. It owns the unpublished Agent composition, selected
35
- * route, one-prompt admission slot, ordered standard updates, and memoized
36
- * quiescent teardown.
41
+ * Per-session ACP module. It owns the unpublished Agent composition, model
42
+ * configuration view, one-prompt admission slot, ordered standard updates,
43
+ * and memoized quiescent teardown.
37
44
  */
38
45
  export class AcpSession {
39
46
  ctx;
@@ -44,12 +51,11 @@ export class AcpSession {
44
51
  outputTail = Promise.resolve();
45
52
  inflight;
46
53
  closing;
47
- pendingSelections = new Map();
48
- constructor(ctx, handle, modelControl, notify) {
54
+ constructor(ctx, handle, notify) {
49
55
  this.ctx = ctx;
50
56
  this.notify = notify;
51
57
  this.agent = handle.agent;
52
- this.modelControl = modelControl;
58
+ this.modelControl = new AcpModelControl(ctx.llm, handle.agent.model);
53
59
  this.disposeAgent = () => handle.dispose();
54
60
  }
55
61
  disposeAgent;
@@ -60,62 +66,32 @@ export class AcpSession {
60
66
  * @returns the fully composed per-session module.
61
67
  */
62
68
  static async create(ctx, options) {
63
- const modelControl = new AcpModelControl(ctx.llm, options.fallbackSelection);
64
69
  const handle = await ctx.agents.create({
65
70
  sessionId: options.sessionId,
66
- // §5.2 (docs/plans/2026-10-09-acp-m2-own-plugin.md): the create header
67
- // records the composed preset identity (frozen creation fact, copied
68
- // into the header by agents.create — core/session/src/index.ts:1058).
71
+ // §5.2: the frozen create header records the composed preset identity.
69
72
  meta: { cwd: options.cwd, agentPreset: options.presetId },
70
73
  agentOptions: options.agentOptions,
71
74
  signal: options.signal,
72
- setup: async (agentCtx) => {
73
- // §5.2, revised after live acceptance (2026-10-09): the preset join
74
- // moved OUT of the create setup — mount() inside setup double-applies
75
- // the roster rows in the composed profile (persona/command
76
- // double-registration surfacing at session/new). The join now runs
77
- // on the serial `agent/created` event via registry select() in
78
- // index.ts (the live-verified P2b form; select also appends the
79
- // model-visible `agent-preset/selected` event). Setup keeps the
80
- // remaining order: model control, then MCP (mounts plugins
81
- // immediately, so it goes last).
82
- modelControl.install(agentCtx);
83
- await mountAcpMcpServers(agentCtx, options.mcpServers, options.cwd);
84
- },
75
+ setup: agentCtx => composeAgent(agentCtx, options),
85
76
  });
86
- return new AcpSession(ctx, handle, modelControl, options.notify);
77
+ return new AcpSession(ctx, handle, options.notify);
87
78
  }
88
79
  /**
89
80
  * Restore a persisted Agent and compose the request's fresh MCP connections.
81
+ * The Session's recorded model selection survives; deployment options supply
82
+ * the route only when the Session records neither a selection nor a request.
90
83
  * @param ctx - ACP plugin context with Agent, LLM, and persistence services.
91
- * @param options - persisted identity, workspace, fallback route, MCP, and notifier.
84
+ * @param options - persisted identity, workspace, initial route, MCP, and notifier.
92
85
  * @returns the restored per-session module.
93
86
  */
94
87
  static async resume(ctx, options) {
95
- let modelControl;
96
88
  const handle = await ctx.agents.resume({
97
89
  resumeSessionId: options.sessionId,
98
90
  agentOptions: options.agentOptions,
99
91
  signal: options.signal,
100
- setup: async (agentCtx, agent) => {
101
- // §5.2, revised after live acceptance (2026-10-09): the preset join
102
- // runs on the serial `agent/created` event (index.ts) for resumed
103
- // agents too — it joins the RECORDED header stamp, so a presetless
104
- // session stays presetless and an unrecorded id fails loudly
105
- // through select(). Resume therefore only re-installs model control
106
- // and MCP here.
107
- modelControl = new AcpModelControl(ctx.llm, selectionFor(agent.session.requestHeader(), options.fallbackSelection));
108
- modelControl.install(agentCtx);
109
- await mountAcpMcpServers(agentCtx, options.mcpServers, options.cwd);
110
- },
92
+ setup: agentCtx => composeAgent(agentCtx, options),
111
93
  });
112
- /* v8 ignore start -- a fulfilled Agent resume necessarily ran setup to completion. */
113
- if (modelControl === undefined) {
114
- await handle.dispose();
115
- throw internalError('session/resume did not compose model selection');
116
- }
117
- /* v8 ignore stop */
118
- return new AcpSession(ctx, handle, modelControl, options.notify);
94
+ return new AcpSession(ctx, handle, options.notify);
119
95
  }
120
96
  /**
121
97
  * Whether this module owns an exact Agent reference.
@@ -143,7 +119,7 @@ export class AcpSession {
143
119
  return this.modelControl.options(signal);
144
120
  }
145
121
  /**
146
- * Apply one standard configuration option to later ACP turns.
122
+ * Apply one standard configuration option from the next model step.
147
123
  * @param configId - advertised standard option id.
148
124
  * @param value - selected standard option value.
149
125
  * @param signal - optional request cancellation.
@@ -180,7 +156,7 @@ export class AcpSession {
180
156
  /* v8 ignore stop */
181
157
  }
182
158
  /**
183
- * Admit, enqueue, and settle one prompt at whole-Agent quiescence.
159
+ * Admit one prompt and settle after the root, descendants, and updates finish.
184
160
  * @param params - standard ACP prompt request for this session.
185
161
  * @param imageEnabled - connection capability advertised at initialization.
186
162
  * @param requestSignal - JSON-RPC request cancellation signal.
@@ -203,7 +179,8 @@ export class AcpSession {
203
179
  admissionDone: admission.promise,
204
180
  finishAdmission: admission.resolve,
205
181
  admissionController,
206
- cancelRequested: false,
182
+ cancellationDone: Promise.withResolvers(),
183
+ cancelStartedIdle: false,
207
184
  settlementStarted: false,
208
185
  outputError: undefined,
209
186
  agentError: undefined,
@@ -216,7 +193,7 @@ export class AcpSession {
216
193
  onRequestAbort();
217
194
  try {
218
195
  let admissionFailure;
219
- const promptSelection = this.modelControl.snapshot();
196
+ const promptSelection = this.agent.model.current();
220
197
  try {
221
198
  if (this.ctx.agents.get(this.agent.id) !== this.agent) {
222
199
  throw internalError('prompt was not queued: the agent was disposed outside the bridge');
@@ -232,14 +209,16 @@ export class AcpSession {
232
209
  });
233
210
  inflight.messageId = message.id;
234
211
  inflight.messageQueued = true;
235
- if (promptSelection !== undefined)
236
- this.pendingSelections.set(message.id, promptSelection);
212
+ // CC-only delta (D4b / D3.2): moa's pre-admission classification runs on
213
+ // the EXACT admitted UserMessage, before the prompt splice — an ACP turn
214
+ // therefore routes through the same entry-point seam the TUI uses.
215
+ // Inert when moa is unmounted or disarmed.
216
+ await routeBeforeAdmission(this.agent, message);
237
217
  try {
238
218
  this.agent.followup(message);
239
219
  }
240
220
  catch (error) {
241
221
  inflight.messageQueued = false;
242
- this.pendingSelections.delete(message.id);
243
222
  throw error;
244
223
  }
245
224
  }
@@ -249,7 +228,7 @@ export class AcpSession {
249
228
  finally {
250
229
  inflight.finishAdmission();
251
230
  }
252
- if (inflight.cancelRequested) {
231
+ if (inflight.admissionController.signal.aborted) {
253
232
  this.settleAfterQuiescence(inflight);
254
233
  return { stopReason: await completion.promise };
255
234
  }
@@ -284,6 +263,10 @@ export class AcpSession {
284
263
  * @param event - committed durable event.
285
264
  */
286
265
  onSessionEvent(session, event) {
266
+ if (event.type === 'turn/start' && this.inflight?.turn !== undefined) {
267
+ this.inflight.turn = event.data.turn;
268
+ this.inflight.endReason = undefined;
269
+ }
287
270
  try {
288
271
  if (event.type === 'assistant/message') {
289
272
  const inflight = this.inflight?.turn === event.data.turn ? this.inflight : undefined;
@@ -328,39 +311,38 @@ export class AcpSession {
328
311
  const inflight = this.inflight;
329
312
  if (inflight !== undefined && event.type === 'turn/end' && inflight.turn === event.data.turn) {
330
313
  inflight.endReason = event.data.reason;
314
+ inflight.agentError = undefined;
331
315
  }
332
- if (event.type === 'turn/end')
333
- this.modelControl.releaseTurn(event.data.turn);
334
316
  }
335
317
  }
336
318
  /**
337
- * Correlate an accepted user message with its Agent turn and pinned route.
319
+ * Correlate an accepted user message with its Agent turn.
338
320
  * @param message - claimed durable inbox message.
339
321
  * @param turn - allocated Agent turn.
340
322
  */
341
323
  onInboxClaimed(message, turn) {
342
324
  if (this.inflight !== undefined && this.inflight.messageId === message.id)
343
325
  this.inflight.turn = turn;
344
- const selection = this.pendingSelections.get(message.id);
345
- this.pendingSelections.delete(message.id);
346
- if (selection !== undefined)
347
- this.modelControl.pinTurn(turn, selection);
348
326
  }
349
327
  /**
350
328
  * Correlate an Agent interval failure with the active ACP prompt.
351
- * @param turn - failed turn number.
352
329
  * @param error - original same-process failure.
353
330
  */
354
- onAgentError(turn, error) {
331
+ onAgentError(error) {
355
332
  const inflight = this.inflight;
356
- if (inflight === undefined || !inflight.messageQueued)
333
+ if (inflight === undefined)
357
334
  return;
358
- // AgentLoop balances an in-turn failure with durable turn/end; settlement
359
- // reads that exact error reason. This slot records interval failures outside it.
360
- if (inflight.turn === turn)
335
+ noteAgentError(inflight, errorChain(error), () => this.settleAfterQuiescence(inflight));
336
+ }
337
+ /**
338
+ * Complete cancelled activity without following a later root driver.
339
+ * @param status - the emitted transition, which may precede a reentrant wake.
340
+ */
341
+ onAgentStatus(status) {
342
+ const inflight = this.inflight;
343
+ if (inflight === undefined)
361
344
  return;
362
- inflight.agentError = new Error(errorChain(error));
363
- this.settleAfterQuiescence(inflight);
345
+ settleCancelledOnStatus(inflight, status, this.outputTail);
364
346
  }
365
347
  /** Await every update queued before this call. */
366
348
  drainUpdates() {
@@ -390,11 +372,11 @@ export class AcpSession {
390
372
  }
391
373
  const subagents = this.ctx.get('subagents');
392
374
  try {
393
- await subagents?.drainContinuableDescendants([this.agent]);
375
+ await subagents?.drainDescendants([this.agent]);
394
376
  }
395
377
  catch (error) {
396
- this.ctx.logger.warn(`acp: continuable subagent teardown failed: ${errorChain(error)}`);
397
- failures.push(new Error('continuable subagent teardown failed', { cause: error }));
378
+ this.ctx.logger.warn(`acp: subagent teardown failed: ${errorChain(error)}`);
379
+ failures.push(new Error('subagent teardown failed', { cause: error }));
398
380
  }
399
381
  try {
400
382
  await this.ctx.sessions.flush(this.agent.session);
@@ -408,7 +390,6 @@ export class AcpSession {
408
390
  catch (error) {
409
391
  failures.push(error);
410
392
  }
411
- this.pendingSelections.clear();
412
393
  if (failures.length === 1)
413
394
  throw failures[0];
414
395
  /* v8 ignore start -- independent teardown failures can aggregate only under multiple simultaneous provider faults. */
@@ -427,11 +408,7 @@ export class AcpSession {
427
408
  const inflight = this.inflight;
428
409
  if (inflight === undefined)
429
410
  return;
430
- inflight.cancelRequested = true;
431
- inflight.admissionController.abort(new Error(detail));
432
- this.settleAfterQuiescence(inflight);
433
- if (inflight.messageQueued)
434
- this.agent.cancel({ kind: 'user' });
411
+ requestPromptCancellation(this.agent, inflight, detail, () => this.settleAfterQuiescence(inflight), () => this.outputTail);
435
412
  }
436
413
  settleAfterQuiescence(inflight) {
437
414
  if (inflight.settlementStarted)
@@ -440,14 +417,14 @@ export class AcpSession {
440
417
  void (async () => {
441
418
  await inflight.admissionDone;
442
419
  if (inflight.messageQueued) {
443
- await this.agent.whenIdle();
444
- await this.outputTail;
420
+ const subagents = this.ctx.get('subagents');
421
+ await awaitQuiescence(this.agent, subagents, inflight, () => this.outputTail);
445
422
  }
446
423
  /* v8 ignore next -- this prompt owns the slot until this exact settlement clears it. */
447
424
  if (this.inflight !== inflight)
448
425
  return;
449
426
  this.inflight = undefined;
450
- if (inflight.cancelRequested) {
427
+ if (inflight.admissionController.signal.aborted) {
451
428
  inflight.resolve('cancelled');
452
429
  return;
453
430
  }