@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
package/dist/chat-tabs.js CHANGED
@@ -22,11 +22,15 @@ export async function closeTerminalChat(session, id) {
22
22
  return session.notify("This is the only chat - /quit leaves turri.", "info");
23
23
  await session.close(id);
24
24
  }
25
- function layout(chats, width) {
25
+ function layout(chats, width, state) {
26
26
  if (width <= 0)
27
27
  return [];
28
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 ? "≡" : "";
29
+ const pending = state?.notifications ?? 0;
30
+ const badge = pending && width >= 30 ? ` · ${pending > 99 ? "99+" : pending}` : "";
31
+ const arrow = state?.open ? "‹" : "›";
32
+ const spin = state?.busy ? spinner(Date.now()) : "";
33
+ const panel = width >= 24 ? ` ${spin && `${spin} `}***plain${badge} ${arrow} ` : width >= 14 ? `${spin}***plain ${arrow}` : width >= 6 ? `${spin}${arrow}` : "";
30
34
  const panelWidth = visibleWidth(panel);
31
35
  const chatWidth = width - (panel ? panelWidth + 1 : 0);
32
36
  // Reserve + and a close target per tab before spending cells on padding, gaps and titles.
@@ -51,17 +55,17 @@ function layout(chats, width) {
51
55
  parts.push({ text: plus, action: { kind: "open" } });
52
56
  if (panel) {
53
57
  const used = parts.reduce((cells, part) => cells + visibleWidth(part.text), 0);
54
- parts.push({ text: " ".repeat(width - used - panelWidth) }, { text: panel, action: { kind: "plain" } });
58
+ parts.push({ text: " ".repeat(width - used - panelWidth) }, { text: panel, action: { kind: "plain" }, role: state?.busy ? "regenerating" : "panel" });
55
59
  }
56
60
  return parts;
57
61
  }
58
62
  /** Mouse positions, like the layout, are in terminal cells, not string offsets. */
59
- export function chatTabs(chats, style, pick) {
63
+ export function chatTabs(chats, style, pick, panel) {
60
64
  let pressed;
61
65
  return {
62
66
  pointer: new PointerHover(),
63
67
  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("")];
68
+ return [layout(chats(), width, panel?.()).map((part) => part.action ? style(part.text, part.shown === true, this.pointer.target === buttonKey(part.action), part.role ?? buttonRole[part.action.kind]) : part.text).join("")];
65
69
  },
66
70
  handleMouse(event) {
67
71
  const move = event.type === "move";
@@ -71,7 +75,7 @@ export function chatTabs(chats, style, pick) {
71
75
  if (!move)
72
76
  pressed = undefined;
73
77
  let x = 0;
74
- for (const part of layout(chats(), event.width)) {
78
+ for (const part of layout(chats(), event.width, panel?.())) {
75
79
  const end = x + visibleWidth(part.text);
76
80
  if (event.x >= x && event.x < end && part.action) {
77
81
  const key = buttonKey(part.action);
@@ -1,5 +1,5 @@
1
1
  import { AgentSessionRuntime, InteractiveMode, SessionManager } from "@earendil-works/pi-coding-agent";
2
- import { chatTabHeader } from "./chat-tab-header.js";
2
+ import { BANNER_ENTRY, chatTabHeader } from "./chat-tab-header.js";
3
3
  import { chatTabs, closeTerminalChat } from "./chat-tabs.js";
4
4
  import { showWaitingMessages } from "./chat-waiting.js";
5
5
  import { buttonLabel } from "./pointer-hover.js";
@@ -70,17 +70,38 @@ export function driveTerminal(core, options = {}) {
70
70
  if (switching || runtime === undefined)
71
71
  return;
72
72
  if (action.kind === "plain")
73
- return core.shownChat()?.instance?.openPlainPanel?.();
73
+ return core.shownChat()?.instance?.plainPanel?.toggle();
74
74
  switching = true;
75
75
  const change = action.kind === "open" ? core.open() : action.kind === "close" ? closeTerminalChat(core, action.id) : core.show(action.id);
76
76
  void change.catch((error) => core.notify(error instanceof Error ? error.message : String(error), "warning")).finally(() => { switching = false; });
77
+ }, () => {
78
+ const panel = core.shownChat()?.instance?.plainPanel;
79
+ return { notifications: core.notifications.count, open: panel?.open() === true, busy: panel?.busy() === true };
77
80
  });
78
- const header = chatTabHeader(tabs);
81
+ const header = chatTabHeader(tabs, () => {
82
+ const id = core.shown();
83
+ return id !== undefined && !core.welcomeVisible(id);
84
+ });
85
+ // pi dispatches slash commands before the extension's input event. Catch the submission before either path.
86
+ const setupSubmit = prototype.setupEditorSubmitHandler;
87
+ prototype.setupEditorSubmitHandler = function () {
88
+ setupSubmit.call(this);
89
+ const editor = this.defaultEditor;
90
+ const submit = editor.onSubmit;
91
+ editor.onSubmit = (text) => {
92
+ if (text.trim())
93
+ core.dismissWelcome();
94
+ return submit.call(editor, text);
95
+ };
96
+ };
79
97
  const addEntry = prototype.addCustomEntryToChat;
80
98
  prototype.addCustomEntryToChat = function (entry) {
81
99
  addEntry.call(this, entry);
82
- if (entry.customType === "turri_banner")
83
- header.afterBanner(this.chatContainer, entry);
100
+ if (entry.customType === BANNER_ENTRY)
101
+ header.afterBanner(this.chatContainer, entry, () => {
102
+ const chat = core.chatOfSession(this.session);
103
+ return chat !== undefined && core.welcomeVisible(chat.id);
104
+ });
84
105
  };
85
106
  let stopWatchingTabs;
86
107
  const mount = prototype.mountInteractiveTui;
@@ -90,7 +111,7 @@ export function driveTerminal(core, options = {}) {
90
111
  const unwatch = header.watch(this, tui);
91
112
  let ticker;
92
113
  const refresh = () => {
93
- if (core.chats().some((chat) => chat.status === "working")) {
114
+ if (core.shownChat()?.instance?.plainPanel?.busy() || core.chats().some((chat) => chat.status === "working")) {
94
115
  ticker ??= setInterval(() => tui.requestRender(), 250).unref();
95
116
  }
96
117
  else {
package/dist/chats.d.ts CHANGED
@@ -2,9 +2,10 @@ import type { AgentSession, ExtensionAPI, ExtensionContext, ExtensionFactory, Ex
2
2
  import { type ChatScope } from "./chat-scope.ts";
3
3
  import { type RunRecord } from "./chat-records.ts";
4
4
  import { type ChatUi } from "./chat-ui.ts";
5
+ import { TerminalNotifications } from "./terminal-notifications.ts";
5
6
  import { type SentinelSetting } from "./config.ts";
6
7
  import type { AskUserIO } from "./ask.ts";
7
- import type { Job, JobRegistry } from "./regenerate/jobs.ts";
8
+ import { type Job, type JobRegistry } from "./regenerate/jobs.ts";
8
9
  import type { Launch } from "./launch-track.ts";
9
10
  import type { ToolDefinition } from "@earendil-works/pi-coding-agent";
10
11
  import { type ChatRole, type Conclusion, type Notice, type NoticeAnswer, type NoticeInput, type SentinelCheck } from "./notice.ts";
@@ -77,7 +78,7 @@ export interface TurriHost {
77
78
  * The host shows the person each pulse that lands and each of the sentinel's conclusions itself - its own
78
79
  * notifications, from onJobChange and onConcluded. With the sentinel on, the chat the person is in is then told of both
79
80
  * without a turn of its own: its agent knows what landed and what the sentinel found when the person asks, and does
80
- * not say it again in the conversation. Unset, it says both, as in the terminal.
81
+ * not say it again in the conversation. Unset in a host, it says both.
81
82
  */
82
83
  pulseEndsShown?: boolean;
83
84
  /**
@@ -102,8 +103,12 @@ export interface TurriHost {
102
103
  }
103
104
  /** What a chat's extension does for its chat when the session asks. */
104
105
  export interface ChatInstance {
105
- /** The terminal header's button: open the project's spec map beside this chat. */
106
- openPlainPanel?(): void;
106
+ /** The terminal header's toggle. Visibility is independent of which side has the keys. */
107
+ plainPanel?: {
108
+ open(): boolean;
109
+ busy(): boolean;
110
+ toggle(): void;
111
+ };
107
112
  /** A pulse it asked for ended: said in the chat, and its agent told, to react to it. */
108
113
  announce(job: Job): void;
109
114
  /**
@@ -141,8 +146,6 @@ export interface ChatInstance {
141
146
  concluded(conclusion: Conclusion): void;
142
147
  /** The person answered a notice with something to do: the chat's agent started on it. */
143
148
  act(task: string): void;
144
- /** The jobs changed: what it draws of them is drawn again. */
145
- jobsChanged(): void;
146
149
  /** How hard the chat's model thinks now: sub-agents started from it think as hard. */
147
150
  thinkingLevel(): string | undefined;
148
151
  /** The chat's context, as its tools get it - for its model and its providers. */
@@ -191,6 +194,8 @@ export interface ChatState {
191
194
  unsubscribe?: () => void;
192
195
  }
193
196
  export interface TurriCore {
197
+ /** Shared by all the terminal's chats. */
198
+ readonly notifications: TerminalNotifications;
194
199
  readonly cwd: string;
195
200
  readonly host: TurriHost;
196
201
  readonly jobs: JobRegistry;
@@ -200,6 +205,9 @@ export interface TurriCore {
200
205
  readonly canOpen: boolean;
201
206
  /** Whether the chats are the terminal's, switched between with /chat and its keys. */
202
207
  readonly terminal: boolean;
208
+ /** Only the first terminal chat shows the welcome, until a non-empty submission anywhere in the session. */
209
+ welcomeVisible(chat: string): boolean;
210
+ dismissWelcome(): void;
203
211
  chats(): ChatInfo[];
204
212
  /** The chat's pi session. */
205
213
  session(id: string): AgentSession | undefined;
@@ -269,8 +277,6 @@ export interface TurriCore {
269
277
  * `refused`: `ignore` on one that is not ignorable.
270
278
  */
271
279
  answer(id: string, answer: NoticeAnswer): "done" | "dismissed" | "ignored" | "refused" | "missing" | "over";
272
- /** For the extension: the jobs changed - every chat draws them again. */
273
- jobsChanged(): void;
274
280
  /** The chat whose work this is, else the one shown: its instance. */
275
281
  instanceInScope(): ChatInstance | undefined;
276
282
  setDriver(driver: ChatDriver): void;
package/dist/chats.js CHANGED
@@ -3,8 +3,10 @@ import { existsSync } from "node:fs";
3
3
  import { currentChat, inChat } from "./chat-scope.js";
4
4
  import { adoptRun, forgetChat, forgetSessionFile, recordRun } from "./chat-records.js";
5
5
  import { createChatUi } from "./chat-ui.js";
6
+ import { TerminalNotifications } from "./terminal-notifications.js";
6
7
  import { debugMode } from "./config.js";
7
8
  import { firstLine, record } from "./regenerate/ledger.js";
9
+ import { pulseName, formatDuration } from "./regenerate/jobs.js";
8
10
  import { newNotice, noticeTask, SENTINEL, sentinelStartChoice, wentWrong } from "./notice.js";
9
11
  /**
10
12
  * The chats of a turri session.
@@ -84,6 +86,8 @@ export function createChats(options) {
84
86
  const listeners = new Set();
85
87
  let driver;
86
88
  let shownId;
89
+ let welcomeChat;
90
+ let welcomeDismissed = false;
87
91
  /** The chat whose extension pi is building now. */
88
92
  let attaching;
89
93
  /** Chats are opened one at a time: each one's extension is built while it is the one attaching. */
@@ -158,6 +162,8 @@ export function createChats(options) {
158
162
  };
159
163
  const newChat = (title, role) => {
160
164
  const id = randomUUID().slice(0, 8);
165
+ if (role === undefined)
166
+ welcomeChat ??= id;
161
167
  const chat = {
162
168
  id,
163
169
  scope: { id, asking: new Set() },
@@ -204,6 +210,7 @@ export function createChats(options) {
204
210
  });
205
211
  };
206
212
  const core = {
213
+ notifications: new TerminalNotifications(),
207
214
  cwd,
208
215
  host,
209
216
  jobs,
@@ -214,6 +221,13 @@ export function createChats(options) {
214
221
  get terminal() {
215
222
  return driver?.terminal === true;
216
223
  },
224
+ welcomeVisible: (id) => !core.terminal || (!welcomeDismissed && welcomeChat === id),
225
+ dismissWelcome() {
226
+ if (!core.terminal || welcomeDismissed)
227
+ return;
228
+ welcomeDismissed = true;
229
+ changed();
230
+ },
217
231
  chats: () => chats.map((chat) => ({ id: chat.id, title: titleFor(chat), status: statusOf(chat), shown: chat.id === shownId, ...(chat.role !== undefined ? { role: chat.role } : {}) })),
218
232
  session: (id) => chats.find((chat) => chat.id === id)?.session,
219
233
  decline(id) {
@@ -385,6 +399,12 @@ export function createChats(options) {
385
399
  },
386
400
  sentinelOn: () => driver !== undefined && wantsSentinel(),
387
401
  jobFinished(job) {
402
+ if (core.terminal) {
403
+ const didNotPass = job.status === "succeeded" && wentWrong(job);
404
+ const result = job.status === "succeeded" ? didNotPass ? "did not pass" : "finished" : job.status;
405
+ core.notifications.add(`${pulseName(job)} · ${result} after ${formatDuration(job)}`, job.error ?? job.report ?? job.note ?? "", { warning: job.status === "failed" || didNotPass });
406
+ changed();
407
+ }
388
408
  // The question was settled in config.turri.yaml while it was open: what it held goes as the file now says.
389
409
  if (consent === "asking" && setting() !== "ask")
390
410
  settleStart(setting() === true ? "given" : "declined", "superseded");
@@ -451,16 +471,6 @@ export function createChats(options) {
451
471
  sentinelChecks(check);
452
472
  return { check: check.id };
453
473
  },
454
- jobsChanged() {
455
- for (const chat of chats) {
456
- try {
457
- chat.instance?.jobsChanged();
458
- }
459
- catch {
460
- /* a chat let go draws nothing */
461
- }
462
- }
463
- },
464
474
  notice(input) {
465
475
  // A check's notice is about its module.
466
476
  const about = input.check !== undefined ? checks.get(input.check) : undefined;
@@ -479,7 +489,13 @@ export function createChats(options) {
479
489
  const { ignorable, ...rest } = input;
480
490
  const notice = newNotice(ignorable === true && input.kind === undefined ? input : rest, target.id);
481
491
  open.push(notice);
482
- if (target.id !== shownId)
492
+ if (core.terminal) {
493
+ // notify_person may omit the id; the sentinel still has exactly one review in progress.
494
+ const work = checking?.work;
495
+ const about = work && currentChat()?.id === sentinelChat()?.id ? ("pulse" in work ? { job: work.pulse.id } : { check: work.check.id }) : undefined;
496
+ core.notifications.put(notice, about);
497
+ }
498
+ else if (target.id !== shownId)
483
499
  target.unread = true;
484
500
  inChat(target.scope, () => record({ kind: "notice.put", notice: notice.id, severity: notice.severity, ...(notice.module !== undefined ? { module: notice.module } : {}) }, { project: cwd }));
485
501
  try {
@@ -511,7 +527,9 @@ export function createChats(options) {
511
527
  const module = conclusion.module ?? job?.module ?? check?.module;
512
528
  const pulse = conclusion.pulse ?? job?.pulse;
513
529
  const told = { ...conclusion, ...(module !== undefined ? { module } : {}), ...(pulse !== undefined ? { pulse } : {}) };
514
- if (target.id !== shownId)
530
+ if (core.terminal)
531
+ core.notifications.concluded(told);
532
+ else if (target.id !== shownId)
515
533
  target.unread = true;
516
534
  inChat(target.scope, () => record({ kind: "sentinel.concluded", verdict: told.verdict, ...(module !== undefined ? { module } : {}), ...(told.check !== undefined ? { check: told.check } : {}) }, { project: cwd, ...(told.job !== undefined ? { job: told.job } : {}) }));
517
535
  try {
@@ -543,7 +561,7 @@ export function createChats(options) {
543
561
  options.ignored?.(notice);
544
562
  }
545
563
  catch (error) {
546
- core.notify(`The sentinel's guidance could not be written: ${error instanceof Error ? error.message : String(error)}`, "warning");
564
+ sentinelMessage(`The sentinel's guidance could not be written: ${error instanceof Error ? error.message : String(error)}`, "warning");
547
565
  }
548
566
  over(notice, "ignored");
549
567
  return "ignored";
@@ -603,6 +621,8 @@ export function createChats(options) {
603
621
  }
604
622
  if (chat !== undefined)
605
623
  inChat(chat.scope, () => record({ kind: "notice.over", notice: notice.id, state }, { project: cwd }));
624
+ if (core.terminal)
625
+ changed();
606
626
  }
607
627
  /** A pulse ended, told to the chat that asked for it - as without a sentinel - or the chat shown, when that one is closed. */
608
628
  function toAsker(job) {
@@ -704,7 +724,7 @@ export function createChats(options) {
704
724
  const asked = chats.find((chat) => chat.id === job.chat && chat.role !== SENTINEL);
705
725
  const where = personFacing(asked);
706
726
  if (where !== undefined) {
707
- if (where.id !== shownId)
727
+ if (where.id !== shownId && !core.terminal)
708
728
  where.unread = true;
709
729
  try {
710
730
  where.instance?.landed(job, { tell: !wentWrong(job) });
@@ -739,7 +759,7 @@ export function createChats(options) {
739
759
  }
740
760
  catch (error) {
741
761
  const why = error instanceof Error ? error.message : String(error);
742
- core.notify(`The sentinel could not be opened: ${why}`, "warning");
762
+ sentinelMessage(`The sentinel could not be opened: ${why}`, "warning");
743
763
  failed(why);
744
764
  return undefined;
745
765
  }
@@ -750,10 +770,16 @@ export function createChats(options) {
750
770
  function unchecked(check, why) {
751
771
  core.concluded({ check: check.id, module: check.module, verdict: "unchecked", summary: `Not checked: ${why}.` });
752
772
  }
773
+ function sentinelMessage(message, level) {
774
+ if (!core.terminal)
775
+ return core.notify(message, level);
776
+ core.notifications.add(message, "");
777
+ changed();
778
+ }
753
779
  /** The sentinel's work, after what it was given before. */
754
780
  function toSentinel(work) {
755
781
  sentinelWork = sentinelWork.then(work).catch((error) => {
756
- core.notify(`The sentinel: ${error instanceof Error ? error.message : String(error)}`, "warning");
782
+ sentinelMessage(`The sentinel: ${error instanceof Error ? error.message : String(error)}`, "warning");
757
783
  });
758
784
  }
759
785
  /**
@@ -788,7 +814,7 @@ export function createChats(options) {
788
814
  async function refuse(sentinel, work, why) {
789
815
  const module = codebaseOf(work);
790
816
  inChat(sentinel.scope, () => record({ kind: "sentinel.refused", ...(module !== undefined ? { module } : {}), ...("check" in work ? { check: work.check.id } : {}), why: firstLine(why, 300) }, { project: cwd, ...("pulse" in work ? { job: work.pulse.id } : {}) }));
791
- if ("pulse" in work)
817
+ if ("pulse" in work && !core.terminal)
792
818
  core.notify(`The sentinel cannot check pulse ${work.pulse.id}: ${why}`, "error");
793
819
  core.concluded({
794
820
  ...("pulse" in work ? { job: work.pulse.id } : { check: work.check.id }),
@@ -823,7 +849,7 @@ export function createChats(options) {
823
849
  await sentinel.instance.briefCheck(check, where !== undefined ? { focused: titleFor(where) } : {});
824
850
  }
825
851
  catch (error) {
826
- core.notify(`The sentinel could not be told of check ${check.id}: ${error instanceof Error ? error.message : String(error)}`, "warning");
852
+ sentinelMessage(`The sentinel could not be told of check ${check.id}: ${error instanceof Error ? error.message : String(error)}`, "warning");
827
853
  checking = undefined;
828
854
  }
829
855
  changed();
@@ -856,7 +882,7 @@ export function createChats(options) {
856
882
  });
857
883
  }
858
884
  catch (error) {
859
- core.notify(`The sentinel could not be told of ${job.id}: ${error instanceof Error ? error.message : String(error)}`, "warning");
885
+ sentinelMessage(`The sentinel could not be told of ${job.id}: ${error instanceof Error ? error.message : String(error)}`, "warning");
860
886
  checking = undefined;
861
887
  }
862
888
  changed();
@@ -933,7 +959,7 @@ export function createChats(options) {
933
959
  catch (error) {
934
960
  Object.assign(chat, old);
935
961
  follow(chat);
936
- core.notify(`The sentinel goes on in the conversation it had - a new one could not be started: ${error instanceof Error ? error.message : String(error)}`, "warning");
962
+ sentinelMessage(`The sentinel goes on in the conversation it had - a new one could not be started: ${error instanceof Error ? error.message : String(error)}`, "warning");
937
963
  return;
938
964
  }
939
965
  const fresh = chat.session;
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,9 @@ 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",
26
+ "capture-exploration": "gathers facts and extracts the interface from the original code",
27
+ "capture-analysis": "checks evidence, outlines features and tries scenarios on the original",
25
28
  diagnosis: "looks into a pulse that failed for good",
26
29
  launch: "the launch agent",
27
30
  coding: "writes the code - as coding-model, which it wins over",
@@ -40,7 +43,7 @@ export function settings(rules = []) {
40
43
  key: `models.${role}`,
41
44
  about: `the ${role} role's model and thinking - ${ROLE_ABOUT[role]}`,
42
45
  kind: "model",
43
- unset: role === "default" ? "harness-model's, for the conversation's side; coding-model's for the rest" : "default's",
46
+ unset: role === "default" ? "harness-model's, for the conversation's side; coding-model's for the rest" : role === "capture-exploration" ? "Haiku low on Claude; otherwise coding-model, low" : role === "capture-analysis" ? "Sonnet low on Claude; otherwise coding-model, low" : role === "capture" ? "Opus medium on Claude; otherwise harness-model, medium" : "default's",
44
47
  effect: role === "chat" ? "now" : "next-pulse",
45
48
  ...(role === "chat" ? { projectOnly: true } : {}),
46
49
  },
@@ -48,7 +51,7 @@ export function settings(rules = []) {
48
51
  key: `models.${role}.turn-limit`,
49
52
  about: `seconds each turn of the ${role} role's agents has - 0 for none`,
50
53
  kind: "number",
51
- unset: "default's, else turn-limit",
54
+ unset: role.startsWith("capture-") ? "capture's, else default's, else turn-limit" : "default's, else turn-limit",
52
55
  effect: "next-pulse",
53
56
  options: SECONDS,
54
57
  min: 0,
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-exploration", "capture-analysis", "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-exploration", "capture-analysis", "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,11 +321,15 @@ export const ROLE_THINKING = {
321
321
  arbiter: "medium",
322
322
  debugger: "medium",
323
323
  planner: "medium",
324
+ capture: "medium",
325
+ "capture-analysis": "low",
326
+ "capture-exploration": "low",
324
327
  diagnosis: "medium",
325
328
  };
326
329
  /** The roles on the conversation's side: without their own entry they take the chat's model, not `default`. */
327
330
  // The launch is not: it follows steps - a script, a start command - and runs on the coding model, thinking low. Nor
328
331
  // is the diagnosis: a post-mortem of a job that failed, read by the person - it runs on the coding model, thinking medium.
332
+ // Capture has its own three tiers, resolved by capture/models.ts.
329
333
  const CHAT_SIDE = ["chat", "sentinel", "planner"];
330
334
  function isThinkingLevel(value) {
331
335
  return typeof value === "string" && THINKING_LEVELS.includes(value);
@@ -406,6 +410,9 @@ export function roleModel(config, role) {
406
410
  return undefined;
407
411
  const models = config.models ?? {};
408
412
  const own = choiceOf(models[role]);
413
+ // Capture supplies its tier defaults; do not inherit a writer's model or thinking for exploration or analysis.
414
+ if (role === "capture-exploration" || role === "capture-analysis" || role === "capture")
415
+ return own;
409
416
  // The debugger looks at the coding agent's failure: without its own entry it runs on the model it is given - a stronger one.
410
417
  if (role === "debugger")
411
418
  return own;
@@ -417,7 +424,7 @@ export function roleModel(config, role) {
417
424
  /** How long each turn of a role's agents may take, in milliseconds: its own, `default`'s, `turn-limit:`'s - or undefined, the harness's default. */
418
425
  export function roleTurnLimitMs(config, role) {
419
426
  const models = config.models ?? {};
420
- const seconds = (role !== undefined ? models[role]?.turnLimit : undefined) ?? models.default?.turnLimit ?? config.turnLimit;
427
+ const seconds = (role !== undefined ? models[role]?.turnLimit : undefined) ?? (role?.startsWith("capture-") ? models.capture?.turnLimit : undefined) ?? models.default?.turnLimit ?? config.turnLimit;
421
428
  return seconds !== undefined ? seconds * 1000 : undefined;
422
429
  }
423
430
  /** A whole number of at least 1, as the config gives it - or nothing. */
@@ -731,6 +738,7 @@ export function unknownConfigKeys(root) {
731
738
  * beside its new one - doing nothing - and each file with keys turri does not read.
732
739
  */
733
740
  export function configLines(root) {
741
+ 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
742
  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
743
  const left = [];
736
744
  for (const file of namesIn(root).filter((name) => /^config\.turri(\.[^.]+)?\.yaml$/.test(name)).sort()) {
@@ -753,5 +761,56 @@ export function configLines(root) {
753
761
  file,
754
762
  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
763
  }));
756
- return [...renamed, ...left, ...unknown];
764
+ return [...broken, ...renamed, ...left, ...unknown];
765
+ }
766
+ /**
767
+ * Why a config file does not parse - its line and what YAML says, a key set twice among them - or undefined when it
768
+ * parses or is not there. turri reads a config that does not parse as empty, every setting at its default, the models
769
+ * pi's own: said, never silently.
770
+ */
771
+ export function configFileProblem(path) {
772
+ let text;
773
+ try {
774
+ if (!statSync(path).isFile())
775
+ return undefined;
776
+ text = readFileSync(path, "utf8");
777
+ }
778
+ catch {
779
+ return undefined;
780
+ }
781
+ const file = basename(path);
782
+ try {
783
+ const parsed = loadYaml(text);
784
+ if (parsed !== null && parsed !== undefined && (typeof parsed !== "object" || Array.isArray(parsed)))
785
+ return `${file} is not a list of settings, a key and its value a line`;
786
+ return undefined;
787
+ }
788
+ catch (error) {
789
+ const reason = error.reason;
790
+ const line = error.mark?.line;
791
+ const at = typeof line === "number" ? `, line ${line + 1}` : "";
792
+ const key = typeof line === "number" ? /^\s*([\w.-]+)\s*:/.exec(text.split("\n")[line] ?? "")?.[1] : undefined;
793
+ if (reason === "duplicated mapping key")
794
+ return `${file}${at}: ${key !== undefined ? `${key} is` : "a key is"} set twice`;
795
+ return `${file}${at} does not parse: ${typeof reason === "string" ? reason : error instanceof Error ? error.message.split("\n")[0] : String(error)}`;
796
+ }
797
+ }
798
+ /** The config files of a project folder that do not parse - config.turri.yaml and each module's own - each with why. */
799
+ export function configProblems(root) {
800
+ return namesIn(root)
801
+ // config.yaml only while turri reads it: until it writes config.turri.yaml, it may be another tool's.
802
+ .filter((name) => /^config\.turri(\.[^.]+)?\.yaml$/.test(name) || (name === LEGACY_CONFIG_FILE && usesLegacyConfig(root)))
803
+ .sort()
804
+ .flatMap((file) => {
805
+ const text = configFileProblem(join(root, file));
806
+ return text === undefined ? [] : [{ file, text }];
807
+ });
808
+ }
809
+ /** Why a project's config does not parse, in a sentence for a refusal - undefined when every file of it parses. */
810
+ export function brokenConfig(root) {
811
+ const problems = configProblems(root);
812
+ if (problems.length === 0)
813
+ return undefined;
814
+ return (`${problems.map((problem) => problem.text).join("; ")}. A config that does not parse is read as empty: none of it would apply - ` +
815
+ `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
816
  }
@@ -162,6 +162,7 @@ export { fromWorkingDir };
162
162
  */
163
163
  export declare function pulseEndNote(job: Job, options?: {
164
164
  launching?: boolean;
165
+ quiet?: boolean;
165
166
  }): string;
166
167
  /**
167
168
  * What the agent is to do with a job that just ended, unasked: what the project's guidance says to do then, or else say
@@ -205,4 +206,4 @@ export declare const shownFrame: () => number;
205
206
  * jellyfish stops for the rest of the session - swimming, whole, drawn once more if it was not, rather than on whatever
206
207
  * frame it was at, a polyp half grown.
207
208
  */
208
- export declare function animateJellyfish(ctx: ExtensionContext): void;
209
+ export declare function animateJellyfish(ctx: ExtensionContext, visible?: () => boolean): void;