@turri-dev/cli 0.2.4-next.8422d0f → 0.2.4-next.d779410
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -8
- package/dist/bedrock-region.js +3 -3
- package/dist/chat-idle.d.ts +2 -2
- package/dist/chat-idle.js +2 -2
- package/dist/chat-models.d.ts +1 -1
- package/dist/chat-models.js +1 -1
- package/dist/chat-scope.d.ts +1 -3
- package/dist/chat-skills.d.ts +1 -1
- package/dist/chat-skills.js +1 -1
- package/dist/chats.d.ts +44 -20
- package/dist/chats.js +125 -64
- package/dist/cli.js +12 -31
- package/dist/config-edit.d.ts +20 -8
- package/dist/config-edit.js +32 -26
- package/dist/config.d.ts +106 -78
- package/dist/config.js +267 -133
- package/dist/conform-cli.js +14 -3
- package/dist/conformance-switch.d.ts +13 -22
- package/dist/conformance-switch.js +37 -59
- package/dist/drift-cli.js +1 -1
- package/dist/extension.d.ts +17 -10
- package/dist/extension.js +435 -532
- package/dist/genome.js +10 -49
- package/dist/graph.js +3 -5
- package/dist/host-session.d.ts +11 -21
- package/dist/host-session.js +6 -8
- package/dist/host.d.ts +4 -4
- package/dist/host.js +4 -7
- package/dist/identity.js +2 -3
- package/dist/init-config.d.ts +1 -2
- package/dist/init-config.js +10 -17
- package/dist/installed-providers.d.ts +1 -1
- package/dist/installed-providers.js +1 -1
- package/dist/launch-agent.d.ts +51 -0
- package/dist/launch-agent.js +267 -0
- package/dist/{release-cli.js → launch-cli.js} +41 -24
- package/dist/launch-session.d.ts +68 -0
- package/dist/launch-session.js +217 -0
- package/dist/launch-tools.d.ts +28 -0
- package/dist/launch-tools.js +69 -0
- package/dist/launch-track.d.ts +125 -0
- package/dist/launch-track.js +320 -0
- package/dist/loop-cli.d.ts +4 -3
- package/dist/loop-cli.js +17 -15
- package/dist/loop-tools.d.ts +45 -21
- package/dist/loop-tools.js +155 -90
- package/dist/new-project.js +2 -2
- package/dist/notice.d.ts +7 -6
- package/dist/parse-cli.js +2 -2
- package/dist/pi-launch.js +4 -1
- package/dist/pi-settings.d.ts +4 -0
- package/dist/pi-settings.js +39 -0
- package/dist/pi.js +12 -9
- package/dist/plain/check.d.ts +2 -9
- package/dist/plain/check.js +6 -39
- package/dist/plain-files.d.ts +2 -2
- package/dist/plain-files.js +7 -7
- package/dist/regenerate/activity.d.ts +0 -7
- package/dist/regenerate/activity.js +2 -20
- package/dist/regenerate/agent-env.d.ts +1 -1
- package/dist/regenerate/agent-env.js +3 -3
- package/dist/regenerate/agent-shell.js +5 -3
- package/dist/regenerate/audit.js +9 -0
- package/dist/regenerate/base-folder.d.ts +2 -2
- package/dist/regenerate/base-folder.js +1 -1
- package/dist/regenerate/cases.js +7 -0
- package/dist/regenerate/chunk-plan.d.ts +5 -0
- package/dist/regenerate/chunk-plan.js +16 -1
- package/dist/regenerate/command-check.d.ts +7 -1
- package/dist/regenerate/command-check.js +43 -1
- package/dist/regenerate/delivery.d.ts +1 -1
- package/dist/regenerate/delivery.js +3 -3
- package/dist/regenerate/drift.d.ts +4 -0
- package/dist/regenerate/drift.js +26 -6
- package/dist/regenerate/failure-reports.d.ts +28 -0
- package/dist/regenerate/failure-reports.js +79 -0
- package/dist/regenerate/job-panel.js +3 -1
- package/dist/regenerate/jobs-tree.js +1 -1
- package/dist/regenerate/jobs.d.ts +4 -2
- package/dist/regenerate/jobs.js +14 -10
- package/dist/regenerate/launch.d.ts +154 -0
- package/dist/regenerate/{release.js → launch.js} +195 -51
- package/dist/regenerate/ledger-view.d.ts +11 -24
- package/dist/regenerate/ledger-view.js +14 -60
- package/dist/regenerate/ledger.d.ts +34 -16
- package/dist/regenerate/ledger.js +1 -1
- package/dist/regenerate/lineage.d.ts +2 -0
- package/dist/regenerate/lineage.js +8 -0
- package/dist/regenerate/loop.d.ts +54 -67
- package/dist/regenerate/loop.js +312 -148
- package/dist/regenerate/model-names.d.ts +33 -0
- package/dist/regenerate/{engine.js → model-names.js} +2 -28
- package/dist/regenerate/paths.d.ts +3 -3
- package/dist/regenerate/paths.js +4 -4
- package/dist/regenerate/records.d.ts +11 -0
- package/dist/regenerate/records.js +15 -0
- package/dist/regenerate/regenerate.d.ts +0 -2
- package/dist/regenerate/regenerate.js +4 -15
- package/dist/regenerate/renames.js +4 -4
- package/dist/regenerate/requires.d.ts +7 -0
- package/dist/regenerate/requires.js +24 -18
- package/dist/regenerate/scripts-being-written.d.ts +4 -4
- package/dist/regenerate/scripts-being-written.js +3 -3
- package/dist/regenerate/spec-map.js +3 -3
- package/dist/regenerate/standing.js +1 -1
- package/dist/regenerate/submit-work.d.ts +2 -0
- package/dist/regenerate/submit-work.js +8 -3
- package/dist/regenerate/test-scripts.d.ts +2 -1
- package/dist/regenerate/test-scripts.js +33 -23
- package/dist/regenerate/testing-steps.d.ts +16 -5
- package/dist/regenerate/testing-steps.js +28 -9
- package/dist/regenerate-cli.js +18 -9
- package/dist/self-invocation.d.ts +11 -0
- package/dist/self-invocation.js +36 -10
- package/dist/sentinel-check.d.ts +3 -3
- package/dist/sentinel-check.js +3 -3
- package/dist/sentinel.d.ts +18 -12
- package/dist/sentinel.js +75 -46
- package/dist/{config-command.d.ts → settings.d.ts} +13 -8
- package/dist/{config-command.js → settings.js} +155 -24
- package/dist/setup.d.ts +2 -2
- package/dist/setup.js +7 -7
- package/dist/skill.d.ts +0 -11
- package/dist/skill.js +0 -9
- package/dist/tools.js +2 -3
- package/dist/turri-versions.js +2 -1
- package/docs/README.md +4 -6
- package/docs/authoring-plain.md +3 -3
- package/docs/chats.md +6 -9
- package/docs/claude-subscription.md +2 -2
- package/docs/config.md +61 -51
- package/docs/development.md +4 -5
- package/docs/headless.md +7 -6
- package/docs/hosting.md +25 -24
- package/docs/launch.md +67 -0
- package/docs/parser.md +3 -3
- package/docs/regenerating.md +30 -22
- package/docs/sandbox.md +3 -3
- package/docs/sentinel.md +28 -16
- package/docs/skills-and-gates.md +6 -11
- package/docs/using.md +25 -42
- package/genome/rules/project-model.md +2 -1
- package/genome/rules/test-plain-files.md +15 -7
- package/genome/rules/turri-regeneration.md +7 -10
- package/genome/skills/convert-old-syntax/SKILL.md +5 -5
- package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
- package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
- package/package.json +1 -1
- package/dist/advisor-chat.d.ts +0 -63
- package/dist/advisor-chat.js +0 -290
- package/dist/change-plain-cli.js +0 -55
- package/dist/ledger-cli.d.ts +0 -1
- package/dist/ledger-cli.js +0 -50
- package/dist/ledger-tools.d.ts +0 -10
- package/dist/ledger-tools.js +0 -64
- package/dist/regenerate/advisor-records.d.ts +0 -93
- package/dist/regenerate/advisor-records.js +0 -110
- package/dist/regenerate/advisor-runs.d.ts +0 -87
- package/dist/regenerate/advisor-runs.js +0 -327
- package/dist/regenerate/engine.d.ts +0 -52
- package/dist/regenerate/release.d.ts +0 -121
- package/dist/regenerate/test-advisor.d.ts +0 -101
- package/dist/regenerate/test-advisor.js +0 -379
- package/dist/release-agent.d.ts +0 -43
- package/dist/release-agent.js +0 -130
- package/dist/release-cli.d.ts +0 -1
- package/dist/release-tools.d.ts +0 -44
- package/dist/release-tools.js +0 -170
- package/dist/spec-tools.d.ts +0 -36
- package/dist/spec-tools.js +0 -128
- package/dist/stacks.d.ts +0 -13
- package/dist/stacks.js +0 -96
- package/docs/deploy.md +0 -48
- package/docs/test-advisor.md +0 -110
- /package/dist/{change-plain-cli.d.ts → launch-cli.d.ts} +0 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import { createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, defineTool, } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { Type } from "typebox";
|
|
5
|
+
import { describeExport, holderOf, launchLogDir, runningLaunched, shortPath, startLaunched } from "./regenerate/launch.js";
|
|
6
|
+
import { machineChange, machineChangeReason } from "./regenerate/command-check.js";
|
|
7
|
+
import { projectDirOf } from "./regenerate/paths.js";
|
|
8
|
+
import { ask, BEGIN, createExecutor } from "./pi.js";
|
|
9
|
+
/**
|
|
10
|
+
* The person's own shell, in the host codebase: it installs what the launch needs into the project, and runs it. It
|
|
11
|
+
* changes nothing of the machine's - no toolchain installed, no system setting changed: a command that would is refused.
|
|
12
|
+
*/
|
|
13
|
+
export function launchShell(dir) {
|
|
14
|
+
const bash = createBashToolDefinition(dir);
|
|
15
|
+
return {
|
|
16
|
+
...bash,
|
|
17
|
+
description: `${bash.description}\n\nIt runs on the person's own machine, in ${shortPath(dir)}. Never start a server here: activate does. It installs nothing on the machine and changes none of its settings: what the machine lacks, the person installs.`,
|
|
18
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
19
|
+
const changes = machineChange(String(params.command ?? ""));
|
|
20
|
+
if (changes !== undefined)
|
|
21
|
+
throw new Error(machineChangeReason(changes));
|
|
22
|
+
return bash.execute(toolCallId, params, signal, onUpdate, ctx);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** A file tool that writes, refused inside plain_modules: the built code is the ***plain's to change, never a launch's. */
|
|
27
|
+
function outsideBuiltCode(tool, dir) {
|
|
28
|
+
return {
|
|
29
|
+
...tool,
|
|
30
|
+
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
31
|
+
const path = resolve(dir, String(params.path ?? ""));
|
|
32
|
+
if (relative(dir, path).split(sep).includes("plain_modules")) {
|
|
33
|
+
throw new Error(`Not written: ${shortPath(path)} is built code. A launch never changes it - a fix belongs in the ***plain.`);
|
|
34
|
+
}
|
|
35
|
+
// The ***plain - a module, a test plain file - is the person's: a launch that finds it wrong says so, never rewrites it.
|
|
36
|
+
if (path.endsWith(".plain")) {
|
|
37
|
+
throw new Error(`Not written: ${shortPath(path)} is ***plain. A launch never changes it - say what is wrong with it instead.`);
|
|
38
|
+
}
|
|
39
|
+
return tool.execute(toolCallId, params, signal, onUpdate, ctx);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function shown(file, max = 40_000) {
|
|
44
|
+
const text = readFileSync(file, "utf8");
|
|
45
|
+
const body = text.length > max ? `${text.slice(0, max)}\n… [the rest of ${shortPath(file)} is not shown]` : text;
|
|
46
|
+
return `<file path="${shortPath(file)}">\n${body.trimEnd()}\n</file>`;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* What the project says of itself, for the agent to find launch guidance in: its AGENTS.md and its skills
|
|
50
|
+
* (`.agents/skills`, `.pi/skills`, `.claude/skills`), where turri runs and in the host codebase - once each, whole.
|
|
51
|
+
*/
|
|
52
|
+
export function projectNotes(dirs) {
|
|
53
|
+
const roots = [...new Set(dirs.map((dir) => resolve(dir)))];
|
|
54
|
+
const files = new Set();
|
|
55
|
+
for (const root of roots) {
|
|
56
|
+
const agents = join(root, "AGENTS.md");
|
|
57
|
+
if (existsSync(agents))
|
|
58
|
+
files.add(agents);
|
|
59
|
+
for (const skills of [".agents/skills", ".pi/skills", ".claude/skills"].map((folder) => join(root, folder))) {
|
|
60
|
+
if (!existsSync(skills))
|
|
61
|
+
continue;
|
|
62
|
+
for (const name of readdirSync(skills)) {
|
|
63
|
+
const skill = join(skills, name, "SKILL.md");
|
|
64
|
+
if (existsSync(skill))
|
|
65
|
+
files.add(skill);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return [...files].map((file) => shown(file));
|
|
70
|
+
}
|
|
71
|
+
function text(value, details = {}) {
|
|
72
|
+
return { content: [{ type: "text", text: value }], details };
|
|
73
|
+
}
|
|
74
|
+
/** The folder a command runs in: in dist, or - `from: host` - in the host codebase; a folder inside either. */
|
|
75
|
+
function inside(root, dir) {
|
|
76
|
+
const target = resolve(root, dir ?? ".");
|
|
77
|
+
const rel = relative(root, target);
|
|
78
|
+
if (rel.startsWith("..") || isAbsolute(rel))
|
|
79
|
+
throw new Error(`${dir} is outside ${shortPath(root)}: what activate starts runs from there, or a folder inside it.`);
|
|
80
|
+
return target;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* activate: start what keeps running - a backend, a frontend's dev server - owned by the harness: in its own process
|
|
84
|
+
* group, its output kept, stopped on the codebase's next launch, on /halt and when turri exits.
|
|
85
|
+
*/
|
|
86
|
+
export function activateTool(launch, code) {
|
|
87
|
+
return defineTool({
|
|
88
|
+
name: "activate",
|
|
89
|
+
label: "Activate",
|
|
90
|
+
description: "Start something that keeps running - a backend, a frontend's dev server - on this machine: in the background, its " +
|
|
91
|
+
"output kept, stopped on the next launch, on /halt and when turri exits. With `url`, waits until something answers " +
|
|
92
|
+
"there and says so, or shows the end of its output. A port something else holds is said, and nothing is started.",
|
|
93
|
+
promptSnippet: "start a server of the launched code, and wait for it to answer",
|
|
94
|
+
parameters: Type.Object({
|
|
95
|
+
name: Type.String({ description: "A short name for it: backend, frontend, app" }),
|
|
96
|
+
command: Type.String({ description: "The command that starts it, as run from its folder" }),
|
|
97
|
+
url: Type.Optional(Type.String({ description: "Where it serves, e.g. http://localhost:5173 - it is ready once this answers" })),
|
|
98
|
+
from: Type.Optional(Type.Union([Type.Literal("dist"), Type.Literal("host")], {
|
|
99
|
+
description: `Where dir is named from: dist, the launched code (${shortPath(code.dir)}) - the default; host, the host codebase (${shortPath(launch.hostDir)}), when guidance says to start it there.`,
|
|
100
|
+
})),
|
|
101
|
+
dir: Type.Optional(Type.String({ description: "The folder to run it in, inside the one `from` names - e.g. frontend. Default: that folder itself." })),
|
|
102
|
+
}),
|
|
103
|
+
async execute(_id, params) {
|
|
104
|
+
const root = params.from === "host" ? launch.hostDir : code.dir;
|
|
105
|
+
const started = await startLaunched({
|
|
106
|
+
name: params.name,
|
|
107
|
+
command: params.command,
|
|
108
|
+
dir: inside(root, params.dir),
|
|
109
|
+
root,
|
|
110
|
+
moduleName: launch.codebase,
|
|
111
|
+
logDir: launchLogDir(projectDirOf(launch.plainFile)),
|
|
112
|
+
...(params.url !== undefined ? { url: params.url } : {}),
|
|
113
|
+
});
|
|
114
|
+
return text(started.text, { ok: started.ok, ...(started.process !== undefined ? { pid: started.process.pid, log: started.process.log } : {}) });
|
|
115
|
+
},
|
|
116
|
+
});
|
|
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
|
+
}
|
|
152
|
+
/** submit_launch: how the launch went, once, last - the harness reads its arguments, never the agent's prose. */
|
|
153
|
+
function submitLaunchTool(launch, submitted) {
|
|
154
|
+
return defineTool({
|
|
155
|
+
name: "submit_launch",
|
|
156
|
+
label: "Submit launch",
|
|
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 " +
|
|
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 " +
|
|
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.",
|
|
162
|
+
parameters: Type.Object({
|
|
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" }),
|
|
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" }),
|
|
166
|
+
}),
|
|
167
|
+
async execute(_id, params) {
|
|
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 };
|
|
173
|
+
return text("Taken. You are done: end your turn.");
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/** What the agent does once the code is in dist: find guidance and follow it from the host, or start it from dist. */
|
|
178
|
+
export function launchGuide(code, hostDir) {
|
|
179
|
+
const dist = shortPath(code.dir);
|
|
180
|
+
const host = shortPath(hostDir);
|
|
181
|
+
const built = shortPath(code.buildDir);
|
|
182
|
+
return [
|
|
183
|
+
"First ask yourself: is there guidance for how this project launches it - what the person said, the project's notes and",
|
|
184
|
+
"skills below, or anything else you find? An integration a host application loads, say, put in place with the host's own",
|
|
185
|
+
"scripts. Then:",
|
|
186
|
+
"",
|
|
187
|
+
`Without guidance - start it from ${dist}, as best it can be:`,
|
|
188
|
+
`1. Find out how it runs: its README, its manifests (package.json, pyproject.toml, requirements.txt, go.mod, Cargo.toml, pom.xml, build.gradle, docker-compose.yml) and entry points, in ${dist}.`,
|
|
189
|
+
"2. Check the toolchains it needs are on this machine (`command -v node`, `python3 --version`, `go version`, ...) - under another name too: python where python3 is not, of the version it needs. One missing: you install nothing on the machine and change none of its settings - stop, and say exactly what to install, the command the person runs themselves (`brew install node`), and that launching again picks it up.",
|
|
190
|
+
"3. Install what it needs into the project yourself, in your shell - dependencies into a virtual environment or node_modules, a build that fetches packages, an image pull. Do not ask: do it, and fix what fails - within the project: never a global install, never a system setting.",
|
|
191
|
+
"4. Start anything that keeps running - a backend, a frontend's dev server - with activate, with the URL it serves at: never in the shell with & or nohup. An app with a backend and a frontend: start both, the backend first.",
|
|
192
|
+
"",
|
|
193
|
+
`With guidance - follow it, on this machine, from the host codebase ${host}:`,
|
|
194
|
+
`1. The code to launch is in ${dist}: the commit, whole. Take it from there, never from ${built}, where a pulse may be writing - always: where the guidance's own tooling reads ${built}, point it at ${dist} if it can take another source; if it cannot, do by hand, from ${dist}, what it does.`,
|
|
195
|
+
`2. Read what the guidance leaves open - the scripts, files and commands it names, in ${host} - then do what it says, in its order. Where it says to change the host - a registration, an import, a config entry - change it.`,
|
|
196
|
+
"3. Run the project's scripts and install what it needs into the project yourself, in your shell. A toolchain or system tool the machine lacks you never install, nor change a setting of the machine's: say the command the person runs themselves.",
|
|
197
|
+
"4. Start what keeps running - a start script, a dev server - with activate (from: host when it runs in the host codebase), with the URL it serves at - never in the shell with & or nohup.",
|
|
198
|
+
"",
|
|
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.`,
|
|
200
|
+
"",
|
|
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.",
|
|
206
|
+
].join("\n");
|
|
207
|
+
}
|
|
208
|
+
/** Run the launch agent to its end: how it went, as it submitted it - or, never submitted, its last words as a failure. */
|
|
209
|
+
export async function runLaunchAgent(input) {
|
|
210
|
+
const { launch, code } = input;
|
|
211
|
+
const dir = launch.hostDir;
|
|
212
|
+
const notes = projectNotes([input.cwd, dir, projectDirOf(launch.plainFile)]);
|
|
213
|
+
const fileTools = [
|
|
214
|
+
createReadToolDefinition(dir),
|
|
215
|
+
createLsToolDefinition(dir),
|
|
216
|
+
createGrepToolDefinition(dir),
|
|
217
|
+
createFindToolDefinition(dir),
|
|
218
|
+
// Guidance may say to change the host - a registration, an import.
|
|
219
|
+
outsideBuiltCode(createEditToolDefinition(dir), dir),
|
|
220
|
+
outsideBuiltCode(createWriteToolDefinition(dir), dir),
|
|
221
|
+
];
|
|
222
|
+
const submitted = {};
|
|
223
|
+
const tools = [activateTool(launch, code), submitLaunchTool(launch, submitted)];
|
|
224
|
+
const executor = await createExecutor({
|
|
225
|
+
// Its sessions are kept in the project, not in the folder it launches.
|
|
226
|
+
cwd: projectDirOf(launch.plainFile),
|
|
227
|
+
customTools: [...fileTools, launchShell(dir), ...tools],
|
|
228
|
+
tools: [...fileTools.map((tool) => tool.name), "bash", ...tools.map((tool) => tool.name)],
|
|
229
|
+
...(input.model !== undefined ? { model: input.model } : {}),
|
|
230
|
+
role: "launch",
|
|
231
|
+
system: [
|
|
232
|
+
"You get software that was just built running on the person's own machine, so they and turri's sentinel can try it. You ask no one: do it.",
|
|
233
|
+
`Your file tools and your shell start in ${dir}. Your shell is the person's own - not a sandbox.`,
|
|
234
|
+
].join("\n"),
|
|
235
|
+
task: [
|
|
236
|
+
"pulse" in launch.cause
|
|
237
|
+
? `A pulse of ${launch.codebase} just landed: ${launch.cause.title}. The project launches what every pulse lands: launch it now, whether or not the guidance speaks of launching after a build - what the guidance says is how.`
|
|
238
|
+
: `Launch ${launch.codebase} for the person to try.`,
|
|
239
|
+
"",
|
|
240
|
+
describeExport(code),
|
|
241
|
+
"",
|
|
242
|
+
launchGuide(code, dir),
|
|
243
|
+
...(launch.inModule !== undefined ? ["", `It is the codebase of module ${launch.inModule}.`] : []),
|
|
244
|
+
...(launch.guidance !== undefined ? ["", "What the person said of how to launch it:", launch.guidance] : []),
|
|
245
|
+
...(notes.length > 0 ? ["", "The project's notes and skills:", ...notes] : []),
|
|
246
|
+
].join("\n"),
|
|
247
|
+
});
|
|
248
|
+
const stop = () => void executor.abort();
|
|
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
|
+
};
|
|
255
|
+
try {
|
|
256
|
+
const said = await ask(executor, BEGIN, input.onDelta);
|
|
257
|
+
if (submitted.outcome !== undefined)
|
|
258
|
+
return checked(submitted.outcome);
|
|
259
|
+
// Ended without saying how it went: asked once more, then taken as not launched.
|
|
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);
|
|
261
|
+
return submitted.outcome !== undefined ? checked(submitted.outcome) : { launched: false, summary: (again.trim() || said.trim() || "The launch agent ended without saying how it went.") };
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
input.signal?.removeEventListener("abort", stop);
|
|
265
|
+
executor.dispose();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -2,27 +2,27 @@ import { closeSync, openSync, readSync, statSync } from "node:fs";
|
|
|
2
2
|
import { refuseTestPlainFile } from "./test-plain-files.js";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { configForSpec, modelSpec, projectModels, readProjectConfig } from "./config.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { createLaunchTrack } from "./launch-track.js";
|
|
6
|
+
import { runLaunchAgent } from "./launch-agent.js";
|
|
7
|
+
import { listLaunched, runningLaunched, stopLaunched } from "./regenerate/launch.js";
|
|
8
8
|
import { c } from "./module-report.js";
|
|
9
|
-
const USAGE = `usage: turri
|
|
9
|
+
const USAGE = `usage: turri launch [file.plain] [options]
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Launches the module on top of the spec's requires chain, which holds the code of the ones below, and
|
|
12
12
|
has an agent start it here, on this machine. The module's code, as its last commit has it, always
|
|
13
|
-
goes in dist/<module> first. The agent looks for guidance on how this project
|
|
13
|
+
goes in dist/<module> first. The agent looks for guidance on how this project launches it - what
|
|
14
14
|
--guidance says, the project's AGENTS.md - and follows it from there when there is some: an
|
|
15
15
|
integration its host application takes with the host's own scripts, say. When there is none, it
|
|
16
16
|
reads how the code in dist runs, installs what it needs, and starts what serves. Either way it asks
|
|
17
17
|
nothing, and stays in the foreground with the servers' output; Ctrl-C stops them.
|
|
18
18
|
|
|
19
19
|
The project's config.turri.yaml gives the defaults: module (the file when none is given) and
|
|
20
|
-
|
|
20
|
+
coding-model (the agent's model).
|
|
21
21
|
|
|
22
22
|
--in-module <module> the codebase to take, when modules built on this one branch
|
|
23
|
-
--guidance <text> how this project
|
|
24
|
-
--model <provider/id> the agent's model (default:
|
|
25
|
-
const PROBLEMS = "If you are having problems,
|
|
23
|
+
--guidance <text> how this project launches it: the scripts to run, in order
|
|
24
|
+
--model <provider/id> the agent's model (default: coding-model)`;
|
|
25
|
+
const PROBLEMS = "If you are having problems, launch it from the chat: run turri and ask to try it.";
|
|
26
26
|
function parseArgs(argv) {
|
|
27
27
|
const positional = [];
|
|
28
28
|
let model;
|
|
@@ -54,8 +54,8 @@ function followLogs() {
|
|
|
54
54
|
const offsets = new Map();
|
|
55
55
|
return new Promise((done) => {
|
|
56
56
|
const tick = () => {
|
|
57
|
-
const running =
|
|
58
|
-
for (const item of
|
|
57
|
+
const running = runningLaunched();
|
|
58
|
+
for (const item of listLaunched()) {
|
|
59
59
|
let size = 0;
|
|
60
60
|
try {
|
|
61
61
|
size = statSync(item.log).size;
|
|
@@ -92,11 +92,10 @@ async function main() {
|
|
|
92
92
|
}
|
|
93
93
|
const plainFile = resolve(named);
|
|
94
94
|
refuseTestPlainFile(plainFile);
|
|
95
|
-
// A
|
|
95
|
+
// A launch follows steps - a script, a start command: the coding model does that well, thinking low.
|
|
96
96
|
const model = args.model ?? modelSpec(projectModels(configForSpec(plainFile)).coding);
|
|
97
|
-
const state = createDeployState();
|
|
98
97
|
const stopAll = async () => {
|
|
99
|
-
const stopped = await
|
|
98
|
+
const stopped = await stopLaunched();
|
|
100
99
|
if (stopped.length > 0)
|
|
101
100
|
console.log(c.dim(`\nStopped ${stopped.join(", ")}.`));
|
|
102
101
|
};
|
|
@@ -104,24 +103,42 @@ async function main() {
|
|
|
104
103
|
void stopAll().then(() => process.exit(0));
|
|
105
104
|
});
|
|
106
105
|
console.log(c.dim(`\nworking out how to start it${model !== undefined ? ` (${model})` : ""}…\n`));
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
// One launch, on a track of its own: the code exported first, then the agent, its words as they come.
|
|
107
|
+
let streamed = "";
|
|
108
|
+
const track = createLaunchTrack({
|
|
109
109
|
cwd: process.cwd(),
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
run: (launch, code, signal) => runLaunchAgent({
|
|
111
|
+
launch,
|
|
112
|
+
code,
|
|
113
|
+
cwd: process.cwd(),
|
|
114
|
+
signal,
|
|
115
|
+
...(model !== undefined ? { model } : {}),
|
|
116
|
+
onDelta: (delta) => {
|
|
117
|
+
streamed += delta;
|
|
118
|
+
process.stdout.write(delta);
|
|
119
|
+
},
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
const { launch } = track.request({
|
|
123
|
+
plainFile,
|
|
112
124
|
...(args.inModule !== undefined ? { inModule: args.inModule } : {}),
|
|
113
125
|
...(args.guidance !== undefined ? { guidance: args.guidance } : {}),
|
|
114
|
-
|
|
126
|
+
cause: {},
|
|
115
127
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
128
|
+
const ended = await track.done(launch.id);
|
|
129
|
+
// What the agent said as it went is on the screen already: its summary only when it said nothing.
|
|
130
|
+
const said = streamed.trim() === "" ? `\n${ended.summary ?? ""}` : "";
|
|
131
|
+
console.log(`\n\n${ended.status === "launched" ? c.success(`Launched.${said}`) : c.error(`It did not come up.${said}`)}`);
|
|
132
|
+
if (ended.status !== "launched")
|
|
133
|
+
console.log(`\n${c.dim(PROBLEMS)}`);
|
|
134
|
+
if (runningLaunched().length === 0)
|
|
135
|
+
process.exit(ended.status === "launched" ? 0 : 1);
|
|
119
136
|
console.log(c.success(c.bold("\nRunning - Ctrl-C stops it.")) + c.dim(" Its output follows.\n"));
|
|
120
137
|
await followLogs();
|
|
121
138
|
process.exit(0);
|
|
122
139
|
}
|
|
123
140
|
main().catch(async (error) => {
|
|
124
|
-
await
|
|
141
|
+
await stopLaunched();
|
|
125
142
|
console.error(error instanceof Error ? error.message : error);
|
|
126
143
|
console.error(`\n${PROBLEMS}`);
|
|
127
144
|
process.exit(1);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { SentinelLaunches } from "./chats.ts";
|
|
2
|
+
import { type Launch, type LaunchTrack } from "./launch-track.ts";
|
|
3
|
+
import { type LaunchedProcess } from "./regenerate/launch.ts";
|
|
4
|
+
import { type Job, type JobRegistry, type PulseSpec } from "./regenerate/jobs.ts";
|
|
5
|
+
import type { SentinelCheck } from "./notice.ts";
|
|
6
|
+
/** What runs for a pulse, as the sentinel is told it. */
|
|
7
|
+
export interface PulseLaunch {
|
|
8
|
+
/** The commit the pulse landed - none when it did not land. */
|
|
9
|
+
commit?: string;
|
|
10
|
+
/** launch-after-pulse was off as it landed: nothing launched for it. */
|
|
11
|
+
off?: boolean;
|
|
12
|
+
/** Its launch could not be asked for, and why. */
|
|
13
|
+
notAsked?: string;
|
|
14
|
+
/** The launch whose commit holds it - what runs. */
|
|
15
|
+
launch?: Launch;
|
|
16
|
+
/** The person stopped the launch: nothing runs to test. */
|
|
17
|
+
stopped?: boolean;
|
|
18
|
+
/** The pulses that landed after it which the launch holds too, oldest first. */
|
|
19
|
+
later: Job[];
|
|
20
|
+
/** Its functional specs a later pulse in the launch changed too: those pulses' checks test them. */
|
|
21
|
+
laterSpecs: PulseSpec[];
|
|
22
|
+
running: LaunchedProcess[];
|
|
23
|
+
}
|
|
24
|
+
export interface SessionLaunches extends SentinelLaunches {
|
|
25
|
+
track: LaunchTrack;
|
|
26
|
+
/** A pulse landed, its commit final: kept - and, under launch-after-pulse, its launch asked for. */
|
|
27
|
+
landed(input: {
|
|
28
|
+
job: Job;
|
|
29
|
+
plainFile: string;
|
|
30
|
+
moduleName: string;
|
|
31
|
+
commit: string;
|
|
32
|
+
title: string;
|
|
33
|
+
}): void;
|
|
34
|
+
/** What runs for a pulse, once `readyFor` resolved. */
|
|
35
|
+
forPulse(job: Job): PulseLaunch;
|
|
36
|
+
/** What the sentinel is told to carry on with a paused check: throws when what runs no longer holds it. */
|
|
37
|
+
resumeText(work: {
|
|
38
|
+
job: Job;
|
|
39
|
+
} | {
|
|
40
|
+
check: SentinelCheck;
|
|
41
|
+
}): string;
|
|
42
|
+
}
|
|
43
|
+
export declare function createSessionLaunches(options: {
|
|
44
|
+
cwd: string;
|
|
45
|
+
jobs: JobRegistry;
|
|
46
|
+
/** The launch agent's model: the coding model of the codebase. */
|
|
47
|
+
model: (plainFile: string) => string | undefined;
|
|
48
|
+
onChange: (launch: Launch) => void;
|
|
49
|
+
}): SessionLaunches;
|
|
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[];
|
|
62
|
+
/**
|
|
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
|
|
64
|
+
* the newer one waiting, which stops what it started: it is told the newer one's end instead.
|
|
65
|
+
*/
|
|
66
|
+
export declare function replacedNote(launch: Launch, next: Launch, job?: Job): string;
|
|
67
|
+
/** What a chat is told of a launch that ended - one it asked for, or one after a pulse with the sentinel off. */
|
|
68
|
+
export declare function launchedNote(launch: Launch, job?: Job): string;
|