@sixb/agent 0.0.0-stage → 0.2.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 (240) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -2
  3. package/dist/abort.d.ts +6 -0
  4. package/dist/abort.d.ts.map +1 -0
  5. package/dist/agent-prompt.d.ts +126 -0
  6. package/dist/agent-prompt.d.ts.map +1 -0
  7. package/dist/agent-runtime/errors.d.ts +13 -0
  8. package/dist/agent-runtime/errors.d.ts.map +1 -0
  9. package/dist/agent-runtime/preflight.d.ts +18 -0
  10. package/dist/agent-runtime/preflight.d.ts.map +1 -0
  11. package/dist/agent-runtime/profile.d.ts +14 -0
  12. package/dist/agent-runtime/profile.d.ts.map +1 -0
  13. package/dist/artifacts/layout-check/layout-check.d.ts +87 -0
  14. package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -0
  15. package/dist/artifacts/materialize.d.ts +115 -0
  16. package/dist/artifacts/materialize.d.ts.map +1 -0
  17. package/dist/artifacts/publish-tool.d.ts +86 -0
  18. package/dist/artifacts/publish-tool.d.ts.map +1 -0
  19. package/dist/ask-parent-tool.d.ts +36 -0
  20. package/dist/ask-parent-tool.d.ts.map +1 -0
  21. package/dist/attachments.d.ts +109 -0
  22. package/dist/attachments.d.ts.map +1 -0
  23. package/dist/child-files.d.ts +91 -0
  24. package/dist/child-files.d.ts.map +1 -0
  25. package/dist/child-questions.d.ts +24 -0
  26. package/dist/child-questions.d.ts.map +1 -0
  27. package/dist/computer-runner.d.ts +74 -0
  28. package/dist/computer-runner.d.ts.map +1 -0
  29. package/dist/context-budget.d.ts +34 -0
  30. package/dist/context-budget.d.ts.map +1 -0
  31. package/dist/context-compaction.d.ts +148 -0
  32. package/dist/context-compaction.d.ts.map +1 -0
  33. package/dist/context-guard.d.ts +69 -0
  34. package/dist/context-guard.d.ts.map +1 -0
  35. package/dist/conversation-memory.d.ts +21 -0
  36. package/dist/conversation-memory.d.ts.map +1 -0
  37. package/dist/conversation-messages.d.ts +33 -0
  38. package/dist/conversation-messages.d.ts.map +1 -0
  39. package/dist/errors.d.ts +46 -0
  40. package/dist/errors.d.ts.map +1 -0
  41. package/dist/execution-plan.d.ts +38 -0
  42. package/dist/execution-plan.d.ts.map +1 -0
  43. package/dist/failure.d.ts +14 -0
  44. package/dist/failure.d.ts.map +1 -0
  45. package/dist/family-mailbox.d.ts +60 -0
  46. package/dist/family-mailbox.d.ts.map +1 -0
  47. package/dist/file-ref.d.ts +6 -0
  48. package/dist/file-ref.d.ts.map +1 -0
  49. package/dist/image-attachments.d.ts +34 -0
  50. package/dist/image-attachments.d.ts.map +1 -0
  51. package/dist/index.d.ts +35 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +14387 -0
  54. package/dist/index.js.map +72 -0
  55. package/dist/inline-images.d.ts +28 -0
  56. package/dist/inline-images.d.ts.map +1 -0
  57. package/dist/message-authors.d.ts +34 -0
  58. package/dist/message-authors.d.ts.map +1 -0
  59. package/dist/message-times.d.ts +9 -0
  60. package/dist/message-times.d.ts.map +1 -0
  61. package/dist/model-adapters.d.ts +59 -0
  62. package/dist/model-adapters.d.ts.map +1 -0
  63. package/dist/model-lines.d.ts +16 -0
  64. package/dist/model-lines.d.ts.map +1 -0
  65. package/dist/prompt-cache.d.ts +28 -0
  66. package/dist/prompt-cache.d.ts.map +1 -0
  67. package/dist/requester.d.ts +15 -0
  68. package/dist/requester.d.ts.map +1 -0
  69. package/dist/run-agent-turn.d.ts +93 -0
  70. package/dist/run-agent-turn.d.ts.map +1 -0
  71. package/dist/run-child.d.ts +77 -0
  72. package/dist/run-child.d.ts.map +1 -0
  73. package/dist/run-conversation-turn.d.ts +42 -0
  74. package/dist/run-conversation-turn.d.ts.map +1 -0
  75. package/dist/run-credential.d.ts +22 -0
  76. package/dist/run-credential.d.ts.map +1 -0
  77. package/dist/run-environment.d.ts +145 -0
  78. package/dist/run-environment.d.ts.map +1 -0
  79. package/dist/run-fate.d.ts +15 -0
  80. package/dist/run-fate.d.ts.map +1 -0
  81. package/dist/run-files-lock.d.ts +16 -0
  82. package/dist/run-files-lock.d.ts.map +1 -0
  83. package/dist/run-sandbox.d.ts +60 -0
  84. package/dist/run-sandbox.d.ts.map +1 -0
  85. package/dist/run-subagent.d.ts +65 -0
  86. package/dist/run-subagent.d.ts.map +1 -0
  87. package/dist/run-workflow-agent-node.d.ts +46 -0
  88. package/dist/run-workflow-agent-node.d.ts.map +1 -0
  89. package/dist/sandbox-api-context.d.ts +34 -0
  90. package/dist/sandbox-api-context.d.ts.map +1 -0
  91. package/dist/sandbox-file-registry.d.ts +9 -0
  92. package/dist/sandbox-file-registry.d.ts.map +1 -0
  93. package/dist/sandbox-files.d.ts +71 -0
  94. package/dist/sandbox-files.d.ts.map +1 -0
  95. package/dist/sandbox-handle.d.ts +15 -0
  96. package/dist/sandbox-handle.d.ts.map +1 -0
  97. package/dist/sandbox-readiness.d.ts +8 -0
  98. package/dist/sandbox-readiness.d.ts.map +1 -0
  99. package/dist/skills/built-in.d.ts +15 -0
  100. package/dist/skills/built-in.d.ts.map +1 -0
  101. package/dist/subagent-context.d.ts +50 -0
  102. package/dist/subagent-context.d.ts.map +1 -0
  103. package/dist/subagent-continuation.d.ts +33 -0
  104. package/dist/subagent-continuation.d.ts.map +1 -0
  105. package/dist/subagent-inbox.d.ts +53 -0
  106. package/dist/subagent-inbox.d.ts.map +1 -0
  107. package/dist/subagent-tools.d.ts +293 -0
  108. package/dist/subagent-tools.d.ts.map +1 -0
  109. package/dist/thread-context.d.ts +17 -0
  110. package/dist/thread-context.d.ts.map +1 -0
  111. package/dist/tools/attachments.d.ts +11 -0
  112. package/dist/tools/attachments.d.ts.map +1 -0
  113. package/dist/tools/bash.d.ts +68 -0
  114. package/dist/tools/bash.d.ts.map +1 -0
  115. package/dist/tools/model-spec.d.ts +9 -0
  116. package/dist/tools/model-spec.d.ts.map +1 -0
  117. package/dist/tools/read.d.ts +43 -0
  118. package/dist/tools/read.d.ts.map +1 -0
  119. package/dist/tools/result-media.d.ts +65 -0
  120. package/dist/tools/result-media.d.ts.map +1 -0
  121. package/dist/tools/result-output.d.ts +18 -0
  122. package/dist/tools/result-output.d.ts.map +1 -0
  123. package/dist/tools/tool-files.d.ts +59 -0
  124. package/dist/tools/tool-files.d.ts.map +1 -0
  125. package/dist/tools/tool-outputs.d.ts +63 -0
  126. package/dist/tools/tool-outputs.d.ts.map +1 -0
  127. package/dist/tools/view-file.d.ts +40 -0
  128. package/dist/tools/view-file.d.ts.map +1 -0
  129. package/dist/tsconfig.json +5 -0
  130. package/dist/turn-runtime.d.ts +19 -0
  131. package/dist/turn-runtime.d.ts.map +1 -0
  132. package/dist/types.d.ts +83 -0
  133. package/dist/types.d.ts.map +1 -0
  134. package/dist/workflow-input-attachments.d.ts +18 -0
  135. package/dist/workflow-input-attachments.d.ts.map +1 -0
  136. package/package.json +59 -4
  137. package/src/abort.ts +40 -0
  138. package/src/agent-prompt.ts +860 -0
  139. package/src/agent-runtime/errors.ts +44 -0
  140. package/src/agent-runtime/preflight.ts +314 -0
  141. package/src/agent-runtime/profile.ts +23 -0
  142. package/src/artifacts/layout-check/check.cjs +478 -0
  143. package/src/artifacts/layout-check/layout-check.ts +460 -0
  144. package/src/artifacts/materialize.ts +380 -0
  145. package/src/artifacts/publish-tool.ts +700 -0
  146. package/src/ask-parent-tool.ts +100 -0
  147. package/src/attachments.ts +1041 -0
  148. package/src/child-files.ts +535 -0
  149. package/src/child-questions.ts +42 -0
  150. package/src/computer-runner.ts +336 -0
  151. package/src/context-budget.ts +177 -0
  152. package/src/context-compaction.ts +1349 -0
  153. package/src/context-guard.ts +826 -0
  154. package/src/conversation-memory.ts +45 -0
  155. package/src/conversation-messages.ts +86 -0
  156. package/src/errors.ts +85 -0
  157. package/src/execution-plan.ts +70 -0
  158. package/src/failure.ts +82 -0
  159. package/src/family-mailbox.ts +189 -0
  160. package/src/file-ref.ts +18 -0
  161. package/src/image-attachments.ts +322 -0
  162. package/src/index.ts +54 -0
  163. package/src/inline-images.ts +69 -0
  164. package/src/message-authors.ts +77 -0
  165. package/src/message-times.ts +24 -0
  166. package/src/model-adapters.ts +273 -0
  167. package/src/model-lines.ts +28 -0
  168. package/src/prompt-cache.ts +40 -0
  169. package/src/requester.ts +21 -0
  170. package/src/run-agent-turn.ts +509 -0
  171. package/src/run-child.ts +344 -0
  172. package/src/run-conversation-turn.ts +272 -0
  173. package/src/run-credential.ts +55 -0
  174. package/src/run-environment.ts +1216 -0
  175. package/src/run-fate.ts +51 -0
  176. package/src/run-files-lock.ts +118 -0
  177. package/src/run-sandbox.ts +63 -0
  178. package/src/run-subagent.ts +433 -0
  179. package/src/run-workflow-agent-node.ts +344 -0
  180. package/src/sandbox-api-context.ts +237 -0
  181. package/src/sandbox-file-registry.ts +26 -0
  182. package/src/sandbox-files.ts +326 -0
  183. package/src/sandbox-handle.ts +19 -0
  184. package/src/sandbox-readiness.ts +22 -0
  185. package/src/skills/built-in.ts +183 -0
  186. package/src/skills/sixb-artifacts/SKILL.md +95 -0
  187. package/src/skills/sixb-artifacts/canvas.md +104 -0
  188. package/src/skills/sixb-artifacts/document.md +63 -0
  189. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/first-job.html +42 -0
  190. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/region.html +29 -0
  191. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/shared.css +35 -0
  192. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/welcome.html +31 -0
  193. package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/canvas.json +107 -0
  194. package/src/skills/sixb-artifacts/examples/canvas/retro/canvas.json +158 -0
  195. package/src/skills/sixb-artifacts/examples/document/incident-report/document.md +35 -0
  196. package/src/skills/sixb-artifacts/examples/document/operations-review/document.md +41 -0
  197. package/src/skills/sixb-artifacts/examples/document/operations-review/figures/restorations.svg +1 -0
  198. package/src/skills/sixb-artifacts/examples/page/collections-desk/index.html +169 -0
  199. package/src/skills/sixb-artifacts/examples/page/collections-desk/queries/overdue.json +13 -0
  200. package/src/skills/sixb-artifacts/examples/page/dispatch-board/data/dispatch.json +234 -0
  201. package/src/skills/sixb-artifacts/examples/page/dispatch-board/index.html +245 -0
  202. package/src/skills/sixb-artifacts/examples/page/fleet-planner/data/plan.json +53 -0
  203. package/src/skills/sixb-artifacts/examples/page/fleet-planner/index.html +462 -0
  204. package/src/skills/sixb-artifacts/examples/page/service-explorer/data/service.json +276 -0
  205. package/src/skills/sixb-artifacts/examples/page/service-explorer/index.html +549 -0
  206. package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/queries/overdue.json +13 -0
  207. package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/workbook.json +30 -0
  208. package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Inventory.csv +13 -0
  209. package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Spend.csv +6 -0
  210. package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/workbook.json +47 -0
  211. package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Quarters.csv +5 -0
  212. package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Regions.csv +5 -0
  213. package/src/skills/sixb-artifacts/examples/sheet/service-metrics/workbook.json +78 -0
  214. package/src/skills/sixb-artifacts/examples/slides/launch-plan/index.html +63 -0
  215. package/src/skills/sixb-artifacts/examples/slides/q3-review/index.html +133 -0
  216. package/src/skills/sixb-artifacts/file.md +17 -0
  217. package/src/skills/sixb-artifacts/page.md +215 -0
  218. package/src/skills/sixb-artifacts/queries.md +66 -0
  219. package/src/skills/sixb-artifacts/references.md +68 -0
  220. package/src/skills/sixb-artifacts/sheet.md +223 -0
  221. package/src/skills/sixb-artifacts/slides.md +137 -0
  222. package/src/skills/sixb-memory/SKILL.md +68 -0
  223. package/src/skills/text-assets.d.ts +25 -0
  224. package/src/subagent-context.ts +182 -0
  225. package/src/subagent-continuation.ts +56 -0
  226. package/src/subagent-inbox.ts +101 -0
  227. package/src/subagent-tools.ts +1671 -0
  228. package/src/thread-context.ts +31 -0
  229. package/src/tools/attachments.ts +28 -0
  230. package/src/tools/bash.ts +233 -0
  231. package/src/tools/model-spec.ts +27 -0
  232. package/src/tools/read.ts +262 -0
  233. package/src/tools/result-media.ts +351 -0
  234. package/src/tools/result-output.ts +46 -0
  235. package/src/tools/tool-files.ts +204 -0
  236. package/src/tools/tool-outputs.ts +464 -0
  237. package/src/tools/view-file.ts +155 -0
  238. package/src/turn-runtime.ts +33 -0
  239. package/src/types.ts +91 -0
  240. package/src/workflow-input-attachments.ts +140 -0
@@ -0,0 +1,44 @@
1
+ import { AGENT_RUNTIME_PROFILE } from "@sixb/cli-core"
2
+ import type { AgentRuntimeFailureReason, AgentRuntimeProfileCheck } from "./profile"
3
+
4
+ /** A provisioned sandbox does not satisfy the worker's versioned agent-runtime contract. */
5
+ export class AgentRuntimeProfileError extends Error {
6
+ override readonly name = "AgentRuntimeProfileError"
7
+ readonly profile = AGENT_RUNTIME_PROFILE
8
+ readonly remediation: string
9
+
10
+ constructor(
11
+ readonly provider: string,
12
+ readonly check: AgentRuntimeProfileCheck,
13
+ readonly reason: AgentRuntimeFailureReason,
14
+ readonly exitCode?: number
15
+ ) {
16
+ const remediation = remediationFor(check)
17
+ const failure = exitCode === undefined ? reason : `${reason} (exit ${exitCode})`
18
+ super(
19
+ `[SixbAgent] Sandbox provider '${provider}' failed '${AGENT_RUNTIME_PROFILE}' check '${check}': ${failure}. ${remediation}`
20
+ )
21
+ this.remediation = remediation
22
+ }
23
+ }
24
+
25
+ function remediationFor(check: AgentRuntimeProfileCheck): string {
26
+ switch (check) {
27
+ case "bash":
28
+ return "Provide Bash in the configured sandbox host or image."
29
+ case "environment-bootstrap":
30
+ return "Ensure sandbox commands preserve the worker-provided environment and load BASH_ENV."
31
+ case "path-bootstrap":
32
+ return "Ensure BASH_ENV can prepend the worker-installed Sixb CLI directory to PATH."
33
+ case "cli-installation":
34
+ return "Ensure sandbox file materialization preserves the Sixb CLI bytes and executable mode."
35
+ case "file-tools":
36
+ return "Provide compatible realpath, tail, head, base64, find, wc, and tr utilities in the sandbox."
37
+ case "javascript-runtime":
38
+ return "Provide Bun 1.3+ or Node 22+ in the configured sandbox host or image."
39
+ case "cli-execution":
40
+ return "Ensure the worker-installed Sixb CLI artifact can execute without modifying it."
41
+ case "gateway-connectivity":
42
+ return "Ensure the Sixb API is reachable from the sandbox with the run's token and identifies the current project."
43
+ }
44
+ }
@@ -0,0 +1,314 @@
1
+ import {
2
+ AGENT_RUNTIME_PROFILE,
3
+ EXIT_API,
4
+ INSTANCE_CLI_VERSION,
5
+ type SandboxStatusReport,
6
+ } from "@sixb/cli-core"
7
+ import type { CommandResult, Sandbox } from "@sixb/core"
8
+ import { AgentRuntimeProfileError } from "./errors"
9
+ import {
10
+ AGENT_RUNTIME_MINIMUM_VERSIONS,
11
+ type AgentJavascriptRuntime,
12
+ type AgentRuntimeFailureReason,
13
+ type AgentRuntimeProfileCheck,
14
+ } from "./profile"
15
+
16
+ const PREFLIGHT_TIMEOUT_MS = 15_000
17
+ /** Backoff between gateway probes while the API may be restarting: a few seconds in total. */
18
+ const GATEWAY_RETRY_DELAYS_MS: readonly number[] = [250, 500, 1_000, 2_000]
19
+ /**
20
+ * Retries end this long after the first gateway probe starts, so a gateway that stays down still
21
+ * fails within a worker's shutdown grace period rather than after several full probe timeouts.
22
+ */
23
+ const GATEWAY_RETRY_WINDOW_MS = 8_000
24
+ /** A retry is only worth starting with at least this much of the window left. */
25
+ const GATEWAY_RETRY_MIN_ATTEMPT_MS = 1_000
26
+
27
+ const CHECK_BY_EXIT_CODE: Readonly<Record<number, AgentRuntimeProfileCheck>> = {
28
+ 20: "environment-bootstrap",
29
+ 21: "path-bootstrap",
30
+ 22: "cli-installation",
31
+ 23: "file-tools",
32
+ 24: "javascript-runtime",
33
+ 25: "cli-execution",
34
+ }
35
+
36
+ export interface AssertAgentRuntimeProfileInput {
37
+ readonly sandbox: Sandbox
38
+ readonly env: Readonly<Record<string, string>>
39
+ readonly projectId: string
40
+ /** Default to {@link GATEWAY_RETRY_DELAYS_MS} and {@link GATEWAY_RETRY_WINDOW_MS}; tests shorten them. */
41
+ readonly gatewayRetryDelaysMs?: readonly number[]
42
+ readonly gatewayRetryWindowMs?: number
43
+ }
44
+
45
+ /**
46
+ * Validate the concrete provisioned environment before a model can use its sandbox tools.
47
+ *
48
+ * The first command is deterministic and network-free. The second deliberately travels through
49
+ * the installed CLI and run-scoped gateway, proving the launcher, JavaScript fetch stack, gateway
50
+ * capability, DNS, and TLS/CA path (when the configured gateway uses HTTPS) together.
51
+ */
52
+ export async function assertAgentRuntimeProfile(
53
+ input: AssertAgentRuntimeProfileInput
54
+ ): Promise<void> {
55
+ const local = await runProbe(input.sandbox, LOCAL_BEHAVIOR_PROBE, input.env, "bash")
56
+ if (local.exitCode !== 0) {
57
+ throw profileError(
58
+ input.sandbox,
59
+ CHECK_BY_EXIT_CODE[local.exitCode] ?? "bash",
60
+ "nonzero-exit",
61
+ local.exitCode
62
+ )
63
+ }
64
+
65
+ const runtime = parseLocalProbe(input.sandbox, local.stdout)
66
+ assertSupportedRuntime(input.sandbox, runtime.name, runtime.version)
67
+ if (runtime.cliVersion !== INSTANCE_CLI_VERSION) {
68
+ throw profileError(input.sandbox, "cli-execution", "invalid-output")
69
+ }
70
+
71
+ const gateway = await probeGateway(input)
72
+ if (gateway.exitCode !== 0) {
73
+ throw profileError(input.sandbox, "gateway-connectivity", "nonzero-exit", gateway.exitCode)
74
+ }
75
+ assertStatusReport(input.sandbox, gateway.stdout, input.projectId, runtime)
76
+ }
77
+
78
+ async function runProbe(
79
+ sandbox: Sandbox,
80
+ script: string,
81
+ env: Readonly<Record<string, string>>,
82
+ failureCheck: AgentRuntimeProfileCheck,
83
+ timeoutMs = PREFLIGHT_TIMEOUT_MS
84
+ ): Promise<CommandResult> {
85
+ try {
86
+ const result = await sandbox.runCommand("bash", ["-lc", script], {
87
+ env,
88
+ timeout: timeoutMs,
89
+ })
90
+ if (result.timedOut) throw profileError(sandbox, failureCheck, "timed-out")
91
+ return result
92
+ } catch (error) {
93
+ if (error instanceof AgentRuntimeProfileError) throw error
94
+ throw profileError(sandbox, failureCheck, "command-error")
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Reach the API through the gateway, retrying only what an API restart looks like from inside the
100
+ * sandbox: a refused or reset connection, a 5xx, or an attempt that times out. The first probe has
101
+ * the full timeout; retries share what is left of a short window, so a probe that timed out once is
102
+ * not retried at all. The last attempt's outcome is the one checked, so a gateway that stays down
103
+ * fails the run as before.
104
+ */
105
+ async function probeGateway(input: AssertAgentRuntimeProfileInput): Promise<CommandResult> {
106
+ const delays = input.gatewayRetryDelaysMs ?? GATEWAY_RETRY_DELAYS_MS
107
+ const deadline = Date.now() + (input.gatewayRetryWindowMs ?? GATEWAY_RETRY_WINDOW_MS)
108
+ for (let retry = 0; ; retry += 1) {
109
+ const timeoutMs = retry === 0 ? PREFLIGHT_TIMEOUT_MS : deadline - Date.now()
110
+ const outcome = await runProbe(
111
+ input.sandbox,
112
+ "sixb status",
113
+ input.env,
114
+ "gateway-connectivity",
115
+ timeoutMs
116
+ ).then(
117
+ (result) => ({ result, transient: isTransientGatewayFailure(result) }),
118
+ (error: unknown) => ({
119
+ error,
120
+ transient: error instanceof AgentRuntimeProfileError && error.reason === "timed-out",
121
+ })
122
+ )
123
+ const delayMs = delays[retry]
124
+ if (
125
+ !outcome.transient ||
126
+ delayMs === undefined ||
127
+ Date.now() + delayMs + GATEWAY_RETRY_MIN_ATTEMPT_MS > deadline
128
+ ) {
129
+ if ("error" in outcome) throw outcome.error
130
+ return outcome.result
131
+ }
132
+ await new Promise((resolve) => setTimeout(resolve, delayMs))
133
+ }
134
+ }
135
+
136
+ /** The CLI reports API failures as `{"error":{...}}` on its last stderr line, with exit code 3. */
137
+ function isTransientGatewayFailure(result: CommandResult): boolean {
138
+ if (result.exitCode !== EXIT_API) return false
139
+ let error: Record<string, unknown>
140
+ try {
141
+ error = record(record(JSON.parse(result.stderr.trim().split("\n").at(-1) ?? "")).error)
142
+ } catch {
143
+ return false
144
+ }
145
+ return (
146
+ error.code === "api_unreachable" || (typeof error.status === "number" && error.status >= 500)
147
+ )
148
+ }
149
+
150
+ function parseLocalProbe(
151
+ sandbox: Sandbox,
152
+ stdout: string
153
+ ): {
154
+ readonly name: AgentJavascriptRuntime
155
+ readonly version: string
156
+ readonly cliVersion: string
157
+ } {
158
+ const fields = stdout.trim().split("\t")
159
+ if (fields.length !== 3) throw profileError(sandbox, "cli-execution", "invalid-output")
160
+ const [name, version, cliOutput] = fields
161
+ if ((name !== "bun" && name !== "node") || !version || !cliOutput) {
162
+ throw profileError(sandbox, "cli-execution", "invalid-output")
163
+ }
164
+ const prefix = "sixb CLI "
165
+ if (!cliOutput.startsWith(prefix)) {
166
+ throw profileError(sandbox, "cli-execution", "invalid-output")
167
+ }
168
+ return { name, version, cliVersion: cliOutput.slice(prefix.length) }
169
+ }
170
+
171
+ function assertSupportedRuntime(
172
+ sandbox: Sandbox,
173
+ name: AgentJavascriptRuntime,
174
+ version: string
175
+ ): void {
176
+ const parsed = parseVersion(version)
177
+ const minimum = AGENT_RUNTIME_MINIMUM_VERSIONS[name]
178
+ if (
179
+ !parsed ||
180
+ parsed.major < minimum.major ||
181
+ (parsed.major === minimum.major && parsed.minor < minimum.minor)
182
+ ) {
183
+ throw profileError(sandbox, "javascript-runtime", "unsupported-version")
184
+ }
185
+ }
186
+
187
+ function parseVersion(version: string): { readonly major: number; readonly minor: number } | null {
188
+ const match = /^v?(\d+)\.(\d+)(?:\.|$)/.exec(version.trim())
189
+ if (!match) return null
190
+ return { major: Number(match[1]), minor: Number(match[2]) }
191
+ }
192
+
193
+ function assertStatusReport(
194
+ sandbox: Sandbox,
195
+ stdout: string,
196
+ projectId: string,
197
+ localRuntime: { readonly name: AgentJavascriptRuntime; readonly version: string }
198
+ ): void {
199
+ let report: SandboxStatusReport
200
+ try {
201
+ const value: unknown = JSON.parse(stdout)
202
+ report = parseStatusReport(value)
203
+ } catch {
204
+ throw profileError(sandbox, "cli-execution", "invalid-output")
205
+ }
206
+ if (
207
+ report.cli.version !== INSTANCE_CLI_VERSION ||
208
+ report.javascript.name !== localRuntime.name ||
209
+ normalizeVersion(report.javascript.version) !== normalizeVersion(localRuntime.version)
210
+ ) {
211
+ throw profileError(sandbox, "cli-execution", "invalid-output")
212
+ }
213
+ if (report.project.id !== projectId) {
214
+ throw profileError(sandbox, "gateway-connectivity", "invalid-output")
215
+ }
216
+ }
217
+
218
+ function parseStatusReport(value: unknown): SandboxStatusReport {
219
+ const report = record(value)
220
+ const cli = record(report.cli)
221
+ const javascript = record(report.javascript)
222
+ const project = record(report.project)
223
+ if (
224
+ report.ok !== true ||
225
+ report.profile !== AGENT_RUNTIME_PROFILE ||
226
+ typeof cli.version !== "string" ||
227
+ cli.version.length === 0 ||
228
+ (javascript.name !== "bun" && javascript.name !== "node") ||
229
+ typeof javascript.version !== "string" ||
230
+ javascript.version.length === 0 ||
231
+ typeof project.id !== "string" ||
232
+ project.id.length === 0
233
+ ) {
234
+ throw new Error("invalid status report")
235
+ }
236
+ return {
237
+ ok: true,
238
+ profile: report.profile,
239
+ cli: { version: cli.version },
240
+ javascript: { name: javascript.name, version: javascript.version },
241
+ project: { id: project.id },
242
+ }
243
+ }
244
+
245
+ function record(value: unknown): Record<string, unknown> {
246
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
247
+ throw new Error("expected object")
248
+ }
249
+ return value as Record<string, unknown>
250
+ }
251
+
252
+ function normalizeVersion(value: string): string {
253
+ return value.trim().replace(/^v/, "")
254
+ }
255
+
256
+ function profileError(
257
+ sandbox: Sandbox,
258
+ check: AgentRuntimeProfileCheck,
259
+ reason: AgentRuntimeFailureReason,
260
+ exitCode?: number
261
+ ): AgentRuntimeProfileError {
262
+ return new AgentRuntimeProfileError(sandbox.provider, check, reason, exitCode)
263
+ }
264
+
265
+ const LOCAL_BEHAVIOR_PROBE = `set -u
266
+ [ "\${SIXB_BASH_ENV_READY:-}" = "1" ] || exit 20
267
+ [ "\${SIXB_AGENT_RUNTIME_PROFILE:-}" = "${AGENT_RUNTIME_PROFILE}" ] || exit 20
268
+ [ "$(command -v sixb)" = "$SIXB_BIN_DIR/sixb" ] || exit 21
269
+ [ -x "$SIXB_BIN_DIR/sixb" ] || exit 22
270
+ [ -r "$SIXB_CONTEXT_DIR/lib/sixb.mjs" ] || exit 22
271
+ realpath_bin="$(command -v realpath)" || exit 23
272
+ tail_bin="$(command -v tail)" || exit 23
273
+ head_bin="$(command -v head)" || exit 23
274
+ base64_bin="$(command -v base64)" || exit 23
275
+ resolved_probe="$("$realpath_bin" "$SIXB_RUNTIME_PROBE_FILE")" || exit 23
276
+ [ -f "$resolved_probe" ] || exit 23
277
+ "$tail_bin" -n "+2" -- "$resolved_probe" | "$head_bin" -n 1 | "$head_bin" -c 19 | "$base64_bin" > "$SIXB_CONTEXT_DIR/runtime/read-probe.out"
278
+ for status in "\${PIPESTATUS[@]}"; do
279
+ case "$status" in 0|141) ;; *) exit 23 ;; esac
280
+ done
281
+ IFS= read -r read_probe < "$SIXB_CONTEXT_DIR/runtime/read-probe.out"
282
+ [ "$read_probe" = "c2l4Yi1ydW50aW1lLXByb2JlCg==" ] || exit 23
283
+ find_bin="$(command -v find)" || exit 23
284
+ wc_bin="$(command -v wc)" || exit 23
285
+ tr_bin="$(command -v tr)" || exit 23
286
+ probe_dir="\${resolved_probe%/*}"
287
+ "$find_bin" "$probe_dir" -type f -name "read-probe.txt" -print0 | while IFS= read -r -d '' path; do
288
+ size="$("$wc_bin" -c < "$path" | "$tr_bin" -d ' ')" || exit 1
289
+ encoded="$(printf '%s' "$path" | "$base64_bin" | "$tr_bin" -d '\n')" || exit 1
290
+ printf '%s\t%s\n' "$size" "$encoded"
291
+ done > "$SIXB_CONTEXT_DIR/runtime/file-tools-probe.out"
292
+ for status in "\${PIPESTATUS[@]}"; do
293
+ [ "$status" = "0" ] || exit 23
294
+ done
295
+ IFS=$'\t' read -r file_size encoded_path < "$SIXB_CONTEXT_DIR/runtime/file-tools-probe.out"
296
+ [ "$file_size" = "31" ] || exit 23
297
+ decoded_path="$(printf '%s' "$encoded_path" | "$base64_bin" -d)" || exit 23
298
+ [ "$decoded_path" = "$resolved_probe" ] || exit 23
299
+ runtime_path="$(command -v bun || true)"
300
+ if [ -n "$runtime_path" ]; then
301
+ runtime_name="bun"
302
+ runtime_version="$("$runtime_path" --version)" || exit 24
303
+ else
304
+ runtime_path="$(command -v node || true)"
305
+ fi
306
+ if [ -z "\${runtime_name:-}" ] && [ -n "$runtime_path" ]; then
307
+ runtime_name="node"
308
+ runtime_version="$("$runtime_path" --version)" || exit 24
309
+ fi
310
+ if [ -z "\${runtime_name:-}" ]; then
311
+ exit 24
312
+ fi
313
+ cli_version="$(sixb --version)" || exit 25
314
+ printf '%s\t%s\t%s\n' "$runtime_name" "$runtime_version" "$cli_version"`
@@ -0,0 +1,23 @@
1
+ export const AGENT_RUNTIME_MINIMUM_VERSIONS = {
2
+ bun: { major: 1, minor: 3 },
3
+ node: { major: 22, minor: 0 },
4
+ } as const
5
+
6
+ export type AgentJavascriptRuntime = keyof typeof AGENT_RUNTIME_MINIMUM_VERSIONS
7
+
8
+ export type AgentRuntimeProfileCheck =
9
+ | "bash"
10
+ | "environment-bootstrap"
11
+ | "path-bootstrap"
12
+ | "cli-installation"
13
+ | "file-tools"
14
+ | "javascript-runtime"
15
+ | "cli-execution"
16
+ | "gateway-connectivity"
17
+
18
+ export type AgentRuntimeFailureReason =
19
+ | "command-error"
20
+ | "timed-out"
21
+ | "nonzero-exit"
22
+ | "invalid-output"
23
+ | "unsupported-version"