@spunto/build 0.31.0 → 0.32.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/README.md +13 -6
- package/package.json +2 -9
- package/src/agent-contract/index.ts +7 -1
- package/src/agent-contract/runner.ts +124 -0
- package/src/agent-contract/vocabulary.ts +1 -1
- package/src/agent-stream/agent-stream.ts +1 -1
- package/src/agent-stream/index.ts +1 -1
- package/src/catalogs/index.ts +0 -22
- package/src/script/local-features.ts +0 -4
- package/src/agent-runners/catalogs.ts +0 -183
- package/src/agent-runners/claude/adapter.ts +0 -623
- package/src/agent-runners/claude/model-window.ts +0 -192
- package/src/agent-runners/claude/turn-limit.ts +0 -188
- package/src/agent-runners/claude.mjs +0 -245
- package/src/agent-runners/codex/adapter.ts +0 -134
- package/src/agent-runners/codex.mjs +0 -178
- package/src/agent-runners/features.ts +0 -109
- package/src/agent-runners/index.ts +0 -107
- package/src/agent-runners/mistral/adapter.ts +0 -219
- package/src/agent-runners/mistral.mjs +0 -355
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Codex's dialect, read into our vocabulary — the events of `@openai/codex-sdk`'s `runStreamed()`
|
|
3
|
-
* (`ThreadEvent`). Written against the SDK's own types (0.164.0).
|
|
4
|
-
*
|
|
5
|
-
* Lives with the Codex runner (RFC 0048 § 9): the runner bundles it and prints the contract
|
|
6
|
-
* (`codexContractLines`): the platform reads no Codex line, ever.
|
|
7
|
-
*
|
|
8
|
-
* Codex works per **turn**, not per session: `turn.completed` is a hand-back the way Claude's
|
|
9
|
-
* `result` is, so it ends the turn here too. Its usage is the turn's sum, which is why it is filed
|
|
10
|
-
* as a `call` (summed over the task) without a `contextTokens`: no single number of it is the
|
|
11
|
-
* size of the prompt last sent.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { clip, type NormalizedEvent } from "../../agent-contract/vocabulary"
|
|
15
|
-
|
|
16
|
-
function num(value: unknown): number | null {
|
|
17
|
-
return typeof value === "number" && Number.isFinite(value) ? value : null
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function adaptCodex(obj: Record<string, unknown>): NormalizedEvent[] {
|
|
21
|
-
const type = obj.type
|
|
22
|
-
if (type === "thread.started") {
|
|
23
|
-
return [{ type: "session.started", payload: { harness: "codex", model: null, sessionId: typeof obj.thread_id === "string" ? obj.thread_id : null } }]
|
|
24
|
-
}
|
|
25
|
-
if (type === "turn.started") return []
|
|
26
|
-
if (type === "turn.completed") {
|
|
27
|
-
const u = (obj.usage ?? {}) as Record<string, unknown>
|
|
28
|
-
return [
|
|
29
|
-
{
|
|
30
|
-
type: "usage",
|
|
31
|
-
payload: {
|
|
32
|
-
scope: "call",
|
|
33
|
-
model: null,
|
|
34
|
-
inputTokens: num(u.input_tokens) ?? 0,
|
|
35
|
-
outputTokens: (num(u.output_tokens) ?? 0) + (num(u.reasoning_output_tokens) ?? 0),
|
|
36
|
-
cacheReadTokens: num(u.cached_input_tokens) ?? 0,
|
|
37
|
-
cacheCreationTokens: num(u.cache_write_input_tokens) ?? 0,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
{ type: "session.ended", payload: { status: "succeeded", stopReason: null, summary: "" } },
|
|
41
|
-
]
|
|
42
|
-
}
|
|
43
|
-
if (type === "turn.failed") {
|
|
44
|
-
const error = (obj.error ?? {}) as Record<string, unknown>
|
|
45
|
-
return [{ type: "session.ended", payload: { status: "failed", stopReason: null, summary: clip(error.message).text } }]
|
|
46
|
-
}
|
|
47
|
-
// Not an end: measured, Codex emits `error` for every retry ("Reconnecting... 2/5 (401 …)") and
|
|
48
|
-
// only the `turn.failed` that follows the last one ends the turn. Kept visible, not fatal.
|
|
49
|
-
if (type === "error") return [{ type: "raw", payload: { json: obj } }]
|
|
50
|
-
if (type !== "item.started" && type !== "item.updated" && type !== "item.completed") {
|
|
51
|
-
return [{ type: "raw", payload: { json: obj } }]
|
|
52
|
-
}
|
|
53
|
-
const item = (obj.item ?? {}) as Record<string, unknown>
|
|
54
|
-
const callId = typeof item.id === "string" ? item.id : null
|
|
55
|
-
const started = type === "item.started"
|
|
56
|
-
const completed = type === "item.completed"
|
|
57
|
-
switch (item.type) {
|
|
58
|
-
case "agent_message": {
|
|
59
|
-
if (!completed) return []
|
|
60
|
-
const { text, truncated } = clip(item.text)
|
|
61
|
-
return text ? [{ type: "message", payload: { role: "assistant", text, truncated } }] : []
|
|
62
|
-
}
|
|
63
|
-
case "reasoning": {
|
|
64
|
-
if (!completed) return []
|
|
65
|
-
const { text, truncated } = clip(item.text)
|
|
66
|
-
return text ? [{ type: "thinking", payload: { text, truncated } }] : []
|
|
67
|
-
}
|
|
68
|
-
case "command_execution": {
|
|
69
|
-
if (started) {
|
|
70
|
-
const { text: input, truncated } = clip({ command: item.command })
|
|
71
|
-
return [{ type: "tool.call", payload: { callId, name: "Bash", input, truncated } }]
|
|
72
|
-
}
|
|
73
|
-
if (!completed) return []
|
|
74
|
-
const { text: output, truncated } = clip(item.aggregated_output)
|
|
75
|
-
const failed = item.status === "failed" || (typeof item.exit_code === "number" && item.exit_code !== 0)
|
|
76
|
-
return [{ type: "tool.result", payload: { callId, isError: failed, output, truncated } }]
|
|
77
|
-
}
|
|
78
|
-
case "file_change": {
|
|
79
|
-
// Reported once, applied: the call and its outcome arrive together.
|
|
80
|
-
if (!completed) return []
|
|
81
|
-
const changes = Array.isArray(item.changes) ? item.changes : []
|
|
82
|
-
const { text: input, truncated } = clip({ changes })
|
|
83
|
-
const output = changes
|
|
84
|
-
.filter((c): c is Record<string, unknown> => !!c && typeof c === "object")
|
|
85
|
-
.map((c) => `${c.kind} ${c.path}`)
|
|
86
|
-
.join("\n")
|
|
87
|
-
return [
|
|
88
|
-
{ type: "tool.call", payload: { callId, name: "Edit", input, truncated } },
|
|
89
|
-
{ type: "tool.result", payload: { callId, isError: item.status === "failed", output, truncated: false } },
|
|
90
|
-
]
|
|
91
|
-
}
|
|
92
|
-
case "mcp_tool_call": {
|
|
93
|
-
const name = `${typeof item.server === "string" ? item.server : "mcp"}.${typeof item.tool === "string" ? item.tool : "tool"}`
|
|
94
|
-
if (started) {
|
|
95
|
-
const { text: input, truncated } = clip(item.arguments)
|
|
96
|
-
return [{ type: "tool.call", payload: { callId, name, input, truncated } }]
|
|
97
|
-
}
|
|
98
|
-
if (!completed) return []
|
|
99
|
-
const error = (item.error ?? null) as Record<string, unknown> | null
|
|
100
|
-
const { text: output, truncated } = clip(error ? error.message : (item.result as Record<string, unknown> | undefined)?.content ?? "")
|
|
101
|
-
return [{ type: "tool.result", payload: { callId, isError: !!error || item.status === "failed", output, truncated } }]
|
|
102
|
-
}
|
|
103
|
-
case "web_search": {
|
|
104
|
-
if (!started) return []
|
|
105
|
-
const { text: input, truncated } = clip({ query: item.query })
|
|
106
|
-
return [{ type: "tool.call", payload: { callId, name: "WebSearch", input, truncated } }]
|
|
107
|
-
}
|
|
108
|
-
case "todo_list": {
|
|
109
|
-
const steps = (Array.isArray(item.items) ? item.items : [])
|
|
110
|
-
.filter((t): t is Record<string, unknown> => !!t && typeof t === "object")
|
|
111
|
-
.map((t) => ({ text: clip(t.text).text, status: t.completed === true ? "completed" : "pending" }))
|
|
112
|
-
.filter((s) => s.text)
|
|
113
|
-
return steps.length > 0 ? [{ type: "plan", payload: { steps } }] : []
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return [{ type: "raw", payload: { json: obj } }]
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* An `agent_message` item being written, as the contract's transient `message.delta`. Codex hands
|
|
121
|
-
* the whole text so far on `item.started` / `item.updated`, not a delta, so every one opens the
|
|
122
|
-
* draft afresh with it (`start`); the completed item, stored as the `message`, closes it.
|
|
123
|
-
*/
|
|
124
|
-
export function codexDelta(obj: Record<string, unknown>): Record<string, unknown>[] {
|
|
125
|
-
if (obj.type !== "item.started" && obj.type !== "item.updated") return []
|
|
126
|
-
const item = (obj.item ?? {}) as Record<string, unknown>
|
|
127
|
-
if (item.type !== "agent_message" || typeof item.text !== "string" || !item.text) return []
|
|
128
|
-
return [{ type: "message.delta", start: true, text: item.text }]
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** One `ThreadEvent`, as the lines of the contract the Codex runner prints, each with the event as `source`. */
|
|
132
|
-
export function codexContractLines(event: Record<string, unknown>): Record<string, unknown>[] {
|
|
133
|
-
return [...codexDelta(event), ...adaptCodex(event).map((e) => ({ type: e.type, ...e.payload, source: event }))]
|
|
134
|
-
}
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// The Codex runner (RFC 0048): same contract as `claude.mjs`, over `@openai/codex-sdk`, installed
|
|
3
|
-
// with the `codex` binary it drives by the `spunto-agent-codex` feature. Bundled with its adapter
|
|
4
|
-
// by the platform, like every runner.
|
|
5
|
-
//
|
|
6
|
-
// node codex.mjs run [--model <id>] [--resume <thread id>]
|
|
7
|
-
// stdin {"type":"user","text"} · {"type":"interrupt","id"} · {"type":"title",…} (ignored: Codex
|
|
8
|
-
// does not name its threads) ; closed = the session ends after its turn
|
|
9
|
-
// stdout **our** vocabulary (`agent-v1`): each `ThreadEvent` read here (`./codex/adapter.ts`),
|
|
10
|
-
// with the event itself as `source`
|
|
11
|
-
// env SPUNTO_AGENT_MCP — the org's MCP servers, through the platform's gateway (RFC 0049)
|
|
12
|
-
// env SPUNTO_AGENT_OPTIONS — the task's parameters (`./catalogs.ts`):
|
|
13
|
-
// `{"reasoningEffort":"high","webSearch":"live"}`
|
|
14
|
-
// exit 0 once the input is closed and the last turn is over, 1 when the session could not run
|
|
15
|
-
//
|
|
16
|
-
// Codex works turn by turn: a message that arrives while a turn runs waits for it to end, then
|
|
17
|
-
// starts the next one in the same thread — what a "queued message" already means on the platform.
|
|
18
|
-
// An interrupt aborts the turn in flight, and the runner says so with a `turn.failed`.
|
|
19
|
-
//
|
|
20
|
-
// Credentials: `OPENAI_API_KEY` (or `CODEX_API_KEY`) as a secret, or a `codex login` done by hand in
|
|
21
|
-
// the machine's terminal (`~/.codex/auth.json`), which the binary reads on its own.
|
|
22
|
-
|
|
23
|
-
import { createInterface } from "node:readline"
|
|
24
|
-
import { codexContractLines } from "./codex/adapter"
|
|
25
|
-
|
|
26
|
-
const SDK = process.env.SPUNTO_CODEX_SDK || "/opt/spunto/agents/codex/node_modules/@openai/codex-sdk/dist/index.js"
|
|
27
|
-
|
|
28
|
-
function out(obj) {
|
|
29
|
-
process.stdout.write(`${JSON.stringify(obj)}\n`)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** One `ThreadEvent` (or one the runner stands in for the SDK), as the contract. */
|
|
33
|
-
function emit(event) {
|
|
34
|
-
for (const line of codexContractLines(event)) out(line)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function fail(message) {
|
|
38
|
-
emit({ type: "turn.failed", error: { message } })
|
|
39
|
-
process.exit(1)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function parseArgs(argv) {
|
|
43
|
-
const [verb, ...rest] = argv
|
|
44
|
-
if (verb !== "run") fail(`codex runner: unknown verb "${verb ?? ""}" (expected "run")`)
|
|
45
|
-
const args = {}
|
|
46
|
-
for (let i = 0; i < rest.length; i++) {
|
|
47
|
-
const flag = rest[i]
|
|
48
|
-
if (flag === "--model" || flag === "--resume") {
|
|
49
|
-
const value = rest[++i]
|
|
50
|
-
if (value) args[flag.slice(2)] = value
|
|
51
|
-
} else {
|
|
52
|
-
fail(`codex runner: unknown flag "${flag}"`)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return args
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const args = parseArgs(process.argv.slice(2))
|
|
59
|
-
|
|
60
|
-
/** The task's parameters. Checked by the platform against the catalog; read defensively all the same. */
|
|
61
|
-
function readOptions() {
|
|
62
|
-
try {
|
|
63
|
-
const parsed = JSON.parse(process.env.SPUNTO_AGENT_OPTIONS || "{}")
|
|
64
|
-
return parsed && typeof parsed === "object" ? parsed : {}
|
|
65
|
-
} catch {
|
|
66
|
-
return {}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const params = readOptions()
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* The org's MCP servers (RFC 0049), as Codex's `mcp_servers` config. Each is the platform's
|
|
73
|
-
* gateway: Codex reads the machine's identity from `SPUNTO_WORKER_TOKEN` itself
|
|
74
|
-
* (`bearer_token_env_var`), and never holds the vendor's token.
|
|
75
|
-
*/
|
|
76
|
-
function readMcpServers() {
|
|
77
|
-
let listed
|
|
78
|
-
try {
|
|
79
|
-
listed = JSON.parse(process.env.SPUNTO_AGENT_MCP || "[]")
|
|
80
|
-
} catch {
|
|
81
|
-
return {}
|
|
82
|
-
}
|
|
83
|
-
const api = (process.env.SPUNTO_API_URL || "").replace(/\/$/, "")
|
|
84
|
-
if (!Array.isArray(listed) || !api || !process.env.SPUNTO_WORKER_TOKEN) return {}
|
|
85
|
-
const servers = {}
|
|
86
|
-
for (const s of listed) {
|
|
87
|
-
if (!s || typeof s.name !== "string" || typeof s.path !== "string") continue
|
|
88
|
-
servers[s.name] = { url: `${api}${s.path}`, bearer_token_env_var: "SPUNTO_WORKER_TOKEN" }
|
|
89
|
-
}
|
|
90
|
-
return servers
|
|
91
|
-
}
|
|
92
|
-
const mcpServers = readMcpServers()
|
|
93
|
-
|
|
94
|
-
let sdk
|
|
95
|
-
try {
|
|
96
|
-
sdk = await import(SDK)
|
|
97
|
-
} catch (err) {
|
|
98
|
-
fail(`codex runner: the Codex SDK is not installed at ${SDK} — is the project's image built with the Codex app's feature? (${err?.message ?? err})`)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const apiKey = process.env.OPENAI_API_KEY || process.env.CODEX_API_KEY
|
|
102
|
-
const codex = new sdk.Codex({
|
|
103
|
-
...(apiKey ? { apiKey } : {}),
|
|
104
|
-
...(Object.keys(mcpServers).length ? { config: { mcp_servers: mcpServers } } : {}),
|
|
105
|
-
})
|
|
106
|
-
const threadOptions = {
|
|
107
|
-
workingDirectory: process.cwd(),
|
|
108
|
-
...(args.model ? { model: args.model } : {}),
|
|
109
|
-
...(typeof params.reasoningEffort === "string" ? { modelReasoningEffort: params.reasoningEffort } : {}),
|
|
110
|
-
...(typeof params.webSearch === "string" ? { webSearchMode: params.webSearch } : {}),
|
|
111
|
-
// A task runs unattended in a disposable machine: no approval prompt nobody would answer, and
|
|
112
|
-
// no sandbox of Codex's own inside the one the machine already is (it needs kernel features a
|
|
113
|
-
// container rarely has).
|
|
114
|
-
approvalPolicy: "never",
|
|
115
|
-
sandboxMode: "danger-full-access",
|
|
116
|
-
networkAccessEnabled: true,
|
|
117
|
-
}
|
|
118
|
-
const thread = args.resume ? codex.resumeThread(args.resume, threadOptions) : codex.startThread(threadOptions)
|
|
119
|
-
// A resumed thread is not announced by the SDK (`thread.started` only comes with a new one), and
|
|
120
|
-
// the platform learns the session id from that line — so the runner says it.
|
|
121
|
-
if (args.resume) emit({ type: "thread.started", thread_id: args.resume })
|
|
122
|
-
|
|
123
|
-
const pending = []
|
|
124
|
-
let closed = false
|
|
125
|
-
let current = null // AbortController of the turn in flight
|
|
126
|
-
let wake = null
|
|
127
|
-
|
|
128
|
-
createInterface({ input: process.stdin, crlfDelay: Infinity })
|
|
129
|
-
.on("line", (line) => {
|
|
130
|
-
let msg
|
|
131
|
-
try {
|
|
132
|
-
msg = JSON.parse(line)
|
|
133
|
-
} catch {
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
if (!msg || typeof msg !== "object") return
|
|
137
|
-
if (msg.type === "user" && typeof msg.text === "string") {
|
|
138
|
-
pending.push(msg.text)
|
|
139
|
-
wake?.()
|
|
140
|
-
} else if (msg.type === "interrupt") {
|
|
141
|
-
current?.abort()
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
.on("close", () => {
|
|
145
|
-
closed = true
|
|
146
|
-
wake?.()
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
let failed = false
|
|
150
|
-
for (;;) {
|
|
151
|
-
if (pending.length === 0) {
|
|
152
|
-
if (closed) break
|
|
153
|
-
await new Promise((resolve) => (wake = resolve))
|
|
154
|
-
wake = null
|
|
155
|
-
continue
|
|
156
|
-
}
|
|
157
|
-
const text = pending.shift()
|
|
158
|
-
current = new AbortController()
|
|
159
|
-
// The SDK also throws once the binary exits after a `turn.failed` it has just yielded; that line
|
|
160
|
-
// already said why, and a second one would end the turn twice in the timeline.
|
|
161
|
-
let lastType = null
|
|
162
|
-
try {
|
|
163
|
-
const { events } = await thread.runStreamed(text, { signal: current.signal })
|
|
164
|
-
for await (const event of events) {
|
|
165
|
-
emit(event)
|
|
166
|
-
lastType = event?.type ?? null
|
|
167
|
-
}
|
|
168
|
-
} catch (err) {
|
|
169
|
-
if (current.signal.aborted) {
|
|
170
|
-
emit({ type: "turn.failed", error: { message: "Interrupted." } })
|
|
171
|
-
} else if (lastType !== "turn.failed") {
|
|
172
|
-
emit({ type: "turn.failed", error: { message: `codex runner: ${err?.message ?? err}` } })
|
|
173
|
-
failed = true
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
current = null
|
|
177
|
-
}
|
|
178
|
-
process.exit(failed ? 1 : 0)
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// The install scripts of the agent apps' features (RFC 0048), shipped by the platform itself like
|
|
2
|
-
// `google-cloud-cli.sh` (`../script/local-features.ts`). Root, at image build time.
|
|
3
|
-
//
|
|
4
|
-
// Each one lays down, under /opt/spunto/agents:
|
|
5
|
-
// node/ a private Node — the runner must not depend on the project's (absent from a
|
|
6
|
-
// Python image, swapped by an nvm feature that installs after this one)
|
|
7
|
-
// <id>/ the harness's official SDK, pinned, with the native binary it drives — or, for
|
|
8
|
-
// a harness with no Node SDK (Mistral Vibe, Python), the harness itself, pinned
|
|
9
|
-
// /usr/local/bin/ the harness's CLI for the humans in the terminal, unless the image has one
|
|
10
|
-
|
|
11
|
-
/** Where every agent feature installs. */
|
|
12
|
-
export const AGENT_HOME = "/opt/spunto/agents"
|
|
13
|
-
/** The private Node the features fetch — the release the sandbox bootstrap fetches too. */
|
|
14
|
-
export const AGENT_NODE_VERSION = "v24.11.1"
|
|
15
|
-
const NODE_VERSION = AGENT_NODE_VERSION
|
|
16
|
-
|
|
17
|
-
/** The pinned Mistral Vibe release, and the uv that installs it (with its own Python). */
|
|
18
|
-
export const MISTRAL_VIBE_VERSION = "3.0.4"
|
|
19
|
-
const UV_VERSION = "0.13.6"
|
|
20
|
-
|
|
21
|
-
/** The SDK, from npm, into `<id>/` — what both Node harnesses install. */
|
|
22
|
-
function npmInstall(id: string, packages: string): string {
|
|
23
|
-
return `mkdir -p "$HOME_DIR/${id}"
|
|
24
|
-
PATH="$NODE_DIR/bin:$PATH" "$NODE_DIR/bin/npm" install --prefix "$HOME_DIR/${id}" \\
|
|
25
|
-
--omit=dev --no-audit --no-fund --no-update-notifier --loglevel=error ${packages}`
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function featureScript(p: { id: string; label: string; install: string; cli: string }): string {
|
|
29
|
-
return `#!/bin/sh
|
|
30
|
-
set -e
|
|
31
|
-
echo "[feature] ${p.id}: installing ${p.label}..."
|
|
32
|
-
|
|
33
|
-
HOME_DIR=${AGENT_HOME}
|
|
34
|
-
NODE_DIR=$HOME_DIR/node
|
|
35
|
-
mkdir -p "$HOME_DIR"
|
|
36
|
-
|
|
37
|
-
fetch() {
|
|
38
|
-
if command -v curl >/dev/null 2>&1; then curl -fsSL --retry 5 --retry-delay 2 "$1" -o "$2"
|
|
39
|
-
elif command -v wget >/dev/null 2>&1; then wget -qO "$2" "$1"
|
|
40
|
-
else echo "[feature] ${p.id}: neither curl nor wget in this image" >&2; exit 1
|
|
41
|
-
fi
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if ! "$NODE_DIR/bin/node" -e 'process.exit(0)' 2>/dev/null; then
|
|
45
|
-
case "$(uname -m)" in
|
|
46
|
-
x86_64|amd64) ARCH=x64 ;;
|
|
47
|
-
aarch64|arm64) ARCH=arm64 ;;
|
|
48
|
-
*) echo "[feature] ${p.id}: unsupported arch $(uname -m)" >&2; exit 1 ;;
|
|
49
|
-
esac
|
|
50
|
-
echo "[feature] ${p.id}: fetching node ${NODE_VERSION} ($ARCH)"
|
|
51
|
-
fetch "https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-linux-$ARCH.tar.gz" /tmp/_spunto_node.tgz
|
|
52
|
-
rm -rf "$NODE_DIR" && mkdir -p "$NODE_DIR"
|
|
53
|
-
tar -xzf /tmp/_spunto_node.tgz -C "$NODE_DIR" --strip-components=1
|
|
54
|
-
rm -f /tmp/_spunto_node.tgz
|
|
55
|
-
fi
|
|
56
|
-
|
|
57
|
-
${p.install}
|
|
58
|
-
chmod -R a+rX "$HOME_DIR"
|
|
59
|
-
|
|
60
|
-
${p.cli}
|
|
61
|
-
|
|
62
|
-
echo "[feature] ${p.id}: done"
|
|
63
|
-
`
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const AGENT_FEATURE_SCRIPTS: Record<string, string> = {
|
|
67
|
-
"spunto-agent-claude.sh": featureScript({
|
|
68
|
-
id: "claude",
|
|
69
|
-
label: "the Claude Agent SDK",
|
|
70
|
-
install: npmInstall("claude", "@anthropic-ai/claude-agent-sdk@0.3.310"),
|
|
71
|
-
// The SDK drives a native \`claude\` binary from a platform package; the same binary is the CLI.
|
|
72
|
-
cli: `if ! command -v claude >/dev/null 2>&1; then
|
|
73
|
-
for b in "$HOME_DIR"/claude/node_modules/@anthropic-ai/claude-agent-sdk-linux-*/claude; do
|
|
74
|
-
if [ -x "$b" ]; then ln -sf "$b" /usr/local/bin/claude; break; fi
|
|
75
|
-
done
|
|
76
|
-
fi`,
|
|
77
|
-
}),
|
|
78
|
-
"spunto-agent-codex.sh": featureScript({
|
|
79
|
-
id: "codex",
|
|
80
|
-
label: "the Codex SDK",
|
|
81
|
-
install: npmInstall("codex", "@openai/codex-sdk@0.164.0"),
|
|
82
|
-
cli: `if ! command -v codex >/dev/null 2>&1; then
|
|
83
|
-
printf '#!/bin/sh\\nexec %s %s "$@"\\n' "$NODE_DIR/bin/node" "$HOME_DIR/codex/node_modules/@openai/codex/bin/codex.js" > /usr/local/bin/codex
|
|
84
|
-
chmod 755 /usr/local/bin/codex
|
|
85
|
-
fi`,
|
|
86
|
-
}),
|
|
87
|
-
// Mistral Vibe has no Node SDK: the runner speaks ACP to `vibe-acp` itself (`../mistral.mjs`).
|
|
88
|
-
// Vibe is Python (≥ 3.12); uv installs it with a Python of its own, so the image's — absent, or
|
|
89
|
-
// too old — never matters, the way the private Node keeps the project's out of the runner.
|
|
90
|
-
"spunto-agent-mistral.sh": featureScript({
|
|
91
|
-
id: "mistral",
|
|
92
|
-
label: "Mistral Vibe",
|
|
93
|
-
install: `MISTRAL_DIR=$HOME_DIR/mistral
|
|
94
|
-
mkdir -p "$MISTRAL_DIR"
|
|
95
|
-
if ! "$MISTRAL_DIR/uv/uv" --version 2>/dev/null | grep -q "${UV_VERSION}"; then
|
|
96
|
-
echo "[feature] mistral: fetching uv ${UV_VERSION}"
|
|
97
|
-
fetch "https://astral.sh/uv/${UV_VERSION}/install.sh" /tmp/_spunto_uv_install.sh
|
|
98
|
-
UV_INSTALL_DIR="$MISTRAL_DIR/uv" UV_NO_MODIFY_PATH=1 sh /tmp/_spunto_uv_install.sh >/dev/null
|
|
99
|
-
rm -f /tmp/_spunto_uv_install.sh
|
|
100
|
-
fi
|
|
101
|
-
UV_PYTHON_INSTALL_DIR="$MISTRAL_DIR/python" UV_TOOL_DIR="$MISTRAL_DIR/tools" UV_TOOL_BIN_DIR="$MISTRAL_DIR/bin" \\
|
|
102
|
-
UV_CACHE_DIR=/tmp/_spunto_uv_cache UV_NO_CONFIG=1 \\
|
|
103
|
-
"$MISTRAL_DIR/uv/uv" tool install --force --managed-python --python 3.13 "mistral-vibe==${MISTRAL_VIBE_VERSION}"
|
|
104
|
-
rm -rf /tmp/_spunto_uv_cache`,
|
|
105
|
-
cli: `for b in vibe vibe-acp; do
|
|
106
|
-
if ! command -v "$b" >/dev/null 2>&1; then ln -sf "$HOME_DIR/mistral/bin/$b" "/usr/local/bin/$b"; fi
|
|
107
|
-
done`,
|
|
108
|
-
}),
|
|
109
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent apps (RFC 0048): what it takes to run a harness in a machine, on both sides of the seam.
|
|
3
|
-
*
|
|
4
|
-
* An agent app is three things, and this module is where they meet:
|
|
5
|
-
*
|
|
6
|
-
* - a **feature** the platform injects into the image of every project that picks the app — it
|
|
7
|
-
* installs a private Node and the harness's **official SDK** (with the binary the SDK drives)
|
|
8
|
-
* under `/opt/spunto/agents/<id>`. Shipped by the platform itself (`localScript`), so an app
|
|
9
|
-
* never waits on a registry release;
|
|
10
|
-
* - a **runner**, a `.mjs` entry of ours (`claude.mjs`, `codex.mjs`, `mistral.mjs`) with its harness's
|
|
11
|
-
* adapter next to it (`claude/adapter.ts`, `codex/adapter.ts`, `mistral/adapter.ts`). The caller **bundles** the two into one
|
|
12
|
-
* file (esbuild, `platform: node`, `format: esm`) and writes it into the machine at the moment a
|
|
13
|
-
* session starts. Not baked: a runner fix reaches the next session, not the next rebuild;
|
|
14
|
-
* - the **Spunto agent contract** (`agent-v1`, `../agent-contract`), which is how the platform
|
|
15
|
-
* writes the runner's stdin and reads its stdout — the same for every app.
|
|
16
|
-
*
|
|
17
|
-
* The runner contract, identical for every app (docs/agent-contract.md):
|
|
18
|
-
*
|
|
19
|
-
* <node> <runner>.mjs run [--model <id>] [--resume <session id>]
|
|
20
|
-
* stdin one JSON object per line: {"type":"user","text"} · {"type":"interrupt","id"} ·
|
|
21
|
-
* {"type":"title","id","description"} (`RunnerInput`); closed ⇒ end after the turn
|
|
22
|
-
* env SPUNTO_AGENT_OPTIONS — the task's parameters (`./catalogs.ts`), one JSON object
|
|
23
|
-
* stdout our vocabulary, one JSON object per line, each event with its harness message as `source`
|
|
24
|
-
* exit 0 = the input closed and the last turn ended; ≠ 0 = the session could not run, and its
|
|
25
|
-
* last line is a failed `session.ended` saying why
|
|
26
|
-
*
|
|
27
|
-
* Pure like the rest of the package: what a caller gets is *where* a runner entry is, and the shell
|
|
28
|
-
* that starts it. Bundling and reading the file are the caller's I/O.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
import type { AgentProtocol } from "../agent-stream/agent-stream"
|
|
32
|
-
|
|
33
|
-
import { AGENT_HOME } from "./features"
|
|
34
|
-
|
|
35
|
-
/** The Node every runner runs on — the private one the features install. */
|
|
36
|
-
export const AGENT_NODE = `${AGENT_HOME}/node/bin/node`
|
|
37
|
-
|
|
38
|
-
export type AgentHarnessId = "claude" | "codex" | "mistral"
|
|
39
|
-
|
|
40
|
-
export type AgentHarness = {
|
|
41
|
-
id: AgentHarnessId
|
|
42
|
-
/** The catalog id of the feature the platform injects (`AVAILABLE_FEATURES`, `localScript`). */
|
|
43
|
-
featureId: string
|
|
44
|
-
/** How the platform talks to the runner — the contract, for every app. */
|
|
45
|
-
protocol: AgentProtocol
|
|
46
|
-
/** The runner's entry, a file of this package — to be bundled with what it imports. */
|
|
47
|
-
runnerFile: URL
|
|
48
|
-
/** Where the harness looks for user-level skills (RFC 0033), as shell evaluated in the machine. */
|
|
49
|
-
skillDirs: string[]
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const AGENT_HARNESSES: Record<AgentHarnessId, AgentHarness> = {
|
|
53
|
-
claude: {
|
|
54
|
-
id: "claude",
|
|
55
|
-
featureId: "spunto-agent-claude",
|
|
56
|
-
protocol: "agent-v1",
|
|
57
|
-
runnerFile: new URL("./claude.mjs", import.meta.url),
|
|
58
|
-
skillDirs: ["${CLAUDE_CONFIG_DIR:-$HOME/.claude}/skills"],
|
|
59
|
-
},
|
|
60
|
-
codex: {
|
|
61
|
-
id: "codex",
|
|
62
|
-
featureId: "spunto-agent-codex",
|
|
63
|
-
protocol: "agent-v1",
|
|
64
|
-
runnerFile: new URL("./codex.mjs", import.meta.url),
|
|
65
|
-
skillDirs: ["${CODEX_HOME:-$HOME/.codex}/skills"],
|
|
66
|
-
},
|
|
67
|
-
mistral: {
|
|
68
|
-
id: "mistral",
|
|
69
|
-
featureId: "spunto-agent-mistral",
|
|
70
|
-
protocol: "agent-v1",
|
|
71
|
-
runnerFile: new URL("./mistral.mjs", import.meta.url),
|
|
72
|
-
skillDirs: ["${VIBE_HOME:-$HOME/.vibe}/skills"],
|
|
73
|
-
},
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** The variable a runner's text travels in, base64 — see `runnerCommand`. */
|
|
77
|
-
export const RUNNER_ENV = "SPUNTO_AGENT_RUNNER"
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* The shell that starts a session: write the runner out of `$SPUNTO_AGENT_RUNNER` (base64, set by
|
|
81
|
-
* the caller in the command's environment), then `exec` it on the feature's Node so the session
|
|
82
|
-
* *is* the runner — stdin, signals and exit code included.
|
|
83
|
-
*
|
|
84
|
-
* The text rides in the environment rather than in the command because the command is what the
|
|
85
|
-
* platform shows ("what the platform ran"): eight kilobytes of base64 there would bury the one line
|
|
86
|
-
* worth reading. `--model` is appended by the platform like for any harness; `resume` adds the
|
|
87
|
-
* session the platform read off the stream, passed as `$SPUNTO_TASK_SESSION_ID`.
|
|
88
|
-
*
|
|
89
|
-
* Only the app's id is needed (it names the file): the platform calls this for apps it learns of by
|
|
90
|
-
* their manifest, outside this package (RFC 0057).
|
|
91
|
-
*/
|
|
92
|
-
export function runnerCommand(harness: Pick<AgentHarness, "id"> | { id: string }, opts: { resume?: boolean } = {}): string {
|
|
93
|
-
const file = `"$HOME/.spunto/agents/${harness.id}.mjs"`
|
|
94
|
-
return [
|
|
95
|
-
`mkdir -p "$HOME/.spunto/agents" && printf %s "$${RUNNER_ENV}" | base64 -d > ${file} && unset ${RUNNER_ENV} &&`,
|
|
96
|
-
`exec ${AGENT_NODE} ${file} run${opts.resume ? ` --resume "$SPUNTO_TASK_SESSION_ID"` : ""}`,
|
|
97
|
-
].join(" ")
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** The harness an injected feature id belongs to, if any. */
|
|
101
|
-
export function harnessOfFeature(featureId: string): AgentHarness | null {
|
|
102
|
-
return Object.values(AGENT_HARNESSES).find((h) => h.featureId === featureId) ?? null
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export { AGENT_FEATURE_SCRIPTS, AGENT_HOME, AGENT_NODE_VERSION, MISTRAL_VIBE_VERSION } from "./features"
|
|
106
|
-
export { AGENT_CATALOGS, MCP_ENV, OPTIONS_ENV, STREAM_ENV, agentOptionsError } from "./catalogs"
|
|
107
|
-
export type { AgentCatalog, AgentMcpServer, AgentModel, AgentParam, AgentParamValue } from "./catalogs"
|