@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.
Files changed (134) hide show
  1. package/README.md +6 -7
  2. package/dist/bedrock-region.js +3 -3
  3. package/dist/chat-models.d.ts +1 -1
  4. package/dist/chat-models.js +1 -1
  5. package/dist/chat-scope.d.ts +1 -3
  6. package/dist/chat-skills.d.ts +1 -1
  7. package/dist/chat-skills.js +1 -1
  8. package/dist/chats.d.ts +44 -10
  9. package/dist/chats.js +125 -41
  10. package/dist/cli.js +10 -26
  11. package/dist/config-edit.d.ts +20 -8
  12. package/dist/config-edit.js +32 -24
  13. package/dist/config.d.ts +101 -58
  14. package/dist/config.js +265 -118
  15. package/dist/conform-cli.js +14 -3
  16. package/dist/conformance-switch.d.ts +7 -6
  17. package/dist/conformance-switch.js +19 -16
  18. package/dist/extension.d.ts +29 -3
  19. package/dist/extension.js +375 -351
  20. package/dist/genome.js +5 -1
  21. package/dist/host-session.d.ts +8 -7
  22. package/dist/host-session.js +4 -4
  23. package/dist/host.d.ts +3 -1
  24. package/dist/host.js +3 -3
  25. package/dist/identity.js +2 -2
  26. package/dist/init-config.d.ts +1 -1
  27. package/dist/init-config.js +8 -8
  28. package/dist/launch-agent.d.ts +51 -0
  29. package/dist/launch-agent.js +267 -0
  30. package/dist/{release-cli.js → launch-cli.js} +41 -24
  31. package/dist/launch-session.d.ts +68 -0
  32. package/dist/launch-session.js +217 -0
  33. package/dist/launch-tools.d.ts +28 -0
  34. package/dist/launch-tools.js +69 -0
  35. package/dist/launch-track.d.ts +125 -0
  36. package/dist/launch-track.js +320 -0
  37. package/dist/loop-cli.js +4 -4
  38. package/dist/loop-tools.d.ts +45 -21
  39. package/dist/loop-tools.js +152 -82
  40. package/dist/notice.d.ts +7 -6
  41. package/dist/parse-cli.js +2 -2
  42. package/dist/pi-launch.js +3 -0
  43. package/dist/pi-settings.d.ts +4 -0
  44. package/dist/pi-settings.js +39 -0
  45. package/dist/pi.js +6 -3
  46. package/dist/plain/check.d.ts +1 -1
  47. package/dist/plain/check.js +3 -1
  48. package/dist/plain-files.d.ts +2 -2
  49. package/dist/plain-files.js +7 -7
  50. package/dist/regenerate/agent-env.d.ts +1 -1
  51. package/dist/regenerate/agent-env.js +3 -3
  52. package/dist/regenerate/agent-shell.js +5 -3
  53. package/dist/regenerate/audit.js +9 -0
  54. package/dist/regenerate/base-folder.d.ts +2 -2
  55. package/dist/regenerate/base-folder.js +1 -1
  56. package/dist/regenerate/cases.js +7 -0
  57. package/dist/regenerate/chunk-plan.d.ts +5 -0
  58. package/dist/regenerate/chunk-plan.js +16 -1
  59. package/dist/regenerate/command-check.d.ts +7 -1
  60. package/dist/regenerate/command-check.js +43 -1
  61. package/dist/regenerate/delivery.d.ts +1 -1
  62. package/dist/regenerate/delivery.js +3 -3
  63. package/dist/regenerate/drift.d.ts +4 -0
  64. package/dist/regenerate/drift.js +26 -6
  65. package/dist/regenerate/job-panel.js +3 -1
  66. package/dist/regenerate/jobs.d.ts +2 -2
  67. package/dist/regenerate/jobs.js +10 -10
  68. package/dist/regenerate/launch.d.ts +154 -0
  69. package/dist/regenerate/{release.js → launch.js} +195 -51
  70. package/dist/regenerate/ledger.d.ts +33 -2
  71. package/dist/regenerate/lineage.d.ts +2 -0
  72. package/dist/regenerate/lineage.js +8 -0
  73. package/dist/regenerate/loop.d.ts +30 -10
  74. package/dist/regenerate/loop.js +166 -59
  75. package/dist/regenerate/model-names.d.ts +33 -0
  76. package/dist/regenerate/{engine.js → model-names.js} +2 -28
  77. package/dist/regenerate/paths.d.ts +3 -3
  78. package/dist/regenerate/paths.js +4 -4
  79. package/dist/regenerate/records.d.ts +11 -0
  80. package/dist/regenerate/records.js +15 -0
  81. package/dist/regenerate/regenerate.js +4 -1
  82. package/dist/regenerate/renames.js +4 -4
  83. package/dist/regenerate/requires.d.ts +7 -0
  84. package/dist/regenerate/requires.js +24 -18
  85. package/dist/regenerate/scripts-being-written.d.ts +4 -4
  86. package/dist/regenerate/scripts-being-written.js +3 -3
  87. package/dist/regenerate/spec-map.js +3 -3
  88. package/dist/regenerate/submit-work.d.ts +2 -0
  89. package/dist/regenerate/submit-work.js +8 -3
  90. package/dist/regenerate/test-scripts.d.ts +2 -1
  91. package/dist/regenerate/test-scripts.js +33 -23
  92. package/dist/regenerate/testing-steps.d.ts +6 -6
  93. package/dist/regenerate/testing-steps.js +8 -8
  94. package/dist/regenerate-cli.js +1 -1
  95. package/dist/self-invocation.d.ts +11 -0
  96. package/dist/self-invocation.js +36 -7
  97. package/dist/sentinel-check.d.ts +3 -3
  98. package/dist/sentinel-check.js +3 -3
  99. package/dist/sentinel.d.ts +18 -12
  100. package/dist/sentinel.js +72 -43
  101. package/dist/{config-command.d.ts → settings.d.ts} +13 -8
  102. package/dist/{config-command.js → settings.js} +155 -24
  103. package/dist/setup.d.ts +2 -2
  104. package/dist/setup.js +7 -7
  105. package/dist/turri-versions.js +2 -1
  106. package/docs/README.md +4 -4
  107. package/docs/chats.md +5 -6
  108. package/docs/claude-subscription.md +2 -2
  109. package/docs/config.md +58 -46
  110. package/docs/development.md +2 -2
  111. package/docs/headless.md +4 -4
  112. package/docs/hosting.md +20 -19
  113. package/docs/launch.md +67 -0
  114. package/docs/parser.md +2 -2
  115. package/docs/regenerating.md +21 -15
  116. package/docs/sandbox.md +3 -3
  117. package/docs/sentinel.md +26 -14
  118. package/docs/skills-and-gates.md +4 -4
  119. package/docs/using.md +19 -28
  120. package/genome/rules/project-model.md +2 -1
  121. package/genome/rules/turri-regeneration.md +5 -3
  122. package/genome/skills/implement-conformance-testing-script/SKILL.md +2 -2
  123. package/genome/skills/implement-unit-testing-script/SKILL.md +3 -3
  124. package/package.json +1 -1
  125. package/dist/regenerate/engine.d.ts +0 -52
  126. package/dist/regenerate/release.d.ts +0 -121
  127. package/dist/release-agent.d.ts +0 -43
  128. package/dist/release-agent.js +0 -130
  129. package/dist/release-tools.d.ts +0 -44
  130. package/dist/release-tools.js +0 -170
  131. package/dist/stacks.d.ts +0 -13
  132. package/dist/stacks.js +0 -96
  133. package/docs/deploy.md +0 -48
  134. /package/dist/{release-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,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"];
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 or pulses 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
- }
package/docs/deploy.md DELETED
@@ -1,48 +0,0 @@
1
- # Trying what is built: deploy
2
-
3
- Ask to try it - "let me try it", "run the app" - at any time, even while a regeneration is running. The chat calls `deploy`: it puts the module's code, as it was last built, in `dist/<module>` in the project, and starts it on your machine. An app with a backend and a frontend is started whole, and you are told where to open your browser. For a command-line tool or a library you get a few commands to paste, run from `dist/<module>`, and what they print.
4
-
5
- ## When the project says how it is released
6
-
7
- Every release starts the same way: the module's last commit - what last landed whole - goes in `dist/<module>`, as below. Not everything is tried from there, though. An integration that a host application loads goes on into the host's own tree, with the host's own scripts, and then the host is started. So the model asks itself whether there is guidance for how this project is released - in what you said, the project's AGENTS.md, a skill, anything it was given - and passes it to `release` whole:
8
-
9
- - **There is guidance.** The code goes on from `dist/<module>` as the guidance says, on your machine, from the host codebase - the git repository the project is in, or else where **turri** runs: the scripts it names, in their order, and any change it says the host needs. The code is taken from `dist`, never from `plain_modules`, where a pulse may be writing; where the host's tooling reads `plain_modules` itself, the model points it at `dist`, or does by hand from `dist` what it does. Whether to release after every pulse is `release-after-pulse`'s to say - see [after every pulse](#after-every-pulse). The rules below hold as they do for `dist`: the model runs the project's scripts and installs what they need itself, and what keeps running - a start script, a server - is started with `activate`. Nothing built is changed, and nor is the \*\*\*plain: its file tools refuse a `.plain` file - a module or a test plain file - as they refuse `plain_modules`.
10
- - **There is none.** The default: it is started from `dist/<module>`, as below, as best it can be.
11
-
12
- Guidance is whatever says it, in any words - a line in AGENTS.md such as *integrations are released with `scripts/deploy_integrations.sh`, then the app is started with `scripts/start.sh`*, or the same said in the chat.
13
-
14
- With `sentinel: false`, the chat reacts to every pulse that finishes as it finishes, without waiting for you to speak: guidance that says to release after a build - *release each integration once it is regenerated* - is followed then. With the [sentinel](sentinel.md) on - the default - the chat is told only that a pulse landed, and does nothing about it: guidance to follow once a pulse finishes is not followed, and releasing after every pulse is `release-after-pulse`'s. It never has to work out whether what a pulse landed is already out: `release` does. When the module's last commit is what its last release in this conversation shipped, it does nothing - nothing exported, nothing stopped, what runs left running - and says so; `again: true` releases it anyway, for when what that release said to do was not done.
15
-
16
- ## What goes in dist
17
-
18
- - **The module on top.** Code accumulates up a `requires` chain: a module starts from a copy of the code of the one it requires. So deploy always takes the module on top of the `requires` chain - the project's `module` from `config.turri.yaml` unless another module's \*\*\*plain is named. Before the module on top has anything built, it takes the nearest one below it that has, and says so.
19
- - **Its last commit.** Each `plain_modules/<module>` is a git repository (`.plaingit`), and every unit of work starts from a commit and ends with one. What a pulse is writing right now is half-done, so it is left out: deploy exports the commit - `git archive` of `code/` - which is the working tree with every unstaged and untracked change put back, and no `node_modules`, `.venv`, `target` or other build leftovers, whatever the stack. The working tree the pulse is using is never read or touched. The harness's own files - `.turri.json`, the agents' notes - are left out too.
20
- - **Replaced whole.** Each deploy stops what the last one of the module started, empties `dist/<module>` and exports again. Change nothing there you want to keep. `dist/` is not added to `.gitignore`: whether it is committed is yours to decide.
21
-
22
- ## Starting it
23
-
24
- It runs on your machine, outside the [sandbox](sandbox.md) - with your toolchains, where your browser can reach it. The chat reads how the code runs (its README, manifests and entry points), then:
25
-
26
- 1. **Checks the toolchains** it needs (`node`, `python3`, `go`, ...) - under another name too: `python` where `python3` is not, of the version it needs. One is missing: it stops, and tells you the exact command to install it yourself (`brew install node`). turri installs nothing on your machine and changes none of its settings - not the release, not the chat, not any agent: its shell refuses it.
27
- 2. **Installs what it needs into the project.** Dependencies into a virtual environment or `node_modules`, a build that downloads packages, an image pull, a guided release's project scripts: it runs them in its own shell, as any agent with a shell would, and fixes what fails. Nothing is put to you - there is no dialog to answer. Never a global install, never a system setting.
28
- 3. **Starts what serves** with `activate`: in the background, in its own process group, its output in `.turri/deploy/<module>-<name>.log`. It waits until something answers at the server's URL - up to a minute - so the URL you are given has answered once; one that exits first comes back with the end of its output. A port something else holds is said, with what holds it, and nothing is started there: the app is not moved to a port you were not told about. It runs in the deployed folder, or a folder inside it the model names relative to it (`frontend`); a folder that is not there starts nothing, and the model is told so with what the deployed folder holds, to name the right one.
29
-
30
- What it started is listed by the `pulses` tool and by **`/halt`**, and stopped by **`/halt activated <name>`**, by `halt`, by the next deploy of the module, and when the chat exits.
31
-
32
- ## After every pulse
33
-
34
- With `release-after-pulse: true` in `config.turri.yaml`, turri releases what each pulse lands itself, as the pulse's last stage (`releasing what this pulse landed`): the pulse ends once it is released, so the module's next pulse starts on what is out, and the chat - waiting on your answer to a question, say - has no part in it. One release a pulse that lands, in order.
35
-
36
- The release is done by an agent on the coding model, thinking low - it follows steps, and a small model does that well - the same one `turri release` runs, and it finds the guidance as the chat would: what was passed to `release` earlier in the conversation, the project's AGENTS.md and its skills. The setting is the word to release; the guidance says only how - without any, the code goes to `dist/<module>` and is started from there. Its last words go in the pulse's report - "Released after the pulse: ..." - and the [sentinel](sentinel.md) is told what was released and where it runs, and tests it: what needs you comes as a notice in the chat you are in, and the chat you are in says only that it landed and is being tested. With `sentinel: false`, the chat, seeing the report, does not release it again: it says in a line what was released, then does what it was told to do once something is released - a host such as a desktop app tells it, in its `surface`, to open it where the person can watch and say what to test. A release that fails is said there too; what the pulse landed stays.
37
-
38
- Off without the key: releasing after a pulse is then the chat's, when its guidance says so. `turri init-config` writes `release-after-pulse: true`.
39
-
40
- ## On the command line
41
-
42
- ```bash
43
- turri release [file.plain] [--in-module <module>] [--guidance <text>] [--model <provider/id>]
44
- ```
45
-
46
- The same, without the chat: a one-off agent on `coding-model`, thinking low (or `--model`; without either, [pi](https://pi.dev)'s default) is given the project's AGENTS.md and what `--guidance <text>` says, looks for guidance in them, and releases as above - as the guidance says, or to `dist/<module>` - then works out how to start it and starts it here, installing what it needs without asking. It stays in the foreground with the servers' output; `Ctrl-C` stops them. If it does not get there, deploy from the chat instead.
47
-
48
- `turri regenerate` and `conform` end a build that landed with `To try it: turri release <spec>`.
File without changes