@turri-dev/cli 0.2.4-next.240620d → 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/README.md +6 -7
- package/dist/bedrock-region.js +3 -3
- 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 -10
- package/dist/chats.js +125 -41
- package/dist/cli.js +10 -26
- package/dist/config-edit.d.ts +20 -8
- package/dist/config-edit.js +32 -24
- package/dist/config.d.ts +101 -58
- package/dist/config.js +265 -118
- package/dist/conform-cli.js +14 -3
- package/dist/conformance-switch.d.ts +7 -6
- package/dist/conformance-switch.js +19 -16
- package/dist/extension.d.ts +29 -3
- package/dist/extension.js +375 -351
- package/dist/genome.js +5 -1
- package/dist/host-session.d.ts +8 -7
- package/dist/host-session.js +4 -4
- package/dist/host.d.ts +3 -1
- package/dist/host.js +3 -3
- package/dist/identity.js +2 -2
- package/dist/init-config.d.ts +1 -1
- package/dist/init-config.js +8 -8
- package/dist/launch-agent.d.ts +51 -0
- package/dist/launch-agent.js +267 -0
- package/dist/{release-cli.js → launch-cli.js} +41 -24
- package/dist/launch-session.d.ts +68 -0
- package/dist/launch-session.js +217 -0
- package/dist/launch-tools.d.ts +28 -0
- package/dist/launch-tools.js +69 -0
- package/dist/launch-track.d.ts +125 -0
- package/dist/launch-track.js +320 -0
- package/dist/loop-cli.js +4 -4
- package/dist/loop-tools.d.ts +45 -21
- package/dist/loop-tools.js +152 -82
- package/dist/notice.d.ts +7 -6
- package/dist/parse-cli.js +2 -2
- package/dist/pi-launch.js +3 -0
- package/dist/pi-settings.d.ts +4 -0
- package/dist/pi-settings.js +39 -0
- package/dist/pi.js +6 -3
- package/dist/plain/check.d.ts +1 -1
- package/dist/plain/check.js +3 -1
- package/dist/plain-files.d.ts +2 -2
- package/dist/plain-files.js +7 -7
- 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/job-panel.js +3 -1
- package/dist/regenerate/jobs.d.ts +2 -2
- package/dist/regenerate/jobs.js +10 -10
- package/dist/regenerate/launch.d.ts +154 -0
- package/dist/regenerate/{release.js → launch.js} +195 -51
- package/dist/regenerate/ledger.d.ts +33 -2
- package/dist/regenerate/lineage.d.ts +2 -0
- package/dist/regenerate/lineage.js +8 -0
- package/dist/regenerate/loop.d.ts +30 -10
- package/dist/regenerate/loop.js +166 -59
- 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.js +4 -1
- 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/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 +6 -6
- package/dist/regenerate/testing-steps.js +8 -8
- package/dist/regenerate-cli.js +1 -1
- package/dist/self-invocation.d.ts +11 -0
- package/dist/self-invocation.js +36 -7
- package/dist/sentinel-check.d.ts +3 -3
- package/dist/sentinel-check.js +3 -3
- package/dist/sentinel.d.ts +18 -12
- package/dist/sentinel.js +72 -43
- 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/turri-versions.js +2 -1
- package/docs/README.md +4 -4
- package/docs/chats.md +5 -6
- package/docs/claude-subscription.md +2 -2
- package/docs/config.md +58 -46
- package/docs/development.md +2 -2
- package/docs/headless.md +4 -4
- package/docs/hosting.md +20 -19
- package/docs/launch.md +67 -0
- package/docs/parser.md +2 -2
- package/docs/regenerating.md +21 -15
- package/docs/sandbox.md +3 -3
- package/docs/sentinel.md +26 -14
- package/docs/skills-and-gates.md +4 -4
- package/docs/using.md +19 -28
- package/genome/rules/project-model.md +2 -1
- package/genome/rules/turri-regeneration.md +5 -3
- 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/regenerate/engine.d.ts +0 -52
- package/dist/regenerate/release.d.ts +0 -121
- package/dist/release-agent.d.ts +0 -43
- package/dist/release-agent.js +0 -130
- package/dist/release-tools.d.ts +0 -44
- package/dist/release-tools.js +0 -170
- package/dist/stacks.d.ts +0 -13
- package/dist/stacks.js +0 -96
- package/docs/deploy.md +0 -48
- /package/dist/{release-cli.d.ts → launch-cli.d.ts} +0 -0
package/dist/genome.js
CHANGED
|
@@ -4,6 +4,7 @@ import { Command, MemorySaver } from "@langchain/langgraph";
|
|
|
4
4
|
import { compileSkill } from "./graph.js";
|
|
5
5
|
import { createExecutor } from "./pi.js";
|
|
6
6
|
import { plainWriteTools } from "./plain-files.js";
|
|
7
|
+
import { skillShell } from "./self-invocation.js";
|
|
7
8
|
import { toolchainsBlock } from "./stack.js";
|
|
8
9
|
import { clearOfStop, describeToolCall, describeToolResult, withStopSignal } from "./regenerate/activity.js";
|
|
9
10
|
import { createLiveReviewer } from "./review/live.js";
|
|
@@ -102,8 +103,11 @@ async function runStoppable(opts) {
|
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
customTools.push(...(opts.sharedTools ?? []));
|
|
105
|
-
// Its write and edit reach the project's ***plain only - not the code, a
|
|
106
|
+
// Its write and edit reach the project's ***plain only - not the code, a launch, or what an app it started writes.
|
|
106
107
|
customTools.push(...plainWriteTools(opts.cwd).filter((tool) => skill.allowedTools.includes(tool.name)));
|
|
108
|
+
// Its shell runs neither turri nor another pi again: that would build outside the session's work loop.
|
|
109
|
+
if (skill.allowedTools.includes("bash"))
|
|
110
|
+
customTools.push(skillShell(opts.cwd));
|
|
107
111
|
const names = customTools.map((tool) => tool.name);
|
|
108
112
|
// Tools this harness provides are never pi built-ins, even when it did not provide them.
|
|
109
113
|
const builtins = skill.allowedTools.filter((t) => !names.includes(t) && !LOOP_TOOLS.includes(t));
|
package/dist/host-session.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface Turri {
|
|
|
51
51
|
/**
|
|
52
52
|
* ctrl+c in a chat, as the terminal has it: what the chat is doing stopped - its turn, a skill or a tool in it, a `!`
|
|
53
53
|
* command, a compaction - and nothing in the others (`stopped`). In a chat doing nothing the session ends - every
|
|
54
|
-
* chat let go and what
|
|
54
|
+
* chat let go and what launches started stopped, as `dispose` does - for the host to close what showed it (`ended`).
|
|
55
55
|
* A second interrupt straight after one that stopped something does nothing (`ignored`); `missing` for a chat not open.
|
|
56
56
|
*/
|
|
57
57
|
interrupt(id: string): Promise<"stopped" | "ignored" | "ended" | "missing">;
|
|
@@ -68,9 +68,10 @@ export interface Turri {
|
|
|
68
68
|
*/
|
|
69
69
|
notices(): Notice[];
|
|
70
70
|
/**
|
|
71
|
-
* The sentinel asked to check functional specs in a module
|
|
72
|
-
* of any module its requires chain builds on (a bare func-id is the module's own) -
|
|
73
|
-
*
|
|
71
|
+
* The sentinel asked to check functional specs in what is launched of a module - `funcIds` each `module:func-id`, of the
|
|
72
|
+
* module or of any module its requires chain builds on (a bare func-id is the module's own) - as it tests a launch after a
|
|
73
|
+
* pulse: the module's own codebase's code, which holds every module its chain builds on. Nothing launched of it, the
|
|
74
|
+
* check ends unchecked: the sentinel launches nothing. Queued behind the
|
|
74
75
|
* sentinel's work, in a conversation of its own. Returns the check's id - its notices and its conclusion carry it - or
|
|
75
76
|
* why it was refused: the sentinel off or not started this session, a module not there or that does not parse, a
|
|
76
77
|
* module outside its chain, a func-id a module does not have, one not built in its codebase as its ***plain has it now.
|
|
@@ -81,7 +82,7 @@ export interface Turri {
|
|
|
81
82
|
refused: string;
|
|
82
83
|
};
|
|
83
84
|
/**
|
|
84
|
-
* Every value /
|
|
85
|
+
* Every value /settings offers for a setting after `typed` - what its completions compute, in their order, but
|
|
85
86
|
* whole: uncapped, and without "unset", which a host draws itself; the values alone, not `<key> <value>`. A model
|
|
86
87
|
* setting's are every model of every provider signed in to, from the model registry the chats use - and after a colon,
|
|
87
88
|
* `harness-model amazon-bedrock/global.anthropic.claude-opus-5-5:`, that model's thinking levels. An unknown key gives none.
|
|
@@ -89,7 +90,7 @@ export interface Turri {
|
|
|
89
90
|
settingChoices(key: string, typed?: string): string[];
|
|
90
91
|
/**
|
|
91
92
|
* Conformance tests turned on, as /conform does before it tests - the person's decision, a host's switch for it:
|
|
92
|
-
* `conformance-tests: true` written where the module's value comes from - its
|
|
93
|
+
* `conformance-tests: true` written where the module's value comes from - its own `config.turri.<module>.yaml`, or a required module's, when
|
|
93
94
|
* that sets the key, else `config.turri.yaml` - the chats' conform no longer refused. `plainFile`, absolute or from the
|
|
94
95
|
* project, picks the module; omitted,
|
|
95
96
|
* the project's. Returns the file written, from the project. Starts no conformance pulse: that is `conform`'s.
|
|
@@ -104,7 +105,7 @@ export interface Turri {
|
|
|
104
105
|
answer(id: string, answer: NoticeAnswer): Promise<"done" | "dismissed" | "ignored" | "refused" | "missing" | "over">;
|
|
105
106
|
/** Told when a chat is opened, closed, renamed, or starts or stops working. */
|
|
106
107
|
onChats(listener: (chats: ChatInfo[]) => void): () => void;
|
|
107
|
-
/** Every chat let go, and what
|
|
108
|
+
/** Every chat let go, and what launches started stopped. */
|
|
108
109
|
dispose(): Promise<void>;
|
|
109
110
|
}
|
|
110
111
|
/** turri's session in a host, in the process's working folder - the project's. */
|
package/dist/host-session.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { createAgentSession, DefaultResourceLoader, getAgentDir, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { lastRun } from "./chat-records.js";
|
|
3
3
|
import { interruptChat } from "./chats.js";
|
|
4
|
-
import { reachable, ruleNames, settingCandidates } from "./
|
|
4
|
+
import { reachable, ruleNames, settingCandidates } from "./settings.js";
|
|
5
5
|
import { settingOf } from "./config-edit.js";
|
|
6
6
|
import { createTurriCore, sessionLoop, turnOnConformance } from "./extension.js";
|
|
7
|
-
import {
|
|
7
|
+
import { stopLaunched } from "./regenerate/launch.js";
|
|
8
8
|
import { prepareCheck } from "./sentinel-check.js";
|
|
9
9
|
/** turri's session in a host, in the process's working folder - the project's. */
|
|
10
10
|
export async function createTurri(options = {}) {
|
|
@@ -43,7 +43,7 @@ export async function createTurri(options = {}) {
|
|
|
43
43
|
let lastStop = 0;
|
|
44
44
|
const dispose = async () => {
|
|
45
45
|
await core.dispose();
|
|
46
|
-
await
|
|
46
|
+
await stopLaunched();
|
|
47
47
|
};
|
|
48
48
|
return {
|
|
49
49
|
jobs: core.jobs,
|
|
@@ -78,7 +78,7 @@ export async function createTurri(options = {}) {
|
|
|
78
78
|
if (setting === undefined)
|
|
79
79
|
return [];
|
|
80
80
|
// The models from a chat's own context - the one shown, else any open: the registry the chats use, whether or not one
|
|
81
|
-
// has run /
|
|
81
|
+
// has run /settings.
|
|
82
82
|
const context = () => {
|
|
83
83
|
const shown = core.shownChat();
|
|
84
84
|
const states = [shown, ...core.chats().map((chat) => core.session(chat.id)).map((session) => (session !== undefined ? core.chatOfSession(session) : undefined))];
|
package/dist/host.d.ts
CHANGED
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { createTurri, type Turri, type TurriOptions } from "./host-session.ts";
|
|
8
8
|
export { MAX_CHATS, type ChatInfo, type ChatStatus, type TurriHost } from "./chats.ts";
|
|
9
|
+
export type { Launch, LaunchCause, LaunchStatus } from "./launch-track.ts";
|
|
10
|
+
export type { ConfigLine, ConfigLineKind } from "./config.ts";
|
|
9
11
|
export { SENTINEL, SENTINEL_START, type Conclusion, type Notice, type NoticeAction, type NoticeAnswer, type NoticeSeverity, type NoticeState, type SentinelCheck } from "./notice.ts";
|
|
10
12
|
export type { CheckRequest } from "./sentinel-check.ts";
|
|
11
13
|
export type { AskUserIO } from "./ask.ts";
|
|
12
14
|
/** pi itself, as turri is built against it: a host's own extensions and UI are made with this one, not another copy. */
|
|
13
15
|
export * as pi from "@earendil-works/pi-coding-agent";
|
|
14
|
-
export { configForSpec, debugMode, DEFAULT_TEST_DIR, hasProjectConfig, modelSpec, projectModels, readProjectConfig,
|
|
16
|
+
export { configForSpec, debugMode, DEFAULT_TEST_DIR, hasProjectConfig, modelSpec, projectModels, readProjectConfig, moduleConfigsOf, testDirOf, type ProjectConfig } from "./config.ts";
|
|
15
17
|
export { MODULES_DIR, projectDirOf, resolveTemplateDirs } from "./regenerate/paths.ts";
|
|
16
18
|
export { configSettings, currentValue, EFFECT_TEXT, overriddenBy, readConfigText, type Effect, type Setting, type SettingKind } from "./config-edit.ts";
|
|
17
19
|
export { bedrockRegionFor, type BedrockRegion, type BedrockRegionSource } from "./bedrock-region.ts";
|
package/dist/host.js
CHANGED
|
@@ -12,10 +12,10 @@ export { SENTINEL, SENTINEL_START } from "./notice.js";
|
|
|
12
12
|
/** pi itself, as turri is built against it: a host's own extensions and UI are made with this one, not another copy. */
|
|
13
13
|
export * as pi from "@earendil-works/pi-coding-agent";
|
|
14
14
|
// The project and its settings.
|
|
15
|
-
export { configForSpec, debugMode, DEFAULT_TEST_DIR, hasProjectConfig, modelSpec, projectModels, readProjectConfig,
|
|
15
|
+
export { configForSpec, debugMode, DEFAULT_TEST_DIR, hasProjectConfig, modelSpec, projectModels, readProjectConfig, moduleConfigsOf, testDirOf } from "./config.js";
|
|
16
16
|
export { MODULES_DIR, projectDirOf, resolveTemplateDirs } from "./regenerate/paths.js";
|
|
17
|
-
// Every setting of config.turri.yaml as /
|
|
18
|
-
// effect - and what the file has now: for a host that shows them all, changing each through /
|
|
17
|
+
// Every setting of config.turri.yaml as /settings knows it - what it takes, what it is unset, when a change takes
|
|
18
|
+
// effect - and what the file has now: for a host that shows them all, changing each through /settings.
|
|
19
19
|
export { configSettings, currentValue, EFFECT_TEXT, overriddenBy, readConfigText } from "./config-edit.js";
|
|
20
20
|
// The AWS region a project's Bedrock models are called in, and where it comes from - what turri sets itself, as a host's
|
|
21
21
|
// session starts, when the models need one and the person set none.
|
package/dist/identity.js
CHANGED
|
@@ -49,13 +49,13 @@ const IDENTITY_BEFORE = [
|
|
|
49
49
|
"they are talking to turri. What they should ask for, they ask you for, here.",
|
|
50
50
|
"",
|
|
51
51
|
"The person may have several chats with you open on this project at once, this one among them. What regenerates is",
|
|
52
|
-
"the same in every chat: the pulses and their plan, steering, the engine's coding model and what
|
|
52
|
+
"the same in every chat: the pulses and their plan, steering, the engine's coding model and what was launched -",
|
|
53
53
|
"pulses lists every pulse, whichever chat asked for it. What was said in another chat is not in this one: when the",
|
|
54
54
|
"person speaks of it, ask.",
|
|
55
55
|
"",
|
|
56
56
|
"Pulses regenerate in the background and never hold the conversation: while they run, you and the person go on -",
|
|
57
57
|
"shaping the ***plain and writing its next change, answering their questions, trying what has landed or was",
|
|
58
|
-
"
|
|
58
|
+
"launched. When a pulse starts, say so in a way that makes it plain they need not wait for it to finish; never tell",
|
|
59
59
|
"them to wait for one, and never stop to wait for one yourself. Changing the ***plain while a pulse runs is safe: a",
|
|
60
60
|
"change inside what the running pulse regenerates steers it, and the rest is planned again around it - the next",
|
|
61
61
|
"change never waits for the last to land.",
|
package/dist/init-config.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ export declare const DEFAULTS: {
|
|
|
111
111
|
readonly review: false;
|
|
112
112
|
readonly mutationTesting: true;
|
|
113
113
|
readonly allowToStopJobs: true;
|
|
114
|
-
readonly
|
|
114
|
+
readonly launchAfterPulse: true;
|
|
115
115
|
readonly sentinel: "ask";
|
|
116
116
|
readonly testingScriptsRunOn: "in-place";
|
|
117
117
|
readonly turnLimit: 120;
|
package/dist/init-config.js
CHANGED
|
@@ -227,7 +227,7 @@ export const DEFAULTS = {
|
|
|
227
227
|
review: false,
|
|
228
228
|
mutationTesting: true,
|
|
229
229
|
allowToStopJobs: true,
|
|
230
|
-
|
|
230
|
+
launchAfterPulse: true,
|
|
231
231
|
sentinel: "ask",
|
|
232
232
|
testingScriptsRunOn: "in-place",
|
|
233
233
|
turnLimit: 120,
|
|
@@ -270,11 +270,11 @@ export function quickStartConfig(vendor = "other", bedrock, models) {
|
|
|
270
270
|
"# Whether turri stops a running pulse the spec has moved on from. false: it lands, the change regenerated on top.",
|
|
271
271
|
`allow-to-stop-jobs: ${DEFAULTS.allowToStopJobs}`,
|
|
272
272
|
"",
|
|
273
|
-
"# Whether every pulse that lands code
|
|
274
|
-
`
|
|
273
|
+
"# Whether every pulse that lands code is launched, in the background, as the project's launch guidance says.",
|
|
274
|
+
`launch-after-pulse: ${DEFAULTS.launchAfterPulse}`,
|
|
275
275
|
"",
|
|
276
|
-
"# Whether a chat of its own, the sentinel, checks every pulse that finishes - and, with
|
|
277
|
-
"# was
|
|
276
|
+
"# Whether a chat of its own, the sentinel, checks every pulse that finishes - and, with launch-after-pulse, tests what",
|
|
277
|
+
"# was launched - and tells you in the chat you are in when something needs you. ask: you are asked, with what it does,",
|
|
278
278
|
"# before it first opens in a session; true: it opens without asking; false: none.",
|
|
279
279
|
`sentinel: ${DEFAULTS.sentinel}`,
|
|
280
280
|
"",
|
|
@@ -348,10 +348,10 @@ export function quickStartConfig(vendor = "other", bedrock, models) {
|
|
|
348
348
|
"# models:",
|
|
349
349
|
`# default: ${coding}`,
|
|
350
350
|
`${column(`# chat: ${harness}`, 72)}# the conversation - as harness-model, which it wins over`,
|
|
351
|
-
`${column(`# sentinel: ${harness}`, 72)}# the sentinel: checks every finished pulse and tests
|
|
351
|
+
`${column(`# sentinel: ${harness}`, 72)}# the sentinel: checks every finished pulse and tests what is launched`,
|
|
352
352
|
role("planner", harness, "cuts the work into pulses"),
|
|
353
353
|
role("diagnosis", harness, "looks into a pulse that failed for good"),
|
|
354
|
-
role("
|
|
354
|
+
role("launch", coding, "the launch agent: turri launch's, the chat's and launch-after-pulse's"),
|
|
355
355
|
`${column(`# coding: { model: ${coding}, thinking: ${ROLE_THINKING.coding}, turn-limit: 180 }`, 72)}# as coding-model, which it wins over`,
|
|
356
356
|
role("conformance", coding, "writes the conformance tests"),
|
|
357
357
|
role("explorer", coding, "explores the code for a conformance run"),
|
|
@@ -591,7 +591,7 @@ export async function initConfig(dir, options = {}) {
|
|
|
591
591
|
return { written: false, message: chosen.problem };
|
|
592
592
|
const { vendor, bedrock, models, given } = chosen;
|
|
593
593
|
const folder = resolve(dir);
|
|
594
|
-
// The old
|
|
594
|
+
// The modules' old files, config.<module>.yaml, copied to their new names; config.turri.yaml is written below.
|
|
595
595
|
adoptLegacyConfig(folder, { projectFile: false });
|
|
596
596
|
const path = join(folder, CONFIG_FILE);
|
|
597
597
|
const existing = existsSync(path) && options.force !== true;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { type ExportedCode } from "./regenerate/launch.ts";
|
|
3
|
+
import type { Launch, LaunchOutcome } from "./launch-track.ts";
|
|
4
|
+
/**
|
|
5
|
+
* The launch agent: every launch's - the chat's launch tool, a pulse that landed under `launch-after-pulse`, and
|
|
6
|
+
* `turri launch`. The harness has put the commit's code in dist/<module> already; the agent finds out how it runs - or
|
|
7
|
+
* the project's guidance for launching it, which it follows from the host codebase - installs what it needs, starts what
|
|
8
|
+
* keeps running with activate, and says how it went with submit_launch. It asks no one.
|
|
9
|
+
*/
|
|
10
|
+
type AnyTool = ToolDefinition<any, any, any>;
|
|
11
|
+
/**
|
|
12
|
+
* The person's own shell, in the host codebase: it installs what the launch needs into the project, and runs it. It
|
|
13
|
+
* changes nothing of the machine's - no toolchain installed, no system setting changed: a command that would is refused.
|
|
14
|
+
*/
|
|
15
|
+
export declare function launchShell(dir: string): AnyTool;
|
|
16
|
+
/**
|
|
17
|
+
* What the project says of itself, for the agent to find launch guidance in: its AGENTS.md and its skills
|
|
18
|
+
* (`.agents/skills`, `.pi/skills`, `.claude/skills`), where turri runs and in the host codebase - once each, whole.
|
|
19
|
+
*/
|
|
20
|
+
export declare function projectNotes(dirs: string[]): string[];
|
|
21
|
+
/**
|
|
22
|
+
* activate: start what keeps running - a backend, a frontend's dev server - owned by the harness: in its own process
|
|
23
|
+
* group, its output kept, stopped on the codebase's next launch, on /halt and when turri exits.
|
|
24
|
+
*/
|
|
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;
|
|
36
|
+
/** What the agent does once the code is in dist: find guidance and follow it from the host, or start it from dist. */
|
|
37
|
+
export declare function launchGuide(code: ExportedCode, hostDir: string): string;
|
|
38
|
+
export interface LaunchAgentInput {
|
|
39
|
+
launch: Launch;
|
|
40
|
+
/** Its code, exported to dist already. */
|
|
41
|
+
code: ExportedCode;
|
|
42
|
+
/** Where turri runs. */
|
|
43
|
+
cwd: string;
|
|
44
|
+
/** The agent's model: the coding model of the codebase. */
|
|
45
|
+
model?: string;
|
|
46
|
+
signal?: AbortSignal;
|
|
47
|
+
onDelta?: (delta: string) => void;
|
|
48
|
+
}
|
|
49
|
+
/** Run the launch agent to its end: how it went, as it submitted it - or, never submitted, its last words as a failure. */
|
|
50
|
+
export declare function runLaunchAgent(input: LaunchAgentInput): Promise<LaunchOutcome>;
|
|
51
|
+
export {};
|
|
@@ -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
|
+
}
|