@spunto/build 0.31.0 → 0.33.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/agent-contract.v1.schema.json +177 -0
- package/src/agent-contract/conformance.ts +25 -2
- package/src/agent-contract/examples/fake-agent.mjs +11 -0
- package/src/agent-contract/index.ts +8 -1
- package/src/agent-contract/runner.ts +131 -0
- package/src/agent-contract/vocabulary.ts +38 -2
- package/src/agent-stream/agent-stream.ts +9 -3
- package/src/agent-stream/index.ts +3 -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
package/README.md
CHANGED
|
@@ -185,8 +185,17 @@ The JSON Schema is shipped as `@spunto/build/agent-contract/schema.json`, genera
|
|
|
185
185
|
table the reader validates with. The conformance suite drives a runner like the platform does and
|
|
186
186
|
checks every line and the order of events (simple turn, tool, interrupt, resume, limit, title,
|
|
187
187
|
files). `@spunto/build/agent-contract/fake-agent.mjs` is a whole runner in 46 lines with no SDK
|
|
188
|
-
that passes it.
|
|
189
|
-
|
|
188
|
+
that passes it.
|
|
189
|
+
|
|
190
|
+
The runner's side of the seam is here too, and nothing harness-specific with it: the shell that
|
|
191
|
+
starts a runner (`runnerCommand`, `AGENT_NODE` under `AGENT_HOME`), the variables a runner is
|
|
192
|
+
handed (`RUNNER_ENV`, `OPTIONS_ENV`, `STREAM_ENV`, `MCP_ENV`), and the shape of what an app lets a
|
|
193
|
+
task choose (`AgentCatalog`, checked by `agentOptionsError`).
|
|
194
|
+
|
|
195
|
+
**No harness lives in this package** (since 0.32.0). Spunto's own runners — Claude Code, Codex,
|
|
196
|
+
Mistral Vibe, with their adapters, the install scripts of their SDKs and their catalogs of models —
|
|
197
|
+
are [`@spunto/agent-runners`](../agent-runners/README.md), imported by the apps that *are* those
|
|
198
|
+
harnesses and never by a control plane.
|
|
190
199
|
|
|
191
200
|
### `@spunto/build/agent-stream` — reading an agent session as it happens
|
|
192
201
|
|
|
@@ -201,8 +210,7 @@ message, never stored. Where the draft lives between two reads is the caller's b
|
|
|
201
210
|
|
|
202
211
|
The harnesses' own dialects (Claude Code's `stream-json`, the runners' former `claude-runner` /
|
|
203
212
|
`codex-runner`) were read here until 0.31.0; they are gone, with `applyProtocol`, the title probe of
|
|
204
|
-
Claude's transcript and `PROJECT_AGENT_PROTOCOLS`.
|
|
205
|
-
next to its runner (`agent-runners/claude/`).
|
|
213
|
+
Claude's transcript and `PROJECT_AGENT_PROTOCOLS`.
|
|
206
214
|
|
|
207
215
|
### `@spunto/build/terminal` — the half of a persistent terminal that is a string
|
|
208
216
|
|
|
@@ -300,8 +308,7 @@ imports them.
|
|
|
300
308
|
|
|
301
309
|
Concretely: **no platform I/O**. No database, no Docker socket, no WebSocket. This package produces
|
|
302
310
|
strings and parses strings. Its only network calls are outbound HTTP on the caller's behalf — a
|
|
303
|
-
public extension registry
|
|
304
|
-
`resolveContextWindow` a credential — and it holds no credential of its own. Configuration arrives
|
|
311
|
+
public extension registry — and it holds no credential of its own. Configuration arrives
|
|
305
312
|
as function parameters, never read from the environment, so that one control plane can scope a
|
|
306
313
|
setting per organization and another per process without either shape leaking in here.
|
|
307
314
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spunto/build",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"description": "Spunto's shared Build engine — the devcontainer image protocol and VS Code extension registry clients, with no database, no HTTP framework and no UI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -87,14 +87,7 @@
|
|
|
87
87
|
},
|
|
88
88
|
"./sandbox-agent/agent.mjs": "./src/sandbox-agent/agent.mjs",
|
|
89
89
|
"./sandbox-agent/bootstrap.sh": "./src/sandbox-agent/bootstrap.sh",
|
|
90
|
-
"./sandbox-agent/runner.sh": "./src/sandbox-agent/runner.sh"
|
|
91
|
-
"./agent-runners": {
|
|
92
|
-
"types": "./src/agent-runners/index.ts",
|
|
93
|
-
"import": "./src/agent-runners/index.ts"
|
|
94
|
-
},
|
|
95
|
-
"./agent-runners/claude.mjs": "./src/agent-runners/claude.mjs",
|
|
96
|
-
"./agent-runners/codex.mjs": "./src/agent-runners/codex.mjs",
|
|
97
|
-
"./agent-runners/mistral.mjs": "./src/agent-runners/mistral.mjs"
|
|
90
|
+
"./sandbox-agent/runner.sh": "./src/sandbox-agent/runner.sh"
|
|
98
91
|
},
|
|
99
92
|
"files": [
|
|
100
93
|
"src",
|
|
@@ -850,6 +850,131 @@
|
|
|
850
850
|
],
|
|
851
851
|
"additionalProperties": false
|
|
852
852
|
},
|
|
853
|
+
{
|
|
854
|
+
"type": "object",
|
|
855
|
+
"properties": {
|
|
856
|
+
"type": {
|
|
857
|
+
"const": "question"
|
|
858
|
+
},
|
|
859
|
+
"source": {
|
|
860
|
+
"description": "The harness's own message this event was read from, verbatim — kept so the projection can be replayed."
|
|
861
|
+
},
|
|
862
|
+
"callId": {
|
|
863
|
+
"type": "string"
|
|
864
|
+
},
|
|
865
|
+
"status": {
|
|
866
|
+
"type": "string",
|
|
867
|
+
"enum": [
|
|
868
|
+
"pending",
|
|
869
|
+
"answered",
|
|
870
|
+
"dismissed"
|
|
871
|
+
]
|
|
872
|
+
},
|
|
873
|
+
"questions": {
|
|
874
|
+
"type": "array",
|
|
875
|
+
"items": {
|
|
876
|
+
"type": "object",
|
|
877
|
+
"properties": {
|
|
878
|
+
"question": {
|
|
879
|
+
"type": "string"
|
|
880
|
+
},
|
|
881
|
+
"header": {
|
|
882
|
+
"anyOf": [
|
|
883
|
+
{
|
|
884
|
+
"type": "string"
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
"type": "null"
|
|
888
|
+
}
|
|
889
|
+
]
|
|
890
|
+
},
|
|
891
|
+
"multiSelect": {
|
|
892
|
+
"type": "boolean"
|
|
893
|
+
},
|
|
894
|
+
"options": {
|
|
895
|
+
"type": "array",
|
|
896
|
+
"items": {
|
|
897
|
+
"type": "object",
|
|
898
|
+
"properties": {
|
|
899
|
+
"label": {
|
|
900
|
+
"type": "string"
|
|
901
|
+
},
|
|
902
|
+
"description": {
|
|
903
|
+
"anyOf": [
|
|
904
|
+
{
|
|
905
|
+
"type": "string"
|
|
906
|
+
},
|
|
907
|
+
{
|
|
908
|
+
"type": "null"
|
|
909
|
+
}
|
|
910
|
+
]
|
|
911
|
+
},
|
|
912
|
+
"preview": {
|
|
913
|
+
"anyOf": [
|
|
914
|
+
{
|
|
915
|
+
"type": "string"
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
"type": "null"
|
|
919
|
+
}
|
|
920
|
+
]
|
|
921
|
+
}
|
|
922
|
+
},
|
|
923
|
+
"required": [
|
|
924
|
+
"label"
|
|
925
|
+
],
|
|
926
|
+
"additionalProperties": false
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
},
|
|
930
|
+
"required": [
|
|
931
|
+
"question",
|
|
932
|
+
"options"
|
|
933
|
+
],
|
|
934
|
+
"additionalProperties": false
|
|
935
|
+
}
|
|
936
|
+
},
|
|
937
|
+
"answers": {
|
|
938
|
+
"type": "array",
|
|
939
|
+
"items": {
|
|
940
|
+
"type": "object",
|
|
941
|
+
"properties": {
|
|
942
|
+
"question": {
|
|
943
|
+
"type": "string"
|
|
944
|
+
},
|
|
945
|
+
"selected": {
|
|
946
|
+
"type": "array",
|
|
947
|
+
"items": {
|
|
948
|
+
"type": "string"
|
|
949
|
+
}
|
|
950
|
+
},
|
|
951
|
+
"text": {
|
|
952
|
+
"anyOf": [
|
|
953
|
+
{
|
|
954
|
+
"type": "string"
|
|
955
|
+
},
|
|
956
|
+
{
|
|
957
|
+
"type": "null"
|
|
958
|
+
}
|
|
959
|
+
]
|
|
960
|
+
}
|
|
961
|
+
},
|
|
962
|
+
"required": [
|
|
963
|
+
"question",
|
|
964
|
+
"selected"
|
|
965
|
+
],
|
|
966
|
+
"additionalProperties": false
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
},
|
|
970
|
+
"required": [
|
|
971
|
+
"type",
|
|
972
|
+
"callId",
|
|
973
|
+
"status",
|
|
974
|
+
"questions"
|
|
975
|
+
],
|
|
976
|
+
"additionalProperties": false
|
|
977
|
+
},
|
|
853
978
|
{
|
|
854
979
|
"type": "object",
|
|
855
980
|
"properties": {
|
|
@@ -955,6 +1080,58 @@
|
|
|
955
1080
|
"description"
|
|
956
1081
|
],
|
|
957
1082
|
"additionalProperties": false
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
"type": "object",
|
|
1086
|
+
"properties": {
|
|
1087
|
+
"type": {
|
|
1088
|
+
"type": "string",
|
|
1089
|
+
"enum": [
|
|
1090
|
+
"answer"
|
|
1091
|
+
]
|
|
1092
|
+
},
|
|
1093
|
+
"callId": {
|
|
1094
|
+
"type": "string"
|
|
1095
|
+
},
|
|
1096
|
+
"answers": {
|
|
1097
|
+
"type": "array",
|
|
1098
|
+
"items": {
|
|
1099
|
+
"type": "object",
|
|
1100
|
+
"properties": {
|
|
1101
|
+
"question": {
|
|
1102
|
+
"type": "string"
|
|
1103
|
+
},
|
|
1104
|
+
"selected": {
|
|
1105
|
+
"type": "array",
|
|
1106
|
+
"items": {
|
|
1107
|
+
"type": "string"
|
|
1108
|
+
}
|
|
1109
|
+
},
|
|
1110
|
+
"text": {
|
|
1111
|
+
"anyOf": [
|
|
1112
|
+
{
|
|
1113
|
+
"type": "string"
|
|
1114
|
+
},
|
|
1115
|
+
{
|
|
1116
|
+
"type": "null"
|
|
1117
|
+
}
|
|
1118
|
+
]
|
|
1119
|
+
}
|
|
1120
|
+
},
|
|
1121
|
+
"required": [
|
|
1122
|
+
"question",
|
|
1123
|
+
"selected"
|
|
1124
|
+
],
|
|
1125
|
+
"additionalProperties": false
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
},
|
|
1129
|
+
"required": [
|
|
1130
|
+
"type",
|
|
1131
|
+
"callId",
|
|
1132
|
+
"answers"
|
|
1133
|
+
],
|
|
1134
|
+
"additionalProperties": false
|
|
958
1135
|
}
|
|
959
1136
|
]
|
|
960
1137
|
}
|
|
@@ -35,7 +35,7 @@ export type RunnerProcess = {
|
|
|
35
35
|
/** Start the runner: `run`, plus `--resume <id>` when asked. */
|
|
36
36
|
export type StartRunner = (opts: { resume?: string }) => RunnerProcess
|
|
37
37
|
|
|
38
|
-
export const CONFORMANCE_SCENARIOS = ["simple", "tool", "interrupt", "resume", "limit", "title", "files"] as const
|
|
38
|
+
export const CONFORMANCE_SCENARIOS = ["simple", "tool", "interrupt", "resume", "limit", "title", "files", "question"] as const
|
|
39
39
|
export type ConformanceScenario = (typeof CONFORMANCE_SCENARIOS)[number]
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -45,7 +45,9 @@ export type ConformanceScenario = (typeof CONFORMANCE_SCENARIOS)[number]
|
|
|
45
45
|
* - `tool`: call one tool, get its result, answer, end the turn;
|
|
46
46
|
* - `long`: keep the turn going (a long tool call, say) until interrupted;
|
|
47
47
|
* - `limit`: end the turn on the account's usage limit, with the time it lifts;
|
|
48
|
-
* - `screenshot`: call a tool whose result is a PNG, inline (base64), and end the turn
|
|
48
|
+
* - `screenshot`: call a tool whose result is a PNG, inline (base64), and end the turn;
|
|
49
|
+
* - `question`: ask the human to choose between at least two options, wait for the answer, then
|
|
50
|
+
* say in prose what was picked and end the turn.
|
|
49
51
|
*/
|
|
50
52
|
export const CONFORMANCE_PROMPTS = {
|
|
51
53
|
reply: "spunto-conformance: reply",
|
|
@@ -53,6 +55,7 @@ export const CONFORMANCE_PROMPTS = {
|
|
|
53
55
|
long: "spunto-conformance: long",
|
|
54
56
|
limit: "spunto-conformance: limit",
|
|
55
57
|
screenshot: "spunto-conformance: screenshot",
|
|
58
|
+
question: "spunto-conformance: question",
|
|
56
59
|
} as const
|
|
57
60
|
|
|
58
61
|
export type ConformanceResult = {
|
|
@@ -288,6 +291,26 @@ const SCENARIOS: Record<ConformanceScenario, (launch: Launch, problems: string[]
|
|
|
288
291
|
if (result) expect(problems, !String(result.output).includes(fileData(result) ?? "\u0000"), "the file's bytes are in the result's `output` text")
|
|
289
292
|
await s.close()
|
|
290
293
|
},
|
|
294
|
+
|
|
295
|
+
// A question of the agent's: printed `pending`, answered by the `answer` verb, restated `answered`
|
|
296
|
+
// with what was picked — and the turn waited for it, then carried on.
|
|
297
|
+
async question(launch, problems) {
|
|
298
|
+
const s = launch()
|
|
299
|
+
s.send({ type: "user", text: CONFORMANCE_PROMPTS.question })
|
|
300
|
+
const asked = await s.next("a `question` `pending`", (l) => l.type === "question" && l.status === "pending")
|
|
301
|
+
const first = (asked.questions as Line[] | undefined)?.[0]
|
|
302
|
+
const options = (first?.options as Line[] | undefined) ?? []
|
|
303
|
+
expect(problems, options.length >= 2, "the question offers fewer than two options")
|
|
304
|
+
expect(problems, !s.all().some((l) => l.type === "session.ended"), "the turn ended before the question was answered — it must wait")
|
|
305
|
+
const pick = String(options[0]?.label ?? "")
|
|
306
|
+
s.send({ type: "answer", callId: String(asked.callId), answers: [{ question: String(first?.question ?? ""), selected: [pick] }] })
|
|
307
|
+
const answered = await s.next("the question restated `answered`", (l) => l.type === "question" && l.callId === asked.callId && l.status === "answered")
|
|
308
|
+
const answers = (answered.answers as Line[] | undefined) ?? []
|
|
309
|
+
expect(problems, answers.some((a) => Array.isArray(a.selected) && a.selected.includes(pick)), "the answered question does not carry the option picked")
|
|
310
|
+
const { ended } = await s.turn()
|
|
311
|
+
expect(problems, ended.status === "succeeded", `the turn ended ${String(ended.status)} after the answer (expected succeeded)`)
|
|
312
|
+
await s.close()
|
|
313
|
+
},
|
|
291
314
|
}
|
|
292
315
|
|
|
293
316
|
/** The first base64 file block's data in a line, if any. */
|
|
@@ -13,6 +13,7 @@ const resume = argv[argv.indexOf("--resume") + 1]
|
|
|
13
13
|
const sessionId = argv.includes("--resume") && resume ? resume : `fake-${process.pid}`
|
|
14
14
|
let started = false
|
|
15
15
|
let pending = null // the turn waiting to be interrupted
|
|
16
|
+
let asked = null // the turn waiting on the human's answer
|
|
16
17
|
|
|
17
18
|
function turn(text) {
|
|
18
19
|
if (!started) out({ type: "session.started", harness: "fake", model: null, sessionId }), (started = true)
|
|
@@ -31,6 +32,15 @@ function turn(text) {
|
|
|
31
32
|
const limit = { kind: "usage", status: 429, message: "Usage limit reached", resetsAt }
|
|
32
33
|
return out({ type: "session.ended", status: "failed", summary: limit.message, limit })
|
|
33
34
|
}
|
|
35
|
+
if (text.endsWith("question")) {
|
|
36
|
+
const questions = [{ question: "Which color?", options: [{ label: "Red" }, { label: "Blue" }] }]
|
|
37
|
+
out({ type: "question", callId: "q1", status: "pending", questions })
|
|
38
|
+
return (asked = (answers) => {
|
|
39
|
+
out({ type: "question", callId: "q1", status: "answered", questions, answers })
|
|
40
|
+
out({ type: "message", role: "assistant", text: `You picked ${answers[0]?.selected.join(", ")}` })
|
|
41
|
+
done("ok")
|
|
42
|
+
})
|
|
43
|
+
}
|
|
34
44
|
if (text.endsWith("long")) return (pending = () => out({ type: "session.ended", status: "failed", summary: "Interrupted." }))
|
|
35
45
|
out({ type: "message", role: "assistant", text: `You said: ${text}` })
|
|
36
46
|
done("ok")
|
|
@@ -41,6 +51,7 @@ createInterface({ input: process.stdin })
|
|
|
41
51
|
const msg = JSON.parse(line)
|
|
42
52
|
if (msg.type === "user") turn(msg.text)
|
|
43
53
|
if (msg.type === "interrupt") pending?.(), (pending = null)
|
|
54
|
+
if (msg.type === "answer") asked?.(msg.answers), (asked = null)
|
|
44
55
|
if (msg.type === "title") out({ type: "session.title", title: msg.description.slice(0, 60) })
|
|
45
56
|
})
|
|
46
57
|
.on("close", () => process.exit(0))
|
|
@@ -5,17 +5,24 @@
|
|
|
5
5
|
export {
|
|
6
6
|
AGENT_CONTRACT_VERSION,
|
|
7
7
|
agentContractSchema,
|
|
8
|
+
cleanTitle,
|
|
8
9
|
clip,
|
|
9
10
|
contractLineProblem,
|
|
10
11
|
isTransient,
|
|
11
12
|
MAX_TEXT,
|
|
13
|
+
QUESTION_STATUSES,
|
|
12
14
|
readContractLine,
|
|
13
15
|
readContractObject,
|
|
14
16
|
SUBAGENT_STATUSES,
|
|
15
17
|
TASK_EVENT_TYPES,
|
|
16
18
|
TRANSIENT_TYPES,
|
|
19
|
+
TURN_LIMIT_KINDS,
|
|
17
20
|
} from "./vocabulary"
|
|
18
|
-
export type { NormalizedEvent, RunnerInput, SourcedEvent, TaskEventType, TransientType } from "./vocabulary"
|
|
21
|
+
export type { NormalizedEvent, QuestionAnswer, RunnerInput, SourcedEvent, TaskEventType, TransientType, TurnLimit, TurnLimitKind } from "./vocabulary"
|
|
22
|
+
|
|
23
|
+
// The runner's side of it: how the platform starts one, what reaches it, what an app lets a task choose.
|
|
24
|
+
export { AGENT_HOME, AGENT_NODE, MCP_ENV, OPTIONS_ENV, QUESTIONS_ENV, RUNNER_ENV, STREAM_ENV, agentOptionsError, runnerCommand } from "./runner"
|
|
25
|
+
export type { AgentCatalog, AgentMcpServer, AgentModel, AgentParam, AgentParamValue } from "./runner"
|
|
19
26
|
|
|
20
27
|
export { CONFORMANCE_PROMPTS, CONFORMANCE_SCENARIOS, runConformance } from "./conformance"
|
|
21
28
|
export type { ConformanceOptions, ConformanceResult, ConformanceScenario, RunnerProcess, StartRunner } from "./conformance"
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The runner contract (RFC 0048), seen from the platform: how a session of an agent app is started,
|
|
3
|
+
* what reaches it in its environment, and the shape of what an app lets a task choose. Every
|
|
4
|
+
* harness is the same here — which one it is, its SDK and its runner live with the app
|
|
5
|
+
* (`@spunto/agent-runners` for Spunto's own: Claude Code, Codex, Mistral Vibe), never in the
|
|
6
|
+
* platform.
|
|
7
|
+
*
|
|
8
|
+
* <node> <runner>.mjs run [--model <id>] [--resume <session id>]
|
|
9
|
+
* stdin one JSON object per line: {"type":"user","text"} · {"type":"interrupt","id"} ·
|
|
10
|
+
* {"type":"title","id","description"} (`RunnerInput`); closed ⇒ end after the turn
|
|
11
|
+
* env SPUNTO_AGENT_OPTIONS — the task's parameters, one JSON object
|
|
12
|
+
* stdout our vocabulary (`./vocabulary.ts`), one JSON object per line
|
|
13
|
+
* exit 0 = the input closed and the last turn ended; ≠ 0 = the session could not run, and its
|
|
14
|
+
* last line is a failed `session.ended` saying why
|
|
15
|
+
*
|
|
16
|
+
* Pure: what a caller gets is the shell that starts a runner. Fetching it and writing it into the
|
|
17
|
+
* machine are the caller's I/O.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** Where an agent app's feature installs its harness — and the private Node its runner runs on. */
|
|
21
|
+
export const AGENT_HOME = "/opt/spunto/agents"
|
|
22
|
+
|
|
23
|
+
/** The Node every runner runs on — the private one the features install. */
|
|
24
|
+
export const AGENT_NODE = `${AGENT_HOME}/node/bin/node`
|
|
25
|
+
|
|
26
|
+
/** The variable a runner's text travels in, base64 — see `runnerCommand`. */
|
|
27
|
+
export const RUNNER_ENV = "SPUNTO_AGENT_RUNNER"
|
|
28
|
+
|
|
29
|
+
/** The variable a task's chosen parameters reach the runner in, as one JSON object. */
|
|
30
|
+
export const OPTIONS_ENV = "SPUNTO_AGENT_OPTIONS"
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* `"1"` when the session should stream the tokens of a message as they are written (partial
|
|
34
|
+
* messages, folded into the draft by `foldDraft`). Set by the platform behind the org flag
|
|
35
|
+
* `token-streaming`; absent, a runner prints finished messages only — the system before it.
|
|
36
|
+
*/
|
|
37
|
+
export const STREAM_ENV = "SPUNTO_AGENT_STREAM"
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The variable the org's MCP servers reach the runner in (RFC 0049): a JSON array of
|
|
41
|
+
* `{ name, path }`, `path` being the platform's gateway for that server, resolved by the runner
|
|
42
|
+
* against `SPUNTO_API_URL` and called with `SPUNTO_WORKER_TOKEN`. No vendor token, no harness shape.
|
|
43
|
+
*/
|
|
44
|
+
export const MCP_ENV = "SPUNTO_AGENT_MCP"
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* `"1"` when a human is at the other end of the session to answer the agent's questions (`question`
|
|
48
|
+
* events, the `answer` verb): a task someone delegated, not a sub-task another agent drives. Absent,
|
|
49
|
+
* a runner does not let its harness ask — the turn would wait on someone who is not coming.
|
|
50
|
+
*/
|
|
51
|
+
export const QUESTIONS_ENV = "SPUNTO_AGENT_QUESTIONS"
|
|
52
|
+
|
|
53
|
+
export type AgentMcpServer = { name: string; path: string }
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The shell that starts a session: write the runner out of `$SPUNTO_AGENT_RUNNER` (base64, set by
|
|
57
|
+
* the caller in the command's environment), then `exec` it on the feature's Node so the session
|
|
58
|
+
* *is* the runner — stdin, signals and exit code included.
|
|
59
|
+
*
|
|
60
|
+
* The text rides in the environment rather than in the command because the command is what the
|
|
61
|
+
* platform shows ("what the platform ran"): eight kilobytes of base64 there would bury the one line
|
|
62
|
+
* worth reading. `--model` is appended by the platform like for any harness; `resume` adds the
|
|
63
|
+
* session the platform read off the stream, passed as `$SPUNTO_TASK_SESSION_ID`.
|
|
64
|
+
*
|
|
65
|
+
* Only the app's id is needed (it names the file): the platform calls this for apps it learns of by
|
|
66
|
+
* their manifest (RFC 0057).
|
|
67
|
+
*/
|
|
68
|
+
export function runnerCommand(harness: { id: string }, opts: { resume?: boolean } = {}): string {
|
|
69
|
+
const file = `"$HOME/.spunto/agents/${harness.id}.mjs"`
|
|
70
|
+
return [
|
|
71
|
+
`mkdir -p "$HOME/.spunto/agents" && printf %s "$${RUNNER_ENV}" | base64 -d > ${file} && unset ${RUNNER_ENV} &&`,
|
|
72
|
+
`exec ${AGENT_NODE} ${file} run${opts.resume ? ` --resume "$SPUNTO_TASK_SESSION_ID"` : ""}`,
|
|
73
|
+
].join(" ")
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ── What an app lets a task choose ────────────────────────────────────────────
|
|
77
|
+
//
|
|
78
|
+
// Its models, and **its own parameters** — effort, reasoning, web search… The platform knows none
|
|
79
|
+
// of them by name: it shows what an app declares, checks a task's choice against it
|
|
80
|
+
// (`agentOptionsError`), and hands the choice to the runner (`OPTIONS_ENV`), the only code that
|
|
81
|
+
// knows what a parameter means to its SDK.
|
|
82
|
+
|
|
83
|
+
export type AgentParamValue = { value: string; label: string; description?: string }
|
|
84
|
+
|
|
85
|
+
/** A parameter an app defines. A choice among values — the one shape both SDKs need today. */
|
|
86
|
+
export type AgentParam = {
|
|
87
|
+
id: string
|
|
88
|
+
label: string
|
|
89
|
+
description?: string
|
|
90
|
+
values: AgentParamValue[]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export type AgentModel = {
|
|
94
|
+
value: string
|
|
95
|
+
label: string
|
|
96
|
+
description?: string
|
|
97
|
+
/** What the harness runs when no model is picked. */
|
|
98
|
+
default?: boolean
|
|
99
|
+
/** Values of a parameter this model allows, when it does not take all of them. */
|
|
100
|
+
params?: Record<string, string[]>
|
|
101
|
+
/** What this model runs with when the parameter is left unset — shown as the chip's placeholder. */
|
|
102
|
+
paramDefaults?: Record<string, string>
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export type AgentCatalog = {
|
|
106
|
+
models: AgentModel[]
|
|
107
|
+
params: AgentParam[]
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Why these options cannot run under this catalog and model — or null when they can. An unknown
|
|
113
|
+
* parameter, a value the parameter does not have, or one the model does not take. A model the
|
|
114
|
+
* catalog does not list (typed by hand) is held to the parameter's values only: the catalog cannot
|
|
115
|
+
* speak for it.
|
|
116
|
+
*/
|
|
117
|
+
export function agentOptionsError(catalog: AgentCatalog, model: string | null | undefined, options: Record<string, string>): string | null {
|
|
118
|
+
const known = model ? catalog.models.find((m) => m.value === model) : undefined
|
|
119
|
+
for (const [id, value] of Object.entries(options)) {
|
|
120
|
+
const param = catalog.params.find((p) => p.id === id)
|
|
121
|
+
if (!param) return `Unknown parameter "${id}" — this harness takes ${catalog.params.map((p) => p.id).join(", ") || "none"}.`
|
|
122
|
+
if (!param.values.some((v) => v.value === value)) {
|
|
123
|
+
return `"${value}" is not a value of ${param.label} — one of ${param.values.map((v) => v.value).join(", ")}.`
|
|
124
|
+
}
|
|
125
|
+
const allowed = known?.params?.[id]
|
|
126
|
+
if (allowed && !allowed.includes(value)) {
|
|
127
|
+
return `${known!.label} does not take ${param.label} "${value}" — one of ${allowed.join(", ")}.`
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return null
|
|
131
|
+
}
|
|
@@ -38,7 +38,7 @@ const MAX_TITLE = 200
|
|
|
38
38
|
* Why a turn ended on a limit rather than on finished work: `usage` (the plan's quota, back at a
|
|
39
39
|
* time the harness usually knows), `rate` (a burst limit, seconds to minutes), `overloaded` (the
|
|
40
40
|
* vendor's API, later). Which harness message is which is the runner's reading
|
|
41
|
-
* (
|
|
41
|
+
* (`claude/turn-limit.ts` of `@spunto/agent-runners` for Claude).
|
|
42
42
|
*/
|
|
43
43
|
export const TURN_LIMIT_KINDS = ["usage", "rate", "overloaded"] as const
|
|
44
44
|
export type TurnLimitKind = (typeof TURN_LIMIT_KINDS)[number]
|
|
@@ -74,6 +74,7 @@ export const TASK_EVENT_TYPES = [
|
|
|
74
74
|
"subagent",
|
|
75
75
|
"context.compacted",
|
|
76
76
|
"skill.loaded",
|
|
77
|
+
"question",
|
|
77
78
|
"raw",
|
|
78
79
|
] as const
|
|
79
80
|
export type TaskEventType = (typeof TASK_EVENT_TYPES)[number]
|
|
@@ -94,8 +95,11 @@ export type NormalizedEvent = {
|
|
|
94
95
|
/** An event and the harness line it came from. One line can yield several. */
|
|
95
96
|
export type SourcedEvent = NormalizedEvent & { source: string }
|
|
96
97
|
|
|
98
|
+
/** The human's answer to one question of a `question` event: the options picked, and/or their own words. */
|
|
99
|
+
export type QuestionAnswer = { question: string; selected: string[]; text?: string | null }
|
|
100
|
+
|
|
97
101
|
/**
|
|
98
|
-
* One line of a runner's stdin. The whole input side of the contract —
|
|
102
|
+
* One line of a runner's stdin. The whole input side of the contract — four verbs, the same for
|
|
99
103
|
* every harness, so the platform never writes a harness's own shape into a runner. Closing stdin
|
|
100
104
|
* ends the session once its turn is over.
|
|
101
105
|
*/
|
|
@@ -103,6 +107,7 @@ export type RunnerInput =
|
|
|
103
107
|
| { type: "user"; text: string }
|
|
104
108
|
| { type: "interrupt"; id: string }
|
|
105
109
|
| { type: "title"; id: string; description: string }
|
|
110
|
+
| { type: "answer"; callId: string; answers: QuestionAnswer[] }
|
|
106
111
|
|
|
107
112
|
// ── The table ─────────────────────────────────────────────────────────────────
|
|
108
113
|
|
|
@@ -182,6 +187,16 @@ const PARENT = nullable(str())
|
|
|
182
187
|
/** How a subagent stands. `stopped`: killed before it ended (an interrupt, a dead process). */
|
|
183
188
|
export const SUBAGENT_STATUSES = ["running", "completed", "failed", "stopped"] as const
|
|
184
189
|
|
|
190
|
+
/**
|
|
191
|
+
* How a question of the agent's stands. `pending`: the turn is waiting on the human's choice.
|
|
192
|
+
* `answered`: they chose (`answer` verb). `dismissed`: it will never be answered as asked — the
|
|
193
|
+
* human wrote a message instead (which the runner hands the harness as the answer), or the turn
|
|
194
|
+
* was interrupted.
|
|
195
|
+
*/
|
|
196
|
+
export const QUESTION_STATUSES = ["pending", "answered", "dismissed"] as const
|
|
197
|
+
|
|
198
|
+
const ANSWERS = array(object({ question: req(str()), selected: req(array(str())), text: nullable(str()) }))
|
|
199
|
+
|
|
185
200
|
/**
|
|
186
201
|
* Every line type, and its fields. `type` and `source` are on every line and not repeated here.
|
|
187
202
|
* A field absent from a line is "unknown", which is not the same as `null` only for the reader of
|
|
@@ -290,6 +305,26 @@ const FIELDS: Record<TaskEventType | TransientType, Record<string, Field>> = {
|
|
|
290
305
|
truncated: bool(),
|
|
291
306
|
parentCallId: PARENT,
|
|
292
307
|
},
|
|
308
|
+
// The agent asks the human to choose, and its turn waits for the answer (Claude Code's
|
|
309
|
+
// `AskUserQuestion`): restated whole on every change, the latest line of a `callId` is where it
|
|
310
|
+
// stands. `callId` is the tool call that asked, when the harness asks through one. `answers` once
|
|
311
|
+
// `answered`, one per question: the options' labels picked, and `text`, the human's own words.
|
|
312
|
+
question: {
|
|
313
|
+
callId: req(str()),
|
|
314
|
+
status: req(oneOf(QUESTION_STATUSES)),
|
|
315
|
+
questions: req(
|
|
316
|
+
array(
|
|
317
|
+
object({
|
|
318
|
+
question: req(str()),
|
|
319
|
+
// A very short label for the question (« Library », « Approach »).
|
|
320
|
+
header: nullable(str()),
|
|
321
|
+
multiSelect: bool(),
|
|
322
|
+
options: req(array(object({ label: req(str()), description: nullable(str()), preview: nullable(str()) }))),
|
|
323
|
+
}),
|
|
324
|
+
),
|
|
325
|
+
),
|
|
326
|
+
answers: ANSWERS,
|
|
327
|
+
},
|
|
293
328
|
raw: { json: any(), text: str() },
|
|
294
329
|
// Not stored. `start` opens a fresh draft (one draft is one text block), else `text` is appended.
|
|
295
330
|
"message.delta": { text: req(str()), start: bool() },
|
|
@@ -306,6 +341,7 @@ export function agentContractSchema(): Record<string, unknown> {
|
|
|
306
341
|
{ type: req(oneOf(["user"])), text: req(str()) },
|
|
307
342
|
{ type: req(oneOf(["interrupt"])), id: req(str()) },
|
|
308
343
|
{ type: req(oneOf(["title"])), id: req(str()), description: req(str()) },
|
|
344
|
+
{ type: req(oneOf(["answer"])), callId: req(str()), answers: req(ANSWERS) },
|
|
309
345
|
]
|
|
310
346
|
return {
|
|
311
347
|
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* The harnesses' own dialects (Claude Code's `stream-json`, Codex's events) used to be read here
|
|
10
10
|
* too, for the tasks delegated before agent apps and the runners' first sessions. Retired on
|
|
11
11
|
* 2026-11-24, once no task alive spoke them: what a harness prints is its runner's business, in the
|
|
12
|
-
* machine (
|
|
12
|
+
* machine (`@spunto/agent-runners` for Spunto's own apps), never the platform's.
|
|
13
13
|
*
|
|
14
14
|
* Two rules the rest of the code depends on:
|
|
15
15
|
*
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
* ingestion loop lives in task-events.service.ts.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import { readContractLine, type NormalizedEvent, type RunnerInput, type SourcedEvent } from "../agent-contract/vocabulary"
|
|
24
|
+
import { readContractLine, type NormalizedEvent, type QuestionAnswer, type RunnerInput, type SourcedEvent } from "../agent-contract/vocabulary"
|
|
25
25
|
|
|
26
26
|
export { TASK_EVENT_TYPES } from "../agent-contract/vocabulary"
|
|
27
|
-
export type { NormalizedEvent, RunnerInput, SourcedEvent, TaskEventType } from "../agent-contract/vocabulary"
|
|
27
|
+
export type { NormalizedEvent, QuestionAnswer, RunnerInput, SourcedEvent, TaskEventType } from "../agent-contract/vocabulary"
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* How a session is read.
|
|
@@ -63,6 +63,12 @@ export function interruptLine(protocol: AgentProtocol, requestId: string): strin
|
|
|
63
63
|
return runnerLine({ type: "interrupt", id: requestId })
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/** The human's choice, for a question the agent asked (`question`) and waits on — or null for a session that cannot be told. */
|
|
67
|
+
export function answerLine(protocol: AgentProtocol, callId: string, answers: QuestionAnswer[]): string | null {
|
|
68
|
+
if (protocol !== "agent-v1") return null
|
|
69
|
+
return runnerLine({ type: "answer", callId, answers })
|
|
70
|
+
}
|
|
71
|
+
|
|
66
72
|
/**
|
|
67
73
|
* Ask the session to **name the conversation**, or null when it cannot be asked. The runner
|
|
68
74
|
* answers — if its harness can name a conversation at all — with a `session.title` line; the
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// vocabulary out, and how to write to a session.
|
|
3
3
|
//
|
|
4
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 (
|
|
5
|
+
// its agent app's runner, in the machine (`@spunto/agent-runners`); nothing here knows which one it was.
|
|
6
6
|
|
|
7
7
|
export {
|
|
8
8
|
AGENT_PROTOCOLS,
|
|
9
|
+
answerLine,
|
|
9
10
|
interruptLine,
|
|
10
11
|
isInteractive,
|
|
11
12
|
parseLines,
|
|
@@ -28,6 +29,7 @@ export type { TurnLimit, TurnLimitKind } from "../agent-contract/vocabulary"
|
|
|
28
29
|
export type {
|
|
29
30
|
AgentProtocol,
|
|
30
31
|
NormalizedEvent,
|
|
32
|
+
QuestionAnswer,
|
|
31
33
|
RunnerInput,
|
|
32
34
|
SessionUsage,
|
|
33
35
|
SourcedEvent,
|