omp-superagent 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/DESIGN.md +27 -16
  2. package/README.ko.md +40 -19
  3. package/README.md +43 -18
  4. package/THIRD_PARTY_NOTICES.md +11 -11
  5. package/config.example.json +2 -1
  6. package/docs/OPERATIONS.md +285 -85
  7. package/docs/design/execution.md +133 -24
  8. package/docs/design/messaging.md +235 -50
  9. package/docs/discord-voice.md +8 -4
  10. package/docs/releases/0.1.8.md +21 -0
  11. package/docs/releases/0.1.9.md +18 -0
  12. package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
  13. package/gateway/bin/omp-gateway-darwin-x64 +0 -0
  14. package/gateway/bin/omp-gateway-linux-arm64 +0 -0
  15. package/gateway/bin/omp-gateway-linux-x64 +0 -0
  16. package/host-owner/bin/notices/darwin-arm64/Cargo-LICENSES.txt +2 -0
  17. package/host-owner/bin/notices/darwin-arm64/Cargo-SOURCES.txt +2 -0
  18. package/host-owner/bin/notices/darwin-arm64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
  19. package/host-owner/bin/notices/darwin-arm64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
  20. package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/COPYRIGHT +29 -0
  21. package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
  22. package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  23. package/host-owner/bin/notices/darwin-arm64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
  24. package/host-owner/bin/notices/darwin-x64/Cargo-LICENSES.txt +2 -0
  25. package/host-owner/bin/notices/darwin-x64/Cargo-SOURCES.txt +2 -0
  26. package/host-owner/bin/notices/darwin-x64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
  27. package/host-owner/bin/notices/darwin-x64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
  28. package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/COPYRIGHT +29 -0
  29. package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
  30. package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  31. package/host-owner/bin/notices/darwin-x64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
  32. package/host-owner/bin/notices/linux-arm64/Cargo-LICENSES.txt +3 -0
  33. package/host-owner/bin/notices/linux-arm64/Cargo-SOURCES.txt +3 -0
  34. package/host-owner/bin/notices/linux-arm64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
  35. package/host-owner/bin/notices/linux-arm64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
  36. package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/COPYRIGHT +29 -0
  37. package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/LICENSE-APACHE +201 -0
  38. package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  39. package/host-owner/bin/notices/linux-arm64/crates/linux-raw-sys-0.12.1/LICENSE-MIT +23 -0
  40. package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/COPYRIGHT +29 -0
  41. package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
  42. package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  43. package/host-owner/bin/notices/linux-arm64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
  44. package/host-owner/bin/notices/linux-x64/Cargo-LICENSES.txt +3 -0
  45. package/host-owner/bin/notices/linux-x64/Cargo-SOURCES.txt +3 -0
  46. package/host-owner/bin/notices/linux-x64/crates/bitflags-2.13.2/LICENSE-APACHE +201 -0
  47. package/host-owner/bin/notices/linux-x64/crates/bitflags-2.13.2/LICENSE-MIT +25 -0
  48. package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/COPYRIGHT +29 -0
  49. package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/LICENSE-APACHE +201 -0
  50. package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  51. package/host-owner/bin/notices/linux-x64/crates/linux-raw-sys-0.12.1/LICENSE-MIT +23 -0
  52. package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/COPYRIGHT +29 -0
  53. package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/LICENSE-APACHE +201 -0
  54. package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  55. package/host-owner/bin/notices/linux-x64/crates/rustix-1.1.6/LICENSE-MIT +23 -0
  56. package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
  57. package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
  58. package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
  59. package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
  60. package/package.json +17 -15
  61. package/skills/head/SKILL.md +3 -11
  62. package/skills/head/references/routing.md +23 -17
  63. package/skills/head/references/supervision.md +13 -1
  64. package/skills/lane/references/workflow.md +8 -8
  65. package/src/cli.ts +6 -3
  66. package/src/config.ts +5 -0
  67. package/src/contracts.ts +95 -10
  68. package/src/cron-jobs.ts +443 -19
  69. package/src/cron-pr-intake.ts +257 -0
  70. package/src/discord-command-registration.ts +34 -186
  71. package/src/extension.ts +31 -3
  72. package/src/gateway-client.ts +11 -59
  73. package/src/gateway-protocol.ts +35 -1
  74. package/src/head-quota.ts +80 -0
  75. package/src/head-recovery.ts +249 -1
  76. package/src/host-extension.ts +194 -5
  77. package/src/host-protocol.ts +16 -9
  78. package/src/host-sdk-helper.ts +105 -10
  79. package/src/host.ts +111 -29
  80. package/src/installed-omp.ts +116 -4
  81. package/src/lane-models.ts +8 -0
  82. package/src/managed-ulw-probe.ts +22 -20
  83. package/src/managed-ulw.ts +137 -24
  84. package/src/messenger-command-catalog.json +6 -3
  85. package/src/messenger-commands.ts +9 -2
  86. package/src/native-presets.ts +32 -5
  87. package/src/omp-usage.ts +254 -36
  88. package/src/operator.ts +77 -0
  89. package/src/pr-github-schema.ts +2 -0
  90. package/src/pr-github.ts +4 -2
  91. package/src/pr-intake-automation.ts +315 -0
  92. package/src/pr-intake-comment.ts +225 -0
  93. package/src/pr-intake-fix.ts +232 -0
  94. package/src/pr-intake-github.ts +479 -0
  95. package/src/pr-intake-material.ts +229 -0
  96. package/src/pr-intake-mode.ts +59 -0
  97. package/src/pr-intake-review.ts +397 -0
  98. package/src/pr-intake-tree.ts +68 -0
  99. package/src/pr-intake-work.ts +29 -0
  100. package/src/pr-review-models.ts +28 -0
  101. package/src/result-attachment.ts +60 -79
  102. package/src/runtime.ts +2968 -449
  103. package/src/setup-profiles.ts +26 -65
  104. package/src/slack-command-registration.ts +48 -197
  105. package/src/store.ts +507 -87
  106. package/src/superkit-skills.ts +22 -0
  107. package/src/telegram-command-languages.json +17 -0
  108. package/src/telegram-command-registration.ts +32 -134
  109. package/src/topic-history.ts +30 -17
  110. package/src/worker-bridge.ts +21 -0
  111. package/src/worker-enrollment.ts +2 -1
  112. package/src/worker-host.ts +0 -24
  113. package/src/worker-serve-prepare.ts +19 -0
  114. package/src/worker-service.ts +51 -47
  115. package/scripts/ci.ts +0 -44
  116. package/scripts/release.ts +0 -112
  117. package/scripts/test-omp.sh +0 -43
  118. package/src/discord-commands.ts +0 -29
  119. package/src/discord-markdown.ts +0 -172
  120. package/src/slack-commands.ts +0 -18
  121. package/src/telegram-signal.ts +0 -14
  122. package/src/worker-stdio.ts +0 -61
@@ -189,8 +189,7 @@ async function probe(packagePath: string, stage: string, manifest: UlwManifest):
189
189
  home, manifest.probeTimeoutMs, env);
190
190
  }
191
191
 
192
- /** Snapshot native discovery in the exact environment the installed CLI will use. */
193
- export async function managedUlwLaunchExtensions(options: {
192
+ export type ManagedUlwLaunchInput = {
194
193
  cwd: string;
195
194
  managedUlwPath: string;
196
195
  extensionPaths: string[];
@@ -200,26 +199,144 @@ export async function managedUlwLaunchExtensions(options: {
200
199
  commandArgs: string[];
201
200
  /** Exact native OMP argv, including the original command's flags and generated Host args; no executable prefix. */
202
201
  launchArgs: string[];
202
+ worker?: Pick<WorkerHostProfile, "extensionPaths">;
203
+ };
204
+ type ManagedUlwLaunchOptions = Omit<ManagedUlwLaunchInput, "managedUlwPath"> & {
205
+ managedUlwPath?: string;
203
206
  env: Record<string, string | undefined>;
204
207
  bunCommand: string[];
205
- worker?: Pick<WorkerHostProfile, "extensionPaths">;
206
- }): Promise<{ extensionPaths: string[]; noExtensions: boolean; memoryWriteDir: string | null }> {
208
+ discoveryTimeoutMs?: number;
209
+ };
210
+ export type ManagedUlwLaunchComposition = { extensionPaths: string[]; noExtensions: boolean; memoryWriteDir: string | null };
211
+
212
+ const LAUNCH_DISCOVERY_TIMEOUT_MS = 30_000;
213
+ const LAUNCH_OUTPUT_LIMIT = 16 * 1024 * 1024; // Same bound as the Rust Gateway.
214
+ const LAUNCH_MARKER = "MANAGED_ULW_LAUNCH ";
215
+ const LAUNCH_ERROR_MARKER = "MANAGED_ULW_LAUNCH_ERROR ";
216
+
217
+ async function launchPhase<T>(deadline: number, message: string, run: (assertActive: () => void) => Promise<T>): Promise<T> {
218
+ let timer: ReturnType<typeof setTimeout> | undefined;
219
+ let timedOut = false;
220
+ const assertActive = () => {
221
+ if (timedOut || performance.now() >= deadline) throw new Error(message);
222
+ };
223
+ try {
224
+ const timeout = new Promise<never>((_, reject) => {
225
+ timer = setTimeout(() => {
226
+ // Once reported, timeout is final even if a caller observes the clock
227
+ // before the absolute deadline (timer granularity or rounding).
228
+ timedOut = true;
229
+ reject(new Error(message));
230
+ }, Math.max(0, Math.ceil(deadline - performance.now())));
231
+ });
232
+ const result = await Promise.race([timeout, run(assertActive)]);
233
+ assertActive();
234
+ return result;
235
+ } finally { clearTimeout(timer); }
236
+ }
237
+
238
+ /** Snapshot native discovery in the exact environment the installed CLI will use. */
239
+ export async function managedUlwLaunchExtensions(options: ManagedUlwLaunchOptions & { managedUlwPath: string }): Promise<ManagedUlwLaunchComposition> {
240
+ return (await managedUlwLaunch(options)).composition;
241
+ }
242
+
243
+ /**
244
+ * Run native launch discovery in the Host SDK helper. With `prepare`, the same
245
+ * helper process then prepares the native session from the manifest the caller
246
+ * builds after seeing the composition, so one launch costs one helper spawn.
247
+ * The helper prepares nothing until that manifest arrives on its stdin.
248
+ */
249
+ export async function managedUlwLaunch(options: ManagedUlwLaunchOptions, prepare?: {
250
+ /** Native stderr destination; preparation output may contain session data. */
251
+ stderr: number;
252
+ timeoutMs: number;
253
+ beforeManifest?: () => void;
254
+ manifest: (composition: ManagedUlwLaunchComposition) => unknown;
255
+ }): Promise<{ composition: ManagedUlwLaunchComposition; prepared?: string; deadline?: number }> {
207
256
  if (!options.bunCommand.length) throw new Error("Managed ULW discovery requires the launcher's Bun command");
208
- const { env, bunCommand, ...input } = options;
209
- const output = await run([...bunCommand, ...(input.worker ? ["--no-install"] : []), fileURLToPath(import.meta.url),
210
- input.worker ? "--worker-launch-extensions" : "--launch-extensions", JSON.stringify(input)],
211
- input.worker ? dirname(options.configPath) : options.cwd, 30_000,
212
- Object.fromEntries(Object.entries(env).filter((entry): entry is [string, string] => entry[1] !== undefined)));
213
- const result = output.split("\n").findLast(line => line.startsWith("MANAGED_ULW_LAUNCH "));
214
- if (!result) throw new Error("Stock OMP discovery did not return a launch composition");
215
- return JSON.parse(result.slice("MANAGED_ULW_LAUNCH ".length));
257
+ const { env, bunCommand, discoveryTimeoutMs = LAUNCH_DISCOVERY_TIMEOUT_MS, ...input } = options;
258
+ const helper = fileURLToPath(new URL("./host-sdk-helper.ts", import.meta.url));
259
+ const child = Bun.spawn([...bunCommand, ...(input.worker ? ["--no-install"] : []), helper, "launch"], {
260
+ cwd: input.worker ? dirname(options.configPath) : options.cwd,
261
+ env: Object.fromEntries(Object.entries(env).filter((entry): entry is [string, string] => entry[1] !== undefined)),
262
+ stdin: "pipe", stdout: "pipe", stderr: prepare?.stderr ?? "ignore",
263
+ });
264
+ const reader = child.stdout.getReader();
265
+ const decoder = new TextDecoder();
266
+ let output = "";
267
+ let bytes = 0;
268
+ const read = async () => {
269
+ const chunk = await reader.read();
270
+ if (chunk.done) return false;
271
+ bytes += chunk.value.byteLength;
272
+ if (bytes > LAUNCH_OUTPUT_LIMIT) throw new Error("Host SDK launch output exceeded its bound");
273
+ output += decoder.decode(chunk.value, { stream: true });
274
+ return true;
275
+ };
276
+ try {
277
+ const discoveryDeadline = performance.now() + Math.max(1, discoveryTimeoutMs);
278
+ const composition = await launchPhase(discoveryDeadline, "Stock OMP discovery timed out", async () => {
279
+ child.stdin.write(JSON.stringify(input.managedUlwPath === undefined ? null : input) + "\n");
280
+ child.stdin.flush();
281
+ let scan = 0;
282
+ for (;;) {
283
+ const newline = output.indexOf("\n", scan);
284
+ if (newline < 0) {
285
+ scan = output.length;
286
+ if (await read()) continue;
287
+ throw new Error("Stock OMP discovery did not return a launch composition");
288
+ }
289
+ const line = output.slice(0, newline);
290
+ output = output.slice(newline + 1);
291
+ scan = 0;
292
+ if (line.startsWith(LAUNCH_ERROR_MARKER)) throw new Error(JSON.parse(line.slice(LAUNCH_ERROR_MARKER.length)));
293
+ if (line.startsWith(LAUNCH_MARKER)) {
294
+ const result: ManagedUlwLaunchComposition = JSON.parse(line.slice(LAUNCH_MARKER.length));
295
+ if (!prepare) {
296
+ child.stdin.end();
297
+ // Discovery-only mode has no further output to consume.
298
+ if (await child.exited !== 0) throw new Error("Stock OMP discovery failed");
299
+ }
300
+ return result;
301
+ }
302
+ }
303
+ });
304
+ if (!prepare) return { composition };
305
+
306
+ const deadline = performance.now() + Math.max(1, prepare.timeoutMs);
307
+ const timeout = "Native session preparation timed out";
308
+ bytes = Buffer.byteLength(output);
309
+ const prepared = await launchPhase(deadline, timeout, async assertActive => {
310
+ const payload = JSON.stringify(await prepare.manifest(composition));
311
+ // A timed-out manifest builder must never cross the worker launch fence.
312
+ assertActive();
313
+ prepare.beforeManifest?.();
314
+ child.stdin.write(payload);
315
+ child.stdin.end();
316
+ while (await read()) {}
317
+ if (await child.exited !== 0) throw new Error("Native session preparation failed");
318
+ return output + decoder.decode();
319
+ });
320
+ return { composition, prepared, deadline };
321
+ } finally {
322
+ // A descendant can hold a pipe open after the helper exits. Stop observing
323
+ // its stdout rather than waiting on it (or stderr) past a phase deadline.
324
+ if (child.exitCode === null && child.signalCode === null) {
325
+ try { child.kill("SIGKILL"); } catch {} // The child may have just exited.
326
+ }
327
+ void reader.cancel().catch(() => {});
328
+ }
216
329
  }
217
330
 
218
- if (import.meta.main && process.argv[2] === "--worker-launch-extensions") {
219
- const input: {
220
- cwd: string; managedUlwPath: string; extensionPaths: string[]; launchArgs: string[];
221
- worker: Pick<WorkerHostProfile, "extensionPaths">;
222
- } = JSON.parse(process.argv[3] ?? "");
331
+ /**
332
+ * Native discovery for one launch, run inside the short-lived Host SDK helper
333
+ * process: it imports SDK modules and mutates process-global discovery state.
334
+ */
335
+ export async function managedUlwLaunchComposition(input: ManagedUlwLaunchInput): Promise<ManagedUlwLaunchComposition> {
336
+ return input.worker ? workerLaunchComposition({ ...input, worker: input.worker }) : launchComposition(input);
337
+ }
338
+
339
+ async function workerLaunchComposition(input: ManagedUlwLaunchInput & { worker: Pick<WorkerHostProfile, "extensionPaths"> }): Promise<ManagedUlwLaunchComposition> {
223
340
  const { assertWorkerWorkspaceStartup } = await import("./worker-profile");
224
341
  const { homedir } = await import("node:os");
225
342
  assertWorkerWorkspaceStartup(input.cwd, homedir());
@@ -236,14 +353,10 @@ if (import.meta.main && process.argv[2] === "--worker-launch-extensions") {
236
353
  // opt-in modules as files, while managed packages retain their own resources.
237
354
  const managed = validateManagedUlwPackage(input.managedUlwPath);
238
355
  const extensionPaths = [...new Set([...input.extensionPaths, managed, ...input.worker.extensionPaths])];
239
- console.log(`MANAGED_ULW_LAUNCH ${JSON.stringify({ extensionPaths, noExtensions: true, memoryWriteDir: null })}`);
356
+ return { extensionPaths, noExtensions: true, memoryWriteDir: null };
240
357
  }
241
358
 
242
- if (import.meta.main && process.argv[2] === "--launch-extensions") {
243
- const input = JSON.parse(process.argv[3]!) as {
244
- cwd: string; managedUlwPath: string; extensionPaths: string[]; parentConfigPath?: string;
245
- commandArgs: string[]; launchArgs: string[];
246
- };
359
+ async function launchComposition(input: ManagedUlwLaunchInput): Promise<ManagedUlwLaunchComposition> {
247
360
  const { parseNativeLaunch } = await import("./native-launch-profile");
248
361
  const parsed = await parseNativeLaunch(input.launchArgs);
249
362
  const { extractProfileFlags } = await import("@oh-my-pi/pi-coding-agent/cli/profile-bootstrap");
@@ -399,7 +512,7 @@ if (import.meta.main && process.argv[2] === "--launch-extensions") {
399
512
  const current = await readNativeSettings(settings).catch(() => { throw new Error(memoryBlockReason({ status: "unknown" })); });
400
513
  const { memory } = await ensureManagedMemory(current, memoryWriteDir);
401
514
  if (memory.status !== "enabled") throw new Error(memoryBlockReason(memory));
402
- console.log(`MANAGED_ULW_LAUNCH ${JSON.stringify({ ...composition, memoryWriteDir })}`);
515
+ return { ...composition, memoryWriteDir };
403
516
  }
404
517
 
405
518
  /** Serialized source preparation only. No Gateway, account adapter, or Host starts here. */
@@ -4,14 +4,17 @@
4
4
  { "name": "status", "description": "Inspect Superagent HEAD and this conversation's lane, including while busy." },
5
5
  { "name": "restart", "description": "Interrupt HEAD work and restart Superagent Gateway and HEAD with the same session and memory." },
6
6
  { "name": "context", "description": "Inspect Superagent HEAD context without starting a model turn." },
7
- { "name": "usage", "description": "Show Superagent's OMP account quotas and reset times." },
7
+ { "name": "usage", "description": "Show Superagent's OMP quotas or open the saved reset picker.", "text": "Omit to view quotas, or enter reset to choose an account and confirm using one saved reset.",
8
+ "discord": { "description": "Show Superagent's OMP quotas.", "text": false } },
8
9
  { "name": "cron", "description": "Schedule and manage Superagent jobs in this conversation.", "text": "Use help, add, list, show, edit, pause, resume, run or remove." },
9
10
  { "name": "resume", "description": "Resume the Superagent lane bound to this conversation." },
10
11
  { "name": "resolve", "description": "Close an uncertain Superagent HEAD or bound lane input without replay.", "text": "Exact uncertain HEAD input ID, or --lane followed by the bound lane's exact input ID." },
11
12
  { "name": "main", "description": "Select the main Superagent topic in this owner DM." },
12
- { "name": "model", "description": "Choose a Superagent HEAD model, or inspect or apply a named preset.", "text": "Omit for the menu, or enter list, an exact provider/model, or a preset command." },
13
+ { "name": "model", "description": "Choose a Superagent HEAD model or preset, or use --lane for the bound lane.", "text": "Omit for the menu, or enter list, provider/model, --lane provider/model, or a preset command.",
14
+ "discord": { "description": "Choose a model for the Superagent HEAD or the current lane.", "text": true } },
13
15
  { "name": "effort", "description": "Choose the Superagent HEAD thinking effort.", "text": "Omit for the menu, or enter an exact advertised effort level." },
14
16
  { "name": "compact", "description": "Compact Superagent HEAD context when idle.", "text": "Optional compaction instructions, including multiple lines." },
15
17
  { "name": "stop", "description": "Stop Superagent work in this conversation, the shared HEAD, or a named lane.", "text": "Omit for this conversation, or specify head or an exact lane ID." },
16
- { "name": "new", "description": "Start a Superagent work topic; use a sibling for a new request in an existing thread.", "text": "An optional first request for the new topic." }
18
+ { "name": "new", "description": "Start a Superagent work topic; use a sibling for a new request in an existing thread.", "text": "An optional first request for the new topic." },
19
+ { "name": "usage-reset", "description": "Choose an OMP account and review a saved usage reset in Superagent.", "discordOnly": true }
17
20
  ]
@@ -1,8 +1,15 @@
1
1
  import catalog from "./messenger-command-catalog.json" with { type: "json" };
2
2
 
3
- /** Supported owner controls shared by each platform's command picker and the native Gateway. */
4
- export const MESSENGER_COMMANDS: readonly {
3
+ /** Owner controls and platform-specific registration metadata shared with the native Gateway. */
4
+ export const MESSENGER_COMMAND_CATALOG: readonly {
5
5
  readonly name: string;
6
6
  readonly description: string;
7
7
  readonly text?: string;
8
+ readonly discordOnly?: boolean;
9
+ readonly discord?: {
10
+ readonly description: string;
11
+ readonly text: boolean;
12
+ };
8
13
  }[] = catalog;
14
+
15
+ export const MESSENGER_COMMANDS = MESSENGER_COMMAND_CATALOG.filter(command => !command.discordOnly);
@@ -1,4 +1,7 @@
1
+ import { homedir } from "node:os";
2
+ import { join, resolve } from "node:path";
1
3
  import type { ExtensionContext } from "@oh-my-pi/pi-coding-agent";
4
+ import { getProjectAgentDir, MAIN_CONFIG_FILENAMES, normalizePathForComparison } from "@oh-my-pi/pi-utils/dirs";
2
5
  import { IsStandardObject as isRecord } from "@sinclair/typebox/value";
3
6
  import { acquireModelRoleMutation, getModelPreset, getModelPresetNames, isValidModelPresetName } from "@oh-my-pi/pi-coding-agent/config/model-presets";
4
7
  import { pickDefaultAvailableModel, resolveModelRoleValue } from "@oh-my-pi/pi-coding-agent/config/model-resolver";
@@ -10,6 +13,7 @@ import { editNativeGlobalConfig, hasUnresolvedNativeLegacy, readNativeSettings }
10
13
 
11
14
  export type NativeModel = Awaited<ReturnType<ExtensionContext["models"]["list"]>>[number];
12
15
  export type BootstrapName = (typeof MODEL_PRESET_NAMES)[number];
16
+ export type PresetSyncOutcome = "applied" | "deferred";
13
17
  type PresetSource = "runtime" | "overlay" | "project" | "global";
14
18
  export type NativePresetChoices = Partial<Record<BootstrapName, { model: LaneModel; reason: string }>>;
15
19
  const followingRoles = { high: "slow", middle: "default", low: "smol" } as const;
@@ -69,6 +73,24 @@ export class NativePresetManager {
69
73
  this.source = settings;
70
74
  }
71
75
 
76
+ watchedPaths(): string[] {
77
+ const agentDir = this.settings.getAgentDir();
78
+ const paths = [
79
+ ...MAIN_CONFIG_FILENAMES.map(filename => join(agentDir, filename)),
80
+ join(agentDir, "settings.json"),
81
+ ];
82
+ const cwd = resolve(this.settings.getCwd());
83
+ if (normalizePathForComparison(cwd) !== normalizePathForComparison(homedir())) {
84
+ const projectDir = getProjectAgentDir(cwd);
85
+ paths.push(
86
+ ...MAIN_CONFIG_FILENAMES.map(filename => join(projectDir, filename)),
87
+ join(projectDir, "settings.json"),
88
+ );
89
+ }
90
+ paths.push(...this.settings.getConfigFiles());
91
+ return [...new Set(paths)];
92
+ }
93
+
72
94
  private async reload(): Promise<void> {
73
95
  await this.source.reloadFromDisk();
74
96
  this.settings = await readNativeSettings(this.source);
@@ -167,11 +189,11 @@ export class NativePresetManager {
167
189
 
168
190
  /** Follow persistent native roles without changing the active native session. */
169
191
  async syncRoles(store: Pick<StorePort, "getMeta" | "setMeta">, canWrite: () => boolean,
170
- reloadCatalog?: () => Promise<void>): Promise<void> {
192
+ reloadCatalog?: () => Promise<void>): Promise<PresetSyncOutcome> {
171
193
  const release = await acquireModelRoleMutation();
172
194
  try {
173
195
  await this.reload();
174
- if (!canWrite()) return;
196
+ if (!canWrite()) return "deferred";
175
197
  const settings = this.settings;
176
198
  const base = this.capture();
177
199
  const before = store.getMeta(followedPresets);
@@ -195,10 +217,10 @@ export class NativePresetManager {
195
217
  }
196
218
  const roles = JSON.stringify(resolved.map(({ selector, defaultSelector }) => [selector ?? null, defaultSelector]));
197
219
  // A temporarily unavailable configured role is not a new policy.
198
- if (resolved.some(({ selector, defaultSelector }) => selector && !defaultSelector)) return;
220
+ if (resolved.some(({ selector, defaultSelector }) => selector && !defaultSelector)) return "deferred";
199
221
  const edits: { name: BootstrapName; snapshot: LanePresetSnapshot }[] = [];
200
222
  for (const { name, model, defaultSelector } of resolved) {
201
- if (!canWrite()) break;
223
+ if (!canWrite()) return "deferred";
202
224
  const tracked = ownership[name];
203
225
  if (tracked === null) continue; // A manual edit/deletion releases management.
204
226
  const owned = settings.getOwnedModelPreset(name);
@@ -228,16 +250,21 @@ export class NativePresetManager {
228
250
  if (Bun.deepEquals(preset, next)) ownership[name] = { preset, roles };
229
251
  else edits.push({ name, snapshot: next });
230
252
  }
253
+ let deferred = false;
231
254
  if (edits.length) {
232
255
  const applied = await editNativeGlobalConfig(settings, edits.map(({ name, snapshot }) => ({
233
256
  path: `modelPresets.${name}`, value: snapshot,
234
257
  })), actual => canWrite() && edits.every(({ name }) => actual.getOwnedModelPreset(name)?.source === "global")
235
258
  && Bun.deepEquals(actual.getModelRoles(), base.modelRoles)
236
259
  && cfgDefaultThinkingLevel.get(actual) === base.defaultThinkingLevel);
237
- for (const [index, { name, snapshot }] of edits.entries()) if (applied[index]) ownership[name] = { preset: snapshot, roles };
260
+ for (const [index, { name, snapshot }] of edits.entries()) {
261
+ if (applied[index]) ownership[name] = { preset: snapshot, roles };
262
+ else deferred = true;
263
+ }
238
264
  }
239
265
  const saved = JSON.stringify(ownership);
240
266
  if (saved !== (before ?? "{}")) store.setMeta(followedPresets, saved);
267
+ return deferred ? "deferred" : "applied";
241
268
  } finally { release(); }
242
269
  }
243
270