@turri-dev/core 0.1.1-next.35d4c49 → 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,9 +1,10 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import { basename, dirname, join, resolve } from "node:path";
3
- import { CONFIG_FILE, CONFIG_KEYS, configFileProblem, projectConfigFile, splitModelSpec } from "../config.js";
3
+ import { CONFIG_FILE, CONFIG_KEYS, configFileProblem, modelSpec, projectConfigFile, projectModels, readConfigFile, splitModelSpec } from "../config.js";
4
4
  import { quickStartForCapture } from "../init-config.js";
5
5
  import { currentValue, shownValue, withSetting } from "../config-edit.js";
6
6
  import { isProjectDir } from "../regenerate/paths.js";
7
+ import { CAPTURE_ROLES } from "./models.js";
7
8
  /**
8
9
  * The captured project's config. It starts as the config in use where the capture was started - the person's models,
9
10
  * thinking, reviews, limits and every other setting they chose - so the capture's own agents, its testing scripts and
@@ -32,18 +33,30 @@ export function configInUseProblem(file) {
32
33
  return problem === undefined ? undefined : `${problem} (${file}). A capture starts from the config in use - its models among it - and this one does not parse: fix it - each key set once - then capture again.`;
33
34
  }
34
35
  /**
35
- * The text the captured project's config starts as: the config in use - config.turri.yaml, never another tool's
36
- * config.yaml - without what was the original project's own, conformance tests on, and the models given for the capture
37
- * where the config in use says otherwise.
36
+ * Start from the config in use. On resume, keep the capture's own settings (including any scripts already written)
37
+ * but take the project and capture models from the current source config, which may have been initialised since.
38
38
  */
39
- export async function startingConfig(source, given) {
40
- const carried = source !== undefined && basename(source) === CONFIG_FILE && existsSync(source) ? readFileSync(source, "utf8") : "";
41
- let text = carried || await quickStartForCapture(splitModelSpec(given.harnessModel).model, splitModelSpec(given.codingModel).model);
42
- for (const key of ORIGINAL_ONLY)
43
- text = withSetting(text, key, undefined);
44
- text = withSetting(text, CONFIG_KEYS.conformanceTests, true);
45
- // A model given - the chat's own, or one named on the command line - is written where the config in use says another:
46
- // under models: when it names the role there, which wins over the key.
39
+ export async function captureConfig(source, given, saved) {
40
+ const project = source !== undefined && basename(source) === CONFIG_FILE ? source : undefined;
41
+ let text;
42
+ if (saved === undefined) {
43
+ const carried = project !== undefined ? readFileSync(project, "utf8") : "";
44
+ text = carried || await quickStartForCapture(splitModelSpec(given.harnessModel).model, splitModelSpec(given.codingModel).model);
45
+ for (const key of ORIGINAL_ONLY)
46
+ text = withSetting(text, key, undefined);
47
+ text = withSetting(text, CONFIG_KEYS.conformanceTests, true);
48
+ const header = [
49
+ "# Written by turri capture.",
50
+ ...(carried !== "" ? [`# It started as the config in use where the capture was started - ${source} - without what was that project's own:`, "# its module, testing scripts, base folder and test folder."] : []),
51
+ "# Every key is in turri's docs/config.md.",
52
+ ];
53
+ text = `${header.join("\n")}\n${text.replace(/^\s*\n/, "")}`;
54
+ }
55
+ else
56
+ text = saved;
57
+ const refreshed = saved !== undefined && project !== undefined ? readConfigFile(project) : undefined;
58
+ const pair = projectModels(refreshed ?? {});
59
+ // Write where the setting takes effect: under models: if that role overrides the top-level key.
47
60
  const set = (role, key, value) => {
48
61
  if (value === undefined)
49
62
  return;
@@ -55,12 +68,13 @@ export async function startingConfig(source, given) {
55
68
  return;
56
69
  text = withSetting(text, target, value);
57
70
  };
58
- set("chat", CONFIG_KEYS.harnessModel, given.harnessModel);
59
- set("coding", CONFIG_KEYS.codingModel, given.codingModel);
60
- const header = [
61
- "# Written by turri capture.",
62
- ...(carried !== "" ? [`# It started as the config in use where the capture was started - ${source} - without what was that project's own:`, "# its module, testing scripts, base folder and test folder."] : []),
63
- "# Every key is in turri's docs/config.md.",
64
- ];
65
- return `${header.join("\n")}\n${text.replace(/^\s*\n/, "")}`;
71
+ set("chat", CONFIG_KEYS.harnessModel, given.harnessModel ?? modelSpec(pair.harness));
72
+ set("coding", CONFIG_KEYS.codingModel, given.codingModel ?? modelSpec(pair.coding));
73
+ for (const role of CAPTURE_ROLES) {
74
+ const value = modelSpec(refreshed?.models?.[role]);
75
+ const key = `models.${role}`;
76
+ if (value !== undefined && currentValue(text, key) !== value)
77
+ text = withSetting(text, key, value);
78
+ }
79
+ return text;
66
80
  }
@@ -1,4 +1,5 @@
1
1
  import { type ModelChoice } from "../config.ts";
2
- export type CaptureRole = "capture-exploration" | "capture-analysis" | "capture";
2
+ export declare const CAPTURE_ROLES: readonly ["capture-exploration", "capture-analysis", "capture"];
3
+ export type CaptureRole = (typeof CAPTURE_ROLES)[number];
3
4
  /** One set of defaults for init-config and capture, including headless captures with no project config. */
4
5
  export declare function captureDefaults(harness?: string, coding?: string): Record<CaptureRole, ModelChoice>;
@@ -1,4 +1,5 @@
1
1
  import { modelOnly } from "../config.js";
2
+ export const CAPTURE_ROLES = ["capture-exploration", "capture-analysis", "capture"];
2
3
  /** One set of defaults for init-config and capture, including headless captures with no project config. */
3
4
  export function captureDefaults(harness, coding) {
4
5
  const bedrock = process.env.AWS_BEARER_TOKEN_BEDROCK || process.env.AWS_PROFILE || process.env.CLAUDE_CODE_USE_BEDROCK === "1";
@@ -1,5 +1,5 @@
1
1
  import type { ConfigLine } from "./config.ts";
2
- import type { sandboxSummary } from "./regenerate/os-sandbox.ts";
2
+ import type { SandboxSummary } from "./regenerate/os-sandbox.ts";
3
3
  import type { CustomMessageEntry, ExtensionAPI, SessionEntry } from "@earendil-works/pi-coding-agent";
4
4
  import type { Notice, Conclusion } from "./notice.ts";
5
5
  import type { Job } from "./regenerate/jobs.ts";
@@ -24,7 +24,7 @@ export declare const SIDE_ENTRY = "turri_btw";
24
24
  /** A message the person sent while a skill ran in the chat, read by the skill's agent: drawn as the message it is. */
25
25
  export declare const SKILL_MESSAGE_ENTRY = "turri_skill_message";
26
26
  export declare const MILESTONE_ENTRY = "turri_milestone";
27
- /** A newer turri out, found once turri had started (turri-versions.ts). */
27
+ /** A newer turri out: appended by an earlier turri, and still in the chats it saved. */
28
28
  export declare const VERSION_ENTRY = "turri_version";
29
29
  export declare const JOB_ENTRY = "turri_job";
30
30
  export declare const JOBS_LIST_ENTRY = "turri_jobs";
@@ -52,14 +52,16 @@ export interface Exchange {
52
52
  }
53
53
  /** What the banner says, appended once a chat. */
54
54
  export interface BannerData {
55
+ /** Who runs turri: the session's front end as it named itself, else the core. Absent in an earlier turri's banner. */
56
+ name?: string;
55
57
  version: string;
56
- /** The commit, when turri runs from a clone - and whether the clone has changes on it. */
58
+ /** The commit, when it runs from a clone - and whether the clone has changes on it. */
57
59
  commit?: string;
58
60
  changed?: boolean;
59
61
  /** How many skills failed to load. */
60
62
  pending: number;
61
- sandbox?: ReturnType<typeof sandboxSummary>;
62
- /** A newer turri out, or installed and hidden behind this one on the PATH: a line each (turri-versions.ts). */
63
+ sandbox?: SandboxSummary;
64
+ /** An earlier turri's: a newer turri out, or one hidden behind it on the PATH, a line each. */
63
65
  versions?: string[];
64
66
  /** What turri says of the config files: a key it renamed in one, an old name left, keys it does not read. */
65
67
  config?: ConfigLine[];
@@ -69,7 +71,22 @@ export declare const NOTICE_OVER_ENTRY = "turri_notice_over";
69
71
  export declare const CONCLUDED_ENTRY = "turri_sentinel_concluded";
70
72
  export declare const SKILL_RUN_ENTRY = "turri_skill_run";
71
73
  export declare const SKILL_REPORT_ENTRY = "turri_skill_report";
72
- interface Entries {
74
+ /** Messages turri sends a chat's agent, unseen by the person: a spec conflict a conformance run found, to decide. */
75
+ export declare const SPEC_CONFLICT_MESSAGE = "turri_spec_conflict";
76
+ /** The sentinel briefed on a pulse, in a conversation of its own. */
77
+ export declare const SENTINEL_PULSE_MESSAGE = "turri_sentinel_pulse";
78
+ /** The sentinel asked to check functional specs in what is launched. */
79
+ export declare const SENTINEL_CHECK_MESSAGE = "turri_sentinel_check";
80
+ /** The sentinel's check, paused while its codebase was launched again, carried on. */
81
+ export declare const SENTINEL_RESUME_MESSAGE = "turri_sentinel_resume";
82
+ /** A pulse landed, told to the chat the person is in while the sentinel has it. */
83
+ export declare const JOB_LANDED_MESSAGE = "turri_job_landed";
84
+ /** A notice the person answered with something to do: the task. */
85
+ export declare const NOTICE_ANSWER_MESSAGE = "turri_notice_answer";
86
+ /** A launch this chat is to hear of ended. */
87
+ export declare const LAUNCH_MESSAGE = "turri_launch";
88
+ /** Each custom entry turri appends to a chat, by its `customType`: the data it carries. */
89
+ export interface ChatEntryMap {
73
90
  [BANNER_ENTRY]: BannerData;
74
91
  [VERSION_ENTRY]: {
75
92
  text: string;
@@ -103,13 +120,15 @@ interface Entries {
103
120
  text: string;
104
121
  };
105
122
  }
106
- type JobDetails = {
123
+ /** A pulse a message is about. */
124
+ export type JobRef = {
107
125
  jobId: string;
108
126
  status: Job["status"];
109
127
  };
110
- interface Messages {
128
+ /** Each custom message turri sends a chat, by its `customType`: its `details` - undefined for one that carries none. */
129
+ export interface ChatMessageMap {
111
130
  [COMMAND_OUTCOME]: undefined;
112
- [JOB_ENTRY]: JobDetails;
131
+ [JOB_ENTRY]: JobRef;
113
132
  [CONCLUDED_ENTRY]: {
114
133
  jobId?: string;
115
134
  checkId?: string;
@@ -126,47 +145,70 @@ interface Messages {
126
145
  [SKILL_REPORT_ENTRY]: {
127
146
  skills: string[];
128
147
  };
129
- turri_spec_conflict: {
148
+ [SPEC_CONFLICT_MESSAGE]: {
130
149
  jobId: string;
131
150
  };
132
- turri_sentinel_pulse: JobDetails;
133
- turri_sentinel_check: {
151
+ [SENTINEL_PULSE_MESSAGE]: JobRef;
152
+ [SENTINEL_CHECK_MESSAGE]: {
134
153
  checkId: string;
135
154
  module: string;
136
155
  funcIds: string[];
137
156
  };
138
- turri_sentinel_resume: undefined;
139
- turri_job_landed: JobDetails;
140
- turri_notice_answer: undefined;
141
- turri_launch: {
157
+ [SENTINEL_RESUME_MESSAGE]: undefined;
158
+ [JOB_LANDED_MESSAGE]: JobRef;
159
+ [NOTICE_ANSWER_MESSAGE]: undefined;
160
+ [LAUNCH_MESSAGE]: {
142
161
  launch: string;
143
162
  status: LaunchStatus;
144
163
  replacedBy?: string;
145
164
  };
146
165
  }
147
- type Entry = {
148
- [K in keyof Entries]: {
149
- type: "custom";
150
- customType: K;
151
- data: Entries[K];
152
- };
153
- }[keyof Entries];
154
- type Message = {
155
- [K in keyof Messages]: Pick<CustomMessageEntry, "type" | "content" | "display"> & {
156
- customType: K;
157
- } & (Messages[K] extends undefined ? {
158
- details?: undefined;
159
- } : {
160
- details: Messages[K];
161
- });
162
- }[keyof Messages];
163
- /** A turri entry from pi's live transcript or saved branch. Narrow by type, then customType. */
164
- export type ChatEntry = Entry | Message;
165
- type PiRecord = SessionEntry | Pick<CustomMessageEntry, "type" | "customType" | "content" | "details" | "display">;
166
- /** Recognise records written by turri in pi's transcript, by their reserved tags and payload envelopes. */
167
- export declare function isChatEntry<T extends PiRecord>(entry: T): entry is T & ChatEntry;
168
- export declare function appendChatEntry<K extends keyof Entries>(pi: ExtensionAPI, kind: K, data: Entries[NoInfer<K>]): void;
166
+ /** A custom entry turri appended, by its type. */
167
+ export type ChatEntryOf<K extends keyof ChatEntryMap> = {
168
+ type: "custom";
169
+ customType: K;
170
+ data: ChatEntryMap[K];
171
+ };
172
+ /** A custom message turri sent, by its type. */
173
+ export type ChatMessageOf<K extends keyof ChatMessageMap> = Pick<CustomMessageEntry, "type" | "content" | "display"> & {
174
+ customType: K;
175
+ } & (ChatMessageMap[K] extends undefined ? {
176
+ details?: undefined;
177
+ } : {
178
+ details: ChatMessageMap[K];
179
+ });
180
+ /** A turri entry or message from pi's live transcript or a saved branch. Narrow by `type`, then `customType`. */
181
+ export type ChatEntry = {
182
+ [K in keyof ChatEntryMap]: ChatEntryOf<K>;
183
+ }[keyof ChatEntryMap] | {
184
+ [K in keyof ChatMessageMap]: ChatMessageOf<K>;
185
+ }[keyof ChatMessageMap];
186
+ /** Every customType turri uses, entries and messages. */
187
+ export type ChatEntryType = ChatEntry["customType"];
188
+ /** A record of pi's transcript: an entry of its session, or a custom message as pi delivers it. */
189
+ export type TranscriptRecord = SessionEntry | Pick<CustomMessageEntry, "type" | "customType" | "content" | "details" | "display">;
190
+ /**
191
+ * Whether a record of pi's transcript is one turri wrote: its type is turri's, and what it carries is what that type
192
+ * carries - every field its type has, of its type. Narrows to ChatEntry; safe as an array filter. A record another
193
+ * extension wrote under a name of turri's, or one written wrong, is not. Data saved by an earlier turri may lack a field
194
+ * added since: the fields a later turri added are optional in their types.
195
+ */
196
+ export declare function isChatEntry<T extends TranscriptRecord>(entry: T): entry is T & ChatEntry;
197
+ /** Whether a record of pi's transcript - or a ChatEntry already - is turri's of this `customType`. Narrows to it. */
198
+ export declare function isChatEntryOf<T extends TranscriptRecord | ChatEntry, K extends ChatEntryType>(entry: T, customType: K): entry is T & Extract<ChatEntry, {
199
+ customType: K;
200
+ }>;
201
+ export declare function appendChatEntry<K extends keyof ChatEntryMap>(pi: ExtensionAPI, kind: K, data: ChatEntryMap[NoInfer<K>]): void;
169
202
  type WithoutType<T> = T extends unknown ? Omit<T, "type"> : never;
170
- type Outgoing = WithoutType<Message>;
203
+ type Outgoing = WithoutType<{
204
+ [K in keyof ChatMessageMap]: ChatMessageOf<K>;
205
+ }[keyof ChatMessageMap]>;
171
206
  export declare function sendChatMessage(pi: ExtensionAPI, message: Outgoing, options?: Parameters<ExtensionAPI["sendMessage"]>[1]): void;
207
+ /**
208
+ * What the model reads of a chat: each message of turri's own inside a `<turri-note>`. pi hands a custom message to the
209
+ * model as one of the person's, and one sent with no turn of its own goes with the person's next message, in the same
210
+ * turn - framed, the model tells turri's note from what the person said. The transcript keeps each as it was sent, and
211
+ * a session saved before is framed the same. Another extension's messages, and everything else, are left as they are.
212
+ */
213
+ export declare function framedForModel<M>(messages: readonly M[]): M[];
172
214
  export {};
@@ -1,3 +1,5 @@
1
+ import { Type } from "typebox";
2
+ import { Value } from "typebox/value";
1
3
  /**
2
4
  * What turri keeps in a chat besides its messages: the custom entries it appends, and the custom messages it sends that
3
5
  * a front-end draws - their types and the data each carries. The core appends them; the terminal draws them, and a host
@@ -10,7 +12,7 @@ export const SIDE_ENTRY = "turri_btw";
10
12
  /** A message the person sent while a skill ran in the chat, read by the skill's agent: drawn as the message it is. */
11
13
  export const SKILL_MESSAGE_ENTRY = "turri_skill_message";
12
14
  export const MILESTONE_ENTRY = "turri_milestone";
13
- /** A newer turri out, found once turri had started (turri-versions.ts). */
15
+ /** A newer turri out: appended by an earlier turri, and still in the chats it saved. */
14
16
  export const VERSION_ENTRY = "turri_version";
15
17
  export const JOB_ENTRY = "turri_job";
16
18
  export const JOBS_LIST_ENTRY = "turri_jobs";
@@ -23,20 +25,113 @@ export const NOTICE_OVER_ENTRY = "turri_notice_over";
23
25
  export const CONCLUDED_ENTRY = "turri_sentinel_concluded";
24
26
  export const SKILL_RUN_ENTRY = "turri_skill_run";
25
27
  export const SKILL_REPORT_ENTRY = "turri_skill_report";
26
- const entries = { turri_banner: 1, turri_version: 1, turri_command_outcome: 1, turri_btw: 1, turri_skill_message: 1, turri_exchange: 1, turri_job: 1, turri_history: 1, turri_milestone: 1, turri_jobs: 1, turri_notice: 1, turri_notice_over: 1, turri_sentinel_concluded: 1, turri_skill_run: 1 };
27
- const needsDetails = {
28
- turri_command_outcome: false, turri_job: true, turri_sentinel_concluded: true,
29
- turri_skill_run: true, turri_skill_report: true, turri_spec_conflict: true,
30
- turri_sentinel_pulse: true, turri_sentinel_check: true, turri_sentinel_resume: false,
31
- turri_job_landed: true, turri_notice_answer: false, turri_launch: true,
28
+ /** Messages turri sends a chat's agent, unseen by the person: a spec conflict a conformance run found, to decide. */
29
+ export const SPEC_CONFLICT_MESSAGE = "turri_spec_conflict";
30
+ /** The sentinel briefed on a pulse, in a conversation of its own. */
31
+ export const SENTINEL_PULSE_MESSAGE = "turri_sentinel_pulse";
32
+ /** The sentinel asked to check functional specs in what is launched. */
33
+ export const SENTINEL_CHECK_MESSAGE = "turri_sentinel_check";
34
+ /** The sentinel's check, paused while its codebase was launched again, carried on. */
35
+ export const SENTINEL_RESUME_MESSAGE = "turri_sentinel_resume";
36
+ /** A pulse landed, told to the chat the person is in while the sentinel has it. */
37
+ export const JOB_LANDED_MESSAGE = "turri_job_landed";
38
+ /** A notice the person answered with something to do: the task. */
39
+ export const NOTICE_ANSWER_MESSAGE = "turri_notice_answer";
40
+ /** A launch this chat is to hear of ended. */
41
+ export const LAUNCH_MESSAGE = "turri_launch";
42
+ // What each entry's data and each message's details must be, checked as a record is read: one saved by another
43
+ // extension, or written wrong, is not turri's. Each schema is its type's, exactly (`Same` below): changing one alone
44
+ // does not compile.
45
+ const Str = Type.String();
46
+ const Opt = (schema) => Type.Optional(schema);
47
+ const Text = Type.Object({ text: Str });
48
+ const ModuleText = Type.Object({ module: Str, text: Str });
49
+ const NoticeStates = Type.Enum(["open", "accepted", "steered", "dismissed", "ignored", "superseded"]);
50
+ const Verdict = Type.Enum(["holds", "wrong", "unchecked"]);
51
+ const JobRefSchema = Type.Object({ jobId: Str, status: Type.Enum(["queued", "running", "succeeded", "failed", "stopped"]) });
52
+ const ENTRY_SCHEMAS = {
53
+ [BANNER_ENTRY]: Type.Object({
54
+ name: Opt(Str),
55
+ version: Str,
56
+ commit: Opt(Str),
57
+ changed: Opt(Type.Boolean()),
58
+ pending: Type.Number(),
59
+ sandbox: Opt(Type.Object({ level: Type.Enum(["ok", "limited"]), text: Str })),
60
+ versions: Opt(Type.Array(Str)),
61
+ config: Opt(Type.Array(Type.Object({ kind: Type.Enum(["broken", "renamed", "old-beside-new", "unknown"]), file: Str, text: Str }))),
62
+ }),
63
+ [VERSION_ENTRY]: Text,
64
+ [COMMAND_OUTCOME]: Type.Object({ command: Str, text: Opt(Str), level: Opt(Type.Enum(["info", "warning", "error"])), echoed: Opt(Type.Boolean()) }),
65
+ [SIDE_ENTRY]: Type.Object({ question: Str, answer: Str }),
66
+ [SKILL_MESSAGE_ENTRY]: Type.Object({ text: Str, skill: Str }),
67
+ [INTERVIEW_ENTRY]: Type.Object({ skill: Str, said: Opt(Str), question: Str, answer: Str }),
68
+ [JOB_ENTRY]: Type.Object({ id: Str, summary: Str, status: Type.Enum(["succeeded", "failed", "stopped"]), incomplete: Opt(Type.Boolean()), duration: Str, spent: Opt(Str), text: Str }),
69
+ [HISTORY_ENTRY]: ModuleText,
70
+ [MILESTONE_ENTRY]: ModuleText,
71
+ [JOBS_LIST_ENTRY]: Text,
72
+ [NOTICE_ENTRY]: Type.Object({
73
+ kind: Opt(Type.Enum(["sentinel-start", "fixed"])),
74
+ severity: Type.Enum(["error", "warning", "info"]),
75
+ summary: Str,
76
+ evidence: Type.Array(Str),
77
+ actions: Type.Array(Type.Object({ label: Str, task: Str })),
78
+ module: Opt(Str),
79
+ job: Opt(Str),
80
+ pulse: Opt(Type.Number()),
81
+ check: Opt(Str),
82
+ ignorable: Opt(Type.Boolean()),
83
+ id: Str,
84
+ chat: Str,
85
+ state: NoticeStates,
86
+ at: Str,
87
+ }),
88
+ [NOTICE_OVER_ENTRY]: Type.Object({ state: NoticeStates, summary: Str }),
89
+ [CONCLUDED_ENTRY]: Type.Object({ job: Opt(Str), check: Opt(Str), verdict: Verdict, summary: Str, module: Opt(Str), pulse: Opt(Type.Number()), tryIt: Opt(Str) }),
90
+ [SKILL_RUN_ENTRY]: Text,
32
91
  };
33
- /** Recognise records written by turri in pi's transcript, by their reserved tags and payload envelopes. */
92
+ /** A message's details: a schema, or none for one that carries none. */
93
+ const MESSAGE_SCHEMAS = {
94
+ [COMMAND_OUTCOME]: undefined,
95
+ [JOB_ENTRY]: JobRefSchema,
96
+ [CONCLUDED_ENTRY]: Type.Object({ jobId: Opt(Str), checkId: Opt(Str), verdict: Verdict }),
97
+ [SKILL_RUN_ENTRY]: Type.Object({ skills: Type.Array(Str), runs: Type.Array(Type.Object({ skill: Str, kind: Opt(Type.Enum(["unit", "conformance"])), plainFile: Opt(Str) })) }),
98
+ [SKILL_REPORT_ENTRY]: Type.Object({ skills: Type.Array(Str) }),
99
+ [SPEC_CONFLICT_MESSAGE]: Type.Object({ jobId: Str }),
100
+ [SENTINEL_PULSE_MESSAGE]: JobRefSchema,
101
+ [SENTINEL_CHECK_MESSAGE]: Type.Object({ checkId: Str, module: Str, funcIds: Type.Array(Str) }),
102
+ [SENTINEL_RESUME_MESSAGE]: undefined,
103
+ [JOB_LANDED_MESSAGE]: JobRefSchema,
104
+ [NOTICE_ANSWER_MESSAGE]: undefined,
105
+ [LAUNCH_MESSAGE]: Type.Object({ launch: Str, status: Type.Enum(["waiting", "running", "launched", "failed", "stopped", "superseded"]), replacedBy: Opt(Str) }),
106
+ };
107
+ // Each schema is its type's: a field added, removed or retyped in one alone fails here.
108
+ const entriesMatch = {
109
+ turri_banner: true, turri_version: true, turri_command_outcome: true, turri_btw: true, turri_skill_message: true, turri_exchange: true, turri_job: true,
110
+ turri_history: true, turri_milestone: true, turri_jobs: true, turri_notice: true, turri_notice_over: true, turri_sentinel_concluded: true, turri_skill_run: true,
111
+ };
112
+ const messagesMatch = {
113
+ turri_command_outcome: true, turri_job: true, turri_sentinel_concluded: true, turri_skill_run: true, turri_skill_report: true, turri_spec_conflict: true,
114
+ turri_sentinel_pulse: true, turri_sentinel_check: true, turri_sentinel_resume: true, turri_job_landed: true, turri_notice_answer: true, turri_launch: true,
115
+ };
116
+ void entriesMatch;
117
+ void messagesMatch;
118
+ /**
119
+ * Whether a record of pi's transcript is one turri wrote: its type is turri's, and what it carries is what that type
120
+ * carries - every field its type has, of its type. Narrows to ChatEntry; safe as an array filter. A record another
121
+ * extension wrote under a name of turri's, or one written wrong, is not. Data saved by an earlier turri may lack a field
122
+ * added since: the fields a later turri added are optional in their types.
123
+ */
34
124
  export function isChatEntry(entry) {
35
125
  if (entry.type === "custom")
36
- return Object.hasOwn(entries, entry.customType) && typeof entry.data === "object" && entry.data !== null;
37
- if (entry.type !== "custom_message" || !Object.hasOwn(needsDetails, entry.customType))
126
+ return Object.hasOwn(ENTRY_SCHEMAS, entry.customType) && Value.Check(ENTRY_SCHEMAS[entry.customType], entry.data);
127
+ if (entry.type !== "custom_message" || !Object.hasOwn(MESSAGE_SCHEMAS, entry.customType))
38
128
  return false;
39
- return needsDetails[entry.customType] ? typeof entry.details === "object" && entry.details !== null : entry.details === undefined;
129
+ const schema = MESSAGE_SCHEMAS[entry.customType];
130
+ return schema === undefined ? entry.details === undefined : Value.Check(schema, entry.details);
131
+ }
132
+ /** Whether a record of pi's transcript - or a ChatEntry already - is turri's of this `customType`. Narrows to it. */
133
+ export function isChatEntryOf(entry, customType) {
134
+ return entry.customType === customType && isChatEntry(entry);
40
135
  }
41
136
  // Both writers check the same discriminated payloads that readers narrow above.
42
137
  export function appendChatEntry(pi, kind, data) {
@@ -45,3 +140,22 @@ export function appendChatEntry(pi, kind, data) {
45
140
  export function sendChatMessage(pi, message, options) {
46
141
  pi.sendMessage(message, options);
47
142
  }
143
+ /**
144
+ * What the model reads of a chat: each message of turri's own inside a `<turri-note>`. pi hands a custom message to the
145
+ * model as one of the person's, and one sent with no turn of its own goes with the person's next message, in the same
146
+ * turn - framed, the model tells turri's note from what the person said. The transcript keeps each as it was sent, and
147
+ * a session saved before is framed the same. Another extension's messages, and everything else, are left as they are.
148
+ */
149
+ export function framedForModel(messages) {
150
+ return messages.map((message) => {
151
+ const sent = message;
152
+ if (sent.role !== "custom" || typeof sent.customType !== "string" || !Object.hasOwn(MESSAGE_SCHEMAS, sent.customType))
153
+ return message;
154
+ const content = typeof sent.content === "string"
155
+ ? `<turri-note>\n${sent.content}\n</turri-note>`
156
+ : Array.isArray(sent.content)
157
+ ? [{ type: "text", text: "<turri-note>" }, ...sent.content, { type: "text", text: "</turri-note>" }]
158
+ : sent.content;
159
+ return { ...message, content };
160
+ });
161
+ }
@@ -0,0 +1,37 @@
1
+ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
2
+ /**
3
+ * A person's chat runs on harness-model, as turri starts pi with it: put on it as the chat starts, and again whenever
4
+ * harness-model changes - read from the project's config each time, so a chat opened after a change starts on the new
5
+ * one. A model the person chooses in a chat holds until harness-model changes again.
6
+ *
7
+ * While harness-model cannot be reached here - no such model, or its provider not signed in - the chat sends nothing to a
8
+ * model: pi's own choice instead would be the first provider with credentials, an AWS account the person's shell has,
9
+ * say, billed there unseen. It is said, and the front end hears it, until a sign-in or a change to harness-model puts the
10
+ * chat on a model it can reach. The sentinel's chat is not one of these: its model is models.sentinel.
11
+ */
12
+ /** harness-model as a chat cannot be on it: the model, its provider, and why - no such model here, or not signed in. */
13
+ export interface ModelOutOfReach {
14
+ /** The model, provider/model-id. */
15
+ model: string;
16
+ provider: string;
17
+ why: "unknown" | "signed-out";
18
+ }
19
+ /** A model of pi's registry. */
20
+ type Model = NonNullable<ReturnType<ExtensionContext["modelRegistry"]["find"]>>;
21
+ export interface HarnessFollower {
22
+ /** Put the chat on harness-model if it is not on it as the config has it now, or say why it cannot be. */
23
+ check(ctx: ExtensionContext): Promise<void>;
24
+ /** harness-model as it cannot be reached now - none while the chat is on it, or harness-model is unset. */
25
+ outOfReach(): ModelOutOfReach | undefined;
26
+ }
27
+ export declare function followHarnessModel(options: {
28
+ /** harness-model as the config has it now: provider/model-id[:thinking], or none. */
29
+ wanted: () => string | undefined;
30
+ setModel: (model: Model) => Promise<boolean>;
31
+ setThinking: (level: string) => void;
32
+ /** What cannot be reached now changed: none once it can be. */
33
+ changed: (outOfReach: ModelOutOfReach | undefined) => void;
34
+ }): HarnessFollower;
35
+ /** What the person is told when a message is not sent: harness-model out of reach, and what to do about it. */
36
+ export declare function outOfReachText(outOfReach: ModelOutOfReach): string;
37
+ export {};
@@ -0,0 +1,61 @@
1
+ import { splitModelSpec } from "./config.js";
2
+ export function followHarnessModel(options) {
3
+ /** The harness-model the chat was last put on: until it changes, a model the person chose holds. */
4
+ let settled;
5
+ let outOfReach;
6
+ const reach = (now) => {
7
+ if (JSON.stringify(now) === JSON.stringify(outOfReach))
8
+ return;
9
+ outOfReach = now;
10
+ options.changed(now);
11
+ };
12
+ return {
13
+ async check(ctx) {
14
+ const wanted = options.wanted() ?? "";
15
+ const { model, thinking } = splitModelSpec(wanted);
16
+ // Unset, or a thinking level alone: pi's own choice of model, as turri has it.
17
+ if (model === undefined) {
18
+ if (thinking !== undefined && settled !== wanted)
19
+ options.setThinking(thinking);
20
+ settled = wanted;
21
+ return reach(undefined);
22
+ }
23
+ if (settled === wanted && outOfReach === undefined)
24
+ return;
25
+ const slash = model.indexOf("/");
26
+ const provider = slash > 0 ? model.slice(0, slash) : model;
27
+ let found;
28
+ let signedIn = false;
29
+ try {
30
+ found = slash > 0 ? ctx.modelRegistry.find(provider, model.slice(slash + 1)) : undefined;
31
+ signedIn = found !== undefined && ctx.modelRegistry.hasConfiguredAuth(found);
32
+ }
33
+ catch {
34
+ /* a registry let go: as if there were no such model */
35
+ }
36
+ if (found === undefined || !signedIn) {
37
+ settled = undefined;
38
+ return reach({ model, provider, why: found === undefined ? "unknown" : "signed-out" });
39
+ }
40
+ const on = ctx.model;
41
+ if (on === undefined || on.provider !== found.provider || on.id !== found.id) {
42
+ if (!(await options.setModel(found))) {
43
+ settled = undefined;
44
+ return reach({ model, provider, why: "signed-out" });
45
+ }
46
+ }
47
+ if (thinking !== undefined)
48
+ options.setThinking(thinking);
49
+ settled = wanted;
50
+ reach(undefined);
51
+ },
52
+ outOfReach: () => outOfReach,
53
+ };
54
+ }
55
+ /** What the person is told when a message is not sent: harness-model out of reach, and what to do about it. */
56
+ export function outOfReachText(outOfReach) {
57
+ const why = outOfReach.why === "unknown"
58
+ ? `there is no model ${outOfReach.model} here - check harness-model in config.turri.yaml, or the provider's extension`
59
+ : `${outOfReach.provider} is not signed in - sign in to it, or choose another harness-model with /settings`;
60
+ return `Nothing was sent: ${outOfReach.model}, the model this project talks to, cannot be reached - ${why}.`;
61
+ }