@turri-dev/cli 0.2.4-next.240620d → 0.2.4-next.359b847

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 (134) hide show
  1. package/README.md +6 -7
  2. package/dist/bedrock-region.js +3 -3
  3. package/dist/chat-models.d.ts +1 -1
  4. package/dist/chat-models.js +1 -1
  5. package/dist/chat-scope.d.ts +1 -3
  6. package/dist/chat-skills.d.ts +1 -1
  7. package/dist/chat-skills.js +1 -1
  8. package/dist/chats.d.ts +44 -10
  9. package/dist/chats.js +125 -41
  10. package/dist/cli.js +10 -26
  11. package/dist/config-edit.d.ts +20 -8
  12. package/dist/config-edit.js +32 -24
  13. package/dist/config.d.ts +101 -58
  14. package/dist/config.js +265 -118
  15. package/dist/conform-cli.js +14 -3
  16. package/dist/conformance-switch.d.ts +7 -6
  17. package/dist/conformance-switch.js +19 -16
  18. package/dist/extension.d.ts +29 -3
  19. package/dist/extension.js +375 -351
  20. package/dist/genome.js +5 -1
  21. package/dist/host-session.d.ts +8 -7
  22. package/dist/host-session.js +4 -4
  23. package/dist/host.d.ts +3 -1
  24. package/dist/host.js +3 -3
  25. package/dist/identity.js +2 -2
  26. package/dist/init-config.d.ts +1 -1
  27. package/dist/init-config.js +8 -8
  28. package/dist/launch-agent.d.ts +51 -0
  29. package/dist/launch-agent.js +267 -0
  30. package/dist/{release-cli.js → launch-cli.js} +41 -24
  31. package/dist/launch-session.d.ts +68 -0
  32. package/dist/launch-session.js +217 -0
  33. package/dist/launch-tools.d.ts +28 -0
  34. package/dist/launch-tools.js +69 -0
  35. package/dist/launch-track.d.ts +125 -0
  36. package/dist/launch-track.js +320 -0
  37. package/dist/loop-cli.js +4 -4
  38. package/dist/loop-tools.d.ts +45 -21
  39. package/dist/loop-tools.js +152 -82
  40. package/dist/notice.d.ts +7 -6
  41. package/dist/parse-cli.js +2 -2
  42. package/dist/pi-launch.js +3 -0
  43. package/dist/pi-settings.d.ts +4 -0
  44. package/dist/pi-settings.js +39 -0
  45. package/dist/pi.js +6 -3
  46. package/dist/plain/check.d.ts +1 -1
  47. package/dist/plain/check.js +3 -1
  48. package/dist/plain-files.d.ts +2 -2
  49. package/dist/plain-files.js +7 -7
  50. package/dist/regenerate/agent-env.d.ts +1 -1
  51. package/dist/regenerate/agent-env.js +3 -3
  52. package/dist/regenerate/agent-shell.js +5 -3
  53. package/dist/regenerate/audit.js +9 -0
  54. package/dist/regenerate/base-folder.d.ts +2 -2
  55. package/dist/regenerate/base-folder.js +1 -1
  56. package/dist/regenerate/cases.js +7 -0
  57. package/dist/regenerate/chunk-plan.d.ts +5 -0
  58. package/dist/regenerate/chunk-plan.js +16 -1
  59. package/dist/regenerate/command-check.d.ts +7 -1
  60. package/dist/regenerate/command-check.js +43 -1
  61. package/dist/regenerate/delivery.d.ts +1 -1
  62. package/dist/regenerate/delivery.js +3 -3
  63. package/dist/regenerate/drift.d.ts +4 -0
  64. package/dist/regenerate/drift.js +26 -6
  65. package/dist/regenerate/job-panel.js +3 -1
  66. package/dist/regenerate/jobs.d.ts +2 -2
  67. package/dist/regenerate/jobs.js +10 -10
  68. package/dist/regenerate/launch.d.ts +154 -0
  69. package/dist/regenerate/{release.js → launch.js} +195 -51
  70. package/dist/regenerate/ledger.d.ts +33 -2
  71. package/dist/regenerate/lineage.d.ts +2 -0
  72. package/dist/regenerate/lineage.js +8 -0
  73. package/dist/regenerate/loop.d.ts +30 -10
  74. package/dist/regenerate/loop.js +166 -59
  75. package/dist/regenerate/model-names.d.ts +33 -0
  76. package/dist/regenerate/{engine.js → model-names.js} +2 -28
  77. package/dist/regenerate/paths.d.ts +3 -3
  78. package/dist/regenerate/paths.js +4 -4
  79. package/dist/regenerate/records.d.ts +11 -0
  80. package/dist/regenerate/records.js +15 -0
  81. package/dist/regenerate/regenerate.js +4 -1
  82. package/dist/regenerate/renames.js +4 -4
  83. package/dist/regenerate/requires.d.ts +7 -0
  84. package/dist/regenerate/requires.js +24 -18
  85. package/dist/regenerate/scripts-being-written.d.ts +4 -4
  86. package/dist/regenerate/scripts-being-written.js +3 -3
  87. package/dist/regenerate/spec-map.js +3 -3
  88. package/dist/regenerate/submit-work.d.ts +2 -0
  89. package/dist/regenerate/submit-work.js +8 -3
  90. package/dist/regenerate/test-scripts.d.ts +2 -1
  91. package/dist/regenerate/test-scripts.js +33 -23
  92. package/dist/regenerate/testing-steps.d.ts +6 -6
  93. package/dist/regenerate/testing-steps.js +8 -8
  94. package/dist/regenerate-cli.js +1 -1
  95. package/dist/self-invocation.d.ts +11 -0
  96. package/dist/self-invocation.js +36 -7
  97. package/dist/sentinel-check.d.ts +3 -3
  98. package/dist/sentinel-check.js +3 -3
  99. package/dist/sentinel.d.ts +18 -12
  100. package/dist/sentinel.js +72 -43
  101. package/dist/{config-command.d.ts → settings.d.ts} +13 -8
  102. package/dist/{config-command.js → settings.js} +155 -24
  103. package/dist/setup.d.ts +2 -2
  104. package/dist/setup.js +7 -7
  105. package/dist/turri-versions.js +2 -1
  106. package/docs/README.md +4 -4
  107. package/docs/chats.md +5 -6
  108. package/docs/claude-subscription.md +2 -2
  109. package/docs/config.md +58 -46
  110. package/docs/development.md +2 -2
  111. package/docs/headless.md +4 -4
  112. package/docs/hosting.md +20 -19
  113. package/docs/launch.md +67 -0
  114. package/docs/parser.md +2 -2
  115. package/docs/regenerating.md +21 -15
  116. package/docs/sandbox.md +3 -3
  117. package/docs/sentinel.md +26 -14
  118. package/docs/skills-and-gates.md +4 -4
  119. package/docs/using.md +19 -28
  120. package/genome/rules/project-model.md +2 -1
  121. package/genome/rules/turri-regeneration.md +5 -3
  122. package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
  123. package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
  124. package/package.json +1 -1
  125. package/dist/regenerate/engine.d.ts +0 -52
  126. package/dist/regenerate/release.d.ts +0 -121
  127. package/dist/release-agent.d.ts +0 -43
  128. package/dist/release-agent.js +0 -130
  129. package/dist/release-tools.d.ts +0 -44
  130. package/dist/release-tools.js +0 -170
  131. package/dist/stacks.d.ts +0 -13
  132. package/dist/stacks.js +0 -96
  133. package/docs/deploy.md +0 -48
  134. /package/dist/{release-cli.d.ts → launch-cli.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { dirname, join, resolve, sep } from "node:path";
2
- import { readProjectConfig, stackOf } from "../config.js";
2
+ import { readProjectConfig, configModuleOf } from "../config.js";
3
3
  import { reportNote } from "./activity.js";
4
4
  import { record } from "./ledger.js";
5
5
  import { agentEnvironment, DARWIN_TEMP_SUFFIX, packageCacheDir, TOOLCHAIN_VARIABLES } from "./agent-env.js";
@@ -32,7 +32,7 @@ export function agentShell(role, options = {}) {
32
32
  const project = projectRootOf(workdir);
33
33
  const { env } = agentEnvironment(moduleDir);
34
34
  const root = projectRootOf(moduleDir);
35
- const toolchains = readProjectConfig(root, stackOf(root)).toolchains ?? [];
35
+ const toolchains = readProjectConfig(root, configModuleOf(root)).toolchains ?? [];
36
36
  const machine = machineFor(env, TOOLCHAIN_VARIABLES, toolchains);
37
37
  const writable = writableFor(env, moduleDir);
38
38
  const commandFence = {
@@ -95,7 +95,9 @@ export function agentShell(role, options = {}) {
95
95
  const checked = checkCommand(command, commandFence);
96
96
  if (!checked.ok) {
97
97
  record({ kind: "command.refused", rule: checked.rule });
98
- reportNote(` refused an agent's command (${checked.rule}): ${command.length > 120 ? `${command.slice(0, 120)}...` : command}`);
98
+ // On one line: a note is a line of the job panel, and a command's newlines would break the screen around it.
99
+ const shown = command.replace(/\s+/g, " ").trim();
100
+ reportNote(` refused an agent's command (${checked.rule}): ${shown.length > 120 ? `${shown.slice(0, 120)}...` : shown}`);
99
101
  const output = `Not run: ${checked.reason}`;
100
102
  runOptions.onData?.(Buffer.from(output));
101
103
  return { exitCode: 126, output };
@@ -9,6 +9,8 @@ const SKIPPED = new Set([
9
9
  "node_modules", ".venv", "venv", "__pycache__", ".pytest_cache", ".mypy_cache", ".ruff_cache", ".tox", "target", "build",
10
10
  "dist", ".gradle", ".m2", ".cargo", ".next", "coverage", ".git", ".turri", ".plaingit", ".idea", ".vscode",
11
11
  ]);
12
+ /** How close to the command's start a file's time must be for its time and size alone not to be trusted. */
13
+ const RACY_MS = 1_000;
12
14
  /** A file kept whole before the command - at most this big. */
13
15
  const MAX_KEPT = 1024 * 1024;
14
16
  function stat(path) {
@@ -156,6 +158,13 @@ export function afterCommand(snapshot) {
156
158
  continue;
157
159
  changed.push(path);
158
160
  }
161
+ else if (seen.mtimeMs >= snapshot.at - RACY_MS) {
162
+ // Its time and size as before, but written around when the command started: rewritten to the same size within
163
+ // the same tick of the file system's clock would look the same. What it held before tells - where it was kept.
164
+ const kept = tree.kept?.get(path);
165
+ if (kept !== undefined && !readFileSync(path).equals(kept))
166
+ changed.push(path);
167
+ }
159
168
  }
160
169
  for (const path of tree.files.keys())
161
170
  if (!after.has(path))
@@ -1,7 +1,7 @@
1
1
  import { BASE_RECORD_FILE } from "./paths.ts";
2
2
  export { BASE_RECORD_FILE };
3
3
  /**
4
- * A base folder (`base-folder:` in config.turri.yaml, a stack's own in its file): what a codebase that requires no other
4
+ * A base folder (`base-folder:` in config.turri.yaml, a module's own in its file): what a codebase that requires no other
5
5
  * module starts from instead of nothing - an existing codebase to build on, files to use (images, animations, fonts), or
6
6
  * both. It is copied in once, before the codebase's first pulse, and never written to; what was copied is recorded beside
7
7
  * the code record, and goes up the chain with the code, so every coding agent of the chain is told where its codebase
@@ -21,7 +21,7 @@ export declare class MissingBaseFolderError extends Error {
21
21
  readonly moduleName: string;
22
22
  constructor(moduleName: string, named: string, path: string);
23
23
  }
24
- /** The base folder a module's codebase starts from - its stack's over the project's - as named and as a path; none when the config names none. */
24
+ /** The base folder a module's codebase starts from - its own file's over the project's - as named and as a path; none when the config names none. */
25
25
  export declare function baseFolderOf(plainFile: string): {
26
26
  named: string;
27
27
  path: string;
@@ -21,7 +21,7 @@ export class MissingBaseFolderError extends Error {
21
21
  this.moduleName = moduleName;
22
22
  }
23
23
  }
24
- /** The base folder a module's codebase starts from - its stack's over the project's - as named and as a path; none when the config names none. */
24
+ /** The base folder a module's codebase starts from - its own file's over the project's - as named and as a path; none when the config names none. */
25
25
  export function baseFolderOf(plainFile) {
26
26
  const named = configForSpec(plainFile).baseFolder;
27
27
  if (named === undefined)
@@ -80,6 +80,8 @@ function scenarioCasesLines(specs, module) {
80
80
  lines.push(` - added - write a test for each: ${labelled(spec, spec.added, module)}.`);
81
81
  if (spec.changed.length > 0)
82
82
  lines.push(` - changed - rewrite its tests to the scenario as it reads now: ${labelled(spec, spec.changed, module)}.`);
83
+ if (spec.rewritten.length > 0)
84
+ lines.push(` - written anew - delete every test labelled with it, then write its tests again from the scenario: ${labelled(spec, spec.rewritten, module)}.`);
83
85
  if (spec.removed.length > 0)
84
86
  lines.push(` - removed - delete every test labelled with it, and its label, and nothing else: ${labelled(spec, spec.removed, module)}.`);
85
87
  if (spec.unchanged.length > 0) {
@@ -91,6 +93,9 @@ function scenarioCasesLines(specs, module) {
91
93
  if (specs.some((spec) => spec.codeChanged !== undefined)) {
92
94
  lines.push("- Where the code changed under unchanged scenarios: their tests were written against the code it replaced. Run them", " against the new code. Those that pass are tests of the new code too - conformance tests are black box - and are", " not rewritten. Fix what fails against its scenario, read with the functional spec's text: what a failing test checks", " that the scenario says stays checked, the test changed only as the new code needs it reached; what it checks that", " the scenario and the specification leave open - a path, a field, a message, a format the old code chose - is the", " new code's choice now: rewrite that check to what the new code does, or take it out. No test may hold the new code", " to what only the old code did.");
93
95
  }
96
+ if (specs.some((spec) => spec.rewritten.length > 0)) {
97
+ lines.push("- Written anew: the person asked for these tests to be written again from scratch - their code did not change.", " Delete every test labelled with the scenario first, and what only those tests used, then write the scenario's", " tests from the scenario and the functional spec's text - never from the old tests, and never copying them back.", " A test that comes out as it was has not been written anew. Helpers the other tests use stay as they are.");
98
+ }
94
99
  lines.push("- The tests of every other functional spec stay as they are.");
95
100
  return lines;
96
101
  }
@@ -126,8 +131,10 @@ export function conformanceReviewCasesBlock(cases, module = "") {
126
131
  const kept = all((spec) => (spec.codeChanged === undefined ? spec.unchanged : []));
127
132
  const rerun = all((spec) => (spec.codeChanged !== undefined ? spec.unchanged : []));
128
133
  const removed = all((spec) => spec.removed);
134
+ const rewritten = all((spec) => spec.rewritten);
129
135
  return [
130
136
  "What this job does to the tests, scenario by scenario - hold it to that:",
137
+ ...(rewritten !== "" ? [`- Written anew, as the person asked - their old tests deleted and written again from the scenario, none left as it was: ${rewritten}.`] : []),
131
138
  ...(kept !== "" ? [`- Unchanged - their tests come out exactly as they were, not rewritten or reworded: ${kept}.`] : []),
132
139
  ...(rerun !== "" ? [`- Unchanged, the code changed under them - a test changed only where it failed on the new code, and only to what its scenario says: ${rerun}.`] : []),
133
140
  ...(removed !== "" ? [`- Removed - no test labelled with them is left: ${removed}.`] : []),
@@ -209,6 +209,11 @@ export declare function placeProblems(input: PlaceInput, answer: PlaceAnswer): s
209
209
  * spec it changes - else of its first change - and how many more it makes. Never the bare word.
210
210
  */
211
211
  export declare function editTitle(changes: SpecChange[]): string;
212
+ /**
213
+ * The title of the pulse that changes what is built, first: what it changes, by name - the functional specs' func-ids,
214
+ * else the kinds of item - so the person reads which, not "changes to what is built".
215
+ */
216
+ export declare function builtTitle(changes: SpecChange[]): string;
212
217
  export declare function planChunks(input: PlanInput, agents?: ChunkAgents, notes?: string[]): Promise<DraftJob[]>;
213
218
  export declare function groupPrompt(specs: NewSpec[], steering?: Steering[], maxSpecs?: number, built?: BuiltChange[]): string;
214
219
  export declare function placePrompt(input: PlaceInput): string;
@@ -358,6 +358,21 @@ export function editTitle(changes) {
358
358
  const more = `, and ${rest.length} more`;
359
359
  return `${shortTitle(line, TITLE_CHARS - more.length, TITLE_WORDS - 3).replace(/[.,;:]+$/, "")}${more}`;
360
360
  }
361
+ /**
362
+ * The title of the pulse that changes what is built, first: what it changes, by name - the functional specs' func-ids,
363
+ * else the kinds of item - so the person reads which, not "changes to what is built".
364
+ */
365
+ export function builtTitle(changes) {
366
+ const ids = [...new Set(changes.filter(isFunctionalSpec).map(funcIdOf).filter((id) => id !== undefined))];
367
+ if (ids.length > 0) {
368
+ const named = ids.slice(0, 2).join(", ");
369
+ const others = changes.length - changes.filter(isFunctionalSpec).length;
370
+ const more = ids.length - 2 + others;
371
+ return `Changes to ${named}${more > 0 ? `, and ${more} more` : ""}`;
372
+ }
373
+ const kinds = [...new Set(changes.map((change) => WHAT[change.section] ?? change.section))].map((kind) => `${kind}s`);
374
+ return `Changes to the ${kinds.length > 1 ? `${kinds.slice(0, -1).join(", ")} and ${kinds.at(-1)}` : kinds[0]}`;
375
+ }
361
376
  /** A change as the title agent is shown it: what it is, how it changes, its text now - and before, for a change. */
362
377
  function titleChangeOf(change) {
363
378
  return {
@@ -553,7 +568,7 @@ async function cut(input, agents, notes) {
553
568
  const bySpec = new Map(specs.map((change, index) => [index + 1, change]));
554
569
  const firstBuilt = () => builtChanges.filter((change) => (builtTo.get(change) ?? "first") === "first");
555
570
  const chunksFor = (list) => [
556
- ...(firstBuilt().length > 0 ? [{ title: "Changes to what is built", specs: [], definitions: [], reqs: [], built: firstBuilt() }] : []),
571
+ ...(firstBuilt().length > 0 ? [{ title: builtTitle(firstBuilt()), specs: [], definitions: [], reqs: [], built: firstBuilt() }] : []),
557
572
  ...list.map((group) => ({
558
573
  title: group.title,
559
574
  specs: group.specs.map((number) => bySpec.get(number)),
@@ -40,11 +40,17 @@ export declare function machineReadable(platform?: NodeJS.Platform): string[];
40
40
  * Why a command line changes the machine - installs software outside the project, or changes a setting of the
41
41
  * machine's or the person's environment - or nothing when it does not. The project's own dependencies, installed into
42
42
  * the project (npm install, a venv, mvn, cargo), change nothing of the machine's. turri changes the machine nowhere: not
43
- * an agent, not the chat, not a release - what the machine lacks is the person's to install, in their own words.
43
+ * an agent, not the chat, not a launch - what the machine lacks is the person's to install, in their own words.
44
44
  */
45
45
  export declare function machineChange(command: string): string | undefined;
46
46
  /** The .plain file a command line writes - a ***plain module or a test plain file - or nothing when it writes none. */
47
47
  export declare function writesPlain(command: string): string | undefined;
48
+ /**
49
+ * The path in plain_modules a command line runs in or from - `cd` there and run something, a program or its arguments
50
+ * there, an environment variable pointing there - or nothing when it only reads there, or does not go there. The code in
51
+ * plain_modules is what a pulse may be writing, and nobody launched it.
52
+ */
53
+ export declare function runsBuiltCode(command: string): string | undefined;
48
54
  /** What turri says when a command would change the machine: what it does instead. */
49
55
  export declare function machineChangeReason(why: string): string;
50
56
  /** Check one command line against a role's fence: `{ ok: true }`, or which rule it breaks and what to do instead. */
@@ -166,7 +166,7 @@ function systemSettingIn(segment) {
166
166
  * Why a command line changes the machine - installs software outside the project, or changes a setting of the
167
167
  * machine's or the person's environment - or nothing when it does not. The project's own dependencies, installed into
168
168
  * the project (npm install, a venv, mvn, cargo), change nothing of the machine's. turri changes the machine nowhere: not
169
- * an agent, not the chat, not a release - what the machine lacks is the person's to install, in their own words.
169
+ * an agent, not the chat, not a launch - what the machine lacks is the person's to install, in their own words.
170
170
  */
171
171
  export function machineChange(command) {
172
172
  if (PIPED_DOWNLOAD.test(command) || RUN_DOWNLOAD.test(command))
@@ -192,6 +192,48 @@ export function writesPlain(command) {
192
192
  }
193
193
  return undefined;
194
194
  }
195
+ /** Programs that only read what they are pointed at: run on built code, they start nothing of it. */
196
+ const READERS = new Set(["ls", "cat", "head", "tail", "less", "more", "grep", "rg", "find", "git", "wc", "diff", "tree", "file", "stat", "du", "jq", "echo", "pwd", "true", "test", "["]);
197
+ /**
198
+ * The path in plain_modules a command line runs in or from - `cd` there and run something, a program or its arguments
199
+ * there, an environment variable pointing there - or nothing when it only reads there, or does not go there. The code in
200
+ * plain_modules is what a pulse may be writing, and nobody launched it.
201
+ */
202
+ export function runsBuiltCode(command) {
203
+ let inBuilt;
204
+ for (const part of command.split(/&&|\|\||[;|\n]/)) {
205
+ const words = part.trim().split(/\s+/).filter((word) => word !== "").map((word) => word.replace(/^["']|["']$/g, ""));
206
+ let at = 0;
207
+ while (at < words.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[at])) {
208
+ if (words[at].includes("plain_modules"))
209
+ return words[at].slice(words[at].indexOf("=") + 1);
210
+ at += 1;
211
+ }
212
+ const program = words[at];
213
+ if (program === undefined)
214
+ continue;
215
+ const args = words.slice(at + 1);
216
+ if (program === "cd" || program === "pushd") {
217
+ const to = args[0];
218
+ if (to !== undefined && to.includes("plain_modules"))
219
+ inBuilt = to;
220
+ else if (to !== undefined)
221
+ inBuilt = undefined;
222
+ continue;
223
+ }
224
+ const name = program.split("/").pop();
225
+ if (program.includes("plain_modules"))
226
+ return program;
227
+ if (READERS.has(name))
228
+ continue;
229
+ const there = args.find((arg) => arg.includes("plain_modules"));
230
+ if (there !== undefined)
231
+ return there;
232
+ if (inBuilt !== undefined)
233
+ return inBuilt;
234
+ }
235
+ return undefined;
236
+ }
195
237
  /** What turri says when a command would change the machine: what it does instead. */
196
238
  export function machineChangeReason(why) {
197
239
  return (`turri changes nothing of this machine's - ${why}. Nothing is installed by turri, and no setting of the machine's or the ` +
@@ -1,2 +1,2 @@
1
- /** A command-line run has no one to ask: the command that releases what it built. */
1
+ /** A command-line run has no one to ask: the command that launches what it built. */
2
2
  export declare function tryItCommand(plainFile: string): string;
@@ -1,12 +1,12 @@
1
1
  import { relative } from "node:path";
2
2
  /**
3
- * How a command-line run that landed code ends: the command that releases it to try.
3
+ * How a command-line run that landed code ends: the command that launches it to try.
4
4
  */
5
5
  function shortPath(buildDir) {
6
6
  const fromHere = relative(process.cwd(), buildDir);
7
7
  return fromHere === "" || fromHere.startsWith("..") ? buildDir : fromHere;
8
8
  }
9
- /** A command-line run has no one to ask: the command that releases what it built. */
9
+ /** A command-line run has no one to ask: the command that launches what it built. */
10
10
  export function tryItCommand(plainFile) {
11
- return `To try it: turri release ${shortPath(plainFile)}`;
11
+ return `To try it: turri launch ${shortPath(plainFile)}`;
12
12
  }
@@ -74,12 +74,16 @@ export interface ScenarioRef {
74
74
  * - `codeChanged`: the functional spec's code moved under its unchanged scenarios - its text or a file it links changed
75
75
  * (`text`), it was regenerated again (`again`), or a concept it uses changed (`concept`): their tests are run on the
76
76
  * new code, and those that fail are fixed against the scenario.
77
+ * - rewritten: its tests are to be written anew - `conform` named it, or asked for its module from scratch: every one
78
+ * labelled with the scenario deleted and written again from it. A functional spec marked so has every scenario it has
79
+ * now rewritten, and those it no longer has removed.
77
80
  */
78
81
  export interface ScenarioCases extends TouchedSpec {
79
82
  added: ScenarioRef[];
80
83
  changed: ScenarioRef[];
81
84
  removed: ScenarioRef[];
82
85
  unchanged: ScenarioRef[];
86
+ rewritten: ScenarioRef[];
83
87
  codeChanged?: "text" | "again" | "concept";
84
88
  }
85
89
  /**
@@ -1,6 +1,6 @@
1
1
  import { DEFAULT_CONCEPTS, extractConceptsFromDefinition, extractConceptsFromSpecText } from "../plain/concepts.js";
2
2
  import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, DEFINITIONS, FUNCTIONAL_REQUIREMENTS, REQUIRED_FUNCTIONAL_SPECS } from "../plain/spec.js";
3
- import { codeTree, conformanceTarget, marksRegenerateAgain } from "./records.js";
3
+ import { codeTree, conformanceTarget, marksConformAgain, marksRegenerateAgain } from "./records.js";
4
4
  import { applyChanges, changesBetween, isMove, parseTree, resourcesChanged, serializeTree } from "./spec-steps.js";
5
5
  /**
6
6
  * The work, derived from the records - see docs/regenerating.md. Nothing here is stored: what is left
@@ -38,15 +38,26 @@ function scenariosIn(item) {
38
38
  function codeOf(item) {
39
39
  if (item === undefined)
40
40
  return "";
41
- const { [CONFORMANCE_TESTS]: _conformance, [ACCEPTANCE_TESTS]: _acceptance, regenerate_again: _again, ...rest } = item;
41
+ const { [CONFORMANCE_TESTS]: _conformance, [ACCEPTANCE_TESTS]: _acceptance, regenerate_again: _again, conform_again: _conform, ...rest } = item;
42
42
  return JSON.stringify({ ...rest, markdown: rest.markdown.trim() });
43
43
  }
44
- /** A functional spec's scenarios by case, from the item its tests were written for to the one they are to be. */
45
- function scenarioCasesOf(spec, was, is, code) {
44
+ /**
45
+ * A functional spec's scenarios by case, from the item its tests were written for to the one they are to be. `anew`: its
46
+ * tests are written again, every scenario it has now rewritten.
47
+ */
48
+ function scenarioCasesOf(spec, was, is, code, anew = false) {
46
49
  const before = scenariosIn(was);
47
50
  const after = scenariosIn(is);
48
51
  const plain = ({ kind, id, text }) => ({ kind, id, text });
49
- const cases = { ...spec, added: [], changed: [], removed: [], unchanged: [] };
52
+ const cases = { ...spec, added: [], changed: [], removed: [], unchanged: [], rewritten: [] };
53
+ if (anew) {
54
+ for (const scenario of after.values())
55
+ cases.rewritten.push(plain(scenario));
56
+ for (const [key, scenario] of before)
57
+ if (!after.has(key))
58
+ cases.removed.push(plain(scenario));
59
+ return cases;
60
+ }
50
61
  for (const [key, scenario] of after) {
51
62
  const old = before.get(key);
52
63
  if (old === undefined)
@@ -125,6 +136,8 @@ export function casesOf(before, changes, options = {}) {
125
136
  const patch = [];
126
137
  const again = [];
127
138
  const removed = [];
139
+ /** Of those regenerated again, the ones whose conformance tests are written anew: conform asked for them again. */
140
+ const anew = new Set();
128
141
  /** Each functional spec touched, as the tests record has it and as it is to be: its scenarios' cases are worked out from them. */
129
142
  const items = new Map();
130
143
  const keyOf = (spec) => `${spec.module ?? ""}:${spec.funcId}`;
@@ -139,6 +152,13 @@ export function casesOf(before, changes, options = {}) {
139
152
  const required = change.section === REQUIRED_FUNCTIONAL_SPECS;
140
153
  const was = itemOfLine(change.before);
141
154
  const is = itemOfLine(change.after);
155
+ // Its conformance tests marked to be written again: written anew, whatever else changed - its code untouched.
156
+ if (change.kind === "change" && is !== undefined && marksConformAgain(was)) {
157
+ const touched = seen(touchedOf(is, required), was, is);
158
+ again.push(touched);
159
+ anew.add(keyOf(touched));
160
+ continue;
161
+ }
142
162
  // Marked to regenerate again: regenerated again, whatever else changed in its text - its own or, required, another module's.
143
163
  if (change.kind === "change" && is !== undefined && marksRegenerateAgain(was)) {
144
164
  again.push(seen(touchedOf(is, required), was, is));
@@ -199,7 +219,7 @@ export function casesOf(before, changes, options = {}) {
199
219
  const { was, is } = items.get(keyOf(spec)) ?? {};
200
220
  return scenarioCasesOf(spec, was, is, was === is ? "concept" : undefined);
201
221
  }),
202
- ...again.map((spec) => scenarioCasesOf(spec, items.get(keyOf(spec))?.was, items.get(keyOf(spec))?.is, "again")),
222
+ ...again.map((spec) => scenarioCasesOf(spec, items.get(keyOf(spec))?.was, items.get(keyOf(spec))?.is, "again", anew.has(keyOf(spec)))),
203
223
  ...removed.map((spec) => scenarioCasesOf(spec, items.get(keyOf(spec))?.was, undefined)),
204
224
  ]
205
225
  : undefined;
@@ -227,7 +227,9 @@ export function jobPanelLines(jobs, options = {}) {
227
227
  const key = options.keys ?? ((_key, text) => text);
228
228
  lines.push(` ${key("trace", `ctrl+o to ${expanded ? "collapse" : "expand"} the trace`)} · ${key("peek", `${PANEL_KEY} to peek at regen`)}`);
229
229
  }
230
- return lines;
230
+ // A line is one row of the screen: a newline in one - an agent's words, a command - would draw past what the renderer
231
+ // tracks and stay on the screen, so each part is a row of its own.
232
+ return lines.flatMap((line) => line.split(/\r?\n/));
231
233
  }
232
234
  /**
233
235
  * The keys of the line, painted at `now`'s breath: one not pressed yet in the text's colour mixed toward the dim one, one
@@ -46,8 +46,8 @@ export interface Job {
46
46
  note?: string;
47
47
  /** "provider/model-id" its agents run on, when known. */
48
48
  model?: string;
49
- /** The stack it is built with - its config.turri.<stack>.yaml over config.turri.yaml - as chosen when it was queued. */
50
- stack?: string;
49
+ /** The module whose config.turri.<module>.yaml it is built with, over config.turri.yaml - as worked out when it was queued. */
50
+ configModule?: string;
51
51
  /** The chat it was asked for in (chat-scope.ts): the one told how it went. */
52
52
  chat?: string;
53
53
  status: JobStatus;
@@ -5,7 +5,7 @@ import { describeEnvironmentError, EnvironmentError, missingCredentials } from "
5
5
  import { addAgentReport, describeAgents, JobStoppedError, withActivity } from "./activity.js";
6
6
  import { projectOfLanes, startJobLog } from "./job-log.js";
7
7
  import { firstLine, healing, record } from "./ledger.js";
8
- import { chosenStack, debugMode, withStack } from "../config.js";
8
+ import { debugMode, moduleConfigFile, pinnedConfigModule, withConfigModule } from "../config.js";
9
9
  import { currentChat } from "../chat-scope.js";
10
10
  import { pulseEnded, pulseWrote } from "./pulse-files.js";
11
11
  import { keepFailureReport } from "./failure-reports.js";
@@ -58,9 +58,9 @@ export function createJobRegistry(options) {
58
58
  },
59
59
  start(input) {
60
60
  const id = randomUUID().slice(0, 8);
61
- // The stack chosen as it is queued - or pinned for the work that queues it - not as it starts: a job that waits
62
- // for a slot is built with the stack it was asked for, whatever is chosen meanwhile.
63
- const stack = chosenStack();
61
+ // The config pinned for the work that queues it, as it is queued - not as it starts: a job that waits for a slot is
62
+ // built with the config it was planned with, whatever the files say meanwhile.
63
+ const configModule = pinnedConfigModule();
64
64
  const chat = currentChat()?.id;
65
65
  const claimed = [...new Set(input.lanes ?? [])];
66
66
  const blockers = [
@@ -82,7 +82,7 @@ export function createJobRegistry(options) {
82
82
  ...(input.diffWhere !== undefined ? { diffWhere: input.diffWhere } : {}),
83
83
  ...(input.cases !== undefined ? { cases: input.cases } : {}),
84
84
  model: input.model,
85
- ...(stack !== undefined ? { stack } : {}),
85
+ ...(configModule !== undefined ? { configModule } : {}),
86
86
  ...(chat !== undefined ? { chat } : {}),
87
87
  ...(input.follows !== undefined ? { follows: input.follows } : {}),
88
88
  status: blockers.length > 0 || (limit !== undefined && active >= limit) ? "queued" : "running",
@@ -108,7 +108,7 @@ export function createJobRegistry(options) {
108
108
  ...(input.pulse !== undefined ? { pulse: input.pulse } : {}),
109
109
  ...(input.title !== undefined ? { title: input.title } : {}),
110
110
  ...(input.model !== undefined ? { model: input.model } : {}),
111
- ...(stack !== undefined ? { stack } : {}),
111
+ ...(configModule !== undefined ? { configModule } : {}),
112
112
  ...(input.cases !== undefined ? { cases: input.cases } : {}),
113
113
  waitingOn: blockers,
114
114
  ...(input.follows !== undefined ? { follows: input.follows } : {}),
@@ -319,9 +319,9 @@ export function createJobRegistry(options) {
319
319
  // Its log is named only where it is kept: otherwise it goes as the pulse ends.
320
320
  const named = log !== undefined && project !== undefined && debugMode(project);
321
321
  record({ kind: "job.started", waitedMs: job.startedAt - job.queuedAt, ...(named ? { logFile: log.file } : {}) }, place);
322
- // What the job's agents start runs until it ends, and no longer (withPulse) - with the stack it was queued
323
- // with, whatever is chosen while it waits or runs.
324
- return withStack(stack, () => (guarded ? runGuarded() : runOnce()));
322
+ // What the job's agents start runs until it ends, and no longer (withPulse) - with the config it was queued
323
+ // with, whatever the files say while it waits or runs.
324
+ return withConfigModule(configModule, () => (guarded ? runGuarded() : runOnce()));
325
325
  })
326
326
  .then((outcome) => {
327
327
  // Asked to stop, it is stopped - whether its work threw as it unwound or returned what it had.
@@ -479,7 +479,7 @@ export function pulseName(job) {
479
479
  }
480
480
  /** What the agent is told when it checks on a job. */
481
481
  export function describeJob(job) {
482
- const name = `${pulseName(job)}${job.stack !== undefined ? ` (stack ${job.stack})` : ""}`;
482
+ const name = `${pulseName(job)}${job.configModule !== undefined ? ` (built with ${moduleConfigFile(job.configModule)})` : ""}`;
483
483
  if (job.status === "queued") {
484
484
  return `${name}: queued behind ${job.waitingOn.map((id) => `pulse ${id}`).join(" and ")}. It starts when that finishes.`;
485
485
  }
@@ -0,0 +1,154 @@
1
+ import { type ChainEntry } from "./requires.ts";
2
+ /**
3
+ * Launch: a codebase's code, as one of its commits has it, put out in `dist/<module>` for the person and the sentinel
4
+ * to try - the commit a pulse landed, or the codebase's last.
5
+ *
6
+ * A pulse works in `plain_modules/<module>/code` while a launch runs, so what is there is half-written. A commit is not:
7
+ * every unit of work starts from one and ends with one, and both are runnable. So the commit is exported from the
8
+ * module's history - git's own list of what it tracks, and nothing else - without a list of what each stack leaves lying
9
+ * around (`node_modules`, `.venv`, `target`). The working tree is never read, reset or touched: the next pulse may be
10
+ * writing in it.
11
+ *
12
+ * What starts it runs here, on the person's machine, unfenced: a server the person opens in their browser, with their
13
+ * toolchains. The launch agent installs and runs what it needs itself, as any agent with a shell would - nothing is put to
14
+ * the person - and everything started is the harness's to stop: on the next launch, on /halt, and when turri exits.
15
+ */
16
+ /** A codebase's code at a commit, exported - what a launch takes on from. */
17
+ export interface ExportedCode {
18
+ /** The codebase: the module whose `plain_modules/<module>` holds the code. */
19
+ moduleName: string;
20
+ plainFile: string;
21
+ /** `dist/<module>`, in the project: the commit's code. */
22
+ dir: string;
23
+ /** Where the module's code is built: `plain_modules/<module>/code`. */
24
+ buildDir: string;
25
+ /** The commit, whole. */
26
+ commit: string;
27
+ /** The commit, short - as the person and the agents are told it. */
28
+ short: string;
29
+ /** The commit's subject: what the unit of work that landed it did. */
30
+ subject: string;
31
+ /** When, as git says it: "3 minutes ago". */
32
+ when: string;
33
+ /** Work under way in the module - changes nobody committed yet - left out. */
34
+ unfinished: boolean;
35
+ /** The module the spec's code lives in had nothing committed yet: the nearest one below it that had, instead. */
36
+ instead?: string;
37
+ }
38
+ /** The tree of a commit's code: two commits with the same one hold the same code - one landed only tests, say. */
39
+ export declare function codeTreeOf(moduleDir: string, commit: string): string | undefined;
40
+ /** Whether `commit` holds `ancestor`: the same commit, or one built on it. */
41
+ export declare function holdsCommit(moduleDir: string, ancestor: string, commit: string): boolean;
42
+ /**
43
+ * Which codebase to launch for a spec, and at which commit: the tip of its codebase - code accumulates up a requires
44
+ * chain, so the top module holds everything below it - at `commit`, or its last. Before the tip has anything committed,
45
+ * the nearest module below it that has.
46
+ */
47
+ export declare function launchTarget(plainFile: string, options?: {
48
+ inModule?: string;
49
+ commit?: string;
50
+ }): {
51
+ entry: ChainEntry;
52
+ commit: string;
53
+ instead?: string;
54
+ };
55
+ /**
56
+ * Export a codebase's code at a commit - its last, unless `commit` names one - into `dist/<module>`, or `into`
57
+ * (`turri regenerate --build-dir`), replacing whatever was there, the harness's own files (what the code is built from,
58
+ * the agents' notes) left out.
59
+ */
60
+ export declare function exportModule(plainFile: string, options?: {
61
+ inModule?: string;
62
+ into?: string;
63
+ commit?: string;
64
+ }): ExportedCode;
65
+ /**
66
+ * The host codebase a launch with guidance works in: the git repository the project is in - an embedded project's host -
67
+ * or else `fallback`, where turri runs.
68
+ */
69
+ export declare function hostDirOf(plainFile: string, fallback: string): string;
70
+ /** Where a path is, said from the current directory when it is below it. */
71
+ export declare function shortPath(path: string): string;
72
+ /** What was exported, in a line or three. */
73
+ export declare function describeExport(code: ExportedCode): string;
74
+ export interface LaunchedProcess {
75
+ name: string;
76
+ moduleName: string;
77
+ command: string;
78
+ /** Where it runs. */
79
+ dir: string;
80
+ url?: string;
81
+ /** Its output, both streams. */
82
+ log: string;
83
+ pid: number;
84
+ startedAt: number;
85
+ /** Set once it has ended. */
86
+ exited?: {
87
+ code: number | null;
88
+ signal: string | null;
89
+ };
90
+ }
91
+ /**
92
+ * What a launch started, written down as it starts - `.turri/launch/running/<pid>.json` - and taken out as it ends: a turri
93
+ * that dies without stopping what it started leaves it findable, for the next session to stop (`stopLeftBehind`).
94
+ */
95
+ export interface LaunchRecord {
96
+ pid: number;
97
+ /** Its process group: the pid, as it was started as the leader of a group of its own. */
98
+ pgid: number;
99
+ name: string;
100
+ moduleName: string;
101
+ command: string;
102
+ dir: string;
103
+ url?: string;
104
+ startedAt: number;
105
+ /** The turri process that started it. */
106
+ turri: number;
107
+ }
108
+ /**
109
+ * Stop what launches of an earlier turri left running in the project - the codebase's, or every one's - as stopLaunched
110
+ * stops this session's: its process group, politely, then not. Only what turri's own records name, whose turri has ended
111
+ * (another turri still running keeps its own), and only when the process is still the one recorded: a process turri did
112
+ * not start is never stopped. Records of what has ended are taken out. Returns what was stopped.
113
+ */
114
+ export declare function stopLeftBehind(projectDir: string, codebase?: string): Promise<LaunchRecord[]>;
115
+ /** What was stopped of an earlier session's, in a line - for a launch's summary. */
116
+ export declare function describeLeftBehind(stopped: LaunchRecord[]): string;
117
+ /** Everything a launch started, running or ended, oldest first. */
118
+ export declare function listLaunched(): LaunchedProcess[];
119
+ /** The ones still running. */
120
+ export declare function runningLaunched(moduleName?: string): LaunchedProcess[];
121
+ /** Where what a project's launches started write their output: its scratch, not the code in dist. */
122
+ export declare function launchLogDir(projectDir: string): string;
123
+ /** The end of a log, for when something did not come up. */
124
+ export declare function logTail(log: string, lines?: number, chars?: number): string;
125
+ /** Stop one launched process, or every one of a module, or every one: politely, then not. Returns the names stopped. */
126
+ export declare function stopLaunched(which?: {
127
+ name?: string;
128
+ moduleName?: string;
129
+ }): Promise<string[]>;
130
+ /** Stop everything at once, without waiting: for when turri itself is going. */
131
+ export declare function stopAllLaunchedNow(): void;
132
+ /** What holds a port, as lsof says it - or nothing when it cannot say. */
133
+ export declare function holderOf(port: number): string;
134
+ /** How long a server is given to answer at its URL, and to stay up when it has none. */
135
+ export declare const READY_TIMEOUT_MS: number;
136
+ export interface StartResult {
137
+ ok: boolean;
138
+ /** What happened, for the agent and the person. */
139
+ text: string;
140
+ process?: LaunchedProcess;
141
+ }
142
+ /**
143
+ * Start what keeps running, in `dir` - the folder `root` it is named from, or one inside it. A folder that is not there
144
+ * starts nothing: said, with what `root` holds, so the agent can name the right one.
145
+ */
146
+ export declare function startLaunched(input: {
147
+ name: string;
148
+ command: string;
149
+ dir: string;
150
+ moduleName: string;
151
+ logDir: string;
152
+ url?: string;
153
+ root?: string;
154
+ }): Promise<StartResult>;