minimal-agent 0.18.21 → 0.18.22

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 (127) hide show
  1. package/README.md +16 -3
  2. package/package.json +1 -1
  3. package/plugins/workflow-runner/plugin.js +1 -0
  4. package/plugins/workflow-runner/plugin.ts +1 -0
  5. package/plugins/workflow-runner/src/index.js +1 -0
  6. package/plugins/workflow-runner/src/index.ts +2 -0
  7. package/plugins/workflow-runner/src/runner.js +6 -1
  8. package/plugins/workflow-runner/src/runner.ts +5 -1
  9. package/plugins/workflow-runner/src/types.ts +1 -0
  10. package/plugins/workflow-runner/test/childWorkflow.test.ts +19 -0
  11. package/src/advisor/README.md +7 -3
  12. package/src/advisor/advisorNudge.js +3 -3
  13. package/src/advisor/advisorNudge.ts +3 -3
  14. package/src/advisor/deliveryReview.js +9 -2
  15. package/src/advisor/deliveryReview.ts +10 -2
  16. package/src/cli/args.js +1 -0
  17. package/src/cli/args.ts +1 -0
  18. package/src/cli/headlessTurn.js +143 -0
  19. package/src/cli/headlessTurn.ts +187 -0
  20. package/src/cli/lifecycle.js +52 -0
  21. package/src/cli/lifecycle.ts +59 -0
  22. package/src/cli/print.js +91 -240
  23. package/src/cli/print.ts +99 -301
  24. package/src/cli/quickModelSetup.js +3 -0
  25. package/src/cli/quickModelSetup.tsx +3 -0
  26. package/src/cli/streamJson.js +244 -334
  27. package/src/cli/streamJson.ts +248 -416
  28. package/src/cli/wizards/providerPresets.js +25 -14
  29. package/src/cli/wizards/providerPresets.ts +25 -14
  30. package/src/cli/wizards/providerWizard.js +29 -11
  31. package/src/cli/wizards/providerWizard.tsx +29 -11
  32. package/src/config/configDiagnostics.js +7 -3
  33. package/src/config/configDiagnostics.ts +6 -3
  34. package/src/context/compact.js +40 -10
  35. package/src/context/compact.ts +51 -12
  36. package/src/context/compactResources.js +39 -0
  37. package/src/context/compactResources.ts +35 -0
  38. package/src/context/manualCompact.js +20 -0
  39. package/src/context/manualCompact.ts +28 -0
  40. package/src/llm/client.js +4 -0
  41. package/src/llm/client.ts +4 -0
  42. package/src/llm/messageProvenance.js +1 -1
  43. package/src/llm/messageProvenance.ts +1 -1
  44. package/src/loop/deliveryIntent.js +3 -2
  45. package/src/loop/deliveryIntent.ts +4 -2
  46. package/src/loop/messages.js +1 -0
  47. package/src/loop/messages.ts +1 -0
  48. package/src/loop/options.ts +2 -0
  49. package/src/loop.js +4 -2
  50. package/src/loop.ts +4 -2
  51. package/src/main.js +40 -45
  52. package/src/main.tsx +33 -52
  53. package/src/plugins/artifactDelivery.js +76 -0
  54. package/src/plugins/artifactDelivery.ts +76 -0
  55. package/src/plugins/pluginApi.ts +2 -0
  56. package/src/plugins/pluginRunner.js +2 -0
  57. package/src/plugins/pluginRunner.ts +3 -0
  58. package/src/prompts/delegation.js +1 -1
  59. package/src/prompts/delegation.ts +1 -1
  60. package/src/prompts/policyRegistry.js +7 -6
  61. package/src/prompts/policyRegistry.ts +7 -6
  62. package/src/prompts/promptAssembly.js +2 -2
  63. package/src/prompts/promptAssembly.ts +2 -2
  64. package/src/runtime/requestIntent.js +86 -0
  65. package/src/runtime/requestIntent.ts +66 -0
  66. package/src/runtime/systemEvents.js +10 -1
  67. package/src/runtime/systemEvents.ts +9 -1
  68. package/src/session/commandTranscript.js +76 -0
  69. package/src/session/commandTranscript.ts +77 -0
  70. package/src/session/runTurn.js +24 -3
  71. package/src/session/runTurn.ts +24 -3
  72. package/src/tools/advisor/advisor.js +1 -1
  73. package/src/tools/advisor/advisor.ts +1 -1
  74. package/src/tools/advisor/advisorCoordination.js +3 -2
  75. package/src/tools/advisor/advisorCoordination.ts +3 -2
  76. package/src/tools/advisor/advisorDescription.js +1 -1
  77. package/src/tools/advisor/advisorDescription.ts +1 -1
  78. package/src/tools/agent/README.md +2 -0
  79. package/src/tools/agent/agent.js +3 -0
  80. package/src/tools/agent/agent.ts +3 -0
  81. package/src/tools/agent/agentHandoff.js +2 -1
  82. package/src/tools/agent/agentHandoff.ts +2 -1
  83. package/src/tools/agent/agentTaskService.js +26 -5
  84. package/src/tools/agent/agentTaskService.ts +23 -5
  85. package/src/tools/agent/agentTypes.js +1 -1
  86. package/src/tools/agent/agentTypes.ts +1 -1
  87. package/src/tools/applypatch/applyPatch.js +39 -13
  88. package/src/tools/applypatch/applyPatch.ts +35 -15
  89. package/src/tools/bash/bash.js +3 -0
  90. package/src/tools/bash/bash.ts +3 -0
  91. package/src/tools/download/download.js +147 -11
  92. package/src/tools/download/download.ts +193 -17
  93. package/src/tools/edit/edit.js +4 -4
  94. package/src/tools/edit/edit.ts +4 -4
  95. package/src/tools/edit/multi-edit.js +2 -2
  96. package/src/tools/edit/multi-edit.ts +2 -2
  97. package/src/tools/powershell/powershell.js +2 -0
  98. package/src/tools/powershell/powershell.ts +2 -0
  99. package/src/tools/shared/fileUtils.js +16 -6
  100. package/src/tools/shared/fileUtils.ts +15 -6
  101. package/src/tools/tasks/backgroundTaskService.js +108 -12
  102. package/src/tools/tasks/backgroundTaskService.ts +106 -14
  103. package/src/tools/tasks/taskOutput.js +15 -5
  104. package/src/tools/tasks/taskOutput.ts +13 -5
  105. package/src/tools/tasks/taskStop.js +2 -2
  106. package/src/tools/tasks/taskStop.ts +2 -2
  107. package/src/tools/toolPromptGuides.js +3 -3
  108. package/src/tools/toolPromptGuides.ts +3 -3
  109. package/src/tools/webfetch/webfetch.js +1 -1
  110. package/src/tools/webfetch/webfetch.ts +1 -1
  111. package/src/types.ts +4 -0
  112. package/src/ui/InputBox.js +2 -2
  113. package/src/ui/InputBox.tsx +2 -2
  114. package/src/ui/MessageList.js +2 -0
  115. package/src/ui/MessageList.tsx +2 -0
  116. package/src/ui/README.md +8 -2
  117. package/src/ui/activityPresentation.js +22 -2
  118. package/src/ui/activityPresentation.ts +21 -2
  119. package/src/ui/backgroundWake.js +20 -4
  120. package/src/ui/backgroundWake.ts +19 -4
  121. package/src/ui/commandTranscript.js +2 -69
  122. package/src/ui/commandTranscript.ts +2 -71
  123. package/src/ui/hooks/useChat.js +41 -25
  124. package/src/ui/hooks/useChat.ts +30 -23
  125. package/src/web/protocol.ts +3 -2
  126. package/src/cli/wizards/advisorWizard.js +0 -152
  127. package/src/cli/wizards/advisorWizard.tsx +0 -203
@@ -3,8 +3,17 @@ export const BACKGROUND_WAKE_MARKER = '[系统事件 · 不是用户输入]';
3
3
  export function isSystemEventMessage(message) {
4
4
  if (message.role !== 'user')
5
5
  return false;
6
+ if (message.inputOrigin)
7
+ return true;
6
8
  if (/^(?:agent-notice:|proc-notice:|proc-wake:)/.test(message.id ?? ''))
7
9
  return true;
8
10
  // Compatibility for wake stubs persisted before IDs were tagged.
9
- return typeof message.content === 'string' && message.content.startsWith(BACKGROUND_WAKE_MARKER);
11
+ const text = typeof message.content === 'string' ? message.content
12
+ : message.content.find(part => part.type === 'text')?.text ?? '';
13
+ return [BACKGROUND_WAKE_MARKER, 'This session is being continued from a previous conversation',
14
+ '(自动压缩失败:', '(LLM 摘要压缩失败,已使用规则式截断继续会话)',
15
+ '(LLM 返回了无效摘要,已使用规则式截断继续会话)',
16
+ '【实况图像】上面是刚才工具执行后附带的真实图像',
17
+ '【实况图像】(此前的实况图像已从上下文移除以节省空间。)',
18
+ ].some(prefix => text.startsWith(prefix));
10
19
  }
@@ -5,7 +5,15 @@ export const BACKGROUND_WAKE_MARKER = '[系统事件 · 不是用户输入]';
5
5
  /** Host events use stable IDs, not a provider role pretending to be a human. */
6
6
  export function isSystemEventMessage(message: Message): boolean {
7
7
  if (message.role !== 'user') return false;
8
+ if (message.inputOrigin) return true;
8
9
  if (/^(?:agent-notice:|proc-notice:|proc-wake:)/.test(message.id ?? '')) return true;
9
10
  // Compatibility for wake stubs persisted before IDs were tagged.
10
- return typeof message.content === 'string' && message.content.startsWith(BACKGROUND_WAKE_MARKER);
11
+ const text = typeof message.content === 'string' ? message.content
12
+ : message.content.find(part => part.type === 'text')?.text ?? '';
13
+ return [BACKGROUND_WAKE_MARKER, 'This session is being continued from a previous conversation',
14
+ '(自动压缩失败:', '(LLM 摘要压缩失败,已使用规则式截断继续会话)',
15
+ '(LLM 返回了无效摘要,已使用规则式截断继续会话)',
16
+ '【实况图像】上面是刚才工具执行后附带的真实图像',
17
+ '【实况图像】(此前的实况图像已从上下文移除以节省空间。)',
18
+ ].some(prefix => text.startsWith(prefix));
11
19
  }
@@ -0,0 +1,76 @@
1
+ import { createPublicTextStream } from '../ui/publicText.js';
2
+ /** A slash command can expand into a different model input, or never call the
3
+ * model at all. Keep the UI transcript independent of that routing decision. */
4
+ export function commandRequest(input, userMessageId) {
5
+ return { role: 'system', _ephemeral: true, _uiProgress: true,
6
+ id: `command:${userMessageId}`, timestamp: Date.now(), content: input,
7
+ commandDisplay: { kind: 'request', userMessageId } };
8
+ }
9
+ /** Some deterministic plugins emit only text + turn_done. Model turns and
10
+ * workflows own their own drafts, echoes, and committed history. Never promote
11
+ * their preview (including a replayed echo) into a second or invented answer. */
12
+ export function captureCommandReply(userMessageId) {
13
+ const stream = createPublicTextStream();
14
+ const chunks = [];
15
+ let standalone = true;
16
+ let resultNumber = 0;
17
+ const result = (content) => ({
18
+ role: 'system', _ephemeral: true, _uiProgress: true,
19
+ id: `command:${userMessageId}:result:${++resultNumber}`, timestamp: Date.now(), content,
20
+ commandDisplay: { kind: 'result' },
21
+ });
22
+ return (event) => {
23
+ if (event.type === 'text' && event.commandResult === true && typeof event.delta === 'string') {
24
+ standalone = false;
25
+ chunks.length = 0;
26
+ stream.reset();
27
+ const content = stream.append(event.delta) + stream.finish();
28
+ return content.trim() ? result(content) : undefined;
29
+ }
30
+ if (!standalone)
31
+ return;
32
+ switch (event.type) {
33
+ case 'text':
34
+ if (typeof event.delta === 'string')
35
+ chunks.push(stream.append(event.delta));
36
+ return;
37
+ case 'plugin_progress':
38
+ case 'warning':
39
+ return;
40
+ case 'turn_done': {
41
+ standalone = false;
42
+ const content = chunks.join('') + stream.finish();
43
+ if (!content.trim() || event.completionStatus === 'no_answer')
44
+ return;
45
+ return result(content);
46
+ }
47
+ default:
48
+ standalone = false;
49
+ chunks.length = 0;
50
+ stream.reset();
51
+ }
52
+ };
53
+ }
54
+ /** Display projection shared by hosts. Never mutate the model's actual input. */
55
+ export function transcriptRows(history) {
56
+ const ids = new Set();
57
+ const users = new Map();
58
+ for (const m of history) {
59
+ if (m.role === 'user' && m.id)
60
+ users.set(m.id, m);
61
+ if (m.role === 'system' && m._ephemeral && m.commandDisplay?.kind === 'request')
62
+ ids.add(m.commandDisplay.userMessageId);
63
+ }
64
+ if (!ids.size)
65
+ return history;
66
+ return history.flatMap((m) => {
67
+ if (m.role === 'user' && m.id && ids.has(m.id))
68
+ return [];
69
+ if (m.role === 'system' && m._ephemeral && m.commandDisplay?.kind === 'request') {
70
+ const requestId = m.commandDisplay.userMessageId;
71
+ const original = users.get(requestId);
72
+ return [{ ...original, role: 'user', content: m.content, timestamp: m.timestamp, id: requestId }];
73
+ }
74
+ return [m];
75
+ });
76
+ }
@@ -0,0 +1,77 @@
1
+ import type { PluginEvent } from '../plugins/pluginApi.js';
2
+ import type { LoopEvent, Message } from '../types.js';
3
+ import { createPublicTextStream } from '../ui/publicText.js';
4
+
5
+ type LocalRow = Extract<Message, { role: 'system' }>;
6
+
7
+ /** A slash command can expand into a different model input, or never call the
8
+ * model at all. Keep the UI transcript independent of that routing decision. */
9
+ export function commandRequest(input: string, userMessageId: string): LocalRow {
10
+ return { role: 'system', _ephemeral: true, _uiProgress: true,
11
+ id: `command:${userMessageId}`, timestamp: Date.now(), content: input,
12
+ commandDisplay: { kind: 'request', userMessageId } };
13
+ }
14
+
15
+ /** Some deterministic plugins emit only text + turn_done. Model turns and
16
+ * workflows own their own drafts, echoes, and committed history. Never promote
17
+ * their preview (including a replayed echo) into a second or invented answer. */
18
+ export function captureCommandReply(userMessageId: string) {
19
+ const stream = createPublicTextStream();
20
+ const chunks: string[] = [];
21
+ let standalone = true;
22
+ let resultNumber = 0;
23
+ const result = (content: string): LocalRow => ({
24
+ role: 'system', _ephemeral: true, _uiProgress: true,
25
+ id: `command:${userMessageId}:result:${++resultNumber}`, timestamp: Date.now(), content,
26
+ commandDisplay: { kind: 'result' },
27
+ });
28
+ return (event: LoopEvent | PluginEvent): LocalRow | undefined => {
29
+ if (event.type === 'text' && event.commandResult === true && typeof event.delta === 'string') {
30
+ standalone = false;
31
+ chunks.length = 0;
32
+ stream.reset();
33
+ const content = stream.append(event.delta) + stream.finish();
34
+ return content.trim() ? result(content) : undefined;
35
+ }
36
+ if (!standalone) return;
37
+ switch (event.type) {
38
+ case 'text':
39
+ if (typeof event.delta === 'string') chunks.push(stream.append(event.delta));
40
+ return;
41
+ case 'plugin_progress':
42
+ case 'warning':
43
+ return;
44
+ case 'turn_done': {
45
+ standalone = false;
46
+ const content = chunks.join('') + stream.finish();
47
+ if (!content.trim() || event.completionStatus === 'no_answer') return;
48
+ return result(content);
49
+ }
50
+ default:
51
+ standalone = false;
52
+ chunks.length = 0;
53
+ stream.reset();
54
+ }
55
+ };
56
+ }
57
+
58
+ /** Display projection shared by hosts. Never mutate the model's actual input. */
59
+ export function transcriptRows(history: Message[]): Message[] {
60
+ const ids = new Set<string>();
61
+ const users = new Map<string, Extract<Message, { role: 'user' }>>();
62
+ for (const m of history) {
63
+ if (m.role === 'user' && m.id) users.set(m.id, m);
64
+ if (m.role === 'system' && m._ephemeral && m.commandDisplay?.kind === 'request')
65
+ ids.add(m.commandDisplay.userMessageId);
66
+ }
67
+ if (!ids.size) return history;
68
+ return history.flatMap((m): Message[] => {
69
+ if (m.role === 'user' && m.id && ids.has(m.id)) return [];
70
+ if (m.role === 'system' && m._ephemeral && m.commandDisplay?.kind === 'request') {
71
+ const requestId = m.commandDisplay.userMessageId;
72
+ const original = users.get(requestId);
73
+ return [{ ...original, role: 'user', content: m.content, timestamp: m.timestamp, id: requestId }];
74
+ }
75
+ return [m];
76
+ });
77
+ }
@@ -24,6 +24,7 @@ import { loadContext, saveContext } from '../context/persistContext.js';
24
24
  import { startTurnJournal } from '../memory/turnJournal.js';
25
25
  import { createLearningModel } from '../memory/learningModel.js';
26
26
  import { runWithPlugins } from '../plugins/pluginRunner.js';
27
+ import { captureCommandReply, commandRequest } from './commandTranscript.js';
27
28
  import { upsertStableSystemMessage } from '../prompts/stableSystemPrompt.js';
28
29
  /**
29
30
  * 已有历史时,用调用方新算好的 systemPrompt(含当前日期/实时扫描的 skills·plugins 清单/
@@ -56,13 +57,20 @@ export async function* runTurn(opts) {
56
57
  yield* runLockedTurn(opts, persist);
57
58
  }
58
59
  finally {
59
- await release();
60
+ try {
61
+ await opts.cleanup?.();
62
+ }
63
+ finally {
64
+ await release();
65
+ }
60
66
  }
61
67
  }
62
68
  /** Initialization is also inside the lock lifetime; failures must not strand it. */
63
69
  async function* runLockedTurn(opts, persist) {
64
70
  const loaded = opts.initialHistory ?? (persist ? await loadContext(opts.sessionFile) : null);
65
71
  const history = buildInitialHistory(loaded, opts.systemPrompt);
72
+ if (opts.prepare)
73
+ opts = { ...opts, ...await opts.prepare(history) };
66
74
  const historyStart = history.length;
67
75
  const userMessageId = opts.userMessageId ?? crypto.randomUUID();
68
76
  // 会话原文记账:实现在 src/memory/turnJournal.ts(TUI 的 useChat 用同一份),
@@ -83,6 +91,14 @@ async function* runLockedTurn(opts, persist) {
83
91
  const trace = createLifecycleTrace('host');
84
92
  let hostFailed = false;
85
93
  try {
94
+ const commandReply = opts.userInput.trim().startsWith('/') ? captureCommandReply(userMessageId) : null;
95
+ if (commandReply) {
96
+ const request = commandRequest(opts.userInput, userMessageId);
97
+ history.push(request);
98
+ if (persist)
99
+ await saveContext(history, opts.sessionFile, { strict: opts.strictPersistence });
100
+ yield { type: 'injected_message', message: request };
101
+ }
86
102
  for await (const event of runWithPlugins(opts.userInput, {
87
103
  executionId: opts.executionId,
88
104
  provider: opts.provider,
@@ -116,13 +132,18 @@ async function* runLockedTurn(opts, persist) {
116
132
  memoryContext: opts.memoryContext,
117
133
  })) {
118
134
  journal?.observe(event);
135
+ const commandResult = commandReply?.(event);
136
+ if (commandResult) {
137
+ history.push(commandResult);
138
+ yield { type: 'injected_message', message: commandResult };
139
+ }
119
140
  // Stage records are user-visible history, not model instructions. Checkpoint
120
141
  // at stage boundaries so a Runtime restart does not lose the whole workflow.
121
142
  if (persist && (['user_message_committed', 'assistant_message', 'compact_start', 'turn_done'].includes(event.type)
122
143
  || (event.type === 'injected_message' && event.message && typeof event.message === 'object' && 'role' in event.message && event.message.role === 'system' && '_uiProgress' in event.message && event.message._uiProgress === true))) {
123
144
  trace('save_start');
124
145
  try {
125
- await saveContext(history, opts.sessionFile);
146
+ await saveContext(history, opts.sessionFile, { strict: opts.strictPersistence });
126
147
  trace('save_end');
127
148
  }
128
149
  catch (error) {
@@ -152,6 +173,6 @@ async function* runLockedTurn(opts, persist) {
152
173
  });
153
174
  trace('memory_end');
154
175
  if (persist)
155
- await saveContext(history, opts.sessionFile);
176
+ await saveContext(history, opts.sessionFile, { strict: opts.strictPersistence });
156
177
  }
157
178
  }
@@ -26,6 +26,7 @@ import { startTurnJournal } from '../memory/turnJournal.js';
26
26
  import { createLearningModel } from '../memory/learningModel.js';
27
27
  import type { PluginEvent } from '../plugins/pluginApi.js';
28
28
  import { runWithPlugins } from '../plugins/pluginRunner.js';
29
+ import { captureCommandReply, commandRequest } from './commandTranscript.js';
29
30
  import { upsertStableSystemMessage } from '../prompts/stableSystemPrompt.js';
30
31
  import type {
31
32
  ImageDetail,
@@ -87,6 +88,13 @@ export interface RunTurnOptions {
87
88
  initialHistory?: Message[];
88
89
  /** Defaults to true. False avoids reading, locking, or writing sessionFile. */
89
90
  persist?: boolean;
91
+ /** Host setup runs after loading history under the session lock. */
92
+ prepare?: (history: Message[]) => Promise<Pick<RunTurnOptions,
93
+ 'runtimeContext' | 'allowedTools' | 'sessionState' | 'transientBundle' |
94
+ 'promptCache' | 'memoryContext' | 'computerRun'>>;
95
+ /** Release turn-owned resources before releasing the session lock. */
96
+ cleanup?: () => Promise<void>;
97
+ strictPersistence?: boolean;
90
98
  }
91
99
 
92
100
  /**
@@ -124,7 +132,7 @@ export async function* runTurn(
124
132
  try {
125
133
  yield* runLockedTurn(opts, persist);
126
134
  } finally {
127
- await release();
135
+ try { await opts.cleanup?.(); } finally { await release(); }
128
136
  }
129
137
  }
130
138
 
@@ -132,6 +140,7 @@ export async function* runTurn(
132
140
  async function* runLockedTurn(opts: RunTurnOptions, persist: boolean): AsyncGenerator<LoopEvent | PluginEvent, void, void> {
133
141
  const loaded = opts.initialHistory ?? (persist ? await loadContext(opts.sessionFile) : null);
134
142
  const history: Message[] = buildInitialHistory(loaded, opts.systemPrompt);
143
+ if (opts.prepare) opts = { ...opts, ...await opts.prepare(history) };
135
144
  const historyStart = history.length;
136
145
  const userMessageId = opts.userMessageId ?? crypto.randomUUID();
137
146
  // 会话原文记账:实现在 src/memory/turnJournal.ts(TUI 的 useChat 用同一份),
@@ -153,6 +162,13 @@ async function* runLockedTurn(opts: RunTurnOptions, persist: boolean): AsyncGene
153
162
  const trace = createLifecycleTrace('host');
154
163
  let hostFailed = false;
155
164
  try {
165
+ const commandReply = opts.userInput.trim().startsWith('/') ? captureCommandReply(userMessageId) : null;
166
+ if (commandReply) {
167
+ const request = commandRequest(opts.userInput, userMessageId);
168
+ history.push(request);
169
+ if (persist) await saveContext(history, opts.sessionFile, { strict: opts.strictPersistence });
170
+ yield { type: 'injected_message', message: request };
171
+ }
156
172
  for await (const event of runWithPlugins(opts.userInput, {
157
173
  executionId: opts.executionId,
158
174
  provider: opts.provider,
@@ -186,13 +202,18 @@ async function* runLockedTurn(opts: RunTurnOptions, persist: boolean): AsyncGene
186
202
  memoryContext: opts.memoryContext,
187
203
  })) {
188
204
  journal?.observe(event);
205
+ const commandResult = commandReply?.(event);
206
+ if (commandResult) {
207
+ history.push(commandResult);
208
+ yield { type: 'injected_message', message: commandResult };
209
+ }
189
210
  // Stage records are user-visible history, not model instructions. Checkpoint
190
211
  // at stage boundaries so a Runtime restart does not lose the whole workflow.
191
212
  if (persist && (['user_message_committed', 'assistant_message', 'compact_start', 'turn_done'].includes(event.type)
192
213
  || (event.type === 'injected_message' && event.message && typeof event.message === 'object' && 'role' in event.message && event.message.role === 'system' && '_uiProgress' in event.message && event.message._uiProgress === true))) {
193
214
  trace('save_start');
194
215
  try {
195
- await saveContext(history, opts.sessionFile);
216
+ await saveContext(history, opts.sessionFile, { strict: opts.strictPersistence });
196
217
  trace('save_end');
197
218
  } catch (error) {
198
219
  trace('save_error');
@@ -216,6 +237,6 @@ async function* runLockedTurn(opts: RunTurnOptions, persist: boolean): AsyncGene
216
237
  process.stderr.write(`[minimal-agent memory] 本轮记忆收尾失败,不影响会话落盘:${(error as Error).message}\n`);
217
238
  });
218
239
  trace('memory_end');
219
- if (persist) await saveContext(history, opts.sessionFile);
240
+ if (persist) await saveContext(history, opts.sessionFile, { strict: opts.strictPersistence });
220
241
  }
221
242
  }
@@ -40,7 +40,7 @@ import { DEFAULT_MAX_RESULT_SIZE_CHARS } from '../types.js';
40
40
  import { ADVISOR_TOOL_DESCRIPTION } from './advisorDescription.js';
41
41
  // ---------------- 1. Zod 输入 schema ----------------
42
42
  const inputSchema = z.object({
43
- purpose: z.enum(['independent', 'synthesis']).optional().describe('independent(默认)独立第二意见,可与子任务并行;synthesis 汇总验收,先核实依赖子任务。'),
43
+ purpose: z.enum(['independent', 'synthesis']).optional().describe('默认按当前交付做 synthesis,先核实依赖子任务;independent 须显式选择,仅用于已有证据上的独立问题,不依赖未返回报告。'),
44
44
  depends_on: z.array(z.string().regex(/^agent_[0-9a-f-]{36}$/i)).max(32).optional().describe('本次咨询依赖的子任务 ID;须先获取报告并由主 Agent 验收。未就绪返回暂缓,不占用顾问请求。synthesis 未指定时检查当前交付的必要任务。'),
45
45
  reviewMode: z.enum(['brief', 'full']).optional().describe('默认 brief 为重点第二意见;用户要求完整代码审查时用 full,并在 note 中说明变更审查/全项目审计、基线和覆盖范围。full 不扩大证据或输出预算,缺失时须报告未完成。'),
46
46
  note: z
@@ -49,7 +49,7 @@ import { ADVISOR_TOOL_DESCRIPTION } from './advisorDescription.js';
49
49
 
50
50
  // ---------------- 1. Zod 输入 schema ----------------
51
51
  const inputSchema = z.object({
52
- purpose: z.enum(['independent', 'synthesis']).optional().describe('independent(默认)独立第二意见,可与子任务并行;synthesis 汇总验收,先核实依赖子任务。'),
52
+ purpose: z.enum(['independent', 'synthesis']).optional().describe('默认按当前交付做 synthesis,先核实依赖子任务;independent 须显式选择,仅用于已有证据上的独立问题,不依赖未返回报告。'),
53
53
  depends_on: z.array(z.string().regex(/^agent_[0-9a-f-]{36}$/i)).max(32).optional().describe('本次咨询依赖的子任务 ID;须先获取报告并由主 Agent 验收。未就绪返回暂缓,不占用顾问请求。synthesis 未指定时检查当前交付的必要任务。'),
54
54
  reviewMode: z.enum(['brief', 'full']).optional().describe('默认 brief 为重点第二意见;用户要求完整代码审查时用 full,并在 note 中说明变更审查/全项目审计、基线和覆盖范围。full 不扩大证据或输出预算,缺失时须报告未完成。'),
55
55
  note: z
@@ -1,10 +1,11 @@
1
1
  import { belongsToDelivery } from '../../runtime/deliveryGate.js';
2
2
  import { agentNeedsResolution, dependencyReceipt, readAgentLedgerStrict } from '../agent/agentTaskService.js';
3
3
  /** Consultation is not delivery: independent criticism can run in parallel.
4
- * Only an explicitly dependent/synthesis request waits for accepted handoffs.
4
+ * Default to the current delivery's dependencies; early independent criticism
5
+ * is an explicit choice, never an accidental bypass of unfinished handoffs.
5
6
  * Return control to the parent instead of blocking a tool while tasks need help. */
6
7
  export async function advisorCoordination(input, ctx) {
7
- const synthesis = input.purpose === 'synthesis';
8
+ const synthesis = input.purpose === 'synthesis' || (input.purpose === undefined && Boolean(ctx?.deliveryId));
8
9
  const ids = [...new Set(input.depends_on ?? [])];
9
10
  if (!synthesis && !ids.length) {
10
11
  const running = [...(ctx?.sessionState?.agentTasks.tasks.values() ?? [])]
@@ -3,13 +3,14 @@ import { belongsToDelivery } from '../../runtime/deliveryGate.js';
3
3
  import { agentNeedsResolution, dependencyReceipt, readAgentLedgerStrict } from '../agent/agentTaskService.js';
4
4
 
5
5
  /** Consultation is not delivery: independent criticism can run in parallel.
6
- * Only an explicitly dependent/synthesis request waits for accepted handoffs.
6
+ * Default to the current delivery's dependencies; early independent criticism
7
+ * is an explicit choice, never an accidental bypass of unfinished handoffs.
7
8
  * Return control to the parent instead of blocking a tool while tasks need help. */
8
9
  export async function advisorCoordination(
9
10
  input: { purpose?: 'independent' | 'synthesis'; depends_on?: string[] },
10
11
  ctx?: ToolCallContext,
11
12
  ): Promise<ToolResult> {
12
- const synthesis = input.purpose === 'synthesis';
13
+ const synthesis = input.purpose === 'synthesis' || (input.purpose === undefined && Boolean(ctx?.deliveryId));
13
14
  const ids = [...new Set(input.depends_on ?? [])];
14
15
  if (!synthesis && !ids.length) {
15
16
  const running = [...(ctx?.sessionState?.agentTasks.tasks.values() ?? [])]
@@ -2,4 +2,4 @@
2
2
  * 发给模型的 Advisor 工具描述(唯一一份)。
3
3
  * 咨询时机、采纳规则住在 policyRegistry 的 capability.advisor;这里只讲工具本身的契约,避免两处各写一遍。
4
4
  */
5
- export const ADVISOR_TOOL_DESCRIPTION = '向顾问模型请求第二意见;容量由顾问模型上下文窗口和最大输出配置决定,没有独立输入配额。purpose=independent 可与后台子任务并行,明确尚未收齐的材料;purpose=synthesis 汇总当前交付的必要任务,或用 depends_on 指定依赖,先获取并验收报告再咨询。未就绪会暂缓,不发模型请求。允许时只读核实工作区文件(不能运行命令或测试)。默认 reviewMode=brief 给重点短评;完整代码审查用 full,note 写范围、基线、证据和待挑战的问题;full 不扩大模型窗口,材料不足须说明未完成。';
5
+ export const ADVISOR_TOOL_DESCRIPTION = '向顾问模型请求第二意见;容量由顾问模型上下文窗口和最大输出配置决定,没有独立输入配额。默认按当前交付做 synthesis,先获取并验收必要子任务报告,或用 depends_on 指定依赖。未就绪会暂缓,不发模型请求。purpose=independent 须显式选择,仅用于不依赖未返回报告的独立问题,说明已有证据和材料缺口,不用于绕过汇总依赖。必要搜索先做,Advisor 放批末,读意见后再规划后续操作。允许时只读核实工作区文件(不能运行命令或测试)。默认 reviewMode=brief 给重点短评;完整代码审查用 full,note 写范围、基线、证据和待挑战的问题;full 不扩大模型窗口,材料不足须说明未完成。';
@@ -2,4 +2,4 @@
2
2
  * 发给模型的 Advisor 工具描述(唯一一份)。
3
3
  * 咨询时机、采纳规则住在 policyRegistry 的 capability.advisor;这里只讲工具本身的契约,避免两处各写一遍。
4
4
  */
5
- export const ADVISOR_TOOL_DESCRIPTION = '向顾问模型请求第二意见;容量由顾问模型上下文窗口和最大输出配置决定,没有独立输入配额。purpose=independent 可与后台子任务并行,明确尚未收齐的材料;purpose=synthesis 汇总当前交付的必要任务,或用 depends_on 指定依赖,先获取并验收报告再咨询。未就绪会暂缓,不发模型请求。允许时只读核实工作区文件(不能运行命令或测试)。默认 reviewMode=brief 给重点短评;完整代码审查用 full,note 写范围、基线、证据和待挑战的问题;full 不扩大模型窗口,材料不足须说明未完成。';
5
+ export const ADVISOR_TOOL_DESCRIPTION = '向顾问模型请求第二意见;容量由顾问模型上下文窗口和最大输出配置决定,没有独立输入配额。默认按当前交付做 synthesis,先获取并验收必要子任务报告,或用 depends_on 指定依赖。未就绪会暂缓,不发模型请求。purpose=independent 须显式选择,仅用于不依赖未返回报告的独立问题,说明已有证据和材料缺口,不用于绕过汇总依赖。必要搜索先做,Advisor 放批末,读意见后再规划后续操作。允许时只读核实工作区文件(不能运行命令或测试)。默认 reviewMode=brief 给重点短评;完整代码审查用 full,note 写范围、基线、证据和待挑战的问题;full 不扩大模型窗口,材料不足须说明未完成。';
@@ -19,6 +19,8 @@
19
19
 
20
20
  `write_scopes` 只限制修改,不限制读取外部模块,worktree 中的路径编辑也遵守显式范围。锁不等于授权,不能通过升级锁扩大任务范围。局部共享目录任务拒绝 Bash/PowerShell,构建验证交给主 Agent;局部范围拒绝无逐路径验证的 ApplyPatch 和 git-clean,使用有路径边界的编辑工具。需要持续并行构建的任务使用 worktree;隔离任务的命令仍不是 OS 沙箱,不能保证任意脚本不越界。
21
21
 
22
+ 不能执行的 Bash/PowerShell/ApplyPatch 同时从该子任务的工具清单去除,运行时权限检查仍保留。`context.verification` 应明确验证责任:分工内未完成事项放 `remaining`,必须 blocked;预先约定的主 Agent 集成验证放 `parentNextSteps`,允许子任务 result,但主 Agent 仍必须验证后 accept,不能据此直接发布最终交付。
23
+
22
24
  ## 并行写任务
23
25
 
24
26
  1. 主 Agent 确认验收与现有修改,复杂方案先请 Advisor 提第二意见,再记录采纳/拒绝理由。顾问不负责授权,也不要求所有小修改都经过顾问。
@@ -313,6 +313,9 @@ async function runAgentTaskImpl(input, signal, ctx, deps = {}) {
313
313
  });
314
314
  const subTools = filterToolsForRuntime(delegatedTools.filter((tool) => allowedTools.includes(tool.name)
315
315
  && (def.type !== 'explore' || tool.isReadOnly === true)
316
+ // Do not advertise commands which the write-scope guard cannot execute.
317
+ && !(def.type === 'general' && !writeScopes.includes(rootScope[0])
318
+ && (tool.name === 'ApplyPatch' || (!wt && ['Bash', 'PowerShell'].includes(tool.name))))
316
319
  // The built-in write-scope adapters know the built-in argument/side-effect
317
320
  // contracts. A replacement writer can only inherit a whole-workspace grant.
318
321
  && (writeScopes.includes(rootScope[0]) || tool.isReadOnly === true || ALL_TOOLS.includes(tool))), childRuntime);
@@ -391,6 +391,9 @@ async function runAgentTaskImpl(
391
391
  const subTools = filterToolsForRuntime(
392
392
  delegatedTools.filter((tool) => allowedTools.includes(tool.name)
393
393
  && (def.type !== 'explore' || tool.isReadOnly === true)
394
+ // Do not advertise commands which the write-scope guard cannot execute.
395
+ && !(def.type === 'general' && !writeScopes.includes(rootScope[0]!)
396
+ && (tool.name === 'ApplyPatch' || (!wt && ['Bash', 'PowerShell'].includes(tool.name))))
394
397
  // The built-in write-scope adapters know the built-in argument/side-effect
395
398
  // contracts. A replacement writer can only inherit a whole-workspace grant.
396
399
  && (writeScopes.includes(rootScope[0]!) || tool.isReadOnly === true || ALL_TOOLS.includes(tool))),
@@ -11,6 +11,7 @@ const reportSchema = z.object({
11
11
  completed: lines,
12
12
  attempted: lines,
13
13
  remaining: lines,
14
+ parentNextSteps: lines.optional().describe('任务书预先约定由主 Agent 执行的集成、组合验证;不计为子任务未完成。不得用它转移自己未完成的必要工作。'),
14
15
  needed: z.string().min(1).max(2000).optional(),
15
16
  evidenceRefs: z.array(z.string().min(1).max(200)).max(40),
16
17
  findings: z.array(researchFindingSchema).max(24).optional(),
@@ -79,7 +80,7 @@ export function writeReviewEvidenceError(history, createdAt, refs, executed) {
79
80
  export const agentReportTool = {
80
81
  get promptGuide() { return BUILTIN_TOOL_PROMPT_GUIDES.AgentReport; }, // private channel; not in ALL_TOOLS
81
82
  name: 'AgentReport', inputSchema: reportSchema, parameters: toToolParameters(reportSchema),
82
- description: '向主 Agent 交接。help=求助但继续独立工作;blocked=交回现场并停止本次执行;result=提交结果并停止。本工具不询问用户、不授予权限。填写完成项、尝试、剩余工作和真实子工具证据 ID。',
83
+ description: '向主 Agent 交接。help=求助但继续独立工作;blocked=交回现场并停止本次执行;result=本次分工完成并停止,不等于主任务验收。本工具不询问用户、不授予权限。remaining 是自己未完成的必要工作,parentNextSteps 只放任务书预定的主 Agent 集成验证。填写完成项、尝试和真实子工具证据 ID。',
83
84
  isReadOnly: true, isConcurrencySafe: false,
84
85
  call: async () => ({ ok: false, error: 'AgentReport requires a parent channel' }),
85
86
  callWithContext: async (input, _signal, ctx) => {
@@ -13,6 +13,7 @@ const reportSchema = z.object({
13
13
  completed: lines,
14
14
  attempted: lines,
15
15
  remaining: lines,
16
+ parentNextSteps: lines.optional().describe('任务书预先约定由主 Agent 执行的集成、组合验证;不计为子任务未完成。不得用它转移自己未完成的必要工作。'),
16
17
  needed: z.string().min(1).max(2000).optional(),
17
18
  evidenceRefs: z.array(z.string().min(1).max(200)).max(40),
18
19
  findings: z.array(researchFindingSchema).max(24).optional(),
@@ -79,7 +80,7 @@ export function writeReviewEvidenceError(
79
80
  export const agentReportTool: Tool<z.infer<typeof reportSchema>> = {
80
81
  get promptGuide() { return BUILTIN_TOOL_PROMPT_GUIDES.AgentReport; }, // private channel; not in ALL_TOOLS
81
82
  name: 'AgentReport', inputSchema: reportSchema, parameters: toToolParameters(reportSchema),
82
- description: '向主 Agent 交接。help=求助但继续独立工作;blocked=交回现场并停止本次执行;result=提交结果并停止。本工具不询问用户、不授予权限。填写完成项、尝试、剩余工作和真实子工具证据 ID。',
83
+ description: '向主 Agent 交接。help=求助但继续独立工作;blocked=交回现场并停止本次执行;result=本次分工完成并停止,不等于主任务验收。本工具不询问用户、不授予权限。remaining 是自己未完成的必要工作,parentNextSteps 只放任务书预定的主 Agent 集成验证。填写完成项、尝试和真实子工具证据 ID。',
83
84
  isReadOnly: true, isConcurrencySafe: false,
84
85
  call: async () => ({ ok: false, error: 'AgentReport requires a parent channel' }),
85
86
  callWithContext: async (input, _signal, ctx) => {
@@ -233,10 +233,18 @@ export function attachAgentHistory(task, history) {
233
233
  export async function stopAllAgentTasks(state) {
234
234
  const running = [...state.tasks.values()].filter((t) => t.status === 'running');
235
235
  running.forEach((t) => t.abort.abort());
236
- await Promise.race([
237
- Promise.allSettled(running.map((t) => t.completion)).then(() => undefined),
238
- new Promise((r) => setTimeout(r, 5000)),
239
- ]);
236
+ if (running.length) {
237
+ let timer;
238
+ try {
239
+ await Promise.race([
240
+ Promise.allSettled(running.map((t) => t.completion)),
241
+ new Promise((resolve) => { timer = setTimeout(resolve, 5000); }),
242
+ ]);
243
+ }
244
+ finally {
245
+ clearTimeout(timer);
246
+ }
247
+ }
240
248
  for (const [id, task] of state.tasks)
241
249
  if (task.status !== 'running')
242
250
  state.tasks.delete(id);
@@ -264,8 +272,20 @@ export async function takeAgentNotifications(ctx) {
264
272
  const key = `${task.id}:${task.attemptId ?? task.createdAt}`;
265
273
  if (!delivered.has(`agent-notice:${key}`)) {
266
274
  const result = task.result;
275
+ const target = task.deliveryId ?? task.parentMessageId;
276
+ const origin = target && ctx.deliveryId ? target === ctx.deliveryId ? '当前目标' : '先前目标' : '来源待确认';
277
+ const date = new Date(task.createdAt);
278
+ const time = Number.isFinite(date.getTime()) ? date.toISOString() : '时间未知';
279
+ // Prefer a bounded, valid handoff object to slicing JSON in half. The
280
+ // complete report/evidence remains in TaskOutput and the durable ledger.
281
+ const handoff = task.handoff;
282
+ const report = handoff ? JSON.stringify({
283
+ kind: handoff.kind, summary: handoff.summary.slice(0, 1200),
284
+ needed: handoff.needed?.slice(0, 500),
285
+ parentNextSteps: handoff.parentNextSteps?.slice(0, 3).map(step => step.slice(0, 200)),
286
+ }) : (result?.ok ? result.content : result?.error ?? '').slice(0, 3000);
267
287
  messages.push({ role: 'user', timestamp: Date.now(), id: `agent-notice:${key}`,
268
- content: `[子 Agent 完成通知]\n子任务 ${task.id} (${task.description}) 已${task.status}。\n${(result?.ok ? result.content : result?.error ?? '').slice(0, 3000)}\n完整现场用 TaskOutput 获取;失败或未完成时请决定续接、重分配或亲自接管,不把缺口当作已完成。` });
288
+ content: `[子 Agent 完成通知]\n子任务 ${task.id} (${task.description}) 已${task.status}。\n来源:${origin} · 派发于 ${time}\n${report}\n完整现场用 TaskOutput 获取;这是状态通知,不是新派发或验收。先前目标不要默默混入当前交付;失败或未完成时请决定续接、重分配或亲自接管,不把缺口当作已完成。` });
269
289
  }
270
290
  // Only consume in memory. A crash before the parent transcript is saved
271
291
  // leaves the durable outbox pending, so the next process can deliver it.
@@ -346,6 +366,7 @@ export async function agentCoordinationContext(ctx) {
346
366
  handoff: r.handoff ? {
347
367
  kind: r.handoff.kind, summary: r.handoff.summary.slice(0, 600),
348
368
  needed: r.handoff.needed?.slice(0, 400), remaining: r.handoff.remaining.slice(0, 4).map((s) => s.slice(0, 200)),
369
+ parentNextSteps: r.handoff.parentNextSteps?.slice(0, 4).map(s => s.slice(0, 200)),
349
370
  } : undefined,
350
371
  result: !r.handoff && r.result ? (r.result.ok ? r.result.content : r.result.error).slice(0, 500) : undefined,
351
372
  }));
@@ -316,10 +316,15 @@ export async function stopAllAgentTasks(state: AgentTaskState): Promise<void> {
316
316
  (t) => t.status === 'running',
317
317
  );
318
318
  running.forEach((t) => t.abort.abort());
319
- await Promise.race([
320
- Promise.allSettled(running.map((t) => t.completion)).then(() => undefined),
321
- new Promise<void>((r) => setTimeout(r, 5000)),
322
- ]);
319
+ if (running.length) {
320
+ let timer: ReturnType<typeof setTimeout> | undefined;
321
+ try {
322
+ await Promise.race([
323
+ Promise.allSettled(running.map((t) => t.completion)),
324
+ new Promise<void>((resolve) => { timer = setTimeout(resolve, 5000); }),
325
+ ]);
326
+ } finally { clearTimeout(timer); }
327
+ }
323
328
  for (const [id, task] of state.tasks) if (task.status !== 'running') state.tasks.delete(id);
324
329
  }
325
330
 
@@ -343,8 +348,20 @@ export async function takeAgentNotifications(ctx: ToolCallContext): Promise<Mess
343
348
  const key = `${task.id}:${task.attemptId ?? task.createdAt}`;
344
349
  if (!delivered.has(`agent-notice:${key}`)) {
345
350
  const result = task.result;
351
+ const target = task.deliveryId ?? task.parentMessageId;
352
+ const origin = target && ctx.deliveryId ? target === ctx.deliveryId ? '当前目标' : '先前目标' : '来源待确认';
353
+ const date = new Date(task.createdAt);
354
+ const time = Number.isFinite(date.getTime()) ? date.toISOString() : '时间未知';
355
+ // Prefer a bounded, valid handoff object to slicing JSON in half. The
356
+ // complete report/evidence remains in TaskOutput and the durable ledger.
357
+ const handoff = task.handoff;
358
+ const report = handoff ? JSON.stringify({
359
+ kind: handoff.kind, summary: handoff.summary.slice(0, 1200),
360
+ needed: handoff.needed?.slice(0, 500),
361
+ parentNextSteps: handoff.parentNextSteps?.slice(0, 3).map(step => step.slice(0, 200)),
362
+ }) : (result?.ok ? result.content : result?.error ?? '').slice(0, 3000);
346
363
  messages.push({ role: 'user', timestamp: Date.now(), id: `agent-notice:${key}`,
347
- content: `[子 Agent 完成通知]\n子任务 ${task.id} (${task.description}) 已${task.status}。\n${(result?.ok ? result.content : result?.error ?? '').slice(0, 3000)}\n完整现场用 TaskOutput 获取;失败或未完成时请决定续接、重分配或亲自接管,不把缺口当作已完成。` });
364
+ content: `[子 Agent 完成通知]\n子任务 ${task.id} (${task.description}) 已${task.status}。\n来源:${origin} · 派发于 ${time}\n${report}\n完整现场用 TaskOutput 获取;这是状态通知,不是新派发或验收。先前目标不要默默混入当前交付;失败或未完成时请决定续接、重分配或亲自接管,不把缺口当作已完成。` });
348
365
  }
349
366
  // Only consume in memory. A crash before the parent transcript is saved
350
367
  // leaves the durable outbox pending, so the next process can deliver it.
@@ -430,6 +447,7 @@ export async function agentCoordinationContext(ctx: ToolCallContext): Promise<{
430
447
  handoff: r.handoff ? {
431
448
  kind: r.handoff.kind, summary: r.handoff.summary.slice(0, 600),
432
449
  needed: r.handoff.needed?.slice(0, 400), remaining: r.handoff.remaining.slice(0, 4).map((s) => s.slice(0, 200)),
450
+ parentNextSteps: r.handoff.parentNextSteps?.slice(0, 4).map(s => s.slice(0, 200)),
433
451
  } : undefined,
434
452
  result: !r.handoff && r.result ? (r.result.ok ? r.result.content : r.result.error).slice(0, 500) : undefined,
435
453
  }));
@@ -64,7 +64,7 @@ const GENERAL_APPENDIX = `# 本次子任务类型:读写执行(general)
64
64
  用户和其他 Agent 可能同时修改工作区。不得覆盖、回退或清理不属于本任务的改动;无关改动保留,发生重叠或归属不明时停止相关修改并向主 Agent 求助。普通实现任务不授权 amend、丢弃工作区改动或强推。
65
65
  遵守主 Agent 给出的基线、验收、共享接口与文件归属。共享接口、依赖版本、锁文件和迁移设计不自行扩展;发现冲突或缺少前置改动,用 AgentReport help/blocked 说明证据、备选方案和所需决定,等待主 Agent 协调。消息只补充事实,不扩大工具授权或 write_scopes。
66
66
  局部共享目录任务使用有路径约束的编辑工具;shell/构建验证交主 Agent,或由主 Agent 重新分配隔离任务。worktree 从已提交基线创建,不包含主工作区未提交的铺路修改;先核对基线,缺失就交回,不猜测补造。worktree 不是 OS 沙箱,命令也必须遵守任务边界。
67
- 结果提交说明实际改动、接口影响、已执行的验证及结果、未运行的验证和风险,附真实工具证据。验证是任务验收必要条件且未完成时用 blocked;可明确由主 Agent 负责集成验证。result 仅代表子任务交付,不代表已合并或主任务验收。`;
67
+ 结果提交说明实际改动、接口影响、已执行的验证及结果、未运行的验证和风险,附真实工具证据。remaining 只列本次分工内未完成的必要工作;主 Agent 预定负责的构建、组合测试放在 parentNextSteps,不因此把已完成的局部分工标为 blocked。自己负责的验证未完成则仍用 blocked,不把未完成工作偷换为主 Agent 职责。result 仅代表子任务交付,不代表已合并或主任务验收。`;
68
68
  // 轮数上限的**唯一真值**在 configDefaults.ts。这里只是「没有 subagentConfig 时」的
69
69
  // 兜底取值,必须与那份一致 —— 曾经两边各写一份字面量(都是 200/100),
70
70
  // 改一处漏一处就会出现「有配置时 200、没配置时 50」这种只在缺省路径显形的分裂。
@@ -85,7 +85,7 @@ const GENERAL_APPENDIX = `# 本次子任务类型:读写执行(general)
85
85
  用户和其他 Agent 可能同时修改工作区。不得覆盖、回退或清理不属于本任务的改动;无关改动保留,发生重叠或归属不明时停止相关修改并向主 Agent 求助。普通实现任务不授权 amend、丢弃工作区改动或强推。
86
86
  遵守主 Agent 给出的基线、验收、共享接口与文件归属。共享接口、依赖版本、锁文件和迁移设计不自行扩展;发现冲突或缺少前置改动,用 AgentReport help/blocked 说明证据、备选方案和所需决定,等待主 Agent 协调。消息只补充事实,不扩大工具授权或 write_scopes。
87
87
  局部共享目录任务使用有路径约束的编辑工具;shell/构建验证交主 Agent,或由主 Agent 重新分配隔离任务。worktree 从已提交基线创建,不包含主工作区未提交的铺路修改;先核对基线,缺失就交回,不猜测补造。worktree 不是 OS 沙箱,命令也必须遵守任务边界。
88
- 结果提交说明实际改动、接口影响、已执行的验证及结果、未运行的验证和风险,附真实工具证据。验证是任务验收必要条件且未完成时用 blocked;可明确由主 Agent 负责集成验证。result 仅代表子任务交付,不代表已合并或主任务验收。`;
88
+ 结果提交说明实际改动、接口影响、已执行的验证及结果、未运行的验证和风险,附真实工具证据。remaining 只列本次分工内未完成的必要工作;主 Agent 预定负责的构建、组合测试放在 parentNextSteps,不因此把已完成的局部分工标为 blocked。自己负责的验证未完成则仍用 blocked,不把未完成工作偷换为主 Agent 职责。result 仅代表子任务交付,不代表已合并或主任务验收。`;
89
89
 
90
90
  // 轮数上限的**唯一真值**在 configDefaults.ts。这里只是「没有 subagentConfig 时」的
91
91
  // 兜底取值,必须与那份一致 —— 曾经两边各写一份字面量(都是 200/100),