@botbotgo/agent-harness 0.0.309 → 0.0.310

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 (195) hide show
  1. package/README.md +14 -0
  2. package/README.zh.md +14 -0
  3. package/dist/acp.d.ts +1 -116
  4. package/dist/acp.js +1 -310
  5. package/dist/api.d.ts +1 -1
  6. package/dist/api.js +1 -1
  7. package/dist/cli/chat-interactive.d.ts +24 -0
  8. package/dist/cli/chat-interactive.js +244 -0
  9. package/dist/cli/chat-rendering.d.ts +9 -0
  10. package/dist/cli/chat-rendering.js +102 -0
  11. package/dist/cli/chat-stream.d.ts +23 -0
  12. package/dist/cli/chat-stream.js +330 -0
  13. package/dist/cli/chat-ui.d.ts +20 -0
  14. package/dist/cli/chat-ui.js +198 -0
  15. package/dist/cli/chat-workspace.d.ts +15 -0
  16. package/dist/cli/chat-workspace.js +205 -0
  17. package/dist/cli/main.d.ts +52 -0
  18. package/dist/cli/main.js +323 -0
  19. package/dist/cli/managed-service-commands.d.ts +23 -0
  20. package/dist/cli/managed-service-commands.js +63 -0
  21. package/dist/cli/managed-service.d.ts +27 -0
  22. package/dist/cli/managed-service.js +61 -0
  23. package/dist/cli/options-init-chat.d.ts +16 -0
  24. package/dist/cli/options-init-chat.js +108 -0
  25. package/dist/cli/options-runtime.d.ts +27 -0
  26. package/dist/cli/options-runtime.js +158 -0
  27. package/dist/cli/options-serve.d.ts +24 -0
  28. package/dist/cli/options-serve.js +166 -0
  29. package/dist/cli/options.d.ts +5 -0
  30. package/dist/cli/options.js +47 -0
  31. package/dist/cli/process-guards.d.ts +14 -0
  32. package/dist/cli/process-guards.js +139 -0
  33. package/dist/cli/request-tree.d.ts +12 -0
  34. package/dist/cli/request-tree.js +296 -0
  35. package/dist/cli/runtime-commands.d.ts +15 -0
  36. package/dist/cli/runtime-commands.js +247 -0
  37. package/dist/cli/runtime-output.d.ts +5 -0
  38. package/dist/cli/runtime-output.js +124 -0
  39. package/dist/cli/server-commands.d.ts +36 -0
  40. package/dist/cli/server-commands.js +250 -0
  41. package/dist/cli/workspace.d.ts +6 -0
  42. package/dist/cli/workspace.js +71 -0
  43. package/dist/cli.d.ts +1 -78
  44. package/dist/cli.js +2 -3024
  45. package/dist/client/acp.d.ts +1 -50
  46. package/dist/client/acp.js +1 -219
  47. package/dist/client/in-process.d.ts +5 -5
  48. package/dist/client/index.d.ts +2 -2
  49. package/dist/client/index.js +1 -1
  50. package/dist/contracts/runtime-evaluation.d.ts +103 -0
  51. package/dist/contracts/runtime-evaluation.js +1 -0
  52. package/dist/contracts/runtime-memory.d.ts +162 -0
  53. package/dist/contracts/runtime-memory.js +1 -0
  54. package/dist/contracts/runtime-observability.d.ts +248 -0
  55. package/dist/contracts/runtime-observability.js +1 -0
  56. package/dist/contracts/runtime-requests.d.ts +342 -0
  57. package/dist/contracts/runtime-requests.js +1 -0
  58. package/dist/contracts/runtime-scheduling.d.ts +146 -0
  59. package/dist/contracts/runtime-scheduling.js +1 -0
  60. package/dist/contracts/runtime.d.ts +5 -1042
  61. package/dist/contracts/runtime.js +27 -1
  62. package/dist/flow/build-flow-graph.js +4 -875
  63. package/dist/flow/flow-graph-normalization.d.ts +56 -0
  64. package/dist/flow/flow-graph-normalization.js +214 -0
  65. package/dist/flow/flow-graph-runtime.d.ts +8 -0
  66. package/dist/flow/flow-graph-runtime.js +107 -0
  67. package/dist/flow/flow-graph-upstream.d.ts +18 -0
  68. package/dist/flow/flow-graph-upstream.js +498 -0
  69. package/dist/flow/types.d.ts +1 -1
  70. package/dist/index.d.ts +3 -3
  71. package/dist/index.js +1 -1
  72. package/dist/init-project.d.ts +1 -12
  73. package/dist/init-project.js +1 -651
  74. package/dist/{procedural → knowledge/procedural}/manager.d.ts +3 -3
  75. package/dist/{procedural → knowledge/procedural}/manager.js +6 -6
  76. package/dist/mcp.d.ts +2 -76
  77. package/dist/mcp.js +2 -428
  78. package/dist/package-version.d.ts +1 -1
  79. package/dist/package-version.js +1 -1
  80. package/dist/persistence/file-store.js +1 -1
  81. package/dist/persistence/sqlite-runtime.d.ts +19 -0
  82. package/dist/persistence/sqlite-runtime.js +86 -0
  83. package/dist/persistence/sqlite-store.js +11 -99
  84. package/dist/{request-events.d.ts → projections/request-events.d.ts} +1 -1
  85. package/dist/{upstream-events.js → projections/upstream-events.js} +1 -1
  86. package/dist/protocol/a2a/http-discovery.d.ts +39 -0
  87. package/dist/protocol/a2a/http-discovery.js +178 -0
  88. package/dist/protocol/a2a/http-rpc.d.ts +28 -0
  89. package/dist/protocol/a2a/http-rpc.js +623 -0
  90. package/dist/protocol/a2a/http.d.ts +72 -1
  91. package/dist/protocol/a2a/http.js +14 -1124
  92. package/dist/protocol/a2a/task-state.d.ts +29 -0
  93. package/dist/protocol/a2a/task-state.js +317 -0
  94. package/dist/protocol/acp/client.js +1 -1
  95. package/dist/protocol/acp/harness-client.d.ts +50 -0
  96. package/dist/protocol/acp/harness-client.js +219 -0
  97. package/dist/protocol/acp/server.d.ts +116 -0
  98. package/dist/protocol/acp/server.js +310 -0
  99. package/dist/protocol/ag-ui/http.js +1 -1
  100. package/dist/protocol/mcp/server.d.ts +76 -0
  101. package/dist/protocol/mcp/server.js +428 -0
  102. package/dist/resource/backend/workspace-scoped-backend.d.ts +40 -0
  103. package/dist/resource/backend/workspace-scoped-backend.js +296 -0
  104. package/dist/resource/mcp/tool-support.d.ts +35 -0
  105. package/dist/resource/mcp/tool-support.js +296 -0
  106. package/dist/resource/mcp-tool-support.d.ts +2 -35
  107. package/dist/resource/mcp-tool-support.js +2 -296
  108. package/dist/resource/providers/resource-provider.d.ts +22 -0
  109. package/dist/resource/providers/resource-provider.js +215 -0
  110. package/dist/resource/resource-impl.d.ts +3 -33
  111. package/dist/resource/resource-impl.js +2 -808
  112. package/dist/resource/resource-types.d.ts +33 -0
  113. package/dist/resource/resource-types.js +1 -0
  114. package/dist/resource/tools/function-tool-resolver.d.ts +2 -0
  115. package/dist/resource/tools/function-tool-resolver.js +306 -0
  116. package/dist/runtime/adapter/middleware-assembly.js +1 -1
  117. package/dist/runtime/adapter/model/invocation-request.js +2 -2
  118. package/dist/runtime/adapter/model/message-assembly.js +1 -1
  119. package/dist/runtime/agent-runtime-adapter.d.ts +3 -63
  120. package/dist/runtime/agent-runtime-adapter.js +5 -233
  121. package/dist/runtime/agent-runtime-assembly.d.ts +67 -0
  122. package/dist/runtime/agent-runtime-assembly.js +211 -0
  123. package/dist/runtime/harness/background-runtime.d.ts +1 -1
  124. package/dist/runtime/harness/events/event-sink.js +1 -1
  125. package/dist/runtime/harness/events/runtime-event-operations.d.ts +1 -1
  126. package/dist/runtime/harness/events/streaming.js +1 -1
  127. package/dist/runtime/harness/public-shapes.d.ts +43 -0
  128. package/dist/runtime/harness/public-shapes.js +186 -0
  129. package/dist/runtime/harness/run/inspection.js +2 -2
  130. package/dist/runtime/harness/run/resources.js +1 -1
  131. package/dist/runtime/harness/run/surface-semantics.js +1 -1
  132. package/dist/runtime/harness/system/inventory.d.ts +1 -1
  133. package/dist/runtime/harness/system/inventory.js +2 -2
  134. package/dist/runtime/harness/system/policy-engine.js +1 -1
  135. package/dist/runtime/harness/system/runtime-memory-manager.js +1 -1
  136. package/dist/runtime/harness/system/skill-requirements.d.ts +1 -1
  137. package/dist/runtime/harness/system/skill-requirements.js +1 -1
  138. package/dist/runtime/harness.d.ts +2 -2
  139. package/dist/runtime/harness.js +7 -191
  140. package/dist/runtime/maintenance/checkpoint-maintenance.js +1 -1
  141. package/dist/runtime/maintenance/runtime-record-maintenance.js +1 -1
  142. package/dist/runtime/parsing/output-content.d.ts +11 -0
  143. package/dist/runtime/parsing/output-content.js +442 -0
  144. package/dist/runtime/parsing/output-parsing.d.ts +3 -29
  145. package/dist/runtime/parsing/output-parsing.js +3 -806
  146. package/dist/runtime/parsing/output-recovery.d.ts +14 -0
  147. package/dist/runtime/parsing/output-recovery.js +288 -0
  148. package/dist/runtime/parsing/output-tool-args.d.ts +4 -0
  149. package/dist/runtime/parsing/output-tool-args.js +120 -0
  150. package/dist/runtime/support/runtime-factories.js +1 -1
  151. package/dist/scaffold/init-project.d.ts +12 -0
  152. package/dist/scaffold/init-project.js +651 -0
  153. package/dist/{extensions.d.ts → tooling/extensions.d.ts} +1 -1
  154. package/dist/{extensions.js → tooling/extensions.js} +3 -3
  155. package/dist/{tool-modules.d.ts → tooling/module-loader.d.ts} +1 -1
  156. package/dist/{tool-modules.js → tooling/module-loader.js} +2 -2
  157. package/dist/workspace/agent-binding-compiler.js +2 -2
  158. package/dist/workspace/compile.js +2 -2
  159. package/dist/workspace/object-loader-paths.d.ts +11 -0
  160. package/dist/workspace/object-loader-paths.js +75 -0
  161. package/dist/workspace/object-loader-readers.d.ts +21 -0
  162. package/dist/workspace/object-loader-readers.js +187 -0
  163. package/dist/workspace/object-loader.d.ts +0 -1
  164. package/dist/workspace/object-loader.js +6 -260
  165. package/dist/workspace/resource-compilers.js +1 -1
  166. package/dist/workspace/support/discovery.js +1 -1
  167. package/package.json +1 -1
  168. package/dist/runtime/adapter/index.d.ts +0 -13
  169. package/dist/runtime/adapter/index.js +0 -13
  170. package/dist/runtime/harness/index.d.ts +0 -19
  171. package/dist/runtime/harness/index.js +0 -19
  172. package/dist/runtime/maintenance/index.d.ts +0 -4
  173. package/dist/runtime/maintenance/index.js +0 -4
  174. package/dist/runtime/parsing/index.d.ts +0 -2
  175. package/dist/runtime/parsing/index.js +0 -2
  176. package/dist/runtime/support/index.d.ts +0 -4
  177. package/dist/runtime/support/index.js +0 -4
  178. package/dist/workspace/support/index.d.ts +0 -2
  179. package/dist/workspace/support/index.js +0 -2
  180. /package/dist/{procedural → knowledge/procedural}/config.d.ts +0 -0
  181. /package/dist/{procedural → knowledge/procedural}/config.js +0 -0
  182. /package/dist/{procedural → knowledge/procedural}/index.d.ts +0 -0
  183. /package/dist/{procedural → knowledge/procedural}/index.js +0 -0
  184. /package/dist/{presentation.d.ts → projections/presentation.d.ts} +0 -0
  185. /package/dist/{presentation.js → projections/presentation.js} +0 -0
  186. /package/dist/{request-events.js → projections/request-events.js} +0 -0
  187. /package/dist/{upstream-events.d.ts → projections/upstream-events.d.ts} +0 -0
  188. /package/dist/runtime/{support → env}/runtime-env.d.ts +0 -0
  189. /package/dist/runtime/{support → env}/runtime-env.js +0 -0
  190. /package/dist/runtime/{support → layout}/runtime-layout.d.ts +0 -0
  191. /package/dist/runtime/{support → layout}/runtime-layout.js +0 -0
  192. /package/dist/runtime/{support → prompts}/runtime-prompts.d.ts +0 -0
  193. /package/dist/runtime/{support → prompts}/runtime-prompts.js +0 -0
  194. /package/dist/runtime/{support → skills}/skill-metadata.d.ts +0 -0
  195. /package/dist/runtime/{support → skills}/skill-metadata.js +0 -0
@@ -0,0 +1,14 @@
1
+ export declare function isToolCallValidationFailure(error: unknown): boolean;
2
+ export declare function isWorkspacePathScopeFailure(error: unknown): boolean;
3
+ export declare function isRepairableWriteTodosPlaceholderFailure(error: unknown): boolean;
4
+ export declare function isRepairableWriteTodosContentFailure(error: unknown): boolean;
5
+ export declare function isRepairableWriteTodosEmptyFailure(error: unknown): boolean;
6
+ export declare function isToolCallRecoveryFailure(error: unknown): boolean;
7
+ export declare function isRetrySafeInvalidToolSelectionError(value: unknown): boolean;
8
+ export declare function shouldValidateExecutionWithoutToolEvidence(request: unknown): boolean;
9
+ export declare function resolveExecutionWithoutToolEvidenceInstruction(request: unknown, result: unknown): string | null;
10
+ export declare function resolveExecutionWithoutToolEvidenceTextInstruction(request: unknown, assistantText: string, toolCallEvidence?: boolean): string | null;
11
+ export declare function resolveToolCallRecoveryInstruction(error: unknown): string | null;
12
+ export declare function appendToolRecoveryInstruction(input: unknown, instruction: string): unknown;
13
+ export declare function wrapResolvedModel<T>(value: T): T;
14
+ export { BROWSER_CAPABILITY_DISCLAIMER_RECOVERY_INSTRUCTION, EXECUTION_WITH_TOOL_EVIDENCE_INSTRUCTION, EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION, INVALID_TOOL_SELECTION_RECOVERY_INSTRUCTION, STRICT_TOOL_JSON_INSTRUCTION, WORKSPACE_RELATIVE_PATH_INSTRUCTION, WRITE_TODOS_DESCRIPTIVE_CONTENT_INSTRUCTION, WRITE_TODOS_FULL_ENTRY_INSTRUCTION, WRITE_TODOS_NON_EMPTY_INITIAL_LIST_INSTRUCTION } from "../prompts/runtime-prompts.js";
@@ -0,0 +1,288 @@
1
+ import { BROWSER_CAPABILITY_DISCLAIMER_RECOVERY_INSTRUCTION, EXECUTION_WITH_TOOL_EVIDENCE_INSTRUCTION, EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION, STRICT_TOOL_JSON_INSTRUCTION, WORKSPACE_RELATIVE_PATH_INSTRUCTION, WRITE_TODOS_DESCRIPTIVE_CONTENT_INSTRUCTION, WRITE_TODOS_FULL_ENTRY_INSTRUCTION, WRITE_TODOS_NON_EMPTY_INITIAL_LIST_INSTRUCTION, } from "../prompts/runtime-prompts.js";
2
+ import { hasToolCalls, readTextContent, wrapNormalizedMessage } from "./output-content.js";
3
+ function isToolCallParseFailure(error) {
4
+ if (!(error instanceof Error))
5
+ return false;
6
+ return /error parsing tool call:/i.test(error.message);
7
+ }
8
+ function isStructuredValidationIssue(value) {
9
+ if (typeof value !== "object" || !value || Array.isArray(value)) {
10
+ return false;
11
+ }
12
+ const typed = value;
13
+ return typeof typed.code === "string" && Array.isArray(typed.path) && (typed.message === undefined || typeof typed.message === "string");
14
+ }
15
+ export function isToolCallValidationFailure(error) {
16
+ if (!(error instanceof Error))
17
+ return false;
18
+ const message = error.message.trim();
19
+ if (!message)
20
+ return false;
21
+ try {
22
+ const direct = JSON.parse(message);
23
+ if (Array.isArray(direct) && direct.length > 0 && direct.every((issue) => isStructuredValidationIssue(issue) && issue.path.length > 0)) {
24
+ return true;
25
+ }
26
+ }
27
+ catch { }
28
+ if (/Invalid input:\s*expected .* received undefined/i.test(message) && /"path"\s*:\s*\[/.test(message)) {
29
+ return true;
30
+ }
31
+ return /Received tool input did not match expected schema/i.test(message) && /(?:→\s*at|at)\s+[\w[\].]+/i.test(message);
32
+ }
33
+ function collectErrorMessages(error) {
34
+ if (!error) {
35
+ return [];
36
+ }
37
+ if (error instanceof Error) {
38
+ const nested = Array.isArray(error.errors)
39
+ ? (error.errors ?? []).flatMap((item) => collectErrorMessages(item))
40
+ : [];
41
+ return [error.message, ...nested].filter((value) => typeof value === "string" && value.trim().length > 0);
42
+ }
43
+ if (typeof error === "string" && error.trim().length > 0) {
44
+ return [error];
45
+ }
46
+ if (typeof error === "object") {
47
+ const record = error;
48
+ return [record.message, record.error, record.details].flatMap((item) => collectErrorMessages(item));
49
+ }
50
+ return [];
51
+ }
52
+ export function isWorkspacePathScopeFailure(error) {
53
+ return collectErrorMessages(error).some((message) => /outside the workspace root|workspace-relative path/i.test(message));
54
+ }
55
+ export function isRepairableWriteTodosPlaceholderFailure(error) {
56
+ if (!(error instanceof Error))
57
+ return false;
58
+ const message = error.message.trim();
59
+ if (!message)
60
+ return false;
61
+ return /write_todos/i.test(message) && /descriptive task content|placeholder entries/i.test(message);
62
+ }
63
+ export function isRepairableWriteTodosContentFailure(error) {
64
+ if (!(error instanceof Error))
65
+ return false;
66
+ const message = error.message.trim();
67
+ if (!message)
68
+ return false;
69
+ return /write_todos/i.test(message) && /todos\[\d+\]\.content/i.test(message);
70
+ }
71
+ export function isRepairableWriteTodosEmptyFailure(error) {
72
+ if (!(error instanceof Error))
73
+ return false;
74
+ const message = error.message.trim();
75
+ if (!message)
76
+ return false;
77
+ return /write_todos/i.test(message) && /Initial write_todos call cannot use an empty todo list/i.test(message);
78
+ }
79
+ export function isToolCallRecoveryFailure(error) {
80
+ return (isToolCallParseFailure(error) ||
81
+ isToolCallValidationFailure(error) ||
82
+ isRepairableWriteTodosEmptyFailure(error) ||
83
+ isRepairableWriteTodosPlaceholderFailure(error) ||
84
+ isWorkspacePathScopeFailure(error));
85
+ }
86
+ function extractMessageContent(message) {
87
+ if (typeof message !== "object" || !message)
88
+ return "";
89
+ const typed = message;
90
+ if (typed.content !== undefined)
91
+ return readTextContent(typed.content);
92
+ if (typeof typed.kwargs === "object" && typed.kwargs) {
93
+ return readTextContent(typed.kwargs.content);
94
+ }
95
+ return "";
96
+ }
97
+ function extractLastUserMessageText(input) {
98
+ if (!Array.isArray(input) && !(typeof input === "object" && input && Array.isArray(input.messages))) {
99
+ return "";
100
+ }
101
+ const messages = Array.isArray(input) ? input : input.messages;
102
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
103
+ const message = messages[index];
104
+ if (typeof message !== "object" || !message)
105
+ continue;
106
+ const typed = message;
107
+ if (typed.role === "user") {
108
+ return extractMessageContent(message).trim();
109
+ }
110
+ const ids = Array.isArray(typed.id) ? typed.id.filter((item) => typeof item === "string") : [];
111
+ const typeName = ids.at(-1);
112
+ const runtimeType = typeof message._getType === "function"
113
+ ? message._getType()
114
+ : typeof message.getType === "function"
115
+ ? message.getType()
116
+ : undefined;
117
+ if (typeName === "HumanMessage" || runtimeType === "human") {
118
+ return extractMessageContent(message).trim();
119
+ }
120
+ if (typeof typed.kwargs === "object" && typed.kwargs && typed.kwargs.role === "user") {
121
+ return extractMessageContent(message).trim();
122
+ }
123
+ }
124
+ return "";
125
+ }
126
+ function isToolRequiredExecutionPrompt(text) {
127
+ if (!text)
128
+ return false;
129
+ return (/write_todos/i.test(text) ||
130
+ /\b(create|write|edit|read|show|display|append|run|execute|wait|sleep|repeat|loop|file|files|command)\b/i.test(text) ||
131
+ /(创建|写入|读取|显示|追加|执行|运行|等待|重复|文件|命令|步骤)/.test(text));
132
+ }
133
+ function isBrowserOrUrlTask(text) {
134
+ if (!text)
135
+ return false;
136
+ return (/https?:\/\/\S+/i.test(text) ||
137
+ /\b(url|urls|website|websites|web page|webpage|browser|browse|page summary|summari[sz]e.*page|open.*page)\b/i.test(text) ||
138
+ /(网址|链接|网页|网站|页面|浏览器|总结.*网页|总结.*页面|打开.*网页)/.test(text));
139
+ }
140
+ function claimsExecutionWithoutToolEvidence(text) {
141
+ if (!text)
142
+ return false;
143
+ return (/\b(completed|done|created|wrote|written|read|displayed|appended|executed|waited|result|results)\b/i.test(text) ||
144
+ /(已创建|已写入|已读取|已显示|已追加|已执行|已等待|执行结果|状态更新|步骤\s*\d+|文件内容)/.test(text));
145
+ }
146
+ function claimsMissingBrowserCapability(text) {
147
+ if (!text)
148
+ return false;
149
+ return (/\b(i do not have the capability to access external websites|i do not have access to external websites|i cannot access external websites|i can(?:not|'t) browse|i do not have (?:direct )?(?:web|browser|browsing) access|i do not have .*tool.*(?:website|url|browser)|i cannot summarize .* because .*tool.*failed|please provide (?:the )?text content.*i (?:will|can) summarize)\b/i.test(text) ||
150
+ /(我没有直接访问外部网站|我无法直接访问外部网站|我无法访问外部网站|我不能访问外部网站|我无法直接访问外部网站内容|我无法访问网页|请提供文本内容.*我将为您进行总结|我没有.*浏览.*工具|我没有.*网页抓取.*工具|我没有.*访问.*网站.*工具|我无法总结该网页内容,因为.*工具执行失败)/.test(text));
151
+ }
152
+ export function isRetrySafeInvalidToolSelectionError(value) {
153
+ const text = readTextContent(value).trim();
154
+ if (!text)
155
+ return false;
156
+ return /is not a valid tool, try one of \[/i.test(text);
157
+ }
158
+ export function shouldValidateExecutionWithoutToolEvidence(request) {
159
+ const userText = extractLastUserMessageText(request);
160
+ const browserOrUrlTask = isBrowserOrUrlTask(userText);
161
+ return browserOrUrlTask || isToolRequiredExecutionPrompt(userText);
162
+ }
163
+ function extractAssistantTextFromResult(result) {
164
+ if (typeof result === "object" && result && "messages" in result) {
165
+ const messages = result.messages;
166
+ if (Array.isArray(messages)) {
167
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
168
+ const message = messages[index];
169
+ if (typeof message !== "object" || !message)
170
+ continue;
171
+ const ids = Array.isArray(message.id)
172
+ ? message.id.filter((item) => typeof item === "string")
173
+ : [];
174
+ const typeName = ids.at(-1);
175
+ const runtimeType = typeof message._getType === "function"
176
+ ? message._getType()
177
+ : typeof message.getType === "function"
178
+ ? message.getType()
179
+ : undefined;
180
+ if (typeName === "AIMessage" || runtimeType === "ai") {
181
+ return extractMessageContent(message).trim();
182
+ }
183
+ }
184
+ }
185
+ }
186
+ return "";
187
+ }
188
+ export function resolveExecutionWithoutToolEvidenceInstruction(request, result) {
189
+ const assistantText = typeof result === "object" && result && "content" in result
190
+ ? readTextContent(result.content).trim()
191
+ : extractAssistantTextFromResult(result);
192
+ return resolveExecutionWithoutToolEvidenceTextInstruction(request, assistantText, hasToolCalls(result));
193
+ }
194
+ export function resolveExecutionWithoutToolEvidenceTextInstruction(request, assistantText, toolCallEvidence = false) {
195
+ const userText = extractLastUserMessageText(request);
196
+ const browserOrUrlTask = isBrowserOrUrlTask(userText);
197
+ if (!shouldValidateExecutionWithoutToolEvidence(request)) {
198
+ return null;
199
+ }
200
+ if (!assistantText || toolCallEvidence) {
201
+ return null;
202
+ }
203
+ if (browserOrUrlTask && claimsMissingBrowserCapability(assistantText)) {
204
+ return BROWSER_CAPABILITY_DISCLAIMER_RECOVERY_INSTRUCTION;
205
+ }
206
+ return claimsExecutionWithoutToolEvidence(assistantText) ? EXECUTION_WITH_TOOL_EVIDENCE_INSTRUCTION : null;
207
+ }
208
+ export function resolveToolCallRecoveryInstruction(error) {
209
+ if (isRepairableWriteTodosEmptyFailure(error)) {
210
+ return WRITE_TODOS_NON_EMPTY_INITIAL_LIST_INSTRUCTION;
211
+ }
212
+ if (isRepairableWriteTodosContentFailure(error)) {
213
+ return WRITE_TODOS_FULL_ENTRY_INSTRUCTION;
214
+ }
215
+ if (isRepairableWriteTodosPlaceholderFailure(error)) {
216
+ return WRITE_TODOS_DESCRIPTIVE_CONTENT_INSTRUCTION;
217
+ }
218
+ if (isWorkspacePathScopeFailure(error)) {
219
+ return WORKSPACE_RELATIVE_PATH_INSTRUCTION;
220
+ }
221
+ if (isToolCallRecoveryFailure(error)) {
222
+ return STRICT_TOOL_JSON_INSTRUCTION;
223
+ }
224
+ return null;
225
+ }
226
+ export function appendToolRecoveryInstruction(input, instruction) {
227
+ if (Array.isArray(input)) {
228
+ return [...input, { role: "system", content: instruction }];
229
+ }
230
+ if (typeof input === "object" && input && Array.isArray(input.messages)) {
231
+ return {
232
+ ...input,
233
+ messages: [...(input.messages), { role: "system", content: instruction }],
234
+ };
235
+ }
236
+ return input;
237
+ }
238
+ export function wrapResolvedModel(value) {
239
+ if (typeof value !== "object" || value === null)
240
+ return value;
241
+ const target = value;
242
+ return new Proxy(target, {
243
+ get(currentTarget, prop, receiver) {
244
+ const member = Reflect.get(currentTarget, prop, receiver);
245
+ if (prop === "invoke" && typeof member === "function") {
246
+ return async (...args) => {
247
+ let activeArgs = [...args];
248
+ for (let attempt = 0; attempt < 3; attempt += 1) {
249
+ try {
250
+ const normalized = wrapNormalizedMessage(await member.apply(currentTarget, activeArgs));
251
+ const executionRecoveryInstruction = resolveExecutionWithoutToolEvidenceInstruction(activeArgs[0], normalized);
252
+ if (!executionRecoveryInstruction) {
253
+ return normalized;
254
+ }
255
+ if (attempt === 2) {
256
+ throw new Error("Model claimed task execution without any tool calls after repeated recovery attempts. Refusing to treat that response as a successful execution.");
257
+ }
258
+ const nextInstruction = attempt === 0
259
+ ? executionRecoveryInstruction
260
+ : EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION;
261
+ activeArgs = [...activeArgs];
262
+ activeArgs[0] = appendToolRecoveryInstruction(activeArgs[0], nextInstruction);
263
+ }
264
+ catch (error) {
265
+ const recoveryInstruction = resolveToolCallRecoveryInstruction(error);
266
+ if (!recoveryInstruction) {
267
+ throw error;
268
+ }
269
+ if (attempt === 2) {
270
+ throw error;
271
+ }
272
+ activeArgs = [...activeArgs];
273
+ activeArgs[0] = appendToolRecoveryInstruction(activeArgs[0], recoveryInstruction);
274
+ }
275
+ }
276
+ throw new Error("Model invocation retry loop exited unexpectedly.");
277
+ };
278
+ }
279
+ if ((prop === "bindTools" || prop === "withConfig" || prop === "withStructuredOutput") && typeof member === "function") {
280
+ return (...args) => wrapResolvedModel(member.apply(currentTarget, args));
281
+ }
282
+ if (typeof member === "function")
283
+ return member.bind(currentTarget);
284
+ return member;
285
+ },
286
+ });
287
+ }
288
+ export { BROWSER_CAPABILITY_DISCLAIMER_RECOVERY_INSTRUCTION, EXECUTION_WITH_TOOL_EVIDENCE_INSTRUCTION, EXECUTION_WITH_TOOL_EVIDENCE_RETRY_INSTRUCTION, INVALID_TOOL_SELECTION_RECOVERY_INSTRUCTION, STRICT_TOOL_JSON_INSTRUCTION, WORKSPACE_RELATIVE_PATH_INSTRUCTION, WRITE_TODOS_DESCRIPTIVE_CONTENT_INSTRUCTION, WRITE_TODOS_FULL_ENTRY_INSTRUCTION, WRITE_TODOS_NON_EMPTY_INITIAL_LIST_INSTRUCTION } from "../prompts/runtime-prompts.js";
@@ -0,0 +1,4 @@
1
+ export declare function tryParseJson(value: string): unknown | null;
2
+ export declare function salvageToolArgs(value: unknown): Record<string, unknown> | null;
3
+ export declare function normalizeKnownToolArgs(toolName: unknown, args: Record<string, unknown>): Record<string, unknown>;
4
+ export declare function isLikelyToolArgsObject(value: unknown): boolean;
@@ -0,0 +1,120 @@
1
+ export function tryParseJson(value) {
2
+ try {
3
+ return JSON.parse(value);
4
+ }
5
+ catch {
6
+ return null;
7
+ }
8
+ }
9
+ function extractBalancedJsonObject(value) {
10
+ const start = value.indexOf("{");
11
+ if (start < 0)
12
+ return null;
13
+ let depth = 0;
14
+ let inString = false;
15
+ let escaping = false;
16
+ for (let index = start; index < value.length; index += 1) {
17
+ const char = value[index];
18
+ if (inString) {
19
+ if (escaping) {
20
+ escaping = false;
21
+ continue;
22
+ }
23
+ if (char === "\\") {
24
+ escaping = true;
25
+ continue;
26
+ }
27
+ if (char === "\"") {
28
+ inString = false;
29
+ }
30
+ continue;
31
+ }
32
+ if (char === "\"") {
33
+ inString = true;
34
+ continue;
35
+ }
36
+ if (char === "{") {
37
+ depth += 1;
38
+ continue;
39
+ }
40
+ if (char === "}") {
41
+ depth -= 1;
42
+ if (depth === 0) {
43
+ return value.slice(start, index + 1);
44
+ }
45
+ }
46
+ }
47
+ return null;
48
+ }
49
+ export function salvageToolArgs(value) {
50
+ if (typeof value === "object" && value && !Array.isArray(value)) {
51
+ return value;
52
+ }
53
+ if (typeof value !== "string") {
54
+ return null;
55
+ }
56
+ const trimmed = value.trim();
57
+ if (!trimmed) {
58
+ return {};
59
+ }
60
+ const direct = tryParseJson(trimmed);
61
+ if (typeof direct === "object" && direct && !Array.isArray(direct)) {
62
+ return direct;
63
+ }
64
+ const embedded = extractBalancedJsonObject(trimmed);
65
+ if (!embedded) {
66
+ return null;
67
+ }
68
+ const parsed = tryParseJson(embedded);
69
+ return typeof parsed === "object" && parsed && !Array.isArray(parsed) ? parsed : null;
70
+ }
71
+ function normalizeWriteTodosArgs(args) {
72
+ if (!Array.isArray(args.todos)) {
73
+ return args;
74
+ }
75
+ return {
76
+ ...args,
77
+ todos: args.todos.map((todo) => {
78
+ if (typeof todo !== "object" || !todo || Array.isArray(todo)) {
79
+ return todo;
80
+ }
81
+ const record = todo;
82
+ const content = typeof record.content === "string" && record.content.trim().length > 0
83
+ ? record.content
84
+ : typeof record.description === "string" && record.description.trim().length > 0
85
+ ? record.description
86
+ : undefined;
87
+ const normalized = {};
88
+ if (content !== undefined)
89
+ normalized.content = content;
90
+ if (typeof record.status === "string")
91
+ normalized.status = record.status;
92
+ return Object.keys(normalized).length > 0 ? normalized : todo;
93
+ }),
94
+ };
95
+ }
96
+ export function normalizeKnownToolArgs(toolName, args) {
97
+ if (toolName === "write_todos") {
98
+ return normalizeWriteTodosArgs(args);
99
+ }
100
+ return args;
101
+ }
102
+ export function isLikelyToolArgsObject(value) {
103
+ if (typeof value !== "object" || !value || Array.isArray(value)) {
104
+ return false;
105
+ }
106
+ const keys = Object.keys(value);
107
+ if (keys.length === 0 || keys.length > 8) {
108
+ return false;
109
+ }
110
+ if (keys.some((key) => ["messages", "output", "content", "todos", "files", "skillsMetadata", "memoryContents"].includes(key))) {
111
+ return false;
112
+ }
113
+ return Object.values(value).every((item) => {
114
+ if (item == null)
115
+ return true;
116
+ if (typeof item === "string" || typeof item === "number" || typeof item === "boolean")
117
+ return true;
118
+ return Array.isArray(item) && item.every((entry) => typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean");
119
+ });
120
+ }
@@ -3,7 +3,7 @@ import { MemorySaver } from "@langchain/langgraph";
3
3
  import { FileCheckpointSaver } from "../maintenance/file-checkpoint-saver.js";
4
4
  import { SqliteCheckpointSaver } from "../maintenance/sqlite-checkpoint-saver.js";
5
5
  import { createInMemoryStore, FileBackedStore, SqliteBackedStore } from "../harness/system/store.js";
6
- import { resolveKnowledgeFileStorePath, resolveKnowledgeStorePath, resolveRuntimeCheckpointerPath, } from "./runtime-layout.js";
6
+ import { resolveKnowledgeFileStorePath, resolveKnowledgeStorePath, resolveRuntimeCheckpointerPath, } from "../layout/runtime-layout.js";
7
7
  export function createStoreForConfig(storeConfig, runtimeRoot) {
8
8
  const kind = typeof storeConfig.kind === "string" ? storeConfig.kind : "FileStore";
9
9
  switch (kind) {
@@ -0,0 +1,12 @@
1
+ export type InitTemplate = "deep-research" | "single-agent";
2
+ export type InitProjectOptions = {
3
+ template?: InitTemplate;
4
+ provider?: string;
5
+ model?: string;
6
+ withWebSearch?: boolean;
7
+ };
8
+ export type InitProjectResult = {
9
+ projectRoot: string;
10
+ projectSlug: string;
11
+ };
12
+ export declare function initProject(projectRoot: string, projectName: string, options?: InitProjectOptions): Promise<InitProjectResult>;