@ycodium-ai/agent-dsh 0.2.3576 → 0.2.3608

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.
Files changed (2) hide show
  1. package/dist/index.js +697 -55
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -5577,8 +5577,8 @@ var require_cst_visit = __commonJS({
5577
5577
  visit2.REMOVE = REMOVE;
5578
5578
  visit2.itemAtPath = (cst, path) => {
5579
5579
  let item = cst;
5580
- for (const [field, index] of path) {
5581
- const tok = item?.[field];
5580
+ for (const [field2, index] of path) {
5581
+ const tok = item?.[field2];
5582
5582
  if (tok && "items" in tok) {
5583
5583
  item = tok.items[index];
5584
5584
  } else
@@ -5588,8 +5588,8 @@ var require_cst_visit = __commonJS({
5588
5588
  };
5589
5589
  visit2.parentCollection = (cst, path) => {
5590
5590
  const parent = visit2.itemAtPath(cst, path.slice(0, -1));
5591
- const field = path[path.length - 1][0];
5592
- const coll = parent?.[field];
5591
+ const field2 = path[path.length - 1][0];
5592
+ const coll = parent?.[field2];
5593
5593
  if (coll && "items" in coll)
5594
5594
  return coll;
5595
5595
  throw new Error("Parent collection not found");
@@ -5598,11 +5598,11 @@ var require_cst_visit = __commonJS({
5598
5598
  let ctrl = visitor(item, path);
5599
5599
  if (typeof ctrl === "symbol")
5600
5600
  return ctrl;
5601
- for (const field of ["key", "value"]) {
5602
- const token = item[field];
5601
+ for (const field2 of ["key", "value"]) {
5602
+ const token = item[field2];
5603
5603
  if (token && "items" in token) {
5604
5604
  for (let i = 0; i < token.items.length; ++i) {
5605
- const ci = _visit(Object.freeze(path.concat([[field, i]])), token.items[i], visitor);
5605
+ const ci = _visit(Object.freeze(path.concat([[field2, i]])), token.items[i], visitor);
5606
5606
  if (typeof ci === "number")
5607
5607
  i = ci - 1;
5608
5608
  else if (ci === BREAK)
@@ -5612,7 +5612,7 @@ var require_cst_visit = __commonJS({
5612
5612
  i -= 1;
5613
5613
  }
5614
5614
  }
5615
- if (typeof ctrl === "function" && field === "key")
5615
+ if (typeof ctrl === "function" && field2 === "key")
5616
5616
  ctrl = ctrl(item, path);
5617
5617
  }
5618
5618
  }
@@ -7427,7 +7427,9 @@ var DSH_CARD = {
7427
7427
  // 声明这一位,界面才画这只手自报的三档并让用户挑;不声明时档位按钮只读,用户被
7428
7428
  // 钉在起点档 `workspace-write`,每次工具调用都要批。这只手不实现 `setNativeMode`,
7429
7429
  // 宿主据此不做活切,挑的档下一轮生效(与 runtimeModeSwitch 同为 next-turn 的原因)。
7430
- nativeModeSwitch: true
7430
+ nativeModeSwitch: true,
7431
+ // 每次 `subagent` / `subagent_fork` 调用报一条 `task.*`;终态不上线,一轮结束按 idle 收尾(见 subagents.ts)。
7432
+ reportsSpawnedAgents: true
7431
7433
  },
7432
7434
  // 凭据由 CLI 自己保管在它 home 里,宿主不读 token。
7433
7435
  credentialSources: [],
@@ -7971,13 +7973,14 @@ function extractToolCallCommand(rawInput, title) {
7971
7973
  }
7972
7974
  var TOOL_CALL_CONTENT_MAX_CHARS = 8e3;
7973
7975
  var TOOL_CALL_CONTENT_TRUNCATION_MARKER = "[Earlier output truncated]\n\n";
7974
- function boundToolCallOutputText(text) {
7975
- if (text.length <= TOOL_CALL_CONTENT_MAX_CHARS) {
7976
+ function boundTailText(text, limit = TOOL_CALL_CONTENT_MAX_CHARS) {
7977
+ if (text.length <= limit) {
7976
7978
  return text;
7977
7979
  }
7978
- const tail = text.slice(text.length - TOOL_CALL_CONTENT_MAX_CHARS);
7980
+ const tail = text.slice(text.length - limit);
7979
7981
  return `${TOOL_CALL_CONTENT_TRUNCATION_MARKER}${tail}`;
7980
7982
  }
7983
+ var boundToolCallOutputText = (text) => boundTailText(text);
7981
7984
  var RAW_OUTPUT_TEXT_FIELDS = ["content", "stdout", "stderr", "output"];
7982
7985
  function boundToolCallRawOutput(rawOutput) {
7983
7986
  if (!isRecord(rawOutput)) {
@@ -7985,10 +7988,10 @@ function boundToolCallRawOutput(rawOutput) {
7985
7988
  }
7986
7989
  let changed = false;
7987
7990
  const bounded = { ...rawOutput };
7988
- for (const field of RAW_OUTPUT_TEXT_FIELDS) {
7989
- const value = rawOutput[field];
7991
+ for (const field2 of RAW_OUTPUT_TEXT_FIELDS) {
7992
+ const value = rawOutput[field2];
7990
7993
  if (typeof value === "string" && value.length > TOOL_CALL_CONTENT_MAX_CHARS) {
7991
- bounded[field] = boundToolCallOutputText(value);
7994
+ bounded[field2] = boundToolCallOutputText(value);
7992
7995
  changed = true;
7993
7996
  }
7994
7997
  }
@@ -8089,6 +8092,7 @@ function makeToolCallState(input2, options) {
8089
8092
  ...status ? { status } : {},
8090
8093
  ...command ? { command } : {},
8091
8094
  ...presentation?.detail ? { detail: presentation.detail } : {},
8095
+ ...textContent ? { contentText: textContent } : {},
8092
8096
  data
8093
8097
  };
8094
8098
  }
@@ -8099,6 +8103,7 @@ function mergeToolCallState(previous, next) {
8099
8103
  const status = next.status ?? previous?.status;
8100
8104
  const command = next.command ?? previous?.command;
8101
8105
  const detail = next.detail ?? previous?.detail;
8106
+ const contentText = "content" in next.data ? next.contentText : previous?.contentText;
8102
8107
  return {
8103
8108
  toolCallId: next.toolCallId,
8104
8109
  ...kind ? { kind } : {},
@@ -8106,6 +8111,7 @@ function mergeToolCallState(previous, next) {
8106
8111
  ...status ? { status } : {},
8107
8112
  ...command ? { command } : {},
8108
8113
  ...detail ? { detail } : {},
8114
+ ...contentText ? { contentText } : {},
8109
8115
  data: {
8110
8116
  ...previous?.data,
8111
8117
  ...next.data
@@ -8652,6 +8658,54 @@ function retainToolCallUpdate(toolCalls, next, seen) {
8652
8658
  return { nextToolCall, decision };
8653
8659
  }
8654
8660
 
8661
+ // ../../packages/ycodium-acp-executor/src/executor/child-sessions.ts
8662
+ var CHILD_LIMIT = 256;
8663
+ var active = (status) => status === "running" || status === "waiting";
8664
+ function createChildSessionRegistry(limit = CHILD_LIMIT) {
8665
+ const records = /* @__PURE__ */ new Map();
8666
+ const evictOne = (keep) => {
8667
+ const protectedIds = /* @__PURE__ */ new Set();
8668
+ for (const [id, record2] of records) {
8669
+ if (!active(record2.observed)) continue;
8670
+ protectedIds.add(id);
8671
+ let parent = record2.parentAgentId;
8672
+ while (parent !== void 0 && !protectedIds.has(parent)) {
8673
+ protectedIds.add(parent);
8674
+ parent = records.get(parent)?.parentAgentId;
8675
+ }
8676
+ }
8677
+ for (const id of records.keys()) {
8678
+ if (id === keep || protectedIds.has(id)) continue;
8679
+ records.delete(id);
8680
+ return;
8681
+ }
8682
+ };
8683
+ const add = (sessionId, record2) => {
8684
+ records.set(sessionId, record2);
8685
+ if (records.size > limit) evictOne(sessionId);
8686
+ };
8687
+ return {
8688
+ has: (sessionId) => records.has(sessionId),
8689
+ get: (sessionId) => records.get(sessionId),
8690
+ mark: (sessionId) => {
8691
+ if (records.has(sessionId)) return;
8692
+ add(sessionId, {
8693
+ turnId: void 0,
8694
+ title: void 0,
8695
+ description: void 0,
8696
+ parentAgentId: void 0,
8697
+ observed: void 0,
8698
+ reported: void 0,
8699
+ reportedError: void 0,
8700
+ announced: false,
8701
+ pendingMetadata: false
8702
+ });
8703
+ },
8704
+ add,
8705
+ entries: () => records.entries()
8706
+ };
8707
+ }
8708
+
8655
8709
  // ../../node_modules/.pnpm/@agentclientprotocol+sdk@1.4.0_zod@4.6.5/node_modules/@agentclientprotocol/sdk/dist/schema/index.js
8656
8710
  var AGENT_METHODS = {
8657
8711
  initialize: "initialize",
@@ -12214,14 +12268,14 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
12214
12268
  const shape = zod.def.shape;
12215
12269
  const propValues = {};
12216
12270
  for (const key in shape) {
12217
- const field = shape[key]._zod;
12218
- if (field.values) {
12271
+ const field2 = shape[key]._zod;
12272
+ if (field2.values) {
12219
12273
  if (!Object.prototype.hasOwnProperty.call(propValues, key)) {
12220
12274
  assignProp(propValues, key, /* @__PURE__ */ new Set());
12221
12275
  }
12222
- for (const v of field.values)
12276
+ for (const v of field2.values)
12223
12277
  propValues[key].add(v);
12224
- if (field.optin !== void 0)
12278
+ if (field2.optin !== void 0)
12225
12279
  propValues[key].add(void 0);
12226
12280
  }
12227
12281
  }
@@ -25149,8 +25203,8 @@ var objectProcessor = (schema, ctx, _json, params) => {
25149
25203
  }
25150
25204
  const requiredKeys = [];
25151
25205
  for (const key of Object.keys(shape)) {
25152
- const field = def.shape[key];
25153
- if (ctx.io === "input" ? inputOptin(field) === void 0 : field._zod.optout === void 0) {
25206
+ const field2 = def.shape[key];
25207
+ if (ctx.io === "input" ? inputOptin(field2) === void 0 : field2._zod.optout === void 0) {
25154
25208
  requiredKeys.push(key);
25155
25209
  }
25156
25210
  }
@@ -32634,7 +32688,9 @@ function createExecutorLifecycle({
32634
32688
  eventStream,
32635
32689
  onInputDead,
32636
32690
  shared,
32637
- promptResults
32691
+ promptResults,
32692
+ settleToolSubagents,
32693
+ settleSessionEnded
32638
32694
  }) {
32639
32695
  const cancel = async (turnId) => {
32640
32696
  failIfDisposed();
@@ -32665,6 +32721,7 @@ function createExecutorLifecycle({
32665
32721
  shared.promptsInFlight = 0;
32666
32722
  shared.activeTurnId = void 0;
32667
32723
  shared.status = "ready";
32724
+ settleToolSubagents("turn-interrupted", targetTurnId);
32668
32725
  emit({
32669
32726
  type: "turn.completed",
32670
32727
  ...stamp(),
@@ -32776,6 +32833,7 @@ function createExecutorLifecycle({
32776
32833
  shared.abortLocalPrompt?.();
32777
32834
  promptResults.finishUnreceived();
32778
32835
  await promptResults.wait();
32836
+ settleSessionEnded();
32779
32837
  emit({
32780
32838
  type: "session.exited",
32781
32839
  ...stamp(),
@@ -32879,6 +32937,304 @@ var acpPromptFailureCategory = (error62, input2) => {
32879
32937
  return error62 instanceof AcpConnectionClosedError ? acpTransportIfEstablished(input2.sessionEstablished, input2.disposed) : void 0;
32880
32938
  };
32881
32939
 
32940
+ // ../../packages/ycodium-acp-executor/src/tool-subagents.ts
32941
+ var EXCLUDED = /* @__PURE__ */ Symbol("excluded");
32942
+ var sealedHidden = (entry) => ({
32943
+ sealed: true,
32944
+ keepToolRow: false,
32945
+ turnId: entry.turnId,
32946
+ kind: entry.kind,
32947
+ taskId: entry.taskId,
32948
+ facts: entry.facts
32949
+ });
32950
+ function toolSubagentSettlementOfTurn(state, failureCategory) {
32951
+ if (state === "cancelled") return "turn-interrupted";
32952
+ return state === "failed" && failureCategory === "transport" ? "session-ended" : "turn-ended";
32953
+ }
32954
+ var sameFacts = (a, b) => a.title === b.title && a.description === b.description && a.summary === b.summary && a.role === b.role && a.model === b.model && a.effort === b.effort && a.rosterKind === b.rosterKind;
32955
+ function linkage(taskId, toolCallId, facts) {
32956
+ return {
32957
+ taskId,
32958
+ taskType: "subagent",
32959
+ toolUseId: toolCallId,
32960
+ title: facts.title,
32961
+ ...facts.role === void 0 ? {} : { role: facts.role },
32962
+ ...facts.model === void 0 ? {} : { model: facts.model },
32963
+ ...facts.effort === void 0 ? {} : { effort: facts.effort },
32964
+ ...facts.rosterKind === void 0 ? {} : { rosterKind: facts.rosterKind }
32965
+ };
32966
+ }
32967
+ var isEntry = (value) => value !== EXCLUDED && !("sealed" in value);
32968
+ function createToolSubagentTracker(spec) {
32969
+ const calls = /* @__PURE__ */ new Map();
32970
+ const agentTasks = /* @__PURE__ */ new Map();
32971
+ const rememberAgent = (ref, taskId, facts) => {
32972
+ agentTasks.set(ref, { taskId, facts });
32973
+ };
32974
+ const turnOf = (turnId) => turnId === void 0 ? {} : { turnId };
32975
+ const onToolCallUpdated = (call) => {
32976
+ const tracked = calls.get(call.toolCallId);
32977
+ if (tracked === EXCLUDED) return void 0;
32978
+ if (tracked !== void 0 && !isEntry(tracked)) {
32979
+ const late = spec.resolve?.(call, tracked.kind, { known: true, background: false });
32980
+ if (late !== void 0 && late.type !== "hold" && late.agentRef !== void 0) {
32981
+ rememberAgent(late.agentRef, tracked.taskId, tracked.facts);
32982
+ }
32983
+ const repeatedTerminal = call.status === "completed" || call.status === "failed";
32984
+ const events2 = [];
32985
+ const final = tracked.final;
32986
+ if (repeatedTerminal && final !== void 0 && final.summary === void 0 && late?.type === "final" && late.status === final.status && late.summary !== void 0) {
32987
+ final.summary = late.summary;
32988
+ events2.push({
32989
+ type: "task.completed",
32990
+ ...turnOf(tracked.turnId),
32991
+ payload: {
32992
+ ...linkage(tracked.taskId, call.toolCallId, tracked.facts),
32993
+ status: final.status,
32994
+ summary: late.summary
32995
+ }
32996
+ });
32997
+ }
32998
+ return {
32999
+ events: events2,
33000
+ handled: !tracked.keepToolRow || repeatedTerminal,
33001
+ ...turnOf(tracked.turnId)
33002
+ };
33003
+ }
33004
+ let known = tracked;
33005
+ let kind;
33006
+ if (known === void 0) {
33007
+ const recognized = spec.recognize(call);
33008
+ if (recognized === void 0) return void 0;
33009
+ if (recognized === "exclude") {
33010
+ calls.set(call.toolCallId, EXCLUDED);
33011
+ return void 0;
33012
+ }
33013
+ kind = recognized;
33014
+ } else {
33015
+ kind = known.kind;
33016
+ }
33017
+ const resolution = spec.resolve?.(call, kind, {
33018
+ known: known?.announced === true,
33019
+ background: known?.background ?? false
33020
+ });
33021
+ if (known?.phase === "idle" && resolution?.type !== "final") {
33022
+ if (resolution?.type === "background" && resolution.agentRef !== void 0) {
33023
+ rememberAgent(resolution.agentRef, known.taskId, known.facts);
33024
+ }
33025
+ return { events: [], handled: true };
33026
+ }
33027
+ let carriedTurn;
33028
+ if (known === void 0 || !known.announced) {
33029
+ if (resolution === void 0 && !(spec.ready?.(call, kind) ?? true)) {
33030
+ if (known === void 0) {
33031
+ calls.set(call.toolCallId, {
33032
+ kind,
33033
+ taskId: call.toolCallId,
33034
+ turnId: call.turnId,
33035
+ facts: spec.facts(call, kind, void 0),
33036
+ phase: "open",
33037
+ status: void 0,
33038
+ background: false,
33039
+ announced: false
33040
+ });
33041
+ }
33042
+ return { events: [], handled: true };
33043
+ }
33044
+ carriedTurn = known?.turnId;
33045
+ calls.delete(call.toolCallId);
33046
+ known = void 0;
33047
+ }
33048
+ const events = [];
33049
+ const ref = known === void 0 ? spec.resumes?.(call, kind) : void 0;
33050
+ const prior = ref === void 0 ? void 0 : agentTasks.get(ref);
33051
+ const facts = spec.facts(call, kind, prior?.facts ?? known?.facts);
33052
+ const turnId = known?.turnId ?? carriedTurn ?? call.turnId;
33053
+ const turn = turnOf(turnId);
33054
+ let entry;
33055
+ if (known !== void 0) {
33056
+ entry = known;
33057
+ } else if (prior !== void 0) {
33058
+ for (const [id, other] of calls) {
33059
+ if (other === EXCLUDED || other.taskId !== prior.taskId) continue;
33060
+ if (isEntry(other)) calls.set(id, sealedHidden(other));
33061
+ else if (other.final !== void 0) {
33062
+ const { final: _superseded, ...rest } = other;
33063
+ calls.set(id, rest);
33064
+ }
33065
+ }
33066
+ entry = {
33067
+ kind,
33068
+ taskId: prior.taskId,
33069
+ turnId,
33070
+ facts,
33071
+ phase: "open",
33072
+ status: "running",
33073
+ background: false,
33074
+ announced: true
33075
+ };
33076
+ calls.set(call.toolCallId, entry);
33077
+ events.push({
33078
+ type: "task.updated",
33079
+ ...turn,
33080
+ payload: {
33081
+ ...linkage(entry.taskId, call.toolCallId, facts),
33082
+ description: facts.description,
33083
+ status: "running"
33084
+ }
33085
+ });
33086
+ } else {
33087
+ entry = {
33088
+ kind,
33089
+ taskId: call.toolCallId,
33090
+ turnId,
33091
+ facts,
33092
+ phase: "open",
33093
+ status: void 0,
33094
+ background: false,
33095
+ announced: true
33096
+ };
33097
+ calls.set(call.toolCallId, entry);
33098
+ if (spec.announce === "started") {
33099
+ events.push({
33100
+ type: "task.started",
33101
+ ...turn,
33102
+ payload: {
33103
+ ...linkage(entry.taskId, call.toolCallId, facts),
33104
+ description: facts.description
33105
+ }
33106
+ });
33107
+ }
33108
+ }
33109
+ const seen = known !== void 0 || prior !== void 0;
33110
+ const wasStatus = entry.status;
33111
+ entry.turnId = turnId;
33112
+ if (resolution?.type === "hold") {
33113
+ entry.facts = facts;
33114
+ return { events, handled: true };
33115
+ }
33116
+ if (resolution?.type === "background") {
33117
+ entry.facts = resolution.role === void 0 ? facts : { ...facts, role: resolution.role };
33118
+ if (!entry.background) {
33119
+ events.push({
33120
+ type: "task.updated",
33121
+ ...turn,
33122
+ payload: {
33123
+ ...linkage(entry.taskId, call.toolCallId, entry.facts),
33124
+ status: "running",
33125
+ isBackgrounded: true
33126
+ }
33127
+ });
33128
+ }
33129
+ entry.background = true;
33130
+ entry.status = "running";
33131
+ if (resolution.agentRef !== void 0)
33132
+ rememberAgent(resolution.agentRef, entry.taskId, entry.facts);
33133
+ return { events, handled: true };
33134
+ }
33135
+ if (resolution?.type === "final") {
33136
+ const finalFacts = resolution.role === void 0 ? facts : { ...facts, role: resolution.role };
33137
+ const keepToolRow = resolution.keepToolRow === true;
33138
+ const base = linkage(entry.taskId, call.toolCallId, finalFacts);
33139
+ if (resolution.agentRef !== void 0)
33140
+ rememberAgent(resolution.agentRef, entry.taskId, finalFacts);
33141
+ calls.set(call.toolCallId, {
33142
+ sealed: true,
33143
+ keepToolRow,
33144
+ ...keepToolRow && (resolution.status === "completed" || resolution.status === "failed") ? { final: { status: resolution.status, summary: resolution.summary } } : {},
33145
+ turnId,
33146
+ kind,
33147
+ taskId: entry.taskId,
33148
+ facts: finalFacts
33149
+ });
33150
+ if (resolution.status === "completed" || resolution.status === "failed") {
33151
+ events.push({
33152
+ type: "task.completed",
33153
+ ...turn,
33154
+ payload: {
33155
+ ...base,
33156
+ status: resolution.status,
33157
+ ...resolution.summary === void 0 ? {} : { summary: resolution.summary }
33158
+ }
33159
+ });
33160
+ } else {
33161
+ events.push({
33162
+ type: "task.updated",
33163
+ ...turn,
33164
+ payload: {
33165
+ ...base,
33166
+ status: resolution.status,
33167
+ ...resolution.status === "idle" ? { outcomeUnknown: true } : {},
33168
+ ...resolution.description === void 0 ? {} : { description: resolution.description },
33169
+ ...resolution.timelineBypass === true ? { timelineBypass: true } : {}
33170
+ }
33171
+ });
33172
+ }
33173
+ return { events, handled: !keepToolRow, ...turn };
33174
+ }
33175
+ const status = call.status === "pending" && wasStatus !== "running" ? "pending" : "running";
33176
+ const changed = !seen && spec.announce === "progress" ? true : seen && (wasStatus !== status || !sameFacts(entry.facts, facts));
33177
+ entry.facts = facts;
33178
+ entry.status = status;
33179
+ if (changed) {
33180
+ events.push({
33181
+ type: "task.progress",
33182
+ ...turn,
33183
+ payload: {
33184
+ ...linkage(entry.taskId, call.toolCallId, facts),
33185
+ description: facts.description,
33186
+ ...facts.summary === void 0 ? {} : { summary: facts.summary },
33187
+ status
33188
+ }
33189
+ });
33190
+ }
33191
+ return { events, handled: true };
33192
+ };
33193
+ const settle2 = (settlement, turnId) => {
33194
+ const events = [];
33195
+ for (const [toolCallId, entry] of calls) {
33196
+ if (!isEntry(entry)) continue;
33197
+ if (settlement !== "session-ended" && turnId !== void 0 && entry.turnId !== void 0 && entry.turnId !== turnId) {
33198
+ continue;
33199
+ }
33200
+ const interrupted = settlement === "turn-interrupted";
33201
+ const ended = settlement === "session-ended" || interrupted && spec.interruptedMayStillRun !== true;
33202
+ if (!entry.announced) {
33203
+ if (ended) calls.set(toolCallId, sealedHidden(entry));
33204
+ else entry.phase = "idle";
33205
+ continue;
33206
+ }
33207
+ const base = linkage(entry.taskId, toolCallId, entry.facts);
33208
+ const turn = turnOf(entry.turnId);
33209
+ if (ended) {
33210
+ events.push({ type: "task.updated", ...turn, payload: { ...base, status: "cancelled" } });
33211
+ calls.set(toolCallId, sealedHidden(entry));
33212
+ continue;
33213
+ }
33214
+ if (entry.phase === "idle") continue;
33215
+ const note = spec.endNote({ interrupted, background: entry.background });
33216
+ events.push({
33217
+ type: "task.updated",
33218
+ ...turn,
33219
+ payload: {
33220
+ ...base,
33221
+ status: "idle",
33222
+ outcomeUnknown: true,
33223
+ description: note.description,
33224
+ ...note.timelineBypass === true ? { timelineBypass: true } : {}
33225
+ }
33226
+ });
33227
+ entry.phase = "idle";
33228
+ }
33229
+ return events;
33230
+ };
33231
+ const mayStillRun = () => {
33232
+ for (const entry of calls.values()) if (isEntry(entry)) return true;
33233
+ return false;
33234
+ };
33235
+ return { onToolCallUpdated, settle: settle2, mayStillRun };
33236
+ }
33237
+
32882
33238
  // ../../packages/ycodium-acp-executor/src/executor/prompt.ts
32883
33239
  function createExecutorPrompt({
32884
33240
  isLive,
@@ -32898,7 +33254,8 @@ function createExecutorPrompt({
32898
33254
  applyRequestedModel,
32899
33255
  notifyPromptSettled,
32900
33256
  shared,
32901
- promptResults
33257
+ promptResults,
33258
+ settleToolSubagents
32902
33259
  }) {
32903
33260
  const settleTurn = (input2) => {
32904
33261
  if (!isLive(input2.expectedGeneration) || input2.record.finished) {
@@ -32922,6 +33279,10 @@ function createExecutorPrompt({
32922
33279
  shared.status = "ready";
32923
33280
  }
32924
33281
  const interrupted = promptResults.hasInterrupted(input2.turnId);
33282
+ settleToolSubagents(
33283
+ toolSubagentSettlementOfTurn(interrupted ? "cancelled" : input2.state, input2.failureCategory),
33284
+ input2.turnId
33285
+ );
32925
33286
  emit({
32926
33287
  type: "turn.completed",
32927
33288
  ...stamp(),
@@ -33820,11 +34181,19 @@ function acpInitializePayload(clientInfo, overrides) {
33820
34181
  writeTextFile: false,
33821
34182
  ...overrides?.fs
33822
34183
  },
33823
- terminal: overrides?.terminal ?? false
34184
+ terminal: overrides?.terminal ?? false,
34185
+ ...overrides?.subagents === true ? { subagents: {} } : {}
33824
34186
  },
33825
34187
  clientInfo
33826
34188
  };
33827
34189
  }
34190
+ function acpCapabilityOverrides(input2) {
34191
+ const rest = {
34192
+ ...input2.clientCapabilities
34193
+ };
34194
+ delete rest.subagents;
34195
+ return input2.subagentSessions === true ? { ...rest, subagents: true } : rest;
34196
+ }
33828
34197
 
33829
34198
  // ../../packages/ycodium-acp-executor/src/refreshDeadline.ts
33830
34199
  var MODEL_CATALOG_REFRESH_TIMEOUT_MS = 9e4;
@@ -33906,6 +34275,20 @@ function createExecutorSession({
33906
34275
  failIfDisposed,
33907
34276
  shared
33908
34277
  }) {
34278
+ const requestSession = async (method, params) => {
34279
+ const knownSessionId = params["sessionId"];
34280
+ if (typeof knownSessionId === "string") shared.ownSessionIds.add(knownSessionId);
34281
+ shared.sessionOpensInFlight += 1;
34282
+ try {
34283
+ const result = await connection.request(method, params);
34284
+ const sessionId = result?.sessionId;
34285
+ if (typeof sessionId === "string" && sessionId.length > 0)
34286
+ shared.ownSessionIds.add(sessionId);
34287
+ return result;
34288
+ } finally {
34289
+ shared.sessionOpensInFlight -= 1;
34290
+ }
34291
+ };
33909
34292
  const openFreshSession = async (expectedGeneration) => {
33910
34293
  const initialized = shared.initializeResult;
33911
34294
  if (initialized === void 0) {
@@ -33916,7 +34299,7 @@ function createExecutorSession({
33916
34299
  initialized.agentCapabilities
33917
34300
  );
33918
34301
  const additionalDirectories = options.additionalDirectories !== void 0 && options.additionalDirectories.length > 0 ? { additionalDirectories: options.additionalDirectories } : {};
33919
- const created = await connection.request("session/new", {
34302
+ const created = await requestSession("session/new", {
33920
34303
  cwd: options.cwd,
33921
34304
  mcpServers,
33922
34305
  ...additionalDirectories
@@ -34033,7 +34416,13 @@ function createExecutorSession({
34033
34416
  return applyOnce(input2.state, input2.acpSessionId, input2.setup, false);
34034
34417
  };
34035
34418
  const startOnce = async (expectedGeneration) => {
34036
- const initializePayload = acpInitializePayload(options.clientInfo, options.clientCapabilities);
34419
+ const initializePayload = acpInitializePayload(
34420
+ options.clientInfo,
34421
+ acpCapabilityOverrides({
34422
+ clientCapabilities: options.clientCapabilities,
34423
+ subagentSessions: options.subagentSessions
34424
+ })
34425
+ );
34037
34426
  const initialized = await connection.request(
34038
34427
  "initialize",
34039
34428
  initializePayload
@@ -34057,7 +34446,7 @@ function createExecutorSession({
34057
34446
  let setup;
34058
34447
  let nextSessionId;
34059
34448
  if (options.resumeSessionId && options.resumeMethod === "session/resume") {
34060
- setup = await connection.request("session/resume", {
34449
+ setup = await requestSession("session/resume", {
34061
34450
  sessionId: options.resumeSessionId,
34062
34451
  cwd: options.cwd,
34063
34452
  mcpServers,
@@ -34067,7 +34456,7 @@ function createExecutorSession({
34067
34456
  } else if (options.resumeSessionId) {
34068
34457
  shared.sessionLoadInFlight = true;
34069
34458
  try {
34070
- setup = await connection.request("session/load", {
34459
+ setup = await requestSession("session/load", {
34071
34460
  sessionId: options.resumeSessionId,
34072
34461
  cwd: options.cwd,
34073
34462
  mcpServers,
@@ -34082,7 +34471,7 @@ function createExecutorSession({
34082
34471
  });
34083
34472
  nextSessionId = options.resumeSessionId;
34084
34473
  } else {
34085
- const created = await connection.request("session/new", {
34474
+ const created = await requestSession("session/new", {
34086
34475
  cwd: options.cwd,
34087
34476
  mcpServers,
34088
34477
  ...additionalDirectories
@@ -34267,6 +34656,127 @@ function createExecutorSettlement({
34267
34656
  return { rememberSettledPromptKey, abortPendingSettlement, settleFromNotification };
34268
34657
  }
34269
34658
 
34659
+ // ../../packages/ycodium-acp-executor/src/executor/subagent-sessions.ts
34660
+ function parseState(raw) {
34661
+ if (!isRecord(raw)) return { status: void 0, error: void 0 };
34662
+ const state = raw["state"];
34663
+ if (state === "running") return { status: "running", error: void 0 };
34664
+ if (state === "requires_action") return { status: "waiting", error: void 0 };
34665
+ if (state !== "idle") return { status: void 0, error: void 0 };
34666
+ const stopReason = raw["stopReason"];
34667
+ const error62 = isRecord(raw["error"]) ? asTrimmedString(raw["error"]["message"]) : void 0;
34668
+ if (stopReason === "error" || isRecord(raw["error"])) return { status: "failed", error: error62 };
34669
+ if (stopReason === "cancelled") return { status: "cancelled", error: void 0 };
34670
+ return { status: "idle", error: void 0 };
34671
+ }
34672
+ function childLinkage(childId, record2) {
34673
+ return {
34674
+ taskType: "subagent",
34675
+ rosterKind: "subagent",
34676
+ nativeSessionId: childId,
34677
+ timelineBypass: true,
34678
+ ...record2.title === void 0 ? {} : { title: record2.title }
34679
+ };
34680
+ }
34681
+ function createSubagentSessionTracker(registry2) {
34682
+ const observe = (notification, ctx) => {
34683
+ const update = notification.update;
34684
+ if (!isRecord(update) || update["sessionUpdate"] !== "subagent_update") return [];
34685
+ const childId = asTrimmedString(update["sessionId"]);
34686
+ if (childId === void 0 || ctx.ownSessionIds.has(childId)) return [];
34687
+ const outerId = notification.sessionId;
34688
+ const nested = registry2.has(outerId);
34689
+ if (ctx.foreign && !nested) return [];
34690
+ if (outerId === childId) return [];
34691
+ const title = asTrimmedString(update["title"]);
34692
+ const description = asTrimmedString(update["description"]);
34693
+ const state = parseState(update["state"]);
34694
+ let record2 = registry2.get(childId);
34695
+ if (record2 === void 0) {
34696
+ record2 = {
34697
+ turnId: ctx.turnId,
34698
+ title,
34699
+ description,
34700
+ parentAgentId: nested ? outerId : void 0,
34701
+ observed: state.status,
34702
+ reported: void 0,
34703
+ reportedError: void 0,
34704
+ // 重放里恢复的身份:宿主早有这一行,不再发 started。
34705
+ announced: ctx.silent,
34706
+ pendingMetadata: false
34707
+ };
34708
+ registry2.add(childId, record2);
34709
+ }
34710
+ record2.turnId ??= ctx.turnId;
34711
+ if (!ctx.silent) {
34712
+ if (title !== void 0 && title !== record2.title || description !== void 0 && description !== record2.description) {
34713
+ record2.pendingMetadata = true;
34714
+ }
34715
+ }
34716
+ if (title !== void 0) record2.title = title;
34717
+ if (description !== void 0) record2.description = description;
34718
+ if (state.status !== void 0) record2.observed = state.status;
34719
+ if (ctx.silent) return [];
34720
+ const linkage2 = childLinkage(childId, record2);
34721
+ const turn = record2.turnId === void 0 ? {} : { turnId: record2.turnId };
34722
+ const events = [];
34723
+ if (!record2.announced && state.status === void 0) return events;
34724
+ if (!record2.announced) {
34725
+ record2.announced = true;
34726
+ record2.pendingMetadata = false;
34727
+ events.push({
34728
+ type: "task.started",
34729
+ ...turn,
34730
+ payload: {
34731
+ taskId: childId,
34732
+ ...linkage2,
34733
+ ...record2.description === void 0 ? {} : { description: record2.description }
34734
+ }
34735
+ });
34736
+ }
34737
+ const statusChanged = state.status !== void 0 && (state.status !== record2.reported || record2.pendingMetadata || state.error !== void 0 && state.error !== record2.reportedError);
34738
+ if (statusChanged) {
34739
+ record2.pendingMetadata = false;
34740
+ record2.reported = state.status;
34741
+ record2.reportedError = state.status === "failed" ? state.error ?? record2.reportedError : void 0;
34742
+ events.push({
34743
+ type: "task.updated",
34744
+ ...turn,
34745
+ payload: {
34746
+ taskId: childId,
34747
+ status: state.status,
34748
+ ...state.error === void 0 ? {} : { error: state.error },
34749
+ ...record2.description === void 0 ? {} : { description: record2.description },
34750
+ ...linkage2
34751
+ }
34752
+ });
34753
+ }
34754
+ return events;
34755
+ };
34756
+ const settleSessionEnded = () => {
34757
+ const events = [];
34758
+ for (const [childId, record2] of registry2.entries()) {
34759
+ const last = record2.reported ?? record2.observed;
34760
+ if (!record2.announced || last !== "running" && last !== "waiting") continue;
34761
+ record2.reported = "idle";
34762
+ record2.observed = "idle";
34763
+ events.push({
34764
+ type: "task.updated",
34765
+ ...record2.turnId === void 0 ? {} : { turnId: record2.turnId },
34766
+ payload: {
34767
+ taskId: childId,
34768
+ status: "idle",
34769
+ outcomeUnknown: true,
34770
+ ...record2.description === void 0 ? {} : { description: record2.description },
34771
+ ...childLinkage(childId, record2)
34772
+ }
34773
+ });
34774
+ }
34775
+ return events;
34776
+ };
34777
+ return { observe, settleSessionEnded };
34778
+ }
34779
+
34270
34780
  // ../../packages/ycodium-acp-executor/src/executor/updates.ts
34271
34781
  var COMPACTION_SUMMARY_MAX_CHARS = 8e3;
34272
34782
  var SHOWN_TOOL_CALL_LIMIT = 256;
@@ -34285,6 +34795,8 @@ function createExecutorUpdates({
34285
34795
  shared
34286
34796
  }) {
34287
34797
  const shownToolCallIds = /* @__PURE__ */ new Set();
34798
+ const markChildSession = shared.childSessions.mark;
34799
+ const subagentSessions = options.subagentSessions === true ? createSubagentSessionTracker(shared.childSessions) : void 0;
34288
34800
  const emitCompactionState = (record2, state) => {
34289
34801
  const summary = record2.summary?.trim() ?? "";
34290
34802
  const truncated = summary.length > COMPACTION_SUMMARY_MAX_CHARS;
@@ -34370,6 +34882,30 @@ function createExecutorUpdates({
34370
34882
  return;
34371
34883
  }
34372
34884
  };
34885
+ const emitTaskEvents = (taskEvents) => {
34886
+ for (const taskEvent of taskEvents ?? []) {
34887
+ emit({
34888
+ type: taskEvent.type,
34889
+ ...stamp(),
34890
+ provider: options.provider,
34891
+ threadId: options.threadId,
34892
+ ...taskEvent.turnId !== void 0 ? { turnId: taskEvent.turnId } : {},
34893
+ payload: taskEvent.payload
34894
+ });
34895
+ }
34896
+ };
34897
+ const toolSubagents = hooks.toolSubagents === void 0 ? void 0 : createToolSubagentTracker(hooks.toolSubagents);
34898
+ const settleToolSubagents = (settlement, turnId) => emitTaskEvents(toolSubagents?.settle(settlement, turnId));
34899
+ const settleSessionEnded = () => {
34900
+ settleToolSubagents("session-ended");
34901
+ emitTaskEvents(subagentSessions?.settleSessionEnded());
34902
+ emitTaskEvents(hooks.onSessionEnded?.());
34903
+ };
34904
+ const observeContext = () => ({
34905
+ turnId: shared.activeTurnId,
34906
+ sessionId: shared.sessionId,
34907
+ markChildSession
34908
+ });
34373
34909
  const handleSessionUpdate = (params) => {
34374
34910
  const parsed = parseSessionUpdateEvent(params);
34375
34911
  if (parsed.modeId && shared.modeState) {
@@ -34396,43 +34932,39 @@ function createExecutorUpdates({
34396
34932
  rawTitle: params.update.title,
34397
34933
  nowMs
34398
34934
  });
34399
- const hookResult = hooks.onToolCallUpdated?.({
34935
+ const hasToolHooks = toolSubagents !== void 0 || hooks.onToolCallUpdated !== void 0;
34936
+ const call = !hasToolHooks ? void 0 : {
34400
34937
  toolCallId: nextToolCall.toolCallId,
34401
34938
  status: nextToolCall.status,
34402
34939
  title: nextToolCall.title,
34403
34940
  kind: nextToolCall.kind,
34404
34941
  rawInput: nextToolCall.data["rawInput"],
34405
34942
  rawOutput: nextToolCall.data["rawOutput"],
34943
+ contentText: nextToolCall.contentText,
34406
34944
  meta: params.update._meta,
34407
34945
  turnId: shared.activeTurnId
34408
- });
34409
- const taskEvents = hookResult === void 0 ? [] : "events" in hookResult ? hookResult.events : hookResult;
34946
+ };
34947
+ const hookResult = call === void 0 ? void 0 : toolSubagents?.onToolCallUpdated(call) ?? hooks.onToolCallUpdated?.(call);
34410
34948
  const handledByHook = hookResult !== void 0 && "events" in hookResult && hookResult.handled === true;
34411
- for (const taskEvent of taskEvents) {
34412
- emit({
34413
- type: taskEvent.type,
34414
- ...stamp(),
34415
- provider: options.provider,
34416
- threadId: options.threadId,
34417
- ...taskEvent.turnId !== void 0 ? { turnId: taskEvent.turnId } : {},
34418
- payload: taskEvent.payload
34419
- });
34420
- }
34949
+ emitTaskEvents(
34950
+ hookResult === void 0 ? [] : "events" in hookResult ? hookResult.events : hookResult
34951
+ );
34421
34952
  if (nextToolCall.status === "completed" && hookResult && "artifacts" in hookResult)
34422
34953
  emitArtifacts(hookResult.artifacts ?? [], nextToolCall.toolCallId);
34423
34954
  if (handledByHook || !decision.emit) {
34424
34955
  continue;
34425
34956
  }
34957
+ const toolTurnId = (hookResult !== void 0 && "events" in hookResult ? hookResult.turnId : void 0) ?? shared.activeTurnId;
34426
34958
  if (!shownToolCallIds.has(nextToolCall.toolCallId)) {
34427
34959
  rememberShownToolCall(nextToolCall.toolCallId);
34428
- closeActiveAssistantSegment(shared.activeTurnId);
34960
+ if (toolTurnId === shared.activeTurnId) closeActiveAssistantSegment(shared.activeTurnId);
34429
34961
  }
34430
34962
  emit(
34431
34963
  makeAcpToolCallEvent({
34432
34964
  stamp: stamp(),
34433
34965
  provider: options.provider,
34434
34966
  threadId: options.threadId,
34435
- turnId: shared.activeTurnId,
34967
+ turnId: toolTurnId,
34436
34968
  toolCall: nextToolCall,
34437
34969
  rawPayload: event.rawPayload
34438
34970
  })
@@ -34509,7 +35041,36 @@ function createExecutorUpdates({
34509
35041
  }
34510
35042
  }
34511
35043
  };
34512
- return { emitCompactionState, handleSessionUpdate };
35044
+ const receiveSessionUpdate = (params) => {
35045
+ const foreign = !shared.ownSessionIds.has(params.sessionId) && (shared.childSessions.has(params.sessionId) || shared.sessionOpensInFlight === 0 && shared.ownSessionIds.size > 0);
35046
+ emitTaskEvents(
35047
+ subagentSessions?.observe(params, {
35048
+ turnId: shared.activeTurnId,
35049
+ foreign,
35050
+ ownSessionIds: shared.ownSessionIds,
35051
+ silent: shared.sessionLoadInFlight
35052
+ })
35053
+ );
35054
+ if (!shared.sessionLoadInFlight) {
35055
+ if (hooks.onSessionUpdate) {
35056
+ emitTaskEvents(hooks.onSessionUpdate(params, { ...observeContext(), foreign }));
35057
+ }
35058
+ }
35059
+ if (!foreign) handleSessionUpdate(params);
35060
+ };
35061
+ const receiveExtensionNotification = (method, params) => {
35062
+ if (shared.sessionLoadInFlight || !hooks.onExtensionNotification) return;
35063
+ const result = hooks.onExtensionNotification(method, params, observeContext());
35064
+ if (Array.isArray(result)) emitTaskEvents(result);
35065
+ };
35066
+ return {
35067
+ emitCompactionState,
35068
+ receiveSessionUpdate,
35069
+ receiveExtensionNotification,
35070
+ settleToolSubagents,
35071
+ settleSessionEnded,
35072
+ toolSubagentsMayRun: () => toolSubagents?.mayStillRun() ?? false
35073
+ };
34513
35074
  }
34514
35075
 
34515
35076
  // ../../packages/ycodium-acp-executor/src/openCommands.ts
@@ -34658,7 +35219,10 @@ function createAcpExecutor(options) {
34658
35219
  abortLocalPrompt: void 0,
34659
35220
  connectionClosed: false,
34660
35221
  sessionLoadInFlight: false,
34661
- droppedReplayUpdates: 0
35222
+ droppedReplayUpdates: 0,
35223
+ ownSessionIds: /* @__PURE__ */ new Set(),
35224
+ childSessions: createChildSessionRegistry(),
35225
+ sessionOpensInFlight: 0
34662
35226
  };
34663
35227
  const interruptedTurnIds = /* @__PURE__ */ new Set();
34664
35228
  const approvals = createApprovalGate({
@@ -34688,7 +35252,14 @@ function createAcpExecutor(options) {
34688
35252
  promptMutex,
34689
35253
  shared
34690
35254
  });
34691
- const { emitCompactionState, handleSessionUpdate } = createExecutorUpdates({
35255
+ const {
35256
+ emitCompactionState,
35257
+ receiveSessionUpdate,
35258
+ receiveExtensionNotification,
35259
+ settleToolSubagents,
35260
+ settleSessionEnded,
35261
+ toolSubagentsMayRun
35262
+ } = createExecutorUpdates({
34692
35263
  emit,
34693
35264
  stamp,
34694
35265
  options,
@@ -34751,11 +35322,11 @@ function createAcpExecutor(options) {
34751
35322
  if (notification.method === "session/update") {
34752
35323
  const params = notification.params;
34753
35324
  const transformed = hooks.transformSessionUpdate ? hooks.transformSessionUpdate(params) : params;
34754
- if (transformed !== void 0) handleSessionUpdate(transformed);
35325
+ if (transformed !== void 0) receiveSessionUpdate(transformed);
34755
35326
  return;
34756
35327
  }
34757
35328
  if (settleFromNotification(notification.method, notification.params)) return;
34758
- void hooks.onExtensionNotification?.(notification.method, notification.params);
35329
+ receiveExtensionNotification(notification.method, notification.params);
34759
35330
  },
34760
35331
  onRequest: async (method, params) => {
34761
35332
  if (method === CLIENT_METHODS.session_request_permission) {
@@ -34811,6 +35382,7 @@ function createAcpExecutor(options) {
34811
35382
  });
34812
35383
  const { sendPromptRpc, prompt } = createExecutorPrompt({
34813
35384
  promptResults,
35385
+ settleToolSubagents,
34814
35386
  isLive,
34815
35387
  closeActiveAssistantSegment,
34816
35388
  emit,
@@ -34835,6 +35407,8 @@ function createAcpExecutor(options) {
34835
35407
  dispose: disposeLifecycle
34836
35408
  } = createExecutorLifecycle({
34837
35409
  promptResults,
35410
+ settleToolSubagents,
35411
+ settleSessionEnded,
34838
35412
  failIfDisposed,
34839
35413
  requireStarted,
34840
35414
  interruptedTurnIds,
@@ -34883,6 +35457,7 @@ function createAcpExecutor(options) {
34883
35457
  setNativeMode,
34884
35458
  compact,
34885
35459
  openToolCalls: () => readOpenToolCalls(toolCalls, shared.activeTurnId),
35460
+ toolSubagentsMayRun,
34886
35461
  dispose: (exitCode) => {
34887
35462
  disposeOnce ??= (async () => {
34888
35463
  try {
@@ -35085,7 +35660,13 @@ async function openAcpProbeHandshake(input2) {
35085
35660
  });
35086
35661
  try {
35087
35662
  const initializeResult = await withProbeTimeout(
35088
- connection.request("initialize", acpInitializePayload(input2.clientInfo)),
35663
+ connection.request(
35664
+ "initialize",
35665
+ acpInitializePayload(
35666
+ input2.clientInfo,
35667
+ acpCapabilityOverrides({ subagentSessions: input2.subagentSessions })
35668
+ )
35669
+ ),
35089
35670
  input2.requestTimeoutMs,
35090
35671
  "ACP probe request 'initialize'",
35091
35672
  input2.signal
@@ -35911,6 +36492,61 @@ function dshOpenCommands(session) {
35911
36492
  };
35912
36493
  }
35913
36494
 
36495
+ // src/subagents.ts
36496
+ var FALLBACK_TITLE = "DeepSeek Harness subagent";
36497
+ var TURN_ENDED_DESCRIPTION = "Turn ended. Individual agent status is unavailable.";
36498
+ var TURN_INTERRUPTED_DESCRIPTION = "Turn interrupted. The subagent may still be running in the background. Individual agent status is unavailable.";
36499
+ var FIELD_LIMIT = 200;
36500
+ var SUBAGENT_TITLES = /* @__PURE__ */ new Set(["subagent", "subagent_fork"]);
36501
+ var isRecord8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
36502
+ function field(rawInput, key) {
36503
+ if (!isRecord8(rawInput)) return void 0;
36504
+ const value = rawInput[key];
36505
+ if (typeof value !== "string") return void 0;
36506
+ const text = value.trim();
36507
+ return text === "" ? void 0 : text.slice(0, FIELD_LIMIT);
36508
+ }
36509
+ function factsOf(rawInput) {
36510
+ const role = field(rawInput, "agent_preset");
36511
+ const model = field(rawInput, "model");
36512
+ const effort = field(rawInput, "reasoning_effort");
36513
+ const title = field(rawInput, "description") ?? FALLBACK_TITLE;
36514
+ return {
36515
+ title,
36516
+ description: title,
36517
+ ...role === void 0 ? {} : { role },
36518
+ ...model === void 0 ? {} : { model },
36519
+ ...effort === void 0 ? {} : { effort },
36520
+ rosterKind: "subagent"
36521
+ };
36522
+ }
36523
+ var dshToolSubagents = {
36524
+ recognize: (call) => {
36525
+ if (call.kind !== void 0 && call.kind !== "other") return void 0;
36526
+ return call.title !== void 0 && SUBAGENT_TITLES.has(call.title) ? "subagent" : void 0;
36527
+ },
36528
+ // 身份在第一次见到时定下,之后合并进来的入参不改它。
36529
+ facts: (call, _kind, previous) => previous ?? factsOf(call.rawInput),
36530
+ announce: "progress",
36531
+ // 工具 completed 只说明子 agent 已启动,不是它跑完了:任务仍然开着。启动当场被拒的才有终态。
36532
+ resolve: (call) => {
36533
+ if (call.status !== "failed") return void 0;
36534
+ const reason = call.contentText;
36535
+ return {
36536
+ type: "final",
36537
+ status: "failed",
36538
+ // 失败的原因要留在可展开的工具行里。
36539
+ keepToolRow: true,
36540
+ ...reason === void 0 ? {} : { summary: reason }
36541
+ };
36542
+ },
36543
+ interruptedMayStillRun: true,
36544
+ endNote: ({ interrupted }) => ({
36545
+ description: interrupted ? TURN_INTERRUPTED_DESCRIPTION : TURN_ENDED_DESCRIPTION,
36546
+ timelineBypass: true
36547
+ })
36548
+ };
36549
+
35914
36550
  // src/dshInstance.ts
35915
36551
  var RESUME_SCHEMA_VERSION = 1;
35916
36552
  var yieldTick = () => new Promise((resolve3) => {
@@ -36079,7 +36715,11 @@ var createDshInstance = (config2, host) => {
36079
36715
  // 该 agent 不实现 session/load,只实现 session/resume——续接重新激活
36080
36716
  // 持久会话而不重放记录,发 load 会卡在永远不结算的重放门上。
36081
36717
  resumeMethod: "session/resume",
36082
- hooks: { permissionRequestKind: dshPermissionRequestKind },
36718
+ hooks: {
36719
+ permissionRequestKind: dshPermissionRequestKind,
36720
+ // `subagent` / `subagent_fork` 由执行器的子 agent 跟踪接管,不再画成普通工具。
36721
+ toolSubagents: dshToolSubagents
36722
+ },
36083
36723
  ...requestedModelId === void 0 ? {} : { requestedModelId },
36084
36724
  ...requestedEffort === void 0 ? {} : { requestedEffort },
36085
36725
  ...input2.bindingGeneration === void 0 ? {} : { originBindingGeneration: input2.bindingGeneration },
@@ -36090,9 +36730,7 @@ var createDshInstance = (config2, host) => {
36090
36730
  ...resume === void 0 ? {} : { resumeSessionId: resume.sessionId }
36091
36731
  });
36092
36732
  const forwarding = (async () => {
36093
- for await (const event of executor.events) {
36094
- events.push(event);
36095
- }
36733
+ for await (const event of executor.events) events.push(event);
36096
36734
  })();
36097
36735
  try {
36098
36736
  throwIfStartAborted(signal);
@@ -36173,6 +36811,10 @@ var createDshInstance = (config2, host) => {
36173
36811
  host.log.info("interrupt turn", { threadId, turnId });
36174
36812
  await booked.executor.cancel(turnId);
36175
36813
  await yieldTick();
36814
+ if (booked.executor.toolSubagentsMayRun()) {
36815
+ host.log.info("stop session to stop its subagents", { threadId });
36816
+ await stopSession(threadId);
36817
+ }
36176
36818
  },
36177
36819
  openCommandProcesses: async (threadId) => {
36178
36820
  const booked = threads.get(threadId);
@@ -36237,7 +36879,7 @@ var executors = [
36237
36879
  ];
36238
36880
  var index_default = definePlugin({
36239
36881
  id: "agent-dsh",
36240
- apiVersion: 47,
36882
+ apiVersion: 49,
36241
36883
  executors,
36242
36884
  activate(ctx) {
36243
36885
  ctx.log.info("dsh executor ready");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-dsh",
3
- "version": "0.2.3576",
3
+ "version": "0.2.3608",
4
4
  "description": "DeepSeek Harness executor: dsh CLI over Agent Client Protocol stdio.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -22,8 +22,8 @@
22
22
  "esbuild": "0.28.1",
23
23
  "vite-plus": "0.2.2",
24
24
  "yaml": "^2.9.0",
25
- "@ycodium-ai/plugin-api": "0.2.3576",
26
- "ycodium-acp-executor": "0.2.3576",
25
+ "@ycodium-ai/plugin-api": "0.2.3608",
26
+ "ycodium-acp-executor": "0.2.3608",
27
27
  "ycodium-executor-testing": "0.0.0"
28
28
  },
29
29
  "ycodium": {