@turri-dev/cli 0.2.4-next.8422d0f → 0.2.4-next.bc1fc47
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.
- package/README.md +3 -3
- package/dist/chat-idle.d.ts +2 -2
- package/dist/chat-idle.js +2 -2
- package/dist/chats.d.ts +0 -10
- package/dist/chats.js +0 -23
- package/dist/cli.js +5 -7
- package/dist/config-edit.js +1 -3
- package/dist/config.d.ts +20 -22
- package/dist/config.js +49 -22
- package/dist/conform-cli.js +13 -2
- package/dist/conformance-switch.d.ts +7 -17
- package/dist/conformance-switch.js +24 -46
- package/dist/drift-cli.js +1 -1
- package/dist/extension.d.ts +8 -10
- package/dist/extension.js +188 -242
- package/dist/genome.js +9 -48
- package/dist/graph.js +3 -5
- package/dist/host-session.d.ts +4 -15
- package/dist/host-session.js +2 -4
- package/dist/host.d.ts +1 -3
- package/dist/host.js +1 -4
- package/dist/identity.js +0 -1
- package/dist/init-config.d.ts +0 -1
- package/dist/init-config.js +2 -9
- package/dist/installed-providers.d.ts +1 -1
- package/dist/installed-providers.js +1 -1
- package/dist/loop-cli.d.ts +4 -3
- package/dist/loop-cli.js +13 -11
- package/dist/loop-tools.d.ts +28 -5
- package/dist/loop-tools.js +87 -22
- package/dist/new-project.js +2 -2
- package/dist/pi-launch.js +1 -1
- package/dist/pi.js +9 -6
- package/dist/plain/check.d.ts +1 -8
- package/dist/plain/check.js +3 -38
- package/dist/regenerate/activity.d.ts +0 -7
- package/dist/regenerate/activity.js +2 -20
- package/dist/regenerate/agent-shell.js +3 -1
- package/dist/regenerate/audit.js +9 -0
- package/dist/regenerate/cases.js +7 -0
- package/dist/regenerate/chunk-plan.d.ts +5 -0
- package/dist/regenerate/chunk-plan.js +16 -1
- package/dist/regenerate/drift.d.ts +4 -0
- package/dist/regenerate/drift.js +26 -6
- package/dist/regenerate/failure-reports.d.ts +28 -0
- package/dist/regenerate/failure-reports.js +79 -0
- package/dist/regenerate/job-panel.js +3 -1
- package/dist/regenerate/jobs-tree.js +1 -1
- package/dist/regenerate/jobs.d.ts +2 -0
- package/dist/regenerate/jobs.js +4 -0
- package/dist/regenerate/ledger-view.d.ts +11 -24
- package/dist/regenerate/ledger-view.js +14 -60
- package/dist/regenerate/ledger.d.ts +1 -14
- package/dist/regenerate/ledger.js +1 -1
- package/dist/regenerate/loop.d.ts +46 -60
- package/dist/regenerate/loop.js +277 -116
- package/dist/regenerate/records.d.ts +11 -0
- package/dist/regenerate/records.js +15 -0
- package/dist/regenerate/regenerate.d.ts +0 -2
- package/dist/regenerate/regenerate.js +4 -15
- package/dist/regenerate/renames.js +4 -4
- package/dist/regenerate/requires.d.ts +7 -0
- package/dist/regenerate/requires.js +24 -18
- package/dist/regenerate/spec-map.js +3 -3
- package/dist/regenerate/standing.js +1 -1
- package/dist/regenerate/submit-work.d.ts +2 -0
- package/dist/regenerate/submit-work.js +8 -3
- package/dist/regenerate/testing-steps.d.ts +11 -0
- package/dist/regenerate/testing-steps.js +22 -3
- package/dist/regenerate-cli.js +18 -9
- package/dist/self-invocation.d.ts +11 -0
- package/dist/self-invocation.js +33 -7
- package/dist/sentinel.js +8 -5
- package/dist/skill.d.ts +0 -11
- package/dist/skill.js +0 -9
- package/dist/stacks.js +1 -1
- package/dist/tools.js +2 -3
- package/dist/turri-versions.js +2 -1
- package/docs/README.md +0 -2
- package/docs/authoring-plain.md +3 -3
- package/docs/chats.md +1 -3
- package/docs/config.md +11 -13
- package/docs/deploy.md +1 -1
- package/docs/development.md +2 -3
- package/docs/headless.md +6 -4
- package/docs/hosting.md +6 -6
- package/docs/parser.md +2 -2
- package/docs/regenerating.md +21 -13
- package/docs/sentinel.md +4 -4
- package/docs/skills-and-gates.md +4 -8
- package/docs/using.md +13 -21
- package/genome/rules/test-plain-files.md +15 -7
- package/genome/rules/turri-regeneration.md +4 -8
- package/genome/skills/convert-old-syntax/SKILL.md +5 -5
- package/package.json +1 -1
- package/dist/advisor-chat.d.ts +0 -63
- package/dist/advisor-chat.js +0 -290
- package/dist/change-plain-cli.d.ts +0 -1
- package/dist/change-plain-cli.js +0 -55
- package/dist/ledger-cli.d.ts +0 -1
- package/dist/ledger-cli.js +0 -50
- package/dist/ledger-tools.d.ts +0 -10
- package/dist/ledger-tools.js +0 -64
- package/dist/regenerate/advisor-records.d.ts +0 -93
- package/dist/regenerate/advisor-records.js +0 -110
- package/dist/regenerate/advisor-runs.d.ts +0 -87
- package/dist/regenerate/advisor-runs.js +0 -327
- package/dist/regenerate/test-advisor.d.ts +0 -101
- package/dist/regenerate/test-advisor.js +0 -379
- package/dist/spec-tools.d.ts +0 -36
- package/dist/spec-tools.js +0 -128
- package/docs/test-advisor.md +0 -110
|
@@ -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
|
-
|
|
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 -
|
|
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;
|
package/dist/regenerate/jobs.js
CHANGED
|
@@ -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
|
-
*
|
|
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
|
|
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
|
-
/**
|
|
58
|
-
|
|
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 `
|
|
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
|
|
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
|
-
/**
|
|
228
|
-
|
|
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
|
|
233
|
-
|
|
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 `
|
|
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
|
|
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
|
|
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
|
|
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
|
|
@@ -180,11 +188,20 @@ export interface WorkLoop {
|
|
|
180
188
|
* Write and run the conformance tests of a spec's module - of the functional specs named, or of every one - on the
|
|
181
189
|
* code as it is built, in the codebases where its code lives: for this session, whatever the config says. Asked
|
|
182
190
|
* again, it clears a halt. Says what it planned.
|
|
191
|
+
*
|
|
192
|
+
* A functional spec named whose tests are written already has them written again: marked in the tests record of
|
|
193
|
+
* every codebase it is tested in - committed - and written anew there, its code untouched. `fromScratch` works where
|
|
194
|
+
* its code lives, as regenerating it from scratch does - the tip of each chain it is built in, never a codebase in the
|
|
195
|
+
* middle: the tip's tests folder taken out - committed first, so its history keeps it - and the tests written again
|
|
196
|
+
* there: `"module"` starting from a copy of the tests of the module the tip requires, `"chain"` from nothing, every
|
|
197
|
+
* functional spec of the chain written anew. The code is untouched, and nothing else is. Destructive: asked for only
|
|
198
|
+
* when the person asked for it. Not both: from scratch writes every one of them again.
|
|
183
199
|
*/
|
|
184
200
|
conformance(plainFile: string, options?: {
|
|
185
201
|
funcIds?: string[];
|
|
186
202
|
model?: string;
|
|
187
203
|
separately?: boolean;
|
|
204
|
+
fromScratch?: "module" | "chain";
|
|
188
205
|
}): Promise<ModuleStatus[]>;
|
|
189
206
|
/**
|
|
190
207
|
* Start over the codebases of a spec's module that now require a module their code was not built on (see
|
|
@@ -230,14 +247,24 @@ export interface WorkLoop {
|
|
|
230
247
|
mapPlan(): MapPlan;
|
|
231
248
|
/** Resolves once nothing runs and nothing more can start. */
|
|
232
249
|
drain(): Promise<void>;
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
250
|
+
}
|
|
251
|
+
/** A planned pulse as `WorkLoop.plannedPulse` tells it. */
|
|
252
|
+
export interface PlannedPulse {
|
|
253
|
+
/** The planned row's id. */
|
|
254
|
+
id: string;
|
|
255
|
+
module: string;
|
|
256
|
+
plainFile: string;
|
|
257
|
+
title: string;
|
|
258
|
+
track: Track;
|
|
259
|
+
cases: JobCases;
|
|
260
|
+
/** Its place among the codebase's planned pulses, from 1. */
|
|
261
|
+
index: number;
|
|
262
|
+
/** Planned by a look ahead: it waits for regenerate, conform or /regenerate to start it. */
|
|
263
|
+
lookedAhead: boolean;
|
|
264
|
+
/** The coding agent's task, whole: the next pulse of a codebase with nothing running, from the kept plan. */
|
|
265
|
+
task?: string;
|
|
266
|
+
/** Why no task is shown, when none is. */
|
|
267
|
+
why?: string;
|
|
241
268
|
}
|
|
242
269
|
/** A pulse as the regeneration places it: by the items its trees differ in. */
|
|
243
270
|
export interface MapPulse {
|
|
@@ -356,14 +383,6 @@ export declare function createWorkLoop(options: {
|
|
|
356
383
|
title: string;
|
|
357
384
|
onDelta: (delta: string) => void;
|
|
358
385
|
}) => 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
386
|
}): WorkLoop;
|
|
368
387
|
/** Why nothing runs in a codebase whose code - and conformance tests, where they are wanted - is built from its spec as it is. */
|
|
369
388
|
export declare const UP_TO_DATE = "built from the ***plain as it is";
|
|
@@ -379,39 +398,6 @@ export declare function funcIdsNamed(module: string, names: string[]): string[];
|
|
|
379
398
|
* go on. What /conform checks before it says anything.
|
|
380
399
|
*/
|
|
381
400
|
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
401
|
/** Nothing runs, is planned or is waiting there, as its code is built from its spec as it is. */
|
|
416
402
|
export declare function isUpToDate(status: ModuleStatus): boolean;
|
|
417
403
|
export declare function describeModules(statuses: ModuleStatus[], options?: {
|