@sixb/agent 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +31 -2
- package/dist/abort.d.ts +6 -0
- package/dist/abort.d.ts.map +1 -0
- package/dist/agent-prompt.d.ts +120 -0
- package/dist/agent-prompt.d.ts.map +1 -0
- package/dist/agent-runtime/errors.d.ts +13 -0
- package/dist/agent-runtime/errors.d.ts.map +1 -0
- package/dist/agent-runtime/preflight.d.ts +18 -0
- package/dist/agent-runtime/preflight.d.ts.map +1 -0
- package/dist/agent-runtime/profile.d.ts +14 -0
- package/dist/agent-runtime/profile.d.ts.map +1 -0
- package/dist/artifacts/layout-check/layout-check.d.ts +87 -0
- package/dist/artifacts/layout-check/layout-check.d.ts.map +1 -0
- package/dist/artifacts/materialize.d.ts +115 -0
- package/dist/artifacts/materialize.d.ts.map +1 -0
- package/dist/artifacts/publish-tool.d.ts +86 -0
- package/dist/artifacts/publish-tool.d.ts.map +1 -0
- package/dist/ask-parent-tool.d.ts +36 -0
- package/dist/ask-parent-tool.d.ts.map +1 -0
- package/dist/attachments.d.ts +68 -0
- package/dist/attachments.d.ts.map +1 -0
- package/dist/child-files.d.ts +96 -0
- package/dist/child-files.d.ts.map +1 -0
- package/dist/child-questions.d.ts +24 -0
- package/dist/child-questions.d.ts.map +1 -0
- package/dist/computer-runner.d.ts +65 -0
- package/dist/computer-runner.d.ts.map +1 -0
- package/dist/context-budget.d.ts +28 -0
- package/dist/context-budget.d.ts.map +1 -0
- package/dist/context-compaction.d.ts +48 -0
- package/dist/context-compaction.d.ts.map +1 -0
- package/dist/conversation-memory.d.ts +21 -0
- package/dist/conversation-memory.d.ts.map +1 -0
- package/dist/errors.d.ts +46 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/execution-plan.d.ts +34 -0
- package/dist/execution-plan.d.ts.map +1 -0
- package/dist/failure.d.ts +14 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/family-mailbox.d.ts +60 -0
- package/dist/family-mailbox.d.ts.map +1 -0
- package/dist/file-ref.d.ts +6 -0
- package/dist/file-ref.d.ts.map +1 -0
- package/dist/image-attachments.d.ts +34 -0
- package/dist/image-attachments.d.ts.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12168 -0
- package/dist/index.js.map +65 -0
- package/dist/message-authors.d.ts +34 -0
- package/dist/message-authors.d.ts.map +1 -0
- package/dist/message-times.d.ts +8 -0
- package/dist/message-times.d.ts.map +1 -0
- package/dist/model-adapters.d.ts +55 -0
- package/dist/model-adapters.d.ts.map +1 -0
- package/dist/model-lines.d.ts +16 -0
- package/dist/model-lines.d.ts.map +1 -0
- package/dist/requester.d.ts +15 -0
- package/dist/requester.d.ts.map +1 -0
- package/dist/run-agent-turn.d.ts +63 -0
- package/dist/run-agent-turn.d.ts.map +1 -0
- package/dist/run-child.d.ts +77 -0
- package/dist/run-child.d.ts.map +1 -0
- package/dist/run-conversation-turn.d.ts +42 -0
- package/dist/run-conversation-turn.d.ts.map +1 -0
- package/dist/run-credential.d.ts +22 -0
- package/dist/run-credential.d.ts.map +1 -0
- package/dist/run-environment.d.ts +115 -0
- package/dist/run-environment.d.ts.map +1 -0
- package/dist/run-fate.d.ts +15 -0
- package/dist/run-fate.d.ts.map +1 -0
- package/dist/run-sandbox.d.ts +60 -0
- package/dist/run-sandbox.d.ts.map +1 -0
- package/dist/run-subagent.d.ts +51 -0
- package/dist/run-subagent.d.ts.map +1 -0
- package/dist/run-workflow-agent-node.d.ts +41 -0
- package/dist/run-workflow-agent-node.d.ts.map +1 -0
- package/dist/sandbox-api-context.d.ts +34 -0
- package/dist/sandbox-api-context.d.ts.map +1 -0
- package/dist/sandbox-file-registry.d.ts +9 -0
- package/dist/sandbox-file-registry.d.ts.map +1 -0
- package/dist/sandbox-files.d.ts +71 -0
- package/dist/sandbox-files.d.ts.map +1 -0
- package/dist/sandbox-handle.d.ts +15 -0
- package/dist/sandbox-handle.d.ts.map +1 -0
- package/dist/sandbox-readiness.d.ts +8 -0
- package/dist/sandbox-readiness.d.ts.map +1 -0
- package/dist/skills/built-in.d.ts +15 -0
- package/dist/skills/built-in.d.ts.map +1 -0
- package/dist/subagent-continuation.d.ts +27 -0
- package/dist/subagent-continuation.d.ts.map +1 -0
- package/dist/subagent-inbox.d.ts +53 -0
- package/dist/subagent-inbox.d.ts.map +1 -0
- package/dist/subagent-tools.d.ts +282 -0
- package/dist/subagent-tools.d.ts.map +1 -0
- package/dist/thread-context.d.ts +12 -0
- package/dist/thread-context.d.ts.map +1 -0
- package/dist/tools/attachments.d.ts +11 -0
- package/dist/tools/attachments.d.ts.map +1 -0
- package/dist/tools/bash.d.ts +60 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/model-spec.d.ts +4 -0
- package/dist/tools/model-spec.d.ts.map +1 -0
- package/dist/tools/read.d.ts +43 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/result-media.d.ts +22 -0
- package/dist/tools/result-media.d.ts.map +1 -0
- package/dist/tools/result-output.d.ts +18 -0
- package/dist/tools/result-output.d.ts.map +1 -0
- package/dist/tools/tool-files.d.ts +59 -0
- package/dist/tools/tool-files.d.ts.map +1 -0
- package/dist/tools/view-file.d.ts +40 -0
- package/dist/tools/view-file.d.ts.map +1 -0
- package/dist/tsconfig.json +5 -0
- package/dist/turn-runtime.d.ts +19 -0
- package/dist/turn-runtime.d.ts.map +1 -0
- package/dist/types.d.ts +76 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/workflow-input-attachments.d.ts +18 -0
- package/dist/workflow-input-attachments.d.ts.map +1 -0
- package/package.json +59 -4
- package/src/abort.ts +40 -0
- package/src/agent-prompt.ts +758 -0
- package/src/agent-runtime/errors.ts +44 -0
- package/src/agent-runtime/preflight.ts +314 -0
- package/src/agent-runtime/profile.ts +23 -0
- package/src/artifacts/layout-check/check.cjs +478 -0
- package/src/artifacts/layout-check/layout-check.ts +460 -0
- package/src/artifacts/materialize.ts +380 -0
- package/src/artifacts/publish-tool.ts +700 -0
- package/src/ask-parent-tool.ts +100 -0
- package/src/attachments.ts +850 -0
- package/src/child-files.ts +540 -0
- package/src/child-questions.ts +42 -0
- package/src/computer-runner.ts +284 -0
- package/src/context-budget.ts +161 -0
- package/src/context-compaction.ts +529 -0
- package/src/conversation-memory.ts +45 -0
- package/src/errors.ts +85 -0
- package/src/execution-plan.ts +50 -0
- package/src/failure.ts +71 -0
- package/src/family-mailbox.ts +189 -0
- package/src/file-ref.ts +18 -0
- package/src/image-attachments.ts +322 -0
- package/src/index.ts +54 -0
- package/src/message-authors.ts +77 -0
- package/src/message-times.ts +21 -0
- package/src/model-adapters.ts +227 -0
- package/src/model-lines.ts +28 -0
- package/src/requester.ts +21 -0
- package/src/run-agent-turn.ts +347 -0
- package/src/run-child.ts +319 -0
- package/src/run-conversation-turn.ts +257 -0
- package/src/run-credential.ts +55 -0
- package/src/run-environment.ts +769 -0
- package/src/run-fate.ts +51 -0
- package/src/run-sandbox.ts +63 -0
- package/src/run-subagent.ts +347 -0
- package/src/run-workflow-agent-node.ts +270 -0
- package/src/sandbox-api-context.ts +234 -0
- package/src/sandbox-file-registry.ts +26 -0
- package/src/sandbox-files.ts +326 -0
- package/src/sandbox-handle.ts +19 -0
- package/src/sandbox-readiness.ts +22 -0
- package/src/skills/built-in.ts +183 -0
- package/src/skills/sixb-artifacts/SKILL.md +95 -0
- package/src/skills/sixb-artifacts/canvas.md +104 -0
- package/src/skills/sixb-artifacts/document.md +63 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/first-job.html +42 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/region.html +29 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/shared.css +35 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/boards/welcome.html +31 -0
- package/src/skills/sixb-artifacts/examples/canvas/onboarding-flow/canvas.json +107 -0
- package/src/skills/sixb-artifacts/examples/canvas/retro/canvas.json +158 -0
- package/src/skills/sixb-artifacts/examples/document/incident-report/document.md +35 -0
- package/src/skills/sixb-artifacts/examples/document/operations-review/document.md +41 -0
- package/src/skills/sixb-artifacts/examples/document/operations-review/figures/restorations.svg +1 -0
- package/src/skills/sixb-artifacts/examples/page/collections-desk/index.html +169 -0
- package/src/skills/sixb-artifacts/examples/page/collections-desk/queries/overdue.json +13 -0
- package/src/skills/sixb-artifacts/examples/page/dispatch-board/data/dispatch.json +234 -0
- package/src/skills/sixb-artifacts/examples/page/dispatch-board/index.html +245 -0
- package/src/skills/sixb-artifacts/examples/page/fleet-planner/data/plan.json +53 -0
- package/src/skills/sixb-artifacts/examples/page/fleet-planner/index.html +462 -0
- package/src/skills/sixb-artifacts/examples/page/service-explorer/data/service.json +276 -0
- package/src/skills/sixb-artifacts/examples/page/service-explorer/index.html +549 -0
- package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/queries/overdue.json +13 -0
- package/src/skills/sixb-artifacts/examples/sheet/overdue-invoices/workbook.json +30 -0
- package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Inventory.csv +13 -0
- package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/sheets/Spend.csv +6 -0
- package/src/skills/sixb-artifacts/examples/sheet/parts-inventory/workbook.json +47 -0
- package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Quarters.csv +5 -0
- package/src/skills/sixb-artifacts/examples/sheet/service-metrics/sheets/Regions.csv +5 -0
- package/src/skills/sixb-artifacts/examples/sheet/service-metrics/workbook.json +78 -0
- package/src/skills/sixb-artifacts/examples/slides/launch-plan/index.html +63 -0
- package/src/skills/sixb-artifacts/examples/slides/q3-review/index.html +133 -0
- package/src/skills/sixb-artifacts/file.md +17 -0
- package/src/skills/sixb-artifacts/page.md +215 -0
- package/src/skills/sixb-artifacts/queries.md +66 -0
- package/src/skills/sixb-artifacts/references.md +68 -0
- package/src/skills/sixb-artifacts/sheet.md +223 -0
- package/src/skills/sixb-artifacts/slides.md +137 -0
- package/src/skills/sixb-memory/SKILL.md +68 -0
- package/src/skills/text-assets.d.ts +25 -0
- package/src/subagent-continuation.ts +51 -0
- package/src/subagent-inbox.ts +101 -0
- package/src/subagent-tools.ts +1609 -0
- package/src/thread-context.ts +25 -0
- package/src/tools/attachments.ts +28 -0
- package/src/tools/bash.ts +217 -0
- package/src/tools/model-spec.ts +22 -0
- package/src/tools/read.ts +262 -0
- package/src/tools/result-media.ts +147 -0
- package/src/tools/result-output.ts +44 -0
- package/src/tools/tool-files.ts +204 -0
- package/src/tools/view-file.ts +155 -0
- package/src/turn-runtime.ts +33 -0
- package/src/types.ts +79 -0
- 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"
|