@turri-dev/cli 0.4.2 → 0.4.3-next.8482fed

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 (99) hide show
  1. package/README.md +1 -0
  2. package/dist/background-skills.d.ts +4 -1
  3. package/dist/background-skills.js +9 -1
  4. package/dist/capture/agents.d.ts +361 -0
  5. package/dist/capture/agents.js +332 -0
  6. package/dist/capture/area.d.ts +58 -0
  7. package/dist/capture/area.js +197 -0
  8. package/dist/capture/assemble.d.ts +122 -0
  9. package/dist/capture/assemble.js +452 -0
  10. package/dist/capture/capture.d.ts +116 -0
  11. package/dist/capture/capture.js +1228 -0
  12. package/dist/capture/chat.d.ts +29 -0
  13. package/dist/capture/chat.js +94 -0
  14. package/dist/capture/checks.d.ts +142 -0
  15. package/dist/capture/checks.js +643 -0
  16. package/dist/capture/config.d.ts +13 -0
  17. package/dist/capture/config.js +60 -0
  18. package/dist/capture/interface.d.ts +71 -0
  19. package/dist/capture/interface.js +199 -0
  20. package/dist/capture/map.d.ts +56 -0
  21. package/dist/capture/map.js +530 -0
  22. package/dist/capture/progress.d.ts +108 -0
  23. package/dist/capture/progress.js +234 -0
  24. package/dist/capture/report.d.ts +75 -0
  25. package/dist/capture/report.js +267 -0
  26. package/dist/capture/scripts.d.ts +26 -0
  27. package/dist/capture/scripts.js +33 -0
  28. package/dist/capture/state.d.ts +296 -0
  29. package/dist/capture/state.js +43 -0
  30. package/dist/capture/trial.d.ts +34 -0
  31. package/dist/capture/trial.js +89 -0
  32. package/dist/capture-cli.d.ts +1 -0
  33. package/dist/capture-cli.js +77 -0
  34. package/dist/chat-commands.d.ts +2 -10
  35. package/dist/chat-commands.js +3 -57
  36. package/dist/chat-tab-header.d.ts +15 -0
  37. package/dist/chat-tab-header.js +78 -0
  38. package/dist/chat-tabs.d.ts +20 -0
  39. package/dist/chat-tabs.js +96 -0
  40. package/dist/chat-terminal.js +54 -8
  41. package/dist/chat-waiting.d.ts +4 -1
  42. package/dist/chat-waiting.js +7 -4
  43. package/dist/chats.d.ts +2 -0
  44. package/dist/cli.js +32 -14
  45. package/dist/config-edit.js +1 -0
  46. package/dist/config.d.ts +15 -2
  47. package/dist/config.js +57 -3
  48. package/dist/extension.js +140 -7
  49. package/dist/identity.js +2 -1
  50. package/dist/init-config.js +1 -0
  51. package/dist/loop-cli.js +5 -1
  52. package/dist/loop-tools.js +5 -1
  53. package/dist/new-project.d.ts +5 -0
  54. package/dist/new-project.js +11 -0
  55. package/dist/pi.js +2 -2
  56. package/dist/plain-code-blocks.d.ts +14 -0
  57. package/dist/plain-code-blocks.js +56 -0
  58. package/dist/pointer-hover.d.ts +12 -0
  59. package/dist/pointer-hover.js +44 -0
  60. package/dist/regenerate/command-check.js +80 -11
  61. package/dist/regenerate/jobs-tree.d.ts +1 -0
  62. package/dist/regenerate/jobs-tree.js +5 -1
  63. package/dist/regenerate/loop.js +9 -1
  64. package/dist/regenerate/side-panel.d.ts +4 -1
  65. package/dist/regenerate/side-panel.js +131 -22
  66. package/dist/regenerate/spec-map-view.d.ts +9 -1
  67. package/dist/regenerate/spec-map-view.js +22 -2
  68. package/dist/regenerate/test-scripts.d.ts +5 -0
  69. package/dist/regenerate/test-scripts.js +4 -0
  70. package/dist/reopen.d.ts +29 -0
  71. package/dist/reopen.js +47 -0
  72. package/dist/resume-line.d.ts +4 -1
  73. package/dist/resume-line.js +5 -2
  74. package/dist/setup.js +9 -1
  75. package/docs/README.md +2 -0
  76. package/docs/capture.md +191 -0
  77. package/docs/chats.md +6 -5
  78. package/docs/config.md +14 -2
  79. package/docs/development.md +4 -1
  80. package/docs/regenerating.md +1 -1
  81. package/docs/sandbox.md +2 -2
  82. package/docs/theming.md +2 -2
  83. package/docs/using.md +9 -1
  84. package/genome/capture/capture.md +26 -0
  85. package/genome/capture/check-conventions.md +5 -0
  86. package/genome/capture/check-reference.md +11 -0
  87. package/genome/capture/concepts.md +3 -0
  88. package/genome/capture/divide.md +9 -0
  89. package/genome/capture/feature.md +45 -0
  90. package/genome/capture/interface.md +9 -0
  91. package/genome/capture/modules.md +23 -0
  92. package/genome/capture/outline.md +11 -0
  93. package/genome/capture/readability.md +12 -0
  94. package/genome/capture/reference.md +10 -0
  95. package/genome/capture/split.md +9 -0
  96. package/genome/capture/survey.md +37 -0
  97. package/genome/capture/trial.md +18 -0
  98. package/genome/capture/verify.md +7 -0
  99. package/package.json +3 -3
@@ -0,0 +1,296 @@
1
+ import type { SurfaceKind } from "./map.ts";
2
+ /**
3
+ * What a capture keeps as it goes, in `<plain>/.turri/capture/state.json`: every agent's answer, saved as it comes. A
4
+ * capture stopped part-way - turri quit, the machine slept - is started again from it, asking no agent twice; a capture
5
+ * that finished is never run over.
6
+ */
7
+ export declare const STATE_VERSION = 1;
8
+ export interface Definition {
9
+ /** `:Note:`. */
10
+ concept: string;
11
+ /** The definition's text, starting with the concept: `:Note: is a short text a :User: keeps.` */
12
+ text: string;
13
+ }
14
+ export interface LeftOut {
15
+ path: string;
16
+ why: string;
17
+ }
18
+ /**
19
+ * What every feature of a part does the same way and a user or a script relies on - how an error is written, the exit
20
+ * code or status of each kind of failure, how it acts when its input or output is not a terminal, what reaches the other
21
+ * side of a call it makes or answers - settled once, by the survey, from the code that does it, and handed to every writer
22
+ * as settled.
23
+ */
24
+ export interface Convention {
25
+ /** One fact, exact: `A usage error prints the usage and the message to standard error and exits with 1.` */
26
+ text: string;
27
+ /** The files whose code decides it. */
28
+ where: string[];
29
+ }
30
+ /** A part of the codebase on a stack of its own - a backend, a frontend - captured as a chain of modules of its own. */
31
+ export interface Part {
32
+ name: string;
33
+ about: string;
34
+ paths: string[];
35
+ /** The standard library's stack it imports, when one matches the original without contradicting it. */
36
+ stdlibStack?: string;
37
+ /** Whether it imports that stack's conformance template too. */
38
+ stdlibConformance?: boolean;
39
+ implementationReqs: string[];
40
+ /** Absent in a capture started before conventions were settled. */
41
+ conventions?: Convention[];
42
+ testReqs: string[];
43
+ definitions: Definition[];
44
+ }
45
+ export interface Survey {
46
+ parts: Part[];
47
+ leftOut: LeftOut[];
48
+ assumptions: string[];
49
+ }
50
+ /** A surface of the code's interface - an option, a command, a route, a screen, an environment variable - and its file. */
51
+ export interface InterfaceSurface {
52
+ path: string;
53
+ kind: SurfaceKind | InterfaceKind;
54
+ name: string;
55
+ }
56
+ export type InterfaceKind = "command" | "argument" | "option" | "route" | "env" | "other";
57
+ /**
58
+ * One piece of the software's interface as the code defines it - what a user, a client or a script calls by name -
59
+ * taken from the code by an agent, every literal it gives checked against the code it cites. The entries of a part are
60
+ * its interface reference, a linked resource every functional spec about it carries: exact where prose would guess.
61
+ */
62
+ export interface InterfaceEntry {
63
+ kind: InterfaceKind;
64
+ /** Exactly as the code has it: `--proxy`, `http`, `httpie plugins install`, `GET /notes/{id}`, `HTTPIE_CONFIG_DIR`. */
65
+ name: string;
66
+ /** Every other name it has: `-x`. */
67
+ aliases: string[];
68
+ /** The command an argument or an option belongs to: `http`, `httpie plugins install`. */
69
+ command?: string;
70
+ /** What it takes: its value's form or type - `PROTOCOL:PROXY_URL`, `int`, `a JSON body`. */
71
+ takes?: string;
72
+ /** The values it accepts, when the code lists them, each as the code has it. */
73
+ choices: string[];
74
+ /** Its default, as the code has it. */
75
+ default?: string;
76
+ repeatable?: boolean;
77
+ required?: boolean;
78
+ /** Left out of its help. */
79
+ hidden?: boolean;
80
+ /** Its help text, word for word. */
81
+ help?: string;
82
+ /** A route's parameters, fields and answers, a line each: `query page: int, 1 by default`, `201: the note created`. */
83
+ details: string[];
84
+ /** Where it is defined, `path:line`. */
85
+ where: string;
86
+ /** Other files its literals come from: where a default or the choices are worked out. */
87
+ also: string[];
88
+ }
89
+ /** A surface of the map left out of the reference, with why: an option of a development script, say. */
90
+ export interface InterfaceExclusion {
91
+ name: string;
92
+ path: string;
93
+ why: string;
94
+ }
95
+ /** What one agent took of a part's interface from some of its files - or why it could not. */
96
+ export type InterfaceBatch = {
97
+ entries: InterfaceEntry[];
98
+ excluded: InterfaceExclusion[];
99
+ /** Its check against the code, by a fresh agent: what it changed and why, or why it did not hold. */
100
+ checked?: {
101
+ changes: string[];
102
+ } | {
103
+ failed: string;
104
+ };
105
+ } | {
106
+ failed: string;
107
+ };
108
+ /** A feature of a leaf area, as its outline names it: what a feature writer is given to capture. */
109
+ export interface FeatureOutline {
110
+ name: string;
111
+ title: string;
112
+ about: string;
113
+ /** The folders and files it owns, where its writer starts looking. */
114
+ paths: string[];
115
+ /**
116
+ * Set on a feature the harness added once the features were written: the interface of its area's code that no
117
+ * feature captured, which its writer captures - every one, or says why it is not the software's interface.
118
+ */
119
+ interface?: InterfaceSurface[];
120
+ }
121
+ /** A correction the interface check made to a functional spec or to one of its scenarios: its whole new text, and why. */
122
+ export interface Correction {
123
+ funcId: string;
124
+ /** The scenario corrected, when it is a scenario. */
125
+ scenarioId?: string;
126
+ text: string;
127
+ why: string;
128
+ }
129
+ export interface Scenario {
130
+ id: string;
131
+ text: string;
132
+ }
133
+ export interface CapturedSpec {
134
+ funcId: string;
135
+ text: string;
136
+ conformance: Scenario[];
137
+ acceptance: Scenario[];
138
+ }
139
+ /** What a feature writer captured of one feature. */
140
+ export interface CapturedFeature {
141
+ specs: CapturedSpec[];
142
+ definitions: Definition[];
143
+ uncertain: string[];
144
+ dropped: string[];
145
+ assumptions: string[];
146
+ }
147
+ export interface AreaState {
148
+ id: string;
149
+ name: string;
150
+ about: string;
151
+ paths: string[];
152
+ part: string;
153
+ /** Split into areas, or a leaf outlined into features - or neither yet. */
154
+ children?: string[];
155
+ features?: FeatureOutline[];
156
+ leftOut?: LeftOut[];
157
+ /** Why it could not be captured, when it could not. */
158
+ failed?: string;
159
+ }
160
+ /**
161
+ * A part's features divided, once every area is outlined and before any is written: each behaviour one feature's. The
162
+ * outlines are made area by area, each from its own files, so the same behaviour - an option parsed in one area, acted
163
+ * on in another - can be outlined twice; written twice, it says the same in different words, or contradicts itself.
164
+ */
165
+ export interface Division {
166
+ /** What each feature that stays alone captures, by feature key. */
167
+ owns: Record<string, string>;
168
+ /** Features whose behaviour others own whole, by key: the features that took it, and why. Never written. */
169
+ merged: Record<string, {
170
+ into: string[];
171
+ why: string;
172
+ }>;
173
+ /** Why the features were not divided, when they were not: each owns what it was outlined for. */
174
+ failed?: string;
175
+ }
176
+ /** A module of a part as its features were gathered: its concern, its features, and what it needs of the modules before it. */
177
+ export interface GatheredModule {
178
+ /** Short kebab-case: the concern - `output-formatting`, `sessions`. */
179
+ name: string;
180
+ about: string;
181
+ /** Its features, by key, in the order its functional specs are written. */
182
+ features: string[];
183
+ /** The modules before it whose behaviour its functional specs build on and its scenarios run, by name. */
184
+ needs: string[];
185
+ }
186
+ /** A scenario rewritten so it needs only the modules before its own: its feature, its functional spec, its whole new text and why. */
187
+ export interface ModuleRewrite {
188
+ /** The feature's key. */
189
+ feature: string;
190
+ funcId: string;
191
+ scenarioId: string;
192
+ text: string;
193
+ why: string;
194
+ }
195
+ /**
196
+ * A part's features gathered into modules by concern and put in the order they are built, once every feature is written.
197
+ * A module is a concern of its own - what a person looks for in one file - never one that holds everything. It is built
198
+ * on the code of the modules before it, and its scenarios run as soon as it is: a module whose scenarios send a request
199
+ * comes after the one that sends it, whatever the code's imports say.
200
+ */
201
+ export interface PartModules {
202
+ /** In the order they are built. */
203
+ modules: GatheredModule[];
204
+ /** Scenarios that needed a module after their own whatever the order, rewritten. */
205
+ rewrites: ModuleRewrite[];
206
+ /** Why the modules are as the code's areas make them, in the order of their code, when they are. */
207
+ failed?: string;
208
+ }
209
+ /** What the original did with a scenario run against it as its conformance test will run it. */
210
+ export type TrialOutcome = "held" | "corrected" | "removed" | "untried";
211
+ export interface TrialResult {
212
+ funcId: string;
213
+ scenarioId: string;
214
+ outcome: TrialOutcome;
215
+ /** What was run against the original, and what it answered. */
216
+ ran: string;
217
+ /** A corrected scenario's whole new text. */
218
+ text?: string;
219
+ /** Why it was corrected, removed or not tried. */
220
+ why?: string;
221
+ }
222
+ /**
223
+ * What one agent found trying some of a module's scenarios on a copy of the original: each scenario's outcome, the
224
+ * functional specs the original contradicts, corrected, and what a conformance test must set up - or why it could not.
225
+ */
226
+ export type TrialBatch = {
227
+ results: TrialResult[];
228
+ specs: Correction[];
229
+ testReqs: string[];
230
+ } | {
231
+ failed: string;
232
+ };
233
+ export interface FeatureState {
234
+ /** `<area id>#<feature name>`. */
235
+ key: string;
236
+ captured?: CapturedFeature;
237
+ failed?: string;
238
+ }
239
+ export interface CaptureState {
240
+ version: number;
241
+ /** The codebase captured, absolute. */
242
+ root: string;
243
+ started: string;
244
+ survey?: Survey;
245
+ /** The areas by id, each part's root area named as the part. */
246
+ areas: Record<string, AreaState>;
247
+ /** Each part's interface taken from the code, by part, then by the files each agent was given (their paths joined). */
248
+ interfaces?: Record<string, Record<string, InterfaceBatch>>;
249
+ /** Parts whose interface reference is whole: every batch answered - and its concept defined. */
250
+ interfaceTaken?: string[];
251
+ /** Each part's conventions checked against the code, by part: what the check changed and why, or why it did not hold. */
252
+ conventionsChecked?: Record<string, {
253
+ changes: string[];
254
+ failed?: string;
255
+ }>;
256
+ /** Each part's features divided, by part - absent until its areas are all outlined. */
257
+ divided?: Record<string, Division>;
258
+ /** Parts whose interface no feature captured was given to writers of its own, once every feature was written. */
259
+ interfaceFilled?: string[];
260
+ features: Record<string, FeatureState>;
261
+ /** Each part's features gathered into modules by concern, in the order they are built, by part - none for a part of one feature. */
262
+ gathered?: Record<string, PartModules>;
263
+ /** Concepts defined twice with different texts, as reconciled - by concept, a part's. */
264
+ reconciled: Record<string, Record<string, string>>;
265
+ /** The readability pass's new texts, by module and func-id. */
266
+ edits: Record<string, Record<string, string>>;
267
+ /** Modules whose readability pass ran - edited or not. */
268
+ edited: string[];
269
+ /** The interface check's corrections, by module, applied over the readability pass's texts. */
270
+ corrections?: Record<string, Correction[]>;
271
+ /** Modules whose interface was checked against the code - corrected or not. */
272
+ verified?: string[];
273
+ /** Each module's scenarios tried on the original, by module, then by batch - its number, from 1. */
274
+ trials?: Record<string, Record<string, TrialBatch>>;
275
+ /** Modules whose scenarios were all tried on the original - held or not. */
276
+ tried?: string[];
277
+ /** Whether the ***plain files are written: written once, the testing scripts then written for them. */
278
+ written?: boolean;
279
+ /** Each part's testing scripts, by `<part>:<unit | conformance>`: where each is, or why there is none. */
280
+ scripts?: Record<string, ScriptOutcome>;
281
+ finished?: string;
282
+ }
283
+ /** A testing script a capture had written: where it is in the project, or why there is none. */
284
+ export type ScriptOutcome = {
285
+ written: string;
286
+ } | {
287
+ failed: string;
288
+ };
289
+ export declare function captureDir(plainDir: string): string;
290
+ export declare function stateFile(plainDir: string): string;
291
+ export declare function reportFile(plainDir: string): string;
292
+ /** The state a capture left in `plainDir`, or undefined when there is none - or one turri cannot read, which is started over. */
293
+ export declare function readState(plainDir: string): CaptureState | undefined;
294
+ export declare function newState(root: string): CaptureState;
295
+ /** Save the state whole, through a file beside it: a capture stopped mid-write leaves the last state as it was. */
296
+ export declare function saveState(plainDir: string, state: CaptureState): void;
@@ -0,0 +1,43 @@
1
+ import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { ensureInScratch } from "../regenerate/paths.js";
4
+ /**
5
+ * What a capture keeps as it goes, in `<plain>/.turri/capture/state.json`: every agent's answer, saved as it comes. A
6
+ * capture stopped part-way - turri quit, the machine slept - is started again from it, asking no agent twice; a capture
7
+ * that finished is never run over.
8
+ */
9
+ export const STATE_VERSION = 1;
10
+ export function captureDir(plainDir) {
11
+ const scratch = join(plainDir, ".turri");
12
+ return ensureInScratch(scratch, join(scratch, "capture"));
13
+ }
14
+ export function stateFile(plainDir) {
15
+ return join(plainDir, ".turri", "capture", "state.json");
16
+ }
17
+ export function reportFile(plainDir) {
18
+ return join(plainDir, ".turri", "capture", "report.md");
19
+ }
20
+ /** The state a capture left in `plainDir`, or undefined when there is none - or one turri cannot read, which is started over. */
21
+ export function readState(plainDir) {
22
+ const file = stateFile(plainDir);
23
+ if (!existsSync(file))
24
+ return undefined;
25
+ try {
26
+ const state = JSON.parse(readFileSync(file, "utf8"));
27
+ return state.version === STATE_VERSION ? state : undefined;
28
+ }
29
+ catch {
30
+ return undefined;
31
+ }
32
+ }
33
+ export function newState(root) {
34
+ return { version: STATE_VERSION, root, started: new Date().toISOString(), areas: {}, features: {}, reconciled: {}, edits: {}, edited: [] };
35
+ }
36
+ /** Save the state whole, through a file beside it: a capture stopped mid-write leaves the last state as it was. */
37
+ export function saveState(plainDir, state) {
38
+ const file = stateFile(plainDir);
39
+ captureDir(plainDir);
40
+ const temporary = `${file}.${process.pid}.tmp`;
41
+ writeFileSync(temporary, `${JSON.stringify(state, null, 2)}\n`);
42
+ renameSync(temporary, file);
43
+ }
@@ -0,0 +1,34 @@
1
+ import type { AssembledModule } from "./assemble.ts";
2
+ import { type CodeMap } from "./map.ts";
3
+ import type { TrialBatch } from "./state.ts";
4
+ /**
5
+ * The scenarios tried on the original, before the ***plain is written. They are what the regenerated code's conformance
6
+ * tests check, written by agents that read the original's code and tests but never ran it - so a scenario can expect a
7
+ * terminal its test will not give, a site on the internet, wrapping at a width nobody set, or a message the original never
8
+ * prints. A coding agent then builds to it, or its module's conformance tests fail for good. So an agent with a shell on
9
+ * a copy of the original runs each as its conformance test will, and corrects what the original does otherwise.
10
+ */
11
+ /** The most scenarios one agent tries on the original: a module's are tried by as many agents as it takes, one after another. */
12
+ export declare const SCENARIOS_PER_TRIAL = 20;
13
+ /** A scenario as an agent is given it to try. */
14
+ export interface TrialScenario {
15
+ funcId: string;
16
+ scenarioId: string;
17
+ kind: "conformance" | "acceptance";
18
+ text: string;
19
+ }
20
+ /** A module's scenarios, in its order, so many an agent. */
21
+ export declare function trialBatches(module: AssembledModule, size?: number): TrialScenario[][];
22
+ /**
23
+ * A copy of the original codebase, for an agent to install and run without touching it: every file the map has - what
24
+ * git tracks, none of what it ignores, so none of the dependencies installed - and the lock files beside its manifests,
25
+ * which the map leaves out, so the copy installs the versions the original pins; but turri's own config files.
26
+ */
27
+ export declare function copyOriginal(map: CodeMap, target: string): void;
28
+ /**
29
+ * A module with what its scenarios' trials found applied: each scenario the original does otherwise corrected, each that
30
+ * nothing outside can check removed, each functional spec the original contradicts corrected.
31
+ */
32
+ export declare function applyTrials(module: AssembledModule, batches: TrialBatch[]): void;
33
+ /** The test reqs the trials of some modules found a conformance test needs, each once, in the order they were found. */
34
+ export declare function trialTestReqs(batches: TrialBatch[]): string[];
@@ -0,0 +1,89 @@
1
+ import { copyFileSync, existsSync, mkdirSync } from "node:fs";
2
+ import { basename, dirname, join, posix } from "node:path";
3
+ import { LOCK_FILES } from "./map.js";
4
+ /**
5
+ * The scenarios tried on the original, before the ***plain is written. They are what the regenerated code's conformance
6
+ * tests check, written by agents that read the original's code and tests but never ran it - so a scenario can expect a
7
+ * terminal its test will not give, a site on the internet, wrapping at a width nobody set, or a message the original never
8
+ * prints. A coding agent then builds to it, or its module's conformance tests fail for good. So an agent with a shell on
9
+ * a copy of the original runs each as its conformance test will, and corrects what the original does otherwise.
10
+ */
11
+ /** The most scenarios one agent tries on the original: a module's are tried by as many agents as it takes, one after another. */
12
+ export const SCENARIOS_PER_TRIAL = 20;
13
+ /** A module's scenarios, in its order, so many an agent. */
14
+ export function trialBatches(module, size = SCENARIOS_PER_TRIAL) {
15
+ const scenarios = module.features.flatMap((feature) => feature.specs.flatMap((spec) => [
16
+ ...spec.conformance.map((scenario) => ({ funcId: spec.funcId, scenarioId: scenario.id, kind: "conformance", text: scenario.text })),
17
+ ...spec.acceptance.map((scenario) => ({ funcId: spec.funcId, scenarioId: scenario.id, kind: "acceptance", text: scenario.text })),
18
+ ]));
19
+ const batches = [];
20
+ for (let at = 0; at < scenarios.length; at += size)
21
+ batches.push(scenarios.slice(at, at + size));
22
+ return batches;
23
+ }
24
+ /** turri's own config files: a copy holding one would be a turri project of its own, read with its settings. */
25
+ function isTurriConfig(path) {
26
+ return /^config\.turri(\..+)?\.yaml$/.test(basename(path));
27
+ }
28
+ /**
29
+ * A copy of the original codebase, for an agent to install and run without touching it: every file the map has - what
30
+ * git tracks, none of what it ignores, so none of the dependencies installed - and the lock files beside its manifests,
31
+ * which the map leaves out, so the copy installs the versions the original pins; but turri's own config files.
32
+ */
33
+ export function copyOriginal(map, target) {
34
+ const copy = (path) => {
35
+ const to = join(target, ...path.split("/"));
36
+ mkdirSync(dirname(to), { recursive: true });
37
+ try {
38
+ copyFileSync(join(map.root, ...path.split("/")), to);
39
+ }
40
+ catch {
41
+ /* gone since the map was made: nothing to copy */
42
+ }
43
+ };
44
+ for (const file of map.files)
45
+ if (!isTurriConfig(file.path))
46
+ copy(file.path);
47
+ const manifestDirs = new Set(map.files.filter((file) => file.kind === "manifest").map((file) => posix.dirname(file.path)));
48
+ for (const dir of manifestDirs) {
49
+ for (const name of LOCK_FILES) {
50
+ const path = dir === "." ? name : posix.join(dir, name);
51
+ if (existsSync(join(map.root, ...path.split("/"))))
52
+ copy(path);
53
+ }
54
+ }
55
+ }
56
+ /**
57
+ * A module with what its scenarios' trials found applied: each scenario the original does otherwise corrected, each that
58
+ * nothing outside can check removed, each functional spec the original contradicts corrected.
59
+ */
60
+ export function applyTrials(module, batches) {
61
+ const specs = module.features.flatMap((feature) => feature.specs);
62
+ for (const batch of batches) {
63
+ if (!("results" in batch))
64
+ continue;
65
+ for (const correction of batch.specs) {
66
+ const spec = specs.find((candidate) => candidate.funcId === correction.funcId);
67
+ if (spec !== undefined)
68
+ spec.text = correction.text;
69
+ }
70
+ for (const result of batch.results) {
71
+ const spec = specs.find((candidate) => candidate.funcId === result.funcId);
72
+ if (spec === undefined)
73
+ continue;
74
+ if (result.outcome === "corrected" && result.text !== undefined) {
75
+ for (const scenario of [...spec.conformance, ...spec.acceptance])
76
+ if (scenario.id === result.scenarioId)
77
+ scenario.text = result.text;
78
+ }
79
+ if (result.outcome === "removed") {
80
+ spec.conformance = spec.conformance.filter((scenario) => scenario.id !== result.scenarioId);
81
+ spec.acceptance = spec.acceptance.filter((scenario) => scenario.id !== result.scenarioId);
82
+ }
83
+ }
84
+ }
85
+ }
86
+ /** The test reqs the trials of some modules found a conformance test needs, each once, in the order they were found. */
87
+ export function trialTestReqs(batches) {
88
+ return [...new Set(batches.flatMap((batch) => ("testReqs" in batch ? batch.testReqs : [])))];
89
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
1
+ import { relative, resolve } from "node:path";
2
+ import { CaptureError, runCapture } from "./capture/capture.js";
3
+ import { c } from "./module-report.js";
4
+ /**
5
+ * `turri capture [path] [--harness-model <m>] [--coding-model <m>] [--into <folder>] [--parallel <n>]`: capture the
6
+ * codebase at `path` - the current folder by default - into ***plain in `<path>/plain`, offline: nothing is asked, and
7
+ * what was decided is in the report. A capture stopped part-way is gone on with by running it again.
8
+ */
9
+ const USAGE = [
10
+ "usage: turri capture [path] [--harness-model <m>] [--coding-model <m>] [--into <folder>] [--parallel <n>]",
11
+ "",
12
+ "Capture the codebase at path (the current folder by default) into ***plain, in <path>/plain - nothing is asked:",
13
+ "what capture decided, left out or could not capture is in plain/.turri/capture/report.md. Run it again to go on",
14
+ "with a capture that was stopped.",
15
+ "",
16
+ " --harness-model <m> the model capture's agents run on, written into the new project as harness-model",
17
+ " --coding-model <m> written into the new project as coding-model: what regenerates the code later",
18
+ " --into <folder> where the ***plain goes, instead of <path>/plain",
19
+ " --parallel <n> how many agents work at once (4)",
20
+ ].join("\n");
21
+ function option(args, name) {
22
+ const at = args.findIndex((arg) => arg === name || arg.startsWith(`${name}=`));
23
+ if (at === -1)
24
+ return undefined;
25
+ const arg = args[at];
26
+ return arg.includes("=") ? arg.slice(arg.indexOf("=") + 1) : args[at + 1];
27
+ }
28
+ async function main() {
29
+ const args = process.argv.slice(2);
30
+ if (args.includes("-h") || args.includes("--help")) {
31
+ console.log(USAGE);
32
+ return 0;
33
+ }
34
+ // cli.ts hands --coding-model on as --model, as every command's agents take it.
35
+ const valued = ["--harness-model", "--model", "--into", "--parallel"];
36
+ const positional = args.filter((arg, at) => !arg.startsWith("-") && !valued.includes(args[at - 1] ?? ""));
37
+ const unknown = args.filter((arg, at) => arg.startsWith("-") && !valued.some((name) => arg === name || arg.startsWith(`${name}=`)) && !valued.includes(args[at - 1] ?? ""));
38
+ if (positional.length > 1 || unknown.length > 0) {
39
+ console.error(`${unknown.length > 0 ? `unknown option: ${unknown[0]}` : "capture takes one path"}\n\n${USAGE}`);
40
+ return 1;
41
+ }
42
+ const parallelText = option(args, "--parallel");
43
+ const parallel = parallelText !== undefined ? Number.parseInt(parallelText, 10) : undefined;
44
+ if (parallel !== undefined && (!Number.isInteger(parallel) || parallel < 1)) {
45
+ console.error(`--parallel takes a whole number of at least 1, not ${parallelText}.`);
46
+ return 1;
47
+ }
48
+ const root = resolve(positional[0] ?? ".");
49
+ const into = option(args, "--into");
50
+ const harnessModel = option(args, "--harness-model");
51
+ const codingModel = option(args, "--model");
52
+ const started = Date.now();
53
+ console.log(c.bold(`capturing ${root}`));
54
+ try {
55
+ const result = await runCapture({
56
+ root,
57
+ // The captured project starts as the config in use here: the one turri reads where the command is run.
58
+ configFrom: process.cwd(),
59
+ ...(into !== undefined ? { plainDir: resolve(into) } : {}),
60
+ ...(harnessModel !== undefined ? { model: harnessModel, harnessModel } : {}),
61
+ ...(codingModel !== undefined ? { codingModel } : {}),
62
+ ...(parallel !== undefined ? { parallel } : {}),
63
+ progress: (line) => console.log(c.dim(` ${line}`)),
64
+ });
65
+ const minutes = Math.round((Date.now() - started) / 60_000);
66
+ console.log(`\n${c.success(c.bold(result.summary))} ${c.dim(`(${minutes} min)`)}`);
67
+ console.log(c.dim(`the report: ${relative(process.cwd(), result.reportFile) || result.reportFile}`));
68
+ return 0;
69
+ }
70
+ catch (error) {
71
+ console.error(`\n${c.error(c.bold("not captured"))} ${error instanceof Error ? error.message : String(error)}`);
72
+ if (!(error instanceof CaptureError) && error instanceof Error && error.stack !== undefined)
73
+ console.error(c.dim(error.stack));
74
+ return 1;
75
+ }
76
+ }
77
+ process.exit(await main());
@@ -1,8 +1,7 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { type ChatInfo, type TurriCore } from "./chats.ts";
2
+ import { type TurriCore } from "./chats.ts";
3
3
  /**
4
- * The terminal's chats, for the person: `/chat` - new, close, a number, or a pick - its keys, and the strip above the
5
- * editor naming each chat with what it is doing.
4
+ * The keyboard counterparts to the terminal's chat tabs: `/chat` - new, close, a number, or a pick - and its keys.
6
5
  */
7
6
  /** A fresh chat. */
8
7
  export declare const NEW_CHAT_KEY = "alt+n";
@@ -15,11 +14,4 @@ export declare const CLOSE_CHAT_KEY = "alt+w";
15
14
  export declare const OPTION_AS_META: string;
16
15
  /** Said once a session, as its second chat opens, on a Mac. */
17
16
  export declare function tellOfOptionOnce(session: TurriCore, platform?: NodeJS.Platform): void;
18
- /** What a chat's mark in the strip and the picker says it is doing. */
19
- export declare function chatMark(chat: ChatInfo, now?: number): string;
20
- /** The strip: each chat by its number, its title and its mark - the one shown set apart - on one line, a rule between them. */
21
- export declare function chatStrip(chats: ChatInfo[], width: number, style: {
22
- shown: (text: string) => string;
23
- muted: (text: string) => string;
24
- }, now?: number): string[];
25
17
  export declare function registerChats(pi: ExtensionAPI, session: TurriCore): void;
@@ -1,9 +1,7 @@
1
- import { truncateToWidth } from "@earendil-works/pi-tui";
2
1
  import { MAX_CHATS } from "./chats.js";
3
- import { spinner } from "./regenerate/job-panel.js";
2
+ import { chatMark, closeTerminalChat } from "./chat-tabs.js";
4
3
  /**
5
- * The terminal's chats, for the person: `/chat` - new, close, a number, or a pick - its keys, and the strip above the
6
- * editor naming each chat with what it is doing.
4
+ * The keyboard counterparts to the terminal's chat tabs: `/chat` - new, close, a number, or a pick - and its keys.
7
5
  */
8
6
  /** A fresh chat. */
9
7
  export const NEW_CHAT_KEY = "alt+n";
@@ -11,7 +9,6 @@ export const NEW_CHAT_KEY = "alt+n";
11
9
  export const CLOSE_CHAT_KEY = "alt+w";
12
10
  /** alt+1 … alt+9: that chat, shown. */
13
11
  const SHOW_KEYS = Array.from({ length: MAX_CHATS }, (_, index) => `alt+${index + 1}`);
14
- const STRIP_WIDGET = "turri-chats";
15
12
  /**
16
13
  * On a Mac, alt is Option, which types ¡ and ñ unless the terminal sends it as Meta: said once a session, as the second
17
14
  * chat opens - when the keys are first worth having.
@@ -34,33 +31,6 @@ export function tellOfOptionOnce(session, platform = process.platform) {
34
31
  setTimeout(() => session.notify(OPTION_AS_META, "info"), 0);
35
32
  });
36
33
  }
37
- /** What a chat's mark in the strip and the picker says it is doing. */
38
- export function chatMark(chat, now = Date.now()) {
39
- switch (chat.status) {
40
- case "working":
41
- return spinner(now);
42
- case "question":
43
- return "?";
44
- case "unread":
45
- return "•";
46
- default:
47
- return " ";
48
- }
49
- }
50
- /** Between two chats in the strip. */
51
- const STRIP_DELIMITER = " │ ";
52
- /** The strip: each chat by its number, its title and its mark - the one shown set apart - on one line, a rule between them. */
53
- export function chatStrip(chats, width, style, now = Date.now()) {
54
- if (chats.length < 2)
55
- return [];
56
- const room = Math.max(8, Math.floor((width - 2) / chats.length) - STRIP_DELIMITER.length - 4);
57
- const parts = chats.map((chat, index) => {
58
- const mark = chatMark(chat, now).trim();
59
- const label = `${index + 1} ${truncateToWidth(chat.title, room, "…")}${mark !== "" ? ` ${mark}` : ""}`;
60
- return chat.shown ? style.shown(label) : style.muted(label);
61
- });
62
- return [truncateToWidth(` ${parts.join(style.muted(STRIP_DELIMITER))}`, width, "…")];
63
- }
64
34
  const label = (chat, index) => `${index + 1} ${chatMark(chat)} ${chat.title}${chat.shown ? " (shown)" : ""}`;
65
35
  /** What the person asked of the chats, done once pi has finished with the command or key that asked it. */
66
36
  function later(ctx, session, work) {
@@ -88,10 +58,7 @@ function closeChat(ctx, session, which) {
88
58
  const chat = chatNamed(session, which);
89
59
  if (typeof chat === "string")
90
60
  return ctx.ui.notify(chat, "warning");
91
- // The sentinel is not the person's: the last chat of theirs is not closed.
92
- if (chat.role === undefined && session.chats().filter((other) => other.role === undefined).length === 1)
93
- return ctx.ui.notify("This is the only chat - /quit leaves turri.", "info");
94
- later(ctx, session, () => session.close(chat.id));
61
+ later(ctx, session, () => closeTerminalChat(session, chat.id));
95
62
  }
96
63
  function showChat(ctx, session, which) {
97
64
  const chat = chatNamed(session, which);
@@ -139,25 +106,4 @@ export function registerChats(pi, session) {
139
106
  description: `Show chat ${index + 1}`,
140
107
  handler: async (ctx) => showChat(ctx, session, `${index + 1}`),
141
108
  }));
142
- // The strip above the editor, while there are two chats or more: drawn again as they change, and while one works.
143
- pi.on("session_start", (_event, ctx) => {
144
- if (!ctx.hasUI)
145
- return;
146
- ctx.ui.setWidget(STRIP_WIDGET, (tui, theme) => {
147
- const stop = session.onChats(() => tui.requestRender());
148
- const ticker = setInterval(() => {
149
- if (session.chats().some((chat) => chat.status === "working"))
150
- tui.requestRender();
151
- }, 250);
152
- ticker.unref?.();
153
- return {
154
- render: (width) => chatStrip(session.chats(), width, { shown: (text) => theme.bold(theme.fg("accent", text)), muted: (text) => theme.fg("muted", text) }),
155
- invalidate: () => { },
156
- dispose: () => {
157
- stop();
158
- clearInterval(ticker);
159
- },
160
- };
161
- });
162
- });
163
109
  }