@archmax-ai/harness 0.0.0

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 (351) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -0
  3. package/dist/agent.d.ts +174 -0
  4. package/dist/agent.js +140 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/assembly/compose.d.ts +170 -0
  7. package/dist/assembly/compose.js +391 -0
  8. package/dist/assembly/compose.js.map +1 -0
  9. package/dist/assembly/delegation-registry.d.ts +5 -0
  10. package/dist/assembly/delegation-registry.js +118 -0
  11. package/dist/assembly/delegation-registry.js.map +1 -0
  12. package/dist/assembly/index.d.ts +192 -0
  13. package/dist/assembly/index.js +265 -0
  14. package/dist/assembly/index.js.map +1 -0
  15. package/dist/assembly/plain.d.ts +7 -0
  16. package/dist/assembly/plain.js +41 -0
  17. package/dist/assembly/plain.js.map +1 -0
  18. package/dist/authoring-skill/archmax-harness/README.md +76 -0
  19. package/dist/authoring-skill/archmax-harness/SKILL.md +241 -0
  20. package/dist/authoring-skill/archmax-harness/references/backend-integration.md +626 -0
  21. package/dist/authoring-skill/archmax-harness/references/cases.md +41 -0
  22. package/dist/authoring-skill/archmax-harness/references/diagnostics.md +51 -0
  23. package/dist/authoring-skill/archmax-harness/references/hook-and-test-scripts.md +1070 -0
  24. package/dist/authoring-skill/archmax-harness/references/hooks-and-scripts.md +82 -0
  25. package/dist/authoring-skill/archmax-harness/references/wiring.md +101 -0
  26. package/dist/authoring-skill/archmax-harness/references/workflow-schema.md +1631 -0
  27. package/dist/authoring-skill/archmax-harness/references/workflow-yaml.md +241 -0
  28. package/dist/behaviour/support.d.ts +232 -0
  29. package/dist/behaviour/support.js +339 -0
  30. package/dist/behaviour/support.js.map +1 -0
  31. package/dist/cli/banner.d.ts +11 -0
  32. package/dist/cli/banner.js +29 -0
  33. package/dist/cli/banner.js.map +1 -0
  34. package/dist/cli/bootstrap.d.ts +33 -0
  35. package/dist/cli/bootstrap.js +153 -0
  36. package/dist/cli/bootstrap.js.map +1 -0
  37. package/dist/cli/command.d.ts +39 -0
  38. package/dist/cli/command.js +97 -0
  39. package/dist/cli/command.js.map +1 -0
  40. package/dist/cli/state-flow.d.ts +46 -0
  41. package/dist/cli/state-flow.js +268 -0
  42. package/dist/cli/state-flow.js.map +1 -0
  43. package/dist/cli/style.d.ts +41 -0
  44. package/dist/cli/style.js +64 -0
  45. package/dist/cli/style.js.map +1 -0
  46. package/dist/cli/turn.d.ts +41 -0
  47. package/dist/cli/turn.js +161 -0
  48. package/dist/cli/turn.js.map +1 -0
  49. package/dist/cli.d.ts +10 -0
  50. package/dist/cli.js +426 -0
  51. package/dist/cli.js.map +1 -0
  52. package/dist/core/code-description.d.ts +22 -0
  53. package/dist/core/code-description.js +38 -0
  54. package/dist/core/code-description.js.map +1 -0
  55. package/dist/core/deepagents.d.ts +183 -0
  56. package/dist/core/deepagents.js +128 -0
  57. package/dist/core/deepagents.js.map +1 -0
  58. package/dist/core/events.d.ts +350 -0
  59. package/dist/core/events.js +205 -0
  60. package/dist/core/events.js.map +1 -0
  61. package/dist/core/frontmatter.d.ts +15 -0
  62. package/dist/core/frontmatter.js +32 -0
  63. package/dist/core/frontmatter.js.map +1 -0
  64. package/dist/core/listing-redact.d.ts +37 -0
  65. package/dist/core/listing-redact.js +88 -0
  66. package/dist/core/listing-redact.js.map +1 -0
  67. package/dist/core/match.d.ts +26 -0
  68. package/dist/core/match.js +75 -0
  69. package/dist/core/match.js.map +1 -0
  70. package/dist/core/message-readers.d.ts +84 -0
  71. package/dist/core/message-readers.js +159 -0
  72. package/dist/core/message-readers.js.map +1 -0
  73. package/dist/core/messages.d.ts +49 -0
  74. package/dist/core/messages.js +85 -0
  75. package/dist/core/messages.js.map +1 -0
  76. package/dist/core/mount-prompt.d.ts +28 -0
  77. package/dist/core/mount-prompt.js +55 -0
  78. package/dist/core/mount-prompt.js.map +1 -0
  79. package/dist/core/mount-redact.d.ts +28 -0
  80. package/dist/core/mount-redact.js +32 -0
  81. package/dist/core/mount-redact.js.map +1 -0
  82. package/dist/core/mounts.d.ts +88 -0
  83. package/dist/core/mounts.js +147 -0
  84. package/dist/core/mounts.js.map +1 -0
  85. package/dist/core/path-mapping.d.ts +52 -0
  86. package/dist/core/path-mapping.js +113 -0
  87. package/dist/core/path-mapping.js.map +1 -0
  88. package/dist/core/platform-prompt.generated.d.ts +2 -0
  89. package/dist/core/platform-prompt.generated.js +4 -0
  90. package/dist/core/platform-prompt.generated.js.map +1 -0
  91. package/dist/core/prompt.d.ts +42 -0
  92. package/dist/core/prompt.js +75 -0
  93. package/dist/core/prompt.js.map +1 -0
  94. package/dist/core/session-id.d.ts +38 -0
  95. package/dist/core/session-id.js +61 -0
  96. package/dist/core/session-id.js.map +1 -0
  97. package/dist/core/session-store.d.ts +85 -0
  98. package/dist/core/session-store.js +149 -0
  99. package/dist/core/session-store.js.map +1 -0
  100. package/dist/core/session-zone.d.ts +54 -0
  101. package/dist/core/session-zone.js +82 -0
  102. package/dist/core/session-zone.js.map +1 -0
  103. package/dist/core/skill-prompt.d.ts +31 -0
  104. package/dist/core/skill-prompt.js +54 -0
  105. package/dist/core/skill-prompt.js.map +1 -0
  106. package/dist/core/skill-redact.d.ts +15 -0
  107. package/dist/core/skill-redact.js +27 -0
  108. package/dist/core/skill-redact.js.map +1 -0
  109. package/dist/core/skills.d.ts +172 -0
  110. package/dist/core/skills.js +214 -0
  111. package/dist/core/skills.js.map +1 -0
  112. package/dist/core/tool-mocks.d.ts +23 -0
  113. package/dist/core/tool-mocks.js +39 -0
  114. package/dist/core/tool-mocks.js.map +1 -0
  115. package/dist/core/tool-telemetry.d.ts +16 -0
  116. package/dist/core/tool-telemetry.js +40 -0
  117. package/dist/core/tool-telemetry.js.map +1 -0
  118. package/dist/core/usage.d.ts +114 -0
  119. package/dist/core/usage.js +226 -0
  120. package/dist/core/usage.js.map +1 -0
  121. package/dist/core/workspace-context.d.ts +136 -0
  122. package/dist/core/workspace-context.js +178 -0
  123. package/dist/core/workspace-context.js.map +1 -0
  124. package/dist/core/workspace-prompt.d.ts +7 -0
  125. package/dist/core/workspace-prompt.js +102 -0
  126. package/dist/core/workspace-prompt.js.map +1 -0
  127. package/dist/core/workspace-router.d.ts +61 -0
  128. package/dist/core/workspace-router.js +145 -0
  129. package/dist/core/workspace-router.js.map +1 -0
  130. package/dist/core/workspace.d.ts +85 -0
  131. package/dist/core/workspace.js +193 -0
  132. package/dist/core/workspace.js.map +1 -0
  133. package/dist/core/zones.d.ts +181 -0
  134. package/dist/core/zones.js +202 -0
  135. package/dist/core/zones.js.map +1 -0
  136. package/dist/env.d.ts +99 -0
  137. package/dist/env.js +271 -0
  138. package/dist/env.js.map +1 -0
  139. package/dist/index.d.ts +265 -0
  140. package/dist/index.js +197 -0
  141. package/dist/index.js.map +1 -0
  142. package/dist/kernel/kernel.d.ts +192 -0
  143. package/dist/kernel/kernel.js +751 -0
  144. package/dist/kernel/kernel.js.map +1 -0
  145. package/dist/lifecycle/hook-shape.d.ts +44 -0
  146. package/dist/lifecycle/hook-shape.js +66 -0
  147. package/dist/lifecycle/hook-shape.js.map +1 -0
  148. package/dist/lifecycle/runner.d.ts +177 -0
  149. package/dist/lifecycle/runner.js +372 -0
  150. package/dist/lifecycle/runner.js.map +1 -0
  151. package/dist/lifecycle/transcript.d.ts +27 -0
  152. package/dist/lifecycle/transcript.js +43 -0
  153. package/dist/lifecycle/transcript.js.map +1 -0
  154. package/dist/machine/allow.d.ts +65 -0
  155. package/dist/machine/allow.js +107 -0
  156. package/dist/machine/allow.js.map +1 -0
  157. package/dist/machine/delegation.d.ts +9 -0
  158. package/dist/machine/delegation.js +10 -0
  159. package/dist/machine/delegation.js.map +1 -0
  160. package/dist/machine/diagnostic.d.ts +14 -0
  161. package/dist/machine/diagnostic.js +2 -0
  162. package/dist/machine/diagnostic.js.map +1 -0
  163. package/dist/machine/lint-spec.d.ts +4 -0
  164. package/dist/machine/lint-spec.js +266 -0
  165. package/dist/machine/lint-spec.js.map +1 -0
  166. package/dist/machine/load-spec.d.ts +90 -0
  167. package/dist/machine/load-spec.js +120 -0
  168. package/dist/machine/load-spec.js.map +1 -0
  169. package/dist/machine/machine.d.ts +273 -0
  170. package/dist/machine/machine.js +551 -0
  171. package/dist/machine/machine.js.map +1 -0
  172. package/dist/machine/mount-grants.d.ts +25 -0
  173. package/dist/machine/mount-grants.js +24 -0
  174. package/dist/machine/mount-grants.js.map +1 -0
  175. package/dist/machine/slug.d.ts +14 -0
  176. package/dist/machine/slug.js +17 -0
  177. package/dist/machine/slug.js.map +1 -0
  178. package/dist/machine/spec-schema.d.ts +662 -0
  179. package/dist/machine/spec-schema.js +717 -0
  180. package/dist/machine/spec-schema.js.map +1 -0
  181. package/dist/machine/tool-names.d.ts +98 -0
  182. package/dist/machine/tool-names.js +144 -0
  183. package/dist/machine/tool-names.js.map +1 -0
  184. package/dist/machine/triggers.d.ts +114 -0
  185. package/dist/machine/triggers.js +165 -0
  186. package/dist/machine/triggers.js.map +1 -0
  187. package/dist/machine/types.d.ts +186 -0
  188. package/dist/machine/types.js +12 -0
  189. package/dist/machine/types.js.map +1 -0
  190. package/dist/machine/validate-spec.d.ts +42 -0
  191. package/dist/machine/validate-spec.js +29 -0
  192. package/dist/machine/validate-spec.js.map +1 -0
  193. package/dist/machine/variables.d.ts +196 -0
  194. package/dist/machine/variables.js +415 -0
  195. package/dist/machine/variables.js.map +1 -0
  196. package/dist/public/cli.d.ts +15 -0
  197. package/dist/public/cli.js +14 -0
  198. package/dist/public/cli.js.map +1 -0
  199. package/dist/public/messages.d.ts +33 -0
  200. package/dist/public/messages.js +33 -0
  201. package/dist/public/messages.js.map +1 -0
  202. package/dist/public/sandbox.d.ts +99 -0
  203. package/dist/public/sandbox.js +32 -0
  204. package/dist/public/sandbox.js.map +1 -0
  205. package/dist/public/spec.d.ts +147 -0
  206. package/dist/public/spec.js +149 -0
  207. package/dist/public/spec.js.map +1 -0
  208. package/dist/public/testing.d.ts +71 -0
  209. package/dist/public/testing.js +39 -0
  210. package/dist/public/testing.js.map +1 -0
  211. package/dist/rubrics/rubrics.d.ts +135 -0
  212. package/dist/rubrics/rubrics.js +145 -0
  213. package/dist/rubrics/rubrics.js.map +1 -0
  214. package/dist/runtime/contract.d.ts +73 -0
  215. package/dist/runtime/contract.js +96 -0
  216. package/dist/runtime/contract.js.map +1 -0
  217. package/dist/sandbox/assets/parts/core.js +22 -0
  218. package/dist/sandbox/assets/parts/lifecycle-hook.js +47 -0
  219. package/dist/sandbox/bridge.d.ts +16 -0
  220. package/dist/sandbox/bridge.js +95 -0
  221. package/dist/sandbox/bridge.js.map +1 -0
  222. package/dist/sandbox/executor.d.ts +46 -0
  223. package/dist/sandbox/executor.js +119 -0
  224. package/dist/sandbox/executor.js.map +1 -0
  225. package/dist/sandbox/imports.d.ts +33 -0
  226. package/dist/sandbox/imports.js +67 -0
  227. package/dist/sandbox/imports.js.map +1 -0
  228. package/dist/sandbox/prelude.d.ts +12 -0
  229. package/dist/sandbox/prelude.js +51 -0
  230. package/dist/sandbox/prelude.js.map +1 -0
  231. package/dist/sandbox/ptc-gateway.d.ts +104 -0
  232. package/dist/sandbox/ptc-gateway.js +167 -0
  233. package/dist/sandbox/ptc-gateway.js.map +1 -0
  234. package/dist/sandbox/runtime.d.ts +59 -0
  235. package/dist/sandbox/runtime.js +51 -0
  236. package/dist/sandbox/runtime.js.map +1 -0
  237. package/dist/sandbox/tools.d.ts +34 -0
  238. package/dist/sandbox/tools.js +147 -0
  239. package/dist/sandbox/tools.js.map +1 -0
  240. package/dist/sessions/operations.d.ts +79 -0
  241. package/dist/sessions/operations.js +121 -0
  242. package/dist/sessions/operations.js.map +1 -0
  243. package/dist/sessions/resolve.d.ts +97 -0
  244. package/dist/sessions/resolve.js +145 -0
  245. package/dist/sessions/resolve.js.map +1 -0
  246. package/dist/sessions/resume.d.ts +242 -0
  247. package/dist/sessions/resume.js +288 -0
  248. package/dist/sessions/resume.js.map +1 -0
  249. package/dist/sessions/scope.d.ts +99 -0
  250. package/dist/sessions/scope.js +145 -0
  251. package/dist/sessions/scope.js.map +1 -0
  252. package/dist/sessions/summary.d.ts +65 -0
  253. package/dist/sessions/summary.js +56 -0
  254. package/dist/sessions/summary.js.map +1 -0
  255. package/dist/testing/assertions.d.ts +30 -0
  256. package/dist/testing/assertions.js +231 -0
  257. package/dist/testing/assertions.js.map +1 -0
  258. package/dist/testing/case-document.d.ts +141 -0
  259. package/dist/testing/case-document.js +51 -0
  260. package/dist/testing/case-document.js.map +1 -0
  261. package/dist/testing/case-schema.d.ts +29 -0
  262. package/dist/testing/case-schema.js +519 -0
  263. package/dist/testing/case-schema.js.map +1 -0
  264. package/dist/testing/discovery.d.ts +10 -0
  265. package/dist/testing/discovery.js +24 -0
  266. package/dist/testing/discovery.js.map +1 -0
  267. package/dist/testing/driver.d.ts +78 -0
  268. package/dist/testing/driver.js +117 -0
  269. package/dist/testing/driver.js.map +1 -0
  270. package/dist/testing/grade.d.ts +116 -0
  271. package/dist/testing/grade.js +261 -0
  272. package/dist/testing/grade.js.map +1 -0
  273. package/dist/testing/interpreter.d.ts +55 -0
  274. package/dist/testing/interpreter.js +103 -0
  275. package/dist/testing/interpreter.js.map +1 -0
  276. package/dist/testing/mock-middleware.d.ts +5 -0
  277. package/dist/testing/mock-middleware.js +33 -0
  278. package/dist/testing/mock-middleware.js.map +1 -0
  279. package/dist/testing/runner.d.ts +205 -0
  280. package/dist/testing/runner.js +266 -0
  281. package/dist/testing/runner.js.map +1 -0
  282. package/dist/testing/target.d.ts +27 -0
  283. package/dist/testing/target.js +21 -0
  284. package/dist/testing/target.js.map +1 -0
  285. package/dist/validate/validate.d.ts +41 -0
  286. package/dist/validate/validate.js +669 -0
  287. package/dist/validate/validate.js.map +1 -0
  288. package/dist/workflow/agent-tools.d.ts +10 -0
  289. package/dist/workflow/agent-tools.js +10 -0
  290. package/dist/workflow/agent-tools.js.map +1 -0
  291. package/dist/workflow/checkpointer.d.ts +52 -0
  292. package/dist/workflow/checkpointer.js +200 -0
  293. package/dist/workflow/checkpointer.js.map +1 -0
  294. package/dist/workflow/control-tools.d.ts +174 -0
  295. package/dist/workflow/control-tools.js +468 -0
  296. package/dist/workflow/control-tools.js.map +1 -0
  297. package/dist/workflow/governance.d.ts +104 -0
  298. package/dist/workflow/governance.js +546 -0
  299. package/dist/workflow/governance.js.map +1 -0
  300. package/dist/workflow/middleware.d.ts +85 -0
  301. package/dist/workflow/middleware.js +283 -0
  302. package/dist/workflow/middleware.js.map +1 -0
  303. package/dist/workflow/on-error.d.ts +25 -0
  304. package/dist/workflow/on-error.js +58 -0
  305. package/dist/workflow/on-error.js.map +1 -0
  306. package/dist/workflow/parks.d.ts +46 -0
  307. package/dist/workflow/parks.js +513 -0
  308. package/dist/workflow/parks.js.map +1 -0
  309. package/dist/workflow/paths.d.ts +67 -0
  310. package/dist/workflow/paths.js +108 -0
  311. package/dist/workflow/paths.js.map +1 -0
  312. package/dist/workflow/prompt-cache.d.ts +70 -0
  313. package/dist/workflow/prompt-cache.js +103 -0
  314. package/dist/workflow/prompt-cache.js.map +1 -0
  315. package/dist/workflow/prompt-pruning.d.ts +20 -0
  316. package/dist/workflow/prompt-pruning.js +83 -0
  317. package/dist/workflow/prompt-pruning.js.map +1 -0
  318. package/dist/workflow/render-prompt.d.ts +45 -0
  319. package/dist/workflow/render-prompt.js +140 -0
  320. package/dist/workflow/render-prompt.js.map +1 -0
  321. package/dist/workflow/runtime-config.d.ts +7 -0
  322. package/dist/workflow/runtime-config.js +9 -0
  323. package/dist/workflow/runtime-config.js.map +1 -0
  324. package/dist/workflow/session-artifacts.d.ts +90 -0
  325. package/dist/workflow/session-artifacts.js +134 -0
  326. package/dist/workflow/session-artifacts.js.map +1 -0
  327. package/dist/workflow/session-view.d.ts +31 -0
  328. package/dist/workflow/session-view.js +94 -0
  329. package/dist/workflow/session-view.js.map +1 -0
  330. package/dist/workflow/snapshot.d.ts +14 -0
  331. package/dist/workflow/snapshot.js +97 -0
  332. package/dist/workflow/snapshot.js.map +1 -0
  333. package/dist/workflow/state.d.ts +347 -0
  334. package/dist/workflow/state.js +322 -0
  335. package/dist/workflow/state.js.map +1 -0
  336. package/dist/workflow/sub-workflow.d.ts +174 -0
  337. package/dist/workflow/sub-workflow.js +392 -0
  338. package/dist/workflow/sub-workflow.js.map +1 -0
  339. package/dist/workflow/tool-service.d.ts +48 -0
  340. package/dist/workflow/tool-service.js +291 -0
  341. package/dist/workflow/tool-service.js.map +1 -0
  342. package/dist/workflow/turn-boundary.d.ts +39 -0
  343. package/dist/workflow/turn-boundary.js +128 -0
  344. package/dist/workflow/turn-boundary.js.map +1 -0
  345. package/dist/workflow/turn-runner.d.ts +40 -0
  346. package/dist/workflow/turn-runner.js +122 -0
  347. package/dist/workflow/turn-runner.js.map +1 -0
  348. package/dist/workflow/workflow-tools.d.ts +46 -0
  349. package/dist/workflow/workflow-tools.js +90 -0
  350. package/dist/workflow/workflow-tools.js.map +1 -0
  351. package/package.json +119 -0
@@ -0,0 +1,145 @@
1
+ import { normalizeHooks } from "../lifecycle/hook-shape.js";
2
+ import { ADVANCE_TOOL } from "../machine/tool-names.js";
3
+ /**
4
+ * The structured output a rubric with an iteration budget must return. Applied
5
+ * automatically, so a grader's output is a contract rather than a prompt
6
+ * convention.
7
+ */
8
+ export const RUBRIC_VERDICT_SCHEMA = {
9
+ type: "object",
10
+ properties: {
11
+ verdict: { type: "string", enum: ["ok", "correct", "veto"] },
12
+ reason: { type: "string" },
13
+ },
14
+ required: ["verdict", "reason"],
15
+ };
16
+ /**
17
+ * The id one inline rubric is registered and dispatched under. Positional
18
+ * because an inline rubric has no name: reordering a phase's hooks re-keys them,
19
+ * which is the same class of change as editing the spec at all (it moves the
20
+ * spec hash).
21
+ */
22
+ export function rubricId(state, phase, index) {
23
+ return `${state}--${phase}--${index}`;
24
+ }
25
+ /** Whether a value is a usable verdict. Anything else has graded nothing. */
26
+ export function isRubricVerdict(value) {
27
+ if (!value || typeof value !== "object")
28
+ return false;
29
+ const v = value;
30
+ return v.verdict === "ok" || v.verdict === "correct" || v.verdict === "veto";
31
+ }
32
+ /**
33
+ * The structured-output schema every dispatch requests: the verdict schema,
34
+ * unconditionally.
35
+ *
36
+ * Not conditional on `max_iterations`, as it was when a grader was a subagent
37
+ * that might also be a general-purpose helper. A rubric only ever grades, so a
38
+ * grader that needs no retries still has to answer in the verdict vocabulary —
39
+ * and without the schema its answer arrives as prose, parses to no verdict, and
40
+ * fails closed on a transition the author expected it to wave through.
41
+ */
42
+ export function resolveRubricResponseFormat(_rubric) {
43
+ return RUBRIC_VERDICT_SCHEMA;
44
+ }
45
+ /** The compact task payload a grader is handed: the request, the transcript, and where it happened. */
46
+ export function buildRubricTaskDescription(args) {
47
+ return JSON.stringify({
48
+ userRequest: args.userRequest ?? null,
49
+ history: args.history ?? [],
50
+ state: args.state ?? null,
51
+ phase: args.phase ?? null,
52
+ }, null, 2);
53
+ }
54
+ /**
55
+ * Map an `after`-hook verdict to an `archmax_advance` rejection outcome. One
56
+ * implementation for every hook kind: the retry flow (bounded iterations with
57
+ * remaining-attempt guidance) is identical whether the verdict came from a
58
+ * rubric or a script — only the label differs (`rubric` vs `hook`).
59
+ */
60
+ export function rubricTransitionOutcome(verdict, opts) {
61
+ const label = verdict.rubric ? "rubric" : "hook";
62
+ if (verdict.verdict === "ok") {
63
+ return { reason: null, budgetExhausted: false, consumesIteration: false };
64
+ }
65
+ if (verdict.verdict === "veto") {
66
+ // A deliberate veto charges nothing: no retry was offered to bill for.
67
+ return {
68
+ reason: `${label} veto: ${verdict.reason}`,
69
+ budgetExhausted: false,
70
+ consumesIteration: false,
71
+ };
72
+ }
73
+ const max = Math.max(0, opts.maxIterations);
74
+ if (opts.iterationsUsed >= max) {
75
+ return {
76
+ reason: `${label} veto: reply still incomplete after ${max} attempt(s) — ${verdict.reason}`,
77
+ budgetExhausted: true,
78
+ consumesIteration: false,
79
+ };
80
+ }
81
+ const remaining = max - opts.iterationsUsed;
82
+ const target = opts.to ? `${ADVANCE_TOOL}({ to: "${opts.to}" })` : ADVANCE_TOOL;
83
+ return {
84
+ reason: `${label}: reply incomplete — ${verdict.reason}. ` +
85
+ `Update your answer and call ${target} again. (${remaining} attempt(s) remaining)`,
86
+ budgetExhausted: false,
87
+ consumesIteration: true,
88
+ };
89
+ }
90
+ /**
91
+ * The rejection reason alone, for callers that do not decide the retry budget.
92
+ */
93
+ export function rubricTransitionReason(verdict, opts) {
94
+ return rubricTransitionOutcome(verdict, opts).reason;
95
+ }
96
+ /**
97
+ * The rubric registry for one machine: every inline rubric its states declare,
98
+ * keyed by {@link rubricId}. Walks the spec rather than reading a root block,
99
+ * because a grader lives on the hook that applies it.
100
+ *
101
+ * Scoped to this spec, so a delegated child is graded by its own standards; two
102
+ * states declaring the same criteria produce two entries, which is the accepted
103
+ * cost of a state being legible on its own.
104
+ */
105
+ export function rubricsFromSpec(spec) {
106
+ const registry = new Map();
107
+ for (const [state, declared] of Object.entries(spec.states ?? {})) {
108
+ for (const phase of ["before", "after"]) {
109
+ normalizeHooks(declared?.[phase]).forEach((hook, index) => {
110
+ const declaration = hook.rubric;
111
+ if (declaration === undefined || typeof declaration !== "object")
112
+ return;
113
+ const id = rubricId(state, phase, index);
114
+ registry.set(id, { ...declaration, id, state, phase, index });
115
+ });
116
+ }
117
+ }
118
+ return registry;
119
+ }
120
+ /**
121
+ * Project the registry into the Deep Agents subagent shape so the framework
122
+ * registers the `task` tool the runtime dispatches through. These are never
123
+ * disclosed to the agent: `task` is withheld in every state and grantable by
124
+ * nothing, so registering a grader here gives the graded agent no reach.
125
+ *
126
+ * `model` resolves the grader's own model when it declared one, else the
127
+ * assembly's `rubric`-role model.
128
+ */
129
+ export function rubricsAsSubagents(registry, modelFor) {
130
+ return [...registry.values()].map((rubric) => {
131
+ const responseFormat = resolveRubricResponseFormat(rubric);
132
+ const model = modelFor?.(rubric);
133
+ return {
134
+ name: rubric.id,
135
+ // A grader is dispatched by the runtime under its positional id, never
136
+ // chosen from a menu by the agent, so the description exists only for the
137
+ // framework's own tool schema — which no state is ever shown.
138
+ description: `Grading rubric on '${rubric.state}' (${rubric.phase}).`,
139
+ systemPrompt: rubric.instructions,
140
+ ...(responseFormat !== undefined ? { responseFormat } : {}),
141
+ ...(model !== undefined ? { model } : {}),
142
+ };
143
+ });
144
+ }
145
+ //# sourceMappingURL=rubrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rubrics.js","sourceRoot":"","sources":["../../src/rubrics/rubrics.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAexD;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE;QAC5D,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC3B;IACD,QAAQ,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;CACvB,CAAC;AAcX;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAa,EAAE,KAAyB,EAAE,KAAa;IAC9E,OAAO,GAAG,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE,CAAC;AACxC,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,CAAC,GAAG,KAAgC,CAAC;IAC3C,OAAO,CAAC,CAAC,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,CAAC,OAAO,KAAK,MAAM,CAAC;AAC/E,CAAC;AAED;;;;;;;;;GASG;AACH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AAE,EAAE,GAAG,WAAW,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;YAChE,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA6B,EAC7B,QAAwD;IAExD,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC3C,MAAM,cAAc,GAAG,2BAA2B,CAAC,MAAM,CAAC,CAAC;QAC3D,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,EAAE;YACf,uEAAuE;YACvE,0EAA0E;YAC1E,8DAA8D;YAC9D,WAAW,EAAE,sBAAsB,MAAM,CAAC,KAAK,MAAM,MAAM,CAAC,KAAK,IAAI;YACrE,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,GAAG,CAAC,cAAc,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3D,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1B,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,73 @@
1
+ import type { RuntimeMetadata } from "../machine/types.js";
2
+ /**
3
+ * A workflow runtime contract: the authoring/runtime semantics a workspace
4
+ * expects. This is a coarse, stable axis (`"1"`, `"2"`, …) and is intentionally
5
+ * **not** the npm package version — patch/minor implementation releases must not
6
+ * force workflow authors to bump their `WORKFLOW.md`.
7
+ */
8
+ export interface RuntimeContract {
9
+ engine: string;
10
+ version: string;
11
+ }
12
+ /**
13
+ * A {@link RuntimeContract} plus whether it was declared or defaulted, and the
14
+ * two surfaces the version implies.
15
+ *
16
+ * `sandbox` and `testFormat` are **derived, never declared**. They used to be
17
+ * three independent vocabularies — a `runtime.version` in the spec, a sandbox
18
+ * contract version, and a per-file `version` in `*.test.yaml` — describing one
19
+ * fact: which release of the authoring surface a workspace targets. Three
20
+ * vocabularies could disagree; one cannot.
21
+ */
22
+ export interface ResolvedRuntimeContract extends RuntimeContract {
23
+ source: "declared" | "defaulted";
24
+ /** Sandbox script contract implied by this runtime version. */
25
+ sandbox: number;
26
+ /** Offline test-case format implied by this runtime version. */
27
+ testFormat: string;
28
+ }
29
+ /** The sandbox script contract applied when nothing resolves a runtime version. */
30
+ export declare const DEFAULT_SANDBOX_VERSION: number;
31
+ /**
32
+ * The execution contexts the runtime assembles a prelude for. The vocabulary
33
+ * survived the contract merge; the list of them did not, because nothing
34
+ * enumerated it — a context is always named, never iterated.
35
+ */
36
+ export type SandboxContext = "lifecycle-hook" | "ptc";
37
+ /** The runtime engine this package implements. */
38
+ export declare const RUNTIME_ENGINE = "archmax-harness";
39
+ /** Default contract version applied when metadata is omitted. */
40
+ export declare const DEFAULT_RUNTIME_VERSION = "1";
41
+ /** The contract resolved for workspaces that omit `runtime` metadata. */
42
+ export declare const DEFAULT_RUNTIME_CONTRACT: RuntimeContract;
43
+ /**
44
+ * The explicit set of runtime contracts the installed runtime supports.
45
+ * Version 2 identifies the v2 authoring contract (two-file `workflow.yaml` /
46
+ * `WORKFLOW.md` layout, declarative `tests:` block, typed sandbox imports,
47
+ * verdict-returning hook functions). Load behavior is
48
+ * layout-driven, not version-driven — the version is declarative metadata for
49
+ * support checking, validation, and docs. Version 1 remains supported.
50
+ */
51
+ export declare const SUPPORTED_RUNTIME_CONTRACTS: readonly RuntimeContract[];
52
+ /** Render a contract as `engine@version` for messages and artifacts. */
53
+ export declare function formatRuntimeContract(contract: RuntimeContract): string;
54
+ /**
55
+ * Resolve a workflow's runtime contract from optional declared metadata. Omitted
56
+ * metadata (or metadata with neither `engine` nor `version`) resolves to the
57
+ * default contract with `source: "defaulted"`.
58
+ */
59
+ export declare function resolveRuntimeContract(metadata?: RuntimeMetadata | null): ResolvedRuntimeContract;
60
+ /** Whether a contract is in the installed runtime's supported set. */
61
+ export declare function isRuntimeContractSupported(contract: RuntimeContract): boolean;
62
+ /**
63
+ * Diagnostic-friendly support check. Returns `null` when the contract is
64
+ * supported, otherwise an actionable message naming the requested contract and
65
+ * the supported set.
66
+ */
67
+ export declare function unsupportedRuntimeContractMessage(contract: RuntimeContract): string | null;
68
+ /** Thrown by assembly when a workflow declares an unsupported contract. */
69
+ export declare class UnsupportedRuntimeContractError extends Error {
70
+ readonly requested: RuntimeContract;
71
+ readonly supported: readonly RuntimeContract[];
72
+ constructor(requested: RuntimeContract, supported?: readonly RuntimeContract[]);
73
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * What each supported runtime version implies for the surfaces that used to
3
+ * version themselves.
4
+ *
5
+ * Sandbox 2 = hooks are default-export functions returning `ok()` / `veto()` /
6
+ * `correct()`,
7
+ * plus typed `@archmax-ai/harness/*` import stripping. The test-case format has not
8
+ * changed across runtime versions, which is exactly why it did not need an axis
9
+ * of its own.
10
+ *
11
+ * This table is the single source of the supported set — adding a runtime
12
+ * version is one entry here.
13
+ */
14
+ const CONTRACT_SURFACES = {
15
+ "1": { sandbox: 1, testFormat: "1" },
16
+ "2": { sandbox: 2, testFormat: "1" },
17
+ };
18
+ /** The sandbox script contract applied when nothing resolves a runtime version. */
19
+ export const DEFAULT_SANDBOX_VERSION = CONTRACT_SURFACES["2"].sandbox;
20
+ /** The runtime engine this package implements. */
21
+ export const RUNTIME_ENGINE = "archmax-harness";
22
+ /** Default contract version applied when metadata is omitted. */
23
+ export const DEFAULT_RUNTIME_VERSION = "1";
24
+ /** The contract resolved for workspaces that omit `runtime` metadata. */
25
+ export const DEFAULT_RUNTIME_CONTRACT = {
26
+ engine: RUNTIME_ENGINE,
27
+ version: DEFAULT_RUNTIME_VERSION,
28
+ };
29
+ /**
30
+ * The explicit set of runtime contracts the installed runtime supports.
31
+ * Version 2 identifies the v2 authoring contract (two-file `workflow.yaml` /
32
+ * `WORKFLOW.md` layout, declarative `tests:` block, typed sandbox imports,
33
+ * verdict-returning hook functions). Load behavior is
34
+ * layout-driven, not version-driven — the version is declarative metadata for
35
+ * support checking, validation, and docs. Version 1 remains supported.
36
+ */
37
+ export const SUPPORTED_RUNTIME_CONTRACTS = Object.keys(CONTRACT_SURFACES).map((version) => ({ engine: RUNTIME_ENGINE, version }));
38
+ /** Render a contract as `engine@version` for messages and artifacts. */
39
+ export function formatRuntimeContract(contract) {
40
+ return `${contract.engine}@${contract.version}`;
41
+ }
42
+ /**
43
+ * Resolve a workflow's runtime contract from optional declared metadata. Omitted
44
+ * metadata (or metadata with neither `engine` nor `version`) resolves to the
45
+ * default contract with `source: "defaulted"`.
46
+ */
47
+ export function resolveRuntimeContract(metadata) {
48
+ if (!metadata || (metadata.engine === undefined && metadata.version === undefined)) {
49
+ return {
50
+ ...DEFAULT_RUNTIME_CONTRACT,
51
+ source: "defaulted",
52
+ ...surfacesFor(DEFAULT_RUNTIME_VERSION),
53
+ };
54
+ }
55
+ const declaredEngine = metadata.engine !== undefined ? String(metadata.engine) : RUNTIME_ENGINE;
56
+ const version = metadata.version !== undefined ? String(metadata.version) : DEFAULT_RUNTIME_VERSION;
57
+ return { engine: declaredEngine, version, source: "declared", ...surfacesFor(version) };
58
+ }
59
+ /**
60
+ * The surfaces a version implies, falling back to the default's for a version
61
+ * outside the table. Resolution stays total on purpose: an unsupported version
62
+ * is reported by {@link isRuntimeContractSupported} and thrown by assembly, so
63
+ * this function must not also throw — a diagnostic path that needs to *name* an
64
+ * unsupported contract has to be able to resolve it first.
65
+ */
66
+ function surfacesFor(version) {
67
+ return CONTRACT_SURFACES[version] ?? CONTRACT_SURFACES[DEFAULT_RUNTIME_VERSION];
68
+ }
69
+ /** Whether a contract is in the installed runtime's supported set. */
70
+ export function isRuntimeContractSupported(contract) {
71
+ return SUPPORTED_RUNTIME_CONTRACTS.some((supported) => supported.engine === contract.engine && supported.version === contract.version);
72
+ }
73
+ /**
74
+ * Diagnostic-friendly support check. Returns `null` when the contract is
75
+ * supported, otherwise an actionable message naming the requested contract and
76
+ * the supported set.
77
+ */
78
+ export function unsupportedRuntimeContractMessage(contract) {
79
+ if (isRuntimeContractSupported(contract))
80
+ return null;
81
+ const supported = SUPPORTED_RUNTIME_CONTRACTS.map(formatRuntimeContract).join(", ");
82
+ return `Unsupported runtime contract '${formatRuntimeContract(contract)}'. Supported: ${supported}.`;
83
+ }
84
+ /** Thrown by assembly when a workflow declares an unsupported contract. */
85
+ export class UnsupportedRuntimeContractError extends Error {
86
+ requested;
87
+ supported;
88
+ constructor(requested, supported = SUPPORTED_RUNTIME_CONTRACTS) {
89
+ super(`Unsupported runtime contract '${formatRuntimeContract(requested)}'. ` +
90
+ `Supported: ${supported.map(formatRuntimeContract).join(", ")}.`);
91
+ this.name = "UnsupportedRuntimeContractError";
92
+ this.requested = requested;
93
+ this.supported = supported;
94
+ }
95
+ }
96
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/runtime/contract.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;;GAYG;AACH,MAAM,iBAAiB,GAAsE;IAC3F,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE;IACpC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE;CACrC,CAAC;AAEF,mFAAmF;AACnF,MAAM,CAAC,MAAM,uBAAuB,GAAG,iBAAiB,CAAC,GAAG,CAAE,CAAC,OAAO,CAAC;AASvE,kDAAkD;AAClD,MAAM,CAAC,MAAM,cAAc,GAAG,iBAAiB,CAAC;AAEhD,iEAAiE;AACjE,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAE3C,yEAAyE;AACzE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C,OAAO,CAAC,IAAI,iBAAiB,CAAC,uBAAuB,CAAE,CAAC;AACnF,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,0BAA0B,CAAC,QAAyB;IAClE,OAAO,2BAA2B,CAAC,IAAI,CACrC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,IAAI,SAAS,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO,CAC9F,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iCAAiC,CAAC,QAAyB;IACzE,IAAI,0BAA0B,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACtD,MAAM,SAAS,GAAG,2BAA2B,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpF,OAAO,iCAAiC,qBAAqB,CAAC,QAAQ,CAAC,iBAAiB,SAAS,GAAG,CAAC;AACvG,CAAC;AAED,2EAA2E;AAC3E,MAAM,OAAO,+BAAgC,SAAQ,KAAK;IAC/C,SAAS,CAAkB;IAC3B,SAAS,CAA6B;IAE/C,YACE,SAA0B,EAC1B,YAAwC,2BAA2B;QAEnE,KAAK,CACH,iCAAiC,qBAAqB,CAAC,SAAS,CAAC,KAAK;YACpE,cAAc,SAAS,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACnE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,iCAAiC,CAAC;QAC9C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ // QuickJS sandbox core: the verdict helpers a lifecycle hook answers with.
2
+ //
3
+ // return ok(); // proceed
4
+ // return correct("why"); // the agent gets another attempt (after hooks)
5
+ // return veto("why"); // block, with the reason shown to the agent
6
+ //
7
+ // Returning nothing is `ok`; throwing is a veto (fail-closed). Nothing else is
8
+ // installed here — the hook reads its inputs from the object it is called with.
9
+
10
+ globalThis.__verdict = (verdict, reason, fallback) => ({
11
+ verdict,
12
+ reason: reason == null || String(reason).trim() === "" ? fallback : String(reason),
13
+ });
14
+
15
+ globalThis.ok = (reason) => globalThis.__verdict("ok", reason, "ok");
16
+ globalThis.veto = (reason) => globalThis.__verdict("veto", reason, "vetoed by hook");
17
+ globalThis.correct = (reason) => globalThis.__verdict("correct", reason, "correction requested");
18
+
19
+ globalThis.__isVerdict = (value) =>
20
+ value != null &&
21
+ typeof value === "object" &&
22
+ (value.verdict === "ok" || value.verdict === "veto" || value.verdict === "correct");
@@ -0,0 +1,47 @@
1
+ // Lifecycle-hook context: the contract marker, the `defineHook` authoring
2
+ // alias, and the reducer that turns whatever a hook produced into a verdict.
3
+ // These globals are absent from the PTC context.
4
+
5
+ globalThis.SANDBOX_CONTRACT = { context: "lifecycle-hook", version: globalThis.__SANDBOX_VERSION };
6
+
7
+ // `export default defineHook(fn)` and `export default async function hook(...)`
8
+ // both register the hook; the executor rewrites `export default` to an
9
+ // assignment of `__hookDef`, so `defineHook` is an identity that also registers.
10
+ globalThis.defineHook = (fn) => {
11
+ globalThis.__hookDef = fn;
12
+ return fn;
13
+ };
14
+
15
+ // How an object that is not a verdict is named back to its author: by its keys,
16
+ // never its values, so a diagnostic cannot leak what the hook was inspecting.
17
+ globalThis.__hookShape = (value) => {
18
+ if (Array.isArray(value)) return "an array";
19
+ try {
20
+ const keys = Object.keys(value);
21
+ if (keys.length === 0) return "an object with no keys";
22
+ const shown = keys.slice(0, 6).map((key) => `'${key}'`).join(", ");
23
+ return `an object with ${keys.length > 6 ? "keys including " : "keys "}${shown}`;
24
+ } catch {
25
+ return "an object";
26
+ }
27
+ };
28
+
29
+ // The verdict of a hook run. A verdict object is taken as is, a bare `false`
30
+ // vetoes, and returning nothing is `ok`.
31
+ //
32
+ // Any *other* object fails closed. A hook's return value is its verdict and
33
+ // nothing else, so an object that is not one is a verdict its author got wrong
34
+ // — a misspelled `verdict`, a retired shape like `{ ok: false, reason }`. Read
35
+ // as `ok` it would silently permit precisely what the hook meant to block, and
36
+ // the author would have no way to notice: the run just proceeds.
37
+ globalThis.__hookVerdict = (value) => {
38
+ if (globalThis.__isVerdict(value)) return value;
39
+ if (value === false) return globalThis.veto("precondition not met");
40
+ if (value !== null && typeof value === "object") {
41
+ throw new Error(
42
+ `hook returned ${globalThis.__hookShape(value)}, which is not a verdict — ` +
43
+ "return ok(), veto(reason), correct(reason), false, or nothing at all",
44
+ );
45
+ }
46
+ return globalThis.ok();
47
+ };
@@ -0,0 +1,16 @@
1
+ import type { RunnableConfig } from "@langchain/core/runnables";
2
+ import type { StructuredTool } from "@langchain/core/tools";
3
+ import { type SubagentBridgeOptions } from "@langchain/quickjs";
4
+ import type { WorkflowEventEmitter } from "../core/events.js";
5
+ /** Recover the textual payload from whatever envelope `task()` returns. */
6
+ export declare function unwrapToolEnvelope(value: unknown): unknown;
7
+ /**
8
+ * Bridge the QuickJS `task()` global to the Deep Agents `task` tool. When
9
+ * `telemetry` is supplied, each dispatch is bracketed with
10
+ * `rubric-start`/`rubric-result` lifecycle events (this path bypasses the
11
+ * outer agent's tool middleware, so it must emit its own bracketing).
12
+ */
13
+ export declare function createSubagentBridgeDispatch(taskTool: StructuredTool, config: RunnableConfig, telemetry?: {
14
+ emit: WorkflowEventEmitter;
15
+ state?: string;
16
+ }): SubagentBridgeOptions["dispatch"];
@@ -0,0 +1,95 @@
1
+ import { BaseMessage } from "@langchain/core/messages";
2
+ import { isCommand } from "@langchain/langgraph";
3
+ import { SUBAGENT_RESPONSE_FORMAT_CONFIG_KEY } from "deepagents";
4
+ import { validateResponseSchema } from "@langchain/quickjs";
5
+ /** Recover the textual payload from whatever envelope `task()` returns. */
6
+ export function unwrapToolEnvelope(value) {
7
+ if (typeof value === "string")
8
+ return value;
9
+ if (isCommand(value)) {
10
+ const messages = value.update?.messages;
11
+ if (Array.isArray(messages)) {
12
+ for (let i = messages.length - 1; i >= 0; i--) {
13
+ const message = messages[i];
14
+ if (BaseMessage.isInstance(message) && message.content != null) {
15
+ return unwrapToolEnvelope(message.content);
16
+ }
17
+ }
18
+ }
19
+ return value;
20
+ }
21
+ if (BaseMessage.isInstance(value))
22
+ return unwrapToolEnvelope(value.content);
23
+ if (Array.isArray(value)) {
24
+ for (let i = value.length - 1; i >= 0; i--) {
25
+ const entry = value[i];
26
+ if (BaseMessage.isInstance(entry))
27
+ return unwrapToolEnvelope(entry.content);
28
+ if (isCommand(entry)) {
29
+ const inner = unwrapToolEnvelope(entry);
30
+ if (inner !== entry)
31
+ return inner;
32
+ }
33
+ }
34
+ }
35
+ return value;
36
+ }
37
+ /** Ids for bridge dispatches, which have no model-assigned tool-call id. */
38
+ let bridgeDispatchSeq = 0;
39
+ /**
40
+ * Bridge the QuickJS `task()` global to the Deep Agents `task` tool. When
41
+ * `telemetry` is supplied, each dispatch is bracketed with
42
+ * `rubric-start`/`rubric-result` lifecycle events (this path bypasses the
43
+ * outer agent's tool middleware, so it must emit its own bracketing).
44
+ */
45
+ export function createSubagentBridgeDispatch(taskTool, config, telemetry) {
46
+ return async (input) => {
47
+ const hasSchema = input.responseSchema != null;
48
+ if (hasSchema)
49
+ validateResponseSchema(input.responseSchema);
50
+ const toolConfig = {
51
+ ...config,
52
+ configurable: {
53
+ ...config.configurable,
54
+ ...(hasSchema && { [SUBAGENT_RESPONSE_FORMAT_CONFIG_KEY]: input.responseSchema }),
55
+ },
56
+ };
57
+ const dispatchId = `bridge-${++bridgeDispatchSeq}`;
58
+ const state = telemetry?.state ?? "";
59
+ telemetry?.emit({
60
+ type: "rubric-start",
61
+ state,
62
+ name: input.subagentType,
63
+ dispatchId,
64
+ });
65
+ const startedAt = Date.now();
66
+ const settle = (status) => telemetry?.emit({
67
+ type: "rubric-result",
68
+ state,
69
+ name: input.subagentType,
70
+ dispatchId,
71
+ status,
72
+ durationMs: Date.now() - startedAt,
73
+ });
74
+ let raw;
75
+ try {
76
+ raw = await taskTool.invoke({ description: input.description, subagent_type: input.subagentType }, toolConfig);
77
+ }
78
+ catch (err) {
79
+ settle("error");
80
+ throw err;
81
+ }
82
+ settle("ok");
83
+ const content = unwrapToolEnvelope(raw);
84
+ if (hasSchema && typeof content === "string") {
85
+ try {
86
+ return JSON.parse(content);
87
+ }
88
+ catch {
89
+ return content;
90
+ }
91
+ }
92
+ return content;
93
+ };
94
+ }
95
+ //# sourceMappingURL=bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/sandbox/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,mCAAmC,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAA8B,MAAM,oBAAoB,CAAC;AAGxF,2EAA2E;AAC3E,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,QAAQ,GAAI,KAA+C,CAAC,MAAM,EAAE,QAAQ,CAAC;QACnF,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC5B,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC9C,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAC5B,IAAI,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;oBAC/D,OAAO,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;g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0 +1,46 @@
1
+ import type { StructuredTool } from "@langchain/core/tools";
2
+ import type { Workspace } from "../core/workspace.js";
3
+ import { type SandboxRuntime } from "./runtime.js";
4
+ export declare const AGENT_SESSION = "agent";
5
+ export declare const PROCESS_SESSION = "process";
6
+ export interface ScriptRunParams {
7
+ sessionId: string;
8
+ sessionNamespace: string;
9
+ args?: Record<string, unknown>;
10
+ tools?: StructuredTool[];
11
+ /** Run as a lifecycle hook: the hook prelude, the hook input, a verdict back. */
12
+ lifecycle?: boolean;
13
+ /**
14
+ * `runCode` only: prepend the context's prelude, so inline code runs under
15
+ * the same contract as an authored file. The agent's `archmax_eval` sets it;
16
+ * bespoke callers that assemble their own preamble leave it off.
17
+ */
18
+ prelude?: boolean;
19
+ }
20
+ export interface ScriptOutcome {
21
+ ok: boolean;
22
+ value: unknown;
23
+ logs: string[];
24
+ error?: {
25
+ name?: string;
26
+ message?: string;
27
+ };
28
+ formatted: string;
29
+ }
30
+ export interface ScriptExecutor {
31
+ runFile(filePath: string, params: ScriptRunParams): Promise<ScriptOutcome>;
32
+ runCode(code: string, params: ScriptRunParams): Promise<ScriptOutcome>;
33
+ dispose(sessionId: string, sessionNamespace?: string): void;
34
+ }
35
+ export interface ScriptExecutorOptions {
36
+ workspace: Workspace;
37
+ timeoutMs?: number;
38
+ memoryLimitBytes?: number;
39
+ maxPtcCalls?: number | null;
40
+ maxResultChars?: number;
41
+ /** Sandbox contract version injected into each prelude (default: current). */
42
+ sandboxVersion?: number;
43
+ /** Script-execution backend; defaults to the bundled QuickJS runtime. */
44
+ sandboxRuntime?: SandboxRuntime;
45
+ }
46
+ export declare function createScriptExecutor(opts: ScriptExecutorOptions): ScriptExecutor;