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

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 (92) hide show
  1. package/README.md +2 -2
  2. package/dist/chat-idle.d.ts +2 -2
  3. package/dist/chat-idle.js +2 -2
  4. package/dist/chats.d.ts +0 -10
  5. package/dist/chats.js +0 -23
  6. package/dist/cli.js +2 -5
  7. package/dist/config-edit.js +1 -3
  8. package/dist/config.d.ts +6 -21
  9. package/dist/config.js +3 -16
  10. package/dist/conformance-switch.d.ts +7 -17
  11. package/dist/conformance-switch.js +21 -46
  12. package/dist/drift-cli.js +1 -1
  13. package/dist/extension.d.ts +2 -10
  14. package/dist/extension.js +109 -205
  15. package/dist/genome.js +5 -48
  16. package/dist/graph.js +3 -5
  17. package/dist/host-session.d.ts +4 -15
  18. package/dist/host-session.js +2 -4
  19. package/dist/host.d.ts +1 -3
  20. package/dist/host.js +1 -4
  21. package/dist/identity.js +0 -1
  22. package/dist/init-config.d.ts +0 -1
  23. package/dist/init-config.js +2 -9
  24. package/dist/installed-providers.d.ts +1 -1
  25. package/dist/installed-providers.js +1 -1
  26. package/dist/loop-cli.d.ts +4 -3
  27. package/dist/loop-cli.js +13 -11
  28. package/dist/loop-tools.js +5 -10
  29. package/dist/new-project.js +2 -2
  30. package/dist/pi-launch.js +1 -1
  31. package/dist/pi.js +6 -6
  32. package/dist/plain/check.d.ts +1 -8
  33. package/dist/plain/check.js +3 -38
  34. package/dist/regenerate/activity.d.ts +0 -7
  35. package/dist/regenerate/activity.js +2 -20
  36. package/dist/regenerate/failure-reports.d.ts +28 -0
  37. package/dist/regenerate/failure-reports.js +79 -0
  38. package/dist/regenerate/jobs-tree.js +1 -1
  39. package/dist/regenerate/jobs.d.ts +2 -0
  40. package/dist/regenerate/jobs.js +4 -0
  41. package/dist/regenerate/ledger-view.d.ts +11 -24
  42. package/dist/regenerate/ledger-view.js +14 -60
  43. package/dist/regenerate/ledger.d.ts +1 -14
  44. package/dist/regenerate/ledger.js +1 -1
  45. package/dist/regenerate/loop.d.ts +37 -60
  46. package/dist/regenerate/loop.js +165 -101
  47. package/dist/regenerate/regenerate.d.ts +0 -2
  48. package/dist/regenerate/regenerate.js +0 -14
  49. package/dist/regenerate/standing.js +1 -1
  50. package/dist/regenerate/testing-steps.d.ts +11 -0
  51. package/dist/regenerate/testing-steps.js +22 -3
  52. package/dist/regenerate-cli.js +18 -9
  53. package/dist/self-invocation.js +4 -7
  54. package/dist/sentinel.js +3 -3
  55. package/dist/skill.d.ts +0 -11
  56. package/dist/skill.js +0 -9
  57. package/dist/stacks.js +1 -1
  58. package/dist/tools.js +2 -3
  59. package/docs/README.md +0 -2
  60. package/docs/authoring-plain.md +3 -3
  61. package/docs/chats.md +1 -3
  62. package/docs/config.md +10 -12
  63. package/docs/deploy.md +1 -1
  64. package/docs/development.md +2 -3
  65. package/docs/headless.md +4 -3
  66. package/docs/hosting.md +6 -6
  67. package/docs/parser.md +2 -2
  68. package/docs/regenerating.md +12 -10
  69. package/docs/sentinel.md +3 -3
  70. package/docs/skills-and-gates.md +3 -8
  71. package/docs/using.md +10 -18
  72. package/genome/rules/test-plain-files.md +15 -7
  73. package/genome/rules/turri-regeneration.md +4 -9
  74. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  75. package/package.json +1 -1
  76. package/dist/advisor-chat.d.ts +0 -63
  77. package/dist/advisor-chat.js +0 -290
  78. package/dist/change-plain-cli.d.ts +0 -1
  79. package/dist/change-plain-cli.js +0 -55
  80. package/dist/ledger-cli.d.ts +0 -1
  81. package/dist/ledger-cli.js +0 -50
  82. package/dist/ledger-tools.d.ts +0 -10
  83. package/dist/ledger-tools.js +0 -64
  84. package/dist/regenerate/advisor-records.d.ts +0 -93
  85. package/dist/regenerate/advisor-records.js +0 -110
  86. package/dist/regenerate/advisor-runs.d.ts +0 -87
  87. package/dist/regenerate/advisor-runs.js +0 -327
  88. package/dist/regenerate/test-advisor.d.ts +0 -101
  89. package/dist/regenerate/test-advisor.js +0 -379
  90. package/dist/spec-tools.d.ts +0 -36
  91. package/dist/spec-tools.js +0 -128
  92. package/docs/test-advisor.md +0 -110
@@ -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. */
@@ -159,13 +159,6 @@ export function reportModelEvent(event) {
159
159
  export function withActivity(sink, run) {
160
160
  return store.run(sink, run);
161
161
  }
162
- /**
163
- * Run work for no job, whatever job the code that starts it runs for - and clear of any stop signal: the test
164
- * 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.
165
- */
166
- export function outsideJobs(run) {
167
- return store.exit(() => stops.exit(run));
168
- }
169
162
  export function reportStage(label) {
170
163
  store.getStore()?.stage(label);
171
164
  }
@@ -199,17 +192,6 @@ function clip(text) {
199
192
  export function withinModules(text) {
200
193
  return text.replace(/(?:(?:\/|~\/)(?:[^\s'"`/]+\/)*|(?<![\w.-]))plain_modules\//g, "");
201
194
  }
202
- /**
203
- * What the person is shown a tool as, where that is not the name its agent calls it by. The agent's name says
204
- * what the call takes - `change_plain` takes a diff of the spec - and the shown one speaks turri's language.
205
- */
206
- const SHOWN_AS = {
207
- change_plain: "mutate",
208
- };
209
- /** A tool's name as the person is shown it. */
210
- export function shownName(name) {
211
- return SHOWN_AS[name] ?? name;
212
- }
213
195
  /** A tool call as one short line. Unknown tools still show up, by name. */
214
196
  export function describeToolCall(name, args) {
215
197
  const text = (key) => (typeof args?.[key] === "string" ? withinModules(args[key]) : undefined);
@@ -253,13 +235,13 @@ export function describeToolCall(name, args) {
253
235
  return `? ask_explorer`;
254
236
  default:
255
237
  // A hand-over - submit_work, submit_review, a verdict - ends with a check; anything else, a dot.
256
- return `${/^submit_/.test(name) ? "✓" : "•"} ${shownName(name)}`;
238
+ return `${/^submit_/.test(name) ? "✓" : "•"} ${name}`;
257
239
  }
258
240
  }
259
241
  /** The outcome of a test run, or nothing for tools whose outcome is not worth a line. */
260
242
  export function describeToolResult(name, result, isError) {
261
243
  if (name !== "run_unit_tests" && name !== "run_conformance_tests") {
262
- return isError ? ` ✗ ${shownName(name)} failed` : undefined;
244
+ return isError ? ` ✗ ${name} failed` : undefined;
263
245
  }
264
246
  const exitCode = result?.details?.exitCode;
265
247
  if (typeof exitCode !== "number")
@@ -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
+ }
@@ -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
  }
@@ -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;
@@ -8,6 +8,7 @@ import { firstLine, healing, record } from "./ledger.js";
8
8
  import { chosenStack, debugMode, withStack } 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. */
@@ -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({
@@ -3,7 +3,7 @@ import { type Job } from "./jobs.ts";
3
3
  import { type LedgerEntry } from "./ledger.ts";
4
4
  /**
5
5
  * What the ledger says of pulses, read back: one pulse - from this session or an earlier one - as the chat and
6
- * `turri ledger` are told it, and the runs a project has had, each with its pulses.
6
+ * a host are told it, and the runs a project has had, each with its pulses.
7
7
  */
8
8
  type Of<K extends LedgerEntry["kind"]> = Extract<LedgerEntry, {
9
9
  kind: K;
@@ -48,14 +48,20 @@ export interface PulseView {
48
48
  /** A pulse's events, gathered: undefined when the ledger has none of it. `entries` are its run's, oldest first. */
49
49
  export declare function pulseView(id: string, entries: LedgerEntry[]): PulseView | undefined;
50
50
  /**
51
- * A pulse from the ledger, for the chat and `turri ledger <pulse>`: what happened in it, as facts - and, last, the
51
+ * A pulse from the ledger, for the chat's `pulses`: what happened in it, as facts - and, last, the
52
52
  * ***plain diff it regenerated, unless `diff` is false.
53
53
  */
54
54
  export declare function describePulseView(view: PulseView, options?: {
55
55
  diff?: boolean;
56
56
  }): string;
57
- /** A pulse the ledger of any of these projects knows, described - or undefined. */
58
- export declare function describePastPulse(projects: string[], id: string): string | undefined;
57
+ /**
58
+ * A pulse the ledger of any of these projects knows, described - or undefined. With `report` (the default), why one
59
+ * that did not land did not, as kept when it ended; without, the ledger's facts alone - for a pulse of this session,
60
+ * whose transcript says why.
61
+ */
62
+ export declare function describePastPulse(projects: string[], id: string, options?: {
63
+ report?: boolean;
64
+ }): string | undefined;
59
65
  /** A run of the project's, and its pulses: runs and pulses the most recent first. */
60
66
  export interface RunView {
61
67
  run: string;
@@ -64,7 +70,7 @@ export interface RunView {
64
70
  pulses: PulseView[];
65
71
  }
66
72
  export declare function runViews(project: string): RunView[];
67
- /** The project's last runs, a line a pulse: what `turri ledger` prints. */
73
+ /** The project's last runs, a line a pulse: what `pulses` lists of earlier sessions. */
68
74
  export declare function describeRuns(runs: RunView[]): string;
69
75
  /**
70
76
  * The pulses of earlier sessions, for a list beside this session's: the last `runs` runs of these projects that are not
@@ -78,23 +84,4 @@ export declare function earlierPulses(projects: string[], known: Set<string>, ru
78
84
  };
79
85
  /** A pulse of the ledger's, as the lists show a job: finished as it ended, its time and cost - and nothing to run. */
80
86
  export declare function asJob(view: PulseView): Job;
81
- /** What to count in the ledger: kinds - whole, or a group by what comes before the dot - a module, since when. */
82
- export interface EventQuery {
83
- /** `healer.failed`, or `healer` for every healer event. */
84
- kinds?: string[];
85
- module?: string;
86
- /** Only events at or after this time. */
87
- since?: Date;
88
- /** How many of the most recent to list, a line each. */
89
- limit?: number;
90
- }
91
- /** One event in a line: when, its pulse and module, its kind, its own fields - the agent's role when it has one. */
92
- export declare function eventLine(entry: LedgerEntry): string;
93
- /**
94
- * The events of these projects' ledgers that `query` asks for: how many of each kind, and the most recent, a line each -
95
- * or, when no kind asked for is in the ledger, the kinds it has.
96
- */
97
- export declare function describeEvents(projects: string[], query?: EventQuery): string;
98
- /** `24h`, `7d`, `30m`, or a date and time: the moment it means, or undefined when it means none. */
99
- export declare function sinceOf(text: string, now?: number): Date | undefined;
100
87
  export {};
@@ -3,6 +3,7 @@ import { join, resolve } from "node:path";
3
3
  import { describeUsage } from "./activity.js";
4
4
  import { formatElapsed } from "./jobs.js";
5
5
  import { LEDGER_DIR, ledgerRun, readLedger } from "./ledger.js";
6
+ import { failureReport } from "./failure-reports.js";
6
7
  /** The projects whose ledgers a folder's pulses may be in: its own, and those of the projects in folders under it. */
7
8
  export function ledgerProjects(cwd, depth = 3) {
8
9
  const found = [];
@@ -149,7 +150,7 @@ function outcomeOf(view) {
149
150
  return `${finished.status}${stopped}${landed}, after ${formatElapsed(finished.ms)}`;
150
151
  }
151
152
  /**
152
- * A pulse from the ledger, for the chat and `turri ledger <pulse>`: what happened in it, as facts - and, last, the
153
+ * A pulse from the ledger, for the chat's `pulses`: what happened in it, as facts - and, last, the
153
154
  * ***plain diff it regenerated, unless `diff` is false.
154
155
  */
155
156
  export function describePulseView(view, options = {}) {
@@ -224,13 +225,20 @@ export function describePulseView(view, options = {}) {
224
225
  lines.push(` its ***plain diff${view.steered > 0 ? ", as last steered" : ""}:`, ...view.diff.diff.trimEnd().split("\n").map((line) => ` ${line}`));
225
226
  return lines.join("\n");
226
227
  }
227
- /** A pulse the ledger of any of these projects knows, described - or undefined. */
228
- export function describePastPulse(projects, id) {
228
+ /**
229
+ * A pulse the ledger of any of these projects knows, described - or undefined. With `report` (the default), why one
230
+ * that did not land did not, as kept when it ended; without, the ledger's facts alone - for a pulse of this session,
231
+ * whose transcript says why.
232
+ */
233
+ export function describePastPulse(projects, id, options = {}) {
229
234
  for (const project of projects) {
230
235
  const entries = readLedger(project);
231
236
  const view = pulseView(id, entries);
232
- if (view !== undefined)
233
- return describePulseView(view);
237
+ if (view === undefined)
238
+ continue;
239
+ // Why one that did not land did not, as it was kept when it ended - what the ledger cannot hold.
240
+ const report = options.report === false ? undefined : failureReport(project, view.id);
241
+ return report !== undefined ? `${describePulseView(view)}\n\nWhy it did not land, as kept when it ended:\n${report}` : describePulseView(view);
234
242
  }
235
243
  return undefined;
236
244
  }
@@ -249,7 +257,7 @@ export function runViews(project) {
249
257
  })
250
258
  .reverse();
251
259
  }
252
- /** The project's last runs, a line a pulse: what `turri ledger` prints. */
260
+ /** The project's last runs, a line a pulse: what `pulses` lists of earlier sessions. */
253
261
  export function describeRuns(runs) {
254
262
  if (runs.length === 0)
255
263
  return "The ledger is empty: nothing has run here since it began.";
@@ -315,57 +323,3 @@ export function asJob(view) {
315
323
  earlier: { run: view.run, ...(view.runMode !== undefined ? { runMode: view.runMode } : {}), lines: describePulseView(view, { diff: false }).split("\n").slice(1).map((line) => line.replace(/^ /, "")) },
316
324
  };
317
325
  }
318
- /** The envelope's fields, said apart from an event's own. */
319
- const ENVELOPE = new Set(["v", "ts", "seq", "run", "job", "module", "agent", "kind"]);
320
- /** One event in a line: when, its pulse and module, its kind, its own fields - the agent's role when it has one. */
321
- export function eventLine(entry) {
322
- const fields = Object.entries(entry)
323
- .filter(([key]) => !ENVELOPE.has(key))
324
- .map(([key, value]) => {
325
- // A long value - a ***plain diff, where its lines are - cut to the start of it: the line is a glance.
326
- const whole = typeof value === "string" ? value : JSON.stringify(value);
327
- const text = typeof value === "string" ? JSON.stringify(value.length > 160 ? `${value.slice(0, 159)}…` : value) : whole.length > 160 ? `${whole.slice(0, 159)}…` : whole;
328
- return `${key}=${text}`;
329
- });
330
- const where = [entry.job, entry.module, entry.agent?.role ?? entry.agent?.label].filter((part) => part !== undefined);
331
- return [entry.ts.slice(0, 19).replace("T", " "), ...where, entry.kind, ...fields].join(" · ");
332
- }
333
- /**
334
- * The events of these projects' ledgers that `query` asks for: how many of each kind, and the most recent, a line each -
335
- * or, when no kind asked for is in the ledger, the kinds it has.
336
- */
337
- export function describeEvents(projects, query = {}) {
338
- const all = projects.flatMap((project) => readLedger(project, query.since !== undefined ? { since: query.since } : {}));
339
- const inModule = query.module !== undefined ? all.filter((entry) => entry.module === query.module) : all;
340
- const wanted = query.kinds?.map((kind) => kind.trim()).filter((kind) => kind !== "");
341
- const matches = (kind) => wanted === undefined || wanted.length === 0 || wanted.some((asked) => kind === asked || kind.startsWith(`${asked}.`));
342
- const found = inModule.filter((entry) => matches(entry.kind));
343
- const scope = [query.module !== undefined ? `in ${query.module}` : "", query.since !== undefined ? `since ${query.since.toISOString().slice(0, 16).replace("T", " ")}` : ""].filter(Boolean).join(", ");
344
- if (found.length === 0) {
345
- const kinds = [...new Set(inModule.map((entry) => entry.kind))].sort();
346
- return `No ${wanted !== undefined && wanted.length > 0 ? wanted.join(", ") : ""} events${scope !== "" ? ` ${scope}` : ""} in the ledger.${kinds.length > 0 ? ` It has: ${kinds.join(", ")}.` : ""}`;
347
- }
348
- const counts = new Map();
349
- for (const entry of found)
350
- counts.set(entry.kind, (counts.get(entry.kind) ?? 0) + 1);
351
- const pulses = new Set(found.map((entry) => entry.job).filter((job) => job !== undefined)).size;
352
- const runs = new Set(found.map((entry) => entry.run)).size;
353
- const limit = Math.max(1, query.limit ?? 20);
354
- const recent = found.slice(-limit).reverse();
355
- return [
356
- `${found.length} event${found.length === 1 ? "" : "s"}${scope !== "" ? ` ${scope}` : ""}, in ${runs} run${runs === 1 ? "" : "s"} and ${pulses} pulse${pulses === 1 ? "" : "s"}: ${[...counts].sort((a, b) => b[1] - a[1]).map(([kind, times]) => `${kind} ${times}`).join(", ")}`,
357
- "",
358
- recent.length === found.length ? "Each, newest first:" : `The last ${recent.length}, newest first:`,
359
- ...recent.map(eventLine),
360
- ].join("\n");
361
- }
362
- /** `24h`, `7d`, `30m`, or a date and time: the moment it means, or undefined when it means none. */
363
- export function sinceOf(text, now = Date.now()) {
364
- const relative = /^(\d+)\s*([mhd])$/i.exec(text.trim());
365
- if (relative !== null) {
366
- const unit = { m: 60_000, h: 3_600_000, d: 86_400_000 }[relative[2].toLowerCase()];
367
- return new Date(now - Number(relative[1]) * unit);
368
- }
369
- const date = new Date(text.trim());
370
- return Number.isNaN(date.getTime()) ? undefined : date;
371
- }
@@ -10,7 +10,7 @@ import { type UsageReport } from "./activity.ts";
10
10
  * was queued, started, went through its stages and ended, and how; what each agent's model calls and
11
11
  * turns cost; each tool call and test run, how long it took and how it ended; the gates' rounds and
12
12
  * verdicts; what turri refused or stopped; what its healers did; the history's commits. What a pulse
13
- * from an earlier session did is looked up here (`pulses`, `diagnose`, `turri ledger`) - and what it
13
+ * from an earlier session did is looked up here (`pulses`) - and what it
14
14
  * regenerated, its ***plain diff, kept whole as the one body the ledger has. Never stored: prompts,
15
15
  * replies, thinking, tool arguments and results, file contents - and what strings an event carries are
16
16
  * masked as the logs are.
@@ -246,19 +246,6 @@ export type LedgerEvent = {
246
246
  missing: string;
247
247
  source: string;
248
248
  sandbox: boolean;
249
- } | {
250
- kind: "advisor.classified";
251
- spec: string;
252
- verdict: "yes" | "no";
253
- questions: string[];
254
- asked: boolean;
255
- } | {
256
- kind: "advisor.dropped";
257
- spec: string;
258
- } | {
259
- kind: "advisor.failed";
260
- spec: string;
261
- reason: string;
262
249
  };
263
250
  export type LedgerKind = LedgerEvent["kind"];
264
251
  /** One line of the ledger: the event, and where and when it happened. */
@@ -17,7 +17,7 @@ import { ensureInScratch } from "./paths.js";
17
17
  * was queued, started, went through its stages and ended, and how; what each agent's model calls and
18
18
  * turns cost; each tool call and test run, how long it took and how it ended; the gates' rounds and
19
19
  * verdicts; what turri refused or stopped; what its healers did; the history's commits. What a pulse
20
- * from an earlier session did is looked up here (`pulses`, `diagnose`, `turri ledger`) - and what it
20
+ * from an earlier session did is looked up here (`pulses`) - and what it
21
21
  * regenerated, its ***plain diff, kept whole as the one body the ledger has. Never stored: prompts,
22
22
  * replies, thinking, tool arguments and results, file contents - and what strings an event carries are
23
23
  * masked as the logs are.
@@ -1,4 +1,3 @@
1
- import { type MarshalledPlainSource } from "../plain/spec.ts";
2
1
  import { type ChunkAgents } from "./chunk-plan.ts";
3
2
  import { type SpecGap } from "./notes.ts";
4
3
  import { type Job, type JobRegistry, type PulseCases } from "./jobs.ts";
@@ -142,25 +141,34 @@ export interface DriftReport {
142
141
  }
143
142
  /** What is left to regenerate, as the conversation and the command line read it. */
144
143
  export declare function describeDrift(reports: DriftReport[]): string;
145
- /** A codebase as the loop has just looked at it: its chain, its spec now, and what its code is built from (`codeTree` form). */
146
- export interface SeenSpec {
147
- chain: ChainEntry[];
148
- tree: MarshalledPlainSource;
149
- built: MarshalledPlainSource;
150
- }
151
144
  export interface WorkLoop {
152
145
  /**
153
146
  * Bring a spec's module up to the spec as the .plain files have it now - in the codebases where its
154
147
  * code lives, and every module it is built on that has to be built first - planning and starting the
155
- * first jobs. Asked again, it clears a halt. Also what a spec change is: the loop works out the work
156
- * again. `specChange`: brought up because its spec was changed, not asked for - a module the person halted stays
157
- * halted. Says what it planned.
148
+ * first jobs. Asked again, it clears a halt - one the person asked for too. Says what it planned.
158
149
  */
159
150
  bringUp(plainFile: string, options?: {
160
151
  model?: string;
161
152
  guidance?: string;
162
- specChange?: boolean;
163
153
  }): Promise<ModuleStatus[]>;
154
+ /**
155
+ * Plan a spec's module as `bringUp` would - the same codebases, its stack pinned, the steering and `guidance` given
156
+ * to the planner - and start nothing: the plans are kept, and its pulses held until regenerate, conform or /regenerate
157
+ * asks for the module. Then the first pulse of the kept plan starts as it is, planned again only when the ***plain,
158
+ * what it is built from or the steering changed since. A module the person halted stays halted, and a codebase whose
159
+ * chain has a pulse running goes on as it was, planning what follows it. Says what is planned.
160
+ */
161
+ lookAhead(plainFile: string, options?: {
162
+ model?: string;
163
+ guidance?: string;
164
+ }): Promise<ModuleStatus[]>;
165
+ /**
166
+ * A planned row (`planned-<module>-N`, as `planned` names it) as the loop keeps it: its cases and, for the next pulse
167
+ * of a codebase with nothing running, the whole prompt its coding agent will get - built from the kept plan, never
168
+ * planned again. Otherwise, or when the ***plain or the steering changed since the plan was made, `why` says why no
169
+ * prompt is shown. Undefined when no row has that id.
170
+ */
171
+ plannedPulse(rowId: string): Promise<PlannedPulse | undefined>;
164
172
  /**
165
173
  * Regenerate functional specs of a module again, their spec changed or not - each named by its func-id: each is marked to regenerate again in
166
174
  * the record of every codebase it is built in - committed - and they are brought up to their spec, the marked ones
@@ -230,14 +238,24 @@ export interface WorkLoop {
230
238
  mapPlan(): MapPlan;
231
239
  /** Resolves once nothing runs and nothing more can start. */
232
240
  drain(): Promise<void>;
233
- /** In a dry run: the job each codebase would start, with the spec it would be given. */
234
- firsts(): Array<{
235
- module: string;
236
- plainFile: string;
237
- buildDir: string;
238
- spec: SpecSnapshot;
239
- planned: PlannedJob;
240
- }>;
241
+ }
242
+ /** A planned pulse as `WorkLoop.plannedPulse` tells it. */
243
+ export interface PlannedPulse {
244
+ /** The planned row's id. */
245
+ id: string;
246
+ module: string;
247
+ plainFile: string;
248
+ title: string;
249
+ track: Track;
250
+ cases: JobCases;
251
+ /** Its place among the codebase's planned pulses, from 1. */
252
+ index: number;
253
+ /** Planned by a look ahead: it waits for regenerate, conform or /regenerate to start it. */
254
+ lookedAhead: boolean;
255
+ /** The coding agent's task, whole: the next pulse of a codebase with nothing running, from the kept plan. */
256
+ task?: string;
257
+ /** Why no task is shown, when none is. */
258
+ why?: string;
241
259
  }
242
260
  /** A pulse as the regeneration places it: by the items its trees differ in. */
243
261
  export interface MapPulse {
@@ -356,14 +374,6 @@ export declare function createWorkLoop(options: {
356
374
  title: string;
357
375
  onDelta: (delta: string) => void;
358
376
  }) => Promise<string>;
359
- /** Plan, and keep the job each codebase would start (`firsts`) - but start none. */
360
- dryRun?: boolean;
361
- /**
362
- * Told each time the loop looks at a codebase whose spec parses: its chain, the spec as the .plain files have it now,
363
- * and what its code is built from - what the test advisor watches (advisor-runs.ts). Nothing it does is the loop's
364
- * concern: one that throws is ignored.
365
- */
366
- onSpec?: (seen: SeenSpec) => void;
367
377
  }): WorkLoop;
368
378
  /** Why nothing runs in a codebase whose code - and conformance tests, where they are wanted - is built from its spec as it is. */
369
379
  export declare const UP_TO_DATE = "built from the ***plain as it is";
@@ -379,39 +389,6 @@ export declare function funcIdsNamed(module: string, names: string[]): string[];
379
389
  * go on. What /conform checks before it says anything.
380
390
  */
381
391
  export declare function conformanceRefusal(plainFile: string, funcIds?: string[]): string | undefined;
382
- /** The codebases the loop looks after, as the person reads them: what runs, what is planned after it, and why nothing does. */
383
- /**
384
- * The coding agent's task for a dry run's first job, built as the render builds it - and all it did rolled back. Not for
385
- * a conformance job: its prompt is built from what the code holds once it is built.
386
- */
387
- export declare function promptOf(first: ReturnType<WorkLoop["firsts"]>[number]): Promise<string | undefined>;
388
- /** The first job a codebase would start, and the prompt its coding agent would get. */
389
- export interface JobPreview {
390
- module: string;
391
- title: string;
392
- track: Track;
393
- cases: JobCases;
394
- /** The coding agent's task, whole. Not for a conformance job: it is built from what the code holds once it is built. */
395
- task?: string;
396
- }
397
- /**
398
- * What bringing a spec's module up would start, in each codebase, and the prompt of each - planned on a loop of its own
399
- * that starts nothing. A codebase `busy` says is running a job is left out: a dry run starts from its last commit, and
400
- * what the next job there is given depends on what the running one lands.
401
- */
402
- export declare function previewJobs(options: {
403
- plainFile: string;
404
- cwd: string;
405
- model?: string;
406
- plannerModel?: string;
407
- steering?: (plainFile: string) => Steering[];
408
- /** Whether a codebase, by its module, has a job running. */
409
- busy?: (module: string) => boolean;
410
- }): Promise<{
411
- statuses: ModuleStatus[];
412
- previews: JobPreview[];
413
- busy: string[];
414
- }>;
415
392
  /** Nothing runs, is planned or is waiting there, as its code is built from its spec as it is. */
416
393
  export declare function isUpToDate(status: ModuleStatus): boolean;
417
394
  export declare function describeModules(statuses: ModuleStatus[], options?: {