@turri-dev/core 0.1.1-next.35d4c49 → 0.1.1-next.ad4aa8f

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 (163) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +17 -11
  3. package/dist/api/models.d.ts +9 -0
  4. package/dist/api/models.js +15 -0
  5. package/dist/api/plain.d.ts +6 -6
  6. package/dist/api/plain.js +4 -7
  7. package/dist/api/project.d.ts +35 -0
  8. package/dist/api/project.js +47 -0
  9. package/dist/api/session.d.ts +48 -0
  10. package/dist/api/session.js +17 -0
  11. package/dist/api/system.d.ts +18 -0
  12. package/dist/api/system.js +23 -0
  13. package/dist/btw.d.ts +1 -1
  14. package/dist/capture/capture.js +11 -8
  15. package/dist/capture/chat.d.ts +0 -11
  16. package/dist/capture/chat.js +0 -29
  17. package/dist/capture/config.d.ts +4 -5
  18. package/dist/capture/config.js +34 -20
  19. package/dist/capture/models.d.ts +2 -1
  20. package/dist/capture/models.js +1 -0
  21. package/dist/chat-entries.d.ts +81 -39
  22. package/dist/chat-entries.js +125 -11
  23. package/dist/chat-model.d.ts +37 -0
  24. package/dist/chat-model.js +61 -0
  25. package/dist/chats.d.ts +54 -42
  26. package/dist/chats.js +86 -80
  27. package/dist/client.d.ts +30 -0
  28. package/dist/client.js +12 -0
  29. package/dist/config-edit.d.ts +54 -1
  30. package/dist/config-edit.js +103 -33
  31. package/dist/config.d.ts +12 -9
  32. package/dist/config.js +38 -9
  33. package/dist/doctor-checks.d.ts +42 -0
  34. package/dist/doctor-checks.js +39 -0
  35. package/dist/environment.d.ts +2 -23
  36. package/dist/environment.js +5 -68
  37. package/dist/errors.d.ts +32 -0
  38. package/dist/errors.js +24 -0
  39. package/dist/extension.d.ts +23 -16
  40. package/dist/extension.js +170 -234
  41. package/dist/identity.d.ts +1 -1
  42. package/dist/identity.js +13 -9
  43. package/dist/init-config.d.ts +11 -9
  44. package/dist/init-config.js +15 -7
  45. package/dist/launch-session.d.ts +2 -0
  46. package/dist/launch-session.js +17 -1
  47. package/dist/loop-tools.js +11 -10
  48. package/dist/module-check.d.ts +13 -0
  49. package/dist/module-check.js +117 -0
  50. package/dist/notice.d.ts +5 -0
  51. package/dist/parse-tool.js +3 -2
  52. package/dist/plain/check.d.ts +27 -13
  53. package/dist/plain/check.js +51 -116
  54. package/dist/plain/files.d.ts +2 -0
  55. package/dist/plain/files.js +13 -0
  56. package/dist/plain/graph.js +2 -2
  57. package/dist/plain/highlight.d.ts +4 -20
  58. package/dist/plain/highlight.js +7 -5
  59. package/dist/project.d.ts +19 -0
  60. package/dist/project.js +34 -0
  61. package/dist/quiet.d.ts +0 -2
  62. package/dist/quiet.js +0 -14
  63. package/dist/regenerate/command-check.d.ts +0 -8
  64. package/dist/regenerate/command-check.js +133 -53
  65. package/dist/regenerate/conversation-writes.d.ts +5 -1
  66. package/dist/regenerate/conversation-writes.js +7 -3
  67. package/dist/regenerate/jobs.d.ts +25 -2
  68. package/dist/regenerate/jobs.js +3 -0
  69. package/dist/regenerate/launch.d.ts +1 -0
  70. package/dist/regenerate/launch.js +9 -0
  71. package/dist/regenerate/ledger-view.d.ts +14 -14
  72. package/dist/regenerate/ledger.d.ts +1 -0
  73. package/dist/regenerate/ledger.js +4 -2
  74. package/dist/regenerate/loop.d.ts +2 -1
  75. package/dist/regenerate/loop.js +9 -1
  76. package/dist/regenerate/os-sandbox.d.ts +4 -2
  77. package/dist/regenerate/os-sandbox.js +0 -1
  78. package/dist/regenerate/regenerate.js +2 -1
  79. package/dist/regenerate/requires-chain.d.ts +44 -0
  80. package/dist/regenerate/requires-chain.js +174 -0
  81. package/dist/regenerate/requires.d.ts +2 -40
  82. package/dist/regenerate/requires.js +14 -171
  83. package/dist/regenerate/resources.d.ts +0 -2
  84. package/dist/regenerate/resources.js +2 -14
  85. package/dist/regenerate/shell.js +20 -9
  86. package/dist/regenerate/spec-map.d.ts +2 -0
  87. package/dist/regenerate/spec-map.js +4 -0
  88. package/dist/regenerate/standing.d.ts +5 -2
  89. package/dist/run-report.js +2 -2
  90. package/dist/self-invocation.d.ts +1 -1
  91. package/dist/self-invocation.js +2 -3
  92. package/dist/sentinel-chat.js +7 -11
  93. package/dist/sentinel.d.ts +1 -1
  94. package/dist/sentinel.js +12 -5
  95. package/dist/session-events.d.ts +14 -0
  96. package/dist/session.d.ts +594 -0
  97. package/dist/session.js +672 -0
  98. package/dist/settings.d.ts +28 -2
  99. package/dist/settings.js +92 -56
  100. package/dist/setup.d.ts +6 -30
  101. package/dist/setup.js +28 -105
  102. package/dist/stack.d.ts +25 -12
  103. package/dist/stack.js +77 -12
  104. package/dist/surface.d.ts +2 -2
  105. package/dist/surface.js +4 -5
  106. package/dist/work.d.ts +125 -0
  107. package/dist/work.js +250 -0
  108. package/docs/README.md +2 -3
  109. package/docs/capture.md +4 -4
  110. package/docs/chats.md +5 -3
  111. package/docs/claude-subscription.md +2 -2
  112. package/docs/config.md +4 -4
  113. package/docs/core.md +105 -128
  114. package/docs/development.md +9 -9
  115. package/docs/headless.md +1 -1
  116. package/docs/installation.md +4 -2
  117. package/docs/launch.md +2 -2
  118. package/docs/parser.md +1 -1
  119. package/docs/regenerating.md +1 -1
  120. package/docs/sandbox.md +4 -4
  121. package/docs/sentinel.md +4 -4
  122. package/docs/skills-and-gates.md +1 -1
  123. package/docs/using.md +2 -2
  124. package/genome/rules/integration-embedded-testing.md +3 -3
  125. package/genome/rules/integration-embedded.md +3 -3
  126. package/genome/skills/implement-conformance-testing-script/SKILL.md +6 -4
  127. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_java.sh +13 -11
  128. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.sh +8 -7
  129. package/genome/skills/implement-unit-testing-script/SKILL.md +7 -5
  130. package/genome/skills/implement-unit-testing-script/assets/run_unittests_java.sh +9 -13
  131. package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.sh +1 -1
  132. package/package.json +19 -32
  133. package/dist/api/commands.d.ts +0 -45
  134. package/dist/api/commands.js +0 -54
  135. package/dist/api/config.d.ts +0 -8
  136. package/dist/api/config.js +0 -8
  137. package/dist/api/ledger.d.ts +0 -3
  138. package/dist/api/ledger.js +0 -3
  139. package/dist/api/startup.d.ts +0 -8
  140. package/dist/api/startup.js +0 -8
  141. package/dist/api/terminal.d.ts +0 -18
  142. package/dist/api/terminal.js +0 -16
  143. package/dist/chat-models.d.ts +0 -11
  144. package/dist/chat-models.js +0 -11
  145. package/dist/chat-ui.d.ts +0 -33
  146. package/dist/chat-ui.js +0 -192
  147. package/dist/headless.d.ts +0 -99
  148. package/dist/headless.js +0 -226
  149. package/dist/host-session.d.ts +0 -136
  150. package/dist/host-session.js +0 -139
  151. package/dist/host.d.ts +0 -8
  152. package/dist/host.js +0 -17
  153. package/dist/index.d.ts +0 -16
  154. package/dist/index.js +0 -7
  155. package/dist/notifications.d.ts +0 -21
  156. package/dist/notifications.js +0 -44
  157. package/dist/reopen.d.ts +0 -29
  158. package/dist/reopen.js +0 -47
  159. package/dist/turri-versions.d.ts +0 -71
  160. package/dist/turri-versions.js +0 -276
  161. package/dist/view.d.ts +0 -78
  162. package/dist/view.js +0 -1
  163. package/docs/hosting.md +0 -284
package/dist/headless.js DELETED
@@ -1,226 +0,0 @@
1
- import { sweepOrphanedGroups } from "./regenerate/shell.js";
2
- import { nextPulses } from "./preview.js";
3
- import { refuseTestPlainFile } from "./test-plain-files.js";
4
- import { resolve, sep } from "node:path";
5
- import { brokenConfig, configForSpec, inheritModel, modelOnly, modelSpec, projectModels, readProjectConfig, roleModel, ROLE_THINKING, splitModelSpec, } from "./config.js";
6
- import { PACKAGE_ROOT } from "./environment.js";
7
- import { describeTurnIncident, onModelEvent } from "./regenerate/activity.js";
8
- import { ledgerWanted, startLedger } from "./regenerate/ledger.js";
9
- import { describeDiagnosis, diagnoseFailure } from "./regenerate/diagnose.js";
10
- import { createJobRegistry } from "./regenerate/jobs.js";
11
- import { createWorkLoop, functionalityCompletion } from "./regenerate/loop.js";
12
- import { MODULES_DIR, projectDirOf } from "./regenerate/paths.js";
13
- import { exportModule } from "./regenerate/launch.js";
14
- import { listFiles } from "./regenerate/testing.js";
15
- import { startRunReport } from "./run-report.js";
16
- /** Run it, the view shown and asked what a person would be: see HeadlessRun. `turri regenerate` and `conform` exit with its exitCode. */
17
- export async function runHeadless(options, view) {
18
- const plainFile = resolve(options.plainFile);
19
- refuseTestPlainFile(plainFile);
20
- // A config that does not parse is read as empty: refused, rather than every pulse run on defaults - pi's model among them.
21
- const broken = brokenConfig(projectDirOf(plainFile));
22
- if (broken !== undefined)
23
- throw new Error(`Nothing was started: ${broken}`);
24
- // What a turri that was killed left running - commands' process groups - stopped before anything starts.
25
- const orphans = sweepOrphanedGroups();
26
- if (orphans > 0)
27
- view.orphansStopped(orphans);
28
- const project = { ...readProjectConfig(process.cwd()), ...Object.fromEntries(Object.entries(configForSpec(plainFile)).filter(([, value]) => value !== undefined)) };
29
- // The models as the config has them - with a command's own options read as its keys (headlessOptions), as the chat reads them.
30
- const model = modelSpec(projectModels(project).coding);
31
- const projectDir = projectDirOf(plainFile);
32
- // What the run does, as facts, in the project's .turri/ledger.
33
- if (ledgerWanted() && options.dryRun !== true)
34
- startLedger({ mode: options.command?.[0] ?? "headless", project: projectDir, warn: (message) => view.warn(message) });
35
- const buildDir = options.buildDir !== undefined && options.dryRun !== true ? resolve(options.buildDir) : undefined;
36
- if (buildDir !== undefined) {
37
- const problem = buildDirProblem(buildDir, projectDir);
38
- if (problem !== undefined)
39
- throw new Error(problem);
40
- }
41
- // The code, exported into --build-dir as the process exits - however it exits - before the report's last write.
42
- let exported;
43
- if (buildDir !== undefined) {
44
- process.once("exit", () => {
45
- exported = exportCode(plainFile, buildDir);
46
- view.exported(exported, buildDir);
47
- });
48
- }
49
- const report = options.report !== undefined && options.dryRun !== true
50
- ? startRunReport({
51
- file: options.report,
52
- command: options.command ?? process.argv.slice(2),
53
- specFile: plainFile,
54
- projectDir,
55
- ...(buildDir !== undefined ? { buildDir } : {}),
56
- review: project.review === true,
57
- mutationTesting: project.mutationTesting !== false,
58
- models: reportModels(project, model),
59
- })
60
- : undefined;
61
- const stopHearing = onModelEvent((event) => {
62
- const line = describeTurnIncident(event);
63
- if (line !== undefined)
64
- view.turnIncident(event, line);
65
- });
66
- try {
67
- return await runLoopReporting({ ...options, plainFile, project, model, projectDir, reporter: report, exported: () => exported }, view);
68
- }
69
- catch (error) {
70
- report?.crashed(error);
71
- throw error;
72
- }
73
- finally {
74
- stopHearing();
75
- }
76
- }
77
- async function runLoopReporting(options, view) {
78
- const { plainFile, project, model, projectDir, reporter: report } = options;
79
- // Each job as it starts and as it ends - the transcript of each is in .turri/jobs/.
80
- const seen = new Map();
81
- const registry = createJobRegistry({
82
- retries: 1,
83
- diagnose: async (job, failures, jobLog) => {
84
- const diagnosis = await diagnoseFailure({ job, failures, projectDir, harnessDir: PACKAGE_ROOT, jobLog, model: modelSpec(modelOnly(job.model ?? model)) });
85
- return diagnosis !== undefined ? describeDiagnosis(diagnosis) : undefined;
86
- },
87
- onChange: (job) => {
88
- const line = job.status === "running" ? `${job.stage ?? "started"}` : job.status;
89
- if (seen.get(job.id) === line)
90
- return;
91
- seen.set(job.id, line);
92
- if (job.status === "running")
93
- view.pulseRunning(job);
94
- },
95
- onFinish: (job) => {
96
- view.pulseFinished(job);
97
- report?.write();
98
- },
99
- });
100
- const planner = modelSpec(projectModels(project).harness);
101
- const loop = createWorkLoop({
102
- registry,
103
- cwd: process.cwd(),
104
- ...(model !== undefined ? { modelFor: () => model } : {}),
105
- ...(planner !== undefined ? { plannerModel: planner } : {}),
106
- });
107
- report?.attach({
108
- jobs: () => registry.list(),
109
- modules: () => moduleStates(loop.drift(plainFile)),
110
- completion: () => functionalityCompletion(plainFile),
111
- atExit: () => {
112
- const exported = options.exported();
113
- return exported !== undefined ? { build_dir_export: exported } : undefined;
114
- },
115
- });
116
- let planned = await options.ask(loop);
117
- view.planned(planned);
118
- // A codebase built without a module it now requires is started over only when the person says so.
119
- const toStartOver = planned.filter((status) => status.startOver !== undefined);
120
- if (toStartOver.length > 0 && options.dryRun !== true) {
121
- const why = toStartOver
122
- .map(({ startOver }) => startOver.old === true
123
- ? `${startOver.codebases.join(", ")} was built when functional specs were numbered, before they had func-ids: nothing more can be built on it.`
124
- : `${startOver.codebases.join(", ")} was built without ${startOver.requires.join(", ")}, which it now requires: no change to its code can bring it in.`)
125
- .join("\n");
126
- // No terminal and no --start-over: no one to ask, so the run stops here rather than build nothing and say it is done.
127
- if (options.startOver !== true && view.canAsk() !== true) {
128
- const message = `${why}\nThere is no terminal to ask whether to start over: run it again with --start-over to start over without asking.`;
129
- view.startOverRefused(message);
130
- report?.end("incomplete", message);
131
- return { status: "incomplete", exitCode: 1 };
132
- }
133
- const agreed = options.startOver === true ||
134
- (await view.ask("Start over?", `${why}\nStarting over takes its code and conformance tests out - they stay in its history - and builds it again from the bottom of the chain.`));
135
- if (agreed === true) {
136
- planned = await loop.startOver(plainFile, model !== undefined ? { model } : {});
137
- view.planned(planned);
138
- }
139
- }
140
- if (options.dryRun === true) {
141
- // The next pulse of each codebase, from the plan the look ahead kept - the one regenerate would start.
142
- for await (const next of nextPulses(loop, planned))
143
- view.nextPulse(next);
144
- return { status: "dry_run", exitCode: 0 };
145
- }
146
- // Until nothing more starts: a choice is made inside the pulse it follows, so draining waits for it.
147
- await loop.drain();
148
- view.drained(loop.status());
149
- const ended = registry.list();
150
- const failed = ended.filter((job) => job.status === "failed");
151
- // Complete: every codebase regenerated from the spec as it is, its conformance tests too - nothing halted, nothing
152
- // waiting for a start over, nothing the planner left out.
153
- const unfinished = moduleStates(loop.drift(plainFile)).filter((module) => module.state !== "complete");
154
- view.ended({ plainFile, jobs: ended, failed, unfinished });
155
- report?.end(failed.length > 0 ? "failed" : unfinished.length > 0 ? "incomplete" : "completed");
156
- return failed.length === 0 && unfinished.length === 0 ? { status: "completed", exitCode: 0 } : { status: failed.length > 0 ? "failed" : "incomplete", exitCode: 1 };
157
- }
158
- /** How each codebase stands, from what is left to regenerate there. */
159
- export function moduleStates(reports) {
160
- return reports.map((report) => {
161
- const state = report.running !== undefined
162
- ? "running"
163
- : report.startOver !== undefined
164
- ? "start_over_needed"
165
- : report.why !== undefined
166
- ? "halted"
167
- : report.code === null && (report.conformance === null || report.conformance === undefined)
168
- ? "complete"
169
- : "incomplete";
170
- const why = state === "start_over_needed"
171
- ? report.startOver.old === true
172
- ? "built when functional specs were numbered, before they had func-ids: run with --start-over to regenerate its chain from scratch"
173
- : `built without ${report.startOver.requires.join(", ")}, which it now requires: run with --start-over`
174
- : state === "incomplete"
175
- ? report.code !== null && report.code !== undefined
176
- ? "its code is not regenerated from the spec as it is"
177
- : "its conformance tests are not written for what is built"
178
- : report.why;
179
- return { module: report.module, state, ...(why !== undefined ? { why } : {}) };
180
- });
181
- }
182
- /**
183
- * Why a --build-dir cannot be used - one the export would wipe something in: the project, a folder holding it, or one
184
- * inside plain_modules - or undefined when it can. Anything else is the export's own, its contents replaced as the run ends.
185
- */
186
- export function buildDirProblem(buildDir, projectDir) {
187
- const within = (dir, of) => dir === of || dir.startsWith(`${of}${sep}`);
188
- const why = within(projectDir, buildDir)
189
- ? "it holds the project, and the export replaces what is in it"
190
- : within(buildDir, resolve(projectDir, MODULES_DIR))
191
- ? `it is inside ${MODULES_DIR}, which turri regenerates in`
192
- : undefined;
193
- if (why === undefined)
194
- return undefined;
195
- return `--build-dir ${buildDir} cannot be used: ${why}. Name a folder of its own - the code is exported there as the run ends.`;
196
- }
197
- /** The furthest-built codebase's last commit, exported into `dir` - or why nothing was. */
198
- export function exportCode(plainFile, dir) {
199
- try {
200
- const code = exportModule(plainFile, { into: dir });
201
- const files = listFiles(dir).length;
202
- // Its history began, and nothing landed in it yet: only the harness's own files, which are left out.
203
- if (files === 0)
204
- return { exported: false, dir, why: `nothing has landed in ${code.moduleName} yet: its codebase holds no code` };
205
- return { exported: true, dir, module: code.moduleName, commit: code.short, files };
206
- }
207
- catch (error) {
208
- return { exported: false, dir, why: error instanceof Error ? error.message : String(error) };
209
- }
210
- }
211
- /** The models of the three roles as this run uses them: the coding model given, the others as they fall back - each with the level it thinks at. */
212
- export function reportModels(project, model) {
213
- const coding = splitModelSpec(model);
214
- const harness = projectModels(project).harness ?? modelOnly(model);
215
- // As the judge's agent finds it: its models: entry over judge-model over models.default, else the coding model's.
216
- const judge = inheritModel(roleModel(project, "judge"), modelOnly(model)) ?? {};
217
- const choice = (given, fallback) => ({
218
- ...(given.model !== undefined ? { model: given.model } : {}),
219
- ...((given.thinking ?? fallback) !== undefined ? { thinking: given.thinking ?? fallback } : {}),
220
- });
221
- return {
222
- harness: choice(harness, ROLE_THINKING.planner),
223
- coding: choice(coding, ROLE_THINKING.coding),
224
- judge: choice(judge, ROLE_THINKING.judge),
225
- };
226
- }
@@ -1,136 +0,0 @@
1
- import { type AgentSession, type ExtensionFactory, type ExtensionUIContext } from "@earendil-works/pi-coding-agent";
2
- import type { AskUserIO } from "./ask.ts";
3
- import { type ChatEntry } from "./chat-entries.ts";
4
- import { type ModuleStanding } from "./regenerate/standing.ts";
5
- import { type ChatInfo, type TurriHost } from "./chats.ts";
6
- import type { Launch } from "./launch-track.ts";
7
- import type { SessionSpending } from "./session-spending.ts";
8
- import type { Job } from "./regenerate/jobs.ts";
9
- import type { ModuleStatus, PlannedPulse } from "./regenerate/loop.ts";
10
- import type { Notice, NoticeAnswer } from "./notice.ts";
11
- import { type CheckRequest } from "./sentinel-check.ts";
12
- /**
13
- * turri's session for a host that runs its chats itself - a desktop app, an editor: the chats, each a pi session with
14
- * turri in it, on one job registry and work loop. The host shows each chat in its own way - subscribes to its session,
15
- * prompts it - and tells turri which one its person looks at (`focus`): a pulse a closed chat asked for is reported
16
- * there.
17
- */
18
- export interface TurriOptions extends Omit<TurriHost, "dialogs"> {
19
- /** pi's folder - its settings, models and credentials. Default: pi's own (`~/.pi/agent`). */
20
- agentDir?: string;
21
- /** Where the chats' conversations are saved. Default: pi's own folder for this project. */
22
- sessionDir?: string;
23
- /** The host's own extensions, built into every chat after turri's. */
24
- extensions?: ExtensionFactory[];
25
- /**
26
- * The dialogs a chat's questions are put in - ask_user's, a skill's interview, a review gate's - by the chat's id. Each
27
- * is given a `signal`, aborted when its question is over without its answer - declined, or its turn stopped - for the
28
- * host to close it.
29
- */
30
- dialogs?: (chat: string) => AskUserIO | undefined;
31
- /** What a chat's other UI calls - its notices, its working line - come to, by the chat's id. */
32
- uiContext?: (chat: string) => ExtensionUIContext | undefined;
33
- /** Reopen the chats of the last session here that has ended, in their order - as `turri --continue` does. */
34
- restore?: boolean;
35
- }
36
- export interface Turri {
37
- /** A snapshot of this session's launches, oldest first, including stopped and replaced ones. */
38
- launches(): Launch[];
39
- /** Dollars spent since this session opened, including closed chats and earlier sentinel conversations. */
40
- spending(): SessionSpending;
41
- /** Every job of this session, including retries; undefined for an unknown job id. */
42
- jobs(): Job[];
43
- job(id: string): Job | undefined;
44
- /** What the Pulses view shows now, including plans held by a look ahead. */
45
- status(): {
46
- modules: (ModuleStatus & {
47
- lookedAhead?: boolean;
48
- })[];
49
- jobs: Job[];
50
- planned: Job[];
51
- };
52
- /** Read drift and completion, even before the first chat opens. Never plans or starts work. */
53
- standing(files?: string[]): ModuleStanding[];
54
- /** Plan on the chats' own loop, hold the plan and return its next prompts. Requires an open chat. */
55
- lookAhead(plainFile: string): Promise<{
56
- statuses: ModuleStatus[];
57
- next: PlannedPulse[];
58
- }>;
59
- /** turri's custom entries in the chat's current branch, in transcript order. */
60
- entries(chat: string): ChatEntry[];
61
- /** The chats, in their order. */
62
- chats(): ChatInfo[];
63
- /** A chat's pi session: to subscribe to, prompt and abort. */
64
- session(id: string): AgentSession | undefined;
65
- /** A fresh chat - or the saved one `sessionFile` is. At most nine are open. */
66
- openChat(options?: {
67
- sessionFile?: string;
68
- }): Promise<ChatInfo & {
69
- session: AgentSession;
70
- }>;
71
- /** A chat closed: its turn stopped, its conversation deleted - its pulses run on. */
72
- closeChat(id: string): Promise<void>;
73
- /** The chat the person looks at now. */
74
- focus(id: string): void;
75
- /**
76
- * ctrl+c in a chat, as the terminal has it: what the chat is doing stopped - its turn, a skill or a tool in it, a `!`
77
- * command, a compaction - and nothing in the others (`stopped`). In a chat doing nothing the session ends - every
78
- * chat let go and what launches started stopped, as `dispose` does - for the host to close what showed it (`ended`).
79
- * A second interrupt straight after one that stopped something does nothing (`ignored`); `missing` for a chat not open.
80
- */
81
- interrupt(id: string): Promise<"stopped" | "ignored" | "ended" | "missing">;
82
- /**
83
- * ctrl+c at a question, as the terminal has it: the question the chat asks now - its ask_user, a skill's interview, a
84
- * review gate's escalation - declined. The asker is told the person declined to answer and the turn goes on; the
85
- * host's dialog for it is told through its `signal`. Each question it is called at, however many in a row - it never
86
- * stops the turn. `none` when the chat asks nothing now, `missing` for a chat not open.
87
- */
88
- decline(id: string): Promise<"declined" | "none" | "missing">;
89
- /**
90
- * The notices put to the person and not yet over - the sentinel's, and turri's own: each in the chat it names. A host
91
- * hears each as it is put (`onNotice`) and as it ends (`onNoticeOver`).
92
- */
93
- notices(): Notice[];
94
- /**
95
- * The sentinel asked to check functional specs in what is launched of a module - `funcIds` each `module:func-id`, of the
96
- * module or of any module its requires chain builds on (a bare func-id is the module's own) - as it tests a launch after a
97
- * pulse: the module's own codebase's code, which holds every module its chain builds on. Nothing launched of it, the
98
- * check ends unchecked: the sentinel launches nothing. Queued behind the
99
- * sentinel's work, in a conversation of its own. Returns the check's id - its notices and its conclusion carry it - or
100
- * why it was refused: the sentinel off or not started this session, a module not there or that does not parse, a
101
- * module outside its chain, a func-id a module does not have, one not built in its codebase as its ***plain has it now.
102
- */
103
- check(request: CheckRequest): {
104
- check: string;
105
- } | {
106
- refused: string;
107
- };
108
- /**
109
- * Every value /settings offers for a setting after `typed` - what its completions compute, in their order, but
110
- * whole: uncapped, and without "unset", which a host draws itself; the values alone, not `<key> <value>`. A model
111
- * setting's are every model of every provider signed in to, from the model registry the chats use - and after a colon,
112
- * `harness-model amazon-bedrock/global.anthropic.claude-opus-5-5:`, that model's thinking levels. An unknown key gives none.
113
- */
114
- settingChoices(key: string, typed?: string): string[];
115
- /**
116
- * Conformance tests turned on, as /conform does before it tests - the person's decision, a host's switch for it:
117
- * `conformance-tests: true` written where the module's value comes from - its own `config.turri.<module>.yaml`, or a required module's, when
118
- * that sets the key, else `config.turri.yaml` - the chats' conform no longer refused. `plainFile`, absolute or from the
119
- * project, picks the module; omitted,
120
- * the project's. Returns the file written, from the project. Starts no conformance pulse: that is `conform`'s.
121
- */
122
- turnOnConformanceTests(plainFile?: string): string;
123
- /**
124
- * A notice answered: one of its actions (by index or label) - the chat it is in started on it - the person's own words
125
- * about it, dismissed, or - `ignorable: true` - ignored for good: left as the build has it, the sentinel told not to
126
- * raise it again. `refused` for `ignore` on one that is not ignorable, `over` when it was answered or superseded
127
- * already, `missing` for one never put.
128
- */
129
- answer(id: string, answer: NoticeAnswer): Promise<"done" | "dismissed" | "ignored" | "refused" | "missing" | "over">;
130
- /** Told when a chat is opened, closed, renamed, or starts or stops working. */
131
- onChats(listener: (chats: ChatInfo[]) => void): () => void;
132
- /** Every chat let go, and what launches started stopped. */
133
- dispose(): Promise<void>;
134
- }
135
- /** turri's session in a host, in the process's working folder - the project's. */
136
- export declare function createTurri(options?: TurriOptions): Promise<Turri>;
@@ -1,139 +0,0 @@
1
- import { createAgentSession, DefaultResourceLoader, getAgentDir, SessionManager } from "@earendil-works/pi-coding-agent";
2
- import { lastRun } from "./chat-records.js";
3
- import { resolve } from "node:path";
4
- import { isChatEntry } from "./chat-entries.js";
5
- import { emitSessionEvent } from "./session-events.js";
6
- import { lookAhead, nextPulses } from "./preview.js";
7
- import { projectStanding } from "./regenerate/standing.js";
8
- import { interruptChat } from "./chats.js";
9
- import { reachable, ruleNames, settingCandidates } from "./settings.js";
10
- import { settingOf } from "./config-edit.js";
11
- import { createTurriCore, plannedLoop, sessionLaunchesOf, sessionLoop, turnOnConformance } from "./extension.js";
12
- import { stopLaunched } from "./regenerate/launch.js";
13
- import { prepareCheck } from "./sentinel-check.js";
14
- /** turri's session in a host, in the process's working folder - the project's. */
15
- export async function createTurri(options = {}) {
16
- const { dialogs, uiContext, extensions = [], agentDir = getAgentDir(), sessionDir, restore, ...host } = options;
17
- const core = createTurriCore(host, { mode: "host", persist: true, ...(dialogs !== undefined ? { dialogs } : {}) });
18
- const cwd = core.cwd;
19
- core.setDriver({
20
- async create(chat, sessionFile) {
21
- const resourceLoader = new DefaultResourceLoader({ cwd, agentDir, extensionFactories: [core.extension, ...extensions] });
22
- await resourceLoader.reload();
23
- const sessionManager = sessionFile !== undefined ? SessionManager.open(sessionFile, sessionDir) : SessionManager.create(cwd, sessionDir);
24
- const { session } = await createAgentSession({ cwd, agentDir, resourceLoader, sessionManager });
25
- chat.session = session;
26
- // Listen before binding: the banner and other session_start entries precede openChat's return.
27
- if (host.onEvent)
28
- session.subscribe((event) => {
29
- // pi announces a custom entry as entry_appended but a delivered custom message as message_end.
30
- const entry = event.type === "entry_appended" ? event.entry : event.type === "message_end" && event.message.role === "custom"
31
- ? { type: "custom_message", customType: event.message.customType, content: event.message.content, details: event.message.details, display: event.message.display } : undefined;
32
- if (entry && isChatEntry(entry))
33
- emitSessionEvent(host, { type: "entry", chat: chat.id, entry });
34
- });
35
- try {
36
- await session.bindExtensions({ uiContext: uiContext?.(chat.id), mode: "tui" });
37
- }
38
- catch (error) {
39
- session.dispose();
40
- throw error;
41
- }
42
- },
43
- async dispose(chat) {
44
- const session = chat.session;
45
- if (session === undefined)
46
- return;
47
- try {
48
- await session.abort();
49
- }
50
- finally {
51
- session.dispose();
52
- }
53
- },
54
- });
55
- if (restore === true) {
56
- const saved = lastRun(cwd);
57
- if (saved !== undefined)
58
- await core.restore(saved);
59
- const first = core.chats()[0];
60
- if (first !== undefined)
61
- await core.show(first.id);
62
- }
63
- let lastStop = 0;
64
- const dispose = async () => {
65
- await core.dispose();
66
- await stopLaunched();
67
- };
68
- return {
69
- launches: () => structuredClone(sessionLaunchesOf(core.jobs).track.list()),
70
- spending: core.spending,
71
- jobs: () => core.jobs.list(),
72
- job: (id) => core.jobs.get(id),
73
- status() {
74
- const loop = plannedLoop(core.jobs);
75
- const planned = loop?.planned() ?? [];
76
- const held = new Set(planned.filter((job) => job.lookedAhead).map((job) => job.module));
77
- return { modules: (loop?.status() ?? []).map((row) => held.has(row.module) ? { ...row, lookedAhead: true } : row), jobs: core.jobs.list().filter((job) => !job.replacedBy), planned };
78
- },
79
- standing: (files) => projectStanding(cwd, { files, loop: plannedLoop(core.jobs) }),
80
- async lookAhead(plainFile) {
81
- const loop = sessionLoop(core);
82
- const statuses = await lookAhead(loop, resolve(cwd, plainFile));
83
- const next = [];
84
- for await (const pulse of nextPulses(loop, statuses))
85
- next.push(pulse);
86
- return { statuses, next };
87
- },
88
- entries: (id) => core.session(id)?.sessionManager.getBranch().filter(isChatEntry) ?? [],
89
- chats: () => core.chats(),
90
- session: (id) => core.session(id),
91
- async openChat(asked = {}) {
92
- const chat = await core.open(asked);
93
- return { ...chat, session: core.session(chat.id) };
94
- },
95
- closeChat: (id) => core.close(id),
96
- focus: (id) => void core.show(id),
97
- async interrupt(id) {
98
- const session = core.session(id);
99
- if (session === undefined)
100
- return "missing";
101
- const did = interruptChat(session, { lastStop, idle: () => "ended" });
102
- if (did === "stopped")
103
- lastStop = Date.now();
104
- if (did === "ended")
105
- await dispose();
106
- return did;
107
- },
108
- decline: async (id) => core.decline(id),
109
- notices: () => core.notices(),
110
- check: (request) => core.check(() => prepareCheck(cwd, request)),
111
- turnOnConformanceTests: (plainFile) => turnOnConformance(core, plainFile),
112
- settingChoices: (key, typed = "") => {
113
- const setting = settingOf(key, ruleNames());
114
- if (setting === undefined)
115
- return [];
116
- // The models from a chat's own context - the one shown, else any open: the registry the chats use, whether or not one
117
- // has run /settings.
118
- const context = () => {
119
- const shown = core.shownChat();
120
- const states = [shown, ...core.chats().map((chat) => core.session(chat.id)).map((session) => (session !== undefined ? core.chatOfSession(session) : undefined))];
121
- for (const state of states) {
122
- try {
123
- const context = state?.instance?.context();
124
- if (context !== undefined)
125
- return context;
126
- }
127
- catch {
128
- /* a context let go: the next one */
129
- }
130
- }
131
- return undefined;
132
- };
133
- return settingCandidates(setting, typed, { cwd, models: () => reachable(context()) });
134
- },
135
- answer: async (id, answer) => core.answer(id, answer),
136
- onChats: (listener) => core.onChats(() => listener(core.chats())),
137
- dispose,
138
- };
139
- }
package/dist/host.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export { machineChange, machineChangeReason } from "./regenerate/command-check.ts";
2
- export { doctor, type Check, type DoctorOptions, type Level } from "./setup.ts";
3
- export { installedModelRuntime, EXTENSION_PROVIDERS } from "./installed-providers.ts";
4
- /** The conversations pi has saved for the project, including ones not open in a chat. */
5
- export declare function savedChatFiles(cwd: string, sessionDir?: string): Promise<string[]>;
6
- /** The path a sign-in sheet shows; credentials are managed by the model runtime. */
7
- export declare function credentialsFile(agentDir?: string): string;
8
- export declare function loginDeviceId(cwd: string, agentDir?: string): string;
package/dist/host.js DELETED
@@ -1,17 +0,0 @@
1
- /** Operations a desktop host needs besides its session. pi itself is a shared peer. */
2
- import { join } from "node:path";
3
- import { getAgentDir, SessionManager, SettingsManager } from "@earendil-works/pi-coding-agent";
4
- export { machineChange, machineChangeReason } from "./regenerate/command-check.js";
5
- export { doctor } from "./setup.js";
6
- export { installedModelRuntime, EXTENSION_PROVIDERS } from "./installed-providers.js";
7
- /** The conversations pi has saved for the project, including ones not open in a chat. */
8
- export async function savedChatFiles(cwd, sessionDir) {
9
- return (await SessionManager.list(cwd, sessionDir)).map((session) => session.path);
10
- }
11
- /** The path a sign-in sheet shows; credentials are managed by the model runtime. */
12
- export function credentialsFile(agentDir = getAgentDir()) {
13
- return join(agentDir, "auth.json");
14
- }
15
- export function loginDeviceId(cwd, agentDir = getAgentDir()) {
16
- return SettingsManager.create(cwd, agentDir).getOrCreateDeviceId();
17
- }
package/dist/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- /** One project's session. Terminal integration and independent project readers have their own entries. */
2
- export { createTurri, type Turri, type TurriOptions } from "./host-session.ts";
3
- export { MAX_CHATS, type ChatInfo, type ChatStatus, type TurriHost } from "./chats.ts";
4
- export { isChatEntry, type ChatEntry } from "./chat-entries.ts";
5
- export type { SessionEvent, SkillProgress } from "./session-events.ts";
6
- export type { SessionSpending } from "./session-spending.ts";
7
- export { capturePhases, type CaptureStatus } from "./capture/progress.ts";
8
- export type { CaptureResult } from "./capture/capture.ts";
9
- export { SENTINEL, SENTINEL_START, type Conclusion, type Notice, type NoticeAction, type NoticeAnswer, type NoticeSeverity, type NoticeState, type SentinelCheck } from "./notice.ts";
10
- export type { CheckRequest } from "./sentinel-check.ts";
11
- export type { AskUserIO } from "./ask.ts";
12
- export { launchText, type Launch, type LaunchStatus, type LaunchStopped } from "./launch-track.ts";
13
- export type { Job, PulseCases, PulseSpec } from "./regenerate/jobs.ts";
14
- export type { TranscriptEntry } from "./regenerate/activity.ts";
15
- export type { DriftReport, ModuleStatus, PlannedPulse } from "./regenerate/loop.ts";
16
- export type { ModuleStanding } from "./regenerate/standing.ts";
package/dist/index.js DELETED
@@ -1,7 +0,0 @@
1
- /** One project's session. Terminal integration and independent project readers have their own entries. */
2
- export { createTurri } from "./host-session.js";
3
- export { MAX_CHATS } from "./chats.js";
4
- export { isChatEntry } from "./chat-entries.js";
5
- export { capturePhases } from "./capture/progress.js";
6
- export { SENTINEL, SENTINEL_START } from "./notice.js";
7
- export { launchText } from "./launch-track.js";
@@ -1,21 +0,0 @@
1
- import type { Conclusion, Notice } from "./notice.ts";
2
- /** The terminal session's inbox. A notice keeps its identity and live state from the session that answers it. */
3
- export interface TerminalNotification {
4
- title: string;
5
- detail: string;
6
- conclusion?: string;
7
- warning?: boolean;
8
- notice?: Notice;
9
- seen: boolean;
10
- }
11
- export declare class TerminalNotifications {
12
- readonly items: TerminalNotification[];
13
- private readonly reviews;
14
- get count(): number;
15
- needsAnswer(item: TerminalNotification): boolean;
16
- add(title: string, detail: string, options?: Pick<TerminalNotification, "notice" | "warning">): void;
17
- /** Only the sentinel's review shares a row. The pulse result and the question whether to start it are independent. */
18
- private review;
19
- put(notice: Notice, work?: Pick<Conclusion, "job" | "check">): void;
20
- concluded(result: Conclusion): void;
21
- }
@@ -1,44 +0,0 @@
1
- export class TerminalNotifications {
2
- items = [];
3
- reviews = new Map();
4
- get count() {
5
- return this.items.filter((item) => !item.seen || this.needsAnswer(item)).length;
6
- }
7
- needsAnswer(item) {
8
- return item.notice?.state === "open" && item.notice.kind !== "fixed";
9
- }
10
- add(title, detail, options = {}) {
11
- this.items.unshift({ title, detail, seen: false, ...options });
12
- }
13
- /** Only the sentinel's review shares a row. The pulse result and the question whether to start it are independent. */
14
- review(about, title) {
15
- const key = about.check ? `check:${about.check}` : about.job ? `pulse:${about.job}` : undefined;
16
- const known = key && this.reviews.get(key);
17
- if (known)
18
- return known;
19
- const item = { title, detail: "", seen: false };
20
- this.items.unshift(item);
21
- if (key)
22
- this.reviews.set(key, item);
23
- return item;
24
- }
25
- put(notice, work) {
26
- const about = [notice.module, notice.pulse !== undefined ? `pulse ${notice.pulse}` : undefined].filter(Boolean).join(" · ");
27
- const heading = notice.kind === "fixed" ? "Fixed" : "Sentinel";
28
- const title = [heading, about, notice.summary].filter(Boolean).join(" · ");
29
- const detail = notice.evidence.join("\n\n");
30
- if (notice.kind === "sentinel-start")
31
- return this.add(title, detail, { notice });
32
- const item = this.review(work ?? notice, title);
33
- if (!item.conclusion)
34
- item.warning = notice.severity !== "info";
35
- Object.assign(item, { title, detail, notice, seen: false });
36
- }
37
- concluded(result) {
38
- const what = result.pulse !== undefined ? `pulse ${result.pulse}` : result.job ?? result.check;
39
- const verdict = result.verdict === "holds" ? "it holds" : result.verdict === "wrong" ? "found something wrong" : "not checked";
40
- const item = this.review(result, ["Sentinel", result.module, what, verdict].filter(Boolean).join(" · "));
41
- item.conclusion = `${verdict}: ${result.summary}`;
42
- item.warning = result.verdict !== "holds";
43
- }
44
- }
package/dist/reopen.d.ts DELETED
@@ -1,29 +0,0 @@
1
- /**
2
- * turri opened again in another folder, in the same terminal, once its chat has quit: a chat works on the project of
3
- * the folder it was opened in, and after a capture the work is in another - `plain/`, a project of its own. `turri`
4
- * (cli.ts) starts the chat as a process of its own, with turri's theme, its screen and the folder's models, and names
5
- * it a file to write in: a chat that is to open again elsewhere writes where, with what, and quits; `turri` reads it and
6
- * starts the chat there as it started the first - the theme, the screen and that folder's models worked out the same.
7
- * A chat `turri` did not start - a host's, a desktop app's - has no file, and is never offered it.
8
- */
9
- /** The file the chat `turri` started writes where it is to open again. */
10
- export declare const REOPEN_FILE_ENV = "TURRI_REOPEN_FILE";
11
- /** Said to the chat opened again, at its start: the capture whose report it tells - what the capture said of itself. */
12
- export declare const REOPENED_AFTER_CAPTURE = "TURRI_REOPENED_AFTER_CAPTURE";
13
- export interface Reopening {
14
- /** The folder the chat opens in. */
15
- dir: string;
16
- /** Its arguments, as `turri` takes them. */
17
- args: string[];
18
- /** What it is told at its start, in its environment. */
19
- env: Record<string, string>;
20
- }
21
- /** Whether this chat can open again in another folder: `turri` started it. */
22
- export declare function canReopen(): boolean;
23
- /** Ask `turri` to open the chat again in `dir` once it has quit - the caller quits it. False when it cannot (`canReopen`). */
24
- export declare function reopenIn(dir: string, options?: {
25
- args?: string[];
26
- env?: Record<string, string>;
27
- }): boolean;
28
- /** What the chat that quit asked for, taken - its file removed - or undefined when it asked for nothing. */
29
- export declare function takeReopening(file: string): Reopening | undefined;