@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.
- package/README.md +57 -62
- package/dist/bedrock-region.js +3 -3
- package/dist/chat-idle.d.ts +2 -2
- package/dist/chat-idle.js +2 -2
- package/dist/chat-models.d.ts +1 -1
- package/dist/chat-models.js +1 -1
- package/dist/chat-scope.d.ts +1 -3
- package/dist/chat-skills.d.ts +1 -1
- package/dist/chat-skills.js +1 -1
- package/dist/chats.d.ts +44 -20
- package/dist/chats.js +125 -64
- package/dist/cli.js +42 -31
- package/dist/config-edit.d.ts +20 -8
- package/dist/config-edit.js +32 -26
- package/dist/config.d.ts +106 -78
- package/dist/config.js +267 -133
- package/dist/conform-cli.js +14 -3
- package/dist/conformance-switch.d.ts +13 -22
- package/dist/conformance-switch.js +37 -59
- package/dist/drift-cli.js +1 -1
- package/dist/extension.d.ts +31 -12
- package/dist/extension.js +555 -556
- package/dist/genome.js +10 -49
- package/dist/graph.js +3 -5
- package/dist/host-session.d.ts +11 -21
- package/dist/host-session.js +6 -8
- package/dist/host.d.ts +4 -4
- package/dist/host.js +4 -7
- package/dist/identity.js +2 -3
- package/dist/init-config.d.ts +1 -2
- package/dist/init-config.js +10 -17
- package/dist/installed-providers.d.ts +1 -1
- package/dist/installed-providers.js +2 -2
- package/dist/launch-agent.d.ts +41 -0
- package/dist/launch-agent.js +219 -0
- package/dist/{release-cli.js → launch-cli.js} +41 -24
- package/dist/launch-session.d.ts +58 -0
- package/dist/launch-session.js +195 -0
- package/dist/launch-tools.d.ts +28 -0
- package/dist/launch-tools.js +69 -0
- package/dist/launch-track.d.ts +120 -0
- package/dist/launch-track.js +298 -0
- package/dist/loop-cli.d.ts +4 -3
- package/dist/loop-cli.js +17 -15
- package/dist/loop-tools.d.ts +45 -21
- package/dist/loop-tools.js +155 -90
- package/dist/new-project.js +2 -2
- package/dist/notice.d.ts +7 -6
- package/dist/parse-cli.js +2 -2
- package/dist/pi-launch.js +4 -1
- package/dist/pi-settings.d.ts +4 -0
- package/dist/pi-settings.js +39 -0
- package/dist/pi.js +12 -9
- package/dist/plain/check.d.ts +2 -9
- package/dist/plain/check.js +6 -39
- package/dist/plain-files.d.ts +2 -2
- package/dist/plain-files.js +7 -7
- package/dist/regenerate/activity.d.ts +0 -7
- package/dist/regenerate/activity.js +2 -20
- package/dist/regenerate/agent-env.d.ts +1 -1
- package/dist/regenerate/agent-env.js +3 -3
- package/dist/regenerate/agent-shell.js +5 -3
- package/dist/regenerate/audit.js +9 -0
- package/dist/regenerate/base-folder.d.ts +2 -2
- package/dist/regenerate/base-folder.js +1 -1
- 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/command-check.d.ts +1 -1
- package/dist/regenerate/command-check.js +1 -1
- package/dist/regenerate/delivery.d.ts +1 -1
- package/dist/regenerate/delivery.js +3 -3
- 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 +4 -2
- package/dist/regenerate/jobs.js +14 -10
- package/dist/regenerate/launch.d.ts +126 -0
- package/dist/regenerate/{release.js → launch.js} +60 -48
- package/dist/regenerate/ledger-view.d.ts +11 -24
- package/dist/regenerate/ledger-view.js +14 -60
- package/dist/regenerate/ledger.d.ts +26 -16
- package/dist/regenerate/ledger.js +1 -1
- package/dist/regenerate/lineage.d.ts +2 -0
- package/dist/regenerate/lineage.js +8 -0
- package/dist/regenerate/loop.d.ts +57 -65
- package/dist/regenerate/loop.js +354 -171
- package/dist/regenerate/model-names.d.ts +33 -0
- package/dist/regenerate/{engine.js → model-names.js} +2 -28
- package/dist/regenerate/paths.d.ts +3 -3
- package/dist/regenerate/paths.js +4 -4
- 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/scripts-being-written.d.ts +4 -4
- package/dist/regenerate/scripts-being-written.js +3 -3
- 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/test-scripts.d.ts +2 -1
- package/dist/regenerate/test-scripts.js +33 -23
- package/dist/regenerate/testing-steps.d.ts +16 -5
- package/dist/regenerate/testing-steps.js +28 -9
- package/dist/regenerate-cli.js +18 -9
- package/dist/self-invocation.d.ts +11 -0
- package/dist/self-invocation.js +37 -11
- package/dist/sentinel-check.d.ts +3 -3
- package/dist/sentinel-check.js +3 -3
- package/dist/sentinel.d.ts +17 -12
- package/dist/sentinel.js +75 -46
- package/dist/{config-command.d.ts → settings.d.ts} +13 -8
- package/dist/{config-command.js → settings.js} +155 -24
- package/dist/setup.d.ts +2 -2
- package/dist/setup.js +7 -7
- package/dist/skill.d.ts +0 -11
- package/dist/skill.js +0 -9
- package/dist/tools.js +2 -3
- package/dist/turri-versions.js +2 -1
- package/docs/README.md +4 -6
- package/docs/authoring-plain.md +3 -3
- package/docs/chats.md +6 -9
- package/docs/claude-subscription.md +8 -8
- package/docs/config.md +62 -52
- package/docs/development.md +4 -5
- package/docs/headless.md +7 -6
- package/docs/hosting.md +25 -24
- package/docs/installation.md +4 -0
- package/docs/launch.md +63 -0
- package/docs/parser.md +3 -3
- package/docs/regenerating.md +30 -22
- package/docs/sandbox.md +3 -3
- package/docs/sentinel.md +27 -16
- package/docs/skills-and-gates.md +6 -11
- package/docs/using.md +26 -42
- package/genome/rules/project-model.md +2 -1
- package/genome/rules/test-plain-files.md +15 -7
- package/genome/rules/turri-regeneration.md +7 -10
- package/genome/skills/convert-old-syntax/SKILL.md +5 -5
- package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
- package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
- 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.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/engine.d.ts +0 -52
- package/dist/regenerate/release.d.ts +0 -121
- package/dist/regenerate/test-advisor.d.ts +0 -101
- package/dist/regenerate/test-advisor.js +0 -379
- package/dist/release-agent.d.ts +0 -43
- package/dist/release-agent.js +0 -130
- package/dist/release-cli.d.ts +0 -1
- package/dist/release-tools.d.ts +0 -44
- package/dist/release-tools.js +0 -170
- package/dist/spec-tools.d.ts +0 -36
- package/dist/spec-tools.js +0 -128
- package/dist/stacks.d.ts +0 -13
- package/dist/stacks.js +0 -96
- package/docs/deploy.md +0 -48
- package/docs/test-advisor.md +0 -110
- /package/dist/{change-plain-cli.d.ts → launch-cli.d.ts} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { Type } from "typebox";
|
|
4
|
+
import { refuseTestPlainFile } from "./test-plain-files.js";
|
|
5
|
+
/**
|
|
6
|
+
* The chat's launch tool (docs/launch.md): it asks the launch track for a launch of a codebase's last commit and returns
|
|
7
|
+
* at once - the launch agent works in the background, and the chat is told how it went once it ends. The harness does
|
|
8
|
+
* the parts that must hold - exporting the commit, stopping what the last launch started, owning what this one starts -
|
|
9
|
+
* and the agent the rest.
|
|
10
|
+
*/
|
|
11
|
+
export function launchTool(options) {
|
|
12
|
+
return defineTool({
|
|
13
|
+
name: "launch",
|
|
14
|
+
label: "Launch",
|
|
15
|
+
description: "Launch what is regenerated for the person to try, in the background: the last commit of the module on top of the " +
|
|
16
|
+
"spec's requires chain, which holds the code of the ones below, exported to dist/<module>, and an agent that starts it " +
|
|
17
|
+
"on this machine - or, with guidance, follows it from the host codebase: an integration a host application loads, " +
|
|
18
|
+
"say, put in place with the host's scripts. Before you call it, ask yourself whether there is guidance for launching " +
|
|
19
|
+
"this project - in what the person said, AGENTS.md, a skill - and pass it in full. It returns at once; you are told " +
|
|
20
|
+
"where it runs, or why it did not come up, once it ends. When what is launched is that code already, it does nothing " +
|
|
21
|
+
"and says so. Under launch-after-pulse turri launches what each pulse lands itself: never call it for that.",
|
|
22
|
+
promptSnippet: "launch the regenerated code for the person to try, in the background - as the project's guidance says, or from dist/<module>",
|
|
23
|
+
parameters: Type.Object({
|
|
24
|
+
plain_file: Type.Optional(Type.String({ description: "A .plain file of the module. Default: the project's module from config.turri.yaml." })),
|
|
25
|
+
in_module: Type.Optional(Type.String({ description: "The codebase to take, when modules built on this one branch" })),
|
|
26
|
+
again: Type.Optional(Type.Boolean({ description: "Launch even when its code is out already - only when the last launch did not leave it as the person needs it, or they want it launched some other way." })),
|
|
27
|
+
guidance: Type.Optional(Type.String({ description: "The guidance for launching this project, whole, from wherever it is - the person, AGENTS.md, a skill: the scripts to run and in which order, where the code goes. Omit when there is none." })),
|
|
28
|
+
}),
|
|
29
|
+
async execute(_id, params, _signal, _onUpdate, ctx) {
|
|
30
|
+
const named = params.plain_file ?? options.defaultPlainFile();
|
|
31
|
+
if (named === undefined)
|
|
32
|
+
throw new Error("Which spec? config.turri.yaml names no module: pass plain_file.");
|
|
33
|
+
const plainFile = resolve(options.cwd, named);
|
|
34
|
+
refuseTestPlainFile(plainFile);
|
|
35
|
+
const chat = options.chat();
|
|
36
|
+
const { launch, already } = options.track.request({
|
|
37
|
+
plainFile,
|
|
38
|
+
...(params.in_module !== undefined ? { inModule: params.in_module } : {}),
|
|
39
|
+
...(params.guidance !== undefined ? { guidance: params.guidance } : {}),
|
|
40
|
+
...(params.again === true ? { again: true } : {}),
|
|
41
|
+
cause: chat !== undefined ? { chat } : {},
|
|
42
|
+
});
|
|
43
|
+
const details = { launch: launch.id, module: launch.codebase, commit: launch.short, already };
|
|
44
|
+
if (already) {
|
|
45
|
+
return {
|
|
46
|
+
content: [{ type: "text", text: `Out already: what runs of ${launch.codebase} is its code at ${launch.short} - nothing was done, and what runs is left running.${launch.summary !== undefined ? `\n${launch.summary}` : ""}\nSay so in a line.` }],
|
|
47
|
+
details,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Where the process ends with the reply, the call waits: a launch left running would end with it.
|
|
51
|
+
if (ctx !== undefined && options.wait?.(ctx) === true) {
|
|
52
|
+
const ended = await options.track.done(launch.id);
|
|
53
|
+
const where = ended.status === "launched" ? `${ended.codebase} at ${ended.short} is launched` : ended.status === "stopped" ? `The launch of ${ended.codebase} was stopped` : `The launch of ${ended.codebase} at ${ended.short} did not come up`;
|
|
54
|
+
return {
|
|
55
|
+
content: [{ type: "text", text: `${where} (${ended.id}).\n${(ended.summary ?? "").trim()}\nTell the person where it runs, or why it did not come up.` }],
|
|
56
|
+
details: { ...details, status: ended.status },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
void options.track.done(launch.id).then(options.ended, () => undefined);
|
|
60
|
+
if (options.replaced !== undefined)
|
|
61
|
+
void options.track.replaced(launch.id).then((next) => options.replaced(launch, next), () => undefined);
|
|
62
|
+
const behind = launch.status === "waiting" ? " - after the launch of it under way" : "";
|
|
63
|
+
return {
|
|
64
|
+
content: [{ type: "text", text: `Launching ${launch.codebase} at ${launch.short} in the background (${launch.id})${behind}. You are told where it runs, or why it did not come up, once it ends: say so in a line, and start nothing for it.` }],
|
|
65
|
+
details,
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { type ExportedCode, type LaunchedProcess } from "./regenerate/launch.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The launch track (docs/launch.md): each codebase's launches, one at a time, the newest commit winning. A pulse that lands
|
|
4
|
+
* under `launch-after-pulse` asks for one with the commit it landed, and so does the chat's launch tool with the codebase's
|
|
5
|
+
* last: neither waits for it, and no pulse waits on it. While one runs, a newer commit asked for waits as the next, and
|
|
6
|
+
* replaces any older one waiting - a commit nobody will try is never launched, and the one after it holds its code.
|
|
7
|
+
*
|
|
8
|
+
* What is launched is recorded - the codebase, the commit, what it started, whether it came up - and the sentinel tests a
|
|
9
|
+
* pulse only in a launch whose commit holds the pulse's (`holds`).
|
|
10
|
+
*/
|
|
11
|
+
export type LaunchStatus = "waiting" | "running" | "launched" | "failed" | "stopped" | "superseded";
|
|
12
|
+
/** Why a launch was asked for: a pulse landed, under launch-after-pulse - or a chat, or `turri launch`, asked. */
|
|
13
|
+
export type LaunchCause = {
|
|
14
|
+
pulse: string;
|
|
15
|
+
title: string;
|
|
16
|
+
} | {
|
|
17
|
+
chat?: string;
|
|
18
|
+
};
|
|
19
|
+
export interface Launch {
|
|
20
|
+
id: string;
|
|
21
|
+
/** The codebase: the module whose `plain_modules/<module>` holds the code. */
|
|
22
|
+
codebase: string;
|
|
23
|
+
/** `plain_modules/<module>`: its history is there. */
|
|
24
|
+
moduleDir: string;
|
|
25
|
+
plainFile: string;
|
|
26
|
+
inModule?: string;
|
|
27
|
+
/** The commit it launches, whole. */
|
|
28
|
+
commit: string;
|
|
29
|
+
short: string;
|
|
30
|
+
/** The host codebase a launch with guidance works in: the git repository the project is in, else where turri runs. */
|
|
31
|
+
hostDir: string;
|
|
32
|
+
/** How this project launches it, as the person or the chat said it. */
|
|
33
|
+
guidance?: string;
|
|
34
|
+
cause: LaunchCause;
|
|
35
|
+
status: LaunchStatus;
|
|
36
|
+
queuedAt: number;
|
|
37
|
+
startedAt?: number;
|
|
38
|
+
finishedAt?: number;
|
|
39
|
+
/** What the agent said it did - where it runs - or why it did not come up. */
|
|
40
|
+
summary?: string;
|
|
41
|
+
/** Its code, once exported. */
|
|
42
|
+
code?: ExportedCode;
|
|
43
|
+
/** When what runs for it was started: a launch that found its code out already keeps the one before it's. */
|
|
44
|
+
serversSince?: number;
|
|
45
|
+
/** It found the commit's code out already: nothing exported, stopped or started. */
|
|
46
|
+
already?: true;
|
|
47
|
+
/** Superseded while it waited: the launch that took its place. */
|
|
48
|
+
supersededBy?: string;
|
|
49
|
+
/**
|
|
50
|
+
* It ended with a newer launch of its codebase waiting, which starts at once and stops what it started: the launch
|
|
51
|
+
* that takes its place. Its own status stays what it was - launched, say - for as long as that runs.
|
|
52
|
+
*/
|
|
53
|
+
replacedBy?: string;
|
|
54
|
+
/** Asked for even were its code out already. */
|
|
55
|
+
again?: true;
|
|
56
|
+
}
|
|
57
|
+
export interface LaunchOutcome {
|
|
58
|
+
launched: boolean;
|
|
59
|
+
summary: string;
|
|
60
|
+
}
|
|
61
|
+
export interface LaunchRequest {
|
|
62
|
+
/** A .plain file of the codebase - its tip, or a module whose codebase it is. */
|
|
63
|
+
plainFile: string;
|
|
64
|
+
/** The codebase to take, when modules built on this one branch. */
|
|
65
|
+
inModule?: string;
|
|
66
|
+
/** The commit to launch - the one a pulse landed. Default: the codebase's last. */
|
|
67
|
+
commit?: string;
|
|
68
|
+
/** How this project launches it - kept for the codebase's launches after it. */
|
|
69
|
+
guidance?: string;
|
|
70
|
+
/** Launch even when its code is out already. */
|
|
71
|
+
again?: boolean;
|
|
72
|
+
cause: LaunchCause;
|
|
73
|
+
}
|
|
74
|
+
export interface LaunchTrack {
|
|
75
|
+
/**
|
|
76
|
+
* Ask for a launch: queued, never waited for. `already` when nothing is under way for the codebase and its code is out
|
|
77
|
+
* already - the same code, nothing it started ended: then nothing is done, and what runs is left.
|
|
78
|
+
*/
|
|
79
|
+
request(input: LaunchRequest): {
|
|
80
|
+
launch: Launch;
|
|
81
|
+
already: boolean;
|
|
82
|
+
};
|
|
83
|
+
/** The codebase's last launch that ended - launched or failed - what runs being its. */
|
|
84
|
+
current(codebase: string): Launch | undefined;
|
|
85
|
+
/** A launch of the codebase running, or waiting. */
|
|
86
|
+
pending(codebase: string): Launch | undefined;
|
|
87
|
+
/** Resolves once nothing of the codebase's is running or waiting. */
|
|
88
|
+
settled(codebase: string): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Resolves with the launch once it ends - or, superseded as it waited or replaced as it ended, with the one that took
|
|
91
|
+
* its place once that ends.
|
|
92
|
+
*/
|
|
93
|
+
done(id: string): Promise<Launch>;
|
|
94
|
+
/**
|
|
95
|
+
* Resolves with the launch that takes this one's place - superseded as it waited, or ended with a newer one waiting,
|
|
96
|
+
* which stops what it started - as soon as it does. Never resolves for a launch nothing takes the place of.
|
|
97
|
+
*/
|
|
98
|
+
replaced(id: string): Promise<Launch>;
|
|
99
|
+
/** Whether what runs for the codebase holds `commit`: its last launch's commit is it, or one built on it. */
|
|
100
|
+
holds(codebase: string, commit: string): boolean;
|
|
101
|
+
/** Stop the codebase's launch under way and the one waiting - every codebase's, none named. Returns what was stopped. */
|
|
102
|
+
stop(codebase?: string): Promise<string[]>;
|
|
103
|
+
/**
|
|
104
|
+
* What launches started was stopped on request (`/halt launched`): the codebase's last launch - every codebase's, none
|
|
105
|
+
* named - that has nothing left running is stopped, nothing of it runs, and the next launch of it launches anew. Told
|
|
106
|
+
* as any launch's end is. Returns the launches stopped.
|
|
107
|
+
*/
|
|
108
|
+
halted(codebase?: string): string[];
|
|
109
|
+
list(): Launch[];
|
|
110
|
+
/** What the codebase's last launch started, still running. */
|
|
111
|
+
running(codebase: string): LaunchedProcess[];
|
|
112
|
+
}
|
|
113
|
+
export declare function createLaunchTrack(options: {
|
|
114
|
+
cwd: string;
|
|
115
|
+
/** The agent that takes exported code on and starts it. */
|
|
116
|
+
run: (launch: Launch, code: ExportedCode, signal: AbortSignal) => Promise<LaunchOutcome>;
|
|
117
|
+
onChange?: (launch: Launch) => void;
|
|
118
|
+
}): LaunchTrack;
|
|
119
|
+
/** A launch in a line: its codebase, commit, how it stands - for /halt, pulses and the panel. */
|
|
120
|
+
export declare function describeLaunchLine(launch: Launch): string;
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
2
|
+
import { codeTreeOf, exportModule, holdsCommit, hostDirOf, launchTarget, listLaunched, runningLaunched, stopLaunched } from "./regenerate/launch.js";
|
|
3
|
+
import { record } from "./regenerate/ledger.js";
|
|
4
|
+
/** How many ended launches are kept to list. */
|
|
5
|
+
const KEPT = 50;
|
|
6
|
+
export function createLaunchTrack(options) {
|
|
7
|
+
const codebases = new Map();
|
|
8
|
+
const launches = [];
|
|
9
|
+
const ends = new Map();
|
|
10
|
+
const takenOver = new Map();
|
|
11
|
+
let count = 0;
|
|
12
|
+
const stateOf = (codebase, moduleDir) => {
|
|
13
|
+
let state = codebases.get(codebase);
|
|
14
|
+
if (state === undefined) {
|
|
15
|
+
state = { moduleDir, settledWaiters: [] };
|
|
16
|
+
codebases.set(codebase, state);
|
|
17
|
+
}
|
|
18
|
+
state.moduleDir = moduleDir;
|
|
19
|
+
return state;
|
|
20
|
+
};
|
|
21
|
+
const changed = (launch) => {
|
|
22
|
+
try {
|
|
23
|
+
options.onChange?.(launch);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
/* one that listens and fails is left out of this change */
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const ended = (launch) => ends.get(launch.id)?.resolve(launch);
|
|
30
|
+
/** `next` takes `launch`'s place: whoever waits on `launch` hears `next`'s end, and that it took over, now. */
|
|
31
|
+
const handOn = (launch, next) => {
|
|
32
|
+
takenOver.get(launch.id)?.resolve(next);
|
|
33
|
+
void track.done(next.id).then((last) => ends.get(launch.id)?.resolve(last));
|
|
34
|
+
};
|
|
35
|
+
const finished = (launch) => record({ kind: "launch.finished", launch: launch.id, commit: launch.short, status: launch.status, ms: (launch.finishedAt ?? Date.now()) - (launch.startedAt ?? launch.queuedAt) }, place(launch));
|
|
36
|
+
const place = (launch) => ({ project: options.cwd, module: launch.codebase });
|
|
37
|
+
/**
|
|
38
|
+
* What runs for the codebase is the commit's code: the same code, nothing it started has ended. Guidance is not
|
|
39
|
+
* compared: the agent finds the project's itself, and the chat passing it on says nothing new - `again` launches anew.
|
|
40
|
+
*/
|
|
41
|
+
const isOut = (state, commit) => {
|
|
42
|
+
const current = state.current;
|
|
43
|
+
if (current === undefined || current.status !== "launched")
|
|
44
|
+
return undefined;
|
|
45
|
+
if (!holdsCommit(state.moduleDir, current.commit, commit) && !holdsCommit(state.moduleDir, commit, current.commit))
|
|
46
|
+
return undefined;
|
|
47
|
+
const tree = codeTreeOf(state.moduleDir, commit);
|
|
48
|
+
if (tree === undefined || tree !== codeTreeOf(state.moduleDir, current.commit))
|
|
49
|
+
return undefined;
|
|
50
|
+
const since = current.serversSince ?? current.startedAt ?? 0;
|
|
51
|
+
const started = listLaunched().filter((item) => item.moduleName === current.codebase && item.startedAt >= since);
|
|
52
|
+
return started.some((item) => item.exited !== undefined) ? undefined : current;
|
|
53
|
+
};
|
|
54
|
+
const settle = (state) => {
|
|
55
|
+
if (state.running !== undefined || state.waiting !== undefined)
|
|
56
|
+
return;
|
|
57
|
+
for (const resolve of state.settledWaiters.splice(0))
|
|
58
|
+
resolve();
|
|
59
|
+
};
|
|
60
|
+
const keep = (launch) => {
|
|
61
|
+
launches.push(launch);
|
|
62
|
+
while (launches.length > KEPT) {
|
|
63
|
+
const first = launches.findIndex((each) => each.status !== "waiting" && each.status !== "running");
|
|
64
|
+
if (first === -1)
|
|
65
|
+
break;
|
|
66
|
+
launches.splice(first, 1);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* A launch whose commit's code is what runs already - a pulse that landed only tests, say, or the chat asking for what
|
|
71
|
+
* runs: ended as launched at once, `already`, nothing stopped or started - nor anyone told it is launching. What runs
|
|
72
|
+
* is its own from then on, when its commit is built on what ran: it holds both. Told as any launch's end is.
|
|
73
|
+
*/
|
|
74
|
+
const outAlready = (state, launch, out) => {
|
|
75
|
+
launch.status = "launched";
|
|
76
|
+
launch.already = true;
|
|
77
|
+
launch.startedAt = Date.now();
|
|
78
|
+
launch.serversSince = out.serversSince ?? out.startedAt ?? 0;
|
|
79
|
+
launch.summary = out.summary ?? `${launch.codebase} at ${out.short} runs already.`;
|
|
80
|
+
launch.finishedAt = Date.now();
|
|
81
|
+
if (holdsCommit(state.moduleDir, out.commit, launch.commit))
|
|
82
|
+
state.current = launch;
|
|
83
|
+
finish(state, launch);
|
|
84
|
+
};
|
|
85
|
+
const start = (state, launch) => {
|
|
86
|
+
// Found out already as it waited.
|
|
87
|
+
const out = launch.again === true ? undefined : isOut(state, launch.commit);
|
|
88
|
+
if (out !== undefined) {
|
|
89
|
+
outAlready(state, launch, out);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const abort = new AbortController();
|
|
93
|
+
state.running = { launch, abort };
|
|
94
|
+
launch.status = "running";
|
|
95
|
+
launch.startedAt = Date.now();
|
|
96
|
+
changed(launch);
|
|
97
|
+
record({ kind: "launch.started", launch: launch.id, commit: launch.short, ...("pulse" in launch.cause ? { pulse: launch.cause.pulse } : {}) }, place(launch));
|
|
98
|
+
void runIt(state, launch, abort);
|
|
99
|
+
};
|
|
100
|
+
const runIt = async (state, launch, abort) => {
|
|
101
|
+
// Halted, it is let go at once: what the agent does after is nobody's.
|
|
102
|
+
const halted = new Promise((_, reject) => abort.signal.addEventListener("abort", () => reject(new Error("stopped")), { once: true }));
|
|
103
|
+
halted.catch(() => undefined);
|
|
104
|
+
try {
|
|
105
|
+
// What the last launch started runs from what is about to be replaced.
|
|
106
|
+
await stopLaunched({ moduleName: launch.codebase });
|
|
107
|
+
const code = exportModule(launch.plainFile, { ...(launch.inModule !== undefined ? { inModule: launch.inModule } : {}), commit: launch.commit });
|
|
108
|
+
launch.code = code;
|
|
109
|
+
launch.serversSince = Date.now();
|
|
110
|
+
changed(launch);
|
|
111
|
+
if (abort.signal.aborted)
|
|
112
|
+
throw new Error("stopped");
|
|
113
|
+
const outcome = await Promise.race([options.run(launch, code, abort.signal), halted]);
|
|
114
|
+
if (abort.signal.aborted)
|
|
115
|
+
throw new Error("stopped");
|
|
116
|
+
launch.status = outcome.launched ? "launched" : "failed";
|
|
117
|
+
launch.summary = outcome.summary.trim();
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
launch.status = abort.signal.aborted ? "stopped" : "failed";
|
|
121
|
+
launch.summary = abort.signal.aborted ? "Stopped on request." : error instanceof Error ? error.message : String(error);
|
|
122
|
+
}
|
|
123
|
+
launch.finishedAt = Date.now();
|
|
124
|
+
// What runs is this launch's - or, stopped, nothing of it.
|
|
125
|
+
state.current = launch.status === "stopped" ? undefined : launch;
|
|
126
|
+
finish(state, launch);
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* A launch ended: the track free for the next - before anyone hears it ended - then it is told, and the next started.
|
|
130
|
+
* With a newer one waiting that will stop what it started - not out already - it is replaced: whoever asked for it
|
|
131
|
+
* hears the newer one's end instead, never that it is up only for it to be stopped the next moment.
|
|
132
|
+
*/
|
|
133
|
+
const finish = (state, launch) => {
|
|
134
|
+
if (state.running?.launch === launch)
|
|
135
|
+
state.running = undefined;
|
|
136
|
+
const next = state.waiting;
|
|
137
|
+
state.waiting = undefined;
|
|
138
|
+
const replaces = next !== undefined && launch.status !== "stopped" && (next.again === true || isOut(state, next.commit) === undefined);
|
|
139
|
+
if (replaces)
|
|
140
|
+
launch.replacedBy = next.id;
|
|
141
|
+
finished(launch);
|
|
142
|
+
changed(launch);
|
|
143
|
+
if (replaces)
|
|
144
|
+
handOn(launch, next);
|
|
145
|
+
else
|
|
146
|
+
ended(launch);
|
|
147
|
+
if (next !== undefined)
|
|
148
|
+
start(state, next);
|
|
149
|
+
else
|
|
150
|
+
settle(state);
|
|
151
|
+
};
|
|
152
|
+
const track = {
|
|
153
|
+
request(input) {
|
|
154
|
+
const target = launchTarget(input.plainFile, { ...(input.inModule !== undefined ? { inModule: input.inModule } : {}), ...(input.commit !== undefined ? { commit: input.commit } : {}) });
|
|
155
|
+
const codebase = target.entry.moduleName;
|
|
156
|
+
const state = stateOf(codebase, dirname(target.entry.buildDir));
|
|
157
|
+
const said = input.guidance?.trim();
|
|
158
|
+
if (said !== undefined && said !== "")
|
|
159
|
+
state.guidance = said;
|
|
160
|
+
const guidance = state.guidance;
|
|
161
|
+
const launch = {
|
|
162
|
+
id: `launch-${++count}`,
|
|
163
|
+
codebase,
|
|
164
|
+
moduleDir: state.moduleDir,
|
|
165
|
+
plainFile: target.entry.plainFile,
|
|
166
|
+
...(input.inModule !== undefined ? { inModule: input.inModule } : {}),
|
|
167
|
+
commit: target.commit,
|
|
168
|
+
short: target.commit.slice(0, 7),
|
|
169
|
+
hostDir: hostDirOf(target.entry.plainFile, options.cwd),
|
|
170
|
+
...(guidance !== undefined ? { guidance } : {}),
|
|
171
|
+
cause: input.cause,
|
|
172
|
+
status: "waiting",
|
|
173
|
+
queuedAt: Date.now(),
|
|
174
|
+
...(input.again === true ? { again: true } : {}),
|
|
175
|
+
};
|
|
176
|
+
let resolve;
|
|
177
|
+
const promise = new Promise((done) => (resolve = done));
|
|
178
|
+
ends.set(launch.id, { promise, resolve });
|
|
179
|
+
let resolveTaken;
|
|
180
|
+
const taken = new Promise((done) => (resolveTaken = done));
|
|
181
|
+
takenOver.set(launch.id, { promise: taken, resolve: resolveTaken });
|
|
182
|
+
// Nothing under way, and its code out already: nothing to do - but it ends as any launch does, told to the host
|
|
183
|
+
// (onChange) with its own cause and the commit asked for, and what runs is its own when that commit is newer.
|
|
184
|
+
if (input.again !== true && state.running === undefined && state.waiting === undefined) {
|
|
185
|
+
const out = isOut(state, launch.commit);
|
|
186
|
+
if (out !== undefined) {
|
|
187
|
+
keep(launch);
|
|
188
|
+
outAlready(state, launch, out);
|
|
189
|
+
return { launch, already: true };
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
keep(launch);
|
|
193
|
+
if (state.running === undefined)
|
|
194
|
+
start(state, launch);
|
|
195
|
+
else {
|
|
196
|
+
// The newest wins: what waited is never launched - this one holds its code.
|
|
197
|
+
const older = state.waiting;
|
|
198
|
+
if (older !== undefined) {
|
|
199
|
+
older.status = "superseded";
|
|
200
|
+
older.supersededBy = launch.id;
|
|
201
|
+
older.finishedAt = Date.now();
|
|
202
|
+
changed(older);
|
|
203
|
+
handOn(older, launch);
|
|
204
|
+
}
|
|
205
|
+
state.waiting = launch;
|
|
206
|
+
changed(launch);
|
|
207
|
+
}
|
|
208
|
+
return { launch, already: false };
|
|
209
|
+
},
|
|
210
|
+
current: (codebase) => codebases.get(codebase)?.current,
|
|
211
|
+
pending(codebase) {
|
|
212
|
+
const state = codebases.get(codebase);
|
|
213
|
+
return state?.running?.launch ?? state?.waiting;
|
|
214
|
+
},
|
|
215
|
+
settled(codebase) {
|
|
216
|
+
const state = codebases.get(codebase);
|
|
217
|
+
if (state === undefined || (state.running === undefined && state.waiting === undefined))
|
|
218
|
+
return Promise.resolve();
|
|
219
|
+
return new Promise((resolve) => state.settledWaiters.push(resolve));
|
|
220
|
+
},
|
|
221
|
+
done(id) {
|
|
222
|
+
const end = ends.get(id);
|
|
223
|
+
if (end !== undefined)
|
|
224
|
+
return end.promise;
|
|
225
|
+
const known = launches.find((launch) => launch.id === id);
|
|
226
|
+
return known !== undefined ? Promise.resolve(known) : Promise.reject(new Error(`No launch ${id}.`));
|
|
227
|
+
},
|
|
228
|
+
replaced(id) {
|
|
229
|
+
const taken = takenOver.get(id);
|
|
230
|
+
return taken !== undefined ? taken.promise : Promise.reject(new Error(`No launch ${id}.`));
|
|
231
|
+
},
|
|
232
|
+
holds(codebase, commit) {
|
|
233
|
+
const state = codebases.get(codebase);
|
|
234
|
+
const current = state?.current;
|
|
235
|
+
if (state === undefined || current === undefined)
|
|
236
|
+
return false;
|
|
237
|
+
return holdsCommit(state.moduleDir, commit, current.commit);
|
|
238
|
+
},
|
|
239
|
+
async stop(codebase) {
|
|
240
|
+
const stopped = [];
|
|
241
|
+
for (const [name, state] of codebases) {
|
|
242
|
+
if (codebase !== undefined && name !== codebase)
|
|
243
|
+
continue;
|
|
244
|
+
const waiting = state.waiting;
|
|
245
|
+
if (waiting !== undefined) {
|
|
246
|
+
state.waiting = undefined;
|
|
247
|
+
waiting.status = "stopped";
|
|
248
|
+
waiting.summary = "Stopped on request, before it started.";
|
|
249
|
+
waiting.finishedAt = Date.now();
|
|
250
|
+
changed(waiting);
|
|
251
|
+
ended(waiting);
|
|
252
|
+
stopped.push(`${waiting.id} (${name})`);
|
|
253
|
+
}
|
|
254
|
+
if (state.running !== undefined) {
|
|
255
|
+
state.running.abort.abort();
|
|
256
|
+
stopped.push(`${state.running.launch.id} (${name})`);
|
|
257
|
+
}
|
|
258
|
+
settle(state);
|
|
259
|
+
}
|
|
260
|
+
return stopped;
|
|
261
|
+
},
|
|
262
|
+
halted(codebase) {
|
|
263
|
+
const stopped = [];
|
|
264
|
+
for (const [name, state] of codebases) {
|
|
265
|
+
if (codebase !== undefined && name !== codebase)
|
|
266
|
+
continue;
|
|
267
|
+
const current = state.current;
|
|
268
|
+
if (current === undefined || current.status !== "launched" || runningLaunched(name).length > 0)
|
|
269
|
+
continue;
|
|
270
|
+
current.status = "stopped";
|
|
271
|
+
current.summary = "Stopped on request.";
|
|
272
|
+
current.finishedAt = Date.now();
|
|
273
|
+
state.current = undefined;
|
|
274
|
+
finished(current);
|
|
275
|
+
changed(current);
|
|
276
|
+
stopped.push(current.id);
|
|
277
|
+
}
|
|
278
|
+
return stopped;
|
|
279
|
+
},
|
|
280
|
+
list: () => [...launches],
|
|
281
|
+
running: (codebase) => runningLaunched(codebase),
|
|
282
|
+
};
|
|
283
|
+
return track;
|
|
284
|
+
}
|
|
285
|
+
/** A launch in a line: its codebase, commit, how it stands - for /halt, pulses and the panel. */
|
|
286
|
+
export function describeLaunchLine(launch) {
|
|
287
|
+
const why = "pulse" in launch.cause ? ` after pulse ${launch.cause.pulse}` : "";
|
|
288
|
+
const how = launch.status === "waiting"
|
|
289
|
+
? "waiting"
|
|
290
|
+
: launch.status === "running"
|
|
291
|
+
? "launching"
|
|
292
|
+
: launch.status === "launched"
|
|
293
|
+
? launch.already === true
|
|
294
|
+
? "out already"
|
|
295
|
+
: "launched"
|
|
296
|
+
: launch.status;
|
|
297
|
+
return `${launch.id} ${how} ${launch.codebase} at ${launch.short}${why}`;
|
|
298
|
+
}
|
package/dist/loop-cli.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type DriftReport, type ModuleStatus, type WorkLoop } from "./regenerate/loop.ts";
|
|
2
2
|
import { type ModuleState } from "./run-report.ts";
|
|
3
3
|
/**
|
|
4
|
-
* What every command that builds - `turri regenerate`, `conform
|
|
4
|
+
* What every command that builds - `turri regenerate`, `conform` - does around its own
|
|
5
5
|
* request of the work loop, as the chat does it: the project's models, a job that fails run once more and, failing again,
|
|
6
6
|
* diagnosed, a line as each job starts and ends; then the loop run until nothing more can start, how each job ended,
|
|
7
|
-
* and exit 1 when any failed or a module is not complete. With `dryRun`,
|
|
8
|
-
*
|
|
7
|
+
* and exit 1 when any failed or a module is not complete. With `dryRun`, `ask` is a look ahead (`WorkLoop.lookAhead`): the work is
|
|
8
|
+
* planned, the prompt of the next pulse of each codebase printed from the plan kept, and nothing runs.
|
|
9
9
|
*/
|
|
10
10
|
export declare function runLoop(options: {
|
|
11
11
|
plainFile: string;
|
|
@@ -15,6 +15,7 @@ export declare function runLoop(options: {
|
|
|
15
15
|
report?: string;
|
|
16
16
|
/** The command, as the report gives it: its name and its arguments. */
|
|
17
17
|
command?: string[];
|
|
18
|
+
/** Plan and print the next pulses, starting nothing - `ask` a look ahead. */
|
|
18
19
|
dryRun?: boolean;
|
|
19
20
|
/** Start over, unasked, a codebase that has to be on a module it now requires (`--start-over`). */
|
|
20
21
|
startOver?: boolean;
|
package/dist/loop-cli.js
CHANGED
|
@@ -10,18 +10,18 @@ import { ledgerWanted, startLedger } from "./regenerate/ledger.js";
|
|
|
10
10
|
import { tryItCommand } from "./regenerate/delivery.js";
|
|
11
11
|
import { describeDiagnosis, diagnoseFailure } from "./regenerate/diagnose.js";
|
|
12
12
|
import { createJobRegistry, pulseName } from "./regenerate/jobs.js";
|
|
13
|
-
import { createWorkLoop, describeModules, functionalityCompletion
|
|
13
|
+
import { createWorkLoop, describeModules, functionalityCompletion } from "./regenerate/loop.js";
|
|
14
14
|
import { MODULES_DIR, projectDirOf } from "./regenerate/paths.js";
|
|
15
|
-
import { exportModule } from "./regenerate/
|
|
15
|
+
import { exportModule } from "./regenerate/launch.js";
|
|
16
16
|
import { listFiles } from "./regenerate/testing.js";
|
|
17
17
|
import { startRunReport } from "./run-report.js";
|
|
18
18
|
import { configKeyOptions, optionValue } from "./cli-options.js";
|
|
19
19
|
/**
|
|
20
|
-
* What every command that builds - `turri regenerate`, `conform
|
|
20
|
+
* What every command that builds - `turri regenerate`, `conform` - does around its own
|
|
21
21
|
* request of the work loop, as the chat does it: the project's models, a job that fails run once more and, failing again,
|
|
22
22
|
* diagnosed, a line as each job starts and ends; then the loop run until nothing more can start, how each job ended,
|
|
23
|
-
* and exit 1 when any failed or a module is not complete. With `dryRun`,
|
|
24
|
-
*
|
|
23
|
+
* and exit 1 when any failed or a module is not complete. With `dryRun`, `ask` is a look ahead (`WorkLoop.lookAhead`): the work is
|
|
24
|
+
* planned, the prompt of the next pulse of each codebase printed from the plan kept, and nothing runs.
|
|
25
25
|
*/
|
|
26
26
|
export async function runLoop(options) {
|
|
27
27
|
const plainFile = resolve(options.plainFile);
|
|
@@ -110,7 +110,6 @@ async function runLoopReporting(options) {
|
|
|
110
110
|
cwd: process.cwd(),
|
|
111
111
|
...(model !== undefined ? { modelFor: () => model } : {}),
|
|
112
112
|
...(planner !== undefined ? { plannerModel: planner } : {}),
|
|
113
|
-
...(options.dryRun === true ? { dryRun: true } : {}),
|
|
114
113
|
});
|
|
115
114
|
report?.attach({
|
|
116
115
|
jobs: () => registry.list(),
|
|
@@ -146,13 +145,16 @@ async function runLoopReporting(options) {
|
|
|
146
145
|
}
|
|
147
146
|
}
|
|
148
147
|
if (options.dryRun === true) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
// The next pulse of each codebase, from the plan the look ahead kept - the one regenerate would start.
|
|
149
|
+
for (const status of planned) {
|
|
150
|
+
const first = status.planned[0];
|
|
151
|
+
if (first === undefined || first.afterCode === true || first.planning === true)
|
|
153
152
|
continue;
|
|
154
|
-
}
|
|
155
|
-
|
|
153
|
+
const next = await loop.plannedPulse(`planned-${status.module}-1`);
|
|
154
|
+
if (next === undefined)
|
|
155
|
+
continue;
|
|
156
|
+
console.log(`\n${c.bold(`${next.module}: ${next.title}`)}${next.track === "conformance" ? c.dim(" (conformance)") : ""}`);
|
|
157
|
+
console.log(next.task ?? c.dim(next.why ?? "(no task)"));
|
|
156
158
|
}
|
|
157
159
|
process.exit(0);
|
|
158
160
|
}
|
|
@@ -220,12 +222,12 @@ function refuseBuildDir(buildDir, projectDir) {
|
|
|
220
222
|
/** The furthest-built codebase's last commit, exported into `dir` - or why nothing was. */
|
|
221
223
|
function exportCode(plainFile, dir) {
|
|
222
224
|
try {
|
|
223
|
-
const
|
|
225
|
+
const code = exportModule(plainFile, { into: dir });
|
|
224
226
|
const files = listFiles(dir).length;
|
|
225
227
|
// Its history began, and nothing landed in it yet: only the harness's own files, which are left out.
|
|
226
228
|
if (files === 0)
|
|
227
|
-
return { exported: false, dir, why: `nothing has landed in ${
|
|
228
|
-
return { exported: true, dir, module:
|
|
229
|
+
return { exported: false, dir, why: `nothing has landed in ${code.moduleName} yet: its codebase holds no code` };
|
|
230
|
+
return { exported: true, dir, module: code.moduleName, commit: code.short, files };
|
|
229
231
|
}
|
|
230
232
|
catch (error) {
|
|
231
233
|
return { exported: false, dir, why: error instanceof Error ? error.message : String(error) };
|