@turri-dev/core 0.1.1-next.8cda3cc → 0.1.1-next.ad4aa8f

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 (163) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +17 -11
  3. package/dist/api/models.d.ts +9 -0
  4. package/dist/api/models.js +15 -0
  5. package/dist/api/plain.d.ts +6 -6
  6. package/dist/api/plain.js +4 -7
  7. package/dist/api/project.d.ts +35 -0
  8. package/dist/api/project.js +47 -0
  9. package/dist/api/session.d.ts +48 -0
  10. package/dist/api/session.js +17 -0
  11. package/dist/api/system.d.ts +18 -0
  12. package/dist/api/system.js +23 -0
  13. package/dist/btw.d.ts +1 -1
  14. package/dist/capture/capture.js +11 -8
  15. package/dist/capture/chat.d.ts +0 -11
  16. package/dist/capture/chat.js +0 -29
  17. package/dist/capture/config.d.ts +4 -5
  18. package/dist/capture/config.js +34 -20
  19. package/dist/capture/models.d.ts +2 -1
  20. package/dist/capture/models.js +1 -0
  21. package/dist/chat-entries.d.ts +81 -39
  22. package/dist/chat-entries.js +125 -11
  23. package/dist/chat-model.d.ts +37 -0
  24. package/dist/chat-model.js +61 -0
  25. package/dist/chats.d.ts +54 -42
  26. package/dist/chats.js +86 -80
  27. package/dist/client.d.ts +30 -0
  28. package/dist/client.js +12 -0
  29. package/dist/config-edit.d.ts +54 -1
  30. package/dist/config-edit.js +103 -33
  31. package/dist/config.d.ts +12 -9
  32. package/dist/config.js +38 -9
  33. package/dist/doctor-checks.d.ts +42 -0
  34. package/dist/doctor-checks.js +39 -0
  35. package/dist/environment.d.ts +2 -23
  36. package/dist/environment.js +5 -68
  37. package/dist/errors.d.ts +32 -0
  38. package/dist/errors.js +24 -0
  39. package/dist/extension.d.ts +23 -16
  40. package/dist/extension.js +170 -234
  41. package/dist/identity.d.ts +1 -1
  42. package/dist/identity.js +13 -9
  43. package/dist/init-config.d.ts +11 -9
  44. package/dist/init-config.js +15 -7
  45. package/dist/launch-session.d.ts +2 -0
  46. package/dist/launch-session.js +17 -1
  47. package/dist/loop-tools.js +11 -10
  48. package/dist/module-check.d.ts +13 -0
  49. package/dist/module-check.js +117 -0
  50. package/dist/notice.d.ts +5 -0
  51. package/dist/parse-tool.js +3 -2
  52. package/dist/plain/check.d.ts +27 -13
  53. package/dist/plain/check.js +51 -116
  54. package/dist/plain/files.d.ts +2 -0
  55. package/dist/plain/files.js +13 -0
  56. package/dist/plain/graph.js +2 -2
  57. package/dist/plain/highlight.d.ts +4 -20
  58. package/dist/plain/highlight.js +7 -5
  59. package/dist/project.d.ts +19 -0
  60. package/dist/project.js +34 -0
  61. package/dist/quiet.d.ts +0 -2
  62. package/dist/quiet.js +0 -14
  63. package/dist/regenerate/command-check.d.ts +0 -8
  64. package/dist/regenerate/command-check.js +133 -53
  65. package/dist/regenerate/conversation-writes.d.ts +5 -1
  66. package/dist/regenerate/conversation-writes.js +7 -3
  67. package/dist/regenerate/jobs.d.ts +25 -2
  68. package/dist/regenerate/jobs.js +3 -0
  69. package/dist/regenerate/launch.d.ts +1 -0
  70. package/dist/regenerate/launch.js +9 -0
  71. package/dist/regenerate/ledger-view.d.ts +14 -14
  72. package/dist/regenerate/ledger.d.ts +1 -0
  73. package/dist/regenerate/ledger.js +4 -2
  74. package/dist/regenerate/loop.d.ts +2 -1
  75. package/dist/regenerate/loop.js +9 -1
  76. package/dist/regenerate/os-sandbox.d.ts +4 -2
  77. package/dist/regenerate/os-sandbox.js +0 -1
  78. package/dist/regenerate/regenerate.js +2 -1
  79. package/dist/regenerate/requires-chain.d.ts +44 -0
  80. package/dist/regenerate/requires-chain.js +174 -0
  81. package/dist/regenerate/requires.d.ts +2 -40
  82. package/dist/regenerate/requires.js +14 -171
  83. package/dist/regenerate/resources.d.ts +0 -2
  84. package/dist/regenerate/resources.js +2 -14
  85. package/dist/regenerate/shell.js +20 -9
  86. package/dist/regenerate/spec-map.d.ts +2 -0
  87. package/dist/regenerate/spec-map.js +4 -0
  88. package/dist/regenerate/standing.d.ts +5 -2
  89. package/dist/run-report.js +2 -2
  90. package/dist/self-invocation.d.ts +1 -1
  91. package/dist/self-invocation.js +2 -3
  92. package/dist/sentinel-chat.js +7 -11
  93. package/dist/sentinel.d.ts +1 -1
  94. package/dist/sentinel.js +12 -5
  95. package/dist/session-events.d.ts +14 -0
  96. package/dist/session.d.ts +594 -0
  97. package/dist/session.js +672 -0
  98. package/dist/settings.d.ts +28 -2
  99. package/dist/settings.js +92 -56
  100. package/dist/setup.d.ts +6 -30
  101. package/dist/setup.js +28 -105
  102. package/dist/stack.d.ts +25 -12
  103. package/dist/stack.js +77 -12
  104. package/dist/surface.d.ts +2 -2
  105. package/dist/surface.js +4 -5
  106. package/dist/work.d.ts +125 -0
  107. package/dist/work.js +250 -0
  108. package/docs/README.md +2 -3
  109. package/docs/capture.md +4 -4
  110. package/docs/chats.md +5 -3
  111. package/docs/claude-subscription.md +2 -2
  112. package/docs/config.md +4 -4
  113. package/docs/core.md +105 -128
  114. package/docs/development.md +9 -9
  115. package/docs/headless.md +1 -1
  116. package/docs/installation.md +4 -2
  117. package/docs/launch.md +2 -2
  118. package/docs/parser.md +1 -1
  119. package/docs/regenerating.md +1 -1
  120. package/docs/sandbox.md +4 -4
  121. package/docs/sentinel.md +4 -4
  122. package/docs/skills-and-gates.md +1 -1
  123. package/docs/using.md +2 -2
  124. package/genome/rules/integration-embedded-testing.md +3 -3
  125. package/genome/rules/integration-embedded.md +3 -3
  126. package/genome/skills/implement-conformance-testing-script/SKILL.md +6 -4
  127. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_java.sh +13 -11
  128. package/genome/skills/implement-conformance-testing-script/assets/run_conformance_tests_python.sh +8 -7
  129. package/genome/skills/implement-unit-testing-script/SKILL.md +7 -5
  130. package/genome/skills/implement-unit-testing-script/assets/run_unittests_java.sh +9 -13
  131. package/genome/skills/implement-unit-testing-script/assets/run_unittests_python.sh +1 -1
  132. package/package.json +19 -32
  133. package/dist/api/commands.d.ts +0 -45
  134. package/dist/api/commands.js +0 -54
  135. package/dist/api/config.d.ts +0 -8
  136. package/dist/api/config.js +0 -8
  137. package/dist/api/ledger.d.ts +0 -3
  138. package/dist/api/ledger.js +0 -3
  139. package/dist/api/startup.d.ts +0 -8
  140. package/dist/api/startup.js +0 -8
  141. package/dist/api/terminal.d.ts +0 -18
  142. package/dist/api/terminal.js +0 -16
  143. package/dist/chat-models.d.ts +0 -11
  144. package/dist/chat-models.js +0 -11
  145. package/dist/chat-ui.d.ts +0 -33
  146. package/dist/chat-ui.js +0 -192
  147. package/dist/headless.d.ts +0 -99
  148. package/dist/headless.js +0 -226
  149. package/dist/host-session.d.ts +0 -136
  150. package/dist/host-session.js +0 -139
  151. package/dist/host.d.ts +0 -8
  152. package/dist/host.js +0 -17
  153. package/dist/index.d.ts +0 -16
  154. package/dist/index.js +0 -7
  155. package/dist/notifications.d.ts +0 -21
  156. package/dist/notifications.js +0 -44
  157. package/dist/reopen.d.ts +0 -29
  158. package/dist/reopen.js +0 -47
  159. package/dist/turri-versions.d.ts +0 -71
  160. package/dist/turri-versions.js +0 -276
  161. package/dist/view.d.ts +0 -78
  162. package/dist/view.js +0 -1
  163. package/docs/hosting.md +0 -284
@@ -1,3 +1,4 @@
1
+ import { type AgentRole } from "./config.ts";
1
2
  /**
2
3
  * `/settings`' and the chat's settings tool's side of config.turri.yaml: every setting turri reads, what it takes - a yes or no, one of a few words, a
3
4
  * number, a model, a list - and when a change to it takes effect, so the person knows whether to wait for the next
@@ -7,9 +8,51 @@
7
8
  /** When a change takes effect. Nothing turri reads needs a restart: what is fixed at its start is changed live. */
8
9
  export type Effect = "now" | "next-message" | "next-pulse" | "next-plan" | "next-test-run" | "next-landing" | "next-regenerate" | "next-start";
9
10
  export type SettingKind = "boolean" | "choice" | "number" | "model" | "list" | "path";
11
+ /** A role with an entry of its own under `models:` - each agent role, and `default`, which the others take. */
12
+ export type ModelRole = "default" | AgentRole;
13
+ /**
14
+ * What each setting takes, by its key as config.turri.yaml writes it: a model as provider/model-id with an optional
15
+ * `:thinking`, a path from the project root, a list as YAML's.
16
+ */
17
+ export type SettingValues = {
18
+ "harness-model": string;
19
+ "coding-model": string;
20
+ "judge-model": string;
21
+ module: string;
22
+ review: boolean;
23
+ "mutation-testing": boolean;
24
+ "allow-to-stop-jobs": boolean;
25
+ "launch-after-pulse": boolean;
26
+ sentinel: boolean | "ask";
27
+ "conformance-tests": boolean;
28
+ "test-dir": string;
29
+ "base-folder": string;
30
+ "unittests-script": string;
31
+ "conformance-tests-script": string;
32
+ "prepare-environment-script": string;
33
+ "testing-scripts-run-on": "in-place" | "copy";
34
+ "parallel-jobs": number;
35
+ "max-specs-per-pulse": number;
36
+ "max-lines-per-pulse": number;
37
+ "turn-limit": number;
38
+ "compact-at": number;
39
+ "rules-off": string[];
40
+ "agent-env.files": string[];
41
+ "agent-env.vars": string[];
42
+ toolchains: string[];
43
+ debug: boolean;
44
+ "cache-keep": number;
45
+ "ledger-keep": number;
46
+ } & {
47
+ [R in ModelRole as `models.${R}`]: string;
48
+ } & {
49
+ [R in ModelRole as `models.${R}.turn-limit`]: number;
50
+ };
51
+ /** A setting, by its key as config.turri.yaml writes it. */
52
+ export type SettingKey = keyof SettingValues;
10
53
  export interface Setting {
11
54
  /** As written in the file - a nested one by its path: `models.coding`, `models.coding.turn-limit`, `agent-env.files`. */
12
- key: string;
55
+ key: SettingKey;
13
56
  /** What it does, in a line. */
14
57
  about: string;
15
58
  kind: SettingKind;
@@ -62,6 +105,16 @@ export declare function withSetting(text: string, key: string, value: unknown):
62
105
  export declare function currentValue(text: string, key: string): unknown;
63
106
  /** A value for showing: `true`, `anthropic/claude-opus-5-5:low`, `[.env, .env.local]`. */
64
107
  export declare function shownValue(value: unknown): string;
108
+ /** What a setting takes, in words: `true or false`, `a model, provider/model-id[:thinking]`, `one of in-place, copy`. */
109
+ export declare function settingTakes(setting: Setting): string;
110
+ /**
111
+ * A setting's value in config.turri.yaml - or `module`'s own config.turri.<module>.yaml - as its kind takes it; undefined
112
+ * when it is unset there. A model is read as provider/model-id[:thinking], its turn limit apart. A value its kind
113
+ * cannot take throws `config-invalid`, naming the file and what it takes; a key there is no setting of, `not-found`.
114
+ */
115
+ export declare function readSetting<K extends SettingKey>(projectDir: string, key: K, options?: {
116
+ module?: string;
117
+ }): SettingValues[K] | undefined;
65
118
  /** The project's config.turri.yaml - or the config.yaml it is read from until it has one - its text, empty when there is neither. */
66
119
  export declare function readConfigText(dir: string): string;
67
120
  /**
@@ -4,6 +4,7 @@ import { dump as dumpYaml, load as loadYaml } from "js-yaml";
4
4
  import { PACKAGE_ROOT } from "./environment.js";
5
5
  import { loadRules } from "./rules.js";
6
6
  import { adoptLegacyConfig, AGENT_ROLES, CONFIG_FILE, moduleConfigFile, moduleConfigFileIn, moduleConfigsOf, projectConfigFile, splitModelSpec, THINKING_LEVELS } from "./config.js";
7
+ import { TurriError } from "./errors.js";
7
8
  /** What each effect is, said to the person. */
8
9
  export const EFFECT_TEXT = {
9
10
  now: "in effect now",
@@ -57,37 +58,41 @@ export function settings(rules = []) {
57
58
  min: 0,
58
59
  },
59
60
  ]);
60
- return [
61
- { key: "harness-model", about: "the model you talk to: it writes the ***plain and plans the work", kind: "model", unset: "pi's own choice", effect: "now", projectOnly: true },
62
- { key: "coding-model", about: "the model that writes the code", kind: "model", unset: "harness-model", effect: "next-pulse" },
63
- { key: "judge-model", about: "the judge and the test review of a conformance run", kind: "model", unset: "coding-model", effect: "next-pulse" },
64
- { key: "module", about: "the .plain file turri regenerate builds when none is named", kind: "path", unset: "the folder's .plain files", effect: "next-regenerate", projectOnly: true },
65
- { key: "review", about: "whether the code and its tests are reviewed once they pass", kind: "boolean", unset: "true", effect: "next-pulse" },
66
- { key: "mutation-testing", about: "whether the coding agent and the reviewer can put a bug in the code for one test run (can_it_fail)", kind: "boolean", unset: "true", effect: "next-pulse" },
67
- { key: "allow-to-stop-jobs", about: "whether turri stops a running pulse the ***plain has moved on from", kind: "boolean", unset: "true", effect: "now" },
68
- { key: "launch-after-pulse", about: "whether every pulse that lands code is launched, in the background", kind: "boolean", unset: "false", effect: "next-landing" },
69
- { key: "sentinel", about: "whether a chat of its own checks every finished pulse, tests what is launched, and tells you what is wrong - ask: you are asked before it first opens", kind: "choice", options: ["ask", "true", "false"], unset: "ask", effect: "next-landing", personOnly: true },
70
- { key: "conformance-tests", about: "whether functional specs' scenarios are written and conformance tested - false: none, and the chat's conform refused", kind: "boolean", unset: "false", effect: "now", personOnly: true },
71
- { key: "test-dir", about: "the folder of the test plain files, a folder per module in it, by path from the project root", kind: "path", unset: "tests", effect: "now" },
72
- { key: "base-folder", about: "a folder a codebase that requires no other module starts from, by path from the project root - code to build on, files to use, copied in once", kind: "path", unset: "none: it starts empty", effect: "next-pulse" },
73
- { key: "unittests-script", about: "the unit testing script, by path from the project root", kind: "path", unset: "the one run_unittests*.sh found", effect: "next-test-run" },
74
- { key: "conformance-tests-script", about: "the conformance testing script, by path from the project root", kind: "path", unset: "the one run_conformance_tests*.sh found", effect: "next-test-run" },
75
- { key: "prepare-environment-script", about: "run on the build before every conformance testing script run, by path from the project root - optional", kind: "path", unset: "the one prepare_environment*.sh found, else none", effect: "next-test-run" },
76
- { key: "testing-scripts-run-on", about: "what the testing scripts run on: the code itself, or a fresh copy", kind: "choice", options: ["in-place", "copy"], unset: "in-place", effect: "next-test-run" },
77
- { key: "parallel-jobs", about: "how many pulses run at once, on modules that share nothing", kind: "number", options: ["1", "2", "3", "4", "6"], min: 1, unset: "half this machine's cores, one to four", effect: "now", projectOnly: true },
78
- { key: "max-specs-per-pulse", about: "the most functional specs the planner groups into one pulse", kind: "number", options: ["1", "2", "3", "4", "5", "6"], min: 1, unset: "3", effect: "next-plan" },
79
- { key: "max-lines-per-pulse", about: "the most lines of ***plain in one pulse before a group is split", kind: "number", options: ["60", "120", "200", "300"], min: 1, unset: "120", effect: "next-plan" },
80
- { key: "turn-limit", about: "seconds each agent turn has, for every role without its own - 0 for none", kind: "number", options: SECONDS, min: 0, unset: "120", effect: "next-pulse" },
81
- { key: "compact-at", about: "tokens of work an agent holds before it is compacted between turns", kind: "number", options: ["50000", "100000", "150000", "200000"], min: 1000, unset: "100000", effect: "next-pulse", projectOnly: true },
82
- { key: "rules-off", about: "***plain rules left out of the prompts of the agents that write ***plain", kind: "list", options: rules, unset: "none", effect: "next-message", projectOnly: true, personOnly: true },
83
- { key: "agent-env.files", about: "dotenv files whose variables the agents' commands get", kind: "list", unset: "none", effect: "next-pulse", projectOnly: true, personOnly: true },
84
- { key: "agent-env.vars", about: "variables from turri's environment the agents' commands get, by name", kind: "list", unset: "none", effect: "next-pulse", projectOnly: true, personOnly: true },
85
- { key: "toolchains", about: "folders of this machine an agent's commands may read beside the usual ones", kind: "list", unset: "none", effect: "next-pulse", projectOnly: true, personOnly: true },
86
- { key: "debug", about: "whether turri keeps what it writes for debugging it - agents' logs and sessions, pulse logs, outputs", kind: "boolean", unset: "false", effect: "next-pulse", projectOnly: true },
87
- { key: "cache-keep", about: "megabytes of package caches the project keeps; 0 keeps none", kind: "number", options: ["0", "1024", "4096", "16384"], min: 0, unset: "4096", effect: "next-start", projectOnly: true },
88
- { key: "ledger-keep", about: "megabytes of the ledger - what turri did, as facts - the project keeps; 0 keeps none", kind: "number", options: ["0", "50", "100", "500"], min: 0, unset: "100", effect: "next-start", projectOnly: true, personOnly: true },
89
- ...roles,
90
- ];
61
+ const fixed = Object.entries(fixedSettings(rules)).map(([key, entry]) => ({ key, ...entry }));
62
+ return [...fixed, ...roles];
63
+ }
64
+ /** The settings that are not a role's, by key - each one there, with the kind its value takes. */
65
+ function fixedSettings(rules) {
66
+ return {
67
+ "harness-model": { about: "the model you talk to: it writes the ***plain and plans the work", kind: "model", unset: "pi's own choice", effect: "now", projectOnly: true },
68
+ "coding-model": { about: "the model that writes the code", kind: "model", unset: "harness-model", effect: "next-pulse" },
69
+ "judge-model": { about: "the judge and the test review of a conformance run", kind: "model", unset: "coding-model", effect: "next-pulse" },
70
+ module: { about: "the .plain file turri regenerate builds when none is named", kind: "path", unset: "the folder's .plain files", effect: "next-regenerate", projectOnly: true },
71
+ review: { about: "whether the code and its tests are reviewed once they pass", kind: "boolean", unset: "true", effect: "next-pulse" },
72
+ "mutation-testing": { about: "whether the coding agent and the reviewer can put a bug in the code for one test run (can_it_fail)", kind: "boolean", unset: "true", effect: "next-pulse" },
73
+ "allow-to-stop-jobs": { about: "whether turri stops a running pulse the ***plain has moved on from", kind: "boolean", unset: "true", effect: "now" },
74
+ "launch-after-pulse": { about: "whether every pulse that lands code is launched, in the background", kind: "boolean", unset: "false", effect: "next-landing" },
75
+ sentinel: { about: "whether a chat of its own checks every finished pulse, tests what is launched, and tells you what is wrong - ask: you are asked before it first opens", kind: "choice", options: ["ask", "true", "false"], unset: "ask", effect: "next-landing", personOnly: true },
76
+ "conformance-tests": { about: "whether functional specs' scenarios are written and conformance tested - false: none, and the chat's conform refused", kind: "boolean", unset: "false", effect: "now", personOnly: true },
77
+ "test-dir": { about: "the folder of the test plain files, a folder per module in it, by path from the project root", kind: "path", unset: "tests", effect: "now" },
78
+ "base-folder": { about: "a folder a codebase that requires no other module starts from, by path from the project root - code to build on, files to use, copied in once", kind: "path", unset: "none: it starts empty", effect: "next-pulse" },
79
+ "unittests-script": { about: "the unit testing script, by path from the project root", kind: "path", unset: "the one run_unittests*.sh found", effect: "next-test-run" },
80
+ "conformance-tests-script": { about: "the conformance testing script, by path from the project root", kind: "path", unset: "the one run_conformance_tests*.sh found", effect: "next-test-run" },
81
+ "prepare-environment-script": { about: "run on the build before every conformance testing script run, by path from the project root - optional", kind: "path", unset: "the one prepare_environment*.sh found, else none", effect: "next-test-run" },
82
+ "testing-scripts-run-on": { about: "what the testing scripts run on: the code itself, or a fresh copy", kind: "choice", options: ["in-place", "copy"], unset: "in-place", effect: "next-test-run" },
83
+ "parallel-jobs": { about: "how many pulses run at once, on modules that share nothing", kind: "number", options: ["1", "2", "3", "4", "6"], min: 1, unset: "half this machine's cores, one to four", effect: "now", projectOnly: true },
84
+ "max-specs-per-pulse": { about: "the most functional specs the planner groups into one pulse", kind: "number", options: ["1", "2", "3", "4", "5", "6"], min: 1, unset: "3", effect: "next-plan" },
85
+ "max-lines-per-pulse": { about: "the most lines of ***plain in one pulse before a group is split", kind: "number", options: ["60", "120", "200", "300"], min: 1, unset: "120", effect: "next-plan" },
86
+ "turn-limit": { about: "seconds each agent turn has, for every role without its own - 0 for none", kind: "number", options: SECONDS, min: 0, unset: "120", effect: "next-pulse" },
87
+ "compact-at": { about: "tokens of work an agent holds before it is compacted between turns", kind: "number", options: ["50000", "100000", "150000", "200000"], min: 1000, unset: "100000", effect: "next-pulse", projectOnly: true },
88
+ "rules-off": { about: "***plain rules left out of the prompts of the agents that write ***plain", kind: "list", options: rules, unset: "none", effect: "next-message", projectOnly: true, personOnly: true },
89
+ "agent-env.files": { about: "dotenv files whose variables the agents' commands get", kind: "list", unset: "none", effect: "next-pulse", projectOnly: true, personOnly: true },
90
+ "agent-env.vars": { about: "variables from turri's environment the agents' commands get, by name", kind: "list", unset: "none", effect: "next-pulse", projectOnly: true, personOnly: true },
91
+ toolchains: { about: "folders of this machine an agent's commands may read beside the usual ones", kind: "list", unset: "none", effect: "next-pulse", projectOnly: true, personOnly: true },
92
+ debug: { about: "whether turri keeps what it writes for debugging it - agents' logs and sessions, pulse logs, outputs", kind: "boolean", unset: "false", effect: "next-pulse", projectOnly: true },
93
+ "cache-keep": { about: "megabytes of package caches the project keeps; 0 keeps none", kind: "number", options: ["0", "1024", "4096", "16384"], min: 0, unset: "4096", effect: "next-start", projectOnly: true },
94
+ "ledger-keep": { about: "megabytes of the ledger - what turri did, as facts - the project keeps; 0 keeps none", kind: "number", options: ["0", "50", "100", "500"], min: 0, unset: "100", effect: "next-start", projectOnly: true, personOnly: true },
95
+ };
91
96
  }
92
97
  /** Every setting, as a host is given them: rules-off offering turri's own rules, as /settings offers them. */
93
98
  export function configSettings() {
@@ -180,8 +185,16 @@ function blockOf(lines, key) {
180
185
  if (at === -1)
181
186
  return undefined;
182
187
  let end = at + 1;
183
- while (end < lines.length && /^\s+\S/.test(lines[end]) && !/^\s*#/.test(lines[end]))
184
- end += 1;
188
+ // Commented examples and blank lines can separate active roles in models:. Stop at the next key,
189
+ // leaving trailing comments alone, or writing the mapping back would duplicate the roles below them.
190
+ for (let i = end; i < lines.length; i++) {
191
+ const line = lines[i];
192
+ if (/^\s*(?:#|$)/.test(line))
193
+ continue;
194
+ if (!/^\s/.test(line))
195
+ break;
196
+ end = i + 1;
197
+ }
185
198
  return { at, end };
186
199
  }
187
200
  /**
@@ -307,6 +320,63 @@ export function shownValue(value) {
307
320
  }
308
321
  return inline(value);
309
322
  }
323
+ /** What a setting takes, in words: `true or false`, `a model, provider/model-id[:thinking]`, `one of in-place, copy`. */
324
+ export function settingTakes(setting) {
325
+ switch (setting.kind) {
326
+ case "boolean":
327
+ return "true or false";
328
+ case "model":
329
+ return "a model, provider/model-id[:thinking]";
330
+ case "path":
331
+ return "a path from the project root";
332
+ case "list":
333
+ return `a list${setting.options !== undefined && setting.options.length > 0 ? ` of ${setting.options.join(", ")}` : ""}`;
334
+ case "number":
335
+ return setting.options !== undefined ? `a number - e.g. ${setting.options.join(", ")}` : "a number";
336
+ case "choice":
337
+ return `one of ${(setting.options ?? []).join(", ")}`;
338
+ }
339
+ }
340
+ /**
341
+ * A setting's value in config.turri.yaml - or `module`'s own config.turri.<module>.yaml - as its kind takes it; undefined
342
+ * when it is unset there. A model is read as provider/model-id[:thinking], its turn limit apart. A value its kind
343
+ * cannot take throws `config-invalid`, naming the file and what it takes; a key there is no setting of, `not-found`.
344
+ */
345
+ export function readSetting(projectDir, key, options = {}) {
346
+ const setting = settingOf(key);
347
+ if (setting === undefined)
348
+ throw new TurriError("not-found", `There is no setting ${String(key)}.`);
349
+ const { module } = options;
350
+ const raw = currentValue(module !== undefined ? readModuleConfigText(projectDir, module) : readConfigText(projectDir), setting.key);
351
+ if (raw === undefined || raw === null)
352
+ return undefined;
353
+ const read = valueOfKind(setting, raw);
354
+ if (read === WRONG)
355
+ throw new TurriError("config-invalid", `${module !== undefined ? moduleConfigFile(module) : CONFIG_FILE}'s ${setting.key} is ${inline(raw)}: it takes ${settingTakes(setting)}.`);
356
+ return read;
357
+ }
358
+ const WRONG = Symbol("wrong");
359
+ /** A value as a file has it, read as its setting's kind takes it - undefined, a model with no model or thinking; WRONG, one it cannot take. */
360
+ function valueOfKind(setting, raw) {
361
+ switch (setting.kind) {
362
+ case "boolean":
363
+ return typeof raw === "boolean" ? raw : WRONG;
364
+ case "number":
365
+ return typeof raw === "number" && Number.isFinite(raw) ? raw : WRONG;
366
+ case "list":
367
+ return Array.isArray(raw) && raw.every((item) => typeof item === "string") ? [...raw] : typeof raw === "string" ? [raw] : WRONG;
368
+ case "path":
369
+ return typeof raw === "string" ? raw : WRONG;
370
+ case "choice":
371
+ return (typeof raw === "string" || typeof raw === "boolean") && (setting.options ?? []).includes(String(raw)) ? raw : WRONG;
372
+ case "model": {
373
+ if (typeof raw !== "string" && (typeof raw !== "object" || Array.isArray(raw)))
374
+ return WRONG;
375
+ const shown = shownValue(raw);
376
+ return shown === "" ? undefined : shown;
377
+ }
378
+ }
379
+ }
310
380
  /** The project's config.turri.yaml - or the config.yaml it is read from until it has one - its text, empty when there is neither. */
311
381
  export function readConfigText(dir) {
312
382
  const path = join(dir, projectConfigFile(dir));
package/dist/config.d.ts CHANGED
@@ -356,13 +356,13 @@ export declare const CONFIG_KEYS: {
356
356
  */
357
357
  export declare function readProjectConfig(root: string, module?: string): ProjectConfig;
358
358
  /**
359
- * What a command's own options say of the config's keys - `turri regenerate --harness-model`, `--coding-model`,
360
- * `--judge-model`, `--review`, `--mutation-testing` - read as if the file had them: each takes its key's value, and
361
- * every key keeps its place in the order, so a run is the same as one with them in config.turri.yaml - a `models:`
362
- * entry still winning over `harness-model`, `coding-model` or `judge-model`. A headless run needs no config file
363
- * edited. Never set in the conversation.
359
+ * A session's own values for config keys - a front end's `--harness-model`, `--coding-model`, `--judge-model`,
360
+ * `--review`, `--mutation-testing` - read in its project as if config.turri.yaml had them: each takes its key's value and
361
+ * keeps its place in the order, so a `models:` entry still wins over `harness-model`, `coding-model` or `judge-model`.
362
+ * No config file is edited. Set by the session as it opens and cleared as it closes; a key the person sets with
363
+ * /settings drops the session's value for it.
364
364
  */
365
- type RunOverrides = Partial<Pick<ProjectConfig, "harnessModel" | "codingModel" | "judgeModel" | "review" | "mutationTesting">>;
365
+ export type ConfigOverrides = Partial<Pick<ProjectConfig, "harnessModel" | "codingModel" | "judgeModel" | "review" | "mutationTesting" | "debug">>;
366
366
  /** Megabytes of package caches a project keeps when `cache-keep:` does not say. */
367
367
  export declare const DEFAULT_CACHE_KEEP_MB = 4096;
368
368
  /**
@@ -370,8 +370,12 @@ export declare const DEFAULT_CACHE_KEEP_MB = 4096;
370
370
  * `0` or `false` turns it off - else the project's `debug:`. Off by default.
371
371
  */
372
372
  export declare function debugMode(project: string): boolean;
373
- /** Read a command's options as the config's keys for the rest of this process. */
374
- export declare function overrideConfig(overrides: RunOverrides): void;
373
+ /** The session's overrides in `project` - undefined to clear them. */
374
+ export declare function setConfigOverrides(project: string, overrides: ConfigOverrides | undefined): void;
375
+ /** The overrides that hold in `folder`: its project's session's, when one is open there or above it. */
376
+ export declare function configOverrides(folder: string): ConfigOverrides;
377
+ /** The session's value for one key dropped, in the project holding `folder` - the person set the key itself. */
378
+ export declare function dropConfigOverride(folder: string, key: keyof ConfigOverrides): void;
375
379
  /** `--review <value>`, `--mutation-testing <value>`: the config's own, true or false. Undefined for anything else. */
376
380
  export declare function booleanOption(value: string): boolean | undefined;
377
381
  /** Where the test plain files are when `test-dir:` does not say. */
@@ -427,4 +431,3 @@ export declare function configProblems(root: string): Array<{
427
431
  }>;
428
432
  /** Why a project's config does not parse, in a sentence for a refusal - undefined when every file of it parses. */
429
433
  export declare function brokenConfig(root: string): string | undefined;
430
- export {};
package/dist/config.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import { copyFileSync, existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
3
- import { basename, join, resolve } from "node:path";
3
+ import { basename, isAbsolute, join, relative, resolve } from "node:path";
4
4
  import { load as loadYaml } from "js-yaml";
5
5
  import { projectDirOf, resolveTemplateDirs } from "./regenerate/paths.js";
6
6
  /**
@@ -528,7 +528,7 @@ function text(value) {
528
528
  * not parse.
529
529
  */
530
530
  export function readProjectConfig(root, module) {
531
- return withRunOverrides(readLayeredConfig(root, module));
531
+ return withSessionOverrides(root, readLayeredConfig(root, module));
532
532
  }
533
533
  function readLayeredConfig(root, module) {
534
534
  // A key turri has renamed, renamed in the files as they are first read.
@@ -551,7 +551,8 @@ function readLayeredConfig(root, module) {
551
551
  merged.models = joinModels(project.models, own.models);
552
552
  return withoutUndefined(merged);
553
553
  }
554
- let runOverrides = {};
554
+ /** The open sessions' overrides, by their project's folder. */
555
+ const sessionOverrides = new Map();
555
556
  /** Megabytes of package caches a project keeps when `cache-keep:` does not say. */
556
557
  export const DEFAULT_CACHE_KEEP_MB = 4096;
557
558
  /**
@@ -569,18 +570,46 @@ export function debugMode(project) {
569
570
  return false;
570
571
  }
571
572
  }
572
- /** Read a command's options as the config's keys for the rest of this process. */
573
- export function overrideConfig(overrides) {
574
- runOverrides = { ...overrides };
573
+ /** The session's overrides in `project` - undefined to clear them. */
574
+ export function setConfigOverrides(project, overrides) {
575
+ const key = resolve(project);
576
+ const given = Object.fromEntries(Object.entries(overrides ?? {}).filter(([, value]) => value !== undefined));
577
+ if (Object.keys(given).length === 0)
578
+ sessionOverrides.delete(key);
579
+ else
580
+ sessionOverrides.set(key, given);
581
+ }
582
+ /** The folder of the open session whose project holds `folder`, if one does. */
583
+ function sessionProjectOf(folder) {
584
+ const at = resolve(folder);
585
+ for (const project of sessionOverrides.keys()) {
586
+ const from = relative(project, at);
587
+ if (from === "" || (!from.startsWith("..") && !isAbsolute(from)))
588
+ return project;
589
+ }
590
+ return undefined;
591
+ }
592
+ /** The overrides that hold in `folder`: its project's session's, when one is open there or above it. */
593
+ export function configOverrides(folder) {
594
+ const project = sessionProjectOf(folder);
595
+ return project !== undefined ? sessionOverrides.get(project) : {};
596
+ }
597
+ /** The session's value for one key dropped, in the project holding `folder` - the person set the key itself. */
598
+ export function dropConfigOverride(folder, key) {
599
+ const project = sessionProjectOf(folder);
600
+ if (project === undefined)
601
+ return;
602
+ const { [key]: _dropped, ...rest } = sessionOverrides.get(project);
603
+ setConfigOverrides(project, rest);
575
604
  }
576
605
  /** `--review <value>`, `--mutation-testing <value>`: the config's own, true or false. Undefined for anything else. */
577
606
  export function booleanOption(value) {
578
607
  const word = value.trim().toLowerCase();
579
608
  return word === "true" ? true : word === "false" ? false : undefined;
580
609
  }
581
- /** The config with the command's options in place of the keys they name. */
582
- function withRunOverrides(config) {
583
- const given = Object.entries(runOverrides).filter(([, value]) => value !== undefined);
610
+ /** The config with the session's overrides in place of the keys they name. */
611
+ function withSessionOverrides(root, config) {
612
+ const given = Object.entries(configOverrides(root));
584
613
  return given.length === 0 ? config : { ...config, ...Object.fromEntries(given) };
585
614
  }
586
615
  /** A module's `models:` over the project's, role by role - each entry taking what it leaves out from the project's; the chat's the project's alone. */
@@ -0,0 +1,42 @@
1
+ /**
2
+ * What doctor is asked - the project, whether to ask its models, models of the caller's own - and what its checks come
3
+ * to, told. Apart from the checks (setup.ts), so the machine's entry loads no pi until doctor runs.
4
+ */
5
+ import { type ProjectConfig } from "./config.ts";
6
+ import type { Check, Level } from "./node-check.ts";
7
+ export declare const MARK: Record<Level, string>;
8
+ /** Models doctor checks in place of the config's - named on a command line - as provider/model-id[:thinking]. */
9
+ export interface DoctorModels {
10
+ harnessModel?: string;
11
+ codingModel?: string;
12
+ judgeModel?: string;
13
+ }
14
+ export interface DoctorOptions {
15
+ /** The project to check. Without it, only the machine. */
16
+ dir?: string;
17
+ /** Ask each model the project's config names for a word - a request a model, which costs money. Off by default. */
18
+ models?: boolean;
19
+ /**
20
+ * Models of the caller's own, checked in place of the config's - as a session's overrides are read, a role's own
21
+ * `models:` entry still winning - and asked, with `models`. Their AWS region is worked out with the config's.
22
+ */
23
+ overrides?: DoctorModels;
24
+ /** The environment whose PATH is looked in - bash, git, the sandbox, the toolchains, what the testing scripts run. */
25
+ env?: NodeJS.ProcessEnv;
26
+ }
27
+ /** Whether doctor asks the models: asked to, and a config that names them - or a session's own models in the project. */
28
+ export declare function asksModels(options: DoctorOptions): options is DoctorOptions & {
29
+ dir: string;
30
+ };
31
+ /** The models given, as the config's keys hold them. */
32
+ export declare function modelChoices(given: DoctorModels): Partial<Pick<ProjectConfig, "harnessModel" | "codingModel" | "judgeModel">>;
33
+ /** The models given, as specs. */
34
+ export declare function specsOf(given: DoctorModels): string[];
35
+ /** What the checks add up to: whether turri can run here, and a line saying so - with its marks, uncoloured. */
36
+ export declare function verdictOf(checks: Check[]): {
37
+ ready: boolean;
38
+ limited: boolean;
39
+ text: string;
40
+ };
41
+ /** The checks as plain text, a line each and what to do under it, and the verdict - for a reader that is not a terminal. */
42
+ export declare function describeChecks(checks: Check[]): string;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * What doctor is asked - the project, whether to ask its models, models of the caller's own - and what its checks come
3
+ * to, told. Apart from the checks (setup.ts), so the machine's entry loads no pi until doctor runs.
4
+ */
5
+ import { configOverrides, hasProjectConfig, splitModelSpec } from "./config.js";
6
+ export const MARK = { ok: "✓", missing: "✗", limited: "!", info: "·" };
7
+ /** Whether doctor asks the models: asked to, and a config that names them - or a session's own models in the project. */
8
+ export function asksModels(options) {
9
+ if (options.models !== true || options.dir === undefined)
10
+ return false;
11
+ const given = { ...configOverrides(options.dir), ...modelChoices(options.overrides ?? {}) };
12
+ return hasProjectConfig(options.dir) || given.harnessModel !== undefined || given.codingModel !== undefined || given.judgeModel !== undefined;
13
+ }
14
+ /** The models given, as the config's keys hold them. */
15
+ export function modelChoices(given) {
16
+ const choice = (spec) => (spec !== undefined && spec.trim() !== "" ? splitModelSpec(spec.trim()) : undefined);
17
+ const [harnessModel, codingModel, judgeModel] = [choice(given.harnessModel), choice(given.codingModel), choice(given.judgeModel)];
18
+ return { ...(harnessModel !== undefined ? { harnessModel } : {}), ...(codingModel !== undefined ? { codingModel } : {}), ...(judgeModel !== undefined ? { judgeModel } : {}) };
19
+ }
20
+ /** The models given, as specs. */
21
+ export function specsOf(given) {
22
+ return Object.values(modelChoices(given)).flatMap((choice) => (choice?.model !== undefined ? [choice.model] : []));
23
+ }
24
+ /** What the checks add up to: whether turri can run here, and a line saying so - with its marks, uncoloured. */
25
+ export function verdictOf(checks) {
26
+ const missing = checks.filter((check) => check.level === "missing").length;
27
+ if (missing > 0)
28
+ return { ready: false, limited: false, text: `Not ready: ${missing} thing${missing === 1 ? "" : "s"} to fix (✗ above).` };
29
+ return checks.some((check) => check.level === "limited") ? { ready: true, limited: true, text: "Ready, with limits (! above)." } : { ready: true, limited: false, text: "Ready." };
30
+ }
31
+ /** The checks as plain text, a line each and what to do under it, and the verdict - for a reader that is not a terminal. */
32
+ export function describeChecks(checks) {
33
+ const lines = checks.flatMap((check) => [
34
+ `${MARK[check.level]} ${check.name}: ${check.detail}`,
35
+ ...(check.more ?? []).map((line) => ` ${line}`),
36
+ ...(check.fix && check.level !== "ok" ? [` → ${check.fix}`] : []),
37
+ ]);
38
+ return `${lines.join("\n")}\n\n${verdictOf(checks).text}`;
39
+ }
@@ -6,36 +6,15 @@
6
6
  /** The core's own package: its genome, stdlib, docs and grammar are read from here. */
7
7
  export declare const PACKAGE_ROOT: string;
8
8
  export declare const AGENT_DIR: string;
9
- /** Where this turri is - the core's own package unless a front end set it. */
10
- export declare function turriRoot(): string;
11
- /** The front end that runs the core says it is this turri: its package's root, from then on, for every question about it. */
12
- export declare function setTurriRoot(root: string): void;
13
9
  /** The oldest Node that runs .ts files by itself, which is how turri runs. */
14
10
  export declare const MIN_NODE: readonly [22, 19];
15
11
  export declare function nodeVersionOk(version?: string): boolean;
16
12
  /** Whether a command runs at all. */
17
13
  export declare function runs(command: string, args?: string[]): boolean;
18
- /** The global pi extension file that loads turri into every `pi`, if there is one. */
19
- export declare function globalExtensionFile(): string | undefined;
20
- export declare function extensionInstalledGlobally(): boolean;
21
- export declare function themeFiles(): string[];
22
- /**
23
- * Are this project's themes already installed globally?
24
- *
25
- * Passing --theme as well would make pi load each of them twice and report a collision
26
- * on startup - the global copy wins and the project copy is skipped, which is noise
27
- * about a duplicate we created ourselves.
28
- */
29
- export declare function themesInstalledGlobally(): boolean;
30
14
  /** The version of the pi turri runs on, as Node finds it - undefined when it is not installed. */
31
15
  export declare function piVersion(): string | undefined;
32
- /**
33
- * What `turri --version` prints: turri's version - from a clone, its commit too, as the banner says it - and pi's
34
- * beside it. pi's own `--version` says only pi's, which read as turri's.
35
- */
36
- export declare function versionLine(identity?: ReturnType<typeof turriIdentity>, pi?: string | null): string;
37
- /** turri's version, and the commit when it runs from a clone. */
38
- export declare function turriIdentity(): {
16
+ /** The core's own version, and the commit when it runs from a clone. */
17
+ export declare function coreIdentity(): {
39
18
  version: string | null;
40
19
  git_commit: string | null;
41
20
  git_dirty: boolean | null;
@@ -1,7 +1,7 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { existsSync, readdirSync, readFileSync } from "node:fs";
2
+ import { existsSync, readFileSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
- import { dirname, join, resolve } from "node:path";
4
+ import { dirname, join } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  /**
7
7
  * What turri needs from the machine it runs on, found out without changing anything.
@@ -11,20 +11,6 @@ import { fileURLToPath } from "node:url";
11
11
  /** The core's own package: its genome, stdlib, docs and grammar are read from here. */
12
12
  export const PACKAGE_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
13
13
  export const AGENT_DIR = join(homedir(), ".pi", "agent");
14
- /**
15
- * This turri: the package the person runs - its version and clone, the turri on the PATH that is this one, its themes, a
16
- * global pi extension file naming it. The core's own until the front end that runs it says it is its own, before it asks
17
- * any of these: PACKAGE_ROOT stays the core's, for the files it reads.
18
- */
19
- let thisTurri = PACKAGE_ROOT;
20
- /** Where this turri is - the core's own package unless a front end set it. */
21
- export function turriRoot() {
22
- return thisTurri;
23
- }
24
- /** The front end that runs the core says it is this turri: its package's root, from then on, for every question about it. */
25
- export function setTurriRoot(root) {
26
- thisTurri = resolve(root);
27
- }
28
14
  /** The oldest Node that runs .ts files by itself, which is how turri runs. */
29
15
  export const MIN_NODE = [22, 19];
30
16
  export function nodeVersionOk(version = process.versions.node) {
@@ -36,47 +22,6 @@ export function runs(command, args = ["--version"]) {
36
22
  const result = spawnSync(command, args, { stdio: "ignore", timeout: 15_000 });
37
23
  return result.status === 0;
38
24
  }
39
- /** The global pi extension file that loads turri into every `pi`, if there is one. */
40
- export function globalExtensionFile() {
41
- const dir = join(AGENT_DIR, "extensions");
42
- try {
43
- for (const entry of readdirSync(dir)) {
44
- try {
45
- if (readFileSync(join(dir, entry), "utf8").includes(turriRoot()))
46
- return join(dir, entry);
47
- }
48
- catch {
49
- // Not a file we can read; not ours.
50
- }
51
- }
52
- }
53
- catch {
54
- // No extensions directory yet.
55
- }
56
- return undefined;
57
- }
58
- export function extensionInstalledGlobally() {
59
- return globalExtensionFile() !== undefined;
60
- }
61
- export function themeFiles() {
62
- try {
63
- return readdirSync(join(turriRoot(), ".pi", "themes")).filter((entry) => entry.endsWith(".json"));
64
- }
65
- catch {
66
- return [];
67
- }
68
- }
69
- /**
70
- * Are this project's themes already installed globally?
71
- *
72
- * Passing --theme as well would make pi load each of them twice and report a collision
73
- * on startup - the global copy wins and the project copy is skipped, which is noise
74
- * about a duplicate we created ourselves.
75
- */
76
- export function themesInstalledGlobally() {
77
- const names = themeFiles();
78
- return names.length > 0 && names.every((name) => existsSync(join(AGENT_DIR, "themes", name)));
79
- }
80
25
  /** The version of the pi turri runs on, as Node finds it - undefined when it is not installed. */
81
26
  export function piVersion() {
82
27
  try {
@@ -95,17 +40,9 @@ export function piVersion() {
95
40
  }
96
41
  return undefined;
97
42
  }
98
- /**
99
- * What `turri --version` prints: turri's version - from a clone, its commit too, as the banner says it - and pi's
100
- * beside it. pi's own `--version` says only pi's, which read as turri's.
101
- */
102
- export function versionLine(identity = turriIdentity(), pi = piVersion() ?? null) {
103
- const clone = identity.git_commit !== null ? `, from a clone, ${identity.git_commit.slice(0, 7)}${identity.git_dirty === true ? " with changes" : ""}` : "";
104
- return `turri ${identity.version ?? "0.0.0"}${clone}${pi !== null ? ` (pi ${pi})` : ""}`;
105
- }
106
- /** turri's version, and the commit when it runs from a clone. */
107
- export function turriIdentity() {
108
- const root = turriRoot();
43
+ /** The core's own version, and the commit when it runs from a clone. */
44
+ export function coreIdentity() {
45
+ const root = PACKAGE_ROOT;
109
46
  let version = null;
110
47
  try {
111
48
  version = JSON.parse(readFileSync(join(root, "package.json"), "utf8")).version ?? null;