@turri-dev/cli 0.2.4-next.35ab04b → 0.2.4-next.636a651

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 (102) hide show
  1. package/README.md +2 -2
  2. package/dist/chat-idle.d.ts +2 -2
  3. package/dist/chat-idle.js +2 -2
  4. package/dist/chats.d.ts +0 -10
  5. package/dist/chats.js +0 -23
  6. package/dist/cli.js +5 -7
  7. package/dist/config-edit.js +1 -3
  8. package/dist/config.d.ts +20 -22
  9. package/dist/config.js +49 -22
  10. package/dist/conformance-switch.d.ts +7 -17
  11. package/dist/conformance-switch.js +24 -46
  12. package/dist/drift-cli.js +1 -1
  13. package/dist/extension.d.ts +8 -10
  14. package/dist/extension.js +157 -217
  15. package/dist/genome.js +9 -48
  16. package/dist/graph.js +3 -5
  17. package/dist/host-session.d.ts +4 -15
  18. package/dist/host-session.js +2 -4
  19. package/dist/host.d.ts +1 -3
  20. package/dist/host.js +1 -4
  21. package/dist/identity.js +0 -1
  22. package/dist/init-config.d.ts +0 -1
  23. package/dist/init-config.js +2 -9
  24. package/dist/installed-providers.d.ts +1 -1
  25. package/dist/installed-providers.js +1 -1
  26. package/dist/loop-cli.d.ts +4 -3
  27. package/dist/loop-cli.js +13 -11
  28. package/dist/loop-tools.d.ts +26 -3
  29. package/dist/loop-tools.js +85 -20
  30. package/dist/new-project.js +2 -2
  31. package/dist/pi-launch.js +1 -1
  32. package/dist/pi.js +9 -6
  33. package/dist/plain/check.d.ts +1 -8
  34. package/dist/plain/check.js +3 -38
  35. package/dist/regenerate/activity.d.ts +0 -7
  36. package/dist/regenerate/activity.js +2 -20
  37. package/dist/regenerate/agent-shell.js +3 -1
  38. package/dist/regenerate/audit.js +9 -0
  39. package/dist/regenerate/chunk-plan.d.ts +5 -0
  40. package/dist/regenerate/chunk-plan.js +16 -1
  41. package/dist/regenerate/failure-reports.d.ts +28 -0
  42. package/dist/regenerate/failure-reports.js +79 -0
  43. package/dist/regenerate/job-panel.js +3 -1
  44. package/dist/regenerate/jobs-tree.js +1 -1
  45. package/dist/regenerate/jobs.d.ts +2 -0
  46. package/dist/regenerate/jobs.js +4 -0
  47. package/dist/regenerate/ledger-view.d.ts +11 -24
  48. package/dist/regenerate/ledger-view.js +14 -60
  49. package/dist/regenerate/ledger.d.ts +1 -14
  50. package/dist/regenerate/ledger.js +1 -1
  51. package/dist/regenerate/loop.d.ts +37 -60
  52. package/dist/regenerate/loop.js +174 -106
  53. package/dist/regenerate/regenerate.d.ts +0 -2
  54. package/dist/regenerate/regenerate.js +4 -15
  55. package/dist/regenerate/standing.js +1 -1
  56. package/dist/regenerate/submit-work.d.ts +2 -0
  57. package/dist/regenerate/submit-work.js +8 -3
  58. package/dist/regenerate/testing-steps.d.ts +11 -0
  59. package/dist/regenerate/testing-steps.js +22 -3
  60. package/dist/regenerate-cli.js +18 -9
  61. package/dist/self-invocation.d.ts +11 -0
  62. package/dist/self-invocation.js +33 -7
  63. package/dist/sentinel.js +8 -5
  64. package/dist/skill.d.ts +0 -11
  65. package/dist/skill.js +0 -9
  66. package/dist/stacks.js +1 -1
  67. package/dist/tools.js +2 -3
  68. package/dist/turri-versions.js +2 -1
  69. package/docs/README.md +0 -2
  70. package/docs/authoring-plain.md +3 -3
  71. package/docs/chats.md +1 -3
  72. package/docs/config.md +11 -13
  73. package/docs/deploy.md +1 -1
  74. package/docs/development.md +2 -3
  75. package/docs/headless.md +5 -4
  76. package/docs/hosting.md +6 -6
  77. package/docs/parser.md +2 -2
  78. package/docs/regenerating.md +14 -12
  79. package/docs/sentinel.md +4 -4
  80. package/docs/skills-and-gates.md +4 -8
  81. package/docs/using.md +10 -18
  82. package/genome/rules/test-plain-files.md +15 -7
  83. package/genome/rules/turri-regeneration.md +4 -9
  84. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  85. package/package.json +1 -1
  86. package/dist/advisor-chat.d.ts +0 -63
  87. package/dist/advisor-chat.js +0 -290
  88. package/dist/change-plain-cli.d.ts +0 -1
  89. package/dist/change-plain-cli.js +0 -55
  90. package/dist/ledger-cli.d.ts +0 -1
  91. package/dist/ledger-cli.js +0 -50
  92. package/dist/ledger-tools.d.ts +0 -10
  93. package/dist/ledger-tools.js +0 -64
  94. package/dist/regenerate/advisor-records.d.ts +0 -93
  95. package/dist/regenerate/advisor-records.js +0 -110
  96. package/dist/regenerate/advisor-runs.d.ts +0 -87
  97. package/dist/regenerate/advisor-runs.js +0 -327
  98. package/dist/regenerate/test-advisor.d.ts +0 -101
  99. package/dist/regenerate/test-advisor.js +0 -379
  100. package/dist/spec-tools.d.ts +0 -36
  101. package/dist/spec-tools.js +0 -128
  102. package/docs/test-advisor.md +0 -110
@@ -36,15 +36,10 @@ The other rules say what a spec means. This one says what turri does with a chan
36
36
  - A functional spec written on its happy path and hardened later - its validation, edge cases and errors added to it - is patched in place each time: growing a spec a step at a time costs no more than writing it whole up front
37
37
  - A module's first pulse, when it builds one functional spec - the project set up and the smallest thing that runs - lands on its unit tests with no review
38
38
 
39
- ## The test advisor
40
-
41
- - Conformance tests are the project's choice: `conformance-tests:` in config.turri.yaml, off when unset. Off, no scenarios are tested and the test advisor is off - write no test plain file, test reqs or conformance testing script unless the person asks for tests; their asking, or their yes when the chat offers them, turns them on first
42
- - In the chat and a host, turri's test advisor looks at each functional spec that is new, or whose text changed since its code was built, and that has no scenarios - in the background, beside the pulses, taking no slot of theirs and never stopping one. It asks whether a wrong implementation could give output that looks right, whether two reasonable readings give different outputs for some input, whether it is likely to be built on later, and whether a bug in it would be costly. A yes to the first, the second or the last, with evidence, means the functional spec needs testing; built on later alone does not
43
- - It writes nothing in the ***plain: you are its only writer. A functional spec with scenarios of any kind is not looked at by it; its scenarios go through the usual review when its text changes
44
- - A change's result names the functional specs the advisor is checking: tell the person in a line that testing scenarios are being evaluated for them, and go on
45
- - Its yes comes to you as a message, once the chat is idle, with its report: tell the person in a line, then write with `change_plain` what testing the functional spec needs - its test reqs, the conformance testing script, its scenarios, in that order and only what is missing - the script written in the background, so you go straight on to the scenarios - as the rules on test plain files say, asking the person nothing. Its no is a line turri draws: nothing for you to do
46
- - `evaluate_tests` asks the advisor yourself, for functional specs you name with why, even a text it judged already: it returns at once, and the verdict comes back the same way. Call it when the person asks whether a functional spec needs tests, and on your own as another way of expressing intent - when pulses keep failing on a complicated functional spec, scenarios may pin down what it should do. A functional spec with scenarios is not evaluated
47
- - When the person asks for scenarios, write them yourself, as the rules on test plain files say. `test-advisor: false` turns off only what a change starts, never `evaluate_tests`; the advisor never runs in a headless run
39
+ ## Conformance tests
40
+
41
+ - Conformance tests are the person's choice: `conformance-tests:` in config.turri.yaml, off when unset, as they make each change take about twice as long. Off, no scenarios are tested and `conform` is refused - write no test plain file, test reqs or conformance testing script. When you think a module needs conformance tests, or the person asks for them, tell them in a line or two why; they decide, and turn them on with `/conform`
42
+ - On, you decide which functional specs need scenarios: as you write or change one, judge it by the criteria in the rules on test plain files, and when it needs them, write them - with the test reqs and the conformance testing script first, when missing, without asking: conformance tests on is the person's yes to all three - as a visible ***plain change the person reviews like any other, then call `regenerate`. The work loop writes and runs their conformance tests once the code is built
48
43
 
49
44
  ## What a coding agent sees
50
45
 
@@ -7,11 +7,11 @@ description: >-
7
7
  when turri says a module is in the old ***plain syntax, or the person asks to
8
8
  convert one. One run converts one module, the lowest of the chain first;
9
9
  it never regenerates.
10
- allowed-tools: [read, ls, grep, find, change_plain, parse]
10
+ allowed-tools: [read, write, edit, ls, grep, find, parse]
11
11
  metadata:
12
12
  phases:
13
13
  ids: "a func-id for each functional spec and a scenario-id for each acceptance test, proposed and confirmed"
14
- rewrite: "the module and its test plain files, in one ***plain diff, word for word"
14
+ rewrite: "the module and its test plain files, word for word"
15
15
  check: "parse, and which module is next"
16
16
  gates:
17
17
  - after: rewrite
@@ -44,7 +44,7 @@ Ask the person once, with `ask_user`: the whole list in its `context` - each fun
44
44
 
45
45
  ### rewrite
46
46
 
47
- Write the whole conversion as one `change_plain` diff, with the confirmed ids:
47
+ Write the whole conversion with `write` and `edit`, with the confirmed ids:
48
48
 
49
49
  - **The module.** Under `***functional specs***`, each bullet becomes its `# <func-id>` heading followed by its body: the bullet's text without its leading `- `, word for word. Its sub-bullets become `- ` bullets under that text, one level less indented, word for word and in the same order. Its nested `***acceptance tests***` are taken out of the module. The functional specs keep their order, one blank line between them. The frontmatter, every other section, the comments and any Liquid stay exactly as they are.
50
50
  - **Its test plain files,** one for each functional spec that has acceptance tests, at `tests/<module>/<func-id>.plain`: frontmatter `module:` (the module's file name without `.plain`) and `func_id:`, then `***conformance tests***`, then `***acceptance tests***` (`test-plain-files.md`). Each acceptance test of the functional spec becomes a scenario under `***acceptance tests***`: its `# <scenario-id>` heading followed by its text without its `- `, word for word, and its sub-bullets as `- ` bullets under it. `***conformance tests***` stays empty. A functional spec with no acceptance tests gets no test plain file: it has no scenarios.
@@ -53,13 +53,13 @@ Nothing else: no word added, reworded or dropped, no conformance scenario, no fi
53
53
 
54
54
  The change regenerates nothing: a module built before func-ids is not built on until its chain is regenerated from scratch, which the chat asks the person for.
55
55
 
56
- The record for the review: the module as it was before the change, word for word as you read it; the confirmed ids; and every file the change wrote. When the review sends the step back, show the person what it found and your fix with `ask_user`, then write the fix with one `change_plain`.
56
+ The record for the review: the module as it was before the change, word for word as you read it; the confirmed ids; and every file the change wrote. When the review sends the step back, show the person what it found and your fix with `ask_user`, then write the fix.
57
57
 
58
58
  ### check
59
59
 
60
60
  Run `parse` on the module and show what it says in your reply.
61
61
 
62
- When it reports an error the conversion made, show it to the person with `ask_user`, with the fix, and write the fix with one `change_plain`; then run `parse` again. An error the module had before the conversion stays for the person.
62
+ When it reports an error the conversion made, show it to the person with `ask_user`, with the fix, and write the fix; then run `parse` again. An error the module had before the conversion stays for the person.
63
63
 
64
64
  End with the result:
65
65
  - the module converted, its functional specs and scenarios counted, and the files written
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turri-dev/cli",
3
- "version": "0.2.4-next.35ab04b",
3
+ "version": "0.2.4-next.636a651",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {
@@ -1,63 +0,0 @@
1
- import { type ExtensionAPI, type ExtensionContext, type ToolDefinition } from "@earendil-works/pi-coding-agent";
2
- import type { ChatLink } from "./chats.ts";
3
- import type { AdvisorVerdict, TestAdvisor } from "./regenerate/advisor-runs.ts";
4
- import type { WorkLoop } from "./regenerate/loop.ts";
5
- /** The line a no is drawn as: the functional spec, and the classifier's reading in a few words - a no has no evidence. */
6
- export declare function noLine(verdict: AdvisorVerdict): string;
7
- /** The line the chat is to tell the person a yes in. */
8
- export declare function yesLine(verdict: AdvisorVerdict): string;
9
- /** A yes's report, as the chat's agent is given it: the questions that were a yes with their evidence, and the inputs. */
10
- export declare function describeReport(verdict: AdvisorVerdict): string[];
11
- /** The turn a batch of yeses starts: each one's report, and what the chat is to do with them - asking the person nothing. */
12
- export declare function yesTask(verdicts: AdvisorVerdict[]): string;
13
- /** How long a verdict waits before the chat is looked at again, while the person types or it cannot be told yet. */
14
- export declare const ADVISOR_RECHECK_MS = 2000;
15
- /**
16
- * A chat's verdicts: held until the chat is idle - its agent done, and nothing typed in its editor - then delivered
17
- * together: one turn for every yes, one line for each no. A verdict no longer about its functional spec as it is - its
18
- * text changed, or it was given scenarios meanwhile - is let go.
19
- */
20
- export declare function verdictDelivery(pi: ExtensionAPI, link: ChatLink, context: () => ExtensionContext | undefined): {
21
- put(verdict: AdvisorVerdict): void;
22
- };
23
- /**
24
- * The test advisor and the chat, in its system prompt while the session has the advisor and the project wants it: the
25
- * two ways an evaluation starts, what to say while it runs, what to do with its verdict, and when to ask for one.
26
- */
27
- export declare const TEST_ADVISOR_BLOCK: string;
28
- /** The test advisor of the session a work loop is in. */
29
- export declare function bindAdvisor(loop: WorkLoop, advisor: () => TestAdvisor | undefined): void;
30
- /**
31
- * What a change's tool result tells the chat's agent of the test advisor: the functional specs it has taken up, so the
32
- * agent tells the person they are being evaluated - nothing when it has taken up none.
33
- */
34
- export declare function advisingNote(loop: WorkLoop, plainFile: string): string;
35
- /** What an evaluation asked for came to, by functional spec - each named `module:func-id`, a missing one with why. */
36
- export interface EvaluateOutcome {
37
- /** Being evaluated now: the verdict comes to the chat the person looks at. */
38
- started: string[];
39
- /** Being evaluated already. */
40
- already: string[];
41
- /** With scenarios already: not evaluated. */
42
- scenarios: string[];
43
- /** Not found, with why. */
44
- missing: string[];
45
- }
46
- /**
47
- * The test advisor asked to evaluate functional specs - `module:func-id`s, or func-ids of `plainFile`'s module (else the
48
- * one the project's config names) - even a text it judged already, and whatever `test-advisor` says: `evaluate_tests`'s
49
- * and a host's `evaluateTests`. It returns at once.
50
- */
51
- export declare function evaluateTests(cwd: string, advisor: TestAdvisor | undefined, funcIds: string[], options?: {
52
- plainFile?: string;
53
- reason?: string;
54
- }): EvaluateOutcome;
55
- /**
56
- * evaluate_tests: the chat's own way to the test advisor - a functional spec evaluated in the background, whatever
57
- * `test-advisor` says, and even when its text was judged already. It returns at once; the verdict comes back to the chat
58
- * as the advisor's verdicts do. In the chat and a host only: the session has an advisor.
59
- */
60
- export declare function evaluateTestsTool(options: {
61
- cwd: string;
62
- advisor: () => TestAdvisor | undefined;
63
- }): ToolDefinition;
@@ -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 +0,0 @@
1
- export {};
@@ -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
- }