minimal-agent 0.18.13 → 0.18.15

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 (181) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -3
  3. package/plugins/workflow-runner/src/runtime/context.js +1 -1
  4. package/plugins/workflow-runner/src/runtime/context.ts +1 -1
  5. package/plugins/workflow-runner/test/embeddedExecution.test.ts +2 -5
  6. package/plugins/workflow-runner/test/execLifetime.test.ts +15 -2
  7. package/skills/ssh-remote-dev/SKILL.md +61 -0
  8. package/skills/ssh-remote-dev/agents/openai.yaml +4 -0
  9. package/src/advisor/README.md +62 -24
  10. package/src/advisor/advisorNudge.js +199 -0
  11. package/src/advisor/advisorNudge.ts +232 -0
  12. package/src/advisor/deliveryReview.js +35 -12
  13. package/src/advisor/deliveryReview.ts +35 -11
  14. package/src/advisor/presentation.js +7 -10
  15. package/src/advisor/presentation.ts +10 -13
  16. package/src/advisor/reviewContext.js +22 -58
  17. package/src/advisor/reviewContext.ts +24 -67
  18. package/src/cli/configMenu.js +17 -128
  19. package/src/cli/configMenu.tsx +17 -193
  20. package/src/cli/print.js +2 -0
  21. package/src/cli/print.ts +2 -0
  22. package/src/cli/streamJson.js +2 -0
  23. package/src/cli/streamJson.ts +2 -0
  24. package/src/cli/wizards/advisorWizard.js +9 -7
  25. package/src/cli/wizards/advisorWizard.tsx +9 -7
  26. package/src/cli/wizards/contextAdvisorWizard.js +9 -7
  27. package/src/cli/wizards/contextAdvisorWizard.tsx +9 -7
  28. package/src/cli/wizards/providerPresets.js +55 -18
  29. package/src/cli/wizards/providerPresets.ts +72 -19
  30. package/src/cli/wizards/providerWizard.js +51 -10
  31. package/src/cli/wizards/providerWizard.tsx +59 -9
  32. package/src/config/configDefaults.js +1 -1
  33. package/src/config/configDefaults.ts +1 -1
  34. package/src/config/configDiagnostics.js +1 -21
  35. package/src/config/configDiagnostics.ts +3 -23
  36. package/src/config/configFile.js +11 -4
  37. package/src/config/configFile.ts +27 -7
  38. package/src/config/configManagement.js +1 -0
  39. package/src/config/configManagement.ts +2 -0
  40. package/src/config/configService.js +12 -8
  41. package/src/config/configService.ts +16 -11
  42. package/src/config/numericLimits.js +0 -4
  43. package/src/config/numericLimits.ts +0 -4
  44. package/src/config/reasoningEffort.js +16 -0
  45. package/src/config/reasoningEffort.ts +18 -0
  46. package/src/context/budgetPlan.js +1 -1
  47. package/src/context/budgetPlan.ts +1 -1
  48. package/src/context/optimizeConversation.js +1 -1
  49. package/src/context/optimizeConversation.ts +1 -1
  50. package/src/harness/stallGuard.js +8 -13
  51. package/src/harness/stallGuard.ts +8 -12
  52. package/src/llm/client.js +64 -17
  53. package/src/llm/client.ts +62 -7
  54. package/src/llm/providers/anthropicFormat.js +3 -1
  55. package/src/llm/providers/anthropicFormat.ts +4 -1
  56. package/src/llm/providers/openaiFormat.js +14 -3
  57. package/src/llm/providers/openaiFormat.ts +17 -3
  58. package/src/llm/providers/responsesFormat.js +277 -0
  59. package/src/llm/providers/responsesFormat.ts +308 -0
  60. package/src/loop/README.md +18 -3
  61. package/src/loop/liveDiagramGate.js +63 -0
  62. package/src/loop/liveDiagramGate.ts +61 -0
  63. package/src/loop/messages.js +12 -0
  64. package/src/loop/messages.ts +13 -0
  65. package/src/loop/options.ts +7 -2
  66. package/src/loop/toolBatch.js +0 -1
  67. package/src/loop/toolBatch.ts +0 -1
  68. package/src/loop/toolExecutor.js +11 -46
  69. package/src/loop/toolExecutor.ts +12 -55
  70. package/src/loop/toolPresentation.js +2 -13
  71. package/src/loop/toolPresentation.ts +2 -13
  72. package/src/loop/toolSemantics.js +3 -4
  73. package/src/loop/toolSemantics.ts +4 -6
  74. package/src/loop.js +222 -214
  75. package/src/loop.ts +226 -232
  76. package/src/memory/dependencies.js +11 -3
  77. package/src/memory/dependencies.ts +11 -3
  78. package/src/memory/episodicMemory.js +59 -18
  79. package/src/memory/episodicMemory.ts +58 -18
  80. package/src/memory/experienceStore.js +4 -3
  81. package/src/memory/experienceStore.ts +4 -3
  82. package/src/memory/factCandidates.js +53 -1
  83. package/src/memory/factCandidates.ts +54 -1
  84. package/src/memory/factLearning.js +2 -2
  85. package/src/memory/factLearning.ts +2 -2
  86. package/src/memory/jobPolicy.js +24 -5
  87. package/src/memory/jobPolicy.ts +25 -5
  88. package/src/memory/learning.js +2 -2
  89. package/src/memory/learning.ts +2 -2
  90. package/src/memory/learningModel.js +7 -0
  91. package/src/memory/learningModel.ts +7 -0
  92. package/src/memory/managementService.js +8 -7
  93. package/src/memory/managementService.ts +16 -8
  94. package/src/memory/memoryService.js +104 -33
  95. package/src/memory/memoryService.ts +132 -28
  96. package/src/memory/projectKnowledge.js +39 -3
  97. package/src/memory/projectKnowledge.ts +45 -3
  98. package/src/memory/recallQuery.js +56 -0
  99. package/src/memory/recallQuery.ts +58 -0
  100. package/src/memory/retrieval.js +39 -10
  101. package/src/memory/retrieval.ts +46 -11
  102. package/src/memory/turnJournal.js +75 -10
  103. package/src/memory/turnJournal.ts +66 -10
  104. package/src/memory/types.ts +7 -1
  105. package/src/prompts/delegation.js +2 -1
  106. package/src/prompts/delegation.ts +3 -1
  107. package/src/prompts/policyRegistry.js +9 -12
  108. package/src/prompts/policyRegistry.ts +9 -12
  109. package/src/prompts/promptAssembly.js +6 -5
  110. package/src/prompts/promptAssembly.ts +8 -6
  111. package/src/prompts/visualPresentation.js +39 -10
  112. package/src/prompts/visualPresentation.ts +38 -9
  113. package/src/runtime/answerPreparation.js +1 -1
  114. package/src/runtime/answerPreparation.ts +1 -1
  115. package/src/runtime/commandCatalog.js +1 -0
  116. package/src/runtime/commandCatalog.ts +9 -0
  117. package/src/runtime/fileLock.js +19 -3
  118. package/src/runtime/fileLock.ts +19 -3
  119. package/src/runtime/invocationPolicy.js +1 -1
  120. package/src/runtime/invocationPolicy.ts +1 -1
  121. package/src/runtime/outputContract.js +0 -4
  122. package/src/runtime/outputContract.ts +0 -7
  123. package/src/session/runAgentTurn.js +3 -0
  124. package/src/session/runAgentTurn.ts +3 -0
  125. package/src/team/onlineToolContract.js +0 -1
  126. package/src/team/onlineToolContract.ts +0 -1
  127. package/src/tools/advisor/advisor.js +207 -365
  128. package/src/tools/advisor/advisor.ts +211 -383
  129. package/src/tools/agent/agentTypes.js +0 -1
  130. package/src/tools/agent/agentTypes.ts +0 -1
  131. package/src/tools/agent/coordinator.js +4 -1
  132. package/src/tools/agent/coordinator.ts +4 -1
  133. package/src/tools/bash/semantics.js +4 -5
  134. package/src/tools/bash/semantics.ts +4 -5
  135. package/src/tools/capabilities.js +2 -3
  136. package/src/tools/capabilities.ts +2 -4
  137. package/src/tools/index.js +0 -16
  138. package/src/tools/index.ts +0 -16
  139. package/src/tools/memory/maintenance.js +8 -9
  140. package/src/tools/memory/maintenance.ts +13 -11
  141. package/src/tools/memory/memory.js +5 -1
  142. package/src/tools/memory/memory.ts +5 -0
  143. package/src/tools/optimizeConversation/README.md +4 -6
  144. package/src/tools/toolPromptGuides.js +2 -9
  145. package/src/tools/toolPromptGuides.ts +2 -9
  146. package/src/types.ts +28 -105
  147. package/src/ui/App.js +22 -1
  148. package/src/ui/App.tsx +26 -1
  149. package/src/ui/MessageList.js +8 -44
  150. package/src/ui/MessageList.tsx +3 -81
  151. package/src/ui/effortCommand.js +19 -0
  152. package/src/ui/effortCommand.ts +36 -0
  153. package/src/ui/hooks/useChat.js +2 -0
  154. package/src/ui/hooks/useChat.ts +2 -0
  155. package/src/ui/toolProgress.js +1 -1
  156. package/src/ui/toolProgress.ts +1 -1
  157. package/src/web/protocol.ts +10 -3
  158. package/src/advisor/advisorCoordinator.js +0 -734
  159. package/src/advisor/advisorCoordinator.ts +0 -825
  160. package/src/cli/wizards/sshHostWizard.js +0 -156
  161. package/src/cli/wizards/sshHostWizard.tsx +0 -214
  162. package/src/context/sshHosts.js +0 -290
  163. package/src/context/sshHosts.ts +0 -312
  164. package/src/loop/publication.js +0 -94
  165. package/src/loop/publication.ts +0 -124
  166. package/src/runtime/finalAnswer.js +0 -9
  167. package/src/runtime/finalAnswer.ts +0 -13
  168. package/src/tools/advisor/advisorDecision.js +0 -79
  169. package/src/tools/advisor/advisorDecision.ts +0 -92
  170. package/src/tools/ssh/ssh.js +0 -152
  171. package/src/tools/ssh/ssh.ts +0 -167
  172. package/src/tools/ssh/sshAvailability.js +0 -35
  173. package/src/tools/ssh/sshAvailability.ts +0 -39
  174. package/src/tools/ssh/sshClient.js +0 -177
  175. package/src/tools/ssh/sshClient.ts +0 -189
  176. package/src/tools/ssh/sshDownload.js +0 -77
  177. package/src/tools/ssh/sshDownload.ts +0 -92
  178. package/src/tools/ssh/sshHostsTool.js +0 -36
  179. package/src/tools/ssh/sshHostsTool.ts +0 -48
  180. package/src/tools/ssh/sshUpload.js +0 -72
  181. package/src/tools/ssh/sshUpload.ts +0 -85
@@ -0,0 +1,63 @@
1
+ import { DIAGRAM_FENCE_INFO, FENCE_CLOSE, FENCE_OPEN, isBoxDiagram } from '../prompts/visualPresentation.js';
2
+ /**
3
+ * Lets a live answer be corrected for text-drawn diagrams without ever
4
+ * retracting shown text. Text streams as it arrives, except a fenced block
5
+ * that could be a prose drawing (no info string, `text`, `plaintext`): that is
6
+ * held from its opening line until it closes. Not a box → released at once.
7
+ * A box → the visible answer stops right before it; the loop keeps the shown
8
+ * part and asks the model to continue from there with a real diagram. Fences
9
+ * with a language are code and stream straight through.
10
+ */
11
+ export class LiveDiagramGate {
12
+ #scanned = 0;
13
+ #fence;
14
+ #hit;
15
+ #released = false;
16
+ /** Start of the held box, once one was found (and not released). */
17
+ get hit() {
18
+ return this.#released ? undefined : this.#hit;
19
+ }
20
+ /** Give up on correcting (tool round, no turns left): show everything. */
21
+ release() {
22
+ this.#released = true;
23
+ }
24
+ /** How much of `text` may be shown now; `final` once the model has finished. */
25
+ releasable(text, final = false) {
26
+ if (this.#released)
27
+ return text.length;
28
+ if (this.#hit !== undefined)
29
+ return this.#hit;
30
+ for (let newline = text.indexOf('\n', this.#scanned); newline >= 0; newline = text.indexOf('\n', this.#scanned)) {
31
+ const start = this.#scanned;
32
+ const line = text.slice(start, newline).replace(/\r$/, '');
33
+ this.#scanned = newline + 1;
34
+ if (!this.#fence) {
35
+ const open = FENCE_OPEN.exec(line);
36
+ if (open)
37
+ this.#fence = { start, body: this.#scanned, marker: open[1], candidate: DIAGRAM_FENCE_INFO.test(open[2]) };
38
+ continue;
39
+ }
40
+ const close = FENCE_CLOSE.exec(line);
41
+ if (!close || close[1][0] !== this.#fence.marker[0] || close[1].length < this.#fence.marker.length)
42
+ continue;
43
+ if (this.#fence.candidate && isBoxDiagram(text.slice(this.#fence.body, start))) {
44
+ this.#hit = this.#fence.start;
45
+ return this.#hit;
46
+ }
47
+ this.#fence = undefined;
48
+ }
49
+ if (final) {
50
+ // The model ended inside a fence: judge what it wrote, then show the rest.
51
+ if (this.#fence?.candidate && isBoxDiagram(text.slice(this.#fence.body)))
52
+ this.#hit = this.#fence.start;
53
+ return this.#hit ?? text.length;
54
+ }
55
+ if (this.#fence?.candidate)
56
+ return this.#fence.start;
57
+ // A partial line outside any fence may still turn into a fence opener
58
+ // (list items indent fences by up to 3 spaces).
59
+ if (!this.#fence && /^ {0,3}[`~]/.test(text.slice(this.#scanned)))
60
+ return this.#scanned;
61
+ return text.length;
62
+ }
63
+ }
@@ -0,0 +1,61 @@
1
+ import { DIAGRAM_FENCE_INFO, FENCE_CLOSE, FENCE_OPEN, isBoxDiagram } from '../prompts/visualPresentation.js';
2
+
3
+ /**
4
+ * Lets a live answer be corrected for text-drawn diagrams without ever
5
+ * retracting shown text. Text streams as it arrives, except a fenced block
6
+ * that could be a prose drawing (no info string, `text`, `plaintext`): that is
7
+ * held from its opening line until it closes. Not a box → released at once.
8
+ * A box → the visible answer stops right before it; the loop keeps the shown
9
+ * part and asks the model to continue from there with a real diagram. Fences
10
+ * with a language are code and stream straight through.
11
+ */
12
+ export class LiveDiagramGate {
13
+ #scanned = 0;
14
+ #fence?: { start: number; body: number; marker: string; candidate: boolean };
15
+ #hit?: number;
16
+ #released = false;
17
+
18
+ /** Start of the held box, once one was found (and not released). */
19
+ get hit(): number | undefined {
20
+ return this.#released ? undefined : this.#hit;
21
+ }
22
+
23
+ /** Give up on correcting (tool round, no turns left): show everything. */
24
+ release(): void {
25
+ this.#released = true;
26
+ }
27
+
28
+ /** How much of `text` may be shown now; `final` once the model has finished. */
29
+ releasable(text: string, final = false): number {
30
+ if (this.#released) return text.length;
31
+ if (this.#hit !== undefined) return this.#hit;
32
+ for (let newline = text.indexOf('\n', this.#scanned); newline >= 0; newline = text.indexOf('\n', this.#scanned)) {
33
+ const start = this.#scanned;
34
+ const line = text.slice(start, newline).replace(/\r$/, '');
35
+ this.#scanned = newline + 1;
36
+ if (!this.#fence) {
37
+ const open = FENCE_OPEN.exec(line);
38
+ if (open)
39
+ this.#fence = { start, body: this.#scanned, marker: open[1]!, candidate: DIAGRAM_FENCE_INFO.test(open[2]!) };
40
+ continue;
41
+ }
42
+ const close = FENCE_CLOSE.exec(line);
43
+ if (!close || close[1]![0] !== this.#fence.marker[0] || close[1]!.length < this.#fence.marker.length) continue;
44
+ if (this.#fence.candidate && isBoxDiagram(text.slice(this.#fence.body, start))) {
45
+ this.#hit = this.#fence.start;
46
+ return this.#hit;
47
+ }
48
+ this.#fence = undefined;
49
+ }
50
+ if (final) {
51
+ // The model ended inside a fence: judge what it wrote, then show the rest.
52
+ if (this.#fence?.candidate && isBoxDiagram(text.slice(this.#fence.body))) this.#hit = this.#fence.start;
53
+ return this.#hit ?? text.length;
54
+ }
55
+ if (this.#fence?.candidate) return this.#fence.start;
56
+ // A partial line outside any fence may still turn into a fence opener
57
+ // (list items indent fences by up to 3 spaces).
58
+ if (!this.#fence && /^ {0,3}[`~]/.test(text.slice(this.#scanned))) return this.#scanned;
59
+ return text.length;
60
+ }
61
+ }
@@ -108,6 +108,18 @@ export function pushManualInterruptMarker(history) {
108
108
  id: crypto.randomUUID(),
109
109
  });
110
110
  }
111
+ /**
112
+ * 回答已发布但实质成果没经顾问复核(advisor.enforcement='followup'):补一条系统提示,
113
+ * 让模型自己去调 Advisor。回答不撤回,Advisor 调用由模型发出,宿主不替它伪造。
114
+ */
115
+ export function pushAdvisorFollowUpMarker(history) {
116
+ history.push({
117
+ role: 'user',
118
+ content: '(系统提示:你刚才给出的回答包含实质结论或成果,但还没有经过顾问复核。现在调用 Advisor 复核:意见指出问题就更正并说明;没有异议则用一句话说明已复核,不要重复整篇回答。)',
119
+ timestamp: Date.now(),
120
+ id: crypto.randomUUID(),
121
+ });
122
+ }
111
123
  /**
112
124
  * 有新的用户输入在队列中,当前安全停靠
113
125
  */
@@ -122,6 +122,19 @@ export function pushManualInterruptMarker(history: Message[]): void {
122
122
  });
123
123
  }
124
124
 
125
+ /**
126
+ * 回答已发布但实质成果没经顾问复核(advisor.enforcement='followup'):补一条系统提示,
127
+ * 让模型自己去调 Advisor。回答不撤回,Advisor 调用由模型发出,宿主不替它伪造。
128
+ */
129
+ export function pushAdvisorFollowUpMarker(history: Message[]): void {
130
+ history.push({
131
+ role: 'user',
132
+ content: '(系统提示:你刚才给出的回答包含实质结论或成果,但还没有经过顾问复核。现在调用 Advisor 复核:意见指出问题就更正并说明;没有异议则用一句话说明已复核,不要重复整篇回答。)',
133
+ timestamp: Date.now(),
134
+ id: crypto.randomUUID(),
135
+ });
136
+ }
137
+
125
138
  /**
126
139
  * 有新的用户输入在队列中,当前安全停靠
127
140
  */
@@ -35,8 +35,13 @@ export interface RunQueryOptions {
35
35
  allowedTools?: string[];
36
36
  /** 调用方工具边界名称,仅用于准确解释越界调用;缺省表示宿主能力边界。 */
37
37
  toolBoundaryLabel?: string;
38
- /** Disable Advisor checkpoints for an explicitly read-only embedded node. */
39
- advisorCheckpoints?: boolean;
38
+ /** False turns off the Advisor reminders for an explicitly read-only embedded node. */
39
+ advisorReminders?: boolean;
40
+ /**
41
+ * 实质回答发布后仍未经顾问复核时,再发一次请求让模型自己补问(回答不撤回)。
42
+ * 缺省读配置 `advisor.enforcement === 'followup'`;测试和内嵌节点可显式指定。
43
+ */
44
+ advisorFollowUp?: boolean;
40
45
  /** Tools the host/workflow explicitly requires; emergency schema reduction preserves them. */
41
46
  requiredTools?: string[];
42
47
  /**
@@ -28,7 +28,6 @@ export async function* executeToolBatch(input) {
28
28
  return (![
29
29
  'AskUserQuestion',
30
30
  'Advisor',
31
- 'AdvisorDecision',
32
31
  'OptimizeConversation',
33
32
  'AgentReport',
34
33
  'AgentResolve',
@@ -41,7 +41,6 @@ export async function* executeToolBatch(input: {
41
41
  ![
42
42
  'AskUserQuestion',
43
43
  'Advisor',
44
- 'AdvisorDecision',
45
44
  'OptimizeConversation',
46
45
  'AgentReport',
47
46
  'AgentResolve',
@@ -9,12 +9,12 @@ import { resolveToolPath } from '../tools/shared/fileUtils.js';
9
9
  import { advisorSemanticsFor } from './toolSemantics.js';
10
10
  /** One batch's execution boundary. Scheduling and history writes belong to callers. */
11
11
  export function createToolExecutor(input) {
12
- const { options, runtimeContext, toolCallContext, currentEffectiveToolSet, advisorCoordinator, stallGuard, modelEnvironmentCwd, observedRuleScopes, pendingRuleScopes, currentUserMessageId, executeToolFn, } = input;
12
+ const { options, runtimeContext, toolCallContext, currentEffectiveToolSet, advisorNudge, stallGuard, modelEnvironmentCwd, observedRuleScopes, pendingRuleScopes, currentUserMessageId, executeToolFn, } = input;
13
13
  const { signal, sessionState } = options;
14
14
  // Convert tool execution failures/aborts into results; host hook failures are
15
15
  // not a successful tool outcome and may propagate to the batch boundary.
16
16
  const failureReviews = [];
17
- const runOneImpl = async (tc, reportProgress, advisorConsultation) => {
17
+ const runOneImpl = async (tc, reportProgress) => {
18
18
  let started = false;
19
19
  try {
20
20
  const handoff = options.agentHandoff?.current();
@@ -33,8 +33,9 @@ export function createToolExecutor(input) {
33
33
  result: { ok: false, disposition: 'deferred', error: 'aborted' },
34
34
  };
35
35
  }
36
- const advisorAvailable = currentEffectiveToolSet.names.has('Advisor');
37
- if (!advisorAvailable && stallGuard.shouldReject(tc)) {
36
+ // Rejecting a third identical failing call is the guard's own job, advisor or
37
+ // not: the advisor is only a reminder now, so nothing else stops the loop.
38
+ if (stallGuard.shouldReject(tc)) {
38
39
  return {
39
40
  tc,
40
41
  result: {
@@ -68,15 +69,6 @@ export function createToolExecutor(input) {
68
69
  },
69
70
  };
70
71
  }
71
- const checkpoint = options.advisorCheckpoints === false
72
- ? { allow: true }
73
- : advisorCoordinator.beforeTool(tc, {
74
- ...advisorSemanticsFor(tc, toolCallContext, currentEffectiveToolSet.tools.find((tool) => tool.name === tc.function.name), { treatVerificationAsReadOnly: true }),
75
- retriesFailure: stallGuard.shouldReject(tc),
76
- });
77
- if (!checkpoint.allow) {
78
- return { tc, result: checkpoint.deferred };
79
- }
80
72
  // 工具执行闸门:宿主注入后覆盖所有工具,包括只读工具。deny → 把 reason 当
81
73
  // tool_result 回填,模型据此改道/如实报告,不抛异常不中断整轮。宿主异常一律 deny。
82
74
  // Keep the host gate's side-effect classification identical to the
@@ -210,7 +202,6 @@ export function createToolExecutor(input) {
210
202
  options.onToolStart?.(tc.function.name, tc.id);
211
203
  result = await executeToolFn(tc.function.name, tc.function.arguments, signal, {
212
204
  ...toolCallContext,
213
- advisorConsultation,
214
205
  delegationTools: currentEffectiveToolSet.tools,
215
206
  cwd: sessionState?.activeWorktree?.path ?? toolCallContext.cwd,
216
207
  toolCallId: tc.id,
@@ -244,10 +235,10 @@ export function createToolExecutor(input) {
244
235
  };
245
236
  }
246
237
  }
247
- if (tc.function.name === 'Advisor' || tc.function.name === 'AdvisorDecision') {
248
- // 串行批次内下一项可能就是 AdvisorDecision/受保护写入,必须立即推进协调器状态。
249
- advisorCoordinator.observeToolResult(tc, result);
250
- }
238
+ // A successful consultation lets the model try the failing path again: the
239
+ // guard stops counting those failures against it.
240
+ if (tc.function.name === 'Advisor' && result.ok)
241
+ stallGuard.noteConsultation();
251
242
  started = false;
252
243
  options.onToolEnd?.(tc.id, false);
253
244
  return { tc, result };
@@ -266,37 +257,11 @@ export function createToolExecutor(input) {
266
257
  }
267
258
  };
268
259
  const runOne = async (tc, reportProgress) => {
269
- // Also settle denied/invalid/unavailable calls that never reached the
270
- // provider adapter. This records a real attempt, not an ignored reminder.
271
- let consultation;
272
- if (tc.function.name === 'Advisor') {
273
- let reason;
274
- try {
275
- reason = JSON.parse(tc.function.arguments).reason;
276
- }
277
- catch {
278
- /* validation handles malformed input */
279
- }
280
- consultation = advisorCoordinator.beginConsultation(reason);
281
- }
282
- const outcome = await runOneImpl(tc, reportProgress, consultation);
283
- if (consultation &&
284
- outcome.result.metadata?.kind !== 'advisor_consultation' &&
285
- !(!outcome.result.ok && outcome.result.error === 'aborted')) {
286
- outcome.result = {
287
- ...outcome.result,
288
- metadata: advisorCoordinator.finishConsultation(consultation, outcome.result.ok),
289
- };
290
- }
291
- const metadata = outcome.result.metadata;
292
- if ((metadata?.kind === 'advisor_decision' && outcome.result.ok) || metadata?.kind === 'advisor_consultation') {
293
- if (metadata.checkpoint === 'stalled')
294
- stallGuard.completeReview(metadata.checkpointKey.split(':').at(-1));
295
- }
260
+ const outcome = await runOneImpl(tc, reportProgress);
296
261
  const failure = stallGuard.observeAttempt(tc, outcome.result);
297
262
  if (failure.stalled && failure.signature) {
298
263
  failureReviews.push(failure);
299
- advisorCoordinator.requireFailureReview(failure.signature, failure.attempts ?? []);
264
+ advisorNudge.notifyStalled(failure.signature);
300
265
  }
301
266
  return outcome;
302
267
  };
@@ -1,5 +1,5 @@
1
1
  import { dirname, resolve } from 'node:path';
2
- import type { AdvisorCoordinator } from '../advisor/advisorCoordinator.js';
2
+ import type { AdvisorNudge } from '../advisor/advisorNudge.js';
3
3
  import { countTextTokens } from '../context/tokenCounter.js';
4
4
  import { StallGuard, type StallObservation } from '../harness/stallGuard.js';
5
5
  import { loadProjectPromptInstructions } from '../prompts/projectInstructions.js';
@@ -21,12 +21,12 @@ export type WorkerOutcome = {
21
21
  interface ToolExecutorInput {
22
22
  options: Pick<RunQueryOptions,
23
23
  'signal' | 'sessionState' | 'agentHandoff' | 'hasQueuedInput' |
24
- 'advisorCheckpoints' | 'toolBoundaryLabel' | 'toolGate' |
24
+ 'toolBoundaryLabel' | 'toolGate' |
25
25
  'onToolStart' | 'onToolEnd' | 'commitFormalDelivery'>;
26
26
  runtimeContext: AgentRuntimeContext;
27
27
  toolCallContext: ToolCallContext;
28
28
  currentEffectiveToolSet: EffectiveToolSet;
29
- advisorCoordinator: AdvisorCoordinator;
29
+ advisorNudge: AdvisorNudge;
30
30
  stallGuard: StallGuard;
31
31
  modelEnvironmentCwd: string;
32
32
  observedRuleScopes: Map<string, string>;
@@ -41,7 +41,7 @@ export function createToolExecutor(input: ToolExecutorInput) {
41
41
  runtimeContext,
42
42
  toolCallContext,
43
43
  currentEffectiveToolSet,
44
- advisorCoordinator,
44
+ advisorNudge,
45
45
  stallGuard,
46
46
  modelEnvironmentCwd,
47
47
  observedRuleScopes,
@@ -56,7 +56,6 @@ export function createToolExecutor(input: ToolExecutorInput) {
56
56
  const runOneImpl = async (
57
57
  tc: ToolCall,
58
58
  reportProgress?: (message: string, detail?: import('../types.js').ToolProgressDetail) => void,
59
- advisorConsultation?: import('../types.js').AdvisorConsultationMetadata,
60
59
  ): Promise<WorkerOutcome> => {
61
60
  let started = false;
62
61
  try {
@@ -76,8 +75,9 @@ export function createToolExecutor(input: ToolExecutorInput) {
76
75
  result: { ok: false, disposition: 'deferred', error: 'aborted' },
77
76
  };
78
77
  }
79
- const advisorAvailable = currentEffectiveToolSet.names.has('Advisor');
80
- if (!advisorAvailable && stallGuard.shouldReject(tc)) {
78
+ // Rejecting a third identical failing call is the guard's own job, advisor or
79
+ // not: the advisor is only a reminder now, so nothing else stops the loop.
80
+ if (stallGuard.shouldReject(tc)) {
81
81
  return {
82
82
  tc,
83
83
  result: {
@@ -112,21 +112,6 @@ export function createToolExecutor(input: ToolExecutorInput) {
112
112
  },
113
113
  };
114
114
  }
115
- const checkpoint =
116
- options.advisorCheckpoints === false
117
- ? { allow: true as const }
118
- : advisorCoordinator.beforeTool(tc, {
119
- ...advisorSemanticsFor(
120
- tc,
121
- toolCallContext,
122
- currentEffectiveToolSet.tools.find((tool) => tool.name === tc.function.name),
123
- { treatVerificationAsReadOnly: true },
124
- ),
125
- retriesFailure: stallGuard.shouldReject(tc),
126
- });
127
- if (!checkpoint.allow) {
128
- return { tc, result: checkpoint.deferred! };
129
- }
130
115
  // 工具执行闸门:宿主注入后覆盖所有工具,包括只读工具。deny → 把 reason 当
131
116
  // tool_result 回填,模型据此改道/如实报告,不抛异常不中断整轮。宿主异常一律 deny。
132
117
  // Keep the host gate's side-effect classification identical to the
@@ -267,7 +252,6 @@ export function createToolExecutor(input: ToolExecutorInput) {
267
252
  options.onToolStart?.(tc.function.name, tc.id);
268
253
  result = await executeToolFn(tc.function.name, tc.function.arguments, signal, {
269
254
  ...toolCallContext,
270
- advisorConsultation,
271
255
  delegationTools: currentEffectiveToolSet.tools,
272
256
  cwd: sessionState?.activeWorktree?.path ?? toolCallContext.cwd,
273
257
  toolCallId: tc.id,
@@ -303,10 +287,9 @@ export function createToolExecutor(input: ToolExecutorInput) {
303
287
  };
304
288
  }
305
289
  }
306
- if (tc.function.name === 'Advisor' || tc.function.name === 'AdvisorDecision') {
307
- // 串行批次内下一项可能就是 AdvisorDecision/受保护写入,必须立即推进协调器状态。
308
- advisorCoordinator.observeToolResult(tc, result);
309
- }
290
+ // A successful consultation lets the model try the failing path again: the
291
+ // guard stops counting those failures against it.
292
+ if (tc.function.name === 'Advisor' && result.ok) stallGuard.noteConsultation();
310
293
  started = false;
311
294
  options.onToolEnd?.(tc.id, false);
312
295
  return { tc, result };
@@ -324,37 +307,11 @@ export function createToolExecutor(input: ToolExecutorInput) {
324
307
  };
325
308
 
326
309
  const runOne = async (tc: ToolCall, reportProgress?: Parameters<typeof runOneImpl>[1]): Promise<WorkerOutcome> => {
327
- // Also settle denied/invalid/unavailable calls that never reached the
328
- // provider adapter. This records a real attempt, not an ignored reminder.
329
- let consultation;
330
- if (tc.function.name === 'Advisor') {
331
- let reason: import('../types.js').AdvisorReason | undefined;
332
- try {
333
- reason = JSON.parse(tc.function.arguments).reason;
334
- } catch {
335
- /* validation handles malformed input */
336
- }
337
- consultation = advisorCoordinator.beginConsultation(reason);
338
- }
339
- const outcome = await runOneImpl(tc, reportProgress, consultation);
340
- if (
341
- consultation &&
342
- outcome.result.metadata?.kind !== 'advisor_consultation' &&
343
- !(!outcome.result.ok && outcome.result.error === 'aborted')
344
- ) {
345
- outcome.result = {
346
- ...outcome.result,
347
- metadata: advisorCoordinator.finishConsultation(consultation, outcome.result.ok),
348
- };
349
- }
350
- const metadata = outcome.result.metadata;
351
- if ((metadata?.kind === 'advisor_decision' && outcome.result.ok) || metadata?.kind === 'advisor_consultation') {
352
- if (metadata.checkpoint === 'stalled') stallGuard.completeReview(metadata.checkpointKey.split(':').at(-1)!);
353
- }
310
+ const outcome = await runOneImpl(tc, reportProgress);
354
311
  const failure = stallGuard.observeAttempt(tc, outcome.result);
355
312
  if (failure.stalled && failure.signature) {
356
313
  failureReviews.push(failure);
357
- advisorCoordinator.requireFailureReview(failure.signature, failure.attempts ?? []);
314
+ advisorNudge.notifyStalled(failure.signature);
358
315
  }
359
316
  return outcome;
360
317
  };
@@ -35,19 +35,8 @@ export function friendlyToolDescription(toolName, rawArgsJson, fileLabel) {
35
35
  return `技能 · ${truncate(args.name, 60)}`;
36
36
  case 'SearchSkills':
37
37
  return `查找技能 · ${truncate(args.query, 60)}`;
38
- case 'Advisor': {
39
- const reasons = {
40
- plan_review: '执行前评审',
41
- delivery_review: '交付前核验',
42
- stalled: '分析重复失败',
43
- uncertainty: '核查不确定问题',
44
- user_dissatisfaction: '复核用户反馈',
45
- evidence_conflict: '核查证据冲突',
46
- };
47
- return `咨询顾问 · ${reasons[String(args.reason)] ?? '独立第二意见'}`;
48
- }
49
- case 'AdvisorDecision':
50
- return `顾问建议 · ${truncate(args.decision ?? args.action, 40) || '记录核验与采纳结论'}`;
38
+ case 'Advisor':
39
+ return `咨询顾问 · ${args.reviewMode === 'full' ? '完整代码审查' : '独立第二意见'}`;
51
40
  case 'AskUserQuestion':
52
41
  return '询问关键决策';
53
42
  case 'PresentResult':
@@ -35,19 +35,8 @@ export function friendlyToolDescription(
35
35
  return `技能 · ${truncate(args.name, 60)}`;
36
36
  case 'SearchSkills':
37
37
  return `查找技能 · ${truncate(args.query, 60)}`;
38
- case 'Advisor': {
39
- const reasons: Record<string, string> = {
40
- plan_review: '执行前评审',
41
- delivery_review: '交付前核验',
42
- stalled: '分析重复失败',
43
- uncertainty: '核查不确定问题',
44
- user_dissatisfaction: '复核用户反馈',
45
- evidence_conflict: '核查证据冲突',
46
- };
47
- return `咨询顾问 · ${reasons[String(args.reason)] ?? '独立第二意见'}`;
48
- }
49
- case 'AdvisorDecision':
50
- return `顾问建议 · ${truncate(args.decision ?? args.action, 40) || '记录核验与采纳结论'}`;
38
+ case 'Advisor':
39
+ return `咨询顾问 · ${args.reviewMode === 'full' ? '完整代码审查' : '独立第二意见'}`;
51
40
  case 'AskUserQuestion':
52
41
  return '询问关键决策';
53
42
  case 'PresentResult':
@@ -2,8 +2,7 @@ import { isReadOnlyShellCommand, isVerificationShellCommand, isAdvisorInspection
2
2
  import { toolEffectFor } from '../tools/capabilities.js';
3
3
  import { getToolByName, getToolGateDetails } from '../tools/index.js';
4
4
  export function advisorSemanticsFor(call, context, tool,
5
- // 默认 false:只有 advisor 检查点/记账(beforeTool、observeToolResult、
6
- // 持久化的 advisorMutatesWorkspace 标注)才传 true。工作区租约判定
5
+ // 默认 false:只有顾问提醒的记账(AdvisorNudge.observeToolResult)才传 true。工作区租约判定
7
6
  // (needsWorkspaceLease)必须保持严格定义不受影响——验证类命令仍可能写
8
7
  // 构建产物/缓存,并发场景下让它绕开租约会重新引入竞态。
9
8
  opts) {
@@ -26,8 +25,8 @@ opts) {
26
25
  try {
27
26
  const input = JSON.parse(call.function.arguments || '{}');
28
27
  if (typeof input.command === 'string') {
29
- // 跑测试/构建/lint 只是核对现状,不该被当成"开始实施改动"而白白烧掉
30
- // pre-execution 检查点——即使它们可能写构建产物/缓存,不满足
28
+ // 跑测试/构建/lint 只是核对现状,不该被当成"开始实施改动"而过早提醒
29
+ // "动手前先咨询"——即使它们可能写构建产物/缓存,不满足
31
30
  // isReadOnlyShellCommand 的并发安全定义(见 opts 注释,那个场景仍要严格)。
32
31
  isReadOnly =
33
32
  isReadOnlyShellCommand(input.command) ||
@@ -1,4 +1,3 @@
1
- import type { AdvisorToolSemantics } from '../advisor/advisorCoordinator.js';
2
1
  import { isReadOnlyShellCommand, isVerificationShellCommand, isAdvisorInspectionCommand } from '../tools/bash/semantics.js';
3
2
  import { toolEffectFor } from '../tools/capabilities.js';
4
3
  import { getToolByName, getToolGateDetails } from '../tools/index.js';
@@ -7,12 +6,11 @@ export function advisorSemanticsFor(
7
6
  call: ToolCall,
8
7
  context?: ToolCallContext,
9
8
  tool?: Tool,
10
- // 默认 false:只有 advisor 检查点/记账(beforeTool、observeToolResult、
11
- // 持久化的 advisorMutatesWorkspace 标注)才传 true。工作区租约判定
9
+ // 默认 false:只有顾问提醒的记账(AdvisorNudge.observeToolResult)才传 true。工作区租约判定
12
10
  // (needsWorkspaceLease)必须保持严格定义不受影响——验证类命令仍可能写
13
11
  // 构建产物/缓存,并发场景下让它绕开租约会重新引入竞态。
14
12
  opts?: { treatVerificationAsReadOnly?: boolean },
15
- ): AdvisorToolSemantics {
13
+ ): { mutatesWorkspace: boolean } {
16
14
  const definition = tool ?? getToolByName(call.function.name);
17
15
  const gate = context ? getToolGateDetails(call.function.name, call.function.arguments, context) : undefined;
18
16
  // Reuse the tool's side-effect contract, including shell/scripts, Trash and
@@ -33,8 +31,8 @@ export function advisorSemanticsFor(
33
31
  command?: unknown;
34
32
  };
35
33
  if (typeof input.command === 'string') {
36
- // 跑测试/构建/lint 只是核对现状,不该被当成"开始实施改动"而白白烧掉
37
- // pre-execution 检查点——即使它们可能写构建产物/缓存,不满足
34
+ // 跑测试/构建/lint 只是核对现状,不该被当成"开始实施改动"而过早提醒
35
+ // "动手前先咨询"——即使它们可能写构建产物/缓存,不满足
38
36
  // isReadOnlyShellCommand 的并发安全定义(见 opts 注释,那个场景仍要严格)。
39
37
  isReadOnly =
40
38
  isReadOnlyShellCommand(input.command) ||