@turri-dev/cli 0.4.3-next.620bae9 → 0.4.3-next.7ada234

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 (122) 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 +406 -0
  5. package/dist/capture/agents.js +379 -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 +112 -0
  9. package/dist/capture/assemble.js +453 -0
  10. package/dist/capture/capture.d.ts +116 -0
  11. package/dist/capture/capture.js +1315 -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 +649 -0
  16. package/dist/capture/config.d.ts +13 -0
  17. package/dist/capture/config.js +66 -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/models.d.ts +4 -0
  23. package/dist/capture/models.js +16 -0
  24. package/dist/capture/plan.d.ts +7 -0
  25. package/dist/capture/plan.js +13 -0
  26. package/dist/capture/progress.d.ts +111 -0
  27. package/dist/capture/progress.js +266 -0
  28. package/dist/capture/python-interface.d.ts +3 -0
  29. package/dist/capture/python-interface.js +17 -0
  30. package/dist/capture/report.d.ts +75 -0
  31. package/dist/capture/report.js +268 -0
  32. package/dist/capture/runners.d.ts +6 -0
  33. package/dist/capture/runners.js +59 -0
  34. package/dist/capture/scripts.d.ts +26 -0
  35. package/dist/capture/scripts.js +38 -0
  36. package/dist/capture/state.d.ts +310 -0
  37. package/dist/capture/state.js +43 -0
  38. package/dist/capture/trial.d.ts +34 -0
  39. package/dist/capture/trial.js +89 -0
  40. package/dist/capture-cli.d.ts +1 -0
  41. package/dist/capture-cli.js +77 -0
  42. package/dist/chat-tab-header.d.ts +3 -2
  43. package/dist/chat-tab-header.js +22 -9
  44. package/dist/chat-tabs.d.ts +7 -1
  45. package/dist/chat-tabs.js +10 -6
  46. package/dist/chat-terminal.js +27 -6
  47. package/dist/chats.d.ts +14 -8
  48. package/dist/chats.js +46 -20
  49. package/dist/cli.js +32 -14
  50. package/dist/config-edit.js +5 -2
  51. package/dist/config.d.ts +15 -2
  52. package/dist/config.js +62 -3
  53. package/dist/extension.d.ts +2 -1
  54. package/dist/extension.js +225 -68
  55. package/dist/identity.js +2 -1
  56. package/dist/init-config.d.ts +4 -1
  57. package/dist/init-config.js +31 -4
  58. package/dist/loop-cli.js +5 -1
  59. package/dist/loop-tools.js +5 -1
  60. package/dist/new-project.d.ts +5 -0
  61. package/dist/new-project.js +11 -0
  62. package/dist/pi-launch.js +2 -0
  63. package/dist/pi-themes.d.ts +3 -0
  64. package/dist/pi-themes.js +21 -0
  65. package/dist/pi.d.ts +2 -2
  66. package/dist/pi.js +4 -4
  67. package/dist/plain-code-blocks.d.ts +14 -0
  68. package/dist/plain-code-blocks.js +56 -0
  69. package/dist/pointer-hover.d.ts +1 -1
  70. package/dist/pointer-hover.js +4 -0
  71. package/dist/question-dialog.d.ts +5 -0
  72. package/dist/question-dialog.js +26 -3
  73. package/dist/regenerate/agent-env.js +5 -1
  74. package/dist/regenerate/command-check.js +80 -11
  75. package/dist/regenerate/job-panel.d.ts +5 -107
  76. package/dist/regenerate/job-panel.js +4 -289
  77. package/dist/regenerate/loop.js +9 -1
  78. package/dist/regenerate/side-panel.d.ts +2 -0
  79. package/dist/regenerate/side-panel.js +32 -5
  80. package/dist/regenerate/spec-map-view.d.ts +2 -2
  81. package/dist/regenerate/test-scripts.d.ts +5 -0
  82. package/dist/regenerate/test-scripts.js +4 -0
  83. package/dist/reopen.d.ts +29 -0
  84. package/dist/reopen.js +47 -0
  85. package/dist/sentinel-chat.js +7 -2
  86. package/dist/sentinel.d.ts +1 -1
  87. package/dist/sentinel.js +3 -1
  88. package/dist/setup.js +9 -1
  89. package/dist/terminal-notifications.d.ts +37 -0
  90. package/dist/terminal-notifications.js +164 -0
  91. package/docs/README.md +2 -0
  92. package/docs/capture.md +227 -0
  93. package/docs/chats.md +6 -3
  94. package/docs/config.md +18 -4
  95. package/docs/development.md +4 -1
  96. package/docs/hosting.md +2 -2
  97. package/docs/launch.md +2 -2
  98. package/docs/regenerating.md +1 -1
  99. package/docs/sandbox.md +4 -2
  100. package/docs/sentinel.md +11 -11
  101. package/docs/theming.md +3 -3
  102. package/docs/using.md +7 -3
  103. package/genome/capture/capture.md +26 -0
  104. package/genome/capture/check-conventions.md +5 -0
  105. package/genome/capture/check-reference.md +12 -0
  106. package/genome/capture/compact.md +7 -0
  107. package/genome/capture/concepts.md +3 -0
  108. package/genome/capture/divide.md +9 -0
  109. package/genome/capture/feature.md +45 -0
  110. package/genome/capture/interface.md +9 -0
  111. package/genome/capture/modules.md +25 -0
  112. package/genome/capture/outline.md +11 -0
  113. package/genome/capture/python-interface.py +111 -0
  114. package/genome/capture/readability.md +12 -0
  115. package/genome/capture/reference.md +10 -0
  116. package/genome/capture/runners/python-requirements.sh +67 -0
  117. package/genome/capture/split.md +9 -0
  118. package/genome/capture/survey.md +39 -0
  119. package/genome/capture/trial.md +18 -0
  120. package/genome/capture/verify.md +7 -0
  121. package/genome/rules/turri-regeneration.md +1 -1
  122. package/package.json +1 -1
@@ -0,0 +1,310 @@
1
+ import type { SurfaceKind } from "./map.ts";
2
+ import type { CapturePlan } from "./plan.ts";
3
+ /**
4
+ * What a capture keeps as it goes, in `<plain>/.turri/capture/state.json`: every agent's answer, saved as it comes. A
5
+ * capture stopped part-way - turri quit, the machine slept - is started again from it, asking no agent twice; a capture
6
+ * that finished is never run over.
7
+ */
8
+ export declare const STATE_VERSION = 1;
9
+ export interface Definition {
10
+ /** `:Note:`. */
11
+ concept: string;
12
+ /** The definition's text, starting with the concept: `:Note: is a short text a :User: keeps.` */
13
+ text: string;
14
+ }
15
+ export interface LeftOut {
16
+ path: string;
17
+ why: string;
18
+ }
19
+ /**
20
+ * 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
21
+ * code or status of each kind of failure, how it acts when its input or output is not a terminal, what reaches the other
22
+ * side of a call it makes or answers - settled once, by the survey, from the code that does it, and handed to every writer
23
+ * as settled.
24
+ */
25
+ export interface Convention {
26
+ /** One fact, exact: `A usage error prints the usage and the message to standard error and exits with 1.` */
27
+ text: string;
28
+ /** The files whose code decides it. */
29
+ where: string[];
30
+ }
31
+ /** A part of the codebase on a stack of its own - a backend, a frontend - captured as a chain of modules of its own. */
32
+ export interface Part {
33
+ name: string;
34
+ about: string;
35
+ paths: string[];
36
+ /** The standard library's stack it imports, when one matches the original without contradicting it. */
37
+ stdlibStack?: string;
38
+ /** Whether it imports that stack's conformance template too. */
39
+ stdlibConformance?: boolean;
40
+ implementationReqs: string[];
41
+ /** Absent in a capture started before conventions were settled. */
42
+ conventions?: Convention[];
43
+ testReqs: string[];
44
+ definitions: Definition[];
45
+ /** Stock runners whose complete invocation matches this part, selected in the survey. */
46
+ runners?: {
47
+ unit?: "pytest";
48
+ conformance?: "pytest" | "bats";
49
+ buildDirEnv?: string;
50
+ pythonEnv?: string;
51
+ };
52
+ }
53
+ export interface Survey {
54
+ separateConcerns?: string;
55
+ parts: Part[];
56
+ leftOut: LeftOut[];
57
+ assumptions: string[];
58
+ }
59
+ /** A surface of the code's interface - an option, a command, a route, a screen, an environment variable - and its file. */
60
+ export interface InterfaceSurface {
61
+ path: string;
62
+ kind: SurfaceKind | InterfaceKind;
63
+ name: string;
64
+ }
65
+ export type InterfaceKind = "command" | "argument" | "option" | "route" | "env" | "other";
66
+ /**
67
+ * One piece of the software's interface as the code defines it - what a user, a client or a script calls by name -
68
+ * taken from the code by an agent, every literal it gives checked against the code it cites. The entries of a part are
69
+ * its interface reference, a linked resource every functional spec about it carries: exact where prose would guess.
70
+ */
71
+ export interface InterfaceEntry {
72
+ kind: InterfaceKind;
73
+ /** Exactly as the code has it: `--proxy`, `http`, `httpie plugins install`, `GET /notes/{id}`, `HTTPIE_CONFIG_DIR`. */
74
+ name: string;
75
+ /** Every other name it has: `-x`. */
76
+ aliases: string[];
77
+ /** The command an argument or an option belongs to: `http`, `httpie plugins install`. */
78
+ command?: string;
79
+ /** What it takes: its value's form or type - `PROTOCOL:PROXY_URL`, `int`, `a JSON body`. */
80
+ takes?: string;
81
+ /** The values it accepts, when the code lists them, each as the code has it. */
82
+ choices: string[];
83
+ /** Its default, as the code has it. */
84
+ default?: string;
85
+ repeatable?: boolean;
86
+ required?: boolean;
87
+ /** Left out of its help. */
88
+ hidden?: boolean;
89
+ /** Its help text, word for word. */
90
+ help?: string;
91
+ /** A route's parameters, fields and answers, a line each: `query page: int, 1 by default`, `201: the note created`. */
92
+ details: string[];
93
+ /** Where it is defined, `path:line`. */
94
+ where: string;
95
+ /** Other files its literals come from: where a default or the choices are worked out. */
96
+ also: string[];
97
+ }
98
+ /** A surface of the map left out of the reference, with why: an option of a development script, say. */
99
+ export interface InterfaceExclusion {
100
+ name: string;
101
+ path: string;
102
+ why: string;
103
+ }
104
+ /** What one agent took of a part's interface from some of its files - or why it could not. */
105
+ export type InterfaceBatch = {
106
+ entries: InterfaceEntry[];
107
+ excluded: InterfaceExclusion[];
108
+ /** Its check against the code, by a fresh agent: what it changed and why, or why it did not hold. */
109
+ checked?: {
110
+ changes: string[];
111
+ } | {
112
+ failed: string;
113
+ };
114
+ } | {
115
+ failed: string;
116
+ };
117
+ /** A feature of a leaf area, as its outline names it: what a feature writer is given to capture. */
118
+ export interface FeatureOutline {
119
+ name: string;
120
+ title: string;
121
+ about: string;
122
+ /** The folders and files it owns, where its writer starts looking. */
123
+ paths: string[];
124
+ /**
125
+ * Set on a feature the harness added once the features were written: the interface of its area's code that no
126
+ * feature captured, which its writer captures - every one, or says why it is not the software's interface.
127
+ */
128
+ interface?: InterfaceSurface[];
129
+ }
130
+ /** A correction the interface check made to a functional spec or to one of its scenarios: its whole new text, and why. */
131
+ export interface Correction {
132
+ funcId: string;
133
+ /** The scenario corrected, when it is a scenario. */
134
+ scenarioId?: string;
135
+ text: string;
136
+ why: string;
137
+ }
138
+ export interface Scenario {
139
+ id: string;
140
+ text: string;
141
+ }
142
+ export interface CapturedSpec {
143
+ funcId: string;
144
+ text: string;
145
+ conformance: Scenario[];
146
+ acceptance: Scenario[];
147
+ }
148
+ /** What a feature writer captured of one feature. */
149
+ export interface CapturedFeature {
150
+ specs: CapturedSpec[];
151
+ definitions: Definition[];
152
+ uncertain: string[];
153
+ dropped: string[];
154
+ assumptions: string[];
155
+ }
156
+ export interface AreaState {
157
+ id: string;
158
+ name: string;
159
+ about: string;
160
+ paths: string[];
161
+ part: string;
162
+ /** Split into areas, or a leaf outlined into features - or neither yet. */
163
+ children?: string[];
164
+ features?: FeatureOutline[];
165
+ leftOut?: LeftOut[];
166
+ /** Why it could not be captured, when it could not. */
167
+ failed?: string;
168
+ }
169
+ /**
170
+ * A part's features divided, once every area is outlined and before any is written: each behaviour one feature's. The
171
+ * outlines are made area by area, each from its own files, so the same behaviour - an option parsed in one area, acted
172
+ * on in another - can be outlined twice; written twice, it says the same in different words, or contradicts itself.
173
+ */
174
+ export interface Division {
175
+ /** What each feature that stays alone captures, by feature key. */
176
+ owns: Record<string, string>;
177
+ /** Features whose behaviour others own whole, by key: the features that took it, and why. Never written. */
178
+ merged: Record<string, {
179
+ into: string[];
180
+ why: string;
181
+ }>;
182
+ /** Why the features were not divided, when they were not: each owns what it was outlined for. */
183
+ failed?: string;
184
+ }
185
+ /** A module of a part as its features were gathered: its concern, its features, and what it needs of the modules before it. */
186
+ export interface GatheredModule {
187
+ /** Short kebab-case: the concern - `output-formatting`, `sessions`. */
188
+ name: string;
189
+ about: string;
190
+ /** Its features, by key, in the order its functional specs are written. */
191
+ features: string[];
192
+ /** The modules before it whose behaviour its functional specs build on and its scenarios run, by name. */
193
+ needs: string[];
194
+ }
195
+ /** A scenario rewritten so it needs only the modules before its own: its feature, its functional spec, its whole new text and why. */
196
+ export interface ModuleRewrite {
197
+ /** The feature's key. */
198
+ feature: string;
199
+ funcId: string;
200
+ scenarioId: string;
201
+ text: string;
202
+ why: string;
203
+ }
204
+ /**
205
+ * A part's features gathered into modules by concern and put in the order they are built, once every feature is written.
206
+ * A module is a concern of its own - what a person looks for in one file - never one that holds everything. It is built
207
+ * on the code of the modules before it, and its scenarios run as soon as it is: a module whose scenarios send a request
208
+ * comes after the one that sends it, whatever the code's imports say.
209
+ */
210
+ export interface PartModules {
211
+ /** In the order they are built. */
212
+ modules: GatheredModule[];
213
+ /** Scenarios that needed a module after their own whatever the order, rewritten. */
214
+ rewrites: ModuleRewrite[];
215
+ /** Why the modules are as the code's areas make them, in the order of their code, when they are. */
216
+ failed?: string;
217
+ }
218
+ /** What the original did with a scenario run against it as its conformance test will run it. */
219
+ export type TrialOutcome = "held" | "corrected" | "removed" | "untried";
220
+ export interface TrialResult {
221
+ funcId: string;
222
+ scenarioId: string;
223
+ outcome: TrialOutcome;
224
+ /** What was run against the original, and what it answered. */
225
+ ran: string;
226
+ /** A corrected scenario's whole new text. */
227
+ text?: string;
228
+ /** Why it was corrected, removed or not tried. */
229
+ why?: string;
230
+ }
231
+ /**
232
+ * What one agent found trying some of a module's scenarios on a copy of the original: each scenario's outcome, the
233
+ * functional specs the original contradicts, corrected, and what a conformance test must set up - or why it could not.
234
+ */
235
+ export type TrialBatch = {
236
+ results: TrialResult[];
237
+ specs: Correction[];
238
+ testReqs: string[];
239
+ } | {
240
+ failed: string;
241
+ };
242
+ export interface FeatureState {
243
+ /** `<area id>#<feature name>`. */
244
+ key: string;
245
+ captured?: CapturedFeature;
246
+ failed?: string;
247
+ }
248
+ export interface CaptureState {
249
+ version: number;
250
+ /** The codebase captured, absolute. */
251
+ root: string;
252
+ started: string;
253
+ /** Saved before the survey. An older capture without a plan continues on the staged pipeline. */
254
+ plan?: CapturePlan;
255
+ survey?: Survey;
256
+ /** The areas by id, each part's root area named as the part. */
257
+ areas: Record<string, AreaState>;
258
+ /** Each part's interface taken from the code, by part, then by the files each agent was given (their paths joined). */
259
+ interfaces?: Record<string, Record<string, InterfaceBatch>>;
260
+ /** Parts whose interface reference is whole: every batch answered - and its concept defined. */
261
+ interfaceTaken?: string[];
262
+ /** Public import signatures found without a model, keyed by the survey's part. */
263
+ pythonInterfaces?: Record<string, string>;
264
+ /** Each part's conventions checked against the code, by part: what the check changed and why, or why it did not hold. */
265
+ conventionsChecked?: Record<string, {
266
+ changes: string[];
267
+ failed?: string;
268
+ }>;
269
+ /** Each part's features divided, by part - absent until its areas are all outlined. */
270
+ divided?: Record<string, Division>;
271
+ /** Parts whose interface no feature captured was given to writers of its own, once every feature was written. */
272
+ interfaceFilled?: string[];
273
+ features: Record<string, FeatureState>;
274
+ /** Each part's features gathered into modules by concern, in the order they are built, by part - none for a part of one feature. */
275
+ gathered?: Record<string, PartModules>;
276
+ /** Concepts defined twice with different texts, as reconciled - by concept, a part's. */
277
+ reconciled: Record<string, Record<string, string>>;
278
+ /** The readability pass's new texts, by module and func-id. */
279
+ edits: Record<string, Record<string, string>>;
280
+ /** Modules whose readability pass ran - edited or not. */
281
+ edited: string[];
282
+ /** The interface check's corrections, by module, applied over the readability pass's texts. */
283
+ corrections?: Record<string, Correction[]>;
284
+ /** Modules whose interface was checked against the code - corrected or not. */
285
+ verified?: string[];
286
+ /** Each module's scenarios tried on the original, by module, then by batch - its number, from 1. */
287
+ trials?: Record<string, Record<string, TrialBatch>>;
288
+ /** Modules whose scenarios were all tried on the original - held or not. */
289
+ tried?: string[];
290
+ /** Whether the ***plain files are written: written once, the testing scripts then written for them. */
291
+ written?: boolean;
292
+ /** Each part's testing scripts, by `<part>:<unit | conformance>`: where each is, or why there is none. */
293
+ scripts?: Record<string, ScriptOutcome>;
294
+ finished?: string;
295
+ }
296
+ /** A testing script a capture had written: where it is in the project, or why there is none. */
297
+ export type ScriptOutcome = {
298
+ written: string;
299
+ finding?: string;
300
+ } | {
301
+ failed: string;
302
+ };
303
+ export declare function captureDir(plainDir: string): string;
304
+ export declare function stateFile(plainDir: string): string;
305
+ export declare function reportFile(plainDir: string): string;
306
+ /** The state a capture left in `plainDir`, or undefined when there is none - or one turri cannot read, which is started over. */
307
+ export declare function readState(plainDir: string): CaptureState | undefined;
308
+ export declare function newState(root: string): CaptureState;
309
+ /** Save the state whole, through a file beside it: a capture stopped mid-write leaves the last state as it was. */
310
+ 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, DEFAULT_PARALLEL, 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 project's harness model; Claude capture defaults to Haiku low / Sonnet low / Opus medium",
17
+ " --coding-model <m> the project's coding model; set models.capture-exploration, capture-analysis and capture to override capture's tiers",
18
+ " --into <folder> where the ***plain goes, instead of <path>/plain",
19
+ ` --parallel <n> how many agents work at once (default: ${DEFAULT_PARALLEL})`,
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,5 +1,6 @@
1
1
  import { type Component, type Container, type ScrollView, type TUI } from "@earendil-works/pi-tui";
2
2
  import type { ChatTabs } from "./chat-tabs.ts";
3
+ export declare const BANNER_ENTRY = "turri_banner";
3
4
  export interface ChatScreen {
4
5
  fullscreenLayoutRoot: Component;
5
6
  documentContainer: Container;
@@ -8,8 +9,8 @@ export interface ChatScreen {
8
9
  }
9
10
  /** The inline tabs are a sibling of the banner in the transcript. A single fixed row takes over when they scroll
10
11
  * off the top (or a resumed conversation has no banner). The banner itself scrolls normally. */
11
- export declare function chatTabHeader(tabs: ChatTabs): {
12
+ export declare function chatTabHeader(tabs: ChatTabs, tabsOnly: () => boolean): {
12
13
  mount(screen: ChatScreen, components: Component[]): Component[];
13
- afterBanner(chat: Container, entry: unknown): void;
14
+ afterBanner(chat: Container, entry: unknown, visible: () => boolean): void;
14
15
  watch(screen: ChatScreen, tui: TUI): () => void;
15
16
  };
@@ -1,5 +1,6 @@
1
1
  import { VStack } from "@earendil-works/pi-tui";
2
2
  import { terminalPointer } from "./pointer-hover.js";
3
+ export const BANNER_ENTRY = "turri_banner";
3
4
  /** Where pi drew a child. Use the row counts its Container already measured for mouse dispatch: the width of the
4
5
  * chat, the banner's image and any wrapped warnings all affect where the divider lands. */
5
6
  function rowOf(parent, child) {
@@ -16,11 +17,17 @@ function rowOf(parent, child) {
16
17
  }
17
18
  /** The inline tabs are a sibling of the banner in the transcript. A single fixed row takes over when they scroll
18
19
  * off the top (or a resumed conversation has no banner). The banner itself scrolls normally. */
19
- export function chatTabHeader(tabs) {
20
+ export function chatTabHeader(tabs, tabsOnly) {
20
21
  let pinned = true;
22
+ // Once the welcome is gone, only the fixed tab row is needed.
23
+ const inline = {
24
+ render: (width) => tabsOnly() ? [] : tabs.render(width),
25
+ handleMouse: (event) => tabs.handleMouse?.(event),
26
+ invalidate() { },
27
+ };
21
28
  const sticky = {
22
- render: (width) => pinned ? tabs.render(width) : [],
23
- handleMouse: (event) => pinned ? tabs.handleMouse?.(event) : undefined,
29
+ render: (width) => pinned || tabsOnly() ? tabs.render(width) : [],
30
+ handleMouse: (event) => pinned || tabsOnly() ? tabs.handleMouse?.(event) : undefined,
24
31
  invalidate() { },
25
32
  };
26
33
  return {
@@ -30,12 +37,16 @@ export function chatTabHeader(tabs) {
30
37
  screen.fullscreenLayoutRoot = new VStack([sticky, { component: screen.fullscreenLayoutRoot, basis: 0, grow: 1, minSize: 1 }]);
31
38
  return [sticky, ...components];
32
39
  },
33
- afterBanner(chat, entry) {
34
- if (chat.children.includes(tabs))
35
- return;
40
+ afterBanner(chat, entry, visible) {
36
41
  const at = chat.children.findIndex((child) => child.entry === entry);
37
- if (at !== -1)
38
- chat.children.splice(at + 1, 0, tabs);
42
+ if (at === -1)
43
+ return;
44
+ // Hide pi's whole entry (including its spacer), but keep the neighbouring tabs and their mouse targets.
45
+ const banner = chat.children[at];
46
+ const render = banner.render.bind(banner);
47
+ banner.render = (width) => visible() ? render(width) : [];
48
+ if (!chat.children.includes(inline))
49
+ chat.children.splice(at + 1, 0, inline);
39
50
  },
40
51
  watch(screen, tui) {
41
52
  if (tui.mode !== "fullscreen") {
@@ -48,8 +59,10 @@ export function chatTabHeader(tabs) {
48
59
  const update = view.updateLayout;
49
60
  view.updateLayout = function (height, viewport, redraw) {
50
61
  update.call(this, height, viewport, redraw);
62
+ if (tabsOnly())
63
+ return;
51
64
  const chat = rowOf(screen.documentContainer, screen.chatContainer);
52
- const tab = rowOf(screen.chatContainer, tabs);
65
+ const tab = rowOf(screen.chatContainer, inline);
53
66
  const row = chat === undefined || tab === undefined ? -1 : chat + tab;
54
67
  const next = row < this.scrollTop || row >= this.scrollTop + viewport;
55
68
  if (next !== pinned) {
@@ -13,8 +13,14 @@ export type TabAction = {
13
13
  };
14
14
  /** Shared by ×, /chat close and alt+w. The last person's chat stays open even if the sentinel has its own tab. */
15
15
  export declare function closeTerminalChat(session: TurriCore, id: string): Promise<void>;
16
+ interface PanelState {
17
+ notifications: number;
18
+ open: boolean;
19
+ busy: boolean;
20
+ }
16
21
  export interface ChatTabs extends Component {
17
22
  pointer: PointerHover;
18
23
  }
19
24
  /** Mouse positions, like the layout, are in terminal cells, not string offsets. */
20
- export declare function chatTabs(chats: () => ChatInfo[], style: ButtonPaint, pick: (action: TabAction) => void): ChatTabs;
25
+ export declare function chatTabs(chats: () => ChatInfo[], style: ButtonPaint, pick: (action: TabAction) => void, panel?: () => PanelState): ChatTabs;
26
+ export {};