@turri-dev/cli 0.2.4-next.8422d0f → 0.2.4-next.efe96fe

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 (143) hide show
  1. package/README.md +5 -6
  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/chats.d.ts +2 -12
  9. package/dist/chats.js +3 -26
  10. package/dist/cli.js +11 -30
  11. package/dist/config-edit.d.ts +20 -8
  12. package/dist/config-edit.js +29 -23
  13. package/dist/config.d.ts +62 -71
  14. package/dist/config.js +170 -125
  15. package/dist/conform-cli.js +14 -3
  16. package/dist/conformance-switch.d.ts +13 -22
  17. package/dist/conformance-switch.js +37 -59
  18. package/dist/drift-cli.js +1 -1
  19. package/dist/extension.d.ts +8 -10
  20. package/dist/extension.js +257 -429
  21. package/dist/genome.js +9 -48
  22. package/dist/graph.js +3 -5
  23. package/dist/host-session.d.ts +5 -16
  24. package/dist/host-session.js +4 -6
  25. package/dist/host.d.ts +2 -4
  26. package/dist/host.js +4 -7
  27. package/dist/identity.js +0 -1
  28. package/dist/init-config.d.ts +0 -1
  29. package/dist/init-config.js +3 -10
  30. package/dist/installed-providers.d.ts +1 -1
  31. package/dist/installed-providers.js +1 -1
  32. package/dist/loop-cli.d.ts +4 -3
  33. package/dist/loop-cli.js +13 -11
  34. package/dist/loop-tools.d.ts +37 -18
  35. package/dist/loop-tools.js +118 -58
  36. package/dist/new-project.js +2 -2
  37. package/dist/parse-cli.js +2 -2
  38. package/dist/pi-launch.js +4 -1
  39. package/dist/pi-settings.d.ts +4 -0
  40. package/dist/pi-settings.js +39 -0
  41. package/dist/pi.js +12 -9
  42. package/dist/plain/check.d.ts +2 -9
  43. package/dist/plain/check.js +6 -39
  44. package/dist/plain-files.js +4 -4
  45. package/dist/regenerate/activity.d.ts +0 -7
  46. package/dist/regenerate/activity.js +2 -20
  47. package/dist/regenerate/agent-env.d.ts +1 -1
  48. package/dist/regenerate/agent-env.js +3 -3
  49. package/dist/regenerate/agent-shell.js +5 -3
  50. package/dist/regenerate/audit.js +9 -0
  51. package/dist/regenerate/base-folder.d.ts +2 -2
  52. package/dist/regenerate/base-folder.js +1 -1
  53. package/dist/regenerate/cases.js +7 -0
  54. package/dist/regenerate/chunk-plan.d.ts +5 -0
  55. package/dist/regenerate/chunk-plan.js +16 -1
  56. package/dist/regenerate/drift.d.ts +4 -0
  57. package/dist/regenerate/drift.js +26 -6
  58. package/dist/regenerate/failure-reports.d.ts +28 -0
  59. package/dist/regenerate/failure-reports.js +79 -0
  60. package/dist/regenerate/job-panel.js +3 -1
  61. package/dist/regenerate/jobs-tree.js +1 -1
  62. package/dist/regenerate/jobs.d.ts +4 -2
  63. package/dist/regenerate/jobs.js +14 -10
  64. package/dist/regenerate/ledger-view.d.ts +11 -24
  65. package/dist/regenerate/ledger-view.js +14 -60
  66. package/dist/regenerate/ledger.d.ts +2 -15
  67. package/dist/regenerate/ledger.js +1 -1
  68. package/dist/regenerate/loop.d.ts +48 -62
  69. package/dist/regenerate/loop.js +296 -131
  70. package/dist/regenerate/model-names.d.ts +33 -0
  71. package/dist/regenerate/{engine.js → model-names.js} +2 -28
  72. package/dist/regenerate/paths.d.ts +1 -1
  73. package/dist/regenerate/paths.js +2 -2
  74. package/dist/regenerate/records.d.ts +11 -0
  75. package/dist/regenerate/records.js +15 -0
  76. package/dist/regenerate/regenerate.d.ts +0 -2
  77. package/dist/regenerate/regenerate.js +4 -15
  78. package/dist/regenerate/renames.js +4 -4
  79. package/dist/regenerate/requires.d.ts +7 -0
  80. package/dist/regenerate/requires.js +24 -18
  81. package/dist/regenerate/scripts-being-written.d.ts +4 -4
  82. package/dist/regenerate/scripts-being-written.js +3 -3
  83. package/dist/regenerate/spec-map.js +3 -3
  84. package/dist/regenerate/standing.js +1 -1
  85. package/dist/regenerate/submit-work.d.ts +2 -0
  86. package/dist/regenerate/submit-work.js +8 -3
  87. package/dist/regenerate/test-scripts.d.ts +2 -1
  88. package/dist/regenerate/test-scripts.js +33 -23
  89. package/dist/regenerate/testing-steps.d.ts +16 -5
  90. package/dist/regenerate/testing-steps.js +28 -9
  91. package/dist/regenerate-cli.js +18 -9
  92. package/dist/self-invocation.d.ts +11 -0
  93. package/dist/self-invocation.js +33 -7
  94. package/dist/sentinel.js +8 -5
  95. package/dist/{config-command.d.ts → settings.d.ts} +13 -8
  96. package/dist/{config-command.js → settings.js} +155 -24
  97. package/dist/setup.d.ts +2 -2
  98. package/dist/setup.js +7 -7
  99. package/dist/skill.d.ts +0 -11
  100. package/dist/skill.js +0 -9
  101. package/dist/tools.js +2 -3
  102. package/dist/turri-versions.js +2 -1
  103. package/docs/README.md +2 -4
  104. package/docs/authoring-plain.md +3 -3
  105. package/docs/chats.md +4 -7
  106. package/docs/claude-subscription.md +2 -2
  107. package/docs/config.md +55 -45
  108. package/docs/deploy.md +1 -1
  109. package/docs/development.md +3 -4
  110. package/docs/headless.md +6 -5
  111. package/docs/hosting.md +11 -11
  112. package/docs/parser.md +3 -3
  113. package/docs/regenerating.md +27 -19
  114. package/docs/sentinel.md +6 -6
  115. package/docs/skills-and-gates.md +4 -9
  116. package/docs/using.md +20 -37
  117. package/genome/rules/project-model.md +2 -1
  118. package/genome/rules/test-plain-files.md +15 -7
  119. package/genome/rules/turri-regeneration.md +6 -9
  120. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  121. package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
  122. package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
  123. package/package.json +1 -1
  124. package/dist/advisor-chat.d.ts +0 -63
  125. package/dist/advisor-chat.js +0 -290
  126. package/dist/change-plain-cli.d.ts +0 -1
  127. package/dist/change-plain-cli.js +0 -55
  128. package/dist/ledger-cli.d.ts +0 -1
  129. package/dist/ledger-cli.js +0 -50
  130. package/dist/ledger-tools.d.ts +0 -10
  131. package/dist/ledger-tools.js +0 -64
  132. package/dist/regenerate/advisor-records.d.ts +0 -93
  133. package/dist/regenerate/advisor-records.js +0 -110
  134. package/dist/regenerate/advisor-runs.d.ts +0 -87
  135. package/dist/regenerate/advisor-runs.js +0 -327
  136. package/dist/regenerate/engine.d.ts +0 -52
  137. package/dist/regenerate/test-advisor.d.ts +0 -101
  138. package/dist/regenerate/test-advisor.js +0 -379
  139. package/dist/spec-tools.d.ts +0 -36
  140. package/dist/spec-tools.js +0 -128
  141. package/dist/stacks.d.ts +0 -13
  142. package/dist/stacks.js +0 -96
  143. package/docs/test-advisor.md +0 -110
@@ -3,11 +3,13 @@ import { refuseTestPlainFile } from "./test-plain-files.js";
3
3
  import { basename, relative, resolve } from "node:path";
4
4
  import { defineTool } from "@earendil-works/pi-coding-agent";
5
5
  import { Type } from "typebox";
6
- import { advisingNote } from "./advisor-chat.js";
7
- import { CONFIG_FILE, readProjectConfig, stackConfigFile, stackForModule, stackNamed, stacksOf, withStack } from "./config.js";
6
+ import { CONFIG_FILE, readProjectConfig, moduleConfigFile, configModuleFor, moduleConfigsOf, withConfigModule } from "./config.js";
8
7
  import { checkPlainFile, formatCheckResults } from "./plain/check.js";
9
8
  import { describeDrift, describeModules } from "./regenerate/loop.js";
10
- import { pulseName } from "./regenerate/jobs.js";
9
+ import { describeJob, pulseName } from "./regenerate/jobs.js";
10
+ import { currentChat } from "./chat-scope.js";
11
+ import { whyFailed } from "./regenerate/diagnose-job.js";
12
+ import { didNotLand } from "./regenerate/failure-reports.js";
11
13
  import { stopDeployed } from "./regenerate/release.js";
12
14
  import { projectDirOf } from "./regenerate/paths.js";
13
15
  import { findTestScripts } from "./regenerate/test-scripts.js";
@@ -18,50 +20,48 @@ export const GUIDANCE_PARAM = Type.Optional(Type.String({
18
20
  "the user said it, or as you understood it. A strong preference for the planner, within its limits. Omit when there is none.",
19
21
  }));
20
22
  export const WORKING_DIR_PARAM = Type.Optional(Type.String({
21
- description: "The folder to render from, relative to where turri was started - as if it had been started there " +
22
- "(e.g. \"plain\"). plain_file, build_dir and a spec diff's paths are then relative to it - hubspot.plain, not " +
23
- "plain/hubspot.plain. Default: where " +
23
+ description: "The folder the .plain files are in, relative to where turri was started - as if it had been started there " +
24
+ "(e.g. \"plain\"). plain_file is then relative to it - hubspot.plain, not plain/hubspot.plain. Default: where " +
24
25
  "turri was started.",
25
26
  }));
26
27
  export const MODEL_PARAM = Type.Optional(Type.String({
27
28
  description: "The model for the agents of this one call: a provider/model-id, or its name as the user said it. " +
28
- "Omitted: the model chosen for this kind of work with engine, else the conversation's. " +
29
- "To change it for every later render, use engine instead.",
30
- }));
31
- export const STACK_PARAM = Type.Optional(Type.String({
32
- description: "In a project of stacks: the stack that builds this module - its config.turri.<stack>.yaml over config.turri.yaml, " +
33
- "its testing scripts, toolchains and models - for every pulse of it, whatever stack is chosen later. \"none\": " +
34
- "config.turri.yaml alone. Omitted: the stack named after the module - config.turri.backend.yaml for backend.plain - " +
35
- "else the one chosen now.",
29
+ "Omitted: the coding model the module's config names, else the conversation's. " +
30
+ "To change it for every later pulse, set coding-model with settings instead.",
36
31
  }));
37
32
  /**
38
- * Why a module asked for with no stack named cannot be built: a project of stacks where it has no stack of its own and
39
- * none is chosen, and config.turri.yaml alone names no unit testing script - every pulse would stop for want of one.
40
- * The stacks and the script each names, and what to do. Undefined when it can be built.
33
+ * Why a module cannot be built with the config it would be built with: two of the modules it requires have a config
34
+ * file of their own (`configModuleFor`); or, in a project where modules have their own files, it has none - nor any
35
+ * module it requires - and config.turri.yaml alone names no unit testing script, so every pulse would stop for want of
36
+ * one. The files there are and the script each names, and what to do. Undefined when it can be built.
41
37
  */
42
- export function stacklessBuild(plainFile) {
38
+ export function unbuildableConfig(plainFile) {
43
39
  const root = projectDirOf(plainFile);
44
- const stacks = stacksOf(root);
45
- if (stacks.length === 0 || stackForModule(plainFile) !== undefined || findTestScripts(root).unit !== undefined)
40
+ let own;
41
+ try {
42
+ own = configModuleFor(plainFile);
43
+ }
44
+ catch (error) {
45
+ return error instanceof Error ? error.message : String(error);
46
+ }
47
+ const files = moduleConfigsOf(root);
48
+ if (files.length === 0 || own !== undefined || findTestScripts(root).unit !== undefined)
46
49
  return undefined;
47
- const scripts = stacks.map((each) => {
48
- const unit = withStack(each, () => findTestScripts(root).unit);
49
- return `${each}${unit !== undefined ? ` (${stackConfigFile(each)}: ${relative(root, unit)})` : ""}`;
50
+ const scripts = files.map((each) => {
51
+ const unit = withConfigModule(each, () => findTestScripts(root).unit);
52
+ return `${moduleConfigFile(each)}${unit !== undefined ? ` (${relative(root, unit)})` : ""}`;
50
53
  });
51
- return (`${basename(plainFile)} would be built with no stack - ${CONFIG_FILE} alone - and that names no unit testing script, so every ` +
52
- `pulse would stop. No stack is named after it, and none is chosen. The project's stacks: ${scripts.join(", ")}. Pass the ` +
53
- `stack that builds ${basename(plainFile)} as stack - or ask the user which, when the spec does not make it plain.`);
54
+ const name = basename(plainFile, ".plain");
55
+ return (`${basename(plainFile)} would be built with ${CONFIG_FILE} alone - it has no ${moduleConfigFile(name)}, and none of the ` +
56
+ `modules it requires has one - and that names no unit testing script, so every pulse would stop. The modules' own ` +
57
+ `files: ${scripts.join(", ")}. Name its testing scripts in its own file - the settings tool, with module ${basename(plainFile)} - ` +
58
+ `or ask the user which, when the ***plain does not make it plain.`);
54
59
  }
55
- /**
56
- * `work` with the stack a call names chosen for it - or, none named, as it is: each module is then built with its own
57
- * (`stackForModule`). A module that could not be built that way is refused before anything is planned (`stacklessBuild`).
58
- */
59
- export function withCallStack(plainFile, named, work) {
60
- if (named !== undefined)
61
- return withStack(stackNamed(projectDirOf(plainFile), named), work);
62
- const stackless = stacklessBuild(plainFile);
63
- if (stackless !== undefined)
64
- throw new Error(`Nothing was started: ${stackless}`);
60
+ /** `work`, once the module asked for can be built with the config it would be built with - refused before anything is planned otherwise (`unbuildableConfig`). */
61
+ export function whenBuildable(plainFile, work) {
62
+ const unbuildable = unbuildableConfig(plainFile);
63
+ if (unbuildable !== undefined)
64
+ throw new Error(`Nothing was started: ${unbuildable}`);
65
65
  return work();
66
66
  }
67
67
  export const WAIT_PARAM = Type.Optional(Type.Boolean({
@@ -92,13 +92,69 @@ export function fromWorkingDir(cwd, params) {
92
92
  ...(params.build_dir !== undefined ? { build_dir: resolve(base, params.build_dir) } : {}),
93
93
  };
94
94
  }
95
- /** What the loop is doing for a spec's modules, for the conversation - and, waiting, how each module ended. */
96
- export async function loopReply(loop, statuses, wait) {
97
- if (wait)
98
- await loop.drain();
95
+ /** The calls waiting now, by registry. */
96
+ const waits = new WeakMap();
97
+ /** A call in this chat starts waiting, from the pulses there are now. */
98
+ export function startWait(jobs) {
99
+ const wait = { chat: currentChat()?.id, before: new Set(jobs.list().map((job) => job.id)) };
100
+ const set = waits.get(jobs) ?? new Set();
101
+ set.add(wait);
102
+ waits.set(jobs, set);
103
+ return wait;
104
+ }
105
+ /** A call is done waiting: what ends now is told as any pulse's end is. */
106
+ export function endWait(jobs, wait) {
107
+ waits.get(jobs)?.delete(wait);
108
+ }
109
+ /**
110
+ * Whether a pulse that ended is told by a call still waiting in its chat - its agent is told it in that call's reply, so
111
+ * a turn of its own to say it again would only repeat it.
112
+ */
113
+ export function toldByWaitingCall(jobs, job) {
114
+ for (const wait of waits.get(jobs) ?? [])
115
+ if (wait.chat === job.chat && !wait.before.has(job.id))
116
+ return true;
117
+ return false;
118
+ }
119
+ /** A module's why while it waits for a testing script being written (loop.ts SCRIPT_BEING_WRITTEN). */
120
+ const SCRIPT_WAIT = /, which is being written$/;
121
+ /** How often a waiting call looks again while its module waits for a testing script. */
122
+ const SCRIPT_POLL_MS = 500;
123
+ /** How much of each pulse that ran while a call waited is told: the rest is pulses' with its id. */
124
+ const RAN_CHARS = 3_000;
125
+ /**
126
+ * What the loop is doing for a spec's modules, for the conversation - and, waiting, the pulses that ran meanwhile and how
127
+ * each ended, then how each module stands: `ran` is the registry and the call's wait (startWait).
128
+ */
129
+ export async function loopReply(loop, statuses, wait, ran) {
130
+ try {
131
+ if (wait) {
132
+ await loop.drain();
133
+ // A module held for a testing script being written - beside this call, by a skill run - starts once it is: a call
134
+ // that waits waits for that too, rather than say it waits and end before its pulse runs.
135
+ while (loop.status().some((status) => statuses.some((asked) => asked.plainFile === status.plainFile) && SCRIPT_WAIT.test(status.why ?? ""))) {
136
+ await new Promise((resolve) => setTimeout(resolve, SCRIPT_POLL_MS));
137
+ await loop.drain();
138
+ }
139
+ }
140
+ }
141
+ finally {
142
+ if (ran !== undefined)
143
+ endWait(ran.jobs, ran.wait);
144
+ }
99
145
  const now = wait ? loop.status().filter((status) => statuses.some((asked) => asked.plainFile === status.plainFile)) : statuses;
100
146
  const jobIds = now.flatMap((status) => (status.running !== undefined ? [status.running.jobId] : []));
147
+ const pulses = wait && ran !== undefined ? ran.jobs.list().filter((job) => job.chat === ran.wait.chat && !ran.wait.before.has(job.id)).sort((a, b) => a.sequence - b.sequence) : [];
148
+ const cut = (text) => (text.length > RAN_CHARS ? `${text.slice(0, RAN_CHARS)}\n… cut short: pulses with its id tells the whole of it` : text);
101
149
  const text = [
150
+ ...(pulses.length > 0
151
+ ? [
152
+ `What ran while you waited - ${pulses.length} pulse${pulses.length === 1 ? "" : "s"}:`,
153
+ ...pulses.map((job) => `\n<pulse id="${job.id}" landed="${didNotLand(job) ? "no" : "yes"}">\n${cut(didNotLand(job) ? whyFailed(job) : describeJob(job))}\n</pulse>`),
154
+ "",
155
+ "How each module stands now:",
156
+ ]
157
+ : []),
102
158
  describeModules(now),
103
159
  "",
104
160
  wait
@@ -151,11 +207,11 @@ function plainFileOf(cwd, given, what) {
151
207
  refuseTestPlainFile(plainFile);
152
208
  return plainFile;
153
209
  }
154
- /** Whether a /regenerate's words ask for the module from scratch: its code deleted, and all of it regenerated again. */
210
+ /** Whether a /regenerate's words ask for the module from scratch - its code deleted, and all of it regenerated again - or a /conform's, for its conformance tests written again. */
155
211
  export function asksFromScratch(words) {
156
212
  return FROM_SCRATCH.test(words);
157
213
  }
158
- /** Whether a /regenerate asking for its module from scratch asks for its whole requires chain with it. */
214
+ /** Whether a /regenerate or /conform asking for its module from scratch asks for its whole requires chain with it. */
159
215
  export function asksWholeChain(words) {
160
216
  return /\bchain\b|\bevery module\b|\ball (the )?modules\b/i.test(words);
161
217
  }
@@ -180,7 +236,6 @@ export function regenerateTool(options) {
180
236
  "A change to a file the spec links - an API surface, a mapping document - is a change to the spec: regenerate sees it by itself, and regenerates every functional spec that uses what links it.",
181
237
  "Never stop pulses and start them again yourself to follow a spec change: regenerate does it.",
182
238
  "Set from_scratch only when the user asks for the module to be regenerated from scratch - started over, its code deleted - in this conversation, or agrees to it when a module's status says it has to start over: never to fix a pulse that did not land.",
183
- "In a project of stacks - a backend and a frontend, each with its config.turri.<stack>.yaml - a module is built with the stack named after it by itself: backend.plain with config.turri.backend.yaml. Pass stack only for a module whose stack has another name. It is pinned to the module's pulses: a backend and a frontend regenerate side by side, each with its own, without switching the stack chosen. What it says back names the stack each module is built with.",
184
239
  'from_scratch "module" takes out the code where the module is built; the modules below keep theirs, and the module starts from a copy of the code below it. "chain" takes out every codebase of its requires chain, the base\'s too, and builds all of it again from the bottom: use it after modules were split, merged or moved (refactor-module), or when the user asks for the whole chain.',
185
240
  ],
186
241
  parameters: Type.Object({
@@ -194,13 +249,12 @@ export function regenerateTool(options) {
194
249
  description: "Only when the user asks for it: the module's code and conformance tests deleted - committed first, so its lineage keeps them - and the whole module regenerated from its spec. " +
195
250
  '"chain": every module of its requires chain too, built again from the bottom',
196
251
  })),
197
- stack: STACK_PARAM,
198
252
  model: MODEL_PARAM,
199
253
  wait: WAIT_PARAM,
200
254
  }),
201
255
  async execute(_id, given, _signal, _onUpdate, ctx) {
202
256
  const plainFile = plainFileOf(options.cwd, given, "regenerate");
203
- return withCallStack(plainFile, given.stack, async () => {
257
+ return whenBuildable(plainFile, async () => {
204
258
  const check = checkPlainFile(plainFile);
205
259
  // The parser's message as it gives it, a test plain file out of place, and turri's next step for the old syntax.
206
260
  if (!check.ok)
@@ -208,20 +262,26 @@ export function regenerateTool(options) {
208
262
  const again = given.funcIds ?? [];
209
263
  if (again.length > 0 && given.from_scratch !== undefined)
210
264
  throw new Error("Name funcIds or set from_scratch, not both: from scratch regenerates every one of them.");
211
- // Named functionalities are work on functionalities, as engine chooses a model for it; the rest, spec changes.
212
- const work = again.length > 0 ? "functionalities" : "spec_changes";
213
- const model = options.model !== undefined ? options.model(ctx, plainFile, given.model, work) : given.model;
265
+ const model = options.model !== undefined ? options.model(ctx, plainFile, given.model) : given.model;
214
266
  const loop = options.loop(ctx);
215
267
  const request = { ...(model !== undefined ? { model } : {}), ...(given.guidance !== undefined ? { guidance: given.guidance } : {}) };
216
- const statuses = given.from_scratch !== undefined
217
- ? await loop.fromScratch(plainFile, { ...request, chain: given.from_scratch === "chain" })
218
- : again.length > 0
219
- ? await loop.regenerateAgain(plainFile, again, request)
220
- : await loop.bringUp(plainFile, request);
221
- const reply = await loopReply(loop, statuses, options.wait !== undefined ? options.wait(ctx, given.wait) : given.wait === true);
222
- // The functional specs the test advisor took up, for the agent to say so rather than offer their scenarios.
223
- const advising = advisingNote(loop, plainFile);
224
- return advising === "" ? reply : { ...reply, content: [...reply.content, { type: "text", text: advising }] };
268
+ const wait = options.wait !== undefined ? options.wait(ctx, given.wait) : given.wait === true;
269
+ const waiting = wait && options.jobs !== undefined ? { jobs: options.jobs, wait: startWait(options.jobs) } : undefined;
270
+ let statuses;
271
+ try {
272
+ statuses =
273
+ given.from_scratch !== undefined
274
+ ? await loop.fromScratch(plainFile, { ...request, chain: given.from_scratch === "chain" })
275
+ : again.length > 0
276
+ ? await loop.regenerateAgain(plainFile, again, request)
277
+ : await loop.bringUp(plainFile, request);
278
+ }
279
+ catch (error) {
280
+ if (waiting !== undefined)
281
+ endWait(waiting.jobs, waiting.wait);
282
+ throw error;
283
+ }
284
+ return loopReply(loop, statuses, wait, waiting);
225
285
  });
226
286
  },
227
287
  });
@@ -237,7 +297,7 @@ export function driftTool(options) {
237
297
  "with nothing left, it says the module is fully regenerated. It plans nothing and starts nothing, and calls no model.",
238
298
  promptSnippet: "drift: what is left to regenerate in a module, code and conformance tests - starting nothing",
239
299
  promptGuidelines: [
240
- "Use drift when the user asks what is left to build, whether a module is up to date with its spec, or what changed since it was last regenerated. To see the next pulse's prompt as well, use glimpse.",
300
+ "Use drift when the user asks what is left to build, whether a module is up to date with its spec, or what changed since it was last regenerated. To see how it is planned into pulses, and the next pulse's prompt, use pulses with plain_file.",
241
301
  ],
242
302
  parameters: Type.Object({
243
303
  plain_file: Type.Optional(Type.String({ description: "Path to the .plain file. Omitted: the module the project's config.turri.yaml names" })),
@@ -15,8 +15,8 @@ export const NEW_PROJECT = [
15
15
  " chosen again.",
16
16
  "4. The unit testing script: keep one turri already finds; otherwise start cultivate with implement-unit-testing-script,",
17
17
  " plainFile the new module. It runs in the background: go straight on - the module's pulses wait for the script.",
18
- " Tests only if the person asked for them: turn conformance tests on first (turn_on_conformance_tests), then in this",
19
- " order: the ***test reqs*** - the stack's conformance template - then cultivate with",
18
+ " Tests only once conformance tests are on: they make each change take about twice as long, so the person turns them",
19
+ " on - asked for tests, tell them /conform does - then in this order: the ***test reqs*** - the stack's conformance template - then cultivate with",
20
20
  " implement-conformance-testing-script, in the background too, then the scenarios.",
21
21
  "5. The first functional spec: the smallest thing that runs and shows something - the server answers GET / with the",
22
22
  " app's name, the CLI prints its usage - with no test plain file, unless they asked for tests. parse, fix",
package/dist/parse-cli.js CHANGED
@@ -5,8 +5,8 @@ const USAGE = `usage: turri parse <file.plain | directory> [options]
5
5
  Parses ***plain - its syntax and structure, never its code or tests: each module with its test plain files,
6
6
  its imports and required modules, every error reported without regenerating anything - and every test plain file
7
7
  outside its module's folder. A functional spec with no test plain file is not tested. A module whose
8
- functional specs have scenarios but which has no test reqs, or no conformance testing script for its
9
- stack, is a warning: its conformance tests are not written until it has them. A test plain file or
8
+ functional specs have scenarios but which has no test reqs, or no conformance testing script,
9
+ is a warning: its conformance tests are not written until it has them. A test plain file or
10
10
  test folder is refused: name its module.
11
11
 
12
12
  --template-dir <dir> extra template directory (repeatable)
package/dist/pi-launch.js CHANGED
@@ -14,6 +14,7 @@ import "./terminal-images.js";
14
14
  import { withoutResumeLine } from "./resume-line.js";
15
15
  import { lastRun } from "./chat-records.js";
16
16
  import { driveTerminal } from "./chat-terminal.js";
17
+ import { takeOverSettings } from "./pi-settings.js";
17
18
  import turri, { createTurriCore, processSession } from "./extension.js";
18
19
  /**
19
20
  * pi, started the way its own CLI starts it, for `turri`.
@@ -42,6 +43,8 @@ ProcessTerminal.prototype.setTitle = function (title) {
42
43
  // is answered for this run as `quietStartup` is; the line it prints instead, to resume the session, is left out too:
43
44
  // `turri --continue` opens the last run again.
44
45
  SettingsManager.prototype.getFullscreenExitOutput = () => "resume-hint";
46
+ // /settings is turri's, pi's own menu the last entry of it (pi-settings.ts).
47
+ takeOverSettings();
45
48
  const write = process.stdout.write.bind(process.stdout);
46
49
  process.stdout.write = ((chunk, ...rest) => write(typeof chunk === "string" ? withoutResumeLine(chunk) : chunk, ...rest));
47
50
  // pi's own keys stand: a new line is shift+enter or ctrl+j. turri's side panel is on ctrl+h (job-panel.ts PANEL_KEY).
@@ -70,7 +73,7 @@ if (interactive) {
70
73
  args.splice(asked, 1);
71
74
  restore = saved;
72
75
  }
73
- driveTerminal(processSession(() => createTurriCore({}, { persist: true, advisor: true })),
76
+ driveTerminal(processSession(() => createTurriCore({}, { persist: true })),
74
77
  // With none of the person's chats saved - only the sentinel's - pi starts a fresh one, and every saved chat is opened beside it.
75
78
  restore !== undefined ? { restore, skipFirst: restore.chats.some((chat) => chat.role === undefined) } : {});
76
79
  }
@@ -0,0 +1,4 @@
1
+ /** Take pi's /settings over: once a process, every chat's screen. */
2
+ export declare function takeOverSettings(): void;
3
+ /** Open pi's own settings menu on the screen /settings was typed on. False where there is none - a host, print mode. */
4
+ export declare function openPiSettings(): boolean;
@@ -0,0 +1,39 @@
1
+ import { InteractiveMode } from "@earendil-works/pi-coding-agent";
2
+ let piMenu;
3
+ /** Take pi's /settings over: once a process, every chat's screen. */
4
+ export function takeOverSettings() {
5
+ if (piMenu !== undefined)
6
+ return;
7
+ const prototype = InteractiveMode.prototype;
8
+ const own = prototype.showSettingsSelector;
9
+ const conflicts = prototype.getBuiltInCommandConflictDiagnostics;
10
+ const completions = prototype.createBaseAutocompleteProvider;
11
+ const menu = { open: (screen) => own.call(screen) };
12
+ piMenu = menu;
13
+ // A bare /settings: turri's, when the extension has one - pi's menu otherwise, as it was.
14
+ prototype.showSettingsSelector = function () {
15
+ if (this.session.extensionRunner.getCommand("settings") === undefined)
16
+ return own.call(this);
17
+ menu.screen = this;
18
+ void this.session.prompt("/settings");
19
+ };
20
+ prototype.getBuiltInCommandConflictDiagnostics = function (runner) {
21
+ return conflicts.call(this, runner).filter((diagnostic) => !diagnostic.message.includes("'/settings'"));
22
+ };
23
+ // The completions: pi's /settings line gives way to turri's, which pi leaves out as a clash.
24
+ prototype.createBaseAutocompleteProvider = function () {
25
+ const provider = completions.call(this);
26
+ const turri = this.session.extensionRunner.getCommand("settings");
27
+ if (turri === undefined)
28
+ return provider;
29
+ provider.commands = provider.commands.map((command) => command.name === "settings" ? { name: "settings", description: turri.description, getArgumentCompletions: turri.getArgumentCompletions } : command);
30
+ return provider;
31
+ };
32
+ }
33
+ /** Open pi's own settings menu on the screen /settings was typed on. False where there is none - a host, print mode. */
34
+ export function openPiSettings() {
35
+ if (piMenu?.screen === undefined)
36
+ return false;
37
+ piMenu.open(piMenu.screen);
38
+ return true;
39
+ }
package/dist/pi.js CHANGED
@@ -3,12 +3,12 @@ import { fileURLToPath } from "node:url";
3
3
  import { createAgentSession, DefaultResourceLoader, getAgentDir, ModelRegistry, SessionManager, } from "@earendil-works/pi-coding-agent";
4
4
  import { installedProviders, runtimeWithProviders } from "./installed-providers.js";
5
5
  import { loadRules, renderRulesBlock } from "./rules.js";
6
- import { debugMode, inheritModel, stackOf, readProjectConfig, ROLE_THINKING, roleModel, roleTurnLimitMs, splitModelSpec } from "./config.js";
6
+ import { debugMode, inheritModel, configModuleOf, readProjectConfig, ROLE_THINKING, roleModel, roleTurnLimitMs, splitModelSpec } from "./config.js";
7
7
  import { maskToolResults } from "./regenerate/masking.js";
8
8
  import { withListArguments } from "./regenerate/list-arguments.js";
9
9
  import { checkAgainstScript, ENVIRONMENT_ERROR_TOOL, EnvironmentError, environmentErrorTool, sandboxGapOf } from "./regenerate/environment-error.js";
10
10
  import { MODULES_DIR, projectRootOf, sessionsDir } from "./regenerate/paths.js";
11
- import { currentStopSignal, describeToolCall, describeToolResult, JobStoppedError, shownName, reportActivity, reportNow, reportAgent, reportTranscript, reportModelEvent, reportUsage, } from "./regenerate/activity.js";
11
+ import { currentStopSignal, describeToolCall, describeToolResult, JobStoppedError, reportActivity, reportNow, reportAgent, reportTranscript, reportModelEvent, reportUsage, } from "./regenerate/activity.js";
12
12
  import { debugLogOf, startDebugLog } from "./regenerate/debug-log.js";
13
13
  import { firstLine, record } from "./regenerate/ledger.js";
14
14
  let thinkingSource;
@@ -317,6 +317,9 @@ async function askOnce(session, text, onDelta) {
317
317
  reportNow("thinking");
318
318
  }
319
319
  else if (update.type === "text_start") {
320
+ // Each message of the turn its own paragraph: the agent's words between tool calls never run into each other.
321
+ if (out !== "" && !/\s$/.test(out))
322
+ out += "\n\n";
320
323
  reportNow("writing");
321
324
  }
322
325
  else if (update.type === "toolcall_start") {
@@ -330,20 +333,20 @@ async function askOnce(session, text, onDelta) {
330
333
  lastCallReport = now;
331
334
  const block = update.partial.content[update.contentIndex];
332
335
  const size = callChars >= 1000 ? `${(callChars / 1000).toFixed(1)}k` : `${callChars}`;
333
- reportNow(`writing ${block?.name !== undefined ? shownName(block.name) : "a tool"} call · ${size} chars`, { keepSince: true });
336
+ reportNow(`writing ${block?.name ?? "a tool"} call · ${size} chars`, { keepSince: true });
334
337
  }
335
338
  }
336
339
  }
337
340
  if (event.type === "tool_execution_start") {
338
341
  toolStarted.set(event.toolCallId, Date.now());
339
342
  const args = JSON.stringify(event.args ?? {});
340
- transcript({ kind: "tool", text: `${shownName(event.toolName)} ${clipText(args, MAX_TOOL_ARGS)}`, full: `${shownName(event.toolName)} ${args}` });
343
+ transcript({ kind: "tool", text: `${event.toolName} ${clipText(args, MAX_TOOL_ARGS)}`, full: `${event.toolName} ${args}` });
341
344
  const took = Date.now() - stepStarted;
342
345
  // Which agent made the call, by its role: several work in one pulse.
343
346
  const role = agentRoles.get(session);
344
347
  const line = `${role !== undefined ? `(${role}) ` : ""}${describeToolCall(event.toolName, event.args)}`;
345
348
  reportActivity(took >= 1000 ? `${line} (model ${seconds(took)})` : line);
346
- reportNow(`running ${shownName(event.toolName)}`);
349
+ reportNow(`running ${event.toolName}`);
347
350
  }
348
351
  if (event.type === "tool_execution_end") {
349
352
  failing = event.isError ? (event.toolName === failingTool ? failing + 1 : 1) : 0;
@@ -352,9 +355,9 @@ async function askOnce(session, text, onDelta) {
352
355
  // A call its tool refuses never reaches the tool, so no guard on the tools sees it: an agent can
353
356
  // make the same bad call, worded a little differently, thousands of times. Its turn ends here, and
354
357
  // the harness goes on from there, as after any turn.
355
- reportActivity(` stopped the agent's turn: ${failing} ${shownName(event.toolName)} calls failed in a row`);
358
+ reportActivity(` stopped the agent's turn: ${failing} ${event.toolName} calls failed in a row`);
356
359
  debugLogOf(session)?.note(`turn stopped: ${failing} ${event.toolName} calls failed in a row`);
357
- stopTurn(session, `${failing} ${shownName(event.toolName)} calls failed in a row`);
360
+ stopTurn(session, `${failing} ${event.toolName} calls failed in a row`);
358
361
  }
359
362
  const output = resultText(event.result);
360
363
  const started = toolStarted.get(event.toolCallId);
@@ -800,11 +803,11 @@ export async function createExecutor(opts) {
800
803
  }
801
804
  return session;
802
805
  }
803
- /** The config an agent working in `cwd` is under: the project's, with the chosen stack's over it. */
806
+ /** The config an agent working in `cwd` is under: the project's, with the pulse's module's own file over it. */
804
807
  function configForCwd(cwd) {
805
808
  try {
806
809
  const root = projectRootOf(cwd);
807
- return readProjectConfig(root, stackOf(root));
810
+ return readProjectConfig(root, configModuleOf(root));
808
811
  }
809
812
  catch {
810
813
  return {};
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Static validation of ***plain, using this repo's own parser - `turri parse`, the chat's `parse`, and the check
3
- * `change_plain` and `turri change-plain` run on what a change touched.
3
+ * `regenerate` runs on the module it is given.
4
4
  *
5
5
  * It parses each module with its test plain files, resolves its imports and required modules, and reports every error
6
6
  * the parser can see without generating anything. The parser's errors come one at a time, the first it meets, as the
7
7
  * reference gives them. turri's own checks list everything they find at once: every functional spec without a test
8
8
  * plain file, and every test plain file that is not where it belongs. A module whose functional specs have scenarios
9
- * but which has no test reqs, or no conformance testing script for its stack, passes with a warning.
9
+ * but which has no test reqs, or no conformance testing script, passes with a warning.
10
10
  */
11
11
  export interface CheckedFunctionalSpec {
12
12
  funcId: string;
@@ -55,13 +55,6 @@ export declare function resolvePlainTargets(target: string): string[];
55
55
  * project's test folder, once, at the end.
56
56
  */
57
57
  export declare function checkPlainTargets(target: string, templateDirs?: string[]): CheckResult[];
58
- /**
59
- * The check of what a ***plain change touched, shared by `change_plain` and `turri change-plain`: each module it
60
- * touched, an import module as the modules that import it read it, and each test plain file as its module - by its
61
- * folder - is parsed with its test plain files; a test plain file the change put where it does not belong is refused
62
- * as `parse` refuses it. A file the change deleted is checked through the module it belonged to.
63
- */
64
- export declare function checkTouchedPlain(paths: string[]): CheckResult[];
65
58
  /**
66
59
  * One line per file, plus the parser's message under any that failed and turri's next step, or every problem turri
67
60
  * found; a module that passed, its functional specs under it, each with its test plain file and its scenarios - and
@@ -1,13 +1,13 @@
1
1
  import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
2
  import { basename, extname, join, relative, resolve, sep } from "node:path";
3
- import { testDirOf } from "../config.js";
3
+ import { configModuleFor, testDirOf } from "../config.js";
4
4
  import { projectDirOf, resolveTemplateDirs } from "../regenerate/paths.js";
5
- import { importingModules, isImportModule } from "../regenerate/requires.js";
5
+ import { isImportModule } from "../regenerate/requires.js";
6
6
  import { testingGap } from "../regenerate/testing-steps.js";
7
7
  import { missingBaseFolder } from "../regenerate/base-folder.js";
8
8
  import { conformanceTestsOn } from "../conformance-switch.js";
9
9
  import { testedFuncIds } from "../regenerate/records.js";
10
- import { moduleOfTestPlainFile, projectModules, strayTestPlainFiles, testPlaceOf, testPlainFileRefusal } from "../test-plain-files.js";
10
+ import { projectModules, strayTestPlainFiles, testPlainFileRefusal } from "../test-plain-files.js";
11
11
  import { plainFileParser, PLAIN_SOURCE_FILE_EXTENSION, PREVIOUS_SYNTAX_HINT, readPlainSourceMetadata, REQUIRES_DIRECTIVE } from "./parser.js";
12
12
  import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, getFunctionalSpecs, TEST_PLAIN_FILES, } from "./spec.js";
13
13
  /** Whether a parser error is one the previous ***plain syntax makes. */
@@ -67,7 +67,7 @@ function testingGapsOf(moduleName, path, tree, projectDir, templateDirs) {
67
67
  if (!conformanceTestsOn(path)) {
68
68
  const tested = testedFuncIds(tree);
69
69
  return tested.length > 0
70
- ? [`its scenarios are not tested - ${tested.map((funcId) => `${moduleName}:${funcId}`).join(", ")}: conformance tests are off (conformance-tests: false, or unset). Asking for them in the chat turns them on, or conformance-tests: true in config.turri.yaml.`]
70
+ ? [`its scenarios are not tested - ${tested.map((funcId) => `${moduleName}:${funcId}`).join(", ")}: conformance tests are off (conformance-tests: false, or unset). /conform in the chat turns them on, or conformance-tests: true in config.turri.yaml.`]
71
71
  : [];
72
72
  }
73
73
  const tips = tipsAbove(moduleName, projectDir);
@@ -114,6 +114,8 @@ export function checkPlainFile(file, templateDirs = []) {
114
114
  testDir,
115
115
  requireTestPlainFiles: false,
116
116
  });
117
+ // Two config files among the modules it requires: which one builds it cannot be told - an error, as a syntax one is.
118
+ configModuleFor(path);
117
119
  // Scenarios with a step of adding tests skipped - the test reqs, or the conformance testing script: a warning, never a failure.
118
120
  const gaps = testingGapsOf(moduleName, path, tree, projectDir, templateDirs);
119
121
  // A codebase that requires nothing starts from its base folder: one named and not there stops its first pulse.
@@ -192,41 +194,6 @@ export function checkPlainTargets(target, templateDirs = []) {
192
194
  }
193
195
  return results;
194
196
  }
195
- /**
196
- * The check of what a ***plain change touched, shared by `change_plain` and `turri change-plain`: each module it
197
- * touched, an import module as the modules that import it read it, and each test plain file as its module - by its
198
- * folder - is parsed with its test plain files; a test plain file the change put where it does not belong is refused
199
- * as `parse` refuses it. A file the change deleted is checked through the module it belonged to.
200
- */
201
- export function checkTouchedPlain(paths) {
202
- const modules = new Set();
203
- const results = [];
204
- for (const given of paths) {
205
- const path = resolve(given);
206
- const place = testPlaceOf(path);
207
- if (place !== undefined && !place.directory) {
208
- const stray = strayTestPlainFiles(place.projectDir).find((found) => resolve(place.projectDir, found.file) === path);
209
- if (stray !== undefined) {
210
- results.push({ file: path, ok: false, errorType: "a test plain file outside its module's folder", problems: [`${stray.file} - ${stray.problem}`] });
211
- continue;
212
- }
213
- const owner = moduleOfTestPlainFile(path);
214
- if (owner?.plainFile !== undefined)
215
- modules.add(owner.plainFile);
216
- else if (owner !== undefined)
217
- results.push({ file: path, ok: false, errorType: "a test plain file outside a module's folder", problems: [`${shown(path, place.projectDir)} - no module ${owner.module}`] });
218
- continue;
219
- }
220
- if (!existsSync(path))
221
- continue;
222
- const importing = isImportModule(path) ? importingModules(path) : [];
223
- for (const module of importing.length > 0 ? importing : [path])
224
- modules.add(resolve(module));
225
- }
226
- for (const module of modules)
227
- results.push(checkPlainFile(module));
228
- return results;
229
- }
230
197
  /** Columns padded to their widest cell, each line indented under the module's. */
231
198
  function columns(rows) {
232
199
  const widths = rows.reduce((acc, row) => row.map((cell, index) => Math.max(acc[index] ?? 0, cell.length)), []);
@@ -2,14 +2,14 @@ import { createHash } from "node:crypto";
2
2
  import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";
4
4
  import { createEditToolDefinition, createWriteToolDefinition } from "@earendil-works/pi-coding-agent";
5
- import { readProjectConfig, stacksOf } from "./config.js";
5
+ import { readProjectConfig, moduleConfigsOf } from "./config.js";
6
6
  import { parseMarkdown } from "./plain/markdown.js";
7
7
  import { hasScheme, linksIn } from "./plain/parser.js";
8
8
  import { insideAny } from "./regenerate/confine.js";
9
9
  import { credentialRefusal, isCredentialFile } from "./regenerate/credentials.js";
10
10
  import { DIST_DIR, MODULES_DIR } from "./regenerate/paths.js";
11
11
  import { PREPARE_NAME, SCRIPTS_DIR, scriptKind } from "./regenerate/test-scripts.js";
12
- /** A config.turri.yaml, a stack's config.turri.<stack>.yaml - what the project's testing scripts are named in. */
12
+ /** A config.turri.yaml, a module's own config.turri.<module>.yaml - what the project's testing scripts are named in. */
13
13
  const TURRI_CONFIG_NAME = /^config\.turri(\.[^/]+)?\.yaml$/;
14
14
  /** Folders that hold what is built, installed or turri's own - never the project's ***plain. */
15
15
  function outsidePlain(path) {
@@ -69,8 +69,8 @@ export function projectFiles(root, also = []) {
69
69
  }
70
70
  }
71
71
  // Scripts config.turri*.yaml names, whatever they are called.
72
- for (const stack of [undefined, ...stacksOf(root)]) {
73
- const config = readProjectConfig(root, stack);
72
+ for (const module of [undefined, ...moduleConfigsOf(root)]) {
73
+ const config = readProjectConfig(root, module);
74
74
  named(config.unittestsScript);
75
75
  named(config.conformanceTestsScript);
76
76
  named(config.prepareEnvironmentScript);
@@ -205,11 +205,6 @@ export declare function onModelEvent(listener: (event: ModelEvent) => void): ()
205
205
  export declare function describeTurnIncident(event: ModelEvent): string | undefined;
206
206
  export declare function reportModelEvent(event: Omit<ModelEvent, "job">): void;
207
207
  export declare function withActivity<T>(sink: ActivitySink, run: () => Promise<T>): Promise<T>;
208
- /**
209
- * Run work for no job, whatever job the code that starts it runs for - and clear of any stop signal: the test
210
- * advisor's, started as the loop looks at a codebase, perhaps as a pulse ends. A pulse's panel, log and stop never reach it.
211
- */
212
- export declare function outsideJobs<T>(run: () => T): T;
213
208
  export declare function reportStage(label: string): void;
214
209
  export declare function reportActivity(line: string): void;
215
210
  /** Say something about the machinery under the work: shown as activity, and kept in the job's log, which the activity is not. */
@@ -226,8 +221,6 @@ export declare function reportNow(label: string | undefined, options?: {
226
221
  * the end of it.
227
222
  */
228
223
  export declare function withinModules(text: string): string;
229
- /** A tool's name as the person is shown it. */
230
- export declare function shownName(name: string): string;
231
224
  /** A tool call as one short line. Unknown tools still show up, by name. */
232
225
  export declare function describeToolCall(name: string, args: Record<string, unknown> | undefined): string;
233
226
  /** The outcome of a test run, or nothing for tools whose outcome is not worth a line. */