@spunto/build 0.32.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spunto/build",
3
- "version": "0.32.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",
@@ -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))
@@ -10,6 +10,7 @@ export {
10
10
  contractLineProblem,
11
11
  isTransient,
12
12
  MAX_TEXT,
13
+ QUESTION_STATUSES,
13
14
  readContractLine,
14
15
  readContractObject,
15
16
  SUBAGENT_STATUSES,
@@ -17,10 +18,10 @@ export {
17
18
  TRANSIENT_TYPES,
18
19
  TURN_LIMIT_KINDS,
19
20
  } from "./vocabulary"
20
- export type { NormalizedEvent, RunnerInput, SourcedEvent, TaskEventType, TransientType, TurnLimit, TurnLimitKind } from "./vocabulary"
21
+ export type { NormalizedEvent, QuestionAnswer, RunnerInput, SourcedEvent, TaskEventType, TransientType, TurnLimit, TurnLimitKind } from "./vocabulary"
21
22
 
22
23
  // The runner's side of it: how the platform starts one, what reaches it, what an app lets a task choose.
23
- export { AGENT_HOME, AGENT_NODE, MCP_ENV, OPTIONS_ENV, RUNNER_ENV, STREAM_ENV, agentOptionsError, runnerCommand } from "./runner"
24
+ export { AGENT_HOME, AGENT_NODE, MCP_ENV, OPTIONS_ENV, QUESTIONS_ENV, RUNNER_ENV, STREAM_ENV, agentOptionsError, runnerCommand } from "./runner"
24
25
  export type { AgentCatalog, AgentMcpServer, AgentModel, AgentParam, AgentParamValue } from "./runner"
25
26
 
26
27
  export { CONFORMANCE_PROMPTS, CONFORMANCE_SCENARIOS, runConformance } from "./conformance"
@@ -43,6 +43,13 @@ export const STREAM_ENV = "SPUNTO_AGENT_STREAM"
43
43
  */
44
44
  export const MCP_ENV = "SPUNTO_AGENT_MCP"
45
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
+
46
53
  export type AgentMcpServer = { name: string; path: string }
47
54
 
48
55
  /**
@@ -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 — three verbs, the same for
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",
@@ -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
@@ -6,6 +6,7 @@
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,