@spunto/build 0.30.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.
@@ -1,9 +1,8 @@
1
1
  // What the agent is writing *right now*, before it has finished saying it.
2
2
  //
3
3
  // The vocabulary (`agent-stream.ts`) is made of finished facts: a message lands once, whole. A
4
- // harness that streams tokens says the same message a second time, piecemeal, ahead of it —
5
- // Claude's `stream_event` lines (`includePartialMessages` in the Agent SDK,
6
- // `--include-partial-messages` on the CLI). Those pieces are **not events**: storing one row per
4
+ // runner whose harness streams tokens says the same message a second time, piecemeal, ahead of
5
+ // it — the contract's `message.delta` lines. Those pieces are **not events**: storing one row per
7
6
  // token would bury a session under thousands of rows that the finished message then repeats in
8
7
  // full. So they fold into one transient value instead — the draft — which the finished message
9
8
  // replaces the moment it lands, and which nothing persists.
@@ -29,17 +28,6 @@ function append(draft: AgentDraft | null, text: string): AgentDraft {
29
28
  return next.length > MAX_DRAFT ? { text: next.slice(0, MAX_DRAFT), truncated: true } : { text: next, truncated: false }
30
29
  }
31
30
 
32
- /** Claude's dialects print token deltas; Codex's prints the message so far on `item.updated`; the contract, `message.delta`. */
33
- function streamsPartials(protocol: AgentProtocol): boolean {
34
- return (
35
- protocol === "agent-v1" ||
36
- protocol === "claude-runner" ||
37
- protocol === "claude-stream" ||
38
- protocol === "claude-json" ||
39
- protocol === "codex-runner"
40
- )
41
- }
42
-
43
31
  /** What closes a draft in the contract: the finished text, or anything that comes after it in the turn. */
44
32
  const CLOSES_DRAFT = new Set(["message", "thinking", "tool.call", "tool.result", "session.ended"])
45
33
 
@@ -72,85 +60,12 @@ function foldContract(lines: string[], draft: AgentDraft | null): AgentDraft | n
72
60
  return current
73
61
  }
74
62
 
75
- /**
76
- * Codex: an `agent_message` item carries its whole text so far, not a delta — `item.started` and
77
- * `item.updated` *are* the draft, `item.completed` (stored as the `message`) or the end of the
78
- * turn closes it. Whether the SDK sends updates of a message mid-write is its business; the runner
79
- * prints every event it gets, so this costs nothing when it does not.
80
- */
81
- function foldCodex(lines: string[], draft: AgentDraft | null): AgentDraft | null {
82
- let current = draft
83
- for (const line of lines) {
84
- const trimmed = line.trim()
85
- if (!trimmed.startsWith("{")) continue
86
- if (!trimmed.includes('"agent_message"') && !trimmed.includes('"turn.')) continue
87
- let obj: Record<string, unknown>
88
- try {
89
- const parsed = JSON.parse(trimmed)
90
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) continue
91
- obj = parsed as Record<string, unknown>
92
- } catch {
93
- continue
94
- }
95
- if (obj.type === "turn.completed" || obj.type === "turn.failed") {
96
- current = null
97
- continue
98
- }
99
- const item = (obj.item ?? {}) as Record<string, unknown>
100
- if (item.type !== "agent_message") continue
101
- if (obj.type === "item.completed") current = null
102
- else if ((obj.type === "item.started" || obj.type === "item.updated") && typeof item.text === "string")
103
- current = item.text ? append(null, item.text) : null
104
- }
105
- return current
106
- }
107
-
108
63
  /**
109
64
  * Fold whole lines of a session's stdout into the draft, starting from `draft` (the value left
110
- * by the previous read). Lines that say nothing about the text in flight leave it as it was.
111
- *
112
- * - a text block starting opens a fresh draft — one draft is one block, as one stored `message`
113
- * is one block;
114
- * - a `text_delta` grows it;
115
- * - the finished `assistant` message, or the turn's `result`, closes it: from there on the
116
- * timeline has the real thing.
117
- *
118
- * A subagent's partials (`parent_tool_use_id` set) are skipped: what it writes is not what the
119
- * session says to the reader, and interleaving it would garble the draft of the main thread.
65
+ * by the previous read). Lines that say nothing about the text in flight leave it as it was; a
66
+ * session that does not speak the contract has no draft.
120
67
  */
121
68
  export function foldDraft(protocol: AgentProtocol, lines: string[], draft: AgentDraft | null): AgentDraft | null {
122
- if (!streamsPartials(protocol)) return null
123
- if (protocol === "agent-v1") return foldContract(lines, draft)
124
- if (protocol === "codex-runner") return foldCodex(lines, draft)
125
- let current = draft
126
- for (const line of lines) {
127
- const trimmed = line.trim()
128
- // Cheap pre-filter: most lines are not about the draft, and some carry megabytes.
129
- if (!trimmed.startsWith("{")) continue
130
- if (!trimmed.includes('"stream_event"') && !trimmed.includes('"assistant"') && !trimmed.includes('"result"')) continue
131
- let obj: Record<string, unknown>
132
- try {
133
- const parsed = JSON.parse(trimmed)
134
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) continue
135
- obj = parsed as Record<string, unknown>
136
- } catch {
137
- continue
138
- }
139
- if (obj.parent_tool_use_id) continue
140
-
141
- if (obj.type === "assistant" || obj.type === "result") {
142
- current = null
143
- continue
144
- }
145
- if (obj.type !== "stream_event") continue
146
- const event = (obj.event ?? {}) as Record<string, unknown>
147
- if (event.type === "content_block_start") {
148
- const block = (event.content_block ?? {}) as Record<string, unknown>
149
- if (block.type === "text") current = append(null, typeof block.text === "string" ? block.text : "")
150
- } else if (event.type === "content_block_delta") {
151
- const delta = (event.delta ?? {}) as Record<string, unknown>
152
- if (delta.type === "text_delta" && typeof delta.text === "string") current = append(current, delta.text)
153
- }
154
- }
155
- return current
69
+ if (protocol !== "agent-v1") return null
70
+ return foldContract(lines, draft)
156
71
  }
@@ -1,44 +1,29 @@
1
- // Reading an agent session as it happens: one adapter per harness dialect, one vocabulary out.
1
+ // Reading an agent session as it happens: the Spunto agent contract (`agent-v1`) in, our
2
+ // vocabulary out, and how to write to a session.
2
3
  //
3
- // A task's harness is launched with a prompt on stdin and nothing else agreed — that poverty is
4
- // what lets the command hold Claude Code, Codex, or a shell script. Streaming needs strictly more
5
- // than that, so the extra knowledge lives here and nowhere else.
6
- //
7
- // **The vocabulary is what gets stored, never the harness's own shape.** A CLI's JSON output is an
8
- // output format, not an API; persisting it would date the history the first time the vendor
9
- // reshuffles a field. Adapters translate into the small set of event types below, and anything
10
- // unmapped becomes `raw` rather than being dropped.
11
- //
12
- // It lives in this package for a reason that inverts the rest of it: **nothing has forked this
13
- // yet.** Every other module here was extracted after two copies had already drifted. This one is
14
- // 700 lines of third-party output parsing that exactly one product has today — putting it in the
15
- // shared package now costs nothing and means the second product never writes its own.
4
+ // **The vocabulary is what gets stored, never the harness's own shape.** Every harness is read by
5
+ // its agent app's runner, in the machine (`@spunto/agent-runners`); nothing here knows which one it was.
16
6
 
17
7
  export {
18
8
  AGENT_PROTOCOLS,
19
- applyProtocol,
20
- cleanTitle,
21
9
  interruptLine,
22
10
  isInteractive,
23
- isRunner,
24
11
  parseLines,
25
- parseSessionTitle,
26
12
  parseStreamLine,
27
- PROJECT_AGENT_PROTOCOLS,
28
- readsTitleOutOfBand,
29
- sessionTitleProbe,
30
13
  sessionTitleRequestLine,
31
14
  splitCompleteLines,
32
15
  summarizeUsage,
33
16
  TASK_EVENT_TYPES,
34
17
  userTurnLine,
35
18
  } from "./agent-stream"
36
- // The text block a streaming harness is still writing — folded from its partial messages, never stored.
19
+ // The text block a streaming harness is still writing — folded from `message.delta`, never stored.
37
20
  export { foldDraft } from "./draft"
38
21
  export type { AgentDraft } from "./draft"
39
- // Turns that ended on a usage/rate limit rather than on finished work, and when the limit lifts.
40
- export { claudeTurnLimit, resetFromText, TURN_LIMIT_KINDS } from "./turn-limit"
41
- export type { TurnLimit, TurnLimitKind } from "./turn-limit"
22
+ // A session's name, as it is kept: one line, bounded.
23
+ export { cleanTitle } from "../agent-contract/vocabulary"
24
+ // Turns that ended on a usage/rate limit rather than on finished work.
25
+ export { TURN_LIMIT_KINDS } from "../agent-contract/vocabulary"
26
+ export type { TurnLimit, TurnLimitKind } from "../agent-contract/vocabulary"
42
27
 
43
28
  export type {
44
29
  AgentProtocol,
@@ -49,17 +34,3 @@ export type {
49
34
  TaskEventType,
50
35
  UsageInput,
51
36
  } from "./agent-stream"
52
-
53
- // Model context windows. `liveContextWindow`/`resolveContextWindow` take a credential as a
54
- // *parameter* and ask the model vendor's own API — the package still reads no environment and
55
- // holds no key of its own, but it is the one place here that talks to something other than a
56
- // public registry, and it does so on the caller's behalf. `resetModelWindowCache` exists for
57
- // tests: the lookup memoises per process.
58
- export {
59
- apiModelId,
60
- contextWindowOf,
61
- liveContextWindow,
62
- resetModelWindowCache,
63
- resolveContextWindow,
64
- } from "./model-window"
65
- export type { ModelCredential } from "./model-window"
@@ -210,28 +210,6 @@ export const AVAILABLE_FEATURES: DevFeature[] = [
210
210
  localScript: "google-cloud-cli.sh",
211
211
  description: "gcloud, gsutil, bq (local install script)",
212
212
  },
213
- {
214
- // The agent apps' features (RFC 0048, `../agent-runners`): injected, never picked.
215
- id: "spunto-agent-claude",
216
- label: "Claude (agent app)",
217
- localScript: "spunto-agent-claude.sh",
218
- description: "The Claude Agent SDK and the Node its runner uses — injected by the Claude app",
219
- injected: true,
220
- },
221
- {
222
- id: "spunto-agent-codex",
223
- label: "Codex (agent app)",
224
- localScript: "spunto-agent-codex.sh",
225
- description: "The Codex SDK and the Node its runner uses — injected by the Codex app",
226
- injected: true,
227
- },
228
- {
229
- id: "spunto-agent-mistral",
230
- label: "Mistral Vibe (agent app)",
231
- localScript: "spunto-agent-mistral.sh",
232
- description: "Mistral Vibe (with its own Python) and the Node its runner uses — injected by the Mistral app",
233
- injected: true,
234
- },
235
213
  {
236
214
  // Always installed, whether or not it's picked here (lib/setup-script.ts § the two features
237
215
  // every worker image is made of): it's what creates the `vscode` user. Listed anyway so a
@@ -8,11 +8,7 @@
8
8
  //
9
9
  // Keyed by the catalog's `localScript` filename so the two stay legible together.
10
10
 
11
- import { AGENT_FEATURE_SCRIPTS } from "../agent-runners/features"
12
-
13
11
  export const LOCAL_FEATURE_SCRIPTS: Record<string, string> = {
14
- // The agent apps' features (RFC 0048): ours by definition — nobody upstream installs our runner's SDK.
15
- ...AGENT_FEATURE_SCRIPTS,
16
12
  // Google's own apt repository; the upstream devcontainer feature pins a gcloud version and
17
13
  // breaks whenever Google retires it.
18
14
  "google-cloud-cli.sh": `#!/bin/sh
package/src/spec/index.ts CHANGED
@@ -102,9 +102,8 @@ export const SpecProjectSchema = z.object({
102
102
  sharedVolumes: z.array(SpecSharedVolumeSchema).optional(),
103
103
 
104
104
  /** Spunto Cloud — how delegated work runs and reports. Meaningless to a product without tasks. */
105
- taskAgentCommand: z.string().optional(),
106
- taskAgentProtocol: z.enum(["none", "claude-json", "claude-stream", "jsonl"]).optional(),
107
- taskFollowUpCommand: z.string().optional(),
105
+ // `taskAgentCommand`, `taskAgentProtocol` and `taskFollowUpCommand` — the harness typed by hand,
106
+ // before agent apps — are gone (2026-11-24): an older file that has them still parses, without them.
108
107
  taskValidateCommand: z.string().optional(),
109
108
  taskCancelCommand: z.string().optional(),
110
109
  taskReviewMode: z.enum(["stop", "keep"]).optional(),
@@ -1,183 +0,0 @@
1
- /**
2
- * What each agent app (RFC 0048) lets a task choose: its models, and **its own parameters** —
3
- * effort, reasoning, web search… The platform knows none of them by name. It shows what an app
4
- * declares, checks a task's choice against it (`validateAgentOptions`), and hands the choice to the
5
- * runner (`OPTIONS_ENV`), which is the only code that knows what a parameter means to its SDK.
6
- *
7
- * **Measured, not remembered.** Each catalog is what the SDK pinned by its feature
8
- * (`./features.ts`) answers, and it changes when that pin moves:
9
- *
10
- * - Claude: `query().supportedModels()` of `@anthropic-ai/claude-agent-sdk` 0.3.310, on
11
- * 2026-10-26. Each model comes back with `supportedEffortLevels`;
12
- * - Codex: `codex debug models` of `@openai/codex` 0.164.0 — the catalog bundled in the binary,
13
- * offline, on 2026-10-26 — the `visibility: "list"` models, with their
14
- * `supported_reasoning_levels` and `default_reasoning_level`;
15
- * - Mistral: the `model` and `thinking` options of a `session/new` of `vibe-acp` 3.0.4, then of
16
- * `session/set_config_option` for each model, on 2026-10-31, with a pay-as-you-go API key.
17
- * Not all in the binary: Vibe's own default is Medium 3.5, and the others came from Mistral's
18
- * remote config (a rollout of Large 4 as the default the account was in) — an account outside
19
- * it may lack them, which the runner then says, with the models it does have.
20
- *
21
- * `packages/build/scripts/agent-catalogs.mjs` prints both again, to diff against this file when a
22
- * pin is bumped.
23
- */
24
-
25
- export type AgentParamValue = { value: string; label: string; description?: string }
26
-
27
- /** A parameter an app defines. A choice among values — the one shape both SDKs need today. */
28
- export type AgentParam = {
29
- id: string
30
- label: string
31
- description?: string
32
- values: AgentParamValue[]
33
- }
34
-
35
- export type AgentModel = {
36
- value: string
37
- label: string
38
- description?: string
39
- /** What the harness runs when no model is picked. */
40
- default?: boolean
41
- /** Values of a parameter this model allows, when it does not take all of them. */
42
- params?: Record<string, string[]>
43
- /** What this model runs with when the parameter is left unset — shown as the chip's placeholder. */
44
- paramDefaults?: Record<string, string>
45
- }
46
-
47
- export type AgentCatalog = {
48
- models: AgentModel[]
49
- params: AgentParam[]
50
- }
51
-
52
- /** The variable a task's chosen parameters reach the runner in, as one JSON object. */
53
- export const OPTIONS_ENV = "SPUNTO_AGENT_OPTIONS"
54
-
55
- /**
56
- * `"1"` when the session should stream the tokens of a message as they are written (partial
57
- * messages, folded into the draft by `foldDraft`). Set by the platform behind the org flag
58
- * `token-streaming`; absent, a runner prints finished messages only — the system before it.
59
- */
60
- export const STREAM_ENV = "SPUNTO_AGENT_STREAM"
61
-
62
- /**
63
- * The variable the org's MCP servers reach the runner in (RFC 0049): a JSON array of
64
- * `{ name, path }`, `path` being the platform's gateway for that server, resolved by the runner
65
- * against `SPUNTO_API_URL` and called with `SPUNTO_WORKER_TOKEN`. No vendor token, no harness shape.
66
- */
67
- export const MCP_ENV = "SPUNTO_AGENT_MCP"
68
-
69
- export type AgentMcpServer = { name: string; path: string }
70
-
71
- const CLAUDE_EFFORT: AgentParamValue[] = [
72
- { value: "low", label: "Low" },
73
- { value: "medium", label: "Medium" },
74
- { value: "high", label: "High" },
75
- { value: "xhigh", label: "Extra high" },
76
- { value: "max", label: "Max" },
77
- ]
78
-
79
- const CODEX_REASONING: AgentParamValue[] = [
80
- { value: "low", label: "Low", description: "Fast responses with lighter reasoning" },
81
- { value: "medium", label: "Medium", description: "Balances speed and reasoning depth for everyday tasks" },
82
- { value: "high", label: "High", description: "Greater reasoning depth for complex problems" },
83
- { value: "xhigh", label: "Extra high", description: "Extra high reasoning depth for complex problems" },
84
- { value: "max", label: "Max", description: "Maximum reasoning depth for the hardest problems" },
85
- { value: "ultra", label: "Ultra", description: "Maximum reasoning with automatic task delegation" },
86
- ]
87
-
88
- const ALL_BUT_ULTRA = ["low", "medium", "high", "xhigh", "max"]
89
-
90
- export const AGENT_CATALOGS: Record<"claude" | "codex" | "mistral", AgentCatalog> = {
91
- claude: {
92
- // The SDK's aliases (`default`, `sonnet`, `opus`, `fable`, `haiku`) resolved to the ids they
93
- // stand for: a task records the model it ran, not a name whose meaning moves.
94
- models: [
95
- { value: "claude-sonnet-5-5", label: "Claude Sonnet 5.5", description: "Default (recommended)", default: true },
96
- { value: "claude-opus-5-5", label: "Claude Opus 5.5" },
97
- { value: "claude-fable-5-2", label: "Claude Fable 5.2" },
98
- { value: "claude-haiku-5-5", label: "Claude Haiku 5.5" },
99
- ],
100
- params: [
101
- {
102
- id: "effort",
103
- label: "Effort",
104
- description: "How much Claude thinks before it acts. Unset = the model's own default.",
105
- values: CLAUDE_EFFORT,
106
- },
107
- ],
108
- },
109
- codex: {
110
- models: [
111
- { value: "gpt-6-astra", label: "GPT-6-Astra", description: "Frontier intelligence for the most demanding work.", paramDefaults: { reasoningEffort: "low" } },
112
- { value: "gpt-6.1-sol", label: "GPT-6.1-Sol", description: "Latest workhorse model for coding and everyday work.", paramDefaults: { reasoningEffort: "low" } },
113
- { value: "gpt-6-sol", label: "GPT-6-Sol", description: "Previous generation workhorse model.", paramDefaults: { reasoningEffort: "medium" } },
114
- { value: "gpt-6-luna", label: "GPT-6-Luna", description: "Fast and affordable model for easier tasks.", params: { reasoningEffort: ALL_BUT_ULTRA }, paramDefaults: { reasoningEffort: "medium" } },
115
- { value: "gpt-5.6-sol", label: "GPT-5.6-Sol", description: "Older generation workhorse model.", paramDefaults: { reasoningEffort: "low" } },
116
- { value: "gpt-5.6-terra", label: "GPT-5.6-Terra", description: "Older balanced model for straightforward work.", paramDefaults: { reasoningEffort: "medium" } },
117
- { value: "gpt-5.6-luna", label: "GPT-5.6-Luna", description: "Older fast and efficient model.", params: { reasoningEffort: ALL_BUT_ULTRA }, paramDefaults: { reasoningEffort: "medium" } },
118
- { value: "gpt-5.5", label: "GPT-5.5", description: "Legacy coding model.", params: { reasoningEffort: ["low", "medium", "high", "xhigh"] }, paramDefaults: { reasoningEffort: "medium" } },
119
- ],
120
- params: [
121
- {
122
- id: "reasoningEffort",
123
- label: "Reasoning",
124
- description: "How deeply Codex reasons. Unset = the model's own default.",
125
- values: CODEX_REASONING,
126
- },
127
- {
128
- id: "webSearch",
129
- label: "Web search",
130
- description: "Whether Codex may search the web: from a cache, live, or not at all. Unset = Codex's default.",
131
- values: [
132
- { value: "disabled", label: "Off" },
133
- { value: "cached", label: "Cached" },
134
- { value: "live", label: "Live" },
135
- ],
136
- },
137
- ],
138
- }, mistral: {
139
- // Vibe's aliases, which are what `session/set_config_option` takes (and what `--model` gets).
140
- models: [
141
- { value: "mistral-medium-3.5", label: "Mistral Medium 3.5", description: "Vibe's own default (mistral-vibe-cli-latest)", default: true, params: { thinking: ["off", "high"] }, paramDefaults: { thinking: "high" } },
142
- { value: "mistral-large-4-0-3", label: "Mistral Large 4", description: "mistral-large-4-0 — rolling out as Vibe's default", params: { thinking: ["low", "medium", "high"] }, paramDefaults: { thinking: "high" } },
143
- { value: "glm-5-3", label: "GLM-5.3", description: "zai-glm-5-3, hosted by Mistral", params: { thinking: ["low", "high", "max"] }, paramDefaults: { thinking: "high" } },
144
- { value: "zai-glm-5-3-flash", label: "GLM-5.3 Flash", description: "zai-glm-5-3-flash, hosted by Mistral", params: { thinking: ["low", "high", "max"] }, paramDefaults: { thinking: "high" } },
145
- ],
146
- params: [
147
- {
148
- id: "thinking",
149
- label: "Thinking",
150
- description: "How much the model reasons before it acts. Unset = the level Vibe last used for the model.",
151
- values: [
152
- { value: "off", label: "Off" },
153
- { value: "low", label: "Low" },
154
- { value: "medium", label: "Medium" },
155
- { value: "high", label: "High" },
156
- { value: "max", label: "Max" },
157
- ],
158
- },
159
- ],
160
- },
161
- }
162
-
163
- /**
164
- * Why these options cannot run under this catalog and model — or null when they can. An unknown
165
- * parameter, a value the parameter does not have, or one the model does not take. A model the
166
- * catalog does not list (typed by hand) is held to the parameter's values only: the catalog cannot
167
- * speak for it.
168
- */
169
- export function agentOptionsError(catalog: AgentCatalog, model: string | null | undefined, options: Record<string, string>): string | null {
170
- const known = model ? catalog.models.find((m) => m.value === model) : undefined
171
- for (const [id, value] of Object.entries(options)) {
172
- const param = catalog.params.find((p) => p.id === id)
173
- if (!param) return `Unknown parameter "${id}" — this harness takes ${catalog.params.map((p) => p.id).join(", ") || "none"}.`
174
- if (!param.values.some((v) => v.value === value)) {
175
- return `"${value}" is not a value of ${param.label} — one of ${param.values.map((v) => v.value).join(", ")}.`
176
- }
177
- const allowed = known?.params?.[id]
178
- if (allowed && !allowed.includes(value)) {
179
- return `${known!.label} does not take ${param.label} "${value}" — one of ${allowed.join(", ")}.`
180
- }
181
- }
182
- return null
183
- }