@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.
Files changed (175) hide show
  1. package/README.md +7 -8
  2. package/dist/bedrock-region.js +3 -3
  3. package/dist/chat-idle.d.ts +2 -2
  4. package/dist/chat-idle.js +2 -2
  5. package/dist/chat-models.d.ts +1 -1
  6. package/dist/chat-models.js +1 -1
  7. package/dist/chat-scope.d.ts +1 -3
  8. package/dist/chat-skills.d.ts +1 -1
  9. package/dist/chat-skills.js +1 -1
  10. package/dist/chats.d.ts +44 -20
  11. package/dist/chats.js +125 -64
  12. package/dist/cli.js +12 -31
  13. package/dist/config-edit.d.ts +20 -8
  14. package/dist/config-edit.js +32 -26
  15. package/dist/config.d.ts +106 -78
  16. package/dist/config.js +267 -133
  17. package/dist/conform-cli.js +14 -3
  18. package/dist/conformance-switch.d.ts +13 -22
  19. package/dist/conformance-switch.js +37 -59
  20. package/dist/drift-cli.js +1 -1
  21. package/dist/extension.d.ts +17 -10
  22. package/dist/extension.js +435 -532
  23. package/dist/genome.js +10 -49
  24. package/dist/graph.js +3 -5
  25. package/dist/host-session.d.ts +11 -21
  26. package/dist/host-session.js +6 -8
  27. package/dist/host.d.ts +4 -4
  28. package/dist/host.js +4 -7
  29. package/dist/identity.js +2 -3
  30. package/dist/init-config.d.ts +1 -2
  31. package/dist/init-config.js +10 -17
  32. package/dist/installed-providers.d.ts +1 -1
  33. package/dist/installed-providers.js +1 -1
  34. package/dist/launch-agent.d.ts +51 -0
  35. package/dist/launch-agent.js +267 -0
  36. package/dist/{release-cli.js → launch-cli.js} +41 -24
  37. package/dist/launch-session.d.ts +68 -0
  38. package/dist/launch-session.js +217 -0
  39. package/dist/launch-tools.d.ts +28 -0
  40. package/dist/launch-tools.js +69 -0
  41. package/dist/launch-track.d.ts +125 -0
  42. package/dist/launch-track.js +320 -0
  43. package/dist/loop-cli.d.ts +4 -3
  44. package/dist/loop-cli.js +17 -15
  45. package/dist/loop-tools.d.ts +45 -21
  46. package/dist/loop-tools.js +155 -90
  47. package/dist/new-project.js +2 -2
  48. package/dist/notice.d.ts +7 -6
  49. package/dist/parse-cli.js +2 -2
  50. package/dist/pi-launch.js +4 -1
  51. package/dist/pi-settings.d.ts +4 -0
  52. package/dist/pi-settings.js +39 -0
  53. package/dist/pi.js +12 -9
  54. package/dist/plain/check.d.ts +2 -9
  55. package/dist/plain/check.js +6 -39
  56. package/dist/plain-files.d.ts +2 -2
  57. package/dist/plain-files.js +7 -7
  58. package/dist/regenerate/activity.d.ts +0 -7
  59. package/dist/regenerate/activity.js +2 -20
  60. package/dist/regenerate/agent-env.d.ts +1 -1
  61. package/dist/regenerate/agent-env.js +3 -3
  62. package/dist/regenerate/agent-shell.js +5 -3
  63. package/dist/regenerate/audit.js +9 -0
  64. package/dist/regenerate/base-folder.d.ts +2 -2
  65. package/dist/regenerate/base-folder.js +1 -1
  66. package/dist/regenerate/cases.js +7 -0
  67. package/dist/regenerate/chunk-plan.d.ts +5 -0
  68. package/dist/regenerate/chunk-plan.js +16 -1
  69. package/dist/regenerate/command-check.d.ts +7 -1
  70. package/dist/regenerate/command-check.js +43 -1
  71. package/dist/regenerate/delivery.d.ts +1 -1
  72. package/dist/regenerate/delivery.js +3 -3
  73. package/dist/regenerate/drift.d.ts +4 -0
  74. package/dist/regenerate/drift.js +26 -6
  75. package/dist/regenerate/failure-reports.d.ts +28 -0
  76. package/dist/regenerate/failure-reports.js +79 -0
  77. package/dist/regenerate/job-panel.js +3 -1
  78. package/dist/regenerate/jobs-tree.js +1 -1
  79. package/dist/regenerate/jobs.d.ts +4 -2
  80. package/dist/regenerate/jobs.js +14 -10
  81. package/dist/regenerate/launch.d.ts +154 -0
  82. package/dist/regenerate/{release.js → launch.js} +195 -51
  83. package/dist/regenerate/ledger-view.d.ts +11 -24
  84. package/dist/regenerate/ledger-view.js +14 -60
  85. package/dist/regenerate/ledger.d.ts +34 -16
  86. package/dist/regenerate/ledger.js +1 -1
  87. package/dist/regenerate/lineage.d.ts +2 -0
  88. package/dist/regenerate/lineage.js +8 -0
  89. package/dist/regenerate/loop.d.ts +54 -67
  90. package/dist/regenerate/loop.js +312 -148
  91. package/dist/regenerate/model-names.d.ts +33 -0
  92. package/dist/regenerate/{engine.js → model-names.js} +2 -28
  93. package/dist/regenerate/paths.d.ts +3 -3
  94. package/dist/regenerate/paths.js +4 -4
  95. package/dist/regenerate/records.d.ts +11 -0
  96. package/dist/regenerate/records.js +15 -0
  97. package/dist/regenerate/regenerate.d.ts +0 -2
  98. package/dist/regenerate/regenerate.js +4 -15
  99. package/dist/regenerate/renames.js +4 -4
  100. package/dist/regenerate/requires.d.ts +7 -0
  101. package/dist/regenerate/requires.js +24 -18
  102. package/dist/regenerate/scripts-being-written.d.ts +4 -4
  103. package/dist/regenerate/scripts-being-written.js +3 -3
  104. package/dist/regenerate/spec-map.js +3 -3
  105. package/dist/regenerate/standing.js +1 -1
  106. package/dist/regenerate/submit-work.d.ts +2 -0
  107. package/dist/regenerate/submit-work.js +8 -3
  108. package/dist/regenerate/test-scripts.d.ts +2 -1
  109. package/dist/regenerate/test-scripts.js +33 -23
  110. package/dist/regenerate/testing-steps.d.ts +16 -5
  111. package/dist/regenerate/testing-steps.js +28 -9
  112. package/dist/regenerate-cli.js +18 -9
  113. package/dist/self-invocation.d.ts +11 -0
  114. package/dist/self-invocation.js +36 -10
  115. package/dist/sentinel-check.d.ts +3 -3
  116. package/dist/sentinel-check.js +3 -3
  117. package/dist/sentinel.d.ts +18 -12
  118. package/dist/sentinel.js +75 -46
  119. package/dist/{config-command.d.ts → settings.d.ts} +13 -8
  120. package/dist/{config-command.js → settings.js} +155 -24
  121. package/dist/setup.d.ts +2 -2
  122. package/dist/setup.js +7 -7
  123. package/dist/skill.d.ts +0 -11
  124. package/dist/skill.js +0 -9
  125. package/dist/tools.js +2 -3
  126. package/dist/turri-versions.js +2 -1
  127. package/docs/README.md +4 -6
  128. package/docs/authoring-plain.md +3 -3
  129. package/docs/chats.md +6 -9
  130. package/docs/claude-subscription.md +2 -2
  131. package/docs/config.md +61 -51
  132. package/docs/development.md +4 -5
  133. package/docs/headless.md +7 -6
  134. package/docs/hosting.md +25 -24
  135. package/docs/launch.md +67 -0
  136. package/docs/parser.md +3 -3
  137. package/docs/regenerating.md +30 -22
  138. package/docs/sandbox.md +3 -3
  139. package/docs/sentinel.md +28 -16
  140. package/docs/skills-and-gates.md +6 -11
  141. package/docs/using.md +25 -42
  142. package/genome/rules/project-model.md +2 -1
  143. package/genome/rules/test-plain-files.md +15 -7
  144. package/genome/rules/turri-regeneration.md +7 -10
  145. package/genome/skills/convert-old-syntax/SKILL.md +5 -5
  146. package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
  147. package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
  148. package/package.json +1 -1
  149. package/dist/advisor-chat.d.ts +0 -63
  150. package/dist/advisor-chat.js +0 -290
  151. package/dist/change-plain-cli.js +0 -55
  152. package/dist/ledger-cli.d.ts +0 -1
  153. package/dist/ledger-cli.js +0 -50
  154. package/dist/ledger-tools.d.ts +0 -10
  155. package/dist/ledger-tools.js +0 -64
  156. package/dist/regenerate/advisor-records.d.ts +0 -93
  157. package/dist/regenerate/advisor-records.js +0 -110
  158. package/dist/regenerate/advisor-runs.d.ts +0 -87
  159. package/dist/regenerate/advisor-runs.js +0 -327
  160. package/dist/regenerate/engine.d.ts +0 -52
  161. package/dist/regenerate/release.d.ts +0 -121
  162. package/dist/regenerate/test-advisor.d.ts +0 -101
  163. package/dist/regenerate/test-advisor.js +0 -379
  164. package/dist/release-agent.d.ts +0 -43
  165. package/dist/release-agent.js +0 -130
  166. package/dist/release-cli.d.ts +0 -1
  167. package/dist/release-tools.d.ts +0 -44
  168. package/dist/release-tools.js +0 -170
  169. package/dist/spec-tools.d.ts +0 -36
  170. package/dist/spec-tools.js +0 -128
  171. package/dist/stacks.d.ts +0 -13
  172. package/dist/stacks.js +0 -96
  173. package/docs/deploy.md +0 -48
  174. package/docs/test-advisor.md +0 -110
  175. /package/dist/{change-plain-cli.d.ts → launch-cli.d.ts} +0 -0
@@ -1,130 +0,0 @@
1
- import { existsSync, readdirSync, readFileSync } from "node:fs";
2
- import { join, relative, resolve, sep } from "node:path";
3
- import { createBashToolDefinition, createEditToolDefinition, createFindToolDefinition, createGrepToolDefinition, createLsToolDefinition, createReadToolDefinition, createWriteToolDefinition, } from "@earendil-works/pi-coding-agent";
4
- import { createDeployTools, DEPLOY_TOOLS } from "./release-tools.js";
5
- import { hostDirOf, shortPath } from "./regenerate/release.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 deployed folder: it installs what the release 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 releaseShell(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 spec's to change, never a release'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 release never changes it - a fix belongs in the spec.`);
34
- }
35
- // The ***plain - a module, a test plain file - is the person's: a release 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 release 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 release 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
- /** Run the release agent to its end; its last reply. */
72
- export async function runReleaseAgent(input) {
73
- const { plainFile } = input;
74
- const tools = createDeployTools({ cwd: input.cwd, state: input.state, defaultPlainFile: () => plainFile });
75
- // It releases from the host codebase, which holds dist too.
76
- const dir = hostDirOf(plainFile, input.cwd);
77
- const notes = projectNotes([input.cwd, dir, projectDirOf(plainFile)]);
78
- const said = input.guidance ?? input.state.guidance.get(input.afterPulse?.moduleName ?? "");
79
- const fileTools = [
80
- createReadToolDefinition(dir),
81
- createLsToolDefinition(dir),
82
- createGrepToolDefinition(dir),
83
- createFindToolDefinition(dir),
84
- // A guided release may say to change the host - a registration, an import.
85
- outsideBuiltCode(createEditToolDefinition(dir), dir),
86
- outsideBuiltCode(createWriteToolDefinition(dir), dir),
87
- ];
88
- const executor = await createExecutor({
89
- // Its sessions are kept in the project, not in the folder it deploys.
90
- cwd: projectDirOf(plainFile),
91
- customTools: [...fileTools, releaseShell(dir), ...tools],
92
- tools: [...fileTools.map((tool) => tool.name), "bash", ...DEPLOY_TOOLS],
93
- ...(input.model !== undefined ? { model: input.model } : {}),
94
- role: "release",
95
- system: [
96
- "You get software that was just built running on the person's own machine, so they can try it. You ask no one: do it.",
97
- `Your file tools and your shell start in ${dir}. Your shell is the person's own - not a sandbox.`,
98
- ].join("\n"),
99
- task: [
100
- input.afterPulse !== undefined
101
- ? `A pulse of module ${input.afterPulse.moduleName} just landed: ${input.afterPulse.subject}. Release it now, before the module's next pulse starts: the project releases after every pulse.`
102
- : input.forCheck !== undefined
103
- ? `The person asked turri's sentinel to check functional specs of module ${input.forCheck.moduleName} in its release, and what runs of it is not its last commit. Release its last commit now, for the sentinel to test.`
104
- : `Release ${shortPath(plainFile)} for the person to try, with the release tool, then do what it says.`,
105
- "",
106
- "First ask yourself: is there guidance for how this project releases it - what the person said below, the project's",
107
- "notes and skills below, or anything else you find? If there is, call release with it as guidance, in full: the code is",
108
- "put in dist/<module>, and the guidance takes it on from there. If there is none, call release without guidance: the",
109
- "code is put in dist/<module> and started from there, as best it can be.",
110
- ...(input.afterPulse !== undefined || input.forCheck !== undefined
111
- ? [
112
- "",
113
- `Release it whether or not the guidance speaks of releasing ${input.afterPulse !== undefined ? "after a build - the project's setting has said to" : "for a check - the person asked for it"}. What`,
114
- "the guidance says is how. When release says it is already released, leave it at that.",
115
- ]
116
- : []),
117
- ...(input.inModule !== undefined ? ["", `Release the codebase of module ${input.inModule}: pass in_module.`] : []),
118
- ...(said !== undefined ? ["", "What the person said of how to release it:", said] : []),
119
- ...(notes.length > 0 ? ["", "The project's notes and skills:", ...notes] : []),
120
- "",
121
- "End with what you did, in a line or two: where it runs, or why nothing was released.",
122
- ].join("\n"),
123
- });
124
- try {
125
- return await ask(executor, BEGIN, input.onDelta);
126
- }
127
- finally {
128
- executor.dispose();
129
- }
130
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,44 +0,0 @@
1
- import { type Deployment } from "./regenerate/release.ts";
2
- import type { JobRegistry } from "./regenerate/jobs.ts";
3
- import type { WorkLoop } from "./regenerate/loop.ts";
4
- /**
5
- * The tools that put a module out for the person to try, and start it: the conversation's, and the
6
- * one-off agent's of `turri release`. The harness does the parts that must hold - exporting the
7
- * last commit, owning what it starts - and the agent the rest: reading the code to see how it runs,
8
- * installing what it needs, starting it, and telling the person where to find it. Nothing is put to
9
- * the person: a release does everything itself.
10
- */
11
- export interface DeployState {
12
- /** The last deploy: where what is started runs from. */
13
- current?: Deployment;
14
- /** The last release of each module in this conversation, by module: the commit it shipped. */
15
- released: Map<string, Deployment>;
16
- /** The guidance each module was last released with, by module: what a release after a pulse is told the person said. */
17
- guidance: Map<string, string>;
18
- }
19
- export declare function createDeployState(): DeployState;
20
- /**
21
- * A module's release as it stands, when it is current: its own codebase's last commit is what the last release shipped,
22
- * and nothing that release started has ended. Undefined when it is behind, was never made, or what it started died -
23
- * then it is released again.
24
- */
25
- export declare function currentRelease(state: DeployState, plainFile: string, moduleName: string): Deployment | undefined;
26
- /** What the agent is to do once the code is in dist - in the deploy tool's answer, and the CLI agent's prompt. */
27
- export declare function deployGuide(dir: string): string;
28
- /**
29
- * What the agent is to do on a guided release: the code is in dist, as on any release, and the guidance takes it on from
30
- * there. The rules of a release to dist hold here too: what keeps running started with activate, and the built code never
31
- * edited - and nothing put to the person.
32
- */
33
- export declare function guidedGuide(deployment: Deployment, guidance: string): string;
34
- export declare function createDeployTools(options: {
35
- cwd: string;
36
- state: DeployState;
37
- /** The spec deploy takes when it is given none: the project's module. */
38
- defaultPlainFile: () => string | undefined;
39
- /** The pulses halt stops as well - the conversation's. */
40
- jobs?: JobRegistry;
41
- /** The work loop whose modules halt halts by a planned row or a name - the conversation's, once it has one. */
42
- workLoop?: () => WorkLoop | undefined;
43
- }): import("@earendil-works/pi-coding-agent").ToolDefinition<any, any, any>[];
44
- export declare const DEPLOY_TOOLS: string[];
@@ -1,170 +0,0 @@
1
- import { isAbsolute, relative, resolve } from "node:path";
2
- import { refuseTestPlainFile } from "./test-plain-files.js";
3
- import { defineTool } from "@earendil-works/pi-coding-agent";
4
- import { Type } from "typebox";
5
- import { deployLogDir, deployTarget, describeDeployment, exportModule, hostDirOf, listDeployed, shortPath, startDeployed, stopDeployed, } from "./regenerate/release.js";
6
- import { projectDirOf } from "./regenerate/paths.js";
7
- import { haltTool } from "./loop-tools.js";
8
- export function createDeployState() {
9
- return { released: new Map(), guidance: new Map() };
10
- }
11
- /**
12
- * A module's release as it stands, when it is current: its own codebase's last commit is what the last release shipped,
13
- * and nothing that release started has ended. Undefined when it is behind, was never made, or what it started died -
14
- * then it is released again.
15
- */
16
- export function currentRelease(state, plainFile, moduleName) {
17
- let target;
18
- try {
19
- target = deployTarget(plainFile, moduleName);
20
- }
21
- catch {
22
- return undefined;
23
- }
24
- const last = state.released.get(moduleName);
25
- if (target.entry.moduleName !== moduleName || last === undefined || !target.commit.startsWith(last.commit))
26
- return undefined;
27
- const started = listDeployed().filter((item) => item.moduleName === moduleName && (last.at === undefined || item.startedAt >= last.at));
28
- return started.some((item) => item.exited !== undefined) ? undefined : last;
29
- }
30
- /** What the agent is to do once the code is in dist - in the deploy tool's answer, and the CLI agent's prompt. */
31
- export function deployGuide(dir) {
32
- const where = shortPath(dir);
33
- return [
34
- `What to do now, to have the person try it - it runs on this machine, outside the sandbox, from ${where}:`,
35
- `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 ${where}.`,
36
- "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 tell the person exactly what to install, the command they run themselves (`brew install node`), and that releasing again picks it up.",
37
- "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 the person: do it, and fix what fails - within the project: never a global install, never a system setting.",
38
- "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.",
39
- "5. Then tell the person, briefly. Something that serves: only where to open it - the frontend's URL, and the API's in one line when there is one. A CLI or a library: a few commands to paste, run from the folder, with what they print. A port that is taken: say which and by what, and do not move the app to another.",
40
- `Do not change the code in ${where} - it is a copy of what was built, and a fix belongs in the spec. A config file it needs made from its example (a .env from .env.example) is fine.`,
41
- ].join("\n");
42
- }
43
- /**
44
- * What the agent is to do on a guided release: the code is in dist, as on any release, and the guidance takes it on from
45
- * there. The rules of a release to dist hold here too: what keeps running started with activate, and the built code never
46
- * edited - and nothing put to the person.
47
- */
48
- export function guidedGuide(deployment, guidance) {
49
- const host = shortPath(deployment.hostDir ?? deployment.dir);
50
- const dist = shortPath(deployment.dir);
51
- const built = shortPath(deployment.buildDir);
52
- return [
53
- "The guidance for releasing it - follow it:",
54
- guidance.trim(),
55
- "",
56
- `What to do now - on this machine, outside the sandbox, from ${host}:`,
57
- `1. The code to release is in ${dist}: the last commit that landed whole. Take it from there, never from ${built}, where a pulse may be writing. 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.`,
58
- `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. Never change ${built} or ${dist}: a fix to the code belongs in the spec.`,
59
- "3. Run the project's scripts and install what it needs into the project yourself, in your shell. Do not ask the person: do it, and fix what fails. A toolchain or system tool the machine lacks you never install, nor change a setting of the machine's: tell the person the command they run themselves.",
60
- "4. Start what keeps running - a start script, a dev server - with activate, with the URL it serves at - never in the shell with & or nohup.",
61
- `5. Then tell the person briefly: what was done, what you changed in ${host} if anything, and where to open it or how to try it. Where the guidance does not fit what you find, say so, and do not guess past it.`,
62
- ].join("\n");
63
- }
64
- function text(value, details = {}) {
65
- return { content: [{ type: "text", text: value }], details };
66
- }
67
- /** The folder a command runs in: dist's, or - guided - the host codebase's, or one inside either. */
68
- function inside(current, dir) {
69
- const base = current.hostDir ?? current.dir;
70
- const target = resolve(base, dir ?? ".");
71
- const within = (root) => {
72
- const rel = relative(root, target);
73
- return !rel.startsWith("..") && !isAbsolute(rel);
74
- };
75
- if (!within(base) && !within(current.dir))
76
- throw new Error(`${dir} is outside ${shortPath(base)}: what release starts runs from there.`);
77
- return target;
78
- }
79
- export function createDeployTools(options) {
80
- const { state } = options;
81
- const needsDeploy = () => {
82
- if (state.current === undefined)
83
- throw new Error("Nothing is released yet: call release first.");
84
- return state.current;
85
- };
86
- const deploy = defineTool({
87
- name: "release",
88
- label: "Release",
89
- description: "Release a module's code for the person to try - the module on top of the spec's requires chain, which holds the " +
90
- "code of the ones below - stopping whatever an earlier release of it started. Before you call it, ask yourself: is " +
91
- "there guidance for releasing this project - in what the person said, the project's AGENTS.md, a skill, or anything " +
92
- "else you were given? An integration a host application loads, say, released with the host's own scripts. If there " +
93
- "is, pass it as guidance, in full. Either way its last commit - what last landed whole - is exported to dist/<module> " +
94
- "first; with guidance it is taken on from there as the guidance says, in the host codebase; without, it is started " +
95
- "from there, as best it can be. Call it when the " +
96
- "person wants to try, run, see or use what was built, and whenever guidance says to release after a pulse: when " +
97
- "the module's last commit is already released it does nothing and says so, so never decide that yourself. It says " +
98
- "what to do next.",
99
- promptSnippet: "release the regenerated code for the person to try - as the project's release guidance says, or to dist/<module> - then activate it",
100
- parameters: Type.Object({
101
- plain_file: Type.Optional(Type.String({ description: "A .plain file of the module. Default: the project's module from config.turri.yaml." })),
102
- in_module: Type.Optional(Type.String({ description: "The codebase to take, when modules built on this one branch" })),
103
- again: Type.Optional(Type.Boolean({ description: "Release even when the module's last commit is already released - only when what the last release said to do was not done." })),
104
- guidance: Type.Optional(Type.String({ description: "The guidance for releasing this project, whole, from wherever it is - the person, AGENTS.md, a skill: the scripts to run and in which order, where the code goes. Omit when there is none." })),
105
- }),
106
- async execute(_id, params) {
107
- const named = params.plain_file ?? options.defaultPlainFile();
108
- if (named === undefined)
109
- throw new Error("Which spec? config.turri.yaml names no module: pass plain_file.");
110
- const plainFile = resolve(options.cwd, named);
111
- refuseTestPlainFile(plainFile);
112
- const target = deployTarget(plainFile, params.in_module);
113
- const guidance = params.guidance?.trim() || undefined;
114
- // Released already: the module's last commit is what the last release shipped. Nothing is exported or stopped -
115
- // releasing it again would only restart what runs - so it is safe to call after every pulse.
116
- const last = state.released.get(target.entry.moduleName);
117
- if (last !== undefined && !params.again && target.commit.startsWith(last.commit) && last.way === (guidance === undefined ? "dist" : "guided")) {
118
- state.current = last;
119
- return text(`Already released: ${target.entry.moduleName}'s last commit, ${last.commit} (${last.subject}), is what the last release shipped, and what that release said to do was done then. Nothing to do - what runs is left running. Say so in a line.`, { module: last.moduleName, commit: last.commit, already: true });
120
- }
121
- // What the last release started runs from what is about to be replaced.
122
- const stopped = await stopDeployed({ moduleName: target.entry.moduleName });
123
- // Always the last commit, clean, in dist first; guidance takes it on from there.
124
- const exported = exportModule(plainFile, params.in_module);
125
- const deployment = guidance === undefined ? exported : { ...exported, way: "guided", hostDir: hostDirOf(plainFile, options.cwd) };
126
- state.current = deployment;
127
- state.released.set(deployment.moduleName, { ...deployment, at: Date.now() });
128
- if (guidance !== undefined)
129
- state.guidance.set(deployment.moduleName, guidance);
130
- return text([
131
- describeDeployment(deployment),
132
- ...(stopped.length > 0 ? [`Stopped what the last release started: ${stopped.join(", ")}.`] : []),
133
- "",
134
- guidance === undefined ? deployGuide(deployment.dir) : guidedGuide(deployment, guidance),
135
- ].join("\n"), { module: deployment.moduleName, way: deployment.way, dir: deployment.dir, ...(deployment.hostDir !== undefined ? { host: deployment.hostDir } : {}), commit: deployment.commit });
136
- },
137
- });
138
- const startTool = defineTool({
139
- name: "activate",
140
- label: "Activate",
141
- description: "Start something that keeps running - a backend, a frontend's dev server - from the deployed folder, on this " +
142
- "machine: in the background, its output kept, stopped on the next release, on /halt and when turri exits. " +
143
- "With `url`, waits until something answers there and says so, or shows the end of its output. A port something " +
144
- "else holds is said, and nothing is started.",
145
- promptSnippet: "start a server of the deployed code, and wait for it to answer",
146
- parameters: Type.Object({
147
- name: Type.String({ description: "A short name for it: backend, frontend, app" }),
148
- command: Type.String({ description: "The command that starts it, as run from its folder" }),
149
- url: Type.Optional(Type.String({ description: "Where it serves, e.g. http://localhost:5173 - it is ready once this answers" })),
150
- dir: Type.Optional(Type.String({ description: "The folder to run it in, relative to the deployed folder - e.g. frontend - never the project's path to the deployed folder (dist/<module>). Default: the deployed folder itself." })),
151
- }),
152
- async execute(_id, params) {
153
- const current = needsDeploy();
154
- const started = await startDeployed({
155
- name: params.name,
156
- command: params.command,
157
- dir: inside(current, params.dir),
158
- root: current.hostDir ?? current.dir,
159
- moduleName: current.moduleName,
160
- logDir: deployLogDir(projectDirOf(current.plainFile)),
161
- ...(params.url !== undefined ? { url: params.url } : {}),
162
- });
163
- return text(started.text, { ok: started.ok, ...(started.process !== undefined ? { pid: started.process.pid, log: started.process.log } : {}) });
164
- },
165
- });
166
- // The one halt: with the pulses in the conversation, and without them for the release agent.
167
- const stopTool = haltTool(options.jobs !== undefined ? { jobs: options.jobs, ...(options.workLoop !== undefined ? { workLoop: options.workLoop } : {}) } : {});
168
- return [deploy, startTool, stopTool];
169
- }
170
- export const DEPLOY_TOOLS = ["release", "activate", "halt"];
@@ -1,36 +0,0 @@
1
- import { type ToolDefinition } from "@earendil-works/pi-coding-agent";
2
- import { type WorkLoop } from "./regenerate/loop.ts";
3
- import { type LiveReviewer } from "./tools.ts";
4
- /** Whether a question has been answered since the last new spec change was written. */
5
- export interface SpecPace {
6
- /** A question was answered; `owesChange` false for one no change comes from - a phase's confirmation, a dismissal. */
7
- answered(owesChange?: boolean): void;
8
- /** Whether an answer has come since the last change, and is not written yet. */
9
- owed(): boolean;
10
- }
11
- type AnyTool = ToolDefinition<any, any, any>;
12
- /**
13
- * Writing a spec change as a diff, and building it, as one step.
14
- *
15
- * In an interview whose unit of work is a spec change, every change is meant to be built the
16
- * moment it is written. Left to two tool calls - change the file, then start the render - the
17
- * second is the one that gets forgotten, and nothing notices. So the diff is applied and its
18
- * build queued in the same call: a change cannot reach the specs without its render being
19
- * started. A new change needs an answer since the last one; a correction does not.
20
- */
21
- export declare function createSpecDiffTools(options: {
22
- loop: WorkLoop;
23
- cwd: string;
24
- liveReview?: LiveReviewer;
25
- /** One new change per answer (the default); false, for a skill that writes the specs on its own. */
26
- paced?: boolean;
27
- /**
28
- * Whether the phase the interview is in lets a change come without an answer before it: one where each answer owes a
29
- * change instead (`owed`, refused a next question until it is written), and the agent writes what it decides itself.
30
- */
31
- free?: () => boolean;
32
- }): {
33
- tools: AnyTool[];
34
- pace: SpecPace;
35
- };
36
- export {};
@@ -1,128 +0,0 @@
1
- import { resolve } from "node:path";
2
- import { defineTool } from "@earendil-works/pi-coding-agent";
3
- import { Type } from "typebox";
4
- import { advisingNote } from "./advisor-chat.js";
5
- import { checkTouchedPlain, formatCheckResults } from "./plain/check.js";
6
- import { applySpecDiff, plainFilesOf, revertSpecDiff } from "./regenerate/regenerate.js";
7
- import { refuseTestPlainFile } from "./test-plain-files.js";
8
- import { describeModules } from "./regenerate/loop.js";
9
- import { reviewNote } from "./tools.js";
10
- import { STACK_PARAM, stacklessBuild, withCallStack } from "./loop-tools.js";
11
- import { stackNamed } from "./config.js";
12
- import { projectDirOf } from "./regenerate/paths.js";
13
- /**
14
- * Writing a spec change as a diff, and building it, as one step.
15
- *
16
- * In an interview whose unit of work is a spec change, every change is meant to be built the
17
- * moment it is written. Left to two tool calls - change the file, then start the render - the
18
- * second is the one that gets forgotten, and nothing notices. So the diff is applied and its
19
- * build queued in the same call: a change cannot reach the specs without its render being
20
- * started. A new change needs an answer since the last one; a correction does not.
21
- */
22
- export function createSpecDiffTools(options) {
23
- const { loop, cwd, liveReview } = options;
24
- const skillPaced = options.paced !== false;
25
- const isPaced = () => skillPaced && options.free?.() !== true;
26
- /** An answer has come since the last change: it is owed one. */
27
- let owed = false;
28
- let answeredSinceLastDiff = true;
29
- const writeDiff = defineTool({
30
- name: "change_plain",
31
- label: "Write spec diff",
32
- description: "Apply a change to the ***plain specs, given as a git diff of the .plain files, and start building it in " +
33
- "the background. The diff is applied with git; if the specs no longer parse, it is undone and nothing is " +
34
- "built. Any section may change - definitions, implementation reqs, functional specs, added, changed or removed - and " +
35
- "every change is built, whatever it touches. A diff may touch test plain files too - tests/<module>/<func-id>.plain, " +
36
- "a functional spec's conformance and acceptance scenarios. A functional spec with none has no test plain file: " +
37
- "write one only to give it scenarios.",
38
- promptSnippet: "apply a git diff of the .plain specs and start building it",
39
- promptGuidelines: [
40
- "Every change to a .plain file in the product phase goes through change_plain, as a git diff with paths relative to the project root. It writes the change and starts its build in one step.",
41
- "A functional spec is a `# <func-id>` heading and its text. One with scenarios has a test plain file, tests/<module>/<func-id>.plain: its `module:` and `func_id:`, then `***conformance tests***` and `***acceptance tests***`, each scenario a `# <scenario-id>` heading and its text - a section only when it has a scenario, an empty one being a syntax error. One with no scenarios has no test plain file. plain_file stays the module's .plain file when the diff touches only its test plain files.",
42
- skillPaced
43
- ? "One change per answer, and a new one only after the user has answered a question about it. Set fixes_earlier to correct something already written."
44
- : "Write the changes one after another, on your own: no answer is needed between them, and none is asked for. Set fixes_earlier to correct something already written.",
45
- "In a project of stacks, the change is built with the stack named after the module - backend.plain with config.turri.backend.yaml - by itself. For a module whose stack has another name, pass it as stack. A change that cannot be built yet for want of a stack is written all the same: carry on, and pass the stack with the next change.",
46
- "To take something out of what is already written and queued - the user drops a page or a feature - write the diff that removes it from every spec that names it, with fixes_earlier. What is left to build is worked out from the spec each time, and a build the change undoes is stopped by itself; never stop builds to drop a change - it stays in the files.",
47
- ],
48
- parameters: Type.Object({
49
- plain_file: Type.String({ description: "The .plain file of the module the change is built for" }),
50
- diff: Type.String({ description: "The change, as a git diff (diff --git a/<file> b/<file> ...)" }),
51
- fixes_earlier: Type.Optional(Type.Boolean({ description: "This corrects something already written - a contradiction, a review finding" })),
52
- stack: STACK_PARAM,
53
- guidance: Type.Optional(Type.String({
54
- description: "How to plan the queue for this change, in a sentence or two - which functional specs go together, what first - as the " +
55
- "user said it or as the interview settled it. A strong preference for the planner. Omit when there is none.",
56
- })),
57
- }),
58
- async execute(_id, params) {
59
- const paced = isPaced();
60
- if (paced && params.fixes_earlier !== true && !answeredSinceLastDiff) {
61
- throw new Error("No question has been answered since the last spec change. Each change comes from its own answer: ask " +
62
- "the user with ask_user first. To correct something already written, set fixes_earlier.");
63
- }
64
- const touched = plainFilesOf(params.diff);
65
- if (touched.length === 0)
66
- throw new Error("The diff changes no .plain file. Nothing was written.");
67
- refuseTestPlainFile(resolve(cwd, params.plain_file));
68
- const result = applySpecDiff(params.diff, cwd);
69
- // A change that breaks a spec is not written at all, so nothing is ever built from a file that cannot be parsed:
70
- // each module it touched is parsed with its test plain files - an import module as the modules that import it
71
- // read it, a test plain file as its module - as parse reads them. A module with no functional specs yet is
72
- // not broken.
73
- const failed = checkTouchedPlain([params.plain_file, ...touched].map((file) => resolve(cwd, file))).filter((check) => !check.ok);
74
- if (failed.length > 0) {
75
- if (result === "applied")
76
- revertSpecDiff(params.diff, cwd);
77
- throw new Error(`Nothing was written: with this change the ***plain no longer checks.\n${formatCheckResults(failed)}`);
78
- }
79
- if (params.fixes_earlier !== true)
80
- answeredSinceLastDiff = false;
81
- owed = false;
82
- liveReview?.notice(`${params.plain_file}, after the change to ${touched.join(", ")}`);
83
- // In the files, the change is work: the loop works out what is left to build and plans it - with the stack the call
84
- // names, else the module's own. A spec change, not a request: a module the person halted stays halted. The change
85
- // is written whatever the stack: one that cannot be built yet is said, and built once it can - nothing is lost.
86
- const building = resolve(cwd, params.plain_file);
87
- let stackless;
88
- try {
89
- stackless = params.stack === undefined ? stacklessBuild(building) : (stackNamed(projectDirOf(building), params.stack), undefined);
90
- }
91
- catch (error) {
92
- stackless = error instanceof Error ? error.message : String(error);
93
- }
94
- const statuses = stackless === undefined
95
- ? await withCallStack(building, params.stack, () => loop.bringUp(params.plain_file, { specChange: true, ...(params.guidance !== undefined ? { guidance: params.guidance } : {}) }))
96
- : [];
97
- const lines = [
98
- result === "applied" ? `Applied the change to ${touched.join(", ")}.` : `The change to ${touched.join(", ")} was already applied.`,
99
- stackless === undefined
100
- ? `Building in the background:\n${describeModules(statuses)}\n`
101
- : `Not built yet - ${stackless} The change is in the spec: pass stack with the next change, or call regenerate with it, and everything written so far is built.\n`,
102
- // An interview goes back to its questions; a skill that writes on its own, straight to its next change - a stop to ask ends it.
103
- paced
104
- ? "Carry on with the interview."
105
- : skillPaced
106
- ? "Carry on: write the next change you decided yourself, or ask the next question - every answer is written as a change before the question after it."
107
- : "Write the next change now, without stopping to ask: this skill goes on until everything it is to write is written.",
108
- ];
109
- // The functional specs the test advisor took up, for the agent to say so rather than offer their scenarios.
110
- const advising = advisingNote(loop, building);
111
- return {
112
- content: [{ type: "text", text: lines.join(" ") + reviewNote(liveReview) + (advising !== "" ? `\n\n${advising}` : "") }],
113
- details: { jobIds: statuses.flatMap((status) => (status.running !== undefined ? [status.running.jobId] : [])), files: touched },
114
- };
115
- },
116
- });
117
- return {
118
- tools: [writeDiff],
119
- pace: {
120
- answered(owesChange = true) {
121
- answeredSinceLastDiff = true;
122
- if (owesChange)
123
- owed = true;
124
- },
125
- owed: () => owed,
126
- },
127
- };
128
- }
package/dist/stacks.d.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * Choosing a stack: `config.turri.<stack>.yaml` laid over `config.turri.yaml` for everything built from then on - a
3
- * backend's testing scripts, then a frontend's. `/stack` and the `stack` tool in the chat, `--stack <name>` on the
4
- * command line (cli.ts). The choice itself is kept in config.ts (`chooseStack`): in the chat it is made in, for that chat
5
- * alone (chat-scope.ts), each new chat starting from `--stack`.
6
- */
7
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
8
- /** The stacks of the projects here: the folder's own, and those of the projects one folder down (specs kept in plain/). */
9
- export declare function knownStacks(root: string): string[];
10
- /** Choose `name` - or none - among the stacks here, and say what is chosen now; a stack the project has no file for is refused. */
11
- export declare function switchStack(root: string, name: string | undefined): string;
12
- /** /stack and the chat's stack tool. */
13
- export declare function registerStacks(pi: ExtensionAPI, cwd: string): void;
package/dist/stacks.js DELETED
@@ -1,96 +0,0 @@
1
- /**
2
- * Choosing a stack: `config.turri.<stack>.yaml` laid over `config.turri.yaml` for everything built from then on - a
3
- * backend's testing scripts, then a frontend's. `/stack` and the `stack` tool in the chat, `--stack <name>` on the
4
- * command line (cli.ts). The choice itself is kept in config.ts (`chooseStack`): in the chat it is made in, for that chat
5
- * alone (chat-scope.ts), each new chat starting from `--stack`.
6
- */
7
- import { readdirSync } from "node:fs";
8
- import { join } from "node:path";
9
- import { defineTool } from "@earendil-works/pi-coding-agent";
10
- import { Type } from "typebox";
11
- import { chooseStack, chosenStack, hasProjectConfig, NO_STACK, stackConfigFile, stacksOf } from "./config.js";
12
- /** The stacks of the projects here: the folder's own, and those of the projects one folder down (specs kept in plain/). */
13
- export function knownStacks(root) {
14
- const below = (() => {
15
- try {
16
- return readdirSync(root, { withFileTypes: true })
17
- .filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules" && entry.name !== "plain_modules")
18
- .map((entry) => join(root, entry.name))
19
- .filter(hasProjectConfig);
20
- }
21
- catch {
22
- return [];
23
- }
24
- })();
25
- return [...new Set([root, ...below].flatMap(stacksOf))].sort();
26
- }
27
- /** Choose `name` - or none - among the stacks here, and say what is chosen now; a stack the project has no file for is refused. */
28
- export function switchStack(root, name) {
29
- const stacks = knownStacks(root);
30
- const wanted = name?.trim() ?? "";
31
- if (wanted === "" || NO_STACK.includes(wanted.toLowerCase())) {
32
- chooseStack(undefined);
33
- return "No stack chosen: everything is built with the project's config.turri.yaml alone, from now on.";
34
- }
35
- if (!stacks.includes(wanted)) {
36
- throw new Error(stacks.length > 0
37
- ? `There is no stack ${wanted} here. The stacks: ${stacks.join(", ")} - or none.`
38
- : `This project has no stacks: a stack is a ${stackConfigFile("<stack>")} beside config.turri.yaml.`);
39
- }
40
- chooseStack(wanted);
41
- return `Stack ${wanted} chosen: everything is built with ${stackConfigFile(wanted)} over config.turri.yaml from now on - a pulse already running keeps the stack it started with.`;
42
- }
43
- /** /stack and the chat's stack tool. */
44
- export function registerStacks(pi, cwd) {
45
- pi.registerCommand("stack", {
46
- description: "Choose the stack everything is built with - its config.turri.<stack>.yaml over config.turri.yaml: /stack [name | none]",
47
- getArgumentCompletions: (prefix) => {
48
- const items = [...knownStacks(cwd), "none"].filter((stack) => stack.startsWith(prefix)).map((stack) => ({ value: stack, label: stack }));
49
- return items.length > 0 ? items : null;
50
- },
51
- handler: async (args, ctx) => {
52
- let name = args.trim();
53
- if (name === "") {
54
- const stacks = knownStacks(cwd);
55
- if (stacks.length === 0)
56
- return ctx.ui.notify(`This project has no stacks: a stack is a ${stackConfigFile("<stack>")} beside config.turri.yaml.`, "info");
57
- const now = chosenStack();
58
- const label = (stack) => `${stack}${stack === now ? " (chosen now)" : ""}`;
59
- const none = `none - config.turri.yaml alone${now === undefined ? " (chosen now)" : ""}`;
60
- const picked = await ctx.ui.select("Build with which stack?", [...stacks.map(label), none]);
61
- if (picked === undefined)
62
- return;
63
- name = picked === none ? "none" : (stacks.find((stack) => label(stack) === picked) ?? "");
64
- }
65
- try {
66
- ctx.ui.notify(switchStack(cwd, name), "info");
67
- }
68
- catch (error) {
69
- ctx.ui.notify(error instanceof Error ? error.message : String(error), "error");
70
- }
71
- },
72
- });
73
- pi.registerTool(defineTool({
74
- name: "stack",
75
- label: "Stack",
76
- description: "Choose the stack everything is built with from now on - the project's config.turri.yaml with the stack's " +
77
- "config.turri.<stack>.yaml over it: its testing scripts, toolchains, models - or none, the project's file alone. " +
78
- "For this chat alone - each chat chooses its own; a pulse already running keeps the stack it started with. Without a name, says the stacks and the one chosen.",
79
- promptSnippet: "choose the stack - its testing scripts and settings - that everything is built with",
80
- promptGuidelines: [
81
- "Switch the stack only when the user asks for it, and say which you chose. A module is built with the stack named after it by itself; to build one whose stack has another name, pass that stack as stack to regenerate, conform, glimpse or change_plain instead: it is pinned to that module's pulses, and this chat's choice stays as it is.",
82
- ],
83
- parameters: Type.Object({
84
- name: Type.Optional(Type.String({ description: "The stack to choose, or none. Omitted: the stacks there are, and the one chosen" })),
85
- }),
86
- async execute(_id, params, _signal, _onUpdate, ctx) {
87
- if (params.name === undefined) {
88
- const stacks = knownStacks(cwd);
89
- const text = stacks.length > 0 ? `The stacks: ${stacks.join(", ")}. Chosen now: ${chosenStack() ?? "none"}.` : "This project has no stacks.";
90
- return { content: [{ type: "text", text }], details: {} };
91
- }
92
- const text = switchStack(cwd, params.name);
93
- return { content: [{ type: "text", text }], details: {} };
94
- },
95
- }));
96
- }