@turri-dev/cli 0.2.3 → 0.2.4-next.009bd0c

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.
Files changed (175) hide show
  1. package/README.md +7 -8
  2. package/dist/bedrock-region.js +3 -3
  3. package/dist/chat-idle.d.ts +2 -2
  4. package/dist/chat-idle.js +2 -2
  5. package/dist/chat-models.d.ts +1 -1
  6. package/dist/chat-models.js +1 -1
  7. package/dist/chat-scope.d.ts +1 -3
  8. package/dist/chat-skills.d.ts +1 -1
  9. package/dist/chat-skills.js +1 -1
  10. package/dist/chats.d.ts +44 -20
  11. package/dist/chats.js +125 -64
  12. package/dist/cli.js +12 -31
  13. package/dist/config-edit.d.ts +20 -8
  14. package/dist/config-edit.js +32 -26
  15. package/dist/config.d.ts +106 -78
  16. package/dist/config.js +267 -133
  17. package/dist/conform-cli.js +14 -3
  18. package/dist/conformance-switch.d.ts +13 -22
  19. package/dist/conformance-switch.js +37 -59
  20. package/dist/drift-cli.js +1 -1
  21. package/dist/extension.d.ts +17 -10
  22. package/dist/extension.js +425 -531
  23. package/dist/genome.js +10 -49
  24. package/dist/graph.js +3 -5
  25. package/dist/host-session.d.ts +11 -21
  26. package/dist/host-session.js +6 -8
  27. package/dist/host.d.ts +4 -4
  28. package/dist/host.js +4 -7
  29. package/dist/identity.js +2 -3
  30. package/dist/init-config.d.ts +1 -2
  31. package/dist/init-config.js +10 -17
  32. package/dist/installed-providers.d.ts +1 -1
  33. package/dist/installed-providers.js +1 -1
  34. package/dist/launch-agent.d.ts +41 -0
  35. package/dist/launch-agent.js +219 -0
  36. package/dist/{release-cli.js → launch-cli.js} +41 -24
  37. package/dist/launch-session.d.ts +58 -0
  38. package/dist/launch-session.js +195 -0
  39. package/dist/launch-tools.d.ts +28 -0
  40. package/dist/launch-tools.js +69 -0
  41. package/dist/launch-track.d.ts +120 -0
  42. package/dist/launch-track.js +298 -0
  43. package/dist/loop-cli.d.ts +4 -3
  44. package/dist/loop-cli.js +17 -15
  45. package/dist/loop-tools.d.ts +45 -21
  46. package/dist/loop-tools.js +155 -90
  47. package/dist/new-project.js +2 -2
  48. package/dist/notice.d.ts +7 -6
  49. package/dist/parse-cli.js +2 -2
  50. package/dist/pi-launch.js +4 -1
  51. package/dist/pi-settings.d.ts +4 -0
  52. package/dist/pi-settings.js +39 -0
  53. package/dist/pi.js +12 -9
  54. package/dist/plain/check.d.ts +2 -9
  55. package/dist/plain/check.js +6 -39
  56. package/dist/plain-files.d.ts +2 -2
  57. package/dist/plain-files.js +7 -7
  58. package/dist/regenerate/activity.d.ts +0 -7
  59. package/dist/regenerate/activity.js +2 -20
  60. package/dist/regenerate/agent-env.d.ts +1 -1
  61. package/dist/regenerate/agent-env.js +3 -3
  62. package/dist/regenerate/agent-shell.js +5 -3
  63. package/dist/regenerate/audit.js +9 -0
  64. package/dist/regenerate/base-folder.d.ts +2 -2
  65. package/dist/regenerate/base-folder.js +1 -1
  66. package/dist/regenerate/cases.js +7 -0
  67. package/dist/regenerate/chunk-plan.d.ts +5 -0
  68. package/dist/regenerate/chunk-plan.js +16 -1
  69. package/dist/regenerate/command-check.d.ts +1 -1
  70. package/dist/regenerate/command-check.js +1 -1
  71. package/dist/regenerate/delivery.d.ts +1 -1
  72. package/dist/regenerate/delivery.js +3 -3
  73. package/dist/regenerate/drift.d.ts +4 -0
  74. package/dist/regenerate/drift.js +26 -6
  75. package/dist/regenerate/failure-reports.d.ts +28 -0
  76. package/dist/regenerate/failure-reports.js +79 -0
  77. package/dist/regenerate/job-panel.js +3 -1
  78. package/dist/regenerate/jobs-tree.js +1 -1
  79. package/dist/regenerate/jobs.d.ts +4 -2
  80. package/dist/regenerate/jobs.js +14 -10
  81. package/dist/regenerate/launch.d.ts +126 -0
  82. package/dist/regenerate/{release.js → launch.js} +60 -48
  83. package/dist/regenerate/ledger-view.d.ts +11 -24
  84. package/dist/regenerate/ledger-view.js +14 -60
  85. package/dist/regenerate/ledger.d.ts +26 -16
  86. package/dist/regenerate/ledger.js +1 -1
  87. package/dist/regenerate/lineage.d.ts +2 -0
  88. package/dist/regenerate/lineage.js +8 -0
  89. package/dist/regenerate/loop.d.ts +54 -67
  90. package/dist/regenerate/loop.js +312 -148
  91. package/dist/regenerate/model-names.d.ts +33 -0
  92. package/dist/regenerate/{engine.js → model-names.js} +2 -28
  93. package/dist/regenerate/paths.d.ts +3 -3
  94. package/dist/regenerate/paths.js +4 -4
  95. package/dist/regenerate/records.d.ts +11 -0
  96. package/dist/regenerate/records.js +15 -0
  97. package/dist/regenerate/regenerate.d.ts +0 -2
  98. package/dist/regenerate/regenerate.js +4 -15
  99. package/dist/regenerate/renames.js +4 -4
  100. package/dist/regenerate/requires.d.ts +7 -0
  101. package/dist/regenerate/requires.js +24 -18
  102. package/dist/regenerate/scripts-being-written.d.ts +4 -4
  103. package/dist/regenerate/scripts-being-written.js +3 -3
  104. package/dist/regenerate/spec-map.js +3 -3
  105. package/dist/regenerate/standing.js +1 -1
  106. package/dist/regenerate/submit-work.d.ts +2 -0
  107. package/dist/regenerate/submit-work.js +8 -3
  108. package/dist/regenerate/test-scripts.d.ts +2 -1
  109. package/dist/regenerate/test-scripts.js +33 -23
  110. package/dist/regenerate/testing-steps.d.ts +16 -5
  111. package/dist/regenerate/testing-steps.js +28 -9
  112. package/dist/regenerate-cli.js +18 -9
  113. package/dist/self-invocation.d.ts +11 -0
  114. package/dist/self-invocation.js +36 -10
  115. package/dist/sentinel-check.d.ts +3 -3
  116. package/dist/sentinel-check.js +3 -3
  117. package/dist/sentinel.d.ts +17 -12
  118. package/dist/sentinel.js +75 -46
  119. package/dist/{config-command.d.ts → settings.d.ts} +13 -8
  120. package/dist/{config-command.js → settings.js} +155 -24
  121. package/dist/setup.d.ts +2 -2
  122. package/dist/setup.js +7 -7
  123. package/dist/skill.d.ts +0 -11
  124. package/dist/skill.js +0 -9
  125. package/dist/tools.js +2 -3
  126. package/dist/turri-versions.js +2 -1
  127. package/docs/README.md +4 -6
  128. package/docs/authoring-plain.md +3 -3
  129. package/docs/chats.md +6 -9
  130. package/docs/claude-subscription.md +2 -2
  131. package/docs/config.md +61 -51
  132. package/docs/development.md +4 -5
  133. package/docs/headless.md +7 -6
  134. package/docs/hosting.md +24 -23
  135. package/docs/launch.md +63 -0
  136. package/docs/parser.md +3 -3
  137. package/docs/regenerating.md +30 -22
  138. package/docs/sandbox.md +3 -3
  139. package/docs/sentinel.md +27 -16
  140. package/docs/skills-and-gates.md +6 -11
  141. package/docs/using.md +25 -42
  142. package/genome/rules/project-model.md +2 -1
  143. package/genome/rules/test-plain-files.md +15 -7
  144. package/genome/rules/turri-regeneration.md +7 -10
  145. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  146. package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
  147. package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
  148. package/package.json +1 -1
  149. package/dist/advisor-chat.d.ts +0 -63
  150. package/dist/advisor-chat.js +0 -290
  151. package/dist/change-plain-cli.js +0 -55
  152. package/dist/ledger-cli.d.ts +0 -1
  153. package/dist/ledger-cli.js +0 -50
  154. package/dist/ledger-tools.d.ts +0 -10
  155. package/dist/ledger-tools.js +0 -64
  156. package/dist/regenerate/advisor-records.d.ts +0 -93
  157. package/dist/regenerate/advisor-records.js +0 -110
  158. package/dist/regenerate/advisor-runs.d.ts +0 -87
  159. package/dist/regenerate/advisor-runs.js +0 -327
  160. package/dist/regenerate/engine.d.ts +0 -52
  161. package/dist/regenerate/release.d.ts +0 -121
  162. package/dist/regenerate/test-advisor.d.ts +0 -101
  163. package/dist/regenerate/test-advisor.js +0 -379
  164. package/dist/release-agent.d.ts +0 -43
  165. package/dist/release-agent.js +0 -130
  166. package/dist/release-cli.d.ts +0 -1
  167. package/dist/release-tools.d.ts +0 -44
  168. package/dist/release-tools.js +0 -170
  169. package/dist/spec-tools.d.ts +0 -36
  170. package/dist/spec-tools.js +0 -128
  171. package/dist/stacks.d.ts +0 -13
  172. package/dist/stacks.js +0 -96
  173. package/docs/deploy.md +0 -48
  174. package/docs/test-advisor.md +0 -110
  175. /package/dist/{change-plain-cli.d.ts → launch-cli.d.ts} +0 -0
@@ -1,379 +0,0 @@
1
- import { defineTool } from "@earendil-works/pi-coding-agent";
2
- import { Type } from "typebox";
3
- import { ask, BEGIN, createExecutor } from "../pi.js";
4
- /** How many times a call that did not answer, or answered what does not hold, is asked again. */
5
- const RETRIES = 2;
6
- /** The fewest and most probes a functional spec is given. */
7
- export const MIN_PROBES = 1;
8
- export const MAX_PROBES = 10;
9
- /** What a reader answers for an input the functional spec does not settle: a scenario on it would pin a guess. */
10
- export const UNSPECIFIED = "unspecified";
11
- /** The readers: the same task, decorrelated by their system prompts alone. */
12
- export const READERS = [
13
- {
14
- name: "literal reader",
15
- system: "You read a functional spec literally: you predict exactly what its words say, and nothing they do not. Where the words are silent, you take the narrowest reading they allow.",
16
- },
17
- {
18
- name: "edge-case hunter",
19
- system: "You read a functional spec as a tester hunting for edge cases: empty and huge values, limits, duplicates, order, rounding, time zones, missing data. You predict what a careful implementation would do at each edge.",
20
- },
21
- {
22
- name: "another domain's reader",
23
- system: "You read a functional spec as someone from another domain would - a different field, a different country, a different habit of mind - bringing the conventions that domain takes for granted. You predict what you would expect the output to be.",
24
- },
25
- ];
26
- /** Ask one call, and ask again with what was wrong, until it holds or the retries are spent. */
27
- async function askAdvisor(options) {
28
- let answer;
29
- const tool = options.tool((given) => (answer = given));
30
- const session = await createExecutor({
31
- cwd: options.cwd,
32
- customTools: [tool],
33
- tools: [tool.name],
34
- model: options.model,
35
- label: options.label,
36
- role: "advisor",
37
- task: options.task,
38
- ...(options.system !== undefined ? { system: options.system } : {}),
39
- budget: { calls: 4, finish: [tool.name] },
40
- });
41
- try {
42
- await ask(session, BEGIN);
43
- for (let again = 0; again < RETRIES; again += 1) {
44
- if (answer !== undefined && options.check(answer).length === 0)
45
- return answer;
46
- const problems = answer === undefined ? [`You did not call ${tool.name}.`] : options.check(answer);
47
- answer = undefined;
48
- await ask(session, `That does not hold:\n- ${problems.join("\n- ")}\n\nCall ${tool.name} again, with it fixed.`);
49
- }
50
- return answer !== undefined && options.check(answer).length === 0 ? answer : undefined;
51
- }
52
- finally {
53
- session.dispose();
54
- }
55
- }
56
- /** Text compared as the readers' outputs are: whitespace collapsed, case left aside. */
57
- export function normalised(text) {
58
- return text.trim().replace(/\s+/g, " ").toLowerCase();
59
- }
60
- /** What every call is given: the functional spec, its module, and the project's own words on what matters. */
61
- function subjectBlock(subject) {
62
- return [
63
- `<functional_spec module="${subject.module}" func_id="${subject.funcId}">`,
64
- subject.text.trim(),
65
- "</functional_spec>",
66
- "",
67
- `<module name="${subject.module}">`,
68
- subject.moduleText.trim(),
69
- "</module>",
70
- ...(subject.testedIn !== undefined
71
- ? [
72
- "",
73
- `Its scenarios are tested against the code of ${subject.testedIn.module}, which is built on ${subject.module}: what a command`,
74
- `or a listing shows there includes ${subject.testedIn.module}'s own functional specs.`,
75
- `<module name="${subject.testedIn.module}">`,
76
- subject.testedIn.text.trim(),
77
- "</module>",
78
- ]
79
- : []),
80
- ...(subject.context.length > 0 ? ["", "<the project's own words on what matters>", ...subject.context.map((text) => text.trim()), "</the project's own words on what matters>"] : []),
81
- ];
82
- }
83
- const stringOf = (value) => (typeof value === "string" ? value.trim() : "");
84
- /**
85
- * The classification, from the call's answer: each yes kept only with its evidence - a yes without it, or with it
86
- * malformed (two readings that are the same), is a no. The verdict is yes on silent failure, divergence or cost.
87
- */
88
- export function classificationOf(answer) {
89
- const questions = [];
90
- const add = (question, yes, evidence) => {
91
- if (yes && evidence !== "")
92
- questions.push({ question, evidence });
93
- };
94
- add("silent-failure", answer.silent_failure?.answer === true, stringOf(answer.silent_failure?.wrong_output));
95
- const input = stringOf(answer.divergence?.input);
96
- const a = stringOf(answer.divergence?.reading_a);
97
- const b = stringOf(answer.divergence?.reading_b);
98
- const diverges = answer.divergence?.answer === true && input !== "" && a !== "" && b !== "" && normalised(a) !== normalised(b);
99
- add("divergence", diverges, diverges ? `${input} - one reading: ${a}; the other: ${b}` : "");
100
- add("revisited", answer.revisited?.answer === true, stringOf(answer.revisited?.would_change));
101
- add("cost", answer.cost?.answer === true, stringOf(answer.cost?.consequence));
102
- const decisive = questions.some((answered) => answered.question !== "revisited");
103
- return { verdict: decisive ? "yes" : "no", questions, ...(diverges ? { divergence: { input, readings: [a, b] } } : {}) };
104
- }
105
- function classifyPrompt(subject) {
106
- return [
107
- "You decide whether one functional spec of a ***plain module needs explicit testing scenarios: black-box tests written",
108
- "from scenarios, beside the unit tests its coding agent writes anyway. Not everything should be tested this way - only",
109
- "functionality where a wrong implementation would go unnoticed, where readers would disagree, or where a bug is costly.",
110
- "",
111
- ...subjectBlock(subject),
112
- ...(subject.reason !== undefined && subject.reason.trim() !== ""
113
- ? ["", "<why it was asked for>", subject.reason.trim(), "</why it was asked for>", "This is context, not evidence: answer the questions from the functional spec, its module and the project."]
114
- : []),
115
- "",
116
- "Answer four questions about the functional spec. Each yes needs concrete evidence; without it, answer no.",
117
- "1. silent_failure: could an incorrect implementation give output that looks plausible but is wrong? Evidence: one such",
118
- " wrong output, concretely - the input and the wrong output it would give.",
119
- "2. divergence: is there an input for which two reasonable readings of the text give different outputs? Evidence: the",
120
- " input, and the output under each reading.",
121
- "3. revisited: is this functionality likely to be changed or built on later? Evidence: what would change.",
122
- "4. cost: would a bug in it cause financial loss, security exposure, data loss, or harm to users' trust? Evidence: the",
123
- " consequence.",
124
- "",
125
- "Judge only this functional spec, from what the module and the project say. Do not answer yes to be safe: a yes",
126
- "starts work, and a functional spec with nothing at stake is better left to its unit tests.",
127
- "Call submit_classification once.",
128
- ].join("\n");
129
- }
130
- /** Classify a functional spec: one call, four evidence-backed questions. Throws when the call gives no answer. */
131
- export async function classify(subject, options) {
132
- const answer = await askAdvisor({
133
- cwd: options.cwd,
134
- model: options.model,
135
- label: `${subject.module}:${subject.funcId} test advisor classifying`,
136
- task: classifyPrompt(subject),
137
- check: () => [],
138
- tool: (take) => defineTool({
139
- name: "submit_classification",
140
- label: "Submit the classification",
141
- description: "The four answers, each yes with its evidence.",
142
- parameters: Type.Object({
143
- silent_failure: Type.Object({ answer: Type.Boolean(), wrong_output: Type.Optional(Type.String({ description: "An input, and the plausible but wrong output an incorrect implementation would give." })) }),
144
- divergence: Type.Object({
145
- answer: Type.Boolean(),
146
- input: Type.Optional(Type.String({ description: "The input two reasonable readings disagree on." })),
147
- reading_a: Type.Optional(Type.String({ description: "The output under one reading." })),
148
- reading_b: Type.Optional(Type.String({ description: "The output under the other." })),
149
- }),
150
- revisited: Type.Object({ answer: Type.Boolean(), would_change: Type.Optional(Type.String({ description: "What would change, or be built on it." })) }),
151
- cost: Type.Object({ answer: Type.Boolean(), consequence: Type.Optional(Type.String({ description: "What a bug would cost, and whom." })) }),
152
- }),
153
- async execute(_id, params) {
154
- take(params);
155
- return { content: [{ type: "text", text: "Recorded." }], details: {}, terminate: true };
156
- },
157
- }),
158
- });
159
- if (answer === undefined)
160
- throw new Error("the classification call gave no answer");
161
- return classificationOf(answer);
162
- }
163
- function probesPrompt(subject, classification) {
164
- return [
165
- "This functional spec needs explicit testing scenarios. Pick the inputs they should cover.",
166
- "",
167
- ...subjectBlock(subject),
168
- "",
169
- "<why it needs them>",
170
- ...classification.questions.map((answered) => `- ${answered.question}: ${answered.evidence}`),
171
- "</why it needs them>",
172
- "",
173
- `Write the probes - as many as the functional spec has real boundaries, ${MIN_PROBES} to ${MAX_PROBES}, one when it has a single input:`,
174
- "concrete inputs at the boundaries of what the functional spec says - limits, empty and missing values, duplicates,",
175
- "order, the cases its wording leaves open - each one an input a black-box test can give through the interface the",
176
- "functional spec names. Concrete values, never descriptions (\"a long name\").",
177
- "Only inputs whose output the functional spec bears on: never a command, flag, alias or option it does not name, and",
178
- "never one that exercises another functional spec of the module instead - a test of what it does not say would pin a guess.",
179
- "Never pad to reach a number: an input that tests nothing new is noise in the scenarios. Do not say what the output",
180
- "should be. Call submit_probes once.",
181
- ].join("\n");
182
- }
183
- /** The probes: 1-10 boundary inputs, and the divergence's input when the classification found one. */
184
- async function probes(subject, classification, options) {
185
- const answer = await askAdvisor({
186
- cwd: options.cwd,
187
- model: options.model,
188
- label: `${subject.module}:${subject.funcId} test advisor probes`,
189
- task: probesPrompt(subject, classification),
190
- check: (given) => {
191
- const inputs = given.probes.map((probe) => stringOf(probe.input)).filter((input) => input !== "");
192
- return inputs.length < MIN_PROBES || inputs.length > MAX_PROBES ? [`Give ${MIN_PROBES} to ${MAX_PROBES} probes, each a concrete input; you gave ${inputs.length}.`] : [];
193
- },
194
- tool: (take) => defineTool({
195
- name: "submit_probes",
196
- label: "Submit the probes",
197
- description: `${MIN_PROBES} to ${MAX_PROBES} concrete boundary inputs.`,
198
- parameters: Type.Object({ probes: Type.Array(Type.Object({ input: Type.String() })) }),
199
- async execute(_id, params) {
200
- take(params);
201
- return { content: [{ type: "text", text: "Recorded." }], details: {}, terminate: true };
202
- },
203
- }),
204
- });
205
- if (answer === undefined)
206
- throw new Error("the probes call gave no probes");
207
- const inputs = [];
208
- const add = (input) => {
209
- if (input !== "" && !inputs.some((known) => normalised(known) === normalised(input)))
210
- inputs.push(input);
211
- };
212
- for (const probe of answer.probes)
213
- add(stringOf(probe.input));
214
- if (classification.divergence !== undefined)
215
- add(classification.divergence.input);
216
- return inputs;
217
- }
218
- function readerPrompt(subject, inputs) {
219
- return [
220
- "Predict what an implementation of this functional spec outputs for each input below.",
221
- "",
222
- ...subjectBlock(subject),
223
- "",
224
- "<inputs>",
225
- ...inputs.map((input, index) => `${index + 1}. ${input}`),
226
- "</inputs>",
227
- "",
228
- "For every input, by its number, give the output you expect - concrete, as a test would check it, in a line. Where",
229
- "the functional spec leaves it open, give the output your reading of it leads to. Where it says nothing that bears on",
230
- `the input at all - a command or an option it does not name - answer exactly ${UNSPECIFIED}. Call submit_predictions once.`,
231
- ].join("\n");
232
- }
233
- /** One reader's predictions, by probe - or nothing when it gave none that hold. */
234
- async function predictions(subject, inputs, reader, options) {
235
- const answer = await askAdvisor({
236
- cwd: options.cwd,
237
- model: options.model,
238
- label: `${subject.module}:${subject.funcId} test advisor ${reader.name}`,
239
- task: readerPrompt(subject, inputs),
240
- system: reader.system,
241
- check: (given) => {
242
- const missing = inputs.flatMap((_input, index) => (given.predictions.filter((prediction) => prediction.input === index + 1 && stringOf(prediction.output) !== "").length === 1 ? [] : [index + 1]));
243
- return missing.length > 0 ? [`Give exactly one output for every input; not for: ${missing.join(", ")}.`] : [];
244
- },
245
- tool: (take) => defineTool({
246
- name: "submit_predictions",
247
- label: "Submit the predictions",
248
- description: "The output expected for every input, by its number.",
249
- parameters: Type.Object({ predictions: Type.Array(Type.Object({ input: Type.Number(), output: Type.String() })) }),
250
- async execute(_id, params) {
251
- take(params);
252
- return { content: [{ type: "text", text: "Recorded." }], details: {}, terminate: true };
253
- },
254
- }),
255
- });
256
- if (answer === undefined)
257
- return undefined;
258
- return inputs.map((_input, index) => stringOf(answer.predictions.find((prediction) => prediction.input === index + 1)?.output));
259
- }
260
- /**
261
- * The inputs the readers split on - every probe where any two predictions differ once normalised: the union, never a
262
- * majority - each with its distinct readings, in the order the readers gave them.
263
- */
264
- export function splitInputs(readings) {
265
- const split = new Map();
266
- const count = readings[0]?.length ?? 0;
267
- for (let index = 0; index < count; index += 1) {
268
- const distinct = [];
269
- for (const reader of readings) {
270
- const output = reader[index] ?? "";
271
- if (!distinct.some((known) => normalised(known) === normalised(output)))
272
- distinct.push(output);
273
- }
274
- if (distinct.length > 1)
275
- split.set(index, distinct);
276
- }
277
- return split;
278
- }
279
- function verifyPrompt(subject, candidates) {
280
- return [
281
- "Readers of this functional spec disagreed on the outputs of some inputs. For each, say which readings a reasonable",
282
- "person could hold, given the functional spec, its module and the project.",
283
- "",
284
- ...subjectBlock(subject),
285
- "",
286
- "<disagreements>",
287
- ...candidates.flatMap((candidate, index) => [`${index + 1}. input: ${candidate.input}`, ...candidate.readings.map((reading, at) => ` reading ${at + 1}: ${reading}`)]),
288
- "</disagreements>",
289
- "",
290
- "For every disagreement, by its number, list the numbers of the readings a reasonable person could hold. Leave out a",
291
- `reading only a misreading or a mistake leads to. A reading of ${UNSPECIFIED} holds when the functional spec says nothing`,
292
- "that settles the input. Call submit_verification once.",
293
- ].join("\n");
294
- }
295
- /** Of each candidate, the readings a reasonable person could hold - or nothing when the call gave no answer that holds. */
296
- async function verify(subject, candidates, options) {
297
- const answer = await askAdvisor({
298
- cwd: options.cwd,
299
- model: options.model,
300
- label: `${subject.module}:${subject.funcId} test advisor verifier`,
301
- task: verifyPrompt(subject, candidates),
302
- check: (given) => {
303
- const problems = [];
304
- candidates.forEach((candidate, index) => {
305
- const said = given.inputs.filter((item) => item.input === index + 1);
306
- if (said.length !== 1)
307
- problems.push(`Say once which readings of disagreement ${index + 1} hold.`);
308
- else if (said[0].reasonable.some((number) => !Number.isInteger(number) || number < 1 || number > candidate.readings.length))
309
- problems.push(`Disagreement ${index + 1} has readings 1 to ${candidate.readings.length} only.`);
310
- });
311
- return problems;
312
- },
313
- tool: (take) => defineTool({
314
- name: "submit_verification",
315
- label: "Submit the verification",
316
- description: "For every disagreement, by its number, the numbers of the readings a reasonable person could hold.",
317
- parameters: Type.Object({ inputs: Type.Array(Type.Object({ input: Type.Number(), reasonable: Type.Array(Type.Number()) })) }),
318
- async execute(_id, params) {
319
- take(params);
320
- return { content: [{ type: "text", text: "Recorded." }], details: {}, terminate: true };
321
- },
322
- }),
323
- });
324
- if (answer === undefined)
325
- return undefined;
326
- return candidates.map((candidate, index) => {
327
- const reasonable = answer.inputs.find((item) => item.input === index + 1)?.reasonable ?? [];
328
- return candidate.readings.filter((_reading, at) => reasonable.includes(at + 1));
329
- });
330
- }
331
- /**
332
- * Pick the inputs a functional spec's scenarios should cover: the probes, the readers' predictions of them, the
333
- * disagreements in code, and the verifier's word on each. An input the readers agree on comes with their output; one
334
- * they split on, with every reading the verifier kept - a single reading left is an agreed one, and none left drops it.
335
- */
336
- export async function pickInputs(subject, classification, options) {
337
- const inputs = await probes(subject, classification, options);
338
- // Two readers first; the third only when they agree on every probe - a disagreement already found is enough.
339
- const first = await Promise.all(READERS.slice(0, 2).map((reader) => predictions(subject, inputs, reader, options)));
340
- const readings = first.filter((reading) => reading !== undefined);
341
- if (readings.length === 0 || splitInputs(readings).size === 0) {
342
- for (const reader of READERS.slice(2)) {
343
- const more = await predictions(subject, inputs, reader, options);
344
- if (more !== undefined)
345
- readings.push(more);
346
- }
347
- }
348
- if (readings.length === 0)
349
- throw new Error("no reader predicted the probes' outputs");
350
- const split = splitInputs(readings);
351
- const candidates = [...split].map(([index, distinct]) => ({ index, input: inputs[index], readings: distinct }));
352
- // Without the verifier's word, every reading stands: a split left unsettled is the chat's to settle as it writes.
353
- const kept = candidates.length > 0 ? ((await verify(subject, candidates, options)) ?? candidates.map((candidate) => candidate.readings)) : [];
354
- const out = [];
355
- inputs.forEach((input, index) => {
356
- const at = candidates.findIndex((candidate) => candidate.index === index);
357
- // An input the functional spec does not settle is left out: a scenario on it would pin a guess.
358
- if (at === -1) {
359
- if (normalised(readings[0][index]) !== UNSPECIFIED)
360
- out.push({ input, agreed: readings[0][index] });
361
- return;
362
- }
363
- const held = kept[at] ?? [];
364
- if (held.some((reading) => normalised(reading) === UNSPECIFIED))
365
- return;
366
- if (held.length > 1)
367
- out.push({ input, readings: held });
368
- else if (held.length === 1)
369
- out.push({ input, agreed: held[0] });
370
- });
371
- return out;
372
- }
373
- /** The whole judgement: classify, and on a yes pick the inputs. Throws when a call that cannot be done without fails. */
374
- export async function advise(subject, options) {
375
- const classification = await classify(subject, options);
376
- if (classification.verdict === "no")
377
- return { verdict: "no", questions: classification.questions, inputs: [] };
378
- return { verdict: "yes", questions: classification.questions, inputs: await pickInputs(subject, classification, options) };
379
- }
@@ -1,43 +0,0 @@
1
- import { type ToolDefinition } from "@earendil-works/pi-coding-agent";
2
- import { type DeployState } from "./release-tools.ts";
3
- /**
4
- * The agent that releases a module on its own - `turri release`'s, and a pulse's last stage under
5
- * `release-after-pulse: true`, which is the word to release: the guidance it finds as the chat does - what it was told,
6
- * the project's AGENTS.md, its skills - says only how. It passes it to `release`, and does what it says, asking no one.
7
- */
8
- type AnyTool = ToolDefinition<any, any, any>;
9
- /**
10
- * The person's own shell, in the deployed folder: it installs what the release needs into the project, and runs it. It
11
- * changes nothing of the machine's - no toolchain installed, no system setting changed: a command that would is refused.
12
- */
13
- export declare function releaseShell(dir: string): AnyTool;
14
- /**
15
- * What the project says of itself, for the agent to find release guidance in: its AGENTS.md and its skills
16
- * (`.agents/skills`, `.pi/skills`, `.claude/skills`), where turri runs and in the host codebase - once each, whole.
17
- */
18
- export declare function projectNotes(dirs: string[]): string[];
19
- export interface ReleaseAgentInput {
20
- plainFile: string;
21
- /** Where turri runs. */
22
- cwd: string;
23
- /** The agent's model: the harness model. */
24
- model?: string;
25
- /** What release has shipped and been told this conversation - shared with the chat's release. */
26
- state: DeployState;
27
- inModule?: string;
28
- /** What the person said of how to release it. */
29
- guidance?: string;
30
- /** Released as a pulse's last stage: what the pulse landed. The setting has said to release it; the guidance says how. */
31
- afterPulse?: {
32
- moduleName: string;
33
- subject: string;
34
- };
35
- /** Released for the sentinel to check functional specs of the module in: asked for, so released; the guidance says how. */
36
- forCheck?: {
37
- moduleName: string;
38
- };
39
- onDelta?: (delta: string) => void;
40
- }
41
- /** Run the release agent to its end; its last reply. */
42
- export declare function runReleaseAgent(input: ReleaseAgentInput): Promise<string>;
43
- export {};
@@ -1,130 +0,0 @@
1
- import { existsSync, readdirSync, readFileSync } from "node:fs";
2
- import { join, relative, resolve, sep } from "node:path";
3
- import { createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, } from "@earendil-works/pi-coding-agent";
4
- import { createDeployTools, DEPLOY_TOOLS } from "./release-tools.js";
5
- import { hostDirOf, shortPath } from "./regenerate/release.js";
6
- import { machineChange, machineChangeReason } from "./regenerate/command-check.js";
7
- import { projectDirOf } from "./regenerate/paths.js";
8
- import { ask, BEGIN, createExecutor } from "./pi.js";
9
- /**
10
- * The person's own shell, in the deployed folder: it installs what the release needs into the project, and runs it. It
11
- * changes nothing of the machine's - no toolchain installed, no system setting changed: a command that would is refused.
12
- */
13
- export function releaseShell(dir) {
14
- const bash = createBashToolDefinition(dir);
15
- return {
16
- ...bash,
17
- description: `${bash.description}\n\nIt runs on the person's own machine, in ${shortPath(dir)}. Never start a server here: activate does. It installs nothing on the machine and changes none of its settings: what the machine lacks, the person installs.`,
18
- async execute(toolCallId, params, signal, onUpdate, ctx) {
19
- const changes = machineChange(String(params.command ?? ""));
20
- if (changes !== undefined)
21
- throw new Error(machineChangeReason(changes));
22
- return bash.execute(toolCallId, params, signal, onUpdate, ctx);
23
- },
24
- };
25
- }
26
- /** A file tool that writes, refused inside plain_modules: the built code is the spec's to change, never a release's. */
27
- function outsideBuiltCode(tool, dir) {
28
- return {
29
- ...tool,
30
- async execute(toolCallId, params, signal, onUpdate, ctx) {
31
- const path = resolve(dir, String(params.path ?? ""));
32
- if (relative(dir, path).split(sep).includes("plain_modules")) {
33
- throw new Error(`Not written: ${shortPath(path)} is built code. A release never changes it - a fix belongs in the spec.`);
34
- }
35
- // The ***plain - a module, a test plain file - is the person's: a release that finds it wrong says so, never rewrites it.
36
- if (path.endsWith(".plain")) {
37
- throw new Error(`Not written: ${shortPath(path)} is ***plain. A release never changes it - say what is wrong with it instead.`);
38
- }
39
- return tool.execute(toolCallId, params, signal, onUpdate, ctx);
40
- },
41
- };
42
- }
43
- function shown(file, max = 40_000) {
44
- const text = readFileSync(file, "utf8");
45
- const body = text.length > max ? `${text.slice(0, max)}\n… [the rest of ${shortPath(file)} is not shown]` : text;
46
- return `<file path="${shortPath(file)}">\n${body.trimEnd()}\n</file>`;
47
- }
48
- /**
49
- * What the project says of itself, for the agent to find release guidance in: its AGENTS.md and its skills
50
- * (`.agents/skills`, `.pi/skills`, `.claude/skills`), where turri runs and in the host codebase - once each, whole.
51
- */
52
- export function projectNotes(dirs) {
53
- const roots = [...new Set(dirs.map((dir) => resolve(dir)))];
54
- const files = new Set();
55
- for (const root of roots) {
56
- const agents = join(root, "AGENTS.md");
57
- if (existsSync(agents))
58
- files.add(agents);
59
- for (const skills of [".agents/skills", ".pi/skills", ".claude/skills"].map((folder) => join(root, folder))) {
60
- if (!existsSync(skills))
61
- continue;
62
- for (const name of readdirSync(skills)) {
63
- const skill = join(skills, name, "SKILL.md");
64
- if (existsSync(skill))
65
- files.add(skill);
66
- }
67
- }
68
- }
69
- return [...files].map((file) => shown(file));
70
- }
71
- /** Run the release agent to its end; its last reply. */
72
- export async function runReleaseAgent(input) {
73
- const { plainFile } = input;
74
- const tools = createDeployTools({ cwd: input.cwd, state: input.state, defaultPlainFile: () => plainFile });
75
- // It releases from the host codebase, which holds dist too.
76
- const dir = hostDirOf(plainFile, input.cwd);
77
- const notes = projectNotes([input.cwd, dir, projectDirOf(plainFile)]);
78
- const said = input.guidance ?? input.state.guidance.get(input.afterPulse?.moduleName ?? "");
79
- const fileTools = [
80
- createReadToolDefinition(dir),
81
- createLsToolDefinition(dir),
82
- createGrepToolDefinition(dir),
83
- createFindToolDefinition(dir),
84
- // A guided release may say to change the host - a registration, an import.
85
- outsideBuiltCode(createEditToolDefinition(dir), dir),
86
- outsideBuiltCode(createWriteToolDefinition(dir), dir),
87
- ];
88
- const executor = await createExecutor({
89
- // Its sessions are kept in the project, not in the folder it deploys.
90
- cwd: projectDirOf(plainFile),
91
- customTools: [...fileTools, releaseShell(dir), ...tools],
92
- tools: [...fileTools.map((tool) => tool.name), "bash", ...DEPLOY_TOOLS],
93
- ...(input.model !== undefined ? { model: input.model } : {}),
94
- role: "release",
95
- system: [
96
- "You get software that was just built running on the person's own machine, so they can try it. You ask no one: do it.",
97
- `Your file tools and your shell start in ${dir}. Your shell is the person's own - not a sandbox.`,
98
- ].join("\n"),
99
- task: [
100
- input.afterPulse !== undefined
101
- ? `A pulse of module ${input.afterPulse.moduleName} just landed: ${input.afterPulse.subject}. Release it now, before the module's next pulse starts: the project releases after every pulse.`
102
- : input.forCheck !== undefined
103
- ? `The person asked turri's sentinel to check functional specs of module ${input.forCheck.moduleName} in its release, and what runs of it is not its last commit. Release its last commit now, for the sentinel to test.`
104
- : `Release ${shortPath(plainFile)} for the person to try, with the release tool, then do what it says.`,
105
- "",
106
- "First ask yourself: is there guidance for how this project releases it - what the person said below, the project's",
107
- "notes and skills below, or anything else you find? If there is, call release with it as guidance, in full: the code is",
108
- "put in dist/<module>, and the guidance takes it on from there. If there is none, call release without guidance: the",
109
- "code is put in dist/<module> and started from there, as best it can be.",
110
- ...(input.afterPulse !== undefined || input.forCheck !== undefined
111
- ? [
112
- "",
113
- `Release it whether or not the guidance speaks of releasing ${input.afterPulse !== undefined ? "after a build - the project's setting has said to" : "for a check - the person asked for it"}. What`,
114
- "the guidance says is how. When release says it is already released, leave it at that.",
115
- ]
116
- : []),
117
- ...(input.inModule !== undefined ? ["", `Release the codebase of module ${input.inModule}: pass in_module.`] : []),
118
- ...(said !== undefined ? ["", "What the person said of how to release it:", said] : []),
119
- ...(notes.length > 0 ? ["", "The project's notes and skills:", ...notes] : []),
120
- "",
121
- "End with what you did, in a line or two: where it runs, or why nothing was released.",
122
- ].join("\n"),
123
- });
124
- try {
125
- return await ask(executor, BEGIN, input.onDelta);
126
- }
127
- finally {
128
- executor.dispose();
129
- }
130
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,44 +0,0 @@
1
- import { type Deployment } from "./regenerate/release.ts";
2
- import type { JobRegistry } from "./regenerate/jobs.ts";
3
- import type { WorkLoop } from "./regenerate/loop.ts";
4
- /**
5
- * The tools that put a module out for the person to try, and start it: the conversation's, and the
6
- * one-off agent's of `turri release`. The harness does the parts that must hold - exporting the
7
- * last commit, owning what it starts - and the agent the rest: reading the code to see how it runs,
8
- * installing what it needs, starting it, and telling the person where to find it. Nothing is put to
9
- * the person: a release does everything itself.
10
- */
11
- export interface DeployState {
12
- /** The last deploy: where what is started runs from. */
13
- current?: Deployment;
14
- /** The last release of each module in this conversation, by module: the commit it shipped. */
15
- released: Map<string, Deployment>;
16
- /** The guidance each module was last released with, by module: what a release after a pulse is told the person said. */
17
- guidance: Map<string, string>;
18
- }
19
- export declare function createDeployState(): DeployState;
20
- /**
21
- * A module's release as it stands, when it is current: its own codebase's last commit is what the last release shipped,
22
- * and nothing that release started has ended. Undefined when it is behind, was never made, or what it started died -
23
- * then it is released again.
24
- */
25
- export declare function currentRelease(state: DeployState, plainFile: string, moduleName: string): Deployment | undefined;
26
- /** What the agent is to do once the code is in dist - in the deploy tool's answer, and the CLI agent's prompt. */
27
- export declare function deployGuide(dir: string): string;
28
- /**
29
- * What the agent is to do on a guided release: the code is in dist, as on any release, and the guidance takes it on from
30
- * there. The rules of a release to dist hold here too: what keeps running started with activate, and the built code never
31
- * edited - and nothing put to the person.
32
- */
33
- export declare function guidedGuide(deployment: Deployment, guidance: string): string;
34
- export declare function createDeployTools(options: {
35
- cwd: string;
36
- state: DeployState;
37
- /** The spec deploy takes when it is given none: the project's module. */
38
- defaultPlainFile: () => string | undefined;
39
- /** The pulses halt stops as well - the conversation's. */
40
- jobs?: JobRegistry;
41
- /** The work loop whose modules halt halts by a planned row or a name - the conversation's, once it has one. */
42
- workLoop?: () => WorkLoop | undefined;
43
- }): import("@earendil-works/pi-coding-agent").ToolDefinition<any, any, any>[];
44
- export declare const DEPLOY_TOOLS: string[];