@turri-dev/cli 0.2.3-next.fea0bd9 → 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 (176) hide show
  1. package/README.md +57 -62
  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 +42 -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 +31 -12
  22. package/dist/extension.js +555 -556
  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 +2 -2
  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 +57 -65
  90. package/dist/regenerate/loop.js +354 -171
  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 +37 -11
  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 +8 -8
  131. package/docs/config.md +62 -52
  132. package/docs/development.md +4 -5
  133. package/docs/headless.md +7 -6
  134. package/docs/hosting.md +25 -24
  135. package/docs/installation.md +4 -0
  136. package/docs/launch.md +63 -0
  137. package/docs/parser.md +3 -3
  138. package/docs/regenerating.md +30 -22
  139. package/docs/sandbox.md +3 -3
  140. package/docs/sentinel.md +27 -16
  141. package/docs/skills-and-gates.md +6 -11
  142. package/docs/using.md +26 -42
  143. package/genome/rules/project-model.md +2 -1
  144. package/genome/rules/test-plain-files.md +15 -7
  145. package/genome/rules/turri-regeneration.md +7 -10
  146. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  147. package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
  148. package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
  149. package/package.json +1 -1
  150. package/dist/advisor-chat.d.ts +0 -63
  151. package/dist/advisor-chat.js +0 -290
  152. package/dist/change-plain-cli.js +0 -55
  153. package/dist/ledger-cli.d.ts +0 -1
  154. package/dist/ledger-cli.js +0 -50
  155. package/dist/ledger-tools.d.ts +0 -10
  156. package/dist/ledger-tools.js +0 -64
  157. package/dist/regenerate/advisor-records.d.ts +0 -93
  158. package/dist/regenerate/advisor-records.js +0 -110
  159. package/dist/regenerate/advisor-runs.d.ts +0 -87
  160. package/dist/regenerate/advisor-runs.js +0 -327
  161. package/dist/regenerate/engine.d.ts +0 -52
  162. package/dist/regenerate/release.d.ts +0 -121
  163. package/dist/regenerate/test-advisor.d.ts +0 -101
  164. package/dist/regenerate/test-advisor.js +0 -379
  165. package/dist/release-agent.d.ts +0 -43
  166. package/dist/release-agent.js +0 -130
  167. package/dist/release-cli.d.ts +0 -1
  168. package/dist/release-tools.d.ts +0 -44
  169. package/dist/release-tools.js +0 -170
  170. package/dist/spec-tools.d.ts +0 -36
  171. package/dist/spec-tools.js +0 -128
  172. package/dist/stacks.d.ts +0 -13
  173. package/dist/stacks.js +0 -96
  174. package/docs/deploy.md +0 -48
  175. package/docs/test-advisor.md +0 -110
  176. /package/dist/{change-plain-cli.d.ts → launch-cli.d.ts} +0 -0
@@ -1,290 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { basename, join, relative, resolve } from "node:path";
3
- import { defineTool } from "@earendil-works/pi-coding-agent";
4
- import { Box, Text } from "@earendil-works/pi-tui";
5
- import { Type } from "typebox";
6
- import { chatBusy } from "./chat-idle.js";
7
- import { conformanceTestsOnIn } from "./conformance-switch.js";
8
- import { readProjectConfig } from "./config.js";
9
- import { modulePlainFile } from "./plain/parser.js";
10
- import { projectDirOf, resolveTemplateDirs } from "./regenerate/paths.js";
11
- import { resolveRequiresChain } from "./regenerate/requires.js";
12
- import { refuseTestPlainFile } from "./test-plain-files.js";
13
- /**
14
- * The test advisor in the chat (docs/test-advisor.md). The advisor decides; the chat is the only writer of the ***plain.
15
- * A finished verdict reaches the chat the person looks at once it is idle - never interrupting it: a yes is a message
16
- * that starts a turn, in which the chat tells the person and writes the scenarios with change_plain, asking nothing; a
17
- * no is one line drawn by turri, starting no turn. What else the chat is told of the advisor - in its system prompt, in a
18
- * change's result - is here too, and its own way to it, evaluate_tests.
19
- */
20
- /** Why, in a few words, by the first question of a yes. */
21
- const WHY = {
22
- "silent-failure": "a wrong implementation could look right",
23
- divergence: "it can be read two ways",
24
- cost: "a bug in it would be costly",
25
- };
26
- const specOf = (verdict) => `${verdict.module}:${verdict.funcId}`;
27
- /** The line a no is drawn as: the functional spec, and the classifier's reading in a few words - a no has no evidence. */
28
- export function noLine(verdict) {
29
- const only = verdict.report.questions.map((answered) => answered.question);
30
- const reading = only.length > 0 && only.every((question) => question === "revisited") ? "its unit tests cover it as it is built on" : "nothing silent to get wrong";
31
- return `${specOf(verdict)} doesn't need testing scenarios - ${reading}.`;
32
- }
33
- /** The line the chat is to tell the person a yes in. */
34
- export function yesLine(verdict) {
35
- const why = verdict.report.questions.map((answered) => WHY[answered.question]).find((reason) => reason !== undefined);
36
- return `${specOf(verdict)} needs testing scenarios${why !== undefined ? ` - ${why}` : ""}. Writing them now.`;
37
- }
38
- /** A yes's report, as the chat's agent is given it: the questions that were a yes with their evidence, and the inputs. */
39
- export function describeReport(verdict) {
40
- return [
41
- "Why it needs testing:",
42
- ...verdict.report.questions.map((answered) => `- ${answered.question}: ${answered.evidence}`),
43
- "Inputs to cover:",
44
- ...(verdict.report.inputs.length === 0
45
- ? ["- none picked: cover its expected use, as the rules on test plain files say"]
46
- : verdict.report.inputs.map((input, index) => "agreed" in input
47
- ? `${index + 1}. input: ${input.input} - agreed output: ${input.agreed}`
48
- : `${index + 1}. input: ${input.input} - split: ${input.readings.map((reading, at) => `(${at + 1}) ${reading}`).join("; ")}`)),
49
- ];
50
- }
51
- /** The turn a batch of yeses starts: each one's report, and what the chat is to do with them - asking the person nothing. */
52
- export function yesTask(verdicts) {
53
- const where = (path, project) => relative(project, path) || path;
54
- return [
55
- `My test advisor judged that ${verdicts.length === 1 ? "this functional spec needs" : "these functional specs need"} explicit testing scenarios. You write them now.`,
56
- "",
57
- ...verdicts.flatMap((verdict) => [
58
- `<functional_spec name="${specOf(verdict)}" plain_file="${where(verdict.plainFile, verdict.project)}" tested_in="${where(verdict.tip, verdict.project)}" test_plain_file="${verdict.testFile}">`,
59
- ...describeReport(verdict),
60
- "</functional_spec>",
61
- "",
62
- ]),
63
- "What to do, in this turn, asking the person nothing:",
64
- `1. Tell the person in a line for each, e.g. "${yesLine(verdicts[0])}"`,
65
- "2. With change_plain, write whatever the step-7 guard would refuse, in this order, only what is missing: the ***test reqs*** of the module",
66
- " it is tested in - the stack's conformance template, stdlib/<kind>/conformance/<stack>, imported, or the module's own - then the",
67
- " conformance testing script for its stack, with implement-conformance-testing-script - cultivate, plainFile the module it is tested in,",
68
- " which returns at once: go straight on - then the scenarios in its test plain file.",
69
- "3. Cover each input of the report that is this functional spec's: an agreed one with the readers' output, never a placeholder such as",
70
- " <name> where a value belongs; a split one settled by the reading most consistent with the functional spec and its module - say which",
71
- " reading you took. Leave out an input that exercises another functional spec, or nothing this one says.",
72
- "4. Ask the person nothing: the change is visible, and turri tests the scenarios once the code is built.",
73
- ].join("\n");
74
- }
75
- /** The line a no is drawn as, in the transcript and in no model's context. */
76
- const ADVISOR_ENTRY = "turri_advisor";
77
- /** How long a verdict waits before the chat is looked at again, while the person types or it cannot be told yet. */
78
- export const ADVISOR_RECHECK_MS = 2000;
79
- /**
80
- * A chat's verdicts: held until the chat is idle - its agent done, and nothing typed in its editor - then delivered
81
- * together: one turn for every yes, one line for each no. A verdict no longer about its functional spec as it is - its
82
- * text changed, or it was given scenarios meanwhile - is let go.
83
- */
84
- export function verdictDelivery(pi, link, context) {
85
- const waiting = [];
86
- let timer;
87
- pi.registerEntryRenderer(ADVISOR_ENTRY, (entry, _options, theme) => {
88
- const data = entry.data;
89
- if (data === undefined)
90
- return undefined;
91
- const box = new Box(1, 0);
92
- box.addChild(new Text(theme.fg("muted", data.text), 0, 0));
93
- return box;
94
- });
95
- const busy = () => chatBusy(link, context);
96
- const later = (ms) => {
97
- if (timer !== undefined)
98
- return;
99
- timer = setTimeout(() => {
100
- timer = undefined;
101
- deliver();
102
- }, ms);
103
- timer.unref?.();
104
- };
105
- const deliver = () => {
106
- if (waiting.length === 0)
107
- return;
108
- if (busy()) {
109
- // Its agent ending says so (agent_settled); the person's typing does not, so it is looked at again.
110
- later(ADVISOR_RECHECK_MS);
111
- return;
112
- }
113
- const now = waiting.splice(0).filter((verdict) => {
114
- try {
115
- return verdict.current();
116
- }
117
- catch {
118
- return false;
119
- }
120
- });
121
- const yes = now.filter((verdict) => verdict.report.verdict === "yes");
122
- try {
123
- for (const verdict of now.filter((verdict) => verdict.report.verdict === "no"))
124
- pi.appendEntry(ADVISOR_ENTRY, { text: noLine(verdict) });
125
- if (yes.length > 0) {
126
- // A follow-up, never a steer: should a turn start in between, this waits for it to end.
127
- void pi.sendMessage({ customType: "turri_advisor_verdict", content: yesTask(yes), display: false, details: { specs: yes.map(specOf) } }, { triggerTurn: true, deliverAs: "followUp" });
128
- }
129
- }
130
- catch {
131
- // Not bound to its session yet: kept, and tried again.
132
- waiting.unshift(...now);
133
- later(ADVISOR_RECHECK_MS);
134
- return;
135
- }
136
- for (const verdict of now)
137
- verdict.delivered();
138
- };
139
- pi.on("agent_settled", () => deliver());
140
- pi.on("session_start", () => later(0));
141
- return {
142
- put(verdict) {
143
- // A newer verdict on the same functional spec replaces the one waiting.
144
- const at = waiting.findIndex((known) => known.project === verdict.project && specOf(known) === specOf(verdict));
145
- if (at !== -1)
146
- waiting.splice(at, 1);
147
- waiting.push(verdict);
148
- // The rest of what arrives at once comes with it.
149
- later(0);
150
- },
151
- };
152
- }
153
- /**
154
- * The test advisor and the chat, in its system prompt while the session has the advisor and the project wants it: the
155
- * two ways an evaluation starts, what to say while it runs, what to do with its verdict, and when to ask for one.
156
- */
157
- export const TEST_ADVISOR_BLOCK = [
158
- "<test advisor>",
159
- "My test advisor decides whether a functional spec needs explicit testing scenarios - whether it could fail silently, be read two ways, or",
160
- "cost a lot when wrong - in the background. You are the only writer of the ***plain: it writes nothing, and you write what its yes calls for.",
161
- "An evaluation starts two ways:",
162
- "- By itself, for each new or changed functional spec that has no scenarios. A change's result names the ones it took up.",
163
- "- When you call evaluate_tests - even for a text it judged already. Call it when the person asks whether a functional spec needs tests,",
164
- " and on your own, as another way of saying what one means: when pulses keep failing on a complicated functional spec, scenarios may pin",
165
- " down what it should do - say why in its reason. A functional spec with scenarios is not evaluated.",
166
- "When a change's result or evaluate_tests says a functional spec is being evaluated, tell the person so in a line, and go on: nothing waits",
167
- "for it. Its verdict comes back to this chat once you are idle:",
168
- "- A yes is a message with its report: tell the person in a line, then write with change_plain what testing it needs - the test reqs, the",
169
- " conformance testing script and its scenarios, in that order and only what is missing - as the message says, asking the person nothing.",
170
- "- A no is a line turri draws itself: there is nothing for you to do.",
171
- "When the person asks you for scenarios (\"write conformance scenarios for core:add-task\"), decide and write them yourself, with change_plain,",
172
- "as a ***plain change they see, as the rules say - whatever test-advisor says.",
173
- "</test advisor>",
174
- ].join("\n");
175
- /** Each work loop's session's test advisor - the chat's and a host's loops have one. */
176
- const advisorsOfLoops = new WeakMap();
177
- /** The test advisor of the session a work loop is in. */
178
- export function bindAdvisor(loop, advisor) {
179
- advisorsOfLoops.set(loop, advisor);
180
- }
181
- /**
182
- * What a change's tool result tells the chat's agent of the test advisor: the functional specs it has taken up, so the
183
- * agent tells the person they are being evaluated - nothing when it has taken up none.
184
- */
185
- export function advisingNote(loop, plainFile) {
186
- const taking = advisorsOfLoops.get(loop)?.()?.taking(projectDirOf(resolve(plainFile))) ?? [];
187
- if (taking.length === 0)
188
- return "";
189
- return [
190
- `My test advisor is evaluating ${taking.join(", ")} in the background, to see whether ${taking.length === 1 ? "it needs" : "they need"} explicit testing scenarios.`,
191
- "Tell the person, in a line, that testing scenarios are being evaluated for them, and go on - there is nothing to wait for: the verdict",
192
- "comes back to this chat.",
193
- ].join("\n");
194
- }
195
- /** The functional specs evaluate_tests is given, each as the advisor is asked for it - or, not found, why. */
196
- function namedSpecs(cwd, names, plainFile) {
197
- const named = plainFile ?? readProjectConfig(cwd).module;
198
- const base = named !== undefined ? resolve(cwd, named) : undefined;
199
- if (base !== undefined)
200
- refuseTestPlainFile(base);
201
- if (base !== undefined && !existsSync(base))
202
- throw new Error(`There is no .plain file at ${base}.`);
203
- const chain = (() => {
204
- try {
205
- return base !== undefined ? resolveRequiresChain(base, [], undefined, { allowNoFunctionalities: true }) : [];
206
- }
207
- catch {
208
- return [];
209
- }
210
- })();
211
- return names.map((given) => {
212
- const name = given.trim();
213
- const at = name.lastIndexOf(":");
214
- if (at === -1 && base === undefined)
215
- return { name, missing: `name it as module:func-id - there is no plain_file, and no module: in the project's config` };
216
- const module = at === -1 ? basename(base, ".plain") : name.slice(0, at);
217
- const funcId = at === -1 ? name : name.slice(at + 1);
218
- const own = chain.find((link) => link.moduleName === module)?.plainFile ?? modulePlainFile(module, resolveTemplateDirs(base ?? join(cwd, `${module}.plain`)));
219
- if (own === null || own === undefined || !existsSync(own))
220
- return { name: `${module}:${funcId}`, missing: `there is no module ${module} here` };
221
- // A module below the one named: its scenarios are tested in the one named, at the top of the chain.
222
- const tip = base !== undefined && chain.some((link) => link.moduleName === module) && resolve(own) !== resolve(base) ? { tip: base } : {};
223
- return { name: `${module}:${funcId}`, asked: { module, funcId, plainFile: resolve(own), ...tip } };
224
- });
225
- }
226
- /**
227
- * The test advisor asked to evaluate functional specs - `module:func-id`s, or func-ids of `plainFile`'s module (else the
228
- * one the project's config names) - even a text it judged already, and whatever `test-advisor` says: `evaluate_tests`'s
229
- * and a host's `evaluateTests`. It returns at once.
230
- */
231
- export function evaluateTests(cwd, advisor, funcIds, options = {}) {
232
- if (advisor === undefined)
233
- throw new Error("This session has no test advisor: it runs in the chat and a host only.");
234
- if (!conformanceTestsOnIn(cwd)) {
235
- throw new Error("Conformance tests are off for this project (conformance-tests: false, or unset), and the test advisor with them. They are turned on in the chat - by asking for them - or with conformance-tests: true in config.turri.yaml.");
236
- }
237
- if (funcIds.length === 0)
238
- throw new Error("Name the functional specs to evaluate, each as module:func-id.");
239
- const said = { started: [], already: [], scenarios: [], missing: [] };
240
- for (const spec of namedSpecs(cwd, funcIds, options.plainFile)) {
241
- if (spec.asked === undefined) {
242
- said.missing.push(`${spec.name}: ${spec.missing}`);
243
- continue;
244
- }
245
- const outcome = advisor.evaluate({ ...spec.asked, ...(options.reason !== undefined ? { reason: options.reason } : {}) });
246
- if (outcome === "missing")
247
- said.missing.push(`${spec.name}: its module has no such functional spec`);
248
- else
249
- said[outcome].push(spec.name);
250
- }
251
- return said;
252
- }
253
- /**
254
- * evaluate_tests: the chat's own way to the test advisor - a functional spec evaluated in the background, whatever
255
- * `test-advisor` says, and even when its text was judged already. It returns at once; the verdict comes back to the chat
256
- * as the advisor's verdicts do. In the chat and a host only: the session has an advisor.
257
- */
258
- export function evaluateTestsTool(options) {
259
- return defineTool({
260
- name: "evaluate_tests",
261
- label: "Evaluate tests",
262
- description: "Have turri's test advisor evaluate, in the background, whether functional specs need explicit testing scenarios - even one it judged " +
263
- "already, and whatever test-advisor says. It returns at once; the verdict comes back to this chat: a yes as a message to write the " +
264
- "scenarios on, a no as a line. A functional spec that has scenarios is not evaluated.",
265
- promptSnippet: "evaluate_tests: have the test advisor judge whether functional specs need testing scenarios, in the background",
266
- promptGuidelines: [
267
- "Call evaluate_tests when the person asks whether a functional spec needs tests (\"does add-task need tests?\"), rather than judging it yourself.",
268
- "Call it on your own too, as another way of saying what a functional spec means: when pulses keep failing on a complicated functional spec, scenarios may pin down what it should do - say so in reason.",
269
- "It returns at once: tell the person testing scenarios are being evaluated, and go on. On a yes, write the scenarios as the verdict's message says.",
270
- ],
271
- parameters: Type.Object({
272
- funcIds: Type.Array(Type.String(), { description: "The functional specs, each as module:func-id (core:add-task) - or a func-id alone, of plain_file's module" }),
273
- plain_file: Type.Optional(Type.String({ description: "The .plain file a func-id alone is of, and whose chain the scenarios are tested in. Omitted: the module the project's config.turri.yaml names" })),
274
- reason: Type.Optional(Type.String({ description: "Why you ask, for the advisor to weigh: \"the coding agent failed three times to implement it\"" })),
275
- }),
276
- async execute(_id, params) {
277
- const said = evaluateTests(options.cwd, options.advisor(), params.funcIds, { ...(params.plain_file !== undefined ? { plainFile: params.plain_file } : {}), ...(params.reason !== undefined ? { reason: params.reason } : {}) });
278
- const list = (names) => names.join(", ");
279
- const one = (names, single, many) => (names.length === 1 ? single : many);
280
- const text = [
281
- ...(said.started.length > 0 ? [`Testing scenarios for ${list(said.started)} are being evaluated in the background; the verdict comes back to this chat.`] : []),
282
- ...(said.already.length > 0 ? [`${list(said.already)} ${one(said.already, "is", "are")} being evaluated already; the verdict comes back to this chat.`] : []),
283
- ...(said.scenarios.length > 0 ? [`${list(said.scenarios)} ${one(said.scenarios, "has", "have")} scenarios already, so ${one(said.scenarios, "it is", "they are")} not evaluated: tested as the scenarios say.`] : []),
284
- ...(said.missing.length > 0 ? [`Not evaluated - ${said.missing.join("; ")}.`] : []),
285
- ...(said.started.length + said.already.length > 0 ? ["Tell the person so in a line, and go on: there is nothing to wait for."] : []),
286
- ].join("\n");
287
- return { content: [{ type: "text", text }], details: said };
288
- },
289
- });
290
- }
@@ -1,55 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { resolve } from "node:path";
3
- import { checkTouchedPlain, formatCheckResults } from "./plain/check.js";
4
- import { applySpecDiff, plainFilesOf, revertSpecDiff } from "./regenerate/regenerate.js";
5
- import { testPlainFileRefusal } from "./test-plain-files.js";
6
- import { parseArgs } from "./cli-options.js";
7
- import { headlessOptions, runLoop } from "./loop-cli.js";
8
- const USAGE = `usage: turri change-plain <file.plain> <diff-file> [options]
9
-
10
- Applies a change to ***plain, given as a git diff of the .plain files - modules and test plain files - and
11
- builds it: the headless
12
- counterpart of regenerate, given a diff. The diff is applied first, unless it is already in; then, as
13
- turri regenerate does, what is left to build is planned into jobs and built.
14
-
15
- --harness-model <p/id> config.turri.yaml's harness-model for this run: the planner, a diagnosis
16
- --coding-model <p/id> its coding-model, --model too: the agents that build
17
- --start-over start over, without asking, a codebase regenerated without a module it now requires
18
- --judge-model <p/id> its judge-model: the judge and the test review
19
- --review <true|false> its review: whether the code and its tests are reviewed once they pass
20
- --build-dir <dir> as the run ends, export the code there (see turri regenerate --help)
21
- --report <file.json> write a report of the run there (see turri regenerate --help)`;
22
- const { positional, options } = parseArgs(process.argv.slice(2), ["--start-over"], USAGE, ["--build-dir", "--report", "--harness-model", "--judge-model", "--review"]);
23
- const { report, buildDir } = headlessOptions(options);
24
- const [plainFile, diffFile] = positional;
25
- if (plainFile === undefined || diffFile === undefined) {
26
- console.error(USAGE);
27
- process.exit(1);
28
- }
29
- const refusal = testPlainFileRefusal(plainFile);
30
- if (refusal !== undefined) {
31
- console.error(refusal);
32
- process.exit(1);
33
- }
34
- const diff = readFileSync(diffFile, "utf8");
35
- const cwd = process.cwd();
36
- const applied = applySpecDiff(diff, cwd);
37
- // Every file the diff touched is checked - a test plain file as its module - not only the one named.
38
- const failed = checkTouchedPlain([plainFile, ...plainFilesOf(diff)].map((file) => resolve(cwd, file))).filter((check) => !check.ok);
39
- if (failed.length > 0) {
40
- if (applied === "applied")
41
- revertSpecDiff(diff, cwd);
42
- console.error(`Nothing was changed: with this diff the ***plain no longer checks.\n${formatCheckResults(failed)}`);
43
- process.exit(1);
44
- }
45
- runLoop({
46
- plainFile,
47
- startOver: options["start-over"] !== undefined,
48
- ...(buildDir !== undefined ? { buildDir } : {}),
49
- ...(report !== undefined ? { report } : {}),
50
- command: ["change-plain", ...process.argv.slice(2)],
51
- ask: (loop) => loop.bringUp(plainFile),
52
- }).catch((error) => {
53
- console.error(error instanceof Error ? error.message : error);
54
- process.exit(1);
55
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,50 +0,0 @@
1
- import { resolve } from "node:path";
2
- import { readLedger } from "./regenerate/ledger.js";
3
- import { describePastPulse, describeRuns, ledgerProjects, runViews } from "./regenerate/ledger-view.js";
4
- const USAGE = `usage: turri ledger [pulse] [--runs <n>] [--json]
5
-
6
- What turri did here, from the project's ledger (.turri/ledger): the last runs, a line a pulse - how each ended, how
7
- long it took and what it cost. With a pulse's id, or the start of it, that pulse: its rounds, test runs, verdicts,
8
- healers, what turri refused and what its history recorded. --json prints the events themselves, a JSON line each.
9
-
10
- --runs <n> how many runs to show, the most recent first (default 5)
11
- --json the events, as the ledger has them - the pulse's alone with a pulse`;
12
- const args = process.argv.slice(2);
13
- if (args.includes("--help") || args.includes("-h")) {
14
- console.log(USAGE);
15
- process.exit(0);
16
- }
17
- const runsAt = args.indexOf("--runs");
18
- const runs = runsAt >= 0 ? Number(args[runsAt + 1]) : 5;
19
- if (runsAt >= 0 && (!Number.isInteger(runs) || runs < 1)) {
20
- console.error(`--runs takes a number of runs, at least 1\n\n${USAGE}`);
21
- process.exit(1);
22
- }
23
- const [pulse] = args.filter((arg, at) => !arg.startsWith("-") && (runsAt < 0 || at !== runsAt + 1));
24
- const projects = ledgerProjects(process.cwd());
25
- if (projects.length === 0) {
26
- console.log("No ledger here: turri has not run in this folder, or in a project under it, since the ledger began.");
27
- process.exit(0);
28
- }
29
- if (args.includes("--json")) {
30
- for (const project of projects)
31
- for (const entry of readLedger(project, pulse !== undefined ? { job: pulse } : {}))
32
- console.log(JSON.stringify(entry));
33
- process.exit(0);
34
- }
35
- if (pulse !== undefined) {
36
- const described = describePastPulse(projects, pulse);
37
- if (described === undefined) {
38
- console.error(`The ledger has no pulse ${pulse}.`);
39
- process.exit(1);
40
- }
41
- console.log(described);
42
- process.exit(0);
43
- }
44
- for (const project of projects) {
45
- if (projects.length > 1)
46
- console.log(`── ${resolve(project)}\n`);
47
- console.log(describeRuns(runViews(project).slice(0, runs)));
48
- if (projects.length > 1)
49
- console.log("");
50
- }
@@ -1,10 +0,0 @@
1
- import { type ToolDefinition } from "@earendil-works/pi-coding-agent";
2
- type AnyTool = ToolDefinition<any, any, any>;
3
- /**
4
- * ledger: what turri did, as the ledger recorded it - in this session and every one before it. One pulse, by its id,
5
- * as facts; the last runs, a line a pulse; or the events of some kinds, counted and listed. Reads only.
6
- */
7
- export declare function ledgerTool(options: {
8
- cwd: string;
9
- }): AnyTool;
10
- export {};
@@ -1,64 +0,0 @@
1
- import { defineTool } from "@earendil-works/pi-coding-agent";
2
- import { Type } from "typebox";
3
- import { describeEvents, describePastPulse, describeRuns, ledgerProjects, runViews, sinceOf } from "./regenerate/ledger-view.js";
4
- /** How many runs `ledger` lists when it is asked for none. */
5
- const RUNS_SHOWN = 3;
6
- /**
7
- * ledger: what turri did, as the ledger recorded it - in this session and every one before it. One pulse, by its id,
8
- * as facts; the last runs, a line a pulse; or the events of some kinds, counted and listed. Reads only.
9
- */
10
- export function ledgerTool(options) {
11
- return defineTool({
12
- name: "ledger",
13
- label: "Ledger",
14
- description: "What turri did here, as its ledger recorded it - facts, not transcripts - in this session and every earlier one. " +
15
- "With pulse: that pulse, this session's or an earlier one's - how it ended, its rounds and test runs (how many failed " +
16
- "the same way), the judge's and the reviews' verdicts, the healers (the debugger, the diagnosis) and whether they " +
17
- "failed, the model provider's trouble, what turri refused and stopped, what it committed or rolled back, its last " +
18
- "stages and its log. With kinds (and module, since): how many events of those kinds there were, and the most recent, " +
19
- "a line each - healer.failed, provider.error, script.run, gate.round, judge.verdict, guard.refused, history.failed, " +
20
- "job.finished, ...; a group by its first part, healer for every healer event. Otherwise: the last runs, a line a pulse - " +
21
- "how each ended, how long, what it cost. Starts nothing and calls no model.",
22
- promptSnippet: "ledger: what turri did - a pulse as facts, the last runs, or events counted by kind - this session and earlier ones",
23
- promptGuidelines: [
24
- "Use ledger for what turri recorded of the work - a pulse's rounds, test runs, verdicts, healers and commits, this session's or an earlier one's; how often something happened; what earlier runs did and cost - rather than reading .turri/ledger with the shell. pulses is what is running and planned now; a pulse's whole transcript is its log, which ledger names when it is kept (debug mode).",
25
- ],
26
- parameters: Type.Object({
27
- pulse: Type.Optional(Type.String({ description: "A pulse's id, or the start of it: that pulse, as the ledger has it" })),
28
- kinds: Type.Optional(Type.Array(Type.String(), { description: "Event kinds to count and list - healer.failed, or healer for the whole group" })),
29
- module: Type.Optional(Type.String({ description: "With kinds: only the events of this module" })),
30
- since: Type.Optional(Type.String({ description: "With kinds: only events since then - 24h, 7d, 30m, or a date and time" })),
31
- runs: Type.Optional(Type.Number({ description: `Without pulse or kinds: how many of the last runs to list (default ${RUNS_SHOWN})` })),
32
- limit: Type.Optional(Type.Number({ description: "With kinds: how many of the most recent events to list (default 20)" })),
33
- }),
34
- async execute(_id, params) {
35
- const text = (body, details = {}) => ({ content: [{ type: "text", text: body }], details });
36
- const projects = ledgerProjects(options.cwd);
37
- if (projects.length === 0)
38
- return text("The ledger is empty here: nothing has run in this folder, or in a project under it, since it began.", { found: false });
39
- if (params.pulse !== undefined) {
40
- const described = describePastPulse(projects, params.pulse.trim());
41
- return described !== undefined ? text(described, { found: true }) : text(`The ledger has no pulse ${params.pulse}.`, { found: false });
42
- }
43
- if (params.kinds !== undefined && params.kinds.length > 0) {
44
- let since;
45
- if (params.since !== undefined) {
46
- since = sinceOf(params.since);
47
- if (since === undefined)
48
- return text(`since takes 24h, 7d, 30m or a date and time, not ${JSON.stringify(params.since)}.`, { found: false });
49
- }
50
- return text(describeEvents(projects, {
51
- kinds: params.kinds,
52
- ...(params.module !== undefined ? { module: params.module } : {}),
53
- ...(since !== undefined ? { since } : {}),
54
- ...(params.limit !== undefined ? { limit: params.limit } : {}),
55
- }), { found: true });
56
- }
57
- const count = params.runs !== undefined && Number.isFinite(params.runs) ? Math.max(1, Math.floor(params.runs)) : RUNS_SHOWN;
58
- const runs = projects.flatMap((project) => runViews(project)).sort((a, b) => (b.started?.ts ?? "").localeCompare(a.started?.ts ?? ""));
59
- const shown = runs.slice(0, count);
60
- const more = runs.length - shown.length;
61
- return text(`${describeRuns(shown)}${more > 0 ? `\n\n${more} earlier run${more === 1 ? "" : "s"} beyond these: ask with runs for more.` : ""}`, { found: true, runs: shown.length });
62
- },
63
- });
64
- }
@@ -1,93 +0,0 @@
1
- /**
2
- * The test advisor's file: `.turri/advisor/<module>.json` in the project - what it made of each functional spec of the
3
- * module it looked at, by func-id, keyed by a hash of its text (docs/test-advisor.md). Local to this machine: `.turri`
4
- * ignores itself, so it is never committed - another machine starts with none, and classifies only what changes there.
5
- *
6
- * An entry is current while its hash is the functional spec's text's: a text that changes makes it stale, and the
7
- * functional spec is looked at again. `pending` is written the moment the advisor sees a functional spec, so quitting
8
- * loses nothing: the next start in the chat or a host picks it up.
9
- */
10
- export declare const ADVISOR_DIR = "advisor";
11
- /** The four questions, each a yes or a no: could it fail silently, be read two ways, be built on later, cost much when wrong. */
12
- export declare const ADVISOR_QUESTIONS: readonly ["silent-failure", "divergence", "revisited", "cost"];
13
- export type AdvisorQuestion = (typeof ADVISOR_QUESTIONS)[number];
14
- /** A question that was a yes, with its evidence in a line: the wrong output, the input read two ways, what would change, the consequence. */
15
- export interface AdvisorAnswer {
16
- question: AdvisorQuestion;
17
- evidence: string;
18
- }
19
- /** An input to cover: one the readers agreed on, with its output, or one they split on, with each reading the verifier kept. */
20
- export type AdvisorInput = {
21
- input: string;
22
- agreed: string;
23
- } | {
24
- input: string;
25
- readings: string[];
26
- };
27
- /** What the advisor made of a functional spec: its verdict, the questions that were a yes, and on a yes the inputs to cover. */
28
- export interface AdvisorReport {
29
- verdict: "yes" | "no";
30
- questions: AdvisorAnswer[];
31
- inputs: AdvisorInput[];
32
- }
33
- /** Where an entry is: seen and not finished, classified yes or no, or failed - tried again only once its text changes. */
34
- export type AdvisorState = "pending" | "yes" | "no" | "failed";
35
- export interface AdvisorEntry {
36
- funcId: string;
37
- /** The hash of the functional spec's text the entry is about (textHash). */
38
- hash: string;
39
- state: AdvisorState;
40
- report?: AdvisorReport;
41
- /** The model the advisor ran on. */
42
- model?: string;
43
- /** When the entry was last written, ISO. */
44
- at: string;
45
- /** Why it failed, for a failed one. */
46
- reason?: string;
47
- /** The tip's .plain file, from the project: where the chain's scenarios are tested. */
48
- tip?: string;
49
- /** A yes not yet handed to a chat: delivered at the next start, as `pending` work is picked up. */
50
- undelivered?: boolean;
51
- /** Pending at the chat's asking (evaluate_tests), with why: picked up at the next start whatever `test-advisor` says. */
52
- asked?: {
53
- reason?: string;
54
- };
55
- }
56
- export interface AdvisorFile {
57
- module: string;
58
- /** The module's .plain file, from the project. */
59
- plainFile: string;
60
- entries: Record<string, AdvisorEntry>;
61
- }
62
- /** The hash a functional spec's text is known by: its text, trimmed. */
63
- export declare function textHash(text: string): string;
64
- /** The folder of a project's advisor files. */
65
- export declare function advisorDir(project: string): string;
66
- /** A module's advisor file. */
67
- export declare function advisorPath(project: string, module: string): string;
68
- /** A module's advisor file, or nothing when there is none or it does not read. */
69
- export declare function readAdvisor(project: string, module: string): AdvisorFile | undefined;
70
- /** A functional spec's entry, or nothing. */
71
- export declare function advisorEntry(project: string, module: string, funcId: string): AdvisorEntry | undefined;
72
- /** Whether an entry is about the text as it is now: one that is not, or none, is stale, and the functional spec is looked at again. */
73
- export declare function isCurrent(entry: AdvisorEntry | undefined, hash: string): entry is AdvisorEntry;
74
- /** Write a functional spec's entry, in place of the one it had. `plainFile` is the module's, from the project. */
75
- export declare function putAdvisorEntry(project: string, module: string, plainFile: string, entry: Omit<AdvisorEntry, "at"> & {
76
- at?: string;
77
- }): AdvisorEntry;
78
- /** Take a functional spec's entry out - its functional spec is gone. */
79
- export declare function removeAdvisorEntry(project: string, module: string, funcId: string): void;
80
- /** Every pending entry of a project's advisor files, with the module and its .plain file - what a start picks up. */
81
- export declare function pendingEntries(project: string): Array<{
82
- module: string;
83
- plainFile: string;
84
- entry: AdvisorEntry;
85
- }>;
86
- /** Every yes of a project's advisor files not yet handed to a chat - what a start delivers. */
87
- export declare function undeliveredEntries(project: string): Array<{
88
- module: string;
89
- plainFile: string;
90
- entry: AdvisorEntry;
91
- }>;
92
- /** A yes handed to a chat: the entry for that text no longer kept for the next start. */
93
- export declare function markDelivered(project: string, module: string, funcId: string, hash: string): void;