@turri-dev/cli 0.2.4-next.009bd0c → 0.2.4-next.359b847
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/dist/extension.d.ts +13 -2
- package/dist/extension.js +52 -18
- package/dist/launch-agent.d.ts +10 -0
- package/dist/launch-agent.js +58 -10
- package/dist/launch-session.d.ts +12 -2
- package/dist/launch-session.js +28 -6
- package/dist/launch-track.d.ts +6 -1
- package/dist/launch-track.js +25 -3
- package/dist/regenerate/command-check.d.ts +6 -0
- package/dist/regenerate/command-check.js +42 -0
- package/dist/regenerate/launch.d.ts +28 -0
- package/dist/regenerate/launch.js +135 -3
- package/dist/regenerate/ledger.d.ts +8 -0
- package/dist/regenerate/loop.d.ts +12 -2
- package/dist/regenerate/loop.js +12 -5
- package/dist/sentinel.d.ts +1 -0
- package/dist/sentinel.js +9 -9
- package/docs/hosting.md +2 -2
- package/docs/launch.md +5 -1
- package/docs/sentinel.md +2 -1
- package/docs/using.md +2 -2
- package/package.json +1 -1
package/dist/extension.d.ts
CHANGED
|
@@ -71,14 +71,25 @@ export declare function asksOneByOne(words: string): boolean;
|
|
|
71
71
|
export declare function shownAfterCommand(pi: ExtensionAPI, ctx: ExtensionContext, command: string, text: string, level: NonNullable<CommandOutcome["level"]>,
|
|
72
72
|
/** The command is in the chat already, above it (echoCommand): the text alone. */
|
|
73
73
|
echoed?: boolean, react?: string): void;
|
|
74
|
+
/**
|
|
75
|
+
* What a slash command found for the agent alone - guidance the person need not see: put in the conversation unseen,
|
|
76
|
+
* and the agent started on it - at once when it is idle, else once its turn ends - told what to do with it.
|
|
77
|
+
*/
|
|
78
|
+
export declare function toldAfterCommand(pi: ExtensionAPI, command: string, text: string, react: string): void;
|
|
74
79
|
/**
|
|
75
80
|
* What the agent does once /regenerate or /conform has started pulses: a command's output alone leaves the chat silent,
|
|
76
81
|
* and the person wondering whether to wait. It says what runs, and that they need not - and starts nothing itself.
|
|
77
82
|
*/
|
|
78
83
|
export declare const COMMAND_STARTED_REACTION: string;
|
|
79
84
|
/**
|
|
80
|
-
* What the agent does when /conform
|
|
81
|
-
*
|
|
85
|
+
* What the agent does when /conform found a step of adding tests still to take: takes it at once, asking nothing - the
|
|
86
|
+
* /conform was the person's yes - and says what it writes as the way there, never as a failure: the person saw none.
|
|
87
|
+
*/
|
|
88
|
+
export declare const CONFORM_STEPS_REACTION: string;
|
|
89
|
+
/**
|
|
90
|
+
* What the agent does when /conform started nothing for a reason that is not a step of adding tests - a functional spec
|
|
91
|
+
* named that is not there, words it does not take: answers it at once - why, and what would let it start - rather than
|
|
92
|
+
* leave the person with a refusal and a silent chat.
|
|
82
93
|
*/
|
|
83
94
|
export declare const CONFORM_REFUSED_REACTION: string;
|
|
84
95
|
export declare const COMMAND_OUTCOME = "turri_command_outcome";
|
package/dist/extension.js
CHANGED
|
@@ -28,7 +28,7 @@ import { unqueue } from "./chat-waiting.js";
|
|
|
28
28
|
import { skillStatus } from "./skill.js";
|
|
29
29
|
import { runningLaunched, stopLaunched } from "./regenerate/launch.js";
|
|
30
30
|
import { launchTool } from "./launch-tools.js";
|
|
31
|
-
import { createSessionLaunches, launchedNote, replacedNote } from "./launch-session.js";
|
|
31
|
+
import { createSessionLaunches, launchedDir, launchedNote, replacedNote } from "./launch-session.js";
|
|
32
32
|
import { describeLaunchLine } from "./launch-track.js";
|
|
33
33
|
import { checkedSpecs } from "./sentinel-check.js";
|
|
34
34
|
import { createSteeringStore, EVERY_MODULE, moduleNameOf, queueSectionOf, steeringFor } from "./regenerate/steer.js";
|
|
@@ -40,7 +40,7 @@ import { checkPlainTool } from "./parse-tool.js";
|
|
|
40
40
|
import { changedFiles, projectFiles } from "./plain-files.js";
|
|
41
41
|
import { whyFailed } from "./regenerate/diagnose-job.js";
|
|
42
42
|
import { didNotLand } from "./regenerate/failure-reports.js";
|
|
43
|
-
import { conformanceRefusal, createWorkLoop, describeModules, isUpToDate } from "./regenerate/loop.js";
|
|
43
|
+
import { conformanceRefusal, createWorkLoop, TestingStepsMissing, describeModules, isUpToDate } from "./regenerate/loop.js";
|
|
44
44
|
import { brandNeon, brandPink, plainPaint } from "./regenerate/plain-palette.js";
|
|
45
45
|
import { halfBlocks, JELLYFISH_FRAME_MS, JELLYFISH_REST, JELLYFISH_SEQUENCE, JELLYFISH_TEXT_FRAMES } from "./jellyfish.js";
|
|
46
46
|
import { createJobPanel, didNotPass, keyPressed, PANEL_KEY, spinner } from "./regenerate/job-panel.js";
|
|
@@ -62,7 +62,7 @@ import { doctorTool } from "./doctor-tool.js";
|
|
|
62
62
|
import { describeSpecConflict } from "./regenerate/stop-report.js";
|
|
63
63
|
import { inheritProviders, inheritThinkingLevel } from "./pi.js";
|
|
64
64
|
import { LOADING_PROVIDERS } from "./installed-providers.js";
|
|
65
|
-
import { machineChange, machineChangeReason, writesPlain } from "./regenerate/command-check.js";
|
|
65
|
+
import { machineChange, machineChangeReason, runsBuiltCode, writesPlain } from "./regenerate/command-check.js";
|
|
66
66
|
import { beginCapture, captureConsole, describeCaptured, dropNoise } from "./quiet.js";
|
|
67
67
|
import { loadRules, renderRulesBlock } from "./rules.js";
|
|
68
68
|
import { registerSettings, ruleNames } from "./settings.js";
|
|
@@ -512,6 +512,7 @@ function turriExtension(api, session, link) {
|
|
|
512
512
|
running: runningLaunched(check.module),
|
|
513
513
|
...(commit !== undefined ? { commit } : {}),
|
|
514
514
|
...(current?.status === "failed" ? { failed: { id: current.id, ...(current.summary !== undefined ? { summary: current.summary } : {}) } } : {}),
|
|
515
|
+
...(current !== undefined ? { dir: launchedDir(current) } : {}),
|
|
515
516
|
...(context.focused !== undefined ? { focused: context.focused } : {}),
|
|
516
517
|
});
|
|
517
518
|
void pi.sendMessage({ customType: "turri_sentinel_check", content, display: false, details: { checkId: check.id, module: check.module, funcIds: check.funcIds } }, { triggerTurn: true });
|
|
@@ -651,6 +652,14 @@ function turriExtension(api, session, link) {
|
|
|
651
652
|
const plain = isSentinel ? writesPlain(command) : undefined;
|
|
652
653
|
if (plain !== undefined)
|
|
653
654
|
return { block: true, reason: `${plain} is ***plain: the sentinel never changes it - put what it needs to the person with notify_person.` };
|
|
655
|
+
// Nor does a host's terminal start the code in plain_modules for it: what it tests is what is launched.
|
|
656
|
+
const built = isSentinel && event.toolName !== "bash" ? runsBuiltCode(command) : undefined;
|
|
657
|
+
if (built !== undefined) {
|
|
658
|
+
return {
|
|
659
|
+
block: true,
|
|
660
|
+
reason: `${built} is in plain_modules - the code a pulse may be writing, which nobody launched: the sentinel never runs it, nor starts a server of its own. Test what is launched, from where its brief says; a server that should run and does not is your finding.`,
|
|
661
|
+
};
|
|
662
|
+
}
|
|
654
663
|
}
|
|
655
664
|
if (event.toolName === "bash" && typeof command === "string") {
|
|
656
665
|
const what = selfInvocation(command);
|
|
@@ -1282,6 +1291,14 @@ echoed = false, react) {
|
|
|
1282
1291
|
else
|
|
1283
1292
|
void pi.sendMessage({ customType: COMMAND_OUTCOME, content, display: false }, { triggerTurn: true, deliverAs: "followUp" });
|
|
1284
1293
|
}
|
|
1294
|
+
/**
|
|
1295
|
+
* What a slash command found for the agent alone - guidance the person need not see: put in the conversation unseen,
|
|
1296
|
+
* and the agent started on it - at once when it is idle, else once its turn ends - told what to do with it.
|
|
1297
|
+
*/
|
|
1298
|
+
export function toldAfterCommand(pi, command, text, react) {
|
|
1299
|
+
const content = `The person ran ${command}. Not shown to them:\n${text}\n\n${react}`;
|
|
1300
|
+
void pi.sendMessage({ customType: COMMAND_OUTCOME, content, display: false }, { triggerTurn: true, deliverAs: "followUp" });
|
|
1301
|
+
}
|
|
1285
1302
|
/**
|
|
1286
1303
|
* What the agent does once /regenerate or /conform has started pulses: a command's output alone leaves the chat silent,
|
|
1287
1304
|
* and the person wondering whether to wait. It says what runs, and that they need not - and starts nothing itself.
|
|
@@ -1290,19 +1307,25 @@ export const COMMAND_STARTED_REACTION = "My pulses are running from the person's
|
|
|
1290
1307
|
"runs and what is planned - and that the two of us can go on with the ***plain, or anything else, meanwhile: they need " +
|
|
1291
1308
|
"not wait for it. Start nothing for it: no regenerate, no check, no launch - its end is told when it comes.";
|
|
1292
1309
|
/**
|
|
1293
|
-
* What the agent does when /conform
|
|
1294
|
-
*
|
|
1310
|
+
* What the agent does when /conform found a step of adding tests still to take: takes it at once, asking nothing - the
|
|
1311
|
+
* /conform was the person's yes - and says what it writes as the way there, never as a failure: the person saw none.
|
|
1295
1312
|
*/
|
|
1296
|
-
export const
|
|
1297
|
-
"
|
|
1298
|
-
"
|
|
1299
|
-
"
|
|
1300
|
-
"
|
|
1301
|
-
"
|
|
1302
|
-
"
|
|
1303
|
-
"each functional spec why it needs scenarios - or, when none does, that and why.
|
|
1304
|
-
|
|
1305
|
-
|
|
1313
|
+
export const CONFORM_STEPS_REACTION = "That is what conform needs before it can start - the steps of adding tests still to take - not an error: nothing " +
|
|
1314
|
+
"failed, and the person saw none of it. Their /conform is their yes to conformance tests here, so take the steps now, " +
|
|
1315
|
+
"in that order and only what is missing, asking nothing: the test reqs first; then the conformance testing script, " +
|
|
1316
|
+
"started with its skill before anything else - it runs in the background, so the scenarios are written while it does; " +
|
|
1317
|
+
"then the scenarios of the functional specs they named, or, naming none, of each functional spec that needs them by " +
|
|
1318
|
+
"the rules on test plain files. Then call regenerate for the module: the work loop writes and runs their tests once the " +
|
|
1319
|
+
"code is built. Tell the person in a line or two, as the way to their conformance tests and not as a refusal, what you " +
|
|
1320
|
+
"are writing, and for each functional spec why it needs scenarios - or, when none does, that and why.";
|
|
1321
|
+
/**
|
|
1322
|
+
* What the agent does when /conform started nothing for a reason that is not a step of adding tests - a functional spec
|
|
1323
|
+
* named that is not there, words it does not take: answers it at once - why, and what would let it start - rather than
|
|
1324
|
+
* leave the person with a refusal and a silent chat.
|
|
1325
|
+
*/
|
|
1326
|
+
export const CONFORM_REFUSED_REACTION = "Nothing was started from the person's /conform, for the reason shown. Tell them in a line or two why, and what would " +
|
|
1327
|
+
"let it start - a functional spec they named that is not there, ***plain that does not parse or would have to change its " +
|
|
1328
|
+
"meaning to be tested - and offer to do what is yours to do; start nothing.";
|
|
1306
1329
|
export const COMMAND_OUTCOME = "turri_command_outcome";
|
|
1307
1330
|
/** Longer than a frame of the TUI's (16ms): an entry appended before it is drawn by its end. */
|
|
1308
1331
|
const ONE_FRAME_MS = 20;
|
|
@@ -1407,10 +1430,18 @@ function registerBind(pi, cwd, jobs, turnOn) {
|
|
|
1407
1430
|
refusal = whenBuildable(plainFile, () => conformanceRefusal(plainFile, funcIds.length > 0 ? funcIds : undefined));
|
|
1408
1431
|
}
|
|
1409
1432
|
catch (error) {
|
|
1410
|
-
refusal = error instanceof Error ? error.message : String(error);
|
|
1433
|
+
refusal = { text: error instanceof Error ? error.message : String(error), stepsMissing: false };
|
|
1434
|
+
}
|
|
1435
|
+
// A step of adding tests still to take - the test reqs, the script, the scenarios: the chat's to take, so told to it
|
|
1436
|
+
// alone, as what conform needs first. The person sees it take them, and conformance turned on, if it was.
|
|
1437
|
+
if (refusal?.stepsMissing === true) {
|
|
1438
|
+
if (turnedOn !== undefined)
|
|
1439
|
+
shownAfterCommand(pi, ctx, command, turnedOn, "info", true);
|
|
1440
|
+
toldAfterCommand(pi, command, refusal.text, CONFORM_STEPS_REACTION);
|
|
1441
|
+
return;
|
|
1411
1442
|
}
|
|
1412
1443
|
if (refusal !== undefined) {
|
|
1413
|
-
refuse(withTurnedOn(refusal));
|
|
1444
|
+
refuse(withTurnedOn(refusal.text));
|
|
1414
1445
|
return;
|
|
1415
1446
|
}
|
|
1416
1447
|
const module = basename(plainFile).replace(/\.plain$/, "");
|
|
@@ -1436,7 +1467,10 @@ function registerBind(pi, cwd, jobs, turnOn) {
|
|
|
1436
1467
|
shownAfterCommand(pi, ctx, command, text, "info", true, upToDate ? undefined : COMMAND_STARTED_REACTION);
|
|
1437
1468
|
}
|
|
1438
1469
|
catch (error) {
|
|
1439
|
-
|
|
1470
|
+
if (error instanceof TestingStepsMissing)
|
|
1471
|
+
toldAfterCommand(pi, command, error.message, CONFORM_STEPS_REACTION);
|
|
1472
|
+
else
|
|
1473
|
+
refuse(error instanceof Error ? error.message : String(error));
|
|
1440
1474
|
}
|
|
1441
1475
|
})().catch(() => {
|
|
1442
1476
|
// The chat let go meanwhile: there is nobody to say it to.
|
package/dist/launch-agent.d.ts
CHANGED
|
@@ -23,6 +23,16 @@ export declare function projectNotes(dirs: string[]): string[];
|
|
|
23
23
|
* group, its output kept, stopped on the codebase's next launch, on /halt and when turri exits.
|
|
24
24
|
*/
|
|
25
25
|
export declare function activateTool(launch: Pick<Launch, "codebase" | "plainFile" | "hostDir">, code: Pick<ExportedCode, "dir">): AnyTool;
|
|
26
|
+
/**
|
|
27
|
+
* Why a launch said to be up is not: it says something serves - `serves`, or a URL in its summary - and nothing this
|
|
28
|
+
* launch started with activate still runs. Something else answering there - an earlier build left running, another
|
|
29
|
+
* program - is not this launch. Undefined when it holds.
|
|
30
|
+
*/
|
|
31
|
+
export declare function notBacked(launch: Pick<Launch, "codebase" | "serversSince">, outcome: {
|
|
32
|
+
launched: boolean;
|
|
33
|
+
summary: string;
|
|
34
|
+
serves?: boolean;
|
|
35
|
+
}): string | undefined;
|
|
26
36
|
/** What the agent does once the code is in dist: find guidance and follow it from the host, or start it from dist. */
|
|
27
37
|
export declare function launchGuide(code: ExportedCode, hostDir: string): string;
|
|
28
38
|
export interface LaunchAgentInput {
|
package/dist/launch-agent.js
CHANGED
|
@@ -2,7 +2,7 @@ import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, defineTool, } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { Type } from "typebox";
|
|
5
|
-
import { describeExport, launchLogDir, shortPath, startLaunched } from "./regenerate/launch.js";
|
|
5
|
+
import { describeExport, holderOf, launchLogDir, runningLaunched, shortPath, startLaunched } from "./regenerate/launch.js";
|
|
6
6
|
import { machineChange, machineChangeReason } from "./regenerate/command-check.js";
|
|
7
7
|
import { projectDirOf } from "./regenerate/paths.js";
|
|
8
8
|
import { ask, BEGIN, createExecutor } from "./pi.js";
|
|
@@ -115,20 +115,61 @@ export function activateTool(launch, code) {
|
|
|
115
115
|
},
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
|
+
/** The ports of the URLs a summary names. */
|
|
119
|
+
function portsIn(summary) {
|
|
120
|
+
const ports = new Set();
|
|
121
|
+
for (const match of summary.matchAll(/\bhttps?:\/\/[^\s/"'`)<>]+/g)) {
|
|
122
|
+
try {
|
|
123
|
+
const url = new URL(match[0]);
|
|
124
|
+
ports.add(url.port !== "" ? Number(url.port) : url.protocol === "https:" ? 443 : 80);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
/* not a URL after all */
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return [...ports];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Why a launch said to be up is not: it says something serves - `serves`, or a URL in its summary - and nothing this
|
|
134
|
+
* launch started with activate still runs. Something else answering there - an earlier build left running, another
|
|
135
|
+
* program - is not this launch. Undefined when it holds.
|
|
136
|
+
*/
|
|
137
|
+
export function notBacked(launch, outcome) {
|
|
138
|
+
if (!outcome.launched)
|
|
139
|
+
return undefined;
|
|
140
|
+
const ports = portsIn(outcome.summary);
|
|
141
|
+
if (outcome.serves !== true && ports.length === 0)
|
|
142
|
+
return undefined;
|
|
143
|
+
const since = launch.serversSince ?? 0;
|
|
144
|
+
if (runningLaunched(launch.codebase).some((item) => item.startedAt >= since))
|
|
145
|
+
return undefined;
|
|
146
|
+
const holders = ports.map((port) => ({ port, holder: holderOf(port) })).filter((each) => each.holder !== "");
|
|
147
|
+
return [
|
|
148
|
+
`nothing this launch started with activate is running, so what answers${ports.length > 0 ? ` at port ${ports.join(", ")}` : ""} is not this launch's code${holders.length > 0 ? " - it is held by something else:" : "."}`,
|
|
149
|
+
...holders.map((each) => `port ${each.port}:\n${each.holder}`),
|
|
150
|
+
].join("\n");
|
|
151
|
+
}
|
|
118
152
|
/** submit_launch: how the launch went, once, last - the harness reads its arguments, never the agent's prose. */
|
|
119
|
-
function submitLaunchTool(submitted) {
|
|
153
|
+
function submitLaunchTool(launch, submitted) {
|
|
120
154
|
return defineTool({
|
|
121
155
|
name: "submit_launch",
|
|
122
156
|
label: "Submit launch",
|
|
123
157
|
description: "Say how the launch went - once, last. launched: true when it is running, or in place for the person to try - a CLI " +
|
|
124
158
|
"or a library ready to run from its folder; false when it is not. The summary is what the person is told: where to " +
|
|
125
|
-
"open it, or what to run - or why it did not come up, and what they can do."
|
|
159
|
+
"open it, or what to run - or why it did not come up, and what they can do. Something that serves counts as running " +
|
|
160
|
+
"only when you started it with activate and it still runs: something else answering at its port - an earlier build, " +
|
|
161
|
+
"another program - is not it, and is refused.",
|
|
126
162
|
parameters: Type.Object({
|
|
127
163
|
launched: Type.Boolean({ description: "true: it runs, or is in place to try; false: it did not come up" }),
|
|
164
|
+
serves: Type.Boolean({ description: "true: something keeps running for the person to open or call - a backend, a frontend; false: a CLI or a library, tried from its folder" }),
|
|
128
165
|
summary: Type.String({ description: "In a line or three: where it runs - the URL to open, the API's in a line - or the commands to try it; or why it did not come up" }),
|
|
129
166
|
}),
|
|
130
167
|
async execute(_id, params) {
|
|
131
|
-
|
|
168
|
+
const why = notBacked(launch, params);
|
|
169
|
+
if (why !== undefined) {
|
|
170
|
+
throw new Error(`Not taken: you say it runs, but ${why}\nStart it with activate - stopping nothing turri did not start - or call submit_launch with launched false, saying what holds the port.`);
|
|
171
|
+
}
|
|
172
|
+
submitted.outcome = { launched: params.launched, summary: params.summary, serves: params.serves };
|
|
132
173
|
return text("Taken. You are done: end your turn.");
|
|
133
174
|
},
|
|
134
175
|
});
|
|
@@ -157,9 +198,11 @@ export function launchGuide(code, hostDir) {
|
|
|
157
198
|
"",
|
|
158
199
|
`Either way, never change ${built} or ${dist}: they are what was built, and a fix belongs in the ***plain. A config file it needs made from its example (a .env from .env.example) is fine. A port that is taken: say which and by what, and do not move the app to another.`,
|
|
159
200
|
"",
|
|
160
|
-
"Last, call submit_launch once: launched, and in a line or three where to open it - the frontend's URL,
|
|
161
|
-
"line when there is one - or, a CLI or a library, a few commands to paste, run from its folder, with
|
|
162
|
-
"why it did not come up. Where the guidance does not fit what you find, say so, and do not guess past it.",
|
|
201
|
+
"Last, call submit_launch once: launched, whether it serves, and in a line or three where to open it - the frontend's URL,",
|
|
202
|
+
"and the API's in one line when there is one - or, a CLI or a library, a few commands to paste, run from its folder, with",
|
|
203
|
+
"what they print; or why it did not come up. Where the guidance does not fit what you find, say so, and do not guess past it.",
|
|
204
|
+
"Something answering at the app's port that you did not start with activate - an earlier build left running, another",
|
|
205
|
+
"program - is not this launch: it is not launched, and you say what holds the port. Never stop a process you did not start.",
|
|
163
206
|
].join("\n");
|
|
164
207
|
}
|
|
165
208
|
/** Run the launch agent to its end: how it went, as it submitted it - or, never submitted, its last words as a failure. */
|
|
@@ -177,7 +220,7 @@ export async function runLaunchAgent(input) {
|
|
|
177
220
|
outsideBuiltCode(createWriteToolDefinition(dir), dir),
|
|
178
221
|
];
|
|
179
222
|
const submitted = {};
|
|
180
|
-
const tools = [activateTool(launch, code), submitLaunchTool(submitted)];
|
|
223
|
+
const tools = [activateTool(launch, code), submitLaunchTool(launch, submitted)];
|
|
181
224
|
const executor = await createExecutor({
|
|
182
225
|
// Its sessions are kept in the project, not in the folder it launches.
|
|
183
226
|
cwd: projectDirOf(launch.plainFile),
|
|
@@ -204,13 +247,18 @@ export async function runLaunchAgent(input) {
|
|
|
204
247
|
});
|
|
205
248
|
const stop = () => void executor.abort();
|
|
206
249
|
input.signal?.addEventListener("abort", stop, { once: true });
|
|
250
|
+
// What it said is checked again as it ends: a server it started may have exited since.
|
|
251
|
+
const checked = (outcome) => {
|
|
252
|
+
const why = notBacked(launch, outcome);
|
|
253
|
+
return why !== undefined ? { launched: false, summary: `Not launched: the launch agent said it runs, but ${why}` } : { launched: outcome.launched, summary: outcome.summary };
|
|
254
|
+
};
|
|
207
255
|
try {
|
|
208
256
|
const said = await ask(executor, BEGIN, input.onDelta);
|
|
209
257
|
if (submitted.outcome !== undefined)
|
|
210
|
-
return submitted.outcome;
|
|
258
|
+
return checked(submitted.outcome);
|
|
211
259
|
// Ended without saying how it went: asked once more, then taken as not launched.
|
|
212
260
|
const again = await ask(executor, "Call submit_launch now: launched or not, and in a line or three where it runs or why it did not come up.", input.onDelta);
|
|
213
|
-
return submitted.outcome
|
|
261
|
+
return submitted.outcome !== undefined ? checked(submitted.outcome) : { launched: false, summary: (again.trim() || said.trim() || "The launch agent ended without saying how it went.") };
|
|
214
262
|
}
|
|
215
263
|
finally {
|
|
216
264
|
input.signal?.removeEventListener("abort", stop);
|
package/dist/launch-session.d.ts
CHANGED
|
@@ -47,8 +47,18 @@ export declare function createSessionLaunches(options: {
|
|
|
47
47
|
model: (plainFile: string) => string | undefined;
|
|
48
48
|
onChange: (launch: Launch) => void;
|
|
49
49
|
}): SessionLaunches;
|
|
50
|
-
/**
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* What the sentinel tests in, whatever is launched: what turri launched, and nothing it starts itself. Said in every
|
|
52
|
+
* brief - a server it starts from plain_modules would pass on code nobody launched.
|
|
53
|
+
*/
|
|
54
|
+
export declare const LAUNCHED_ONLY = "Never run the code in plain_modules, where a pulse may be writing, nor start a server of your own - not in your shell, not with a host's terminal: what would pass there is not what the person tries. A server that should run and does not is your finding.";
|
|
55
|
+
/** The folder a launch's code is in: dist/<module>, where it is tried from. */
|
|
56
|
+
export declare function launchedDir(launch: Pick<Launch, "code" | "plainFile" | "codebase">): string;
|
|
57
|
+
/**
|
|
58
|
+
* What runs of a launch, a line each: where, from where, its output - or that nothing was left running, and the folder it
|
|
59
|
+
* is tried from.
|
|
60
|
+
*/
|
|
61
|
+
export declare function whatRuns(running: LaunchedProcess[], from?: string): string[];
|
|
52
62
|
/**
|
|
53
63
|
* What the chat that asked for a launch is told when a newer one takes its place - superseded as it waited, or ended with
|
|
54
64
|
* the newer one waiting, which stops what it started: it is told the newer one's end instead.
|
package/dist/launch-session.js
CHANGED
|
@@ -2,6 +2,7 @@ import { configForSpec, readProjectConfig } from "./config.js";
|
|
|
2
2
|
import { createLaunchTrack } from "./launch-track.js";
|
|
3
3
|
import { runLaunchAgent } from "./launch-agent.js";
|
|
4
4
|
import { holdsCommit, runningLaunched } from "./regenerate/launch.js";
|
|
5
|
+
import { distDirFor, projectDirOf } from "./regenerate/paths.js";
|
|
5
6
|
import { pulseName } from "./regenerate/jobs.js";
|
|
6
7
|
/** How long a pulse that landed is waited for to say its commit: the loop says it as the pulse settles. */
|
|
7
8
|
const COMMIT_WAIT_MS = 10_000;
|
|
@@ -16,6 +17,8 @@ export function createSessionLaunches(options) {
|
|
|
16
17
|
},
|
|
17
18
|
onChange: options.onChange,
|
|
18
19
|
});
|
|
20
|
+
// What an earlier session's launches left running holds the ports this one's need: stopped as the session starts.
|
|
21
|
+
void track.sweep().catch(() => undefined);
|
|
19
22
|
/** Whether the pulse's module launches what lands: its config as the pulse was queued with it. */
|
|
20
23
|
const launchesAfter = (job) => {
|
|
21
24
|
try {
|
|
@@ -134,8 +137,9 @@ export function createSessionLaunches(options) {
|
|
|
134
137
|
return [
|
|
135
138
|
`What you were testing was launched again: ${launch.codebase} at ${launch.short} (${launch.id}${launch.status === "failed" ? ", which did not come up" : ""}). It still holds pulse ${work.job.id}'s commit, ${short(landing.commit)}.`,
|
|
136
139
|
launch.status === "failed" ? `It did not come up: ${launch.summary ?? "the launch agent did not say why"}. That is what you find out about now.` : "What runs now:",
|
|
137
|
-
...(launch.status === "failed" ? [] : whatRuns(runningLaunched(launch.codebase))),
|
|
140
|
+
...(launch.status === "failed" ? [] : whatRuns(runningLaunched(launch.codebase), launchedDir(launch))),
|
|
138
141
|
"",
|
|
142
|
+
LAUNCHED_ONLY,
|
|
139
143
|
"Carry on the check where you were. Do again what you were doing as it restarted: what failed then may have failed for that alone.",
|
|
140
144
|
].join("\n");
|
|
141
145
|
}
|
|
@@ -144,8 +148,9 @@ export function createSessionLaunches(options) {
|
|
|
144
148
|
throw new Error(`nothing of ${work.check.module} runs any more to test check ${work.check.id} in.`);
|
|
145
149
|
return [
|
|
146
150
|
`What you were testing was launched again: ${work.check.module}${track.current(work.check.module) !== undefined ? ` at ${track.current(work.check.module).short}` : ""}. What runs now:`,
|
|
147
|
-
...whatRuns(running),
|
|
151
|
+
...whatRuns(running, track.current(work.check.module) !== undefined ? launchedDir(track.current(work.check.module)) : undefined),
|
|
148
152
|
"",
|
|
153
|
+
LAUNCHED_ONLY,
|
|
149
154
|
"Carry on the check where you were. Do again what you were doing as it restarted: what failed then may have failed for that alone.",
|
|
150
155
|
].join("\n");
|
|
151
156
|
},
|
|
@@ -156,10 +161,27 @@ function specsOf(job) {
|
|
|
156
161
|
const cases = job.cases;
|
|
157
162
|
return cases === undefined ? [] : [...cases.add, ...cases.patch, ...cases.again, ...cases.delete];
|
|
158
163
|
}
|
|
159
|
-
/**
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
164
|
+
/**
|
|
165
|
+
* What the sentinel tests in, whatever is launched: what turri launched, and nothing it starts itself. Said in every
|
|
166
|
+
* brief - a server it starts from plain_modules would pass on code nobody launched.
|
|
167
|
+
*/
|
|
168
|
+
export const LAUNCHED_ONLY = "Never run the code in plain_modules, where a pulse may be writing, nor start a server of your own - not in your shell, not with a host's terminal: what would pass there is not what the person tries. A server that should run and does not is your finding.";
|
|
169
|
+
/** The folder a launch's code is in: dist/<module>, where it is tried from. */
|
|
170
|
+
export function launchedDir(launch) {
|
|
171
|
+
return launch.code?.dir ?? distDirFor(projectDirOf(launch.plainFile), launch.codebase);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* What runs of a launch, a line each: where, from where, its output - or that nothing was left running, and the folder it
|
|
175
|
+
* is tried from.
|
|
176
|
+
*/
|
|
177
|
+
export function whatRuns(running, from) {
|
|
178
|
+
if (running.length === 0) {
|
|
179
|
+
return [
|
|
180
|
+
from !== undefined
|
|
181
|
+
? ` nothing is left running. It is in place in ${from}: try it from there - a CLI or a library as its README and entry points say. Something there that should serve and does not is what you find out about.`
|
|
182
|
+
: " nothing is left running.",
|
|
183
|
+
];
|
|
184
|
+
}
|
|
163
185
|
return running.map((item) => ` ${item.name}: ${item.url ?? item.command} - in ${item.dir}, its output in ${item.log}`);
|
|
164
186
|
}
|
|
165
187
|
/** Why a launch was asked for, as the chat is told it: after which pulse landed - nothing for one a chat asked for. */
|
package/dist/launch-track.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ExportedCode, type LaunchedProcess } from "./regenerate/launch.ts";
|
|
1
|
+
import { type ExportedCode, type LaunchedProcess, type LaunchRecord } from "./regenerate/launch.ts";
|
|
2
2
|
/**
|
|
3
3
|
* The launch track (docs/launch.md): each codebase's launches, one at a time, the newest commit winning. A pulse that lands
|
|
4
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
|
|
@@ -107,6 +107,11 @@ export interface LaunchTrack {
|
|
|
107
107
|
*/
|
|
108
108
|
halted(codebase?: string): string[];
|
|
109
109
|
list(): Launch[];
|
|
110
|
+
/**
|
|
111
|
+
* Stop what launches of an earlier turri left running in the project - as a session starts. Said in the ledger, and in
|
|
112
|
+
* the summary of the next launch of each codebase it stopped something of. A launch does it for its codebase too.
|
|
113
|
+
*/
|
|
114
|
+
sweep(): Promise<LaunchRecord[]>;
|
|
110
115
|
/** What the codebase's last launch started, still running. */
|
|
111
116
|
running(codebase: string): LaunchedProcess[];
|
|
112
117
|
}
|
package/dist/launch-track.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { dirname } from "node:path";
|
|
2
|
-
import { codeTreeOf, exportModule, holdsCommit, hostDirOf, launchTarget, listLaunched, runningLaunched, stopLaunched } from "./regenerate/launch.js";
|
|
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";
|
|
3
4
|
import { record } from "./regenerate/ledger.js";
|
|
4
5
|
/** How many ended launches are kept to list. */
|
|
5
6
|
const KEPT = 50;
|
|
@@ -34,6 +35,15 @@ export function createLaunchTrack(options) {
|
|
|
34
35
|
};
|
|
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));
|
|
36
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
|
+
};
|
|
37
47
|
/**
|
|
38
48
|
* What runs for the codebase is the commit's code: the same code, nothing it started has ended. Guidance is not
|
|
39
49
|
* compared: the agent finds the project's itself, and the chat passing it on says nothing new - `again` launches anew.
|
|
@@ -102,7 +112,9 @@ export function createLaunchTrack(options) {
|
|
|
102
112
|
const halted = new Promise((_, reject) => abort.signal.addEventListener("abort", () => reject(new Error("stopped")), { once: true }));
|
|
103
113
|
halted.catch(() => undefined);
|
|
104
114
|
try {
|
|
105
|
-
// What the last launch started runs from what is about to be replaced
|
|
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));
|
|
106
118
|
await stopLaunched({ moduleName: launch.codebase });
|
|
107
119
|
const code = exportModule(launch.plainFile, { ...(launch.inModule !== undefined ? { inModule: launch.inModule } : {}), commit: launch.commit });
|
|
108
120
|
launch.code = code;
|
|
@@ -120,6 +132,11 @@ export function createLaunchTrack(options) {
|
|
|
120
132
|
launch.status = abort.signal.aborted ? "stopped" : "failed";
|
|
121
133
|
launch.summary = abort.signal.aborted ? "Stopped on request." : error instanceof Error ? error.message : String(error);
|
|
122
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
|
+
}
|
|
123
140
|
launch.finishedAt = Date.now();
|
|
124
141
|
// What runs is this launch's - or, stopped, nothing of it.
|
|
125
142
|
state.current = launch.status === "stopped" ? undefined : launch;
|
|
@@ -278,6 +295,11 @@ export function createLaunchTrack(options) {
|
|
|
278
295
|
return stopped;
|
|
279
296
|
},
|
|
280
297
|
list: () => [...launches],
|
|
298
|
+
async sweep() {
|
|
299
|
+
const stopped = await stopLeftBehind(projectDirOf(join(options.cwd, "turri.plain")));
|
|
300
|
+
noteLeftBehind(stopped);
|
|
301
|
+
return stopped;
|
|
302
|
+
},
|
|
281
303
|
running: (codebase) => runningLaunched(codebase),
|
|
282
304
|
};
|
|
283
305
|
return track;
|
|
@@ -45,6 +45,12 @@ export declare function machineReadable(platform?: NodeJS.Platform): string[];
|
|
|
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. */
|
|
@@ -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 ` +
|
|
@@ -88,6 +88,32 @@ export interface LaunchedProcess {
|
|
|
88
88
|
signal: string | null;
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* What a launch started, written down as it starts - `.turri/launch/running/<pid>.json` - and taken out as it ends: a turri
|
|
93
|
+
* that dies without stopping what it started leaves it findable, for the next session to stop (`stopLeftBehind`).
|
|
94
|
+
*/
|
|
95
|
+
export interface LaunchRecord {
|
|
96
|
+
pid: number;
|
|
97
|
+
/** Its process group: the pid, as it was started as the leader of a group of its own. */
|
|
98
|
+
pgid: number;
|
|
99
|
+
name: string;
|
|
100
|
+
moduleName: string;
|
|
101
|
+
command: string;
|
|
102
|
+
dir: string;
|
|
103
|
+
url?: string;
|
|
104
|
+
startedAt: number;
|
|
105
|
+
/** The turri process that started it. */
|
|
106
|
+
turri: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Stop what launches of an earlier turri left running in the project - the codebase's, or every one's - as stopLaunched
|
|
110
|
+
* stops this session's: its process group, politely, then not. Only what turri's own records name, whose turri has ended
|
|
111
|
+
* (another turri still running keeps its own), and only when the process is still the one recorded: a process turri did
|
|
112
|
+
* not start is never stopped. Records of what has ended are taken out. Returns what was stopped.
|
|
113
|
+
*/
|
|
114
|
+
export declare function stopLeftBehind(projectDir: string, codebase?: string): Promise<LaunchRecord[]>;
|
|
115
|
+
/** What was stopped of an earlier session's, in a line - for a launch's summary. */
|
|
116
|
+
export declare function describeLeftBehind(stopped: LaunchRecord[]): string;
|
|
91
117
|
/** Everything a launch started, running or ended, oldest first. */
|
|
92
118
|
export declare function listLaunched(): LaunchedProcess[];
|
|
93
119
|
/** The ones still running. */
|
|
@@ -103,6 +129,8 @@ export declare function stopLaunched(which?: {
|
|
|
103
129
|
}): Promise<string[]>;
|
|
104
130
|
/** Stop everything at once, without waiting: for when turri itself is going. */
|
|
105
131
|
export declare function stopAllLaunchedNow(): void;
|
|
132
|
+
/** What holds a port, as lsof says it - or nothing when it cannot say. */
|
|
133
|
+
export declare function holderOf(port: number): string;
|
|
106
134
|
/** How long a server is given to answer at its URL, and to stay up when it has none. */
|
|
107
135
|
export declare const READY_TIMEOUT_MS: number;
|
|
108
136
|
export interface StartResult {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
-
import { closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, rmSync, statSync } from "node:fs";
|
|
2
|
+
import { closeSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { connect } from "node:net";
|
|
4
4
|
import { dirname, join, relative } from "node:path";
|
|
5
5
|
import { HISTORY_DIR } from "./lineage.js";
|
|
@@ -110,6 +110,126 @@ export function describeExport(code) {
|
|
|
110
110
|
].join("\n");
|
|
111
111
|
}
|
|
112
112
|
const processes = new Map();
|
|
113
|
+
const RUNNING_DIR = "running";
|
|
114
|
+
function writeRecord(logDir, record) {
|
|
115
|
+
try {
|
|
116
|
+
const dir = join(logDir, RUNNING_DIR);
|
|
117
|
+
mkdirSync(dir, { recursive: true });
|
|
118
|
+
const file = join(dir, `${record.pid}.json`);
|
|
119
|
+
writeFileSync(file, `${JSON.stringify(record, null, 2)}\n`);
|
|
120
|
+
return file;
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Unrecorded, it is still stopped by this turri - only a turri that dies leaves it.
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function dropRecord(file) {
|
|
128
|
+
if (file === undefined)
|
|
129
|
+
return false;
|
|
130
|
+
try {
|
|
131
|
+
unlinkSync(file);
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const alive = (pid) => {
|
|
139
|
+
try {
|
|
140
|
+
process.kill(pid, 0);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
// Alive, but another user's: it is not one turri started.
|
|
145
|
+
return error.code === "EPERM";
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* The processes of the group a launch started, as `ps` says them now - none when it has none left, or ps cannot say
|
|
150
|
+
* (Windows): what cannot be told to be turri's is never stopped. Theirs only when the group is the one the record names:
|
|
151
|
+
* its leader started when the record says, or - the leader gone - every one of them started after it. A pid is not given
|
|
152
|
+
* again while a group of that id has a process left.
|
|
153
|
+
*/
|
|
154
|
+
function groupOf(record) {
|
|
155
|
+
const listed = spawnSync("ps", ["-A", "-o", "pid=,pgid=,lstart="], { encoding: "utf8", env: { ...process.env, LC_ALL: "C" } });
|
|
156
|
+
if (listed.status !== 0)
|
|
157
|
+
return [];
|
|
158
|
+
const members = [];
|
|
159
|
+
for (const line of listed.stdout.split("\n")) {
|
|
160
|
+
const match = /^\s*(\d+)\s+(\d+)\s+(.+?)\s*$/.exec(line);
|
|
161
|
+
if (match === null || Number(match[2]) !== record.pgid)
|
|
162
|
+
continue;
|
|
163
|
+
members.push({ pid: Number(match[1]), started: Date.parse(match[3]) });
|
|
164
|
+
}
|
|
165
|
+
if (members.length === 0)
|
|
166
|
+
return [];
|
|
167
|
+
const slack = 5000;
|
|
168
|
+
const leader = members.find((member) => member.pid === record.pgid);
|
|
169
|
+
const theirs = leader !== undefined
|
|
170
|
+
? Number.isFinite(leader.started) && Math.abs(leader.started - record.startedAt) <= slack
|
|
171
|
+
: members.every((member) => Number.isFinite(member.started) && member.started >= record.startedAt - slack);
|
|
172
|
+
return theirs ? members.map((member) => member.pid) : [];
|
|
173
|
+
}
|
|
174
|
+
const groupAlive = (pgid) => {
|
|
175
|
+
try {
|
|
176
|
+
process.kill(-pgid, 0);
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
return error.code === "EPERM";
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Stop what launches of an earlier turri left running in the project - the codebase's, or every one's - as stopLaunched
|
|
185
|
+
* stops this session's: its process group, politely, then not. Only what turri's own records name, whose turri has ended
|
|
186
|
+
* (another turri still running keeps its own), and only when the process is still the one recorded: a process turri did
|
|
187
|
+
* not start is never stopped. Records of what has ended are taken out. Returns what was stopped.
|
|
188
|
+
*/
|
|
189
|
+
export async function stopLeftBehind(projectDir, codebase) {
|
|
190
|
+
const dir = join(projectDir, ".turri", "launch", RUNNING_DIR);
|
|
191
|
+
let names;
|
|
192
|
+
try {
|
|
193
|
+
names = readdirSync(dir).filter((name) => name.endsWith(".json"));
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
const stopping = [];
|
|
199
|
+
for (const name of names) {
|
|
200
|
+
const file = join(dir, name);
|
|
201
|
+
let record;
|
|
202
|
+
try {
|
|
203
|
+
record = JSON.parse(readFileSync(file, "utf8"));
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
if (codebase !== undefined && record.moduleName !== codebase)
|
|
209
|
+
continue;
|
|
210
|
+
// This turri's own are stopLaunched's; another turri still running keeps its own.
|
|
211
|
+
if (record.turri === process.pid || alive(record.turri))
|
|
212
|
+
continue;
|
|
213
|
+
const group = groupOf(record);
|
|
214
|
+
// Taken by whoever takes the record out first: a sweep at the session's start and one before a launch never both stop it.
|
|
215
|
+
if (!dropRecord(file) || group.length === 0)
|
|
216
|
+
continue;
|
|
217
|
+
signalGroup(record.pgid, "SIGTERM");
|
|
218
|
+
stopping.push(record);
|
|
219
|
+
}
|
|
220
|
+
const deadline = Date.now() + 5000;
|
|
221
|
+
while (Date.now() < deadline && stopping.some((record) => groupAlive(record.pgid)))
|
|
222
|
+
await sleep(100);
|
|
223
|
+
for (const record of stopping)
|
|
224
|
+
if (groupAlive(record.pgid))
|
|
225
|
+
signalGroup(record.pgid, "SIGKILL");
|
|
226
|
+
return stopping;
|
|
227
|
+
}
|
|
228
|
+
/** What was stopped of an earlier session's, in a line - for a launch's summary. */
|
|
229
|
+
export function describeLeftBehind(stopped) {
|
|
230
|
+
const each = stopped.map((record) => `${record.name} (pid ${record.pid}${record.url !== undefined ? `, ${record.url}` : ""})`);
|
|
231
|
+
return `Stopped what an earlier turri session left running of ${[...new Set(stopped.map((record) => record.moduleName))].join(", ")}: ${each.join(", ")}.`;
|
|
232
|
+
}
|
|
113
233
|
/** Everything a launch started, running or ended, oldest first. */
|
|
114
234
|
export function listLaunched() {
|
|
115
235
|
return [...processes.values()].map((entry) => entry.info);
|
|
@@ -193,7 +313,7 @@ function portTaken(host, port) {
|
|
|
193
313
|
});
|
|
194
314
|
}
|
|
195
315
|
/** What holds a port, as lsof says it - or nothing when it cannot say. */
|
|
196
|
-
function holderOf(port) {
|
|
316
|
+
export function holderOf(port) {
|
|
197
317
|
const found = spawnSync("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN"], { encoding: "utf8" });
|
|
198
318
|
return found.status === 0 ? found.stdout.trim().split("\n").slice(0, 4).join("\n") : "";
|
|
199
319
|
}
|
|
@@ -292,10 +412,22 @@ export async function startLaunched(input) {
|
|
|
292
412
|
}
|
|
293
413
|
const started = { name: input.name, moduleName: input.moduleName, command: input.command, dir: input.dir, log, pid: child.pid, startedAt: Date.now(), ...(input.url !== undefined ? { url: input.url } : {}) };
|
|
294
414
|
info = started;
|
|
415
|
+
const record = writeRecord(input.logDir, {
|
|
416
|
+
pid: child.pid,
|
|
417
|
+
pgid: child.pid,
|
|
418
|
+
name: input.name,
|
|
419
|
+
moduleName: input.moduleName,
|
|
420
|
+
command: input.command,
|
|
421
|
+
dir: input.dir,
|
|
422
|
+
...(input.url !== undefined ? { url: input.url } : {}),
|
|
423
|
+
startedAt: started.startedAt,
|
|
424
|
+
turri: process.pid,
|
|
425
|
+
});
|
|
295
426
|
child.on("exit", (code, signal) => {
|
|
296
427
|
started.exited = { code, signal };
|
|
428
|
+
dropRecord(record);
|
|
297
429
|
});
|
|
298
|
-
processes.set(input.name, { info: started, child });
|
|
430
|
+
processes.set(input.name, { info: started, child, ...(record !== undefined ? { record } : {}) });
|
|
299
431
|
stopOnExit();
|
|
300
432
|
const failed = (why) => {
|
|
301
433
|
const tail = logTail(log);
|
|
@@ -94,6 +94,14 @@ export type LedgerEvent = {
|
|
|
94
94
|
commit: string;
|
|
95
95
|
status: string;
|
|
96
96
|
ms: number;
|
|
97
|
+
} | {
|
|
98
|
+
kind: "launch.left-behind";
|
|
99
|
+
stopped: Array<{
|
|
100
|
+
name: string;
|
|
101
|
+
pid: number;
|
|
102
|
+
module: string;
|
|
103
|
+
url?: string;
|
|
104
|
+
}>;
|
|
97
105
|
} | {
|
|
98
106
|
kind: "sentinel.concluded";
|
|
99
107
|
verdict: string;
|
|
@@ -394,11 +394,21 @@ export declare function namesOf(module: string, funcIds: string[]): string;
|
|
|
394
394
|
* a func-id is unique in its module only.
|
|
395
395
|
*/
|
|
396
396
|
export declare function funcIdsNamed(module: string, names: string[]): string[];
|
|
397
|
+
/**
|
|
398
|
+
* Why conform starts nothing when a step of adding tests is still to take - the test reqs, the conformance testing
|
|
399
|
+
* script, the scenarios: not a failure but what conform needs first, each step one the chat takes itself.
|
|
400
|
+
*/
|
|
401
|
+
export declare class TestingStepsMissing extends Error {
|
|
402
|
+
}
|
|
397
403
|
/**
|
|
398
404
|
* Why conform would start nothing for a module, from its ***plain alone (`conformanceAskedIn`): undefined when it would
|
|
399
|
-
* go on. What /conform checks before it says anything.
|
|
405
|
+
* go on. What /conform checks before it says anything. `stepsMissing`: what is missing is a step of adding tests - the
|
|
406
|
+
* test reqs, the conformance testing script, the scenarios - guidance for the chat, not an error for the person.
|
|
400
407
|
*/
|
|
401
|
-
export declare function conformanceRefusal(plainFile: string, funcIds?: string[]):
|
|
408
|
+
export declare function conformanceRefusal(plainFile: string, funcIds?: string[]): {
|
|
409
|
+
text: string;
|
|
410
|
+
stepsMissing: boolean;
|
|
411
|
+
} | undefined;
|
|
402
412
|
/** Nothing runs, is planned or is waiting there, as its code is built from its spec as it is. */
|
|
403
413
|
export declare function isUpToDate(status: ModuleStatus): boolean;
|
|
404
414
|
export declare function describeModules(statuses: ModuleStatus[], options?: {
|
package/dist/regenerate/loop.js
CHANGED
|
@@ -1854,6 +1854,12 @@ export function funcIdsNamed(module, names) {
|
|
|
1854
1854
|
return funcId;
|
|
1855
1855
|
});
|
|
1856
1856
|
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Why conform starts nothing when a step of adding tests is still to take - the test reqs, the conformance testing
|
|
1859
|
+
* script, the scenarios: not a failure but what conform needs first, each step one the chat takes itself.
|
|
1860
|
+
*/
|
|
1861
|
+
export class TestingStepsMissing extends Error {
|
|
1862
|
+
}
|
|
1857
1863
|
/**
|
|
1858
1864
|
* What conform is asked for in a module, checked from its ***plain alone - quick, before anything is said or touched: the
|
|
1859
1865
|
* functional specs named, as func-ids, and the module's spec and those of its functional specs with scenarios. Throws,
|
|
@@ -1869,7 +1875,7 @@ function conformanceAskedIn(own, funcIds) {
|
|
|
1869
1875
|
// No scenarios: the steps still to take, from the first one missing - the test reqs and the script come before them.
|
|
1870
1876
|
const toScenarios = () => stepsToScenarios({ moduleName: self.moduleName, plainFile: self.plainFile, tree: spec, buildDir: self.buildDir });
|
|
1871
1877
|
if (withScenarios.length === 0) {
|
|
1872
|
-
throw new
|
|
1878
|
+
throw new TestingStepsMissing(`No functional spec of ${self.moduleName} has scenarios - none has a test plain file - so there is nothing to test. ${toScenarios()} ` +
|
|
1873
1879
|
"Their tests are written once the code is built. Nothing was started.");
|
|
1874
1880
|
}
|
|
1875
1881
|
if (named !== undefined && named.length > 0) {
|
|
@@ -1879,19 +1885,20 @@ function conformanceAskedIn(own, funcIds) {
|
|
|
1879
1885
|
throw new Error(`${self.moduleName} has no functional spec ${namesOf(self.moduleName, unknown)}. Nothing was started.`);
|
|
1880
1886
|
const untested = named.filter((funcId) => !hasScenarios(items.find((item) => item.id === funcId)));
|
|
1881
1887
|
if (untested.length > 0) {
|
|
1882
|
-
throw new
|
|
1888
|
+
throw new TestingStepsMissing(`${namesOf(self.moduleName, untested)} ${untested.length === 1 ? "has" : "have"} no scenarios - no test plain file - so there is nothing to test. ${toScenarios()} ` +
|
|
1883
1889
|
"Their tests are written once the code is built. Nothing was started.");
|
|
1884
1890
|
}
|
|
1885
1891
|
}
|
|
1886
1892
|
// A step of adding tests skipped - its test reqs, or the conformance testing script: refused, naming it.
|
|
1887
1893
|
const gap = testingGap({ moduleName: self.moduleName, plainFile: self.plainFile, tree: spec, buildDir: self.buildDir });
|
|
1888
1894
|
if (gap !== undefined)
|
|
1889
|
-
throw new
|
|
1895
|
+
throw new TestingStepsMissing(`${gap.text} Nothing was started.`);
|
|
1890
1896
|
return { named, spec, withScenarios };
|
|
1891
1897
|
}
|
|
1892
1898
|
/**
|
|
1893
1899
|
* Why conform would start nothing for a module, from its ***plain alone (`conformanceAskedIn`): undefined when it would
|
|
1894
|
-
* go on. What /conform checks before it says anything.
|
|
1900
|
+
* go on. What /conform checks before it says anything. `stepsMissing`: what is missing is a step of adding tests - the
|
|
1901
|
+
* test reqs, the conformance testing script, the scenarios - guidance for the chat, not an error for the person.
|
|
1895
1902
|
*/
|
|
1896
1903
|
export function conformanceRefusal(plainFile, funcIds) {
|
|
1897
1904
|
try {
|
|
@@ -1899,7 +1906,7 @@ export function conformanceRefusal(plainFile, funcIds) {
|
|
|
1899
1906
|
return undefined;
|
|
1900
1907
|
}
|
|
1901
1908
|
catch (error) {
|
|
1902
|
-
return error instanceof Error ? error.message : String(error);
|
|
1909
|
+
return { text: error instanceof Error ? error.message : String(error), stepsMissing: error instanceof TestingStepsMissing };
|
|
1903
1910
|
}
|
|
1904
1911
|
}
|
|
1905
1912
|
/** What a job does, in a few words: its cases, each functional spec by its func-id - with its module, a module below's. */
|
package/dist/sentinel.d.ts
CHANGED
|
@@ -69,6 +69,7 @@ export declare function sentinelCheckBrief(check: SentinelCheck, context: {
|
|
|
69
69
|
summary?: string;
|
|
70
70
|
};
|
|
71
71
|
focused?: string;
|
|
72
|
+
dir?: string;
|
|
72
73
|
}): string;
|
|
73
74
|
/**
|
|
74
75
|
* The tools the sentinel's agent may call: what reads, write and edit for the project's tooling alone, resume, its
|
package/dist/sentinel.js
CHANGED
|
@@ -11,7 +11,7 @@ import { formatDuration, pulseName } from "./regenerate/jobs.js";
|
|
|
11
11
|
import { readLedger } from "./regenerate/ledger.js";
|
|
12
12
|
import { describePulseView, pulseView } from "./regenerate/ledger-view.js";
|
|
13
13
|
import { MODULES_DIR, ensureInScratch } from "./regenerate/paths.js";
|
|
14
|
-
import { whatRuns } from "./launch-session.js";
|
|
14
|
+
import { LAUNCHED_ONLY, launchedDir, whatRuns } from "./launch-session.js";
|
|
15
15
|
import { SENTINEL, SENTINEL_START, wentWrong } from "./notice.js";
|
|
16
16
|
export * from "./notice.js";
|
|
17
17
|
/**
|
|
@@ -287,24 +287,24 @@ export function sentinelBrief(job, context) {
|
|
|
287
287
|
function launchLines(job, launch) {
|
|
288
288
|
const spec = (each) => `${each.module}:${each.funcId}`;
|
|
289
289
|
if (launch.off === true)
|
|
290
|
-
return [`${launch.commit !== undefined ? `Its commit is ${launch.commit.slice(0, 7)}. ` : ""}launch-after-pulse is off: nothing was launched, and you test nothing running - check the pulse alone
|
|
290
|
+
return [`${launch.commit !== undefined ? `Its commit is ${launch.commit.slice(0, 7)}. ` : ""}launch-after-pulse is off: nothing was launched, and you test nothing running - check the pulse alone.`, LAUNCHED_ONLY];
|
|
291
291
|
if (launch.commit === undefined)
|
|
292
|
-
return ["Nothing was launched for it: turri has no commit it landed - check the pulse alone."];
|
|
292
|
+
return ["Nothing was launched for it: turri has no commit it landed - check the pulse alone.", LAUNCHED_ONLY];
|
|
293
293
|
const commit = launch.commit.slice(0, 7);
|
|
294
294
|
if (launch.notAsked !== undefined)
|
|
295
|
-
return [`Its commit is ${commit}. Its launch could not be asked for: ${launch.notAsked}`, "That is what you find out about: the launch did not come up."];
|
|
295
|
+
return [`Its commit is ${commit}. Its launch could not be asked for: ${launch.notAsked}`, "That is what you find out about: the launch did not come up.", LAUNCHED_ONLY];
|
|
296
296
|
if (launch.stopped === true || launch.launch === undefined)
|
|
297
|
-
return [`Its commit is ${commit}. The person stopped its launch: nothing of it runs - check the pulse alone
|
|
297
|
+
return [`Its commit is ${commit}. The person stopped its launch: nothing of it runs - check the pulse alone.`, LAUNCHED_ONLY];
|
|
298
298
|
const what = launch.launch;
|
|
299
299
|
const later = launch.later.map((other) => `${other.id} (${pulseName(other)})`);
|
|
300
300
|
const lines = [
|
|
301
301
|
`Its commit is ${commit}. It was launched in the background (launch-after-pulse): what runs is ${what.codebase} at ${what.short} (${what.id}), which holds it${later.length > 0 ? ` and the pulses that landed after it - ${later.join(", ")}` : ""}.`,
|
|
302
302
|
];
|
|
303
303
|
if (what.status === "failed") {
|
|
304
|
-
lines.push(`That launch did not come up: ${what.summary ?? "the launch agent did not say why"}`, "That is what you find out about: the launch did not come up. Test nothing in its place
|
|
304
|
+
lines.push(`That launch did not come up: ${what.summary ?? "the launch agent did not say why"}`, "That is what you find out about: the launch did not come up. Test nothing in its place.", LAUNCHED_ONLY);
|
|
305
305
|
return lines;
|
|
306
306
|
}
|
|
307
|
-
lines.push("What runs now:", ...whatRuns(launch.running));
|
|
307
|
+
lines.push("What runs now:", ...whatRuns(launch.running, launchedDir(what)), LAUNCHED_ONLY);
|
|
308
308
|
if (launch.laterSpecs.length > 0) {
|
|
309
309
|
lines.push(`Test what this pulse changed - but not ${launch.laterSpecs.map(spec).join(", ")}: a later pulse changed ${launch.laterSpecs.length === 1 ? "it" : "them"} again, and its check tests ${launch.laterSpecs.length === 1 ? "it" : "them"}.`);
|
|
310
310
|
}
|
|
@@ -325,9 +325,9 @@ export function sentinelCheckBrief(check, context) {
|
|
|
325
325
|
lines.push("", `What is launched of ${check.module} holds its code and that of every module its requires chain builds on${context.commit !== undefined ? `, at its commit ${context.commit}` : ""} - a commit that landed whole, never what a pulse is writing now.${context.failed !== undefined ? "" : " What runs now:"}`, ...(context.failed !== undefined
|
|
326
326
|
? [
|
|
327
327
|
`Its last launch, ${context.failed.id}, did not come up: ${context.failed.summary ?? "the launch agent did not say why"}`,
|
|
328
|
-
"That is what you find out about: the launch did not come up. Test nothing in its place
|
|
328
|
+
"That is what you find out about: the launch did not come up. Test nothing in its place.",
|
|
329
329
|
]
|
|
330
|
-
: whatRuns(context.running)), "", `Test these functional specs of ${check.module} - only these, not its others, though they run too:`);
|
|
330
|
+
: whatRuns(context.running, context.dir)), LAUNCHED_ONLY, "", `Test these functional specs of ${check.module} - only these, not its others, though they run too:`);
|
|
331
331
|
for (const spec of context.specs) {
|
|
332
332
|
lines.push("", `# ${spec.funcId}`, spec.text);
|
|
333
333
|
for (const [title, scenarios] of [["Conformance scenarios", spec.conformance], ["Acceptance scenarios", spec.acceptance]]) {
|
package/docs/hosting.md
CHANGED
|
@@ -151,7 +151,7 @@ await turri.dispose(); // every chat let go, what launches start
|
|
|
151
151
|
- **The record.** The chats are recorded in `.turri/chats.json` as the terminal records them, and `restore: true` reopens the last ended session's - without it, a host starts with none and deletes nothing. A chat closed is deleted; a session's chats are kept until five newer sessions have recorded theirs.
|
|
152
152
|
- **The jobs.** The host is told of each job as it changes, and has the registry and the loop themselves, so it shows the very jobs the chats run. Its buttons are best a chat's commands - `session.prompt("/regenerate app.plain")`, `session.prompt("/conform app.plain app:add-task")` - so the plan is the chats', and no model turn stands between the button and the pulse. A job's \*\*\*plain diff is `job.diff`, and `job.diffWhere` places its lines in the `.plain` files: by a line's place in the diff, its `file`, its `line` there, the `section` it is in and `written` - the line as the file has it. The diff is \*\*\*plain as read, a link `[text](path)` in it as `` `[resource]text` ``, so a host that finds the lines again in a file's text - after an edit since the pulse started - matches them by `written`, never by the diff's text. A `job.diff` in a ledger written before `written` was added has none. `job.cases` is the functional specs the pulse covers, as planned, by what it does to each - `{ add, patch, again, delete }`, each a list of `{ module, funcId }`, `module` the pulse's own or one below it: new, changed, regenerated again with its text unchanged, taken out. A host lights those specs from it, and marks a line of the diff as regenerated again from `again` - never from the diff, where such a line is unchanged. A pulse of none is mechanical - reqs, or definitions none uses; a job that is not a pulse has no `cases`. The ledger's `job.queued` carries them too. `job.building` is the one functional spec a job is on now, when it is on one: `{ spec: { module, funcId }, label, text, since }` - `spec` the functional spec as data, `label` and `text` what the terminal shows (`core:add-task, functional spec of 3`, its text with its scenarios). Only a conformance run of one named functional spec sets it; a pulse the work loop plans covers its functional specs together and leaves it unset - light those from `cases`.
|
|
153
153
|
- **The questions.** `dialogs(chat)` gives a chat's two dialogs: `select(title, options, context, at, { signal })` and `input(title, context, { signal })`, each resolving with the answer, or undefined when the person dismissed it. `signal` is aborted when the question is over without the dialog's answer - declined by `decline`, or its turn stopped (`interrupt`, `session.abort()`): the host closes the dialog it opened for it, whatever it resolves with then being ignored. A host may leave it unread. The chat's questions, a skill's interview and a review gate's escalation are put in them; without them, in the `uiContext`'s own dialogs.
|
|
154
|
-
- **The surface.** What turri tells the model of where the person watches the work is the terminal's by default: regen, the side panel on `ctrl+h`, `/pulses`. In a host none of that is there, and the model would send the person to keys and panels that do not exist. `surface` is the host's own description of its UI - the views it has in place of the terminal's, what its marks and buttons mean, where questions appear - in its own words. Given, turri leaves every terminal instruction out of what the model is told and puts the surface in turri's identity, as a `<surface>` block, where the identity speaks of regen. It reaches the side questions and the tools' own words too: a pulse not found says the `pulses` tool lists them, not `/pulses`. Text only the person sees in the terminal - the job panel, the side panel - is the terminal's and stays as it is. Without `surface`, the prompt is the terminal's, byte for byte. What the conversation is to do once something is launched belongs there too - open it in the host's preview, say what to test: it is told once each launch it asked for ends, and - with `sentinel: false` - each launch after a pulse under `launch-after-pulse`, and does then what it was told to do once something is launched. With the sentinel on, the sentinel tests what is launched after a pulse, and the conversation only says it landed. With `sentinel: false`, the chat that asked for a pulse that lands under `launch-after-pulse` is told as it lands that its commit is being launched in the background - to say so in a line and offer nothing else - and then told the launch's end. Every launch, as it is asked for, starts and ends, comes to the host as `onLaunch(launch)` - its codebase, commit, status and summary. One whose code runs already - the chat asking for what runs, a pulse that landed only tests - comes once, `status: "launched"` with `already: true`, its own cause and the commit it was asked for; the launch that started what runs is not told again. One that ended with a newer launch of its codebase waiting comes with its real status and `replacedBy`, the newer one's id: that one starts at once and stops what it started, so draw it as replaced rather than as running - the chat that asked for it is told so, and hears the newer one's end instead, as for one `superseded` as it waited (`supersededBy`). What a launch started, halted on request (`/halt launched`, the `halt` tool) with nothing of it left running, comes again as `status: "stopped"`, "Stopped on request.": nothing of the codebase is launched from then on, and its next launch launches anew.
|
|
154
|
+
- **The surface.** What turri tells the model of where the person watches the work is the terminal's by default: regen, the side panel on `ctrl+h`, `/pulses`. In a host none of that is there, and the model would send the person to keys and panels that do not exist. `surface` is the host's own description of its UI - the views it has in place of the terminal's, what its marks and buttons mean, where questions appear - in its own words. Given, turri leaves every terminal instruction out of what the model is told and puts the surface in turri's identity, as a `<surface>` block, where the identity speaks of regen. It reaches the side questions and the tools' own words too: a pulse not found says the `pulses` tool lists them, not `/pulses`. Text only the person sees in the terminal - the job panel, the side panel - is the terminal's and stays as it is. Without `surface`, the prompt is the terminal's, byte for byte. What the conversation is to do once something is launched belongs there too - open it in the host's preview, say what to test: it is told once each launch it asked for ends, and - with `sentinel: false` - each launch after a pulse under `launch-after-pulse`, and does then what it was told to do once something is launched. With the sentinel on, the sentinel tests what is launched after a pulse, and the conversation only says it landed. With `sentinel: false`, the chat that asked for a pulse that lands under `launch-after-pulse` is told as it lands that its commit is being launched in the background - to say so in a line and offer nothing else - and then told the launch's end. Every launch, as it is asked for, starts and ends, comes to the host as `onLaunch(launch)` - its codebase, commit, status and summary. One whose code runs already - the chat asking for what runs, a pulse that landed only tests - comes once, `status: "launched"` with `already: true`, its own cause and the commit it was asked for; the launch that started what runs is not told again. One that ended with a newer launch of its codebase waiting comes with its real status and `replacedBy`, the newer one's id: that one starts at once and stops what it started, so draw it as replaced rather than as running - the chat that asked for it is told so, and hears the newer one's end instead, as for one `superseded` as it waited (`supersededBy`). What a launch started, halted on request (`/halt launched`, the `halt` tool) with nothing of it left running, comes again as `status: "stopped"`, "Stopped on request.": nothing of the codebase is launched from then on, and its next launch launches anew. A launch that said a server runs is `launched` only while one it started itself runs: something else answering at its port - a server an earlier session left, another program - makes it `failed`, its summary saying what holds the port. What an earlier turri's launches left running - a host that quit without `dispose`, a turri killed outright - is stopped as the session starts and before each launch of its codebase, and the next launch's `summary` begins with what was stopped (see [what an earlier session left running](launch.md#what-an-earlier-session-left-running)).
|
|
155
155
|
- **The banner.** The first chat's session starts with turri's banner, an entry `customType: "turri_banner"`. Its `data.config` is what turri says of the project's config files, a line each - `{ kind, file, text }`, `text` as the terminal shows it: `renamed`, a key turri renamed in the file itself, its value kept (`release-after-pulse` to `launch-after-pulse`) - information, nothing to do; `old-beside-new`, a file that sets an old name beside its new one, the old doing nothing - take it out; `unknown`, keys turri does not read - a setting it no longer has, a misspelt one. Draw `renamed` as information, the others as warnings, by `kind`, never by the words. `ConfigLine` and `ConfigLineKind` are exported.
|
|
156
156
|
- **The system prompt.** `systemPrompt(prompt)` gets the whole system prompt for the turn - [pi](https://pi.dev)'s, turri's identity and blocks, the rules - after turri's own `before_agent_start` work, and returns what is sent. It is for what `surface` does not cover; to describe the UI, use `surface`, rather than words appended after turri's that contradict them.
|
|
157
157
|
- **The mode.** Each chat is bound in [pi](https://pi.dev)'s `tui` mode: the work runs in the background and keeps the chat free, as the terminal does. Its other UI calls - its notices, its working line, a confirm - come to `uiContext(chat)`, as [pi](https://pi.dev)'s [SDK](https://github.com/earendil-works/pi) describes it.
|
|
@@ -172,7 +172,7 @@ The [sentinel](sentinel.md) is one of the host's chats: turri opens it with the
|
|
|
172
172
|
|
|
173
173
|
- **Notices.** What it finds wrong comes as `onNotice(notice)`: `{ id, chat, severity: "error" | "warning" | "info", summary, evidence: string[], actions: [{ label, task }], module?, pulse?, job?, ignorable?, state: "open" }`. Draw it in the chat `chat` names - the one `focus` last named, or, while that is the sentinel, the chat that asked for the pulse. It is drawn there as a card in the transcript too. A host given `onNotice` answers it itself - the terminal's dialog is not opened - with `answer(id, …)`: `{ action: index | label }` starts that chat's agent on the action's task, `{ steer: text }` on the person's words, `{ dismiss: true }` on nothing, this once. A notice with `ignorable: true` - a gap in the \*\*\*plain the build settled with an assumption, which the person may leave as it is - takes `{ ignore: true }` too: offer it as its own button beside the actions. Nothing is done in the chat, the notice ends `state: "ignored"` (`"ignored"`), and turri writes it to the sentinel's guidance, so it is not raised again in this session or the next; on a notice without `ignorable`, `{ ignore: true }` is `"refused"` and the notice stays open. `onNoticeOver(notice)` comes as it is answered - and when a newer notice about its module supersedes it (`state: "superseded"`) - for the host to take the card down. `notices()` lists the open ones.
|
|
174
174
|
- **Fixes it made.** The sentinel fixes the project's testing scripts and their config itself ([what it may do](sentinel.md#what-it-may-do)), and says so as a notice with `kind: "fixed"`, `severity: "info"`, no actions, the lines before and after in `evidence`: a note, with nothing to answer. Draw it as one - its card with a way to put it away (`answer(id, { dismiss: true })`), no "say what to do instead". It never supersedes a notice about its module. The terminal draws its card and puts no dialog.
|
|
175
|
-
- **The machine is the person's.** turri installs nothing and changes no setting of the machine's or the person's shell, in any chat, the sentinel's included - and through a host's tools as through its own: a tool call whose input has a `command` string - a host's `terminal_run` - is refused when the command would (`machineChange`), with what to do instead (`machineChangeReason`), as turri's own `bash` is; and the sentinel's, also when it writes a `.plain` file. A tool that types into what already runs - a terminal's `terminal_type` at a shell prompt - is the host's to check: `machineChange(text)` says whether a line would change the machine, and why.
|
|
175
|
+
- **The machine is the person's.** turri installs nothing and changes no setting of the machine's or the person's shell, in any chat, the sentinel's included - and through a host's tools as through its own: a tool call whose input has a `command` string - a host's `terminal_run` - is refused when the command would (`machineChange`), with what to do instead (`machineChangeReason`), as turri's own `bash` is; and the sentinel's, also when it writes a `.plain` file, or starts or runs the code in `plain_modules` - what nobody launched: it tests what is launched. A tool that types into what already runs - a terminal's `terminal_type` at a shell prompt - is the host's to check: `machineChange(text)` says whether a line would change the machine, and why.
|
|
176
176
|
- **Starting it.** Under `sentinel: ask` - as it is unset - the person is asked before it first opens in the session: a notice with `kind: "sentinel-start"`, `severity: "info"`, in the chat `chat` names, its `summary` the question in one sentence, no `evidence`, and its actions the answers - `Start the sentinel`, `Start it, and don't ask again`, `Not this session`, `Turn it off for this project`. Draw it as a question rather than as something wrong. `answer(id, { action })` answers it, by index or label - `"done"` - and `{ dismiss: true }` is not this session; turri writes `sentinel:` itself for the two that choose for the project. Until it is answered, the pulses that finish are held: neither the sentinel nor the chat hears of them. A host that offers the setting too writes it as `/settings` does - `ask`, `true` or `false` (see `configSettings`).
|
|
177
177
|
- **Conclusions.** As the sentinel is done with each pulse - all well or not - `onConcluded({ job, verdict: "holds" | "wrong", summary, module, pulse, chat })` comes, and the chat `chat` names - the one `focus` last named, as for a notice - shows it and its agent says so in a line. A pulse turri cannot brief it on - what runs cannot hold the pulse's commit, turri's own error - ends `verdict: "unchecked"`, with an error shown in that chat as well.
|
|
178
178
|
- **A host that shows them itself.** With the sentinel on, the chat the person is in is told of each pulse that lands - to say it landed and what the sentinel does with it - and of each conclusion, each in a turn of its own: its agent says it in the conversation, as the terminal has it. A host that shows both itself - its own notifications, from `onJobChange` and `onConcluded` - passes `pulseEndsShown: true`, and the chat then says neither. Both still reach it - `customType: "turri_job_landed"` and `"turri_sentinel_concluded"`, hidden - put in its conversation in order and starting no turn: its agent has them in its next turn, and knows what landed and what the sentinel found when the person asks. Their words say what happened, and ask nothing of it. The rest is as it was: the sentinel's briefs and checks, its notices, a pulse that stopped on \*\*\*plain that contradicts itself (a notice of turri's own), `onConcluded` itself - and, with the sentinel off, the turn in the chat that asked for a pulse, which does what the project's guidance says once a pulse finishes.
|
package/docs/launch.md
CHANGED
|
@@ -37,10 +37,14 @@ It runs on your machine, outside the [sandbox](sandbox.md) - with your toolchain
|
|
|
37
37
|
1. **Checks the toolchains** it needs (`node`, `python3`, `go`, ...) - under another name too: `python` where `python3` is not, of the version it needs. One is missing: it stops, and says the exact command to install it yourself (`brew install node`). turri installs nothing on your machine and changes none of its settings - not a launch, not the chat, not any agent: its shell refuses it.
|
|
38
38
|
2. **Installs what it needs into the project.** Dependencies into a virtual environment or `node_modules`, a build that downloads packages, an image pull, a guided launch's project scripts: it runs them in its own shell, as any agent with a shell would, and fixes what fails. Nothing is put to you - there is no dialog to answer. Never a global install, never a system setting.
|
|
39
39
|
3. **Starts what serves** with `activate`: in the background, in its own process group, its output in `.turri/launch/<module>-<name>.log`. It waits until something answers at the server's URL - up to a minute - so the URL you are given has answered once; one that exits first comes back with the end of its output. A port something else holds is said, with what holds it, and nothing is started there: the app is not moved to a port you were not told about. It runs in `dist/<module>`, or a folder inside it the agent names (`frontend`) - or, with guidance, in the host codebase; a folder that is not there starts nothing, and the agent is told so with what the folder holds, to name the right one.
|
|
40
|
-
4. **Says how it went** with `submit_launch`: launched or not, and in a line or three where it runs
|
|
40
|
+
4. **Says how it went** with `submit_launch`: launched or not, whether it serves - a backend or a frontend, against a CLI or a library tried from its folder - and in a line or three where it runs, or why it did not come up. The chat is told that, not the agent's prose. turri checks it rather than trusting it: a launch that says it serves - or names a URL - is launched only while something it started with `activate` still runs. Something else answering at its port - an earlier build left running, another program - is not this launch: `submit_launch` refuses it, and a launch that ends that way is `failed`, saying what holds the port.
|
|
41
41
|
|
|
42
42
|
`activate` and `submit_launch` are the launch agent's alone: the chat has `launch`, and nothing else of it. What a launch started is listed by the `pulses` tool and by **`/halt`**, with the launches under way and waiting, and stopped by **`/halt launched <name>`** (one server), **`/halt launched <module>`** (the module's launch under way, the one waiting, and what it started), by `halt` with `launched`, by the next launch of the codebase, and when turri exits. Halted, a launch that has nothing left running is `stopped` - "Stopped on request." - a host hears it, the sentinel has nothing of it to test, and the next launch of the codebase launches anew, never out already.
|
|
43
43
|
|
|
44
|
+
### What an earlier session left running
|
|
45
|
+
|
|
46
|
+
What a launch starts is written down as it starts - `.turri/launch/running/<pid>.json`: its process, its process group, its codebase, its command, folder and URL, and the turri that started it - and taken out as it ends. A turri that is killed outright stops nothing it started, and a server it left would hold its port in the next session, answering with old code. So as a session starts, and again before each launch of a codebase, turri stops what those records name whose turri has ended - its process group, politely and then not, as it stops its own - and says so in the ledger (`launch.left-behind`) and at the head of the summary of the codebase's next launch: `Stopped what an earlier turri session left running of shorty: backend (pid 66816, http://127.0.0.1:8000).` It stops only a process its records name, and only while it is still the one recorded - started when the record says; a pid given to another process since is left alone, its record taken out. What another turri still running started is that turri's.
|
|
47
|
+
|
|
44
48
|
## After every pulse
|
|
45
49
|
|
|
46
50
|
With `launch-after-pulse: true` in `config.turri.yaml`, turri launches what each pulse lands itself, on the launch track: the pulse ends as it lands - once its line in the notes is committed with it - and its commit is asked for as the codebase's next launch. The codebase's next pulse starts at once; nothing waits on the launch, and the chat - waiting on your answer to a question, say - has no part in it.
|
package/docs/sentinel.md
CHANGED
|
@@ -47,9 +47,10 @@ It checks every pulse, one at a time, in the order they finished. A pulse that f
|
|
|
47
47
|
|
|
48
48
|
With `launch-after-pulse` on, a pulse is launched in the background on the [launch track](launch.md#the-launch-track), the newest commit winning - so what runs may be a later commit than the pulse's own. The sentinel tests a pulse only in a launch whose commit holds the pulse's: its commit, or one built on it. Before it is told of a pulse, turri waits for its codebase's launches to settle - nothing launching, nothing waiting to - and checks that what runs holds the pulse's commit. The pulses waiting behind it wait with it.
|
|
49
49
|
|
|
50
|
-
- **What runs holds it**: it is told the launch, the commit, the pulses after it that the launch holds too - and that what those changed again is theirs to test.
|
|
50
|
+
- **What runs holds it**: it is told the launch, the commit, the pulses after it that the launch holds too - and that what those changed again is theirs to test. A launch that left nothing running - a CLI, a library - is named with the folder to try it from, `dist/<module>`, its absolute path.
|
|
51
51
|
- **The launch did not come up**: it is told why, and that is what it finds out about - a finding like any other. It tests nothing in its place: never the code in `plain_modules`, where a pulse may be writing, nor a server of its own.
|
|
52
52
|
- **You stopped the launch** (`/halt launched <module>`, or every server it started): nothing runs, and it checks the pulse alone.
|
|
53
|
+
- **Whichever it is**, it is told never to run the code in `plain_modules`, where a pulse may be writing, nor to start a server of its own - not in its shell, not with a host's terminal: what would pass there is not what you try. A server that should run and does not is its finding. A host's terminal command that starts or runs the code there - `cd plain_modules/shorty/code && .venv/bin/uvicorn …`, a program or a path there, an environment variable pointing there - is refused it, saying why; reading there is not.
|
|
53
54
|
- **What runs cannot hold it** - turri got it wrong: it is not told of the pulse. The error is shown in the chat you are in, recorded in the ledger (`sentinel.refused`), and the pulse is concluded unchecked; the next is taken.
|
|
54
55
|
|
|
55
56
|
When its codebase is launched again while it checks a pulse - a newer pulse landed - its turn is stopped where it is, its conversation kept: what it was testing is being replaced. It takes nothing else meanwhile. Once the codebase's launches have settled - one, or several in a row - turri checks again that what runs holds the pulse's commit, and tells it, in the same conversation, to carry on: what runs now, and to do again what it was doing as the servers restarted. What runs no longer holding it, it is refused as above. A launch of another codebase leaves it alone.
|
package/docs/using.md
CHANGED
|
@@ -79,9 +79,9 @@ A regeneration takes minutes, so in the TUI every tool that regenerates starts t
|
|
|
79
79
|
- **`/settings`** changes a setting of the project's `config.turri.yaml` - the models, review, conformance tests, any key - and says when it takes effect: now, at your next message, or at the next pulse; never only after a restart. It takes [pi](https://pi.dev)'s own `/settings` over, pi's menu the last entry of its list. See [changing it from the chat](config.md#changing-it-from-the-chat).
|
|
80
80
|
- **`/sentinel`** says whether the [sentinel](sentinel.md) checks every pulse that finishes: `ask` - you are asked before it first opens in a session - `on`, or `off`; written to `config.turri.yaml`.
|
|
81
81
|
- **`/regenerate [module | file.plain] [module:func-id ...] [from scratch [whole chain]] [how to cut the work]`** regenerates a module from its \*\*\*plain as it is now, as the `regenerate` tool does: what is left to regenerate is planned into pulses - one functional spec at a time, a few together or the whole module in one, as the planner judges - and the first starts. Words after the module are guidance for that plan (`/regenerate app models first`). A module's name typed with spaces for its underscores is that module - `/regenerate d365_function executor` is `d365_function_executor`. With no module named: the one `module:` in `config.turri.yaml` names, else the folder's top modules, to pick from. Asked for from scratch - `from scratch`, `start over`, `delete the module` - it starts at once, with nothing to confirm: it deletes the module's code and conformance tests in every codebase where they live, committed so `/lineage` keeps them, and regenerates the whole module from its \*\*\*plain, built though nothing in it changed: `/regenerate shorty from scratch`. The modules below it keep their code, and the module starts again from a copy of the code below it. Asked for its chain too - `/regenerate shorty from scratch, the whole chain` - the code of every module of its requires chain is deleted, the base's included, and the whole chain is regenerated from the bottom: what to do after modules were split, merged or moved, when the code below was laid out for modules that are no more. The chat's `regenerate` does the same with `from_scratch: "module"` or `"chain"`, when you ask for it; `turri regenerate --from-scratch` or `--from-scratch-chain` on the command line, not with `--dry-run`. Functional specs named after the module, each as `<module>:<func-id>` - `/regenerate shorty shorty:shorten shorty:expand` - are regenerated though their \*\*\*plain did not change, on the coding model: as `turri regenerate shorty.plain shorty:shorten shorty:expand` does, and the chat's `regenerate` with `funcIds`. A bare func-id is refused: the module is always named. Code built before functional specs had func-ids - its record numbers them - is never built on: the module's whole chain has to be regenerated from scratch, and the chat asks you first, as for a start over.
|
|
82
|
-
- **`/conform [module | file.plain] [module:func-id ...] [from scratch [whole chain]] [one by one]`** writes and runs a module's conformance tests now, as the `conform` tool does: those of the functional specs named, each as `<module>:<func-id>` - `/conform shorty shorty:shorten shorty:expand` - or, with none named, of every functional spec with scenarios. A functional spec named whose tests are written has them written again, deleted and written anew from its scenarios; `from scratch` takes out the tests folder where the module's code lives - the tip of its chain, never a module in the middle - its lineage keeping it, and writes the tests again from a copy of the tests of the module the tip requires; `from scratch, whole chain`, from nothing. None of it touches the code ([written again](regenerating.md#conformance-tests-in-the-work-loop)). They go in one pulse, as far as a size guardrail lets; `one by one` (or `separately`, `one at a time`) has a pulse a functional spec. No other words are taken: there is no plan to guide. The module is found as `/regenerate` finds it. Asking for them is asking for them on: with conformance tests off, `/conform` turns them on first - `conformance-tests: true`, written where the module's value comes from - and says so: the one way the chat's work has them turned on, as the `conform` tool is refused while they are off. What would start nothing is found from the \*\*\*plain before anything is said
|
|
82
|
+
- **`/conform [module | file.plain] [module:func-id ...] [from scratch [whole chain]] [one by one]`** writes and runs a module's conformance tests now, as the `conform` tool does: those of the functional specs named, each as `<module>:<func-id>` - `/conform shorty shorty:shorten shorty:expand` - or, with none named, of every functional spec with scenarios. A functional spec named whose tests are written has them written again, deleted and written anew from its scenarios; `from scratch` takes out the tests folder where the module's code lives - the tip of its chain, never a module in the middle - its lineage keeping it, and writes the tests again from a copy of the tests of the module the tip requires; `from scratch, whole chain`, from nothing. None of it touches the code ([written again](regenerating.md#conformance-tests-in-the-work-loop)). They go in one pulse, as far as a size guardrail lets; `one by one` (or `separately`, `one at a time`) has a pulse a functional spec. No other words are taken: there is no plan to guide. The module is found as `/regenerate` finds it. Asking for them is asking for them on: with conformance tests off, `/conform` turns them on first - `conformance-tests: true`, written where the module's value comes from - and says so: the one way the chat's work has them turned on, as the `conform` tool is refused while they are off. What would start nothing is found from the \*\*\*plain before anything is said. A step of adding tests still to take - no test reqs, no conformance testing script, no scenarios - is not an error: it is what `/conform` needs first, told to turri alone, not shown to you, and turri takes it at once - the test reqs, the conformance testing script, the scenarios of the functional specs named, or of each one that needs them - without asking again: your `/conform` was the yes. Then it regenerates the module, and says what it is writing and why. What is yours to settle - a functional spec named that is not there - is shown to you, and turri tells you what would let it start, starting nothing. Its tests come before anything is built on it: a codebase built on the module is stopped and deleted, and regenerated from it once they pass. Tests written already for the scenarios as built are said to be, and nothing starts.
|
|
83
83
|
- **`/halt <id>`** halts a pulse - a queued one never starts - **`/halt <module>`** (or a planned row's id) halts a module's planned pulses until you ask for it again, a \*\*\*plain change not starting it, and **`/halt launched <name>`** halts a server a launch started - **`/halt launched <module>`** the module's launch under way, the one waiting, and what it started; it lists them all when no id is given.
|
|
84
|
-
- **What these commands show you, the chat knows.** What `/regenerate`, `/conform` and `/halt launched` tell you - \*\*\*plain that does not parse, the pulses planned, a server halted - stays in the chat under the command, and since a slash command runs outside the conversation, it is put in the conversation as well: say "fix it" next and turri knows what you are looking at. When `/conform` starts nothing, turri answers it at once -
|
|
84
|
+
- **What these commands show you, the chat knows.** What `/regenerate`, `/conform` and `/halt launched` tell you - \*\*\*plain that does not parse, the pulses planned, a server halted - stays in the chat under the command, and since a slash command runs outside the conversation, it is put in the conversation as well: say "fix it" next and turri knows what you are looking at. When `/conform` starts nothing, turri answers it at once - taking the steps of adding tests still to take, which you are not shown, and saying why for the rest. Once `/regenerate` or `/conform` has started pulses, turri says so in the chat too - what runs and what is planned, and that you need not wait for it - without starting anything more for it; a module already up to date gets the plan's answer alone. A halted pulse reaches it as every pulse's end does.
|
|
85
85
|
- **Nothing is queued.** What is left to build is worked out from what each codebase is built from and \*\*\*plain as it is now - again whenever a pulse ends or \*\*\*plain changes - and the first pulse of it runs; see [a whole module](regenerating.md#a-whole-module). Changes that overlap never pile up: the next pulse builds \*\*\*plain as it is. The pulses planned after the one running are listed behind it, as queued, and so is each module waiting for the one it is built on - "waits for base" - until it can be planned. A change inside what the running pulse regenerates - a functional spec it regenerates reworded or given a sub-bullet, a definition or req it is given, a file they link - steers it: its agent is told, and it lands \*\*\*plain as it is now there, twice a pulse at most. Otherwise a pulse building something \*\*\*plain no longer wants is stopped and rolled back - unless `allow-to-stop-jobs: false` in `config.turri.yaml`, which has it land first and the change regenerated on top. To drop something, take it out of \*\*\*plain - one \*\*\*plain diff. Stopping a pulse leaves its change in \*\*\*plain: the codebase waits until its \*\*\*plain changes or it is asked for again.
|
|
86
86
|
- **A change to a module below** is made in the codebase at the tip of the chain, where its code lives; the codebase below is left as it was, and is brought up to its own \*\*\*plain only when a new module is to start from it. \*\*\*plain moved into a module the code was not built on stops the codebase: no change to its code brings that module in, so it has to be started over - its code and conformance tests taken out, kept in its history, and built again from the bottom of the chain. That is never done unasked: the chat asks you, saying why, and regenerates it from scratch once you agree; on the command line `turri regenerate` asks at the terminal, and `--start-over` agrees in advance.
|
|
87
87
|
- **Conformance tests are a track of their own.** A code pulse lands once its unit tests pass and are reviewed. Then, before the next one builds on it, a conformance pulse writes and runs the tests of what it built - the scenarios of its functional specs, by the test reqs - with the whole suite the module inherits, and, where one fails, fixes the test or the code, whichever is wrong; what they are written for is recorded in `tests/.turri.json`. A functional spec with no test plain file, or an empty one, gets none: to have it tested, ask for conformance tests - or, with them on, the chat writes scenarios itself for a functional spec it judges needs them (when an incorrect implementation could give output that looks right but is wrong, when two reasonable readings of its text answer some input differently, or when a bug would be costly - money, security, data, users' trust) - either way the chat writes its scenarios with its file tools and calls `regenerate`, and the loop tests them once the code is built. `conform` runs them now, for a module or some of its functional specs. A conformance pulse that does not pass is undone whole and halts the conformance tests alone: the code goes on being built.
|