@turri-dev/cli 0.2.4-next.efe96fe → 0.2.4-next.f26a225
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 +2 -2
- package/dist/chat-skills.d.ts +1 -1
- package/dist/chat-skills.js +1 -1
- package/dist/chats.d.ts +42 -8
- package/dist/chats.js +122 -38
- package/dist/cli.js +1 -1
- package/dist/config-edit.js +4 -4
- package/dist/config.d.ts +48 -11
- package/dist/config.js +102 -13
- package/dist/extension.d.ts +9 -0
- package/dist/extension.js +184 -109
- package/dist/genome.js +1 -1
- package/dist/host-session.d.ts +6 -5
- package/dist/host-session.js +2 -2
- package/dist/host.d.ts +2 -0
- package/dist/identity.js +2 -2
- package/dist/init-config.d.ts +1 -1
- package/dist/init-config.js +7 -7
- package/dist/launch-agent.d.ts +51 -0
- package/dist/launch-agent.js +267 -0
- package/dist/{release-cli.js → launch-cli.js} +41 -24
- package/dist/launch-session.d.ts +68 -0
- package/dist/launch-session.js +217 -0
- package/dist/launch-tools.d.ts +28 -0
- package/dist/launch-tools.js +69 -0
- package/dist/launch-track.d.ts +125 -0
- package/dist/launch-track.js +320 -0
- package/dist/loop-cli.js +4 -4
- package/dist/loop-tools.d.ts +8 -3
- package/dist/loop-tools.js +37 -32
- package/dist/notice.d.ts +7 -6
- package/dist/plain-files.d.ts +2 -2
- package/dist/plain-files.js +3 -3
- package/dist/regenerate/command-check.d.ts +7 -1
- package/dist/regenerate/command-check.js +43 -1
- package/dist/regenerate/delivery.d.ts +1 -1
- package/dist/regenerate/delivery.js +3 -3
- package/dist/regenerate/launch.d.ts +154 -0
- package/dist/regenerate/{release.js → launch.js} +195 -51
- package/dist/regenerate/ledger.d.ts +32 -1
- package/dist/regenerate/lineage.d.ts +2 -0
- package/dist/regenerate/lineage.js +8 -0
- package/dist/regenerate/loop.d.ts +6 -5
- package/dist/regenerate/loop.js +16 -17
- package/dist/regenerate/paths.d.ts +2 -2
- package/dist/regenerate/paths.js +2 -2
- package/dist/self-invocation.js +7 -7
- package/dist/sentinel-check.d.ts +3 -3
- package/dist/sentinel-check.js +3 -3
- package/dist/sentinel.d.ts +18 -12
- package/dist/sentinel.js +68 -42
- package/docs/README.md +2 -2
- package/docs/chats.md +2 -2
- package/docs/config.md +9 -9
- package/docs/development.md +1 -1
- package/docs/headless.md +1 -1
- package/docs/hosting.md +14 -13
- package/docs/launch.md +67 -0
- package/docs/parser.md +1 -1
- package/docs/regenerating.md +3 -3
- package/docs/sandbox.md +3 -3
- package/docs/sentinel.md +24 -12
- package/docs/skills-and-gates.md +3 -3
- package/docs/using.md +7 -7
- package/genome/rules/turri-regeneration.md +1 -1
- package/package.json +1 -1
- package/dist/regenerate/release.d.ts +0 -121
- package/dist/release-agent.d.ts +0 -43
- package/dist/release-agent.js +0 -130
- package/dist/release-tools.d.ts +0 -44
- package/dist/release-tools.js +0 -170
- package/docs/deploy.md +0 -48
- /package/dist/{release-cli.d.ts → launch-cli.d.ts} +0 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { dirname, join } from "node:path";
|
|
2
|
+
import { codeTreeOf, describeLeftBehind, exportModule, holdsCommit, hostDirOf, launchTarget, listLaunched, runningLaunched, stopLaunched, stopLeftBehind } from "./regenerate/launch.js";
|
|
3
|
+
import { projectDirOf } from "./regenerate/paths.js";
|
|
4
|
+
import { record } from "./regenerate/ledger.js";
|
|
5
|
+
/** How many ended launches are kept to list. */
|
|
6
|
+
const KEPT = 50;
|
|
7
|
+
export function createLaunchTrack(options) {
|
|
8
|
+
const codebases = new Map();
|
|
9
|
+
const launches = [];
|
|
10
|
+
const ends = new Map();
|
|
11
|
+
const takenOver = new Map();
|
|
12
|
+
let count = 0;
|
|
13
|
+
const stateOf = (codebase, moduleDir) => {
|
|
14
|
+
let state = codebases.get(codebase);
|
|
15
|
+
if (state === undefined) {
|
|
16
|
+
state = { moduleDir, settledWaiters: [] };
|
|
17
|
+
codebases.set(codebase, state);
|
|
18
|
+
}
|
|
19
|
+
state.moduleDir = moduleDir;
|
|
20
|
+
return state;
|
|
21
|
+
};
|
|
22
|
+
const changed = (launch) => {
|
|
23
|
+
try {
|
|
24
|
+
options.onChange?.(launch);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
/* one that listens and fails is left out of this change */
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const ended = (launch) => ends.get(launch.id)?.resolve(launch);
|
|
31
|
+
/** `next` takes `launch`'s place: whoever waits on `launch` hears `next`'s end, and that it took over, now. */
|
|
32
|
+
const handOn = (launch, next) => {
|
|
33
|
+
takenOver.get(launch.id)?.resolve(next);
|
|
34
|
+
void track.done(next.id).then((last) => ends.get(launch.id)?.resolve(last));
|
|
35
|
+
};
|
|
36
|
+
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));
|
|
37
|
+
const place = (launch) => ({ project: options.cwd, module: launch.codebase });
|
|
38
|
+
/** What an earlier session left running and was stopped, by codebase, not yet said in a launch's summary. */
|
|
39
|
+
const leftBehind = new Map();
|
|
40
|
+
const noteLeftBehind = (stopped) => {
|
|
41
|
+
if (stopped.length === 0)
|
|
42
|
+
return;
|
|
43
|
+
record({ kind: "launch.left-behind", stopped: stopped.map((each) => ({ name: each.name, pid: each.pid, module: each.moduleName, ...(each.url !== undefined ? { url: each.url } : {}) })) }, { project: options.cwd });
|
|
44
|
+
for (const each of stopped)
|
|
45
|
+
leftBehind.set(each.moduleName, [...(leftBehind.get(each.moduleName) ?? []), each]);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* What runs for the codebase is the commit's code: the same code, nothing it started has ended. Guidance is not
|
|
49
|
+
* compared: the agent finds the project's itself, and the chat passing it on says nothing new - `again` launches anew.
|
|
50
|
+
*/
|
|
51
|
+
const isOut = (state, commit) => {
|
|
52
|
+
const current = state.current;
|
|
53
|
+
if (current === undefined || current.status !== "launched")
|
|
54
|
+
return undefined;
|
|
55
|
+
if (!holdsCommit(state.moduleDir, current.commit, commit) && !holdsCommit(state.moduleDir, commit, current.commit))
|
|
56
|
+
return undefined;
|
|
57
|
+
const tree = codeTreeOf(state.moduleDir, commit);
|
|
58
|
+
if (tree === undefined || tree !== codeTreeOf(state.moduleDir, current.commit))
|
|
59
|
+
return undefined;
|
|
60
|
+
const since = current.serversSince ?? current.startedAt ?? 0;
|
|
61
|
+
const started = listLaunched().filter((item) => item.moduleName === current.codebase && item.startedAt >= since);
|
|
62
|
+
return started.some((item) => item.exited !== undefined) ? undefined : current;
|
|
63
|
+
};
|
|
64
|
+
const settle = (state) => {
|
|
65
|
+
if (state.running !== undefined || state.waiting !== undefined)
|
|
66
|
+
return;
|
|
67
|
+
for (const resolve of state.settledWaiters.splice(0))
|
|
68
|
+
resolve();
|
|
69
|
+
};
|
|
70
|
+
const keep = (launch) => {
|
|
71
|
+
launches.push(launch);
|
|
72
|
+
while (launches.length > KEPT) {
|
|
73
|
+
const first = launches.findIndex((each) => each.status !== "waiting" && each.status !== "running");
|
|
74
|
+
if (first === -1)
|
|
75
|
+
break;
|
|
76
|
+
launches.splice(first, 1);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* A launch whose commit's code is what runs already - a pulse that landed only tests, say, or the chat asking for what
|
|
81
|
+
* runs: ended as launched at once, `already`, nothing stopped or started - nor anyone told it is launching. What runs
|
|
82
|
+
* is its own from then on, when its commit is built on what ran: it holds both. Told as any launch's end is.
|
|
83
|
+
*/
|
|
84
|
+
const outAlready = (state, launch, out) => {
|
|
85
|
+
launch.status = "launched";
|
|
86
|
+
launch.already = true;
|
|
87
|
+
launch.startedAt = Date.now();
|
|
88
|
+
launch.serversSince = out.serversSince ?? out.startedAt ?? 0;
|
|
89
|
+
launch.summary = out.summary ?? `${launch.codebase} at ${out.short} runs already.`;
|
|
90
|
+
launch.finishedAt = Date.now();
|
|
91
|
+
if (holdsCommit(state.moduleDir, out.commit, launch.commit))
|
|
92
|
+
state.current = launch;
|
|
93
|
+
finish(state, launch);
|
|
94
|
+
};
|
|
95
|
+
const start = (state, launch) => {
|
|
96
|
+
// Found out already as it waited.
|
|
97
|
+
const out = launch.again === true ? undefined : isOut(state, launch.commit);
|
|
98
|
+
if (out !== undefined) {
|
|
99
|
+
outAlready(state, launch, out);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const abort = new AbortController();
|
|
103
|
+
state.running = { launch, abort };
|
|
104
|
+
launch.status = "running";
|
|
105
|
+
launch.startedAt = Date.now();
|
|
106
|
+
changed(launch);
|
|
107
|
+
record({ kind: "launch.started", launch: launch.id, commit: launch.short, ...("pulse" in launch.cause ? { pulse: launch.cause.pulse } : {}) }, place(launch));
|
|
108
|
+
void runIt(state, launch, abort);
|
|
109
|
+
};
|
|
110
|
+
const runIt = async (state, launch, abort) => {
|
|
111
|
+
// Halted, it is let go at once: what the agent does after is nobody's.
|
|
112
|
+
const halted = new Promise((_, reject) => abort.signal.addEventListener("abort", () => reject(new Error("stopped")), { once: true }));
|
|
113
|
+
halted.catch(() => undefined);
|
|
114
|
+
try {
|
|
115
|
+
// What the last launch started runs from what is about to be replaced - and what an earlier session's left, which
|
|
116
|
+
// would hold its ports.
|
|
117
|
+
noteLeftBehind(await stopLeftBehind(projectDirOf(launch.plainFile), launch.codebase));
|
|
118
|
+
await stopLaunched({ moduleName: launch.codebase });
|
|
119
|
+
const code = exportModule(launch.plainFile, { ...(launch.inModule !== undefined ? { inModule: launch.inModule } : {}), commit: launch.commit });
|
|
120
|
+
launch.code = code;
|
|
121
|
+
launch.serversSince = Date.now();
|
|
122
|
+
changed(launch);
|
|
123
|
+
if (abort.signal.aborted)
|
|
124
|
+
throw new Error("stopped");
|
|
125
|
+
const outcome = await Promise.race([options.run(launch, code, abort.signal), halted]);
|
|
126
|
+
if (abort.signal.aborted)
|
|
127
|
+
throw new Error("stopped");
|
|
128
|
+
launch.status = outcome.launched ? "launched" : "failed";
|
|
129
|
+
launch.summary = outcome.summary.trim();
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
launch.status = abort.signal.aborted ? "stopped" : "failed";
|
|
133
|
+
launch.summary = abort.signal.aborted ? "Stopped on request." : error instanceof Error ? error.message : String(error);
|
|
134
|
+
}
|
|
135
|
+
const left = leftBehind.get(launch.codebase);
|
|
136
|
+
if (left !== undefined) {
|
|
137
|
+
leftBehind.delete(launch.codebase);
|
|
138
|
+
launch.summary = `${describeLeftBehind(left)}\n${launch.summary ?? ""}`.trim();
|
|
139
|
+
}
|
|
140
|
+
launch.finishedAt = Date.now();
|
|
141
|
+
// What runs is this launch's - or, stopped, nothing of it.
|
|
142
|
+
state.current = launch.status === "stopped" ? undefined : launch;
|
|
143
|
+
finish(state, launch);
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* A launch ended: the track free for the next - before anyone hears it ended - then it is told, and the next started.
|
|
147
|
+
* With a newer one waiting that will stop what it started - not out already - it is replaced: whoever asked for it
|
|
148
|
+
* hears the newer one's end instead, never that it is up only for it to be stopped the next moment.
|
|
149
|
+
*/
|
|
150
|
+
const finish = (state, launch) => {
|
|
151
|
+
if (state.running?.launch === launch)
|
|
152
|
+
state.running = undefined;
|
|
153
|
+
const next = state.waiting;
|
|
154
|
+
state.waiting = undefined;
|
|
155
|
+
const replaces = next !== undefined && launch.status !== "stopped" && (next.again === true || isOut(state, next.commit) === undefined);
|
|
156
|
+
if (replaces)
|
|
157
|
+
launch.replacedBy = next.id;
|
|
158
|
+
finished(launch);
|
|
159
|
+
changed(launch);
|
|
160
|
+
if (replaces)
|
|
161
|
+
handOn(launch, next);
|
|
162
|
+
else
|
|
163
|
+
ended(launch);
|
|
164
|
+
if (next !== undefined)
|
|
165
|
+
start(state, next);
|
|
166
|
+
else
|
|
167
|
+
settle(state);
|
|
168
|
+
};
|
|
169
|
+
const track = {
|
|
170
|
+
request(input) {
|
|
171
|
+
const target = launchTarget(input.plainFile, { ...(input.inModule !== undefined ? { inModule: input.inModule } : {}), ...(input.commit !== undefined ? { commit: input.commit } : {}) });
|
|
172
|
+
const codebase = target.entry.moduleName;
|
|
173
|
+
const state = stateOf(codebase, dirname(target.entry.buildDir));
|
|
174
|
+
const said = input.guidance?.trim();
|
|
175
|
+
if (said !== undefined && said !== "")
|
|
176
|
+
state.guidance = said;
|
|
177
|
+
const guidance = state.guidance;
|
|
178
|
+
const launch = {
|
|
179
|
+
id: `launch-${++count}`,
|
|
180
|
+
codebase,
|
|
181
|
+
moduleDir: state.moduleDir,
|
|
182
|
+
plainFile: target.entry.plainFile,
|
|
183
|
+
...(input.inModule !== undefined ? { inModule: input.inModule } : {}),
|
|
184
|
+
commit: target.commit,
|
|
185
|
+
short: target.commit.slice(0, 7),
|
|
186
|
+
hostDir: hostDirOf(target.entry.plainFile, options.cwd),
|
|
187
|
+
...(guidance !== undefined ? { guidance } : {}),
|
|
188
|
+
cause: input.cause,
|
|
189
|
+
status: "waiting",
|
|
190
|
+
queuedAt: Date.now(),
|
|
191
|
+
...(input.again === true ? { again: true } : {}),
|
|
192
|
+
};
|
|
193
|
+
let resolve;
|
|
194
|
+
const promise = new Promise((done) => (resolve = done));
|
|
195
|
+
ends.set(launch.id, { promise, resolve });
|
|
196
|
+
let resolveTaken;
|
|
197
|
+
const taken = new Promise((done) => (resolveTaken = done));
|
|
198
|
+
takenOver.set(launch.id, { promise: taken, resolve: resolveTaken });
|
|
199
|
+
// Nothing under way, and its code out already: nothing to do - but it ends as any launch does, told to the host
|
|
200
|
+
// (onChange) with its own cause and the commit asked for, and what runs is its own when that commit is newer.
|
|
201
|
+
if (input.again !== true && state.running === undefined && state.waiting === undefined) {
|
|
202
|
+
const out = isOut(state, launch.commit);
|
|
203
|
+
if (out !== undefined) {
|
|
204
|
+
keep(launch);
|
|
205
|
+
outAlready(state, launch, out);
|
|
206
|
+
return { launch, already: true };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
keep(launch);
|
|
210
|
+
if (state.running === undefined)
|
|
211
|
+
start(state, launch);
|
|
212
|
+
else {
|
|
213
|
+
// The newest wins: what waited is never launched - this one holds its code.
|
|
214
|
+
const older = state.waiting;
|
|
215
|
+
if (older !== undefined) {
|
|
216
|
+
older.status = "superseded";
|
|
217
|
+
older.supersededBy = launch.id;
|
|
218
|
+
older.finishedAt = Date.now();
|
|
219
|
+
changed(older);
|
|
220
|
+
handOn(older, launch);
|
|
221
|
+
}
|
|
222
|
+
state.waiting = launch;
|
|
223
|
+
changed(launch);
|
|
224
|
+
}
|
|
225
|
+
return { launch, already: false };
|
|
226
|
+
},
|
|
227
|
+
current: (codebase) => codebases.get(codebase)?.current,
|
|
228
|
+
pending(codebase) {
|
|
229
|
+
const state = codebases.get(codebase);
|
|
230
|
+
return state?.running?.launch ?? state?.waiting;
|
|
231
|
+
},
|
|
232
|
+
settled(codebase) {
|
|
233
|
+
const state = codebases.get(codebase);
|
|
234
|
+
if (state === undefined || (state.running === undefined && state.waiting === undefined))
|
|
235
|
+
return Promise.resolve();
|
|
236
|
+
return new Promise((resolve) => state.settledWaiters.push(resolve));
|
|
237
|
+
},
|
|
238
|
+
done(id) {
|
|
239
|
+
const end = ends.get(id);
|
|
240
|
+
if (end !== undefined)
|
|
241
|
+
return end.promise;
|
|
242
|
+
const known = launches.find((launch) => launch.id === id);
|
|
243
|
+
return known !== undefined ? Promise.resolve(known) : Promise.reject(new Error(`No launch ${id}.`));
|
|
244
|
+
},
|
|
245
|
+
replaced(id) {
|
|
246
|
+
const taken = takenOver.get(id);
|
|
247
|
+
return taken !== undefined ? taken.promise : Promise.reject(new Error(`No launch ${id}.`));
|
|
248
|
+
},
|
|
249
|
+
holds(codebase, commit) {
|
|
250
|
+
const state = codebases.get(codebase);
|
|
251
|
+
const current = state?.current;
|
|
252
|
+
if (state === undefined || current === undefined)
|
|
253
|
+
return false;
|
|
254
|
+
return holdsCommit(state.moduleDir, commit, current.commit);
|
|
255
|
+
},
|
|
256
|
+
async stop(codebase) {
|
|
257
|
+
const stopped = [];
|
|
258
|
+
for (const [name, state] of codebases) {
|
|
259
|
+
if (codebase !== undefined && name !== codebase)
|
|
260
|
+
continue;
|
|
261
|
+
const waiting = state.waiting;
|
|
262
|
+
if (waiting !== undefined) {
|
|
263
|
+
state.waiting = undefined;
|
|
264
|
+
waiting.status = "stopped";
|
|
265
|
+
waiting.summary = "Stopped on request, before it started.";
|
|
266
|
+
waiting.finishedAt = Date.now();
|
|
267
|
+
changed(waiting);
|
|
268
|
+
ended(waiting);
|
|
269
|
+
stopped.push(`${waiting.id} (${name})`);
|
|
270
|
+
}
|
|
271
|
+
if (state.running !== undefined) {
|
|
272
|
+
state.running.abort.abort();
|
|
273
|
+
stopped.push(`${state.running.launch.id} (${name})`);
|
|
274
|
+
}
|
|
275
|
+
settle(state);
|
|
276
|
+
}
|
|
277
|
+
return stopped;
|
|
278
|
+
},
|
|
279
|
+
halted(codebase) {
|
|
280
|
+
const stopped = [];
|
|
281
|
+
for (const [name, state] of codebases) {
|
|
282
|
+
if (codebase !== undefined && name !== codebase)
|
|
283
|
+
continue;
|
|
284
|
+
const current = state.current;
|
|
285
|
+
if (current === undefined || current.status !== "launched" || runningLaunched(name).length > 0)
|
|
286
|
+
continue;
|
|
287
|
+
current.status = "stopped";
|
|
288
|
+
current.summary = "Stopped on request.";
|
|
289
|
+
current.finishedAt = Date.now();
|
|
290
|
+
state.current = undefined;
|
|
291
|
+
finished(current);
|
|
292
|
+
changed(current);
|
|
293
|
+
stopped.push(current.id);
|
|
294
|
+
}
|
|
295
|
+
return stopped;
|
|
296
|
+
},
|
|
297
|
+
list: () => [...launches],
|
|
298
|
+
async sweep() {
|
|
299
|
+
const stopped = await stopLeftBehind(projectDirOf(join(options.cwd, "turri.plain")));
|
|
300
|
+
noteLeftBehind(stopped);
|
|
301
|
+
return stopped;
|
|
302
|
+
},
|
|
303
|
+
running: (codebase) => runningLaunched(codebase),
|
|
304
|
+
};
|
|
305
|
+
return track;
|
|
306
|
+
}
|
|
307
|
+
/** A launch in a line: its codebase, commit, how it stands - for /halt, pulses and the panel. */
|
|
308
|
+
export function describeLaunchLine(launch) {
|
|
309
|
+
const why = "pulse" in launch.cause ? ` after pulse ${launch.cause.pulse}` : "";
|
|
310
|
+
const how = launch.status === "waiting"
|
|
311
|
+
? "waiting"
|
|
312
|
+
: launch.status === "running"
|
|
313
|
+
? "launching"
|
|
314
|
+
: launch.status === "launched"
|
|
315
|
+
? launch.already === true
|
|
316
|
+
? "out already"
|
|
317
|
+
: "launched"
|
|
318
|
+
: launch.status;
|
|
319
|
+
return `${launch.id} ${how} ${launch.codebase} at ${launch.short}${why}`;
|
|
320
|
+
}
|
package/dist/loop-cli.js
CHANGED
|
@@ -12,7 +12,7 @@ import { describeDiagnosis, diagnoseFailure } from "./regenerate/diagnose.js";
|
|
|
12
12
|
import { createJobRegistry, pulseName } from "./regenerate/jobs.js";
|
|
13
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";
|
|
@@ -222,12 +222,12 @@ function refuseBuildDir(buildDir, projectDir) {
|
|
|
222
222
|
/** The furthest-built codebase's last commit, exported into `dir` - or why nothing was. */
|
|
223
223
|
function exportCode(plainFile, dir) {
|
|
224
224
|
try {
|
|
225
|
-
const
|
|
225
|
+
const code = exportModule(plainFile, { into: dir });
|
|
226
226
|
const files = listFiles(dir).length;
|
|
227
227
|
// Its history began, and nothing landed in it yet: only the harness's own files, which are left out.
|
|
228
228
|
if (files === 0)
|
|
229
|
-
return { exported: false, dir, why: `nothing has landed in ${
|
|
230
|
-
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 };
|
|
231
231
|
}
|
|
232
232
|
catch (error) {
|
|
233
233
|
return { exported: false, dir, why: error instanceof Error ? error.message : String(error) };
|
package/dist/loop-tools.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type ExtensionContext, type ToolDefinition } from "@earendil-works/pi-c
|
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import { type ModuleStatus, type WorkLoop } from "./regenerate/loop.ts";
|
|
4
4
|
import { type Job, type JobRegistry } from "./regenerate/jobs.ts";
|
|
5
|
+
import type { LaunchTrack } from "./launch-track.ts";
|
|
5
6
|
/**
|
|
6
7
|
* The tools that act on the work loop - `regenerate`, `drift` and `halt` - defined once, for the conversation and for the
|
|
7
8
|
* skills alike: a skill that regenerates what a spec holds, or reads how far it is regenerated, uses the conversation's
|
|
@@ -71,7 +72,7 @@ export declare function stopJob(jobs: JobRegistry, named: string, reason?: strin
|
|
|
71
72
|
export interface LoopToolsOptions {
|
|
72
73
|
/** Where turri was started: the folder plain_file and working_dir are relative to. */
|
|
73
74
|
cwd: string;
|
|
74
|
-
/** The pulses
|
|
75
|
+
/** The pulses the tools act on. */
|
|
75
76
|
jobs?: JobRegistry;
|
|
76
77
|
/** The work loop the tools act on - the conversation's, for a call in it. */
|
|
77
78
|
loop?: (ctx: ExtensionContext) => WorkLoop;
|
|
@@ -92,8 +93,12 @@ export declare function regenerateTool(options: LoopToolsOptions & {
|
|
|
92
93
|
export declare function driftTool(options: LoopToolsOptions & {
|
|
93
94
|
loop: (ctx: ExtensionContext) => WorkLoop;
|
|
94
95
|
}): AnyTool;
|
|
95
|
-
/** halt: stop a pulse, or what
|
|
96
|
-
export declare function haltTool(options:
|
|
96
|
+
/** halt: stop a pulse, a module's planned pulses, a launch under way, or what a launch started. */
|
|
97
|
+
export declare function haltTool(options: {
|
|
98
|
+
jobs: JobRegistry;
|
|
97
99
|
workLoop?: () => WorkLoop | undefined;
|
|
100
|
+
launches?: LaunchTrack;
|
|
98
101
|
}): AnyTool;
|
|
102
|
+
/** Halt what a launch started by its name, a module's launch under way and what it started, or every one: what was halted, said. */
|
|
103
|
+
export declare function haltLaunched(which: string, launches: LaunchTrack | undefined): Promise<string>;
|
|
99
104
|
export {};
|
package/dist/loop-tools.js
CHANGED
|
@@ -10,7 +10,7 @@ import { describeJob, pulseName } from "./regenerate/jobs.js";
|
|
|
10
10
|
import { currentChat } from "./chat-scope.js";
|
|
11
11
|
import { whyFailed } from "./regenerate/diagnose-job.js";
|
|
12
12
|
import { didNotLand } from "./regenerate/failure-reports.js";
|
|
13
|
-
import {
|
|
13
|
+
import { runningLaunched, stopLaunched } from "./regenerate/launch.js";
|
|
14
14
|
import { projectDirOf } from "./regenerate/paths.js";
|
|
15
15
|
import { findTestScripts } from "./regenerate/test-scripts.js";
|
|
16
16
|
import { surfaceOf } from "./surface.js";
|
|
@@ -309,49 +309,54 @@ export function driftTool(options) {
|
|
|
309
309
|
},
|
|
310
310
|
});
|
|
311
311
|
}
|
|
312
|
-
const
|
|
313
|
-
const HALT_PULSE_PARAMS = Type.Object({
|
|
312
|
+
const HALT_PARAMS = Type.Object({
|
|
314
313
|
job_id: Type.Optional(Type.String({ description: "The pulse's id, or the start of it; a planned row's id (planned-<module>-...), or a module's name, halts the module" })),
|
|
315
314
|
reason: Type.Optional(Type.String({ description: "Why it is halted, kept with it - what the spec now says that it did not, say" })),
|
|
316
|
-
|
|
315
|
+
launched: Type.Optional(Type.String({ description: 'What a launch started, by name; a module\'s name for its launch under way and what it started; or "all"' })),
|
|
317
316
|
});
|
|
318
|
-
/**
|
|
319
|
-
const HALT_ACTIVATED_PARAMS = Type.Object({ activated: ACTIVATED_PARAM });
|
|
320
|
-
/** halt: stop a pulse, or what activate started. */
|
|
317
|
+
/** halt: stop a pulse, a module's planned pulses, a launch under way, or what a launch started. */
|
|
321
318
|
export function haltTool(options) {
|
|
322
319
|
const { jobs } = options;
|
|
323
320
|
return defineTool({
|
|
324
321
|
name: "halt",
|
|
325
322
|
label: "Halt",
|
|
326
|
-
description:
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
"A planned row for a module that is no longer in the project is halted the same way, and dropped.",
|
|
340
|
-
]
|
|
341
|
-
: [],
|
|
342
|
-
parameters: (jobs !== undefined ? HALT_PULSE_PARAMS : HALT_ACTIVATED_PARAMS),
|
|
323
|
+
description: "Halt a pulse, a module's planned pulses, or a launch. A pulse: a queued one never starts, a running one has its " +
|
|
324
|
+
"agent stopped at once, and the pulses queued behind it move up - what a running pulse already changed is rolled back, and what " +
|
|
325
|
+
"it was regenerating counts as not regenerated. A planned row (planned-<module>-...) or a module's name halts the module: its " +
|
|
326
|
+
"running pulse stopped, none of its planned pulses started, and the modules built on it waiting - until it is asked for again " +
|
|
327
|
+
"with regenerate; a spec change does not start it. A module whose .plain file is gone is dropped. launched: what a launch " +
|
|
328
|
+
"started, by name; a module's name, its launch under way and what it started; or all.",
|
|
329
|
+
promptSnippet: "halt a pulse, or a launch and what it started",
|
|
330
|
+
promptGuidelines: [
|
|
331
|
+
"Halt a pulse only when the user asks, or your instructions say to. Name which one, and say which pulses were queued behind it - they will now run.",
|
|
332
|
+
"Halting a planned row halts its whole module - one planned pulse cannot be taken out alone, as the plan is made again from the spec. To build some of it later, or cut it differently, use steer; to drop work, change the spec.",
|
|
333
|
+
"A planned row for a module that is no longer in the project is halted the same way, and dropped.",
|
|
334
|
+
],
|
|
335
|
+
parameters: HALT_PARAMS,
|
|
343
336
|
async execute(_id, params) {
|
|
344
|
-
if (params.job_id === undefined && params.
|
|
345
|
-
throw new Error(
|
|
346
|
-
}
|
|
337
|
+
if (params.job_id === undefined && params.launched === undefined)
|
|
338
|
+
throw new Error("Say what to halt: a job_id, or a launch (launched).");
|
|
347
339
|
const lines = [];
|
|
348
|
-
if (params.job_id !== undefined
|
|
340
|
+
if (params.job_id !== undefined)
|
|
349
341
|
lines.push(stopJob(jobs, params.job_id, params.reason, options.workLoop?.()));
|
|
350
|
-
if (params.
|
|
351
|
-
|
|
352
|
-
lines.push(stopped.length > 0 ? `Halted ${stopped.join(", ")}.` : `Nothing activate started is running${params.activated === "all" ? "" : ` as ${params.activated}`}.`);
|
|
353
|
-
}
|
|
342
|
+
if (params.launched !== undefined)
|
|
343
|
+
lines.push(await haltLaunched(params.launched, options.launches));
|
|
354
344
|
return { content: [{ type: "text", text: lines.join("\n") }], details: {} };
|
|
355
345
|
},
|
|
356
346
|
});
|
|
357
347
|
}
|
|
348
|
+
/** Halt what a launch started by its name, a module's launch under way and what it started, or every one: what was halted, said. */
|
|
349
|
+
export async function haltLaunched(which, launches) {
|
|
350
|
+
const all = which === "all";
|
|
351
|
+
const underWay = launches !== undefined && (all || launches.pending(which) !== undefined) ? await launches.stop(all ? undefined : which) : [];
|
|
352
|
+
const module = !all && runningLaunched(which).length > 0 && !runningLaunched().some((item) => item.name === which);
|
|
353
|
+
const before = runningLaunched();
|
|
354
|
+
const stopped = await stopLaunched(all ? {} : module || underWay.length > 0 ? { moduleName: which } : { name: which });
|
|
355
|
+
// The launches whose servers those were, with nothing of them left running: stopped too - a host hears it, and the next
|
|
356
|
+
// launch of the codebase launches anew.
|
|
357
|
+
const codebases = new Set(before.filter((item) => item.exited !== undefined).map((item) => item.moduleName));
|
|
358
|
+
for (const codebase of codebases)
|
|
359
|
+
launches?.halted(codebase);
|
|
360
|
+
const halted = [...underWay.map((id) => `the launch ${id}`), ...stopped];
|
|
361
|
+
return halted.length > 0 ? `Halted ${halted.join(", ")}.` : `Nothing a launch started is running${all ? "" : ` as ${which}`}, and no launch of it is under way.`;
|
|
362
|
+
}
|
package/dist/notice.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export interface NoticeInput {
|
|
|
35
35
|
check?: string;
|
|
36
36
|
/**
|
|
37
37
|
* The person may leave it as the build has it, for good (`{ ignore: true }`): a gap in the ***plain the build settled
|
|
38
|
-
* with an assumption - never something broken, a pulse that went wrong, a
|
|
38
|
+
* with an assumption - never something broken, a pulse that went wrong, a launch that did not come up, nor the
|
|
39
39
|
* question whether to start the sentinel.
|
|
40
40
|
*/
|
|
41
41
|
ignorable?: boolean;
|
|
@@ -85,8 +85,9 @@ export declare function describeNotice(notice: NoticeInput): string;
|
|
|
85
85
|
export declare function wentWrong(job: Job): boolean;
|
|
86
86
|
/**
|
|
87
87
|
* The sentinel done with a pulse - or a check a host asked for: whether what it checked holds, and what it checked and
|
|
88
|
-
* found, in a line or two. `unchecked`: a check that never
|
|
89
|
-
* be opened
|
|
88
|
+
* found, in a line or two. `unchecked`: a pulse or a check that was never checked - the person did not start the
|
|
89
|
+
* sentinel, it could not be opened, nothing of the module is launched to test a check in, or what runs cannot hold a
|
|
90
|
+
* pulse's commit - turri's own word, never the sentinel's.
|
|
90
91
|
*/
|
|
91
92
|
export interface Conclusion {
|
|
92
93
|
/** The pulse: its job id. Undefined for a check. */
|
|
@@ -99,12 +100,12 @@ export interface Conclusion {
|
|
|
99
100
|
pulse?: number;
|
|
100
101
|
}
|
|
101
102
|
/**
|
|
102
|
-
* Functional specs of a module a host asked the sentinel to check, in the module
|
|
103
|
-
*
|
|
103
|
+
* Functional specs of a module a host asked the sentinel to check, in what is launched of the module: its codebase's code,
|
|
104
|
+
* which holds every module its requires chain builds on. Queued with the pulses, in a conversation of its own.
|
|
104
105
|
*/
|
|
105
106
|
export interface SentinelCheck {
|
|
106
107
|
id: string;
|
|
107
|
-
/** The module
|
|
108
|
+
/** The module whose launch is tested, by name. */
|
|
108
109
|
module: string;
|
|
109
110
|
plainFile: string;
|
|
110
111
|
/** The functional specs to test, each `module:func-id` - of the module, or of a module its requires chain builds on. */
|
package/dist/plain-files.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
/**
|
|
3
3
|
* The project's ***plain and what it is built with, and a digest of each: its .plain files, the resources they link,
|
|
4
|
-
* its testing scripts and its config.turri*.yaml. Nothing else is a skill's to change - not the built code, a
|
|
4
|
+
* its testing scripts and its config.turri*.yaml. Nothing else is a skill's to change - not the built code, a launch,
|
|
5
5
|
* what a running app writes. `also`: paths that were among them before, digested while they are there, so one a skill
|
|
6
6
|
* stopped linking or naming is still seen if it changed it.
|
|
7
7
|
*/
|
|
@@ -11,7 +11,7 @@ export declare function changedFiles(before: Map<string, string>, after: Map<str
|
|
|
11
11
|
/**
|
|
12
12
|
* Why a skill's agent may not write a path, or nothing when it may. It writes the project's ***plain: a file of it
|
|
13
13
|
* (`projectFiles`), or a new one - a resource it is about to link, a testing script - anywhere in the project but where
|
|
14
|
-
* what is built,
|
|
14
|
+
* what is built, launched or installed lives. Never an existing file that is not the ***plain's: the code, a launch,
|
|
15
15
|
* what an app it started writes.
|
|
16
16
|
*/
|
|
17
17
|
export declare function plainWriteRefusal(root: string, path: string): string | undefined;
|
package/dist/plain-files.js
CHANGED
|
@@ -18,7 +18,7 @@ function outsidePlain(path) {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* The project's ***plain and what it is built with, and a digest of each: its .plain files, the resources they link,
|
|
21
|
-
* its testing scripts and its config.turri*.yaml. Nothing else is a skill's to change - not the built code, a
|
|
21
|
+
* its testing scripts and its config.turri*.yaml. Nothing else is a skill's to change - not the built code, a launch,
|
|
22
22
|
* what a running app writes. `also`: paths that were among them before, digested while they are there, so one a skill
|
|
23
23
|
* stopped linking or naming is still seen if it changed it.
|
|
24
24
|
*/
|
|
@@ -97,7 +97,7 @@ export function changedFiles(before, after) {
|
|
|
97
97
|
/**
|
|
98
98
|
* Why a skill's agent may not write a path, or nothing when it may. It writes the project's ***plain: a file of it
|
|
99
99
|
* (`projectFiles`), or a new one - a resource it is about to link, a testing script - anywhere in the project but where
|
|
100
|
-
* what is built,
|
|
100
|
+
* what is built, launched or installed lives. Never an existing file that is not the ***plain's: the code, a launch,
|
|
101
101
|
* what an app it started writes.
|
|
102
102
|
*/
|
|
103
103
|
export function plainWriteRefusal(root, path) {
|
|
@@ -109,7 +109,7 @@ export function plainWriteRefusal(root, path) {
|
|
|
109
109
|
const inProject = relative(resolve(root), absolute);
|
|
110
110
|
if (outsidePlain(inProject)) {
|
|
111
111
|
return (`${inProject} is not the project's ***plain - ${MODULES_DIR}/, ${DIST_DIR}/ and the hidden folders hold what is ` +
|
|
112
|
-
"built,
|
|
112
|
+
"built, launched and installed, and turri's own. A skill writes .plain files, the resources they link and the testing scripts.");
|
|
113
113
|
}
|
|
114
114
|
if (existsSync(absolute) && !projectFiles(root).has(inProject)) {
|
|
115
115
|
return (`${inProject} is not the project's ***plain: no .plain file links it, and it is not a testing script or a ` +
|
|
@@ -40,11 +40,17 @@ export declare function machineReadable(platform?: NodeJS.Platform): string[];
|
|
|
40
40
|
* Why a command line changes the machine - installs software outside the project, or changes a setting of the
|
|
41
41
|
* machine's or the person's environment - or nothing when it does not. The project's own dependencies, installed into
|
|
42
42
|
* the project (npm install, a venv, mvn, cargo), change nothing of the machine's. turri changes the machine nowhere: not
|
|
43
|
-
* an agent, not the chat, not a
|
|
43
|
+
* an agent, not the chat, not a launch - what the machine lacks is the person's to install, in their own words.
|
|
44
44
|
*/
|
|
45
45
|
export declare function machineChange(command: string): string | undefined;
|
|
46
46
|
/** The .plain file a command line writes - a ***plain module or a test plain file - or nothing when it writes none. */
|
|
47
47
|
export declare function writesPlain(command: string): string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* The path in plain_modules a command line runs in or from - `cd` there and run something, a program or its arguments
|
|
50
|
+
* there, an environment variable pointing there - or nothing when it only reads there, or does not go there. The code in
|
|
51
|
+
* plain_modules is what a pulse may be writing, and nobody launched it.
|
|
52
|
+
*/
|
|
53
|
+
export declare function runsBuiltCode(command: string): string | undefined;
|
|
48
54
|
/** What turri says when a command would change the machine: what it does instead. */
|
|
49
55
|
export declare function machineChangeReason(why: string): string;
|
|
50
56
|
/** Check one command line against a role's fence: `{ ok: true }`, or which rule it breaks and what to do instead. */
|
|
@@ -166,7 +166,7 @@ function systemSettingIn(segment) {
|
|
|
166
166
|
* Why a command line changes the machine - installs software outside the project, or changes a setting of the
|
|
167
167
|
* machine's or the person's environment - or nothing when it does not. The project's own dependencies, installed into
|
|
168
168
|
* the project (npm install, a venv, mvn, cargo), change nothing of the machine's. turri changes the machine nowhere: not
|
|
169
|
-
* an agent, not the chat, not a
|
|
169
|
+
* an agent, not the chat, not a launch - what the machine lacks is the person's to install, in their own words.
|
|
170
170
|
*/
|
|
171
171
|
export function machineChange(command) {
|
|
172
172
|
if (PIPED_DOWNLOAD.test(command) || RUN_DOWNLOAD.test(command))
|
|
@@ -192,6 +192,48 @@ export function writesPlain(command) {
|
|
|
192
192
|
}
|
|
193
193
|
return undefined;
|
|
194
194
|
}
|
|
195
|
+
/** Programs that only read what they are pointed at: run on built code, they start nothing of it. */
|
|
196
|
+
const READERS = new Set(["ls", "cat", "head", "tail", "less", "more", "grep", "rg", "find", "git", "wc", "diff", "tree", "file", "stat", "du", "jq", "echo", "pwd", "true", "test", "["]);
|
|
197
|
+
/**
|
|
198
|
+
* The path in plain_modules a command line runs in or from - `cd` there and run something, a program or its arguments
|
|
199
|
+
* there, an environment variable pointing there - or nothing when it only reads there, or does not go there. The code in
|
|
200
|
+
* plain_modules is what a pulse may be writing, and nobody launched it.
|
|
201
|
+
*/
|
|
202
|
+
export function runsBuiltCode(command) {
|
|
203
|
+
let inBuilt;
|
|
204
|
+
for (const part of command.split(/&&|\|\||[;|\n]/)) {
|
|
205
|
+
const words = part.trim().split(/\s+/).filter((word) => word !== "").map((word) => word.replace(/^["']|["']$/g, ""));
|
|
206
|
+
let at = 0;
|
|
207
|
+
while (at < words.length && /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[at])) {
|
|
208
|
+
if (words[at].includes("plain_modules"))
|
|
209
|
+
return words[at].slice(words[at].indexOf("=") + 1);
|
|
210
|
+
at += 1;
|
|
211
|
+
}
|
|
212
|
+
const program = words[at];
|
|
213
|
+
if (program === undefined)
|
|
214
|
+
continue;
|
|
215
|
+
const args = words.slice(at + 1);
|
|
216
|
+
if (program === "cd" || program === "pushd") {
|
|
217
|
+
const to = args[0];
|
|
218
|
+
if (to !== undefined && to.includes("plain_modules"))
|
|
219
|
+
inBuilt = to;
|
|
220
|
+
else if (to !== undefined)
|
|
221
|
+
inBuilt = undefined;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const name = program.split("/").pop();
|
|
225
|
+
if (program.includes("plain_modules"))
|
|
226
|
+
return program;
|
|
227
|
+
if (READERS.has(name))
|
|
228
|
+
continue;
|
|
229
|
+
const there = args.find((arg) => arg.includes("plain_modules"));
|
|
230
|
+
if (there !== undefined)
|
|
231
|
+
return there;
|
|
232
|
+
if (inBuilt !== undefined)
|
|
233
|
+
return inBuilt;
|
|
234
|
+
}
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
195
237
|
/** What turri says when a command would change the machine: what it does instead. */
|
|
196
238
|
export function machineChangeReason(why) {
|
|
197
239
|
return (`turri changes nothing of this machine's - ${why}. Nothing is installed by turri, and no setting of the machine's or the ` +
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** A command-line run has no one to ask: the command that
|
|
1
|
+
/** A command-line run has no one to ask: the command that launches what it built. */
|
|
2
2
|
export declare function tryItCommand(plainFile: string): string;
|