@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,15 @@
1
+ import { type Component, type Container, type ScrollView, type TUI } from "@earendil-works/pi-tui";
2
+ import type { ChatTabs } from "./chat-tabs.ts";
3
+ export interface ChatScreen {
4
+ fullscreenLayoutRoot: Component;
5
+ documentContainer: Container;
6
+ chatContainer: Container;
7
+ transcriptScrollView: ScrollView;
8
+ }
9
+ /** The inline tabs are a sibling of the banner in the transcript. A single fixed row takes over when they scroll
10
+ * off the top (or a resumed conversation has no banner). The banner itself scrolls normally. */
11
+ export declare function chatTabHeader(tabs: ChatTabs): {
12
+ mount(screen: ChatScreen, components: Component[]): Component[];
13
+ afterBanner(chat: Container, entry: unknown): void;
14
+ watch(screen: ChatScreen, tui: TUI): () => void;
15
+ };
@@ -0,0 +1,78 @@
1
+ import { VStack } from "@earendil-works/pi-tui";
2
+ import { terminalPointer } from "./pointer-hover.js";
3
+ /** Where pi drew a child. Use the row counts its Container already measured for mouse dispatch: the width of the
4
+ * chat, the banner's image and any wrapped warnings all affect where the divider lands. */
5
+ function rowOf(parent, child) {
6
+ const measured = parent.childLines;
7
+ if (measured === undefined)
8
+ return undefined;
9
+ let row = 0;
10
+ for (const [index, component] of measured.children.entries()) {
11
+ if (component === child)
12
+ return row;
13
+ row += measured.parts[index].length;
14
+ }
15
+ return undefined;
16
+ }
17
+ /** The inline tabs are a sibling of the banner in the transcript. A single fixed row takes over when they scroll
18
+ * off the top (or a resumed conversation has no banner). The banner itself scrolls normally. */
19
+ export function chatTabHeader(tabs) {
20
+ let pinned = true;
21
+ const sticky = {
22
+ render: (width) => pinned ? tabs.render(width) : [],
23
+ handleMouse: (event) => pinned ? tabs.handleMouse?.(event) : undefined,
24
+ invalidate() { },
25
+ };
26
+ return {
27
+ mount(screen, components) {
28
+ if (components.includes(sticky))
29
+ return components;
30
+ screen.fullscreenLayoutRoot = new VStack([sticky, { component: screen.fullscreenLayoutRoot, basis: 0, grow: 1, minSize: 1 }]);
31
+ return [sticky, ...components];
32
+ },
33
+ afterBanner(chat, entry) {
34
+ if (chat.children.includes(tabs))
35
+ return;
36
+ const at = chat.children.findIndex((child) => child.entry === entry);
37
+ if (at !== -1)
38
+ chat.children.splice(at + 1, 0, tabs);
39
+ },
40
+ watch(screen, tui) {
41
+ if (tui.mode !== "fullscreen") {
42
+ // Regular mode has native scrollback: the row below the banner scrolls with it.
43
+ pinned = false;
44
+ return () => { };
45
+ }
46
+ const view = screen.transcriptScrollView;
47
+ tabs.pointer = terminalPointer(tui.terminal);
48
+ const update = view.updateLayout;
49
+ view.updateLayout = function (height, viewport, redraw) {
50
+ update.call(this, height, viewport, redraw);
51
+ const chat = rowOf(screen.documentContainer, screen.chatContainer);
52
+ const tab = rowOf(screen.chatContainer, tabs);
53
+ const row = chat === undefined || tab === undefined ? -1 : chat + tab;
54
+ const next = row < this.scrollTop || row >= this.scrollTop + viewport;
55
+ if (next !== pinned) {
56
+ pinned = next;
57
+ redraw();
58
+ }
59
+ };
60
+ // pi normally asks multiplexers for button motion only. The tabs need motion without a button too. pi disables
61
+ // all mouse modes itself when it leaves fullscreen, including when the terminal is suspended.
62
+ const mouse = tui;
63
+ const start = mouse.beforeTerminalStart;
64
+ mouse.beforeTerminalStart = function () {
65
+ start.call(this);
66
+ if (this.mouseEnabled)
67
+ tui.terminal.write("\x1b[?1003h");
68
+ };
69
+ const input = mouse.handleViewportInput;
70
+ mouse.handleViewportInput = (data) => tabs.pointer.dispatch(() => input.call(mouse, data), () => tui.requestRender());
71
+ return () => {
72
+ view.updateLayout = update;
73
+ mouse.beforeTerminalStart = start;
74
+ mouse.handleViewportInput = input;
75
+ };
76
+ },
77
+ };
78
+ }
@@ -0,0 +1,20 @@
1
+ import { type Component } from "@earendil-works/pi-tui";
2
+ import type { ChatInfo, TurriCore } from "./chats.ts";
3
+ import { PointerHover, type ButtonPaint } from "./pointer-hover.ts";
4
+ /** Shared by the tabs and the /chat picker. */
5
+ export declare function chatMark(chat: ChatInfo): string;
6
+ export type TabAction = {
7
+ kind: "open";
8
+ } | {
9
+ kind: "plain";
10
+ } | {
11
+ kind: "show" | "close";
12
+ id: string;
13
+ };
14
+ /** Shared by ×, /chat close and alt+w. The last person's chat stays open even if the sentinel has its own tab. */
15
+ export declare function closeTerminalChat(session: TurriCore, id: string): Promise<void>;
16
+ export interface ChatTabs extends Component {
17
+ pointer: PointerHover;
18
+ }
19
+ /** 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;
@@ -0,0 +1,96 @@
1
+ import { stripTerminalSequences, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
2
+ import { PointerHover } from "./pointer-hover.js";
3
+ import { spinner } from "./regenerate/job-panel.js";
4
+ /** Shared by the tabs and the /chat picker. */
5
+ export function chatMark(chat) {
6
+ switch (chat.status) {
7
+ case "working": return spinner(Date.now());
8
+ case "question": return "?";
9
+ case "unread": return "•";
10
+ default: return " ";
11
+ }
12
+ }
13
+ const buttonRole = { open: "new", plain: "panel", show: "tab", close: "close" };
14
+ function buttonKey(action) {
15
+ return "id" in action ? `${action.kind}:${action.id}` : action.kind;
16
+ }
17
+ /** Shared by ×, /chat close and alt+w. The last person's chat stays open even if the sentinel has its own tab. */
18
+ export async function closeTerminalChat(session, id) {
19
+ const chats = session.chats();
20
+ const people = chats.filter((chat) => chat.role === undefined);
21
+ if (people.length === 1 && people[0].id === id)
22
+ return session.notify("This is the only chat - /quit leaves turri.", "info");
23
+ await session.close(id);
24
+ }
25
+ function layout(chats, width) {
26
+ if (width <= 0)
27
+ return [];
28
+ // Keep the panel button at the right edge while chat titles grow and shrink on the left.
29
+ const panel = width >= 30 ? " ***plain › " : width >= 14 ? " ***plain " : width >= 6 ? "≡" : "";
30
+ const panelWidth = visibleWidth(panel);
31
+ const chatWidth = width - (panel ? panelWidth + 1 : 0);
32
+ // Reserve + and a close target per tab before spending cells on padding, gaps and titles.
33
+ const spaced = chatWidth >= chats.length * 5 + 3;
34
+ const plus = spaced ? " + " : "+";
35
+ const count = Math.min(chats.length, Math.floor((chatWidth - plus.length) / 2));
36
+ const room = Math.floor((chatWidth - plus.length) / Math.max(1, count)) - (spaced ? 1 : 0);
37
+ const parts = [];
38
+ for (const [index, chat] of chats.slice(0, count).entries()) {
39
+ const lead = !spaced ? "" : room >= 8 ? (chat.shown ? " ▸ " : " ") : (chat.shown ? "▸" : " ");
40
+ let label = `${lead}${index + 1}`;
41
+ const close = spaced ? (room > 4 ? " × " : "× ") : "×";
42
+ const mark = chatMark(chat).trim();
43
+ const suffix = mark ? ` ${mark}` : "";
44
+ const titleRoom = room - visibleWidth(label + close + suffix) - 1;
45
+ if (titleRoom > 0)
46
+ label += ` ${truncateToWidth(stripTerminalSequences(chat.title).replace(/\s+/g, " ").trim(), titleRoom, "…")}${suffix}`;
47
+ parts.push({ text: label, action: { kind: "show", id: chat.id }, shown: chat.shown }, { text: close, action: { kind: "close", id: chat.id }, shown: chat.shown });
48
+ if (spaced)
49
+ parts.push({ text: " " });
50
+ }
51
+ parts.push({ text: plus, action: { kind: "open" } });
52
+ if (panel) {
53
+ const used = parts.reduce((cells, part) => cells + visibleWidth(part.text), 0);
54
+ parts.push({ text: " ".repeat(width - used - panelWidth) }, { text: panel, action: { kind: "plain" } });
55
+ }
56
+ return parts;
57
+ }
58
+ /** Mouse positions, like the layout, are in terminal cells, not string offsets. */
59
+ export function chatTabs(chats, style, pick) {
60
+ let pressed;
61
+ return {
62
+ pointer: new PointerHover(),
63
+ render(width) {
64
+ return [layout(chats(), width).map((part) => part.action ? style(part.text, part.shown === true, this.pointer.target === buttonKey(part.action), buttonRole[part.action.kind]) : part.text).join("")];
65
+ },
66
+ handleMouse(event) {
67
+ const move = event.type === "move";
68
+ if (event.y !== 0 || (!move && (event.button !== "left" || (event.type !== "press" && event.type !== "click"))))
69
+ return;
70
+ const down = pressed;
71
+ if (!move)
72
+ pressed = undefined;
73
+ let x = 0;
74
+ for (const part of layout(chats(), event.width)) {
75
+ const end = x + visibleWidth(part.text);
76
+ if (event.x >= x && event.x < end && part.action) {
77
+ const key = buttonKey(part.action);
78
+ this.pointer.target = key;
79
+ if (move)
80
+ return { handled: true, render: false };
81
+ // Claim the press so pi delivers a click on release, without moving focus out of the editor.
82
+ if (event.type === "press")
83
+ pressed = key;
84
+ // A chat can change its title or close between press and release, moving another tab under the pointer.
85
+ else if (down === key && !(part.shown && part.action.kind === "show")) {
86
+ this.pointer.target = undefined;
87
+ pick(part.action);
88
+ }
89
+ return { handled: true };
90
+ }
91
+ x = end;
92
+ }
93
+ },
94
+ invalidate() { },
95
+ };
96
+ }
@@ -1,5 +1,8 @@
1
1
  import { AgentSessionRuntime, InteractiveMode, SessionManager } from "@earendil-works/pi-coding-agent";
2
+ import { chatTabHeader } from "./chat-tab-header.js";
3
+ import { chatTabs, closeTerminalChat } from "./chat-tabs.js";
2
4
  import { showWaitingMessages } from "./chat-waiting.js";
5
+ import { buttonLabel } from "./pointer-hover.js";
3
6
  import { interruptChat, terminalUi } from "./chats.js";
4
7
  /**
5
8
  * ctrl+c, in the chat shown: what it is doing stopped, the other chats left as they are (`interruptChat`). In a chat
@@ -59,6 +62,47 @@ export function driveTerminal(core, options = {}) {
59
62
  };
60
63
  showWaitingMessages();
61
64
  const prototype = InteractiveMode.prototype;
65
+ let switching = false;
66
+ const tabs = chatTabs(() => core.chats(), (text, shown, hovered, role) => {
67
+ const theme = real?.theme;
68
+ return theme === undefined ? text : buttonLabel(theme, text, shown, hovered, role);
69
+ }, (action) => {
70
+ if (switching || runtime === undefined)
71
+ return;
72
+ if (action.kind === "plain")
73
+ return core.shownChat()?.instance?.openPlainPanel?.();
74
+ switching = true;
75
+ const change = action.kind === "open" ? core.open() : action.kind === "close" ? closeTerminalChat(core, action.id) : core.show(action.id);
76
+ void change.catch((error) => core.notify(error instanceof Error ? error.message : String(error), "warning")).finally(() => { switching = false; });
77
+ });
78
+ const header = chatTabHeader(tabs);
79
+ const addEntry = prototype.addCustomEntryToChat;
80
+ prototype.addCustomEntryToChat = function (entry) {
81
+ addEntry.call(this, entry);
82
+ if (entry.customType === "turri_banner")
83
+ header.afterBanner(this.chatContainer, entry);
84
+ };
85
+ let stopWatchingTabs;
86
+ const mount = prototype.mountInteractiveTui;
87
+ prototype.mountInteractiveTui = function (tui, components) {
88
+ stopWatchingTabs?.();
89
+ mount.call(this, tui, header.mount(this, components));
90
+ const unwatch = header.watch(this, tui);
91
+ let ticker;
92
+ const refresh = () => {
93
+ if (core.chats().some((chat) => chat.status === "working")) {
94
+ ticker ??= setInterval(() => tui.requestRender(), 250).unref();
95
+ }
96
+ else {
97
+ clearInterval(ticker);
98
+ ticker = undefined;
99
+ }
100
+ tui.requestRender();
101
+ };
102
+ const stop = core.onChats(refresh);
103
+ refresh();
104
+ stopWatchingTabs = () => { stop(); clearInterval(ticker); unwatch(); };
105
+ };
62
106
  const rebind = prototype.rebindCurrentSession;
63
107
  prototype.rebindCurrentSession = async function (...args) {
64
108
  await rebind.apply(this, args);
@@ -102,8 +146,10 @@ export function driveTerminal(core, options = {}) {
102
146
  // Leaving turri: every chat let go - the one shown by pi, as it always is.
103
147
  const dispose = runtimes.dispose;
104
148
  runtimes.dispose = async function () {
105
- if (this === runtime)
149
+ if (this === runtime) {
150
+ stopWatchingTabs?.();
106
151
  await core.dispose({ except: runtime.session });
152
+ }
107
153
  return dispose.call(this);
108
154
  };
109
155
  core.setDriver({
@@ -135,17 +181,17 @@ export function driveTerminal(core, options = {}) {
135
181
  return;
136
182
  from?.ui?.hide();
137
183
  // pi takes the shown chat's widgets and dialogs off the screen, as it does before replacing a session - but not the
138
- // overlay on it: the side panel, the session's and not the chat's, stays where it is, beside the chat or over it.
139
- const tui = screen?.ui;
140
- const hideOverlay = tui?.hideOverlay;
141
- if (tui !== undefined)
142
- tui.hideOverlay = () => { };
184
+ // overlays on it: the side panel, the session's and not the chat's, stays where it is, beside the chat or over it.
185
+ // pi takes off every overlay it holds, so for that moment it holds none.
186
+ const overlays = screen?.extensionOverlays;
187
+ const kept = [...(overlays ?? [])];
188
+ overlays?.clear();
143
189
  try {
144
190
  runtime.beforeSessionInvalidate?.();
145
191
  }
146
192
  finally {
147
- if (tui !== undefined && hideOverlay !== undefined)
148
- tui.hideOverlay = hideOverlay;
193
+ for (const [handle, remove] of kept)
194
+ overlays?.set(handle, remove);
149
195
  }
150
196
  runtime._session = chat.session;
151
197
  runtime._services = chat.services;
@@ -14,6 +14,8 @@ import { type Component } from "@earendil-works/pi-tui";
14
14
  export interface WaitingScreen {
15
15
  chatContainer: Container;
16
16
  pendingMessagesContainer: Container;
17
+ /** The output of commands the person ran (`!`) while the agent works: pi keeps it there until it goes in the chat. */
18
+ pendingBashComponents?: Component[];
17
19
  getAllQueuedMessages(): {
18
20
  steering: string[];
19
21
  followUp: string[];
@@ -36,7 +38,8 @@ export declare class Shade implements Component {
36
38
  }
37
39
  /**
38
40
  * Under the chat, each message the agent has not read yet, drawn as pi draws a message in the chat - shaded, and
39
- * marked not read yet - in the order they were sent.
41
+ * marked not read yet - in the order they were sent; under the output of any command the person ran meanwhile, as pi
42
+ * draws them.
40
43
  */
41
44
  export declare function showWaiting(screen: WaitingScreen): void;
42
45
  /** What of pi's session `unqueue` reaches. */
@@ -21,11 +21,14 @@ export class Shade {
21
21
  }
22
22
  /**
23
23
  * Under the chat, each message the agent has not read yet, drawn as pi draws a message in the chat - shaded, and
24
- * marked not read yet - in the order they were sent.
24
+ * marked not read yet - in the order they were sent; under the output of any command the person ran meanwhile, as pi
25
+ * draws them.
25
26
  */
26
27
  export function showWaiting(screen) {
27
28
  const area = screen.pendingMessagesContainer;
28
29
  area.clear();
30
+ for (const output of screen.pendingBashComponents ?? [])
31
+ area.addChild(output);
29
32
  const { steering, followUp } = screen.getAllQueuedMessages();
30
33
  const waiting = [...steering, ...followUp];
31
34
  if (waiting.length === 0)
@@ -36,9 +39,9 @@ export function showWaiting(screen) {
36
39
  const chat = screen.chatContainer;
37
40
  screen.chatContainer = area;
38
41
  try {
39
- for (const text of waiting) {
40
- // A line between it and the chat; pi puts one between messages itself.
41
- if (area.children.length === 0)
42
+ for (const [index, text] of waiting.entries()) {
43
+ // A line between it and what is above it; pi puts one between messages itself.
44
+ if (index === 0)
42
45
  area.addChild(new Spacer(1));
43
46
  const before = area.children.length;
44
47
  screen.addMessageToChat({ role: "user", content: [{ type: "text", text }], timestamp: Date.now() });
package/dist/chats.d.ts CHANGED
@@ -102,6 +102,8 @@ export interface TurriHost {
102
102
  }
103
103
  /** What a chat's extension does for its chat when the session asks. */
104
104
  export interface ChatInstance {
105
+ /** The terminal header's button: open the project's spec map beside this chat. */
106
+ openPlainPanel?(): void;
105
107
  /** A pulse it asked for ended: said in the chat, and its agent told, to react to it. */
106
108
  announce(job: Job): void;
107
109
  /**
package/dist/cli.js CHANGED
@@ -15,12 +15,14 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
15
15
  return path;
16
16
  };
17
17
  import { spawnSync } from "node:child_process";
18
+ import { tmpdir } from "node:os";
18
19
  import { dirname, join } from "node:path";
19
20
  import { fileURLToPath } from "node:url";
20
21
  import { CODING_MODEL_ENV, chatModels } from "./chat-models.js";
21
22
  import { readProjectConfig } from "./config.js";
22
23
  import { extensionInstalledGlobally, PACKAGE_ROOT, themesInstalledGlobally, versionLine } from "./environment.js";
23
24
  import { dropNoise } from "./quiet.js";
25
+ import { REOPEN_FILE_ENV, takeReopening } from "./reopen.js";
24
26
  /**
25
27
  * Start pi with this project's extension and themes already wired in.
26
28
  *
@@ -56,20 +58,35 @@ function chat(args) {
56
58
  // in as well: pi-launch.ts is told, and leaves it to that. turri doctor offers to remove the file.
57
59
  const inPi = extensionInstalledGlobally();
58
60
  const themes = themesInstalledGlobally() ? [] : ["--theme", join(PACKAGE_ROOT, ".pi", "themes")];
59
- // turri's own theme, unless this run names another. For this run only: pi's settings
60
- // are left as they are, so a plain `pi` keeps its theme.
61
- const useTheme = args.some((arg) => arg === "--use-theme" || arg.startsWith("--use-theme=")) ? [] : ["--use-theme", DEFAULT_THEME];
62
- // The model the person talks to, and the one every render runs on - see chat-models.ts.
63
- const { piArgs, codingModel } = chatModels(args, readProjectConfig(process.cwd()));
64
- // Fullscreen: pi owns the viewport, so the conversation stays where it is scrolled to while the
65
- // jobs redraw - in the terminal's own scrollback, every redraw pulls it back to the bottom.
66
- const tuiMode = args.some((arg) => arg === "--tui-mode" || arg.startsWith("--tui-mode=")) ? [] : ["--tui-mode", "fullscreen"];
67
- const result = spawnSync(process.execPath, [launcher, ...themes, ...useTheme, ...tuiMode, ...piArgs], {
68
- stdio: "inherit",
69
- cwd: process.cwd(),
70
- env: { ...process.env, ...(codingModel ? { [CODING_MODEL_ENV]: codingModel } : {}), ...(inPi ? { TURRI_EXTENSION_IN_PI: "1" } : {}) },
71
- });
72
- process.exit(result.status ?? 1);
61
+ // A chat that quits asking to open again elsewhere - after a capture, in the project it wrote - writes where in this
62
+ // file, and is started again there, as the first was (reopen.ts).
63
+ const reopenFile = join(tmpdir(), `turri-reopen-${process.pid}.json`);
64
+ let run = { cwd: process.cwd(), args, env: {} };
65
+ for (;;) {
66
+ // turri's own theme, unless this run names another. For this run only: pi's settings
67
+ // are left as they are, so a plain `pi` keeps its theme.
68
+ const useTheme = run.args.some((arg) => arg === "--use-theme" || arg.startsWith("--use-theme=")) ? [] : ["--use-theme", DEFAULT_THEME];
69
+ // The model the person talks to, and the one every render runs on - see chat-models.ts.
70
+ const { piArgs, codingModel } = chatModels(run.args, readProjectConfig(run.cwd));
71
+ // Fullscreen: pi owns the viewport, so the conversation stays where it is scrolled to while the
72
+ // jobs redraw - in the terminal's own scrollback, every redraw pulls it back to the bottom.
73
+ const tuiMode = run.args.some((arg) => arg === "--tui-mode" || arg.startsWith("--tui-mode=")) ? [] : ["--tui-mode", "fullscreen"];
74
+ const result = spawnSync(process.execPath, [launcher, ...themes, ...useTheme, ...tuiMode, ...piArgs], {
75
+ stdio: "inherit",
76
+ cwd: run.cwd,
77
+ env: {
78
+ ...process.env,
79
+ ...run.env,
80
+ [REOPEN_FILE_ENV]: reopenFile,
81
+ ...(codingModel ? { [CODING_MODEL_ENV]: codingModel } : {}),
82
+ ...(inPi ? { TURRI_EXTENSION_IN_PI: "1" } : {}),
83
+ },
84
+ });
85
+ const next = takeReopening(reopenFile);
86
+ if (next === undefined)
87
+ process.exit(result.status ?? 1);
88
+ run = { cwd: next.dir, args: next.args, env: next.env };
89
+ }
73
90
  }
74
91
  const COMMANDS = {
75
92
  regenerate: { module: "./regenerate-cli.ts", blurb: "regenerate a module and its chain from the spec as it is (with module:func-ids: regenerate those again)" },
@@ -79,6 +96,7 @@ const COMMANDS = {
79
96
  lineage: { module: "./lineage-cli.ts", blurb: "a module's lineage: what was regenerated into it, and when" },
80
97
  launch: { module: "./launch-cli.ts", blurb: "launch what is regenerated from dist/<module> on this machine" },
81
98
  cultivate: { module: "./cultivate-cli.ts", blurb: "run a gated skill" },
99
+ capture: { module: "./capture-cli.ts", blurb: "capture an existing codebase into ***plain, in <path>/plain - offline, with a report of what it decided" },
82
100
  };
83
101
  /** Getting the machine ready, and checking it is. */
84
102
  const SETUP_COMMANDS = {
@@ -22,6 +22,7 @@ const ROLE_ABOUT = {
22
22
  chat: "the conversation - as harness-model, which it wins over",
23
23
  sentinel: "the sentinel: checks every finished pulse and tests what is launched",
24
24
  planner: "cuts the work into pulses",
25
+ capture: "captures an existing codebase into ***plain",
25
26
  diagnosis: "looks into a pulse that failed for good",
26
27
  launch: "the launch agent",
27
28
  coding: "writes the code - as coding-model, which it wins over",
package/dist/config.d.ts CHANGED
@@ -143,7 +143,7 @@ export interface ModelChoice {
143
143
  * The code fixer of a conformance run and the repair agent are coding agents; the unit-test and conformance arbiters
144
144
  * are both `arbiter`.
145
145
  */
146
- export declare const AGENT_ROLES: readonly ["chat", "sentinel", "planner", "diagnosis", "launch", "coding", "conformance", "explorer", "reviewer", "test-reviewer", "judge", "arbiter", "debugger"];
146
+ export declare const AGENT_ROLES: readonly ["chat", "sentinel", "planner", "capture", "diagnosis", "launch", "coding", "conformance", "explorer", "reviewer", "test-reviewer", "judge", "arbiter", "debugger"];
147
147
  export type AgentRole = (typeof AGENT_ROLES)[number];
148
148
  /**
149
149
  * How hard each role thinks when nothing names a level - not the config's `models:`, nor a `:level` on the model it is
@@ -399,7 +399,7 @@ export declare function unknownConfigKeys(root: string): Array<{
399
399
  * a key turri renamed in the file - information, nothing to do; `old-beside-new`, an old name left beside its new one,
400
400
  * doing nothing - take it out; `unknown`, keys turri does not read - take them out, or fix their spelling.
401
401
  */
402
- export type ConfigLineKind = "renamed" | "old-beside-new" | "unknown";
402
+ export type ConfigLineKind = "broken" | "renamed" | "old-beside-new" | "unknown";
403
403
  export interface ConfigLine {
404
404
  kind: ConfigLineKind;
405
405
  /** The file, from the project: `config.turri.yaml`, `config.turri.<module>.yaml`. */
@@ -412,4 +412,17 @@ export interface ConfigLine {
412
412
  * beside its new one - doing nothing - and each file with keys turri does not read.
413
413
  */
414
414
  export declare function configLines(root: string): ConfigLine[];
415
+ /**
416
+ * Why a config file does not parse - its line and what YAML says, a key set twice among them - or undefined when it
417
+ * parses or is not there. turri reads a config that does not parse as empty, every setting at its default, the models
418
+ * pi's own: said, never silently.
419
+ */
420
+ export declare function configFileProblem(path: string): string | undefined;
421
+ /** The config files of a project folder that do not parse - config.turri.yaml and each module's own - each with why. */
422
+ export declare function configProblems(root: string): Array<{
423
+ file: string;
424
+ text: string;
425
+ }>;
426
+ /** Why a project's config does not parse, in a sentence for a refusal - undefined when every file of it parses. */
427
+ export declare function brokenConfig(root: string): string | undefined;
415
428
  export {};
package/dist/config.js CHANGED
@@ -303,7 +303,7 @@ export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhig
303
303
  * The code fixer of a conformance run and the repair agent are coding agents; the unit-test and conformance arbiters
304
304
  * are both `arbiter`.
305
305
  */
306
- export const AGENT_ROLES = ["chat", "sentinel", "planner", "diagnosis", "launch", "coding", "conformance", "explorer", "reviewer", "test-reviewer", "judge", "arbiter", "debugger"];
306
+ export const AGENT_ROLES = ["chat", "sentinel", "planner", "capture", "diagnosis", "launch", "coding", "conformance", "explorer", "reviewer", "test-reviewer", "judge", "arbiter", "debugger"];
307
307
  /**
308
308
  * How hard each role thinks when nothing names a level - not the config's `models:`, nor a `:level` on the model it is
309
309
  * given. The agents that do the work - write the code and the tests, explore, launch - think little: they work from a
@@ -321,12 +321,14 @@ export const ROLE_THINKING = {
321
321
  arbiter: "medium",
322
322
  debugger: "medium",
323
323
  planner: "medium",
324
+ capture: "medium",
324
325
  diagnosis: "medium",
325
326
  };
326
327
  /** The roles on the conversation's side: without their own entry they take the chat's model, not `default`. */
327
328
  // The launch is not: it follows steps - a script, a start command - and runs on the coding model, thinking low. Nor
328
329
  // is the diagnosis: a post-mortem of a job that failed, read by the person - it runs on the coding model, thinking medium.
329
- const CHAT_SIDE = ["chat", "sentinel", "planner"];
330
+ // Capture is too: it writes ***plain, as the chat does.
331
+ const CHAT_SIDE = ["chat", "sentinel", "planner", "capture"];
330
332
  function isThinkingLevel(value) {
331
333
  return typeof value === "string" && THINKING_LEVELS.includes(value);
332
334
  }
@@ -731,6 +733,7 @@ export function unknownConfigKeys(root) {
731
733
  * beside its new one - doing nothing - and each file with keys turri does not read.
732
734
  */
733
735
  export function configLines(root) {
736
+ const broken = configProblems(root).map((problem) => ({ kind: "broken", file: problem.file, text: `${problem.text} - so none of ${problem.file} applies: turri runs on its defaults and pi's, the models among them. Set each key once.` }));
734
737
  const renamed = renameOldKeys(root).map(({ file, from, to }) => ({ kind: "renamed", file, text: `${file}: ${from} is called ${to} now - turri renamed it there, its value kept.` }));
735
738
  const left = [];
736
739
  for (const file of namesIn(root).filter((name) => /^config\.turri(\.[^.]+)?\.yaml$/.test(name)).sort()) {
@@ -753,5 +756,56 @@ export function configLines(root) {
753
756
  file,
754
757
  text: `${file} has ${keys.length === 1 ? "a key" : "keys"} turri does not read - ${keys.join(", ")}: no setting turri has, so ${keys.length === 1 ? "it does" : "they do"} nothing. Take ${keys.length === 1 ? "it" : "them"} out, or see docs/config.md for the spelling.`,
755
758
  }));
756
- return [...renamed, ...left, ...unknown];
759
+ return [...broken, ...renamed, ...left, ...unknown];
760
+ }
761
+ /**
762
+ * Why a config file does not parse - its line and what YAML says, a key set twice among them - or undefined when it
763
+ * parses or is not there. turri reads a config that does not parse as empty, every setting at its default, the models
764
+ * pi's own: said, never silently.
765
+ */
766
+ export function configFileProblem(path) {
767
+ let text;
768
+ try {
769
+ if (!statSync(path).isFile())
770
+ return undefined;
771
+ text = readFileSync(path, "utf8");
772
+ }
773
+ catch {
774
+ return undefined;
775
+ }
776
+ const file = basename(path);
777
+ try {
778
+ const parsed = loadYaml(text);
779
+ if (parsed !== null && parsed !== undefined && (typeof parsed !== "object" || Array.isArray(parsed)))
780
+ return `${file} is not a list of settings, a key and its value a line`;
781
+ return undefined;
782
+ }
783
+ catch (error) {
784
+ const reason = error.reason;
785
+ const line = error.mark?.line;
786
+ const at = typeof line === "number" ? `, line ${line + 1}` : "";
787
+ const key = typeof line === "number" ? /^\s*([\w.-]+)\s*:/.exec(text.split("\n")[line] ?? "")?.[1] : undefined;
788
+ if (reason === "duplicated mapping key")
789
+ return `${file}${at}: ${key !== undefined ? `${key} is` : "a key is"} set twice`;
790
+ return `${file}${at} does not parse: ${typeof reason === "string" ? reason : error instanceof Error ? error.message.split("\n")[0] : String(error)}`;
791
+ }
792
+ }
793
+ /** The config files of a project folder that do not parse - config.turri.yaml and each module's own - each with why. */
794
+ export function configProblems(root) {
795
+ return namesIn(root)
796
+ // config.yaml only while turri reads it: until it writes config.turri.yaml, it may be another tool's.
797
+ .filter((name) => /^config\.turri(\.[^.]+)?\.yaml$/.test(name) || (name === LEGACY_CONFIG_FILE && usesLegacyConfig(root)))
798
+ .sort()
799
+ .flatMap((file) => {
800
+ const text = configFileProblem(join(root, file));
801
+ return text === undefined ? [] : [{ file, text }];
802
+ });
803
+ }
804
+ /** Why a project's config does not parse, in a sentence for a refusal - undefined when every file of it parses. */
805
+ export function brokenConfig(root) {
806
+ const problems = configProblems(root);
807
+ if (problems.length === 0)
808
+ return undefined;
809
+ return (`${problems.map((problem) => problem.text).join("; ")}. A config that does not parse is read as empty: none of it would apply - ` +
810
+ `not the models, not conformance tests, no other setting - and turri would run on its defaults and pi's. Fix it - each key set once - then ask again.`);
757
811
  }