@turri-dev/cli 0.4.2-next.a6867e8 → 0.4.3-next.3fc888b

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 (128) 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 +391 -0
  5. package/dist/capture/agents.js +338 -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 +1281 -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 +58 -0
  21. package/dist/capture/map.js +530 -0
  22. package/dist/capture/plan.d.ts +8 -0
  23. package/dist/capture/plan.js +13 -0
  24. package/dist/capture/progress.d.ts +109 -0
  25. package/dist/capture/progress.js +240 -0
  26. package/dist/capture/report.d.ts +75 -0
  27. package/dist/capture/report.js +268 -0
  28. package/dist/capture/scripts.d.ts +26 -0
  29. package/dist/capture/scripts.js +33 -0
  30. package/dist/capture/state.d.ts +299 -0
  31. package/dist/capture/state.js +43 -0
  32. package/dist/capture/trial.d.ts +34 -0
  33. package/dist/capture/trial.js +89 -0
  34. package/dist/capture-cli.d.ts +1 -0
  35. package/dist/capture-cli.js +77 -0
  36. package/dist/chat-commands.d.ts +2 -10
  37. package/dist/chat-commands.js +3 -57
  38. package/dist/chat-tab-header.d.ts +15 -0
  39. package/dist/chat-tab-header.js +78 -0
  40. package/dist/chat-tabs.d.ts +26 -0
  41. package/dist/chat-tabs.js +100 -0
  42. package/dist/chat-terminal.js +57 -8
  43. package/dist/chat-waiting.d.ts +4 -1
  44. package/dist/chat-waiting.js +7 -4
  45. package/dist/chats.d.ts +12 -7
  46. package/dist/chats.js +35 -21
  47. package/dist/cli.js +32 -14
  48. package/dist/config-edit.js +4 -2
  49. package/dist/config.d.ts +15 -2
  50. package/dist/config.js +62 -4
  51. package/dist/extension.d.ts +1 -0
  52. package/dist/extension.js +262 -136
  53. package/dist/identity.js +3 -2
  54. package/dist/init-config.js +2 -0
  55. package/dist/loop-cli.js +5 -1
  56. package/dist/loop-tools.d.ts +2 -3
  57. package/dist/loop-tools.js +12 -13
  58. package/dist/new-project.d.ts +5 -0
  59. package/dist/new-project.js +11 -0
  60. package/dist/pi-launch.js +2 -0
  61. package/dist/pi-themes.d.ts +3 -0
  62. package/dist/pi-themes.js +21 -0
  63. package/dist/pi.js +2 -2
  64. package/dist/plain-code-blocks.d.ts +14 -0
  65. package/dist/plain-code-blocks.js +56 -0
  66. package/dist/pointer-hover.d.ts +12 -0
  67. package/dist/pointer-hover.js +48 -0
  68. package/dist/question-dialog.d.ts +5 -0
  69. package/dist/question-dialog.js +20 -1
  70. package/dist/regenerate/chunk-plan.d.ts +2 -11
  71. package/dist/regenerate/chunk-plan.js +9 -20
  72. package/dist/regenerate/command-check.d.ts +9 -0
  73. package/dist/regenerate/command-check.js +163 -14
  74. package/dist/regenerate/job-panel.d.ts +5 -107
  75. package/dist/regenerate/job-panel.js +4 -289
  76. package/dist/regenerate/jobs-tree.d.ts +1 -0
  77. package/dist/regenerate/jobs-tree.js +5 -1
  78. package/dist/regenerate/loop.d.ts +6 -14
  79. package/dist/regenerate/loop.js +51 -35
  80. package/dist/regenerate/side-panel.d.ts +6 -1
  81. package/dist/regenerate/side-panel.js +158 -22
  82. package/dist/regenerate/spec-map-view.d.ts +11 -3
  83. package/dist/regenerate/spec-map-view.js +22 -2
  84. package/dist/regenerate/test-scripts.d.ts +8 -0
  85. package/dist/regenerate/test-scripts.js +20 -5
  86. package/dist/reopen.d.ts +29 -0
  87. package/dist/reopen.js +47 -0
  88. package/dist/resume-line.d.ts +4 -1
  89. package/dist/resume-line.js +5 -2
  90. package/dist/sentinel-chat.js +7 -2
  91. package/dist/sentinel.d.ts +1 -1
  92. package/dist/sentinel.js +4 -2
  93. package/dist/setup.js +9 -1
  94. package/dist/terminal-notifications.d.ts +31 -0
  95. package/dist/terminal-notifications.js +134 -0
  96. package/docs/README.md +2 -0
  97. package/docs/capture.md +207 -0
  98. package/docs/chats.md +8 -7
  99. package/docs/config.md +18 -3
  100. package/docs/development.md +4 -1
  101. package/docs/hosting.md +2 -2
  102. package/docs/launch.md +2 -2
  103. package/docs/regenerating.md +9 -8
  104. package/docs/sandbox.md +3 -1
  105. package/docs/sentinel.md +11 -11
  106. package/docs/skills-and-gates.md +1 -1
  107. package/docs/theming.md +3 -3
  108. package/docs/using.md +12 -5
  109. package/genome/capture/capture.md +26 -0
  110. package/genome/capture/check-conventions.md +5 -0
  111. package/genome/capture/check-reference.md +11 -0
  112. package/genome/capture/compact.md +7 -0
  113. package/genome/capture/concepts.md +3 -0
  114. package/genome/capture/divide.md +9 -0
  115. package/genome/capture/feature.md +45 -0
  116. package/genome/capture/interface.md +9 -0
  117. package/genome/capture/modules.md +23 -0
  118. package/genome/capture/outline.md +11 -0
  119. package/genome/capture/readability.md +12 -0
  120. package/genome/capture/reference.md +10 -0
  121. package/genome/capture/split.md +9 -0
  122. package/genome/capture/survey.md +37 -0
  123. package/genome/capture/trial.md +18 -0
  124. package/genome/capture/verify.md +7 -0
  125. package/genome/rules/turri-regeneration.md +2 -2
  126. package/package.json +3 -3
  127. package/dist/regenerate/steer.d.ts +0 -34
  128. package/dist/regenerate/steer.js +0 -91
package/dist/identity.js CHANGED
@@ -42,14 +42,15 @@ const IDENTITY_BEFORE = [
42
42
  "regenerative software - you write ***plain with them and regenerate the code from it. Never say they write the",
43
43
  "***plain and you help: you write it, together. Not an assistant, and not a helper with specifications: ***plain is",
44
44
  "the language the software is written in, and naming it is the point. Your replies are Markdown, where",
45
- "three asterisks start bold italics: write the name escaped, \\*\\*\\*plain, so it shows as ***plain.",
45
+ "three asterisks start bold italics: write the name escaped, \\*\\*\\*plain, so it shows as ***plain. ***plain you",
46
+ "show is fenced as ```plain, which highlights it.",
46
47
  "",
47
48
  "Speak as turri, in the first person - I, my pulses, my agents - to the person, in whole sentences. Never speak of",
48
49
  "turri in the third person, as if it were someone else, and never tell the person to tell or ask turri something:",
49
50
  "they are talking to turri. What they should ask for, they ask you for, here.",
50
51
  "",
51
52
  "The person may have several chats with you open on this project at once, this one among them. What regenerates is",
52
- "the same in every chat: the pulses and their plan, steering, the engine's coding model and what was launched -",
53
+ "the same in every chat: the pulses and their plan, the engine's coding model and what was launched -",
53
54
  "pulses lists every pulse, whichever chat asked for it. What was said in another chat is not in this one: when the",
54
55
  "person speaks of it, ask.",
55
56
  "",
@@ -350,6 +350,8 @@ export function quickStartConfig(vendor = "other", bedrock, models) {
350
350
  `${column(`# chat: ${harness}`, 72)}# the conversation - as harness-model, which it wins over`,
351
351
  `${column(`# sentinel: ${harness}`, 72)}# the sentinel: checks every finished pulse and tests what is launched`,
352
352
  role("planner", harness, "cuts the work into pulses"),
353
+ role("capture", harness, "captures an existing codebase into ***plain"),
354
+ role("capture-analysis", coding, "extracts the interface reference and outlines features during capture"),
353
355
  role("diagnosis", harness, "looks into a pulse that failed for good"),
354
356
  role("launch", coding, "the launch agent: turri launch's, the chat's and launch-after-pulse's"),
355
357
  `${column(`# coding: { model: ${coding}, thinking: ${ROLE_THINKING.coding}, turn-limit: 180 }`, 72)}# as coding-model, which it wins over`,
package/dist/loop-cli.js CHANGED
@@ -2,7 +2,7 @@ import { sweepOrphanedGroups } from "./regenerate/shell.js";
2
2
  import { refuseTestPlainFile } from "./test-plain-files.js";
3
3
  import { createInterface } from "node:readline/promises";
4
4
  import { resolve, sep } from "node:path";
5
- import { configForSpec, inheritModel, modelOnly, modelSpec, projectModels, readProjectConfig, roleModel, ROLE_THINKING, splitModelSpec, } from "./config.js";
5
+ import { brokenConfig, configForSpec, inheritModel, modelOnly, modelSpec, projectModels, readProjectConfig, roleModel, ROLE_THINKING, splitModelSpec, } from "./config.js";
6
6
  import { PACKAGE_ROOT } from "./environment.js";
7
7
  import { c } from "./module-report.js";
8
8
  import { describeTurnIncident, onModelEvent } from "./regenerate/activity.js";
@@ -26,6 +26,10 @@ import { configKeyOptions, optionValue } from "./cli-options.js";
26
26
  export async function runLoop(options) {
27
27
  const plainFile = resolve(options.plainFile);
28
28
  refuseTestPlainFile(plainFile);
29
+ // A config that does not parse is read as empty: refused, rather than every pulse run on defaults - pi's model among them.
30
+ const broken = brokenConfig(projectDirOf(plainFile));
31
+ if (broken !== undefined)
32
+ throw new Error(`Nothing was started: ${broken}`);
29
33
  // What a turri that was killed left running - commands' process groups - stopped before anything starts.
30
34
  const orphans = sweepOrphanedGroups();
31
35
  if (orphans > 0)
@@ -9,15 +9,14 @@ import type { LaunchTrack } from "./launch-track.ts";
9
9
  * own tools, on the conversation's loop, never copies of them.
10
10
  */
11
11
  type AnyTool = ToolDefinition<any, any, any>;
12
- /** How the queue is to be planned, for the work this call queues - see regenerate/steer.ts. */
13
- export declare const GUIDANCE_PARAM: Type.TOptional<Type.TString>;
14
12
  export declare const WORKING_DIR_PARAM: Type.TOptional<Type.TString>;
15
13
  export declare const MODEL_PARAM: Type.TOptional<Type.TString>;
16
14
  /**
17
15
  * Why a module cannot be built with the config it would be built with: two of the modules it requires have a config
18
16
  * file of their own (`configModuleFor`); or, in a project where modules have their own files, it has none - nor any
19
17
  * module it requires - and config.turri.yaml alone names no unit testing script, so every pulse would stop for want of
20
- * one. The files there are and the script each names, and what to do. Undefined when it can be built.
18
+ * one. The files there are and the script each names, and what to do. Undefined when it can be built - and while a unit
19
+ * testing script is being written in the project, which may be its own: the work loop holds it until it has one.
21
20
  */
22
21
  export declare function unbuildableConfig(plainFile: string): string | undefined;
23
22
  /** `work`, once the module asked for can be built with the config it would be built with - refused before anything is planned otherwise (`unbuildableConfig`). */
@@ -3,7 +3,7 @@ import { refuseTestPlainFile } from "./test-plain-files.js";
3
3
  import { basename, relative, resolve } from "node:path";
4
4
  import { defineTool } from "@earendil-works/pi-coding-agent";
5
5
  import { Type } from "typebox";
6
- import { CONFIG_FILE, readProjectConfig, moduleConfigFile, configModuleFor, moduleConfigsOf, withConfigModule } from "./config.js";
6
+ import { brokenConfig, CONFIG_FILE, readProjectConfig, moduleConfigFile, configModuleFor, moduleConfigsOf, withConfigModule } from "./config.js";
7
7
  import { checkPlainFile, formatCheckResults } from "./plain/check.js";
8
8
  import { describeDrift, describeModules } from "./regenerate/loop.js";
9
9
  import { describeJob, pulseName } from "./regenerate/jobs.js";
@@ -13,12 +13,8 @@ import { didNotLand } from "./regenerate/failure-reports.js";
13
13
  import { runningLaunched, stopLaunched } from "./regenerate/launch.js";
14
14
  import { projectDirOf } from "./regenerate/paths.js";
15
15
  import { findTestScripts } from "./regenerate/test-scripts.js";
16
+ import { scriptBeingWritten } from "./regenerate/scripts-being-written.js";
16
17
  import { surfaceOf } from "./surface.js";
17
- /** How the queue is to be planned, for the work this call queues - see regenerate/steer.ts. */
18
- export const GUIDANCE_PARAM = Type.Optional(Type.String({
19
- description: "How to plan the queue for this work, in a sentence or two - which functional specs go together, what first - as " +
20
- "the user said it, or as you understood it. A strong preference for the planner, within its limits. Omit when there is none.",
21
- }));
22
18
  export const WORKING_DIR_PARAM = Type.Optional(Type.String({
23
19
  description: "The folder the .plain files are in, relative to where turri was started - as if it had been started there " +
24
20
  "(e.g. \"plain\"). plain_file is then relative to it - hubspot.plain, not plain/hubspot.plain. Default: where " +
@@ -33,10 +29,15 @@ export const MODEL_PARAM = Type.Optional(Type.String({
33
29
  * Why a module cannot be built with the config it would be built with: two of the modules it requires have a config
34
30
  * file of their own (`configModuleFor`); or, in a project where modules have their own files, it has none - nor any
35
31
  * module it requires - and config.turri.yaml alone names no unit testing script, so every pulse would stop for want of
36
- * one. The files there are and the script each names, and what to do. Undefined when it can be built.
32
+ * one. The files there are and the script each names, and what to do. Undefined when it can be built - and while a unit
33
+ * testing script is being written in the project, which may be its own: the work loop holds it until it has one.
37
34
  */
38
35
  export function unbuildableConfig(plainFile) {
39
36
  const root = projectDirOf(plainFile);
37
+ // A config that does not parse is read as empty: built with it, every pulse would run on defaults - pi's model among them.
38
+ const broken = brokenConfig(root);
39
+ if (broken !== undefined)
40
+ return broken;
40
41
  let own;
41
42
  try {
42
43
  own = configModuleFor(plainFile);
@@ -45,7 +46,7 @@ export function unbuildableConfig(plainFile) {
45
46
  return error instanceof Error ? error.message : String(error);
46
47
  }
47
48
  const files = moduleConfigsOf(root);
48
- if (files.length === 0 || own !== undefined || findTestScripts(root).unit !== undefined)
49
+ if (files.length === 0 || own !== undefined || findTestScripts(root).unit !== undefined || scriptBeingWritten(root, "unit"))
49
50
  return undefined;
50
51
  const scripts = files.map((each) => {
51
52
  const unit = withConfigModule(each, () => findTestScripts(root).unit);
@@ -190,8 +191,7 @@ export function stopJob(jobs, named, reason, loop) {
190
191
  // A spec diff's change is in the .plain files: stopping its render does not take it out of the spec.
191
192
  const inSpec = target.kind === "regenerate"
192
193
  ? " Its change is still in the .plain files: nothing more is regenerated in that codebase until the spec changes or it is asked " +
193
- "for again with regenerate - then it is regenerated with the rest. To drop the change, take it out of the spec and regenerate; to change " +
194
- "how the work is cut or ordered, use steer."
194
+ "for again with regenerate - then it is regenerated with the rest. To drop the change, take it out of the spec and regenerate."
195
195
  : "";
196
196
  return stopped.status === "stopped"
197
197
  ? `Stopped ${pulseName(target)} (${target.id}) before it started.${queued}${inSpec}`
@@ -241,7 +241,6 @@ export function regenerateTool(options) {
241
241
  parameters: Type.Object({
242
242
  plain_file: Type.Optional(Type.String({ description: "Path to the .plain file. Omitted: the module the project's config.turri.yaml names" })),
243
243
  working_dir: WORKING_DIR_PARAM,
244
- guidance: GUIDANCE_PARAM,
245
244
  funcIds: Type.Optional(Type.Array(Type.String(), {
246
245
  description: "Functional specs already built, each as module:func-id (todo:add-task), to regenerate though their spec did not change. Omitted: what the spec now differs from the code in",
247
246
  })),
@@ -264,7 +263,7 @@ export function regenerateTool(options) {
264
263
  throw new Error("Name funcIds or set from_scratch, not both: from scratch regenerates every one of them.");
265
264
  const model = options.model !== undefined ? options.model(ctx, plainFile, given.model) : given.model;
266
265
  const loop = options.loop(ctx);
267
- const request = { ...(model !== undefined ? { model } : {}), ...(given.guidance !== undefined ? { guidance: given.guidance } : {}) };
266
+ const request = { ...(model !== undefined ? { model } : {}) };
268
267
  const wait = options.wait !== undefined ? options.wait(ctx, given.wait) : given.wait === true;
269
268
  const waiting = wait && options.jobs !== undefined ? { jobs: options.jobs, wait: startWait(options.jobs) } : undefined;
270
269
  let statuses;
@@ -329,7 +328,7 @@ export function haltTool(options) {
329
328
  promptSnippet: "halt a pulse, or a launch and what it started",
330
329
  promptGuidelines: [
331
330
  "Halt a pulse only when the user asks, or your instructions say to. Name which one, and say which pulses were queued behind it - they will now run.",
332
- "Halting a planned row halts its whole module - one planned pulse cannot be taken out alone, as the plan is made again from the spec. To build some of it later, or cut it differently, use steer; to drop work, change the spec.",
331
+ "Halting a planned row halts its whole module - one planned pulse cannot be taken out alone, as the plan is made again from the spec. To drop work, change the spec.",
333
332
  "A planned row for a module that is no longer in the project is halted the same way, and dropped.",
334
333
  ],
335
334
  parameters: HALT_PARAMS,
@@ -3,3 +3,8 @@
3
3
  * Spring Boot" - and the chat writes the ***plain itself, here, with no skill, regenerating from the first functional spec.
4
4
  */
5
5
  export declare const NEW_PROJECT: string;
6
+ /**
7
+ * Bringing an existing codebase under ***plain: the person starts /capture, never the chat - it runs a while, and turns
8
+ * conformance tests on in the project it writes.
9
+ */
10
+ export declare const CAPTURE_HINT: string;
@@ -29,3 +29,14 @@ export const NEW_PROJECT = [
29
29
  "go on, or what to change, and every change after is ***plain you write and regenerate.",
30
30
  "</new-project>",
31
31
  ].join("\n");
32
+ /**
33
+ * Bringing an existing codebase under ***plain: the person starts /capture, never the chat - it runs a while, and turns
34
+ * conformance tests on in the project it writes.
35
+ */
36
+ export const CAPTURE_HINT = [
37
+ "<capture>",
38
+ "When the person wants an existing codebase brought under ***plain - written down as ***plain, to work on from then on",
39
+ "instead of the code - tell them /capture [path] does it: in the background, asking nothing, into <path>/plain, with a",
40
+ "report of what it decided. Only they start it; you cannot.",
41
+ "</capture>",
42
+ ].join("\n");
package/dist/pi-launch.js CHANGED
@@ -15,6 +15,7 @@ import { withoutResumeLine } from "./resume-line.js";
15
15
  import { lastRun } from "./chat-records.js";
16
16
  import { driveTerminal } from "./chat-terminal.js";
17
17
  import { takeOverSettings } from "./pi-settings.js";
18
+ import { quietBrandThemeOverrides } from "./pi-themes.js";
18
19
  import turri, { createTurriCore, processSession } from "./extension.js";
19
20
  /**
20
21
  * pi, started the way its own CLI starts it, for `turri`.
@@ -45,6 +46,7 @@ ProcessTerminal.prototype.setTitle = function (title) {
45
46
  SettingsManager.prototype.getFullscreenExitOutput = () => "resume-hint";
46
47
  // /settings is turri's, pi's own menu the last entry of it (pi-settings.ts).
47
48
  takeOverSettings();
49
+ quietBrandThemeOverrides();
48
50
  const write = process.stdout.write.bind(process.stdout);
49
51
  process.stdout.write = ((chunk, ...rest) => write(typeof chunk === "string" ? withoutResumeLine(chunk) : chunk, ...rest));
50
52
  // pi's own keys stand: a new line is shift+enter or ctrl+j. turri's side panel is on ctrl+h (job-panel.ts PANEL_KEY).
@@ -0,0 +1,3 @@
1
+ /** pi already picks the project's theme over the user's, then turri's bundled fallback. In the chat these copies
2
+ * of a brand theme are expected; a broken file or a clash with a theme from elsewhere is still worth showing. */
3
+ export declare function quietBrandThemeOverrides(cwd?: string, agentDir?: string): void;
@@ -0,0 +1,21 @@
1
+ import { join, relative } from "node:path";
2
+ import { DefaultResourceLoader, getAgentDir } from "@earendil-works/pi-coding-agent";
3
+ import { PACKAGE_ROOT, themeFiles } from "./environment.js";
4
+ /** pi already picks the project's theme over the user's, then turri's bundled fallback. In the chat these copies
5
+ * of a brand theme are expected; a broken file or a clash with a theme from elsewhere is still worth showing. */
6
+ export function quietBrandThemeOverrides(cwd = process.cwd(), agentDir = getAgentDir()) {
7
+ const directories = [join(cwd, ".pi", "themes"), join(agentDir, "themes"), join(PACKAGE_ROOT, ".pi", "themes")];
8
+ const files = new Set(themeFiles());
9
+ const expected = ({ type, collision }) => {
10
+ if (type !== "collision" || collision?.resourceType !== "theme")
11
+ return false;
12
+ const file = `${collision.name}.json`;
13
+ const isCopy = (path) => directories.some((dir) => relative(dir, path) === file);
14
+ return files.has(file) && isCopy(collision.winnerPath) && isCopy(collision.loserPath);
15
+ };
16
+ const getThemes = DefaultResourceLoader.prototype.getThemes;
17
+ DefaultResourceLoader.prototype.getThemes = function () {
18
+ const { themes, diagnostics } = getThemes.call(this);
19
+ return { themes, diagnostics: diagnostics.filter((item) => !expected(item)) };
20
+ };
21
+ }
package/dist/pi.js CHANGED
@@ -237,8 +237,8 @@ export function providerRetryDelay(attempt, random = Math.random) {
237
237
  }
238
238
  /** How long a request to the model may go without anything coming back before the provider is said to be stalling; 0 never. */
239
239
  export const PROVIDER_STALL_MS = Number(process.env.TURRI_PROVIDER_STALL ?? 120) * 1000;
240
- /** A provider error that passes: overloaded, rate limited, unreachable, timed out. */
241
- const TRANSIENT_PROVIDER_ERROR = /\b(429|500|502|503|504|529)\b|overloaded|high demand|rate.?limit|too many requests|unavailable|fetch failed|network|connection|timed? ?out|ECONNRESET|socket|terminated/i;
240
+ /** A provider error that passes: overloaded, rate limited, unreachable, timed out, its stream cut off part-way. */
241
+ const TRANSIENT_PROVIDER_ERROR = /\b(429|500|502|503|504|529)\b|overloaded|high demand|rate.?limit|too many requests|unavailable|fetch failed|network|connection|timed? ?out|ECONNRESET|socket|terminated|truncated|stream ended/i;
242
242
  /** Wait, unless the job is stopped first. */
243
243
  async function waitOrStop(ms) {
244
244
  const stop = currentStopSignal();
@@ -0,0 +1,14 @@
1
+ import { type PlainRole } from "./plain/highlight.ts";
2
+ export declare function isPlainLanguage(lang: string | undefined): boolean;
3
+ /** Whether a fenced block is ***plain: fenced as plain, or fenced with no language around a section's header. */
4
+ export declare function isPlainBlock(lang: string | undefined, text: string): boolean;
5
+ /** Lines of ***plain, each piece painted by its role; the text around them in `rest`. */
6
+ export declare function highlightPlain(code: string, paint: (role: PlainRole, text: string) => string, rest?: (text: string) => string): string[];
7
+ /** What a theme says of itself that the palette needs: dark or light, and how many colours the terminal has. */
8
+ type ThemeLike = {
9
+ appearance?: "dark" | "light";
10
+ getColorMode?(): string;
11
+ };
12
+ /** From now on, a ***plain block in the chat is highlighted - in the colours of the theme `theme` gives at the time. */
13
+ export declare function highlightPlainCodeBlocks(theme: () => ThemeLike | undefined): void;
14
+ export {};
@@ -0,0 +1,56 @@
1
+ import { Markdown } from "@earendil-works/pi-tui";
2
+ import { highlightLines, roleOf } from "./plain/highlight.js";
3
+ import { plainPaint } from "./regenerate/plain-palette.js";
4
+ /**
5
+ * A fenced block of ***plain in the chat - ```plain, as an agent shows a module, or a fence with no language around
6
+ * a section's header - highlighted as turri highlights ***plain everywhere else: by its own grammar
7
+ * (plain/highlight.ts), in the colours of a ***plain diff (plain-palette.ts). pi highlights a code block through highlight.js, which knows no ***plain, and has no hook for
8
+ * a language of an extension's: so pi-tui's Markdown is patched, as chat-terminal.ts patches pi's screen - a ***plain
9
+ * block drawn with a highlighter of turri's in place of the theme's, every other block as pi draws it.
10
+ */
11
+ /** The fence's languages that are ***plain. */
12
+ const PLAIN_LANGUAGES = new Set(["plain", "***plain"]);
13
+ export function isPlainLanguage(lang) {
14
+ return lang !== undefined && PLAIN_LANGUAGES.has(lang.trim().toLowerCase());
15
+ }
16
+ /** A section's header on a line of its own - `***functional specs***` - which nothing but ***plain writes. */
17
+ const SECTION_HEADER = /^\*\*\*[a-z][a-z ]*\*\*\*[ \t]*$/m;
18
+ /** Whether a fenced block is ***plain: fenced as plain, or fenced with no language around a section's header. */
19
+ export function isPlainBlock(lang, text) {
20
+ return isPlainLanguage(lang) || ((lang ?? "").trim() === "" && SECTION_HEADER.test(text));
21
+ }
22
+ /** Lines of ***plain, each piece painted by its role; the text around them in `rest`. */
23
+ export function highlightPlain(code, paint, rest = (text) => text) {
24
+ return highlightLines(code.split("\n")).map((tokens) => tokens
25
+ .map((token) => {
26
+ const role = roleOf(token.scopes);
27
+ return role !== undefined ? paint(role, token.text) : rest(token.text);
28
+ })
29
+ .join(""));
30
+ }
31
+ let themeNow = () => undefined;
32
+ let patched = false;
33
+ /** From now on, a ***plain block in the chat is highlighted - in the colours of the theme `theme` gives at the time. */
34
+ export function highlightPlainCodeBlocks(theme) {
35
+ themeNow = theme;
36
+ if (patched)
37
+ return;
38
+ patched = true;
39
+ const prototype = Markdown.prototype;
40
+ const renderToken = prototype.renderToken;
41
+ prototype.renderToken = function (token, ...rest) {
42
+ const theme = this.theme;
43
+ const current = themeNow();
44
+ if (token.type !== "code" || !isPlainBlock(token.lang, token.text ?? "") || current === undefined)
45
+ return renderToken.call(this, token, ...rest);
46
+ const paint = plainPaint(current);
47
+ // Drawn by pi, with turri's highlighter in the theme's place for this block alone.
48
+ this.theme = { ...theme, highlightCode: (code) => highlightPlain(code, paint.syntax, theme.codeBlock) };
49
+ try {
50
+ return renderToken.call(this, token, ...rest);
51
+ }
52
+ finally {
53
+ this.theme = theme;
54
+ }
55
+ };
56
+ }
@@ -0,0 +1,12 @@
1
+ import type { Theme } from "@earendil-works/pi-coding-agent";
2
+ export type ButtonRole = "tab" | "new" | "close" | "panel" | "regenerating";
3
+ export type ButtonPaint = (text: string, active: boolean, hovered: boolean, role: ButtonRole) => string;
4
+ /** The layout owns the padding, so the entire coloured surface is also the click target. */
5
+ export declare function buttonLabel(theme: Theme, text: string, active: boolean, hovered: boolean, role: ButtonRole): string;
6
+ /** pi sends moves to the component under the pointer but has no leave event. Share one hover target across the
7
+ * screen: if the next input is dispatched elsewhere the old highlight goes away. Redraw only on a change. */
8
+ export declare class PointerHover {
9
+ target: string | undefined;
10
+ dispatch<T>(dispatch: () => T, redraw: () => void): T;
11
+ }
12
+ export declare function terminalPointer(terminal: object): PointerHover;
@@ -0,0 +1,48 @@
1
+ import { colorToRgb, parseColor } from "@earendil-works/pi-tui";
2
+ import { BRAND_PINK } from "./regenerate/plain-palette.js";
3
+ const abyss = parseColor("#0a0f1a");
4
+ const pink = parseColor(BRAND_PINK.dark);
5
+ const white = parseColor("#f4f7f9");
6
+ const linear = (byte) => byte <= 10 ? byte / 3294.6 : ((byte / 255 + 0.055) / 1.055) ** 2.4;
7
+ function luminance(color) {
8
+ const { r, g, b } = colorToRgb(color);
9
+ return 0.2126 * linear(r) + 0.7152 * linear(g) + 0.0722 * linear(b);
10
+ }
11
+ // The point at which white and abyss have equal contrast on a fill. Paint both sides explicitly: the
12
+ // terminal's own background can still be dark when the person picks the light theme (and vice versa).
13
+ const inkSwitch = Math.sqrt((luminance(abyss) + 0.05) * (luminance(white) + 0.05)) - 0.05;
14
+ /** The layout owns the padding, so the entire coloured surface is also the click target. */
15
+ export function buttonLabel(theme, text, active, hovered, role) {
16
+ if (role === "regenerating")
17
+ return theme.style(text, { bg: pink, fg: abyss, bold: true, underline: hovered });
18
+ if (role === "new" || active || hovered) {
19
+ const fill = theme.colors[role === "new" ? "success" : role === "close" && hovered ? "error" : "accent"];
20
+ return theme.style(text, { bg: fill, fg: luminance(fill) > inkSwitch ? abyss : white, bold: true, underline: hovered });
21
+ }
22
+ return theme.style(text, { bg: "selectedBg", fg: role === "panel" ? "accent" : "text", bold: role === "panel" });
23
+ }
24
+ /** pi sends moves to the component under the pointer but has no leave event. Share one hover target across the
25
+ * screen: if the next input is dispatched elsewhere the old highlight goes away. Redraw only on a change. */
26
+ export class PointerHover {
27
+ target;
28
+ dispatch(dispatch, redraw) {
29
+ const before = this.target;
30
+ this.target = undefined;
31
+ try {
32
+ return dispatch();
33
+ }
34
+ finally {
35
+ if (before !== this.target)
36
+ redraw();
37
+ }
38
+ }
39
+ }
40
+ const pointers = new WeakMap();
41
+ export function terminalPointer(terminal) {
42
+ let pointer = pointers.get(terminal);
43
+ if (pointer === undefined) {
44
+ pointer = new PointerHover();
45
+ pointers.set(terminal, pointer);
46
+ }
47
+ return pointer;
48
+ }
@@ -18,6 +18,8 @@ export interface QuestionDialogOptions {
18
18
  question: string;
19
19
  /** The choices. Without them, a line to type the answer on. */
20
20
  options?: string[];
21
+ /** Clickable choices when this dialog is embedded in the side panel. */
22
+ clickable?: boolean;
21
23
  /** The choice the cursor starts on. */
22
24
  selected?: number;
23
25
  /** The terminal's height, for the window the brief scrolls in. */
@@ -40,6 +42,9 @@ export declare class QuestionDialog implements Component, Focusable {
40
42
  private maxScroll;
41
43
  private window;
42
44
  private answered;
45
+ private choiceLines;
46
+ private choiceTop;
47
+ private pressed;
43
48
  private focusedNow;
44
49
  constructor(options: QuestionDialogOptions);
45
50
  get focused(): boolean;
@@ -15,6 +15,9 @@ export class QuestionDialog {
15
15
  maxScroll = 0;
16
16
  window = 0;
17
17
  answered = false;
18
+ choiceLines = [];
19
+ choiceTop = 0;
20
+ pressed;
18
21
  focusedNow = false;
19
22
  constructor(options) {
20
23
  this.options = options;
@@ -61,10 +64,13 @@ export class QuestionDialog {
61
64
  const brief = context === "" ? [] : context.split("\n").flatMap((line) => (line.trim() === "" ? [""] : wrapTextWithAnsi(styled(line, style), inner)));
62
65
  const question = wrapTextWithAnsi(style.bold(style.accent(this.options.question)), inner);
63
66
  const choices = this.options.options ?? [];
67
+ this.choiceLines = [];
64
68
  const body = this.input !== undefined
65
69
  ? this.input.render(inner)
66
70
  : // A long option wraps, its lines under its first, rather than cut off where the person cannot read it.
67
71
  choices.flatMap((choice, index) => wrapTextWithAnsi(choice, Math.max(1, inner - 2)).map((line, at) => {
72
+ if (this.options.clickable)
73
+ this.choiceLines.push(index);
68
74
  const shown = `${at === 0 && index === this.selected ? "›" : " "} ${line}`;
69
75
  return index === this.selected ? style.accent(shown) : shown;
70
76
  }));
@@ -89,7 +95,9 @@ export class QuestionDialog {
89
95
  }
90
96
  lines.push("");
91
97
  }
92
- lines.push(...question.map(pad), ...body.map(pad), "", pad(style.muted(hint)));
98
+ lines.push(...question.map(pad));
99
+ this.choiceTop = lines.length;
100
+ lines.push(...body.map(pad), "", pad(style.muted(hint)));
93
101
  return lines;
94
102
  }
95
103
  handleInput(data) {
@@ -131,6 +139,17 @@ export class QuestionDialog {
131
139
  }
132
140
  }
133
141
  handleMouse(event) {
142
+ if (this.options.clickable && event.button === "left" && (event.type === "press" || event.type === "click")) {
143
+ const index = this.choiceLines[event.y - this.choiceTop];
144
+ const down = this.pressed;
145
+ this.pressed = event.type === "press" ? index : undefined;
146
+ if (index === undefined)
147
+ return;
148
+ this.selected = index;
149
+ if (event.type === "click" && down === index)
150
+ this.finish(this.options.options?.[index]);
151
+ return { handled: true };
152
+ }
134
153
  if (event.type !== "wheel" || event.wheelDelta === undefined || this.maxScroll === 0)
135
154
  return undefined;
136
155
  this.scrollBy(event.wheelDelta);
@@ -1,5 +1,4 @@
1
1
  import { type MarshalledPlainSource } from "../plain/spec.ts";
2
- import { type Steering } from "./steer.ts";
3
2
  import { type SpecChange, type SpecStep, type TestPlainPath } from "./spec-steps.ts";
4
3
  /**
5
4
  * The queue's work, cut into jobs of a size worth rendering.
@@ -30,8 +29,6 @@ export interface PlanInput {
30
29
  base: MarshalledPlainSource;
31
30
  /** What it ends on: the spec as the track sees it now. */
32
31
  current: MarshalledPlainSource;
33
- /** How the person wants the work cut and ordered. */
34
- steering?: Steering[];
35
32
  /** The module whose codebase it is: its own functional specs are given with it. */
36
33
  moduleName?: string;
37
34
  /** The module's .plain file, as the diffs name it, and its text - for the diffs' layout. */
@@ -123,12 +120,8 @@ export interface GroupAnswer {
123
120
  change: number;
124
121
  to: number | "first";
125
122
  }>;
126
- /** What of the person's wishes it did not follow, and why. */
127
- notes?: string;
128
123
  }
129
124
  export interface PlaceInput {
130
- /** How the person or the harness wants the queue planned. */
131
- steering?: Steering[];
132
125
  groups: Array<{
133
126
  number: number;
134
127
  title: string;
@@ -157,8 +150,6 @@ export interface PlaceAnswer {
157
150
  req: number;
158
151
  to: Target;
159
152
  }>;
160
- /** What of the person's wishes it did not follow, and why. */
161
- notes?: string;
162
153
  }
163
154
  /**
164
155
  * A group to title: the number the agent answers with, and its functional specs' text - or, for a pulse that makes the
@@ -190,7 +181,7 @@ export interface TitleAnswer {
190
181
  * too, shown the edit's changes; without it, that pulse is titled by `editTitle`.
191
182
  */
192
183
  export interface ChunkAgents {
193
- group(specs: NewSpec[], check: (answer: GroupAnswer) => string[], steering?: Steering[], maxSpecs?: number, built?: BuiltChange[]): Promise<GroupAnswer | undefined>;
184
+ group(specs: NewSpec[], check: (answer: GroupAnswer) => string[], maxSpecs?: number, built?: BuiltChange[]): Promise<GroupAnswer | undefined>;
194
185
  place(input: PlaceInput, check: (answer: PlaceAnswer) => string[]): Promise<PlaceAnswer | undefined>;
195
186
  title?(groups: TitleGroup[], check: (answer: TitleAnswer) => string[], track: "code" | "conformance"): Promise<TitleAnswer | undefined>;
196
187
  }
@@ -215,7 +206,7 @@ export declare function editTitle(changes: SpecChange[]): string;
215
206
  */
216
207
  export declare function builtTitle(changes: SpecChange[]): string;
217
208
  export declare function planChunks(input: PlanInput, agents?: ChunkAgents, notes?: string[]): Promise<DraftJob[]>;
218
- export declare function groupPrompt(specs: NewSpec[], steering?: Steering[], maxSpecs?: number, built?: BuiltChange[]): string;
209
+ export declare function groupPrompt(specs: NewSpec[], maxSpecs?: number, built?: BuiltChange[]): string;
219
210
  export declare function placePrompt(input: PlaceInput): string;
220
211
  export declare function titlePrompt(groups: TitleGroup[], track: "code" | "conformance"): string;
221
212
  /** The chunking's agents, on a model - fresh for every plan. */
@@ -5,7 +5,6 @@ import { ACCEPTANCE_TESTS, CONFORMANCE_TESTS, DEFINITIONS, FUNCTIONAL_REQUIREMEN
5
5
  import { ask, BEGIN, createExecutor } from "../pi.js";
6
6
  import { reportActivity, reportStage } from "./activity.js";
7
7
  import { firstLine, record } from "./ledger.js";
8
- import { steeringBlock } from "./steer.js";
9
8
  import { marksRegenerateAgain } from "./records.js";
10
9
  import { validateConcepts } from "../plain/concepts.js";
11
10
  import { applyChanges, changesBetween, inconsistencies, layoutOf, makeStep, parseTree, serializeTree } from "./spec-steps.js";
@@ -384,9 +383,9 @@ function titleChangeOf(change) {
384
383
  }
385
384
  /**
386
385
  * Cut the queue's work - from `input.base` to `input.current` - into jobs, as the three steps say. Returns the draft
387
- * the work loop runs: checked (checkDraft), or, when nothing holds, the whole work as one job. `notes` is given what
388
- * the plan did not do as asked - the person's wishes an agent did not follow and why, an answer that did not hold, a
389
- * group split for its size - for the conversation to say, rather than guess.
386
+ * the work loop runs: checked (checkDraft), or, when nothing holds, the whole work as one job. `notes` is given where
387
+ * the plan fell back - an answer that was not given or did not hold, a group split for its size - for the conversation
388
+ * to say, rather than guess.
390
389
  */
391
390
  /** A planner agent that failed: the plan falls back, and the ledger says why. */
392
391
  function plannerFailed(step, error) {
@@ -495,7 +494,7 @@ function funcIdOf(change) {
495
494
  async function cut(input, agents, notes) {
496
495
  // How big a pulse may be: the config's, else the defaults.
497
496
  const { specs: maxSpecs, lines: maxLines } = input.limits ?? { specs: MAX_SPECS_PER_JOB, lines: MAX_LINES_PER_JOB };
498
- /** What the plan did not do as asked: in the activity, and in the notes. */
497
+ /** Where the plan fell back: in the activity, and in the notes. */
499
498
  const say = (text) => {
500
499
  reportActivity(` ${text}`);
501
500
  notes?.push(text);
@@ -598,7 +597,7 @@ async function cut(input, agents, notes) {
598
597
  say(answer === undefined ? "the titles were not given - each pulse titled by its functional specs' first lines" : `the titles did not hold (${problems.join(" ")}) - each pulse titled by its functional specs' first lines`);
599
598
  return list;
600
599
  };
601
- const grouped = conformance ? undefined : ((await agents?.group(numbered, (answer) => groupProblems(numbered, answer, maxSpecs, builtShown), input.steering, maxSpecs, builtShown.length > 0 ? builtShown : undefined).catch((error) => plannerFailed("group", error))) ?? undefined);
600
+ const grouped = conformance ? undefined : ((await agents?.group(numbered, (answer) => groupProblems(numbered, answer, maxSpecs, builtShown), maxSpecs, builtShown.length > 0 ? builtShown : undefined).catch((error) => plannerFailed("group", error))) ?? undefined);
602
601
  const holds = grouped !== undefined && groupProblems(numbered, grouped, maxSpecs, builtShown).length === 0;
603
602
  // The grouping holds: each change to what is built goes where it was placed.
604
603
  if (holds) {
@@ -617,8 +616,6 @@ async function cut(input, agents, notes) {
617
616
  : grouped !== undefined && holds
618
617
  ? grouped.groups
619
618
  : numbered.map((spec, index) => ({ specs: [spec.number], title: titleOf(specs[index]) }));
620
- if (grouped?.notes !== undefined && grouped.notes.trim() !== "")
621
- say(`the grouping: ${grouped.notes.trim()}`);
622
619
  if (!conformance && agents !== undefined) {
623
620
  if (grouped === undefined) {
624
621
  record({ kind: "planner.fellBack", step: "group", why: "no grouping was given" });
@@ -641,15 +638,12 @@ async function cut(input, agents, notes) {
641
638
  if (implementationReqs.length + testReqs.length > 0) {
642
639
  reportStage(`planning the queue: where each of ${implementationReqs.length + testReqs.length} new req${implementationReqs.length + testReqs.length === 1 ? "" : "s"} goes`);
643
640
  const placeInput = {
644
- ...(input.steering !== undefined ? { steering: input.steering } : {}),
645
641
  groups: newChunks().map((chunk, index) => ({ number: index + 1, title: chunk.title, specs: chunk.specs.map(textOf), definitions: chunk.definitions.map(textOf) })),
646
642
  built: chunks.some((chunk) => chunk.built !== undefined),
647
643
  implementationReqs: implementationReqs.map((change, index) => ({ number: index + 1, text: textOf(change) })),
648
644
  testReqs: testReqs.map((change, index) => ({ number: index + 1, text: textOf(change) })),
649
645
  };
650
646
  const answer = (await planners?.place(placeInput, (given) => placeProblems(placeInput, given)).catch((error) => plannerFailed("place", error))) ?? undefined;
651
- if (answer?.notes !== undefined && answer.notes.trim() !== "")
652
- say(`the placement: ${answer.notes.trim()}`);
653
647
  placement = answer !== undefined && placeProblems(placeInput, answer).length === 0 ? answer : undefined;
654
648
  if (placement === undefined && planners !== undefined)
655
649
  record({ kind: "planner.fellBack", step: "place", why: answer === undefined ? "no placement was given" : firstLine(placeProblems(placeInput, answer).join(" "), 300) });
@@ -741,7 +735,7 @@ async function cut(input, agents, notes) {
741
735
  }
742
736
  // ---------------------------------------------------------------------------------------------
743
737
  // The agents.
744
- export function groupPrompt(specs, steering, maxSpecs = MAX_SPECS_PER_JOB, built = []) {
738
+ export function groupPrompt(specs, maxSpecs = MAX_SPECS_PER_JOB, built = []) {
745
739
  return [
746
740
  "You plan how new work on a codebase is built: which of its new functional specs are built together, in one job.",
747
741
  "",
@@ -760,7 +754,6 @@ export function groupPrompt(specs, steering, maxSpecs = MAX_SPECS_PER_JOB, built
760
754
  "The specification is split into modules - a ***plain matter, not how the code is laid out. A functional spec has a",
761
755
  "func-id, unique in its module: each below is given with its module, its func-id, its place among the module's functional specs, and a number of its own to answer with.",
762
756
  "",
763
- ...steeringBlock(steering),
764
757
  ...(specs.some((spec) => spec.again === true)
765
758
  ? [
766
759
  "Those marked again=\"true\" are built already, and are regenerated again - rewritten, doing what they say. Group them as",
@@ -804,7 +797,6 @@ export function placePrompt(input) {
804
797
  "- A test req goes with the first group whose conformance tests need it; one about all the tests to \"all\".",
805
798
  ...(input.built ? ['- "built" is the job that changes what is built already, and goes first: a req about the code there already goes there.'] : []),
806
799
  "",
807
- ...steeringBlock(input.steering),
808
800
  ...input.groups.map((group) => [
809
801
  // A title that is only its first spec's first line is not said twice.
810
802
  group.specs[0] !== undefined && group.specs[0].includes(group.title.trim().replace(/\.$/, "")) ? `<group number="${group.number}">` : `<group number="${group.number}" title="${group.title}">`,
@@ -852,7 +844,6 @@ export function titlePrompt(groups, track) {
852
844
  ].join("\n");
853
845
  }
854
846
  const TargetSchema = Type.Union([Type.Number(), Type.Literal("all"), Type.Literal("built")]);
855
- const NOTES = "Each of the person's wishes for how the queue is planned that you did not follow, and why - a limit it would break, say. Leave it out when you followed them all, or there are none.";
856
847
  /** Ask one step of an agent, and ask again with what was wrong, until it holds or the retries are spent. */
857
848
  async function askStep(options) {
858
849
  let answer;
@@ -877,11 +868,11 @@ async function askStep(options) {
877
868
  export function llmChunkAgents(options) {
878
869
  const label = options.label ?? "queue planner";
879
870
  return {
880
- group: (specs, check, steering, maxSpecs, built) => askStep({
871
+ group: (specs, check, maxSpecs, built) => askStep({
881
872
  cwd: options.cwd,
882
873
  model: options.model,
883
874
  label: `${label} grouping`,
884
- task: groupPrompt(specs, steering, maxSpecs, built),
875
+ task: groupPrompt(specs, maxSpecs, built),
885
876
  check,
886
877
  tool: (take) => defineTool({
887
878
  name: "submit_groups",
@@ -892,7 +883,6 @@ export function llmChunkAgents(options) {
892
883
  built: Type.Optional(Type.Array(Type.Object({ change: Type.Number(), to: Type.Union([Type.Number(), Type.Literal("first")]) }), {
893
884
  description: 'Where each change to what is built goes: with a group, by its number, or "first" - a pulse of its own, before the new work.',
894
885
  })),
895
- notes: Type.Optional(Type.String({ description: NOTES })),
896
886
  }),
897
887
  async execute(_id, params) {
898
888
  take(params);
@@ -913,11 +903,10 @@ export function llmChunkAgents(options) {
913
903
  parameters: Type.Object({
914
904
  implementation_reqs: Type.Array(Type.Object({ req: Type.Number(), to: TargetSchema })),
915
905
  test_reqs: Type.Array(Type.Object({ req: Type.Number(), to: TargetSchema })),
916
- notes: Type.Optional(Type.String({ description: NOTES })),
917
906
  }),
918
907
  async execute(_id, params) {
919
908
  const given = params;
920
- take({ implementationReqs: given.implementation_reqs, testReqs: given.test_reqs, ...(given.notes !== undefined ? { notes: given.notes } : {}) });
909
+ take({ implementationReqs: given.implementation_reqs, testReqs: given.test_reqs });
921
910
  return { content: [{ type: "text", text: "Recorded." }], details: {}, terminate: true };
922
911
  },
923
912
  }),