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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +57 -62
  2. package/dist/bedrock-region.js +3 -3
  3. package/dist/chat-idle.d.ts +2 -2
  4. package/dist/chat-idle.js +2 -2
  5. package/dist/chat-models.d.ts +1 -1
  6. package/dist/chat-models.js +1 -1
  7. package/dist/chat-scope.d.ts +1 -3
  8. package/dist/chat-skills.d.ts +1 -1
  9. package/dist/chat-skills.js +1 -1
  10. package/dist/chats.d.ts +44 -20
  11. package/dist/chats.js +125 -64
  12. package/dist/cli.js +42 -31
  13. package/dist/config-edit.d.ts +20 -8
  14. package/dist/config-edit.js +32 -26
  15. package/dist/config.d.ts +106 -78
  16. package/dist/config.js +267 -133
  17. package/dist/conform-cli.js +14 -3
  18. package/dist/conformance-switch.d.ts +13 -22
  19. package/dist/conformance-switch.js +37 -59
  20. package/dist/drift-cli.js +1 -1
  21. package/dist/extension.d.ts +31 -12
  22. package/dist/extension.js +555 -556
  23. package/dist/genome.js +10 -49
  24. package/dist/graph.js +3 -5
  25. package/dist/host-session.d.ts +11 -21
  26. package/dist/host-session.js +6 -8
  27. package/dist/host.d.ts +4 -4
  28. package/dist/host.js +4 -7
  29. package/dist/identity.js +2 -3
  30. package/dist/init-config.d.ts +1 -2
  31. package/dist/init-config.js +10 -17
  32. package/dist/installed-providers.d.ts +1 -1
  33. package/dist/installed-providers.js +2 -2
  34. package/dist/launch-agent.d.ts +41 -0
  35. package/dist/launch-agent.js +219 -0
  36. package/dist/{release-cli.js → launch-cli.js} +41 -24
  37. package/dist/launch-session.d.ts +58 -0
  38. package/dist/launch-session.js +195 -0
  39. package/dist/launch-tools.d.ts +28 -0
  40. package/dist/launch-tools.js +69 -0
  41. package/dist/launch-track.d.ts +120 -0
  42. package/dist/launch-track.js +298 -0
  43. package/dist/loop-cli.d.ts +4 -3
  44. package/dist/loop-cli.js +17 -15
  45. package/dist/loop-tools.d.ts +45 -21
  46. package/dist/loop-tools.js +155 -90
  47. package/dist/new-project.js +2 -2
  48. package/dist/notice.d.ts +7 -6
  49. package/dist/parse-cli.js +2 -2
  50. package/dist/pi-launch.js +4 -1
  51. package/dist/pi-settings.d.ts +4 -0
  52. package/dist/pi-settings.js +39 -0
  53. package/dist/pi.js +12 -9
  54. package/dist/plain/check.d.ts +2 -9
  55. package/dist/plain/check.js +6 -39
  56. package/dist/plain-files.d.ts +2 -2
  57. package/dist/plain-files.js +7 -7
  58. package/dist/regenerate/activity.d.ts +0 -7
  59. package/dist/regenerate/activity.js +2 -20
  60. package/dist/regenerate/agent-env.d.ts +1 -1
  61. package/dist/regenerate/agent-env.js +3 -3
  62. package/dist/regenerate/agent-shell.js +5 -3
  63. package/dist/regenerate/audit.js +9 -0
  64. package/dist/regenerate/base-folder.d.ts +2 -2
  65. package/dist/regenerate/base-folder.js +1 -1
  66. package/dist/regenerate/cases.js +7 -0
  67. package/dist/regenerate/chunk-plan.d.ts +5 -0
  68. package/dist/regenerate/chunk-plan.js +16 -1
  69. package/dist/regenerate/command-check.d.ts +1 -1
  70. package/dist/regenerate/command-check.js +1 -1
  71. package/dist/regenerate/delivery.d.ts +1 -1
  72. package/dist/regenerate/delivery.js +3 -3
  73. package/dist/regenerate/drift.d.ts +4 -0
  74. package/dist/regenerate/drift.js +26 -6
  75. package/dist/regenerate/failure-reports.d.ts +28 -0
  76. package/dist/regenerate/failure-reports.js +79 -0
  77. package/dist/regenerate/job-panel.js +3 -1
  78. package/dist/regenerate/jobs-tree.js +1 -1
  79. package/dist/regenerate/jobs.d.ts +4 -2
  80. package/dist/regenerate/jobs.js +14 -10
  81. package/dist/regenerate/launch.d.ts +126 -0
  82. package/dist/regenerate/{release.js → launch.js} +60 -48
  83. package/dist/regenerate/ledger-view.d.ts +11 -24
  84. package/dist/regenerate/ledger-view.js +14 -60
  85. package/dist/regenerate/ledger.d.ts +26 -16
  86. package/dist/regenerate/ledger.js +1 -1
  87. package/dist/regenerate/lineage.d.ts +2 -0
  88. package/dist/regenerate/lineage.js +8 -0
  89. package/dist/regenerate/loop.d.ts +57 -65
  90. package/dist/regenerate/loop.js +354 -171
  91. package/dist/regenerate/model-names.d.ts +33 -0
  92. package/dist/regenerate/{engine.js → model-names.js} +2 -28
  93. package/dist/regenerate/paths.d.ts +3 -3
  94. package/dist/regenerate/paths.js +4 -4
  95. package/dist/regenerate/records.d.ts +11 -0
  96. package/dist/regenerate/records.js +15 -0
  97. package/dist/regenerate/regenerate.d.ts +0 -2
  98. package/dist/regenerate/regenerate.js +4 -15
  99. package/dist/regenerate/renames.js +4 -4
  100. package/dist/regenerate/requires.d.ts +7 -0
  101. package/dist/regenerate/requires.js +24 -18
  102. package/dist/regenerate/scripts-being-written.d.ts +4 -4
  103. package/dist/regenerate/scripts-being-written.js +3 -3
  104. package/dist/regenerate/spec-map.js +3 -3
  105. package/dist/regenerate/standing.js +1 -1
  106. package/dist/regenerate/submit-work.d.ts +2 -0
  107. package/dist/regenerate/submit-work.js +8 -3
  108. package/dist/regenerate/test-scripts.d.ts +2 -1
  109. package/dist/regenerate/test-scripts.js +33 -23
  110. package/dist/regenerate/testing-steps.d.ts +16 -5
  111. package/dist/regenerate/testing-steps.js +28 -9
  112. package/dist/regenerate-cli.js +18 -9
  113. package/dist/self-invocation.d.ts +11 -0
  114. package/dist/self-invocation.js +37 -11
  115. package/dist/sentinel-check.d.ts +3 -3
  116. package/dist/sentinel-check.js +3 -3
  117. package/dist/sentinel.d.ts +17 -12
  118. package/dist/sentinel.js +75 -46
  119. package/dist/{config-command.d.ts → settings.d.ts} +13 -8
  120. package/dist/{config-command.js → settings.js} +155 -24
  121. package/dist/setup.d.ts +2 -2
  122. package/dist/setup.js +7 -7
  123. package/dist/skill.d.ts +0 -11
  124. package/dist/skill.js +0 -9
  125. package/dist/tools.js +2 -3
  126. package/dist/turri-versions.js +2 -1
  127. package/docs/README.md +4 -6
  128. package/docs/authoring-plain.md +3 -3
  129. package/docs/chats.md +6 -9
  130. package/docs/claude-subscription.md +8 -8
  131. package/docs/config.md +62 -52
  132. package/docs/development.md +4 -5
  133. package/docs/headless.md +7 -6
  134. package/docs/hosting.md +25 -24
  135. package/docs/installation.md +4 -0
  136. package/docs/launch.md +63 -0
  137. package/docs/parser.md +3 -3
  138. package/docs/regenerating.md +30 -22
  139. package/docs/sandbox.md +3 -3
  140. package/docs/sentinel.md +27 -16
  141. package/docs/skills-and-gates.md +6 -11
  142. package/docs/using.md +26 -42
  143. package/genome/rules/project-model.md +2 -1
  144. package/genome/rules/test-plain-files.md +15 -7
  145. package/genome/rules/turri-regeneration.md +7 -10
  146. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  147. package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
  148. package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
  149. package/package.json +1 -1
  150. package/dist/advisor-chat.d.ts +0 -63
  151. package/dist/advisor-chat.js +0 -290
  152. package/dist/change-plain-cli.js +0 -55
  153. package/dist/ledger-cli.d.ts +0 -1
  154. package/dist/ledger-cli.js +0 -50
  155. package/dist/ledger-tools.d.ts +0 -10
  156. package/dist/ledger-tools.js +0 -64
  157. package/dist/regenerate/advisor-records.d.ts +0 -93
  158. package/dist/regenerate/advisor-records.js +0 -110
  159. package/dist/regenerate/advisor-runs.d.ts +0 -87
  160. package/dist/regenerate/advisor-runs.js +0 -327
  161. package/dist/regenerate/engine.d.ts +0 -52
  162. package/dist/regenerate/release.d.ts +0 -121
  163. package/dist/regenerate/test-advisor.d.ts +0 -101
  164. package/dist/regenerate/test-advisor.js +0 -379
  165. package/dist/release-agent.d.ts +0 -43
  166. package/dist/release-agent.js +0 -130
  167. package/dist/release-cli.d.ts +0 -1
  168. package/dist/release-tools.d.ts +0 -44
  169. package/dist/release-tools.js +0 -170
  170. package/dist/spec-tools.d.ts +0 -36
  171. package/dist/spec-tools.js +0 -128
  172. package/dist/stacks.d.ts +0 -13
  173. package/dist/stacks.js +0 -96
  174. package/docs/deploy.md +0 -48
  175. package/docs/test-advisor.md +0 -110
  176. /package/dist/{change-plain-cli.d.ts → launch-cli.d.ts} +0 -0
@@ -1,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;
@@ -0,0 +1,28 @@
1
+ import type { Job } from "./jobs.ts";
2
+ /**
3
+ * Why a pulse did not land, kept past its session.
4
+ *
5
+ * Outside debug mode a pulse's log and transcript go as it ends (pulse-files.ts), and the ledger keeps facts, never
6
+ * what a tool printed. So a pulse of an earlier session would be told as one-line facts alone - its failure's first
7
+ * line, its test runs' exit codes. What `pulses` says of one that did not land - its diagnosis, the stages that went
8
+ * wrong, the last failing test run's output, the last review that sent the work back, the tool calls that failed - is
9
+ * written here as it ends, whatever the debug setting, masked as the logs are: `.turri/pulses/<id>.md`. Kept while the
10
+ * ledger is on, and as long as the project keeps a ledger (`ledger-keep:`, 0 for none); the newest `KEPT` alone.
11
+ */
12
+ /** The folder, in a project's `.turri`. */
13
+ export declare const REPORTS_DIR = "pulses";
14
+ /** How many reports a project keeps: the newest. */
15
+ export declare const KEPT = 200;
16
+ /** Where a project's reports are. */
17
+ export declare function reportsDir(project: string): string;
18
+ /** Whether a pulse ended without landing: failed, stopped, or finished with nothing landed. */
19
+ export declare function didNotLand(job: Job): boolean;
20
+ /**
21
+ * A pulse has ended: one that failed, or finished with nothing landed, has its report written, and the oldest past
22
+ * `KEPT` go. A stopped one has none - the person halted it, or the ***plain moved on, and the ledger says which. Nothing
23
+ * while the ledger is off, or where the project keeps none. Never throws: a report that cannot be written is never a
24
+ * reason for the pulse to fail.
25
+ */
26
+ export declare function keepFailureReport(project: string, job: Job): void;
27
+ /** A pulse's report, by its whole id - or undefined when it has none. */
28
+ export declare function failureReport(project: string, id: string): string | undefined;
@@ -0,0 +1,79 @@
1
+ import { existsSync, readdirSync, readFileSync, statSync, unlinkSync, writeFileSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { readProjectConfig } from "../config.js";
4
+ import { whyFailed } from "./diagnose-job.js";
5
+ import { DEFAULT_LEDGER_KEEP_MB, ledgerRun } from "./ledger.js";
6
+ import { maskSecrets } from "./masking.js";
7
+ import { ensureInScratch } from "./paths.js";
8
+ /**
9
+ * Why a pulse did not land, kept past its session.
10
+ *
11
+ * Outside debug mode a pulse's log and transcript go as it ends (pulse-files.ts), and the ledger keeps facts, never
12
+ * what a tool printed. So a pulse of an earlier session would be told as one-line facts alone - its failure's first
13
+ * line, its test runs' exit codes. What `pulses` says of one that did not land - its diagnosis, the stages that went
14
+ * wrong, the last failing test run's output, the last review that sent the work back, the tool calls that failed - is
15
+ * written here as it ends, whatever the debug setting, masked as the logs are: `.turri/pulses/<id>.md`. Kept while the
16
+ * ledger is on, and as long as the project keeps a ledger (`ledger-keep:`, 0 for none); the newest `KEPT` alone.
17
+ */
18
+ /** The folder, in a project's `.turri`. */
19
+ export const REPORTS_DIR = "pulses";
20
+ /** How many reports a project keeps: the newest. */
21
+ export const KEPT = 200;
22
+ /** Where a project's reports are. */
23
+ export function reportsDir(project) {
24
+ return join(resolve(project), ".turri", REPORTS_DIR);
25
+ }
26
+ /** Whether a pulse ended without landing: failed, stopped, or finished with nothing landed. */
27
+ export function didNotLand(job) {
28
+ if (job.status === "failed" || job.status === "stopped")
29
+ return true;
30
+ return job.status === "succeeded" && job.details?.landed === false;
31
+ }
32
+ /** Whether the project keeps a ledger, and so its reports. */
33
+ function keeps(project) {
34
+ try {
35
+ return (readProjectConfig(project).ledgerKeep ?? DEFAULT_LEDGER_KEEP_MB) > 0;
36
+ }
37
+ catch {
38
+ return true;
39
+ }
40
+ }
41
+ /**
42
+ * A pulse has ended: one that failed, or finished with nothing landed, has its report written, and the oldest past
43
+ * `KEPT` go. A stopped one has none - the person halted it, or the ***plain moved on, and the ledger says which. Nothing
44
+ * while the ledger is off, or where the project keeps none. Never throws: a report that cannot be written is never a
45
+ * reason for the pulse to fail.
46
+ */
47
+ export function keepFailureReport(project, job) {
48
+ if (ledgerRun() === undefined || job.status === "stopped" || !didNotLand(job) || !keeps(project))
49
+ return;
50
+ try {
51
+ const dir = ensureInScratch(join(resolve(project), ".turri"), reportsDir(project));
52
+ writeFileSync(join(dir, `${job.id}.md`), `${maskSecrets(whyFailed(job))}\n`);
53
+ prune(dir);
54
+ }
55
+ catch {
56
+ /* kept when it can be: the ledger still has the facts */
57
+ }
58
+ }
59
+ /** The newest `KEPT` reports stay. */
60
+ function prune(dir) {
61
+ const reports = readdirSync(dir)
62
+ .filter((name) => name.endsWith(".md"))
63
+ .map((name) => ({ name, at: statSync(join(dir, name)).mtimeMs }))
64
+ .sort((a, b) => b.at - a.at);
65
+ for (const old of reports.slice(KEPT))
66
+ unlinkSync(join(dir, old.name));
67
+ }
68
+ /** A pulse's report, by its whole id - or undefined when it has none. */
69
+ export function failureReport(project, id) {
70
+ const file = join(reportsDir(project), `${id}.md`);
71
+ if (!existsSync(file))
72
+ return undefined;
73
+ try {
74
+ return readFileSync(file, "utf8").trimEnd();
75
+ }
76
+ catch {
77
+ return undefined;
78
+ }
79
+ }
@@ -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
@@ -209,7 +209,7 @@ export function jobsTreeLines(jobs, state, width, style) {
209
209
  });
210
210
  // The ledger has more than the runs shown: where to find them.
211
211
  if (state.open.earlier && (state.earlierMore ?? 0) > 0) {
212
- lines.push(style.muted(` ${state.earlierMore} earlier run${state.earlierMore === 1 ? "" : "s"} in the ledger - turri ledger lists them`));
212
+ lines.push(style.muted(` ${state.earlierMore} earlier run${state.earlierMore === 1 ? "" : "s"} in the ledger - pulses with runs lists them`));
213
213
  }
214
214
  return { lines, rowStarts, rows };
215
215
  }
@@ -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;
@@ -60,6 +60,8 @@ export interface Job {
60
60
  planning?: {
61
61
  since: number;
62
62
  };
63
+ /** A row of the work loop's planned by a look ahead: it waits for regenerate, conform or /regenerate to start it. */
64
+ lookedAhead?: true;
63
65
  /** While queued: the jobs it is waiting for. */
64
66
  waitingOn: string[];
65
67
  finishedAt?: number;
@@ -5,9 +5,10 @@ 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
+ import { keepFailureReport } from "./failure-reports.js";
11
12
  const DEFAULT_TAIL_CHARS = 4000;
12
13
  const ACTIVITY_LINES = 10;
13
14
  /** A long render's full transcript is kept, up to about this much text. */
@@ -57,9 +58,9 @@ export function createJobRegistry(options) {
57
58
  },
58
59
  start(input) {
59
60
  const id = randomUUID().slice(0, 8);
60
- // The stack chosen as it is queued - or pinned for the work that queues it - not as it starts: a job that waits
61
- // for a slot is built with the stack it was asked for, whatever is chosen meanwhile.
62
- 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();
63
64
  const chat = currentChat()?.id;
64
65
  const claimed = [...new Set(input.lanes ?? [])];
65
66
  const blockers = [
@@ -81,7 +82,7 @@ export function createJobRegistry(options) {
81
82
  ...(input.diffWhere !== undefined ? { diffWhere: input.diffWhere } : {}),
82
83
  ...(input.cases !== undefined ? { cases: input.cases } : {}),
83
84
  model: input.model,
84
- ...(stack !== undefined ? { stack } : {}),
85
+ ...(configModule !== undefined ? { configModule } : {}),
85
86
  ...(chat !== undefined ? { chat } : {}),
86
87
  ...(input.follows !== undefined ? { follows: input.follows } : {}),
87
88
  status: blockers.length > 0 || (limit !== undefined && active >= limit) ? "queued" : "running",
@@ -107,7 +108,7 @@ export function createJobRegistry(options) {
107
108
  ...(input.pulse !== undefined ? { pulse: input.pulse } : {}),
108
109
  ...(input.title !== undefined ? { title: input.title } : {}),
109
110
  ...(input.model !== undefined ? { model: input.model } : {}),
110
- ...(stack !== undefined ? { stack } : {}),
111
+ ...(configModule !== undefined ? { configModule } : {}),
111
112
  ...(input.cases !== undefined ? { cases: input.cases } : {}),
112
113
  waitingOn: blockers,
113
114
  ...(input.follows !== undefined ? { follows: input.follows } : {}),
@@ -318,9 +319,9 @@ export function createJobRegistry(options) {
318
319
  // Its log is named only where it is kept: otherwise it goes as the pulse ends.
319
320
  const named = log !== undefined && project !== undefined && debugMode(project);
320
321
  record({ kind: "job.started", waitedMs: job.startedAt - job.queuedAt, ...(named ? { logFile: log.file } : {}) }, place);
321
- // What the job's agents start runs until it ends, and no longer (withPulse) - with the stack it was queued
322
- // with, whatever is chosen while it waits or runs.
323
- 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()));
324
325
  })
325
326
  .then((outcome) => {
326
327
  // Asked to stop, it is stopped - whether its work threw as it unwound or returned what it had.
@@ -347,6 +348,9 @@ export function createJobRegistry(options) {
347
348
  // What it wrote for a person goes now, outside debug mode - its log too, which nothing names from then on.
348
349
  if (ran && project !== undefined && !pulseEnded({ job: id, project, ...(input.module !== undefined ? { module: input.module } : {}), lanes: claimed }))
349
350
  delete finished.logFile;
351
+ // Why one that did not land did not, kept past the session whatever the debug setting (failure-reports.ts).
352
+ if (ran && project !== undefined)
353
+ keepFailureReport(project, finished);
350
354
  const outcome = finished.details;
351
355
  const stopReason = stopReasons.get(id);
352
356
  record({
@@ -475,7 +479,7 @@ export function pulseName(job) {
475
479
  }
476
480
  /** What the agent is told when it checks on a job. */
477
481
  export function describeJob(job) {
478
- const name = `${pulseName(job)}${job.stack !== undefined ? ` (stack ${job.stack})` : ""}`;
482
+ const name = `${pulseName(job)}${job.configModule !== undefined ? ` (built with ${moduleConfigFile(job.configModule)})` : ""}`;
479
483
  if (job.status === "queued") {
480
484
  return `${name}: queued behind ${job.waitingOn.map((id) => `pulse ${id}`).join(" and ")}. It starts when that finishes.`;
481
485
  }
@@ -0,0 +1,126 @@
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
+ /** Everything a launch started, running or ended, oldest first. */
92
+ export declare function listLaunched(): LaunchedProcess[];
93
+ /** The ones still running. */
94
+ export declare function runningLaunched(moduleName?: string): LaunchedProcess[];
95
+ /** Where what a project's launches started write their output: its scratch, not the code in dist. */
96
+ export declare function launchLogDir(projectDir: string): string;
97
+ /** The end of a log, for when something did not come up. */
98
+ export declare function logTail(log: string, lines?: number, chars?: number): string;
99
+ /** Stop one launched process, or every one of a module, or every one: politely, then not. Returns the names stopped. */
100
+ export declare function stopLaunched(which?: {
101
+ name?: string;
102
+ moduleName?: string;
103
+ }): Promise<string[]>;
104
+ /** Stop everything at once, without waiting: for when turri itself is going. */
105
+ export declare function stopAllLaunchedNow(): void;
106
+ /** How long a server is given to answer at its URL, and to stay up when it has none. */
107
+ export declare const READY_TIMEOUT_MS: number;
108
+ export interface StartResult {
109
+ ok: boolean;
110
+ /** What happened, for the agent and the person. */
111
+ text: string;
112
+ process?: LaunchedProcess;
113
+ }
114
+ /**
115
+ * Start what keeps running, in `dir` - the folder `root` it is named from, or one inside it. A folder that is not there
116
+ * starts nothing: said, with what `root` holds, so the agent can name the right one.
117
+ */
118
+ export declare function startLaunched(input: {
119
+ name: string;
120
+ command: string;
121
+ dir: string;
122
+ moduleName: string;
123
+ logDir: string;
124
+ url?: string;
125
+ root?: string;
126
+ }): Promise<StartResult>;
@@ -10,41 +10,58 @@ import { RECORD_FILE } from "./paths.js";
10
10
  function git(moduleDir, args) {
11
11
  return spawnSync("git", ["--git-dir", join(moduleDir, HISTORY_DIR), "--work-tree", moduleDir, ...args], { cwd: moduleDir, encoding: "utf8" });
12
12
  }
13
- /** The module's last commit, when it has one with code in it. */
14
- function committedCode(moduleDir) {
13
+ /** A commit of the module's history, whole - `HEAD` its last - when it has one with code in it. */
14
+ function committedCode(moduleDir, commit = "HEAD") {
15
15
  if (!existsSync(join(moduleDir, HISTORY_DIR)))
16
16
  return undefined;
17
- const commit = git(moduleDir, ["rev-parse", "--verify", "--quiet", "HEAD"]);
18
- if (commit.status !== 0)
17
+ const found = git(moduleDir, ["rev-parse", "--verify", "--quiet", `${commit}^{commit}`]);
18
+ if (found.status !== 0)
19
19
  return undefined;
20
+ const whole = found.stdout.trim();
20
21
  // A commit with no code folder in it has nothing to run.
21
- if (git(moduleDir, ["rev-parse", "--verify", "--quiet", "HEAD:code"]).status !== 0)
22
+ if (git(moduleDir, ["rev-parse", "--verify", "--quiet", `${whole}:code`]).status !== 0)
22
23
  return undefined;
23
- return commit.stdout.trim();
24
+ return whole;
25
+ }
26
+ /** The tree of a commit's code: two commits with the same one hold the same code - one landed only tests, say. */
27
+ export function codeTreeOf(moduleDir, commit) {
28
+ const tree = git(moduleDir, ["rev-parse", "--verify", "--quiet", `${commit}:code`]);
29
+ return tree.status === 0 ? tree.stdout.trim() : undefined;
30
+ }
31
+ /** Whether `commit` holds `ancestor`: the same commit, or one built on it. */
32
+ export function holdsCommit(moduleDir, ancestor, commit) {
33
+ return git(moduleDir, ["merge-base", "--is-ancestor", ancestor, commit]).status === 0;
24
34
  }
25
35
  /**
26
- * Which module to deploy for a spec: the tip of its codebase - code accumulates up a requires chain, so
27
- * the top module holds everything below it. Before the tip has anything committed, the nearest module
28
- * below it that has.
36
+ * Which codebase to launch for a spec, and at which commit: the tip of its codebase - code accumulates up a requires
37
+ * chain, so the top module holds everything below it - at `commit`, or its last. Before the tip has anything committed,
38
+ * the nearest module below it that has.
29
39
  */
30
- export function deployTarget(plainFile, inModule) {
31
- const { tip, chain } = findCodebaseTip(plainFile, { allowNoFunctionalities: true, ...(inModule !== undefined ? { inModule } : {}) });
40
+ export function launchTarget(plainFile, options = {}) {
41
+ const { tip, chain } = findCodebaseTip(plainFile, { allowNoFunctionalities: true, ...(options.inModule !== undefined ? { inModule: options.inModule } : {}) });
42
+ if (options.commit !== undefined) {
43
+ const commit = committedCode(dirname(tip.buildDir), options.commit);
44
+ if (commit === undefined)
45
+ throw new Error(`${tip.moduleName} has no commit ${options.commit} with code in it: nothing to launch.`);
46
+ return { entry: tip, commit };
47
+ }
32
48
  const candidates = [tip, ...[...chain].reverse().filter((entry) => entry.moduleName !== tip.moduleName)];
33
49
  for (const entry of candidates) {
34
50
  const commit = committedCode(dirname(entry.buildDir));
35
51
  if (commit !== undefined)
36
52
  return { entry, commit, ...(entry.moduleName !== tip.moduleName ? { instead: tip.moduleName } : {}) };
37
53
  }
38
- throw new Error(`Nothing is built yet for ${tip.moduleName}${candidates.length > 1 ? " or the modules it requires" : ""}: there is no code to deploy. Render it first.`);
54
+ throw new Error(`Nothing is built yet for ${tip.moduleName}${candidates.length > 1 ? " or the modules it requires" : ""}: there is no code to launch. Regenerate it first.`);
39
55
  }
40
56
  /**
41
- * Export the module's code at its last commit into `dist/<module>` - or `into`, `turri regenerate --build-dir` -
42
- * replacing whatever was there, the harness's own files (what the code is built from, the agents' notes) left out.
57
+ * Export a codebase's code at a commit - its last, unless `commit` names one - into `dist/<module>`, or `into`
58
+ * (`turri regenerate --build-dir`), replacing whatever was there, the harness's own files (what the code is built from,
59
+ * the agents' notes) left out.
43
60
  */
44
- export function exportModule(plainFile, inModule, into) {
45
- const { entry, commit, instead } = deployTarget(plainFile, inModule);
61
+ export function exportModule(plainFile, options = {}) {
62
+ const { entry, commit, instead } = launchTarget(plainFile, options);
46
63
  const moduleDir = dirname(entry.buildDir);
47
- const dir = into ?? distDirFor(projectDirOf(entry.plainFile), entry.moduleName);
64
+ const dir = options.into ?? distDirFor(projectDirOf(entry.plainFile), entry.moduleName);
48
65
  // Emptied, not removed: the folder may be a mount point - a container's volume - that cannot be removed.
49
66
  mkdirSync(dir, { recursive: true });
50
67
  for (const entry of readdirSync(dir))
@@ -59,10 +76,10 @@ export function exportModule(plainFile, inModule, into) {
59
76
  return {
60
77
  moduleName: entry.moduleName,
61
78
  plainFile: entry.plainFile,
62
- way: "dist",
63
79
  dir,
64
80
  buildDir: entry.buildDir,
65
- commit: short ?? commit.slice(0, 8),
81
+ commit,
82
+ short: short ?? commit.slice(0, 8),
66
83
  subject: subject ?? "",
67
84
  when: when ?? "",
68
85
  unfinished,
@@ -70,7 +87,7 @@ export function exportModule(plainFile, inModule, into) {
70
87
  };
71
88
  }
72
89
  /**
73
- * The host codebase a guided release works in: the git repository the project is in - an embedded project's host -
90
+ * The host codebase a launch with guidance works in: the git repository the project is in - an embedded project's host -
74
91
  * or else `fallback`, where turri runs.
75
92
  */
76
93
  export function hostDirOf(plainFile, fallback) {
@@ -82,34 +99,29 @@ export function shortPath(path) {
82
99
  const fromHere = relative(process.cwd(), path);
83
100
  return fromHere === "" || fromHere.startsWith("..") ? path : fromHere;
84
101
  }
85
- /** What was deployed, in a line or three. */
86
- export function describeDeployment(deployment) {
102
+ /** What was exported, in a line or three. */
103
+ export function describeExport(code) {
87
104
  return [
88
- `Deployed ${deployment.moduleName} to ${shortPath(deployment.dir)} - commit ${deployment.commit}, ${deployment.when}: ${deployment.subject}.`,
89
- ...(deployment.hostDir !== undefined ? [`Its guidance takes it on from there, in ${shortPath(deployment.hostDir)}.`] : []),
90
- ...(deployment.instead !== undefined ? [`${deployment.instead}, the module on top, has nothing built yet - this is ${deployment.moduleName}, the module below it.`] : []),
91
- ...(deployment.unfinished
92
- ? [
93
- deployment.hostDir === undefined
94
- ? "A pulse is at work on the module right now: what it has written so far is not finished, and is left out."
95
- : `A pulse is at work on the module right now: what it has written so far is not finished, and is left out of ${shortPath(deployment.dir)} - but ${shortPath(deployment.buildDir)} holds it, so take the code from ${shortPath(deployment.dir)}, never from there.`,
96
- ]
105
+ `${code.moduleName}'s code at commit ${code.short} (${code.when}: ${code.subject}) is in ${shortPath(code.dir)}.`,
106
+ ...(code.instead !== undefined ? [`${code.instead}, the module on top, has nothing built yet - this is ${code.moduleName}, the module below it.`] : []),
107
+ ...(code.unfinished
108
+ ? [`A pulse is at work on the module right now: what it has written so far is not finished, and is left out of ${shortPath(code.dir)} - ${shortPath(code.buildDir)} holds it, so take the code from ${shortPath(code.dir)}, never from there.`]
97
109
  : []),
98
110
  ].join("\n");
99
111
  }
100
112
  const processes = new Map();
101
- /** Everything deploy started, running or ended, oldest first. */
102
- export function listDeployed() {
113
+ /** Everything a launch started, running or ended, oldest first. */
114
+ export function listLaunched() {
103
115
  return [...processes.values()].map((entry) => entry.info);
104
116
  }
105
117
  /** The ones still running. */
106
- export function runningDeployed(moduleName) {
107
- return listDeployed().filter((info) => info.exited === undefined && (moduleName === undefined || info.moduleName === moduleName));
118
+ export function runningLaunched(moduleName) {
119
+ return listLaunched().filter((info) => info.exited === undefined && (moduleName === undefined || info.moduleName === moduleName));
108
120
  }
109
- /** Where a project's deployed processes write their output: its scratch, not the code in dist. */
110
- export function deployLogDir(projectDir) {
121
+ /** Where what a project's launches started write their output: its scratch, not the code in dist. */
122
+ export function launchLogDir(projectDir) {
111
123
  const scratch = join(projectDir, ".turri");
112
- return ensureInScratch(scratch, join(scratch, "deploy"));
124
+ return ensureInScratch(scratch, join(scratch, "launch"));
113
125
  }
114
126
  /** The end of a log, for when something did not come up. */
115
127
  export function logTail(log, lines = 40, chars = 4000) {
@@ -136,8 +148,8 @@ function signalGroup(pid, signal) {
136
148
  }
137
149
  }
138
150
  const sleep = (ms) => new Promise((done) => setTimeout(done, ms));
139
- /** Stop one deployed process, or every one of a module, or every one: politely, then not. Returns the names stopped. */
140
- export async function stopDeployed(which = {}) {
151
+ /** Stop one launched process, or every one of a module, or every one: politely, then not. Returns the names stopped. */
152
+ export async function stopLaunched(which = {}) {
141
153
  const targets = [...processes.values()].filter(({ info }) => info.exited === undefined && (which.name === undefined || info.name === which.name) && (which.moduleName === undefined || info.moduleName === which.moduleName));
142
154
  for (const { info } of targets)
143
155
  signalGroup(info.pid, "SIGTERM");
@@ -150,7 +162,7 @@ export async function stopDeployed(which = {}) {
150
162
  return targets.map(({ info }) => info.name);
151
163
  }
152
164
  /** Stop everything at once, without waiting: for when turri itself is going. */
153
- export function stopAllDeployedNow() {
165
+ export function stopAllLaunchedNow() {
154
166
  for (const { info } of processes.values())
155
167
  if (info.exited === undefined)
156
168
  signalGroup(info.pid, "SIGTERM");
@@ -160,7 +172,7 @@ function stopOnExit() {
160
172
  if (exitHooked)
161
173
  return;
162
174
  exitHooked = true;
163
- process.on("exit", stopAllDeployedNow);
175
+ process.on("exit", stopAllLaunchedNow);
164
176
  }
165
177
  function portOf(url) {
166
178
  if (url.port !== "")
@@ -195,7 +207,7 @@ async function answers(url) {
195
207
  }
196
208
  }
197
209
  /** How long a server is given to answer at its URL, and to stay up when it has none. */
198
- export const READY_TIMEOUT_MS = Number(process.env.TURRI_DEPLOY_READY_TIMEOUT ?? 60) * 1000;
210
+ export const READY_TIMEOUT_MS = Number(process.env.TURRI_LAUNCH_READY_TIMEOUT ?? 60) * 1000;
199
211
  const ALIVE_AFTER_MS = 4000;
200
212
  /**
201
213
  * Start something that keeps running - a server, a frontend's dev server - in `dir`, on this machine,
@@ -219,10 +231,10 @@ function listing(dir) {
219
231
  }
220
232
  }
221
233
  /**
222
- * Start what keeps running, in `dir` - the deployed folder `root`, or one inside it. A folder that is not there starts
223
- * nothing: said, with what the deployed folder holds, so the agent can name the right one.
234
+ * Start what keeps running, in `dir` - the folder `root` it is named from, or one inside it. A folder that is not there
235
+ * starts nothing: said, with what `root` holds, so the agent can name the right one.
224
236
  */
225
- export async function startDeployed(input) {
237
+ export async function startLaunched(input) {
226
238
  let isFolder = false;
227
239
  try {
228
240
  isFolder = statSync(input.dir).isDirectory();
@@ -235,11 +247,11 @@ export async function startDeployed(input) {
235
247
  return {
236
248
  ok: false,
237
249
  text: input.root !== undefined
238
- ? `${input.name} was not started: ${shortPath(input.dir)} ${why}. \`dir\` is relative to the deployed folder, ${shortPath(input.root)} - a folder inside it, e.g. frontend, or none for the deployed folder itself; never the project's path to it. ${shortPath(input.root)} holds: ${listing(input.root)}.`
250
+ ? `${input.name} was not started: ${shortPath(input.dir)} ${why}. \`dir\` is relative to ${shortPath(input.root)} - a folder inside it, e.g. frontend, or none for the folder itself; never the project's path to it. ${shortPath(input.root)} holds: ${listing(input.root)}.`
239
251
  : `${input.name} was not started: ${shortPath(input.dir)} ${why}.`,
240
252
  };
241
253
  }
242
- await stopDeployed({ name: input.name });
254
+ await stopLaunched({ name: input.name });
243
255
  let url;
244
256
  if (input.url !== undefined) {
245
257
  try {