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
package/src/host.ts CHANGED
@@ -10,20 +10,42 @@ import {
10
10
  type RpcAgentProcess,
11
11
  } from "@oh-my-pi/pi-coding-agent/modes/rpc/rpc-client";
12
12
  import { RPC_GOAL_CONTINUATION_MODE } from "@oh-my-pi/pi-coding-agent/modes/rpc/rpc-goal";
13
- import { HostChannel, type HostResponse, type HostState } from "./host-protocol";
13
+ import { HostChannel, PR_REVIEW_GITHUB_ENV, PR_REVIEW_SYSTEM_PROMPT, type HostResponse, type HostState } from "./host-protocol";
14
14
  import { requireHostOwner } from "./host-owner-path";
15
15
  import { inspectInstalledOmp, resolveOmpCommand } from "./installed-omp";
16
16
  import type { DialogResponse, LanePresetSnapshot } from "./contracts";
17
17
  import type { WorkerHostProfile } from "./worker-profile";
18
- import { activeManagedUlw, managedUlwLaunchExtensions, MANAGED_ULW_ENV, MANAGED_ULW_FIXTURE_ENV, MANAGED_ULW_FIXTURE_ROOT_ENV, validateManagedUlwPackage } from "./managed-ulw";
18
+ import { activeManagedUlw, managedUlwLaunch, MANAGED_ULW_ENV, MANAGED_ULW_FIXTURE_ENV, MANAGED_ULW_FIXTURE_ROOT_ENV, validateManagedUlwPackage } from "./managed-ulw";
19
19
 
20
20
  const CONNECT_TIMEOUT_MS = 5_000;
21
21
  const START_TIMEOUT_MS = 30_000;
22
22
  const MAX_PENDING_BYTES = 16 * 1024 * 1024;
23
23
  const MAX_PENDING_WRITES = 4096;
24
+ export const PR_REVIEW_INPUT_PREFIX = "Static PR review input:\n";
25
+
26
+ // These settings are scoped to the private launch overlay. In particular no
27
+ // review text enters the ordinary memory backend or an autonomous side turn.
28
+ const prReviewSettings = {
29
+ memory: { backend: "off" },
30
+ goal: { enabled: false },
31
+ compaction: { enabled: false },
32
+ advisor: { enabled: false },
33
+ autolearn: { enabled: false },
34
+ dev: { autoqa: false },
35
+ skills: { enabled: false, enableSkillCommands: false, customDirectories: [] },
36
+ mcp: { enableProjectConfig: false },
37
+ marketplace: { autoUpdate: "off" },
38
+ magicKeywords: { enabled: false },
39
+ prewalk: { enabled: false, auto: "off" },
40
+ spotlight: { experiment: { enabled: false } },
41
+ providers: { cacheWarming: "off" },
42
+ telemetry: { otlpExportEnabled: false },
43
+ };
24
44
 
25
45
  export interface HostOptions {
26
46
  command: string[];
47
+ /** Local managed static review lane; cwd must be a private empty non-checkout. */
48
+ readonly prReviewOnly?: true;
27
49
  /** Target-owned launch policy, never decoded from an SSH request. */
28
50
  readonly worker?: WorkerHostProfile;
29
51
  socketPath: string;
@@ -176,7 +198,8 @@ export class HostConnection {
176
198
  const timeout = setTimeout(disconnect, CONNECT_TIMEOUT_MS);
177
199
  try {
178
200
  const state = await connection.#handshake();
179
- if (state.hostPid !== expected.pid || state.sessionId !== expected.sessionId || state.sessionFile !== expected.sessionFile) {
201
+ if (state.prReviewPolicy !== undefined || state.hostPid !== expected.pid || state.sessionId !== expected.sessionId ||
202
+ state.sessionFile !== expected.sessionFile) {
180
203
  throw new Error("Remote Host identity differs from its worker registration");
181
204
  }
182
205
  await connection.#enableActivityUpdates(state);
@@ -229,7 +252,8 @@ export class HostConnection {
229
252
  }
230
253
 
231
254
  async #enableActivityUpdates(state: HostState): Promise<void> {
232
- if (typeof state.loadedSuperkitPath !== "string" || !path.isAbsolute(state.loadedSuperkitPath))
255
+ if (state.prReviewPolicy?.version !== 1 &&
256
+ (typeof state.loadedSuperkitPath !== "string" || !path.isAbsolute(state.loadedSuperkitPath)))
233
257
  throw new Error("Native Host has not verified its omp-superkit extension; stop and start the Host");
234
258
  const capability = await this.request({ type: "get_host_admission", messageUpdateCapability: true });
235
259
  if (!capability.success || capability.command !== "get_host_admission") {
@@ -244,6 +268,12 @@ export class HostConnection {
244
268
  }
245
269
  }
246
270
 
271
+ /** Call on the exact local connection before admitting each review round. */
272
+ async assertPrReviewOnly(cwd: string): Promise<void> {
273
+ const state = await this.client.getState();
274
+ await assertPrReviewState(state, cwd);
275
+ }
276
+
247
277
  /** Private adapter correlation. Stock RpcClient deliberately has no generic request API. */
248
278
  request(command: Record<string, unknown>, id?: string): Promise<HostResponse> {
249
279
  if (typeof command.type !== "string" || !command.type) throw new Error("RPC command requires a type");
@@ -284,6 +314,23 @@ export function connect(socketPath: string): Promise<HostConnection> {
284
314
  return HostConnection.connect(socketPath);
285
315
  }
286
316
 
317
+ async function assertPrReviewState(state: HostState, cwd: string): Promise<void> {
318
+ const canonical = await fs.realpath(cwd);
319
+ if (state.prReviewPolicy?.version !== 1 || state.prReviewPolicy.cwd !== canonical ||
320
+ typeof state.prReviewPolicy.modelApi !== "string" || state.prReviewPolicy.modelApi !== state.model?.api ||
321
+ !Array.isArray(state.dumpTools) || state.dumpTools.length !== 0)
322
+ throw new Error("Native Host did not confirm the local static PR review policy");
323
+ }
324
+
325
+ async function assertPrReviewLaunch(options: HostOptions): Promise<void> {
326
+ if (options.worker || options.modelPreset || options.modelSettings || options.env.OMP_SUPERAGENT_WORKER_ATTEMPT)
327
+ throw new Error("Static PR review requires an exact-model local Host, without worker or preset policy");
328
+ const { extractProfileFlags } = await import("@oh-my-pi/pi-coding-agent/cli/profile-bootstrap");
329
+ const bootstrap = extractProfileFlags(options.command.slice(1));
330
+ if (bootstrap.argv.length || bootstrap.aliasName !== undefined)
331
+ throw new Error("Static PR review Host accepts only the native --profile launch prefix");
332
+ }
333
+
287
334
  export async function buildHostArgs(options: HostOptions, configPath = `${options.socketPath}.config.json`,
288
335
  composition?: { extensionPaths: string[]; noExtensions: boolean }): Promise<string[]> {
289
336
  assertSocketPath(options.socketPath);
@@ -299,6 +346,14 @@ export async function buildHostArgs(options: HostOptions, configPath = `${option
299
346
  if (!Number.isSafeInteger(options.subagentConcurrency) || options.subagentConcurrency < 1) {
300
347
  throw new Error("subagentConcurrency must be a positive integer");
301
348
  }
349
+ if (options.prReviewOnly) {
350
+ await assertPrReviewLaunch(options);
351
+ return ["--mode", "rpc-ui", "--session", options.sessionFile, "--cwd", options.cwd,
352
+ "--no-tools", "--no-extensions", "--no-lsp", "--no-skills", "--no-rules", "--no-context-files",
353
+ "--no-title", "--no-prewalk", "--offline",
354
+ "--trusted-extension", await fs.realpath(fileURLToPath(new URL("./host-extension.ts", import.meta.url))),
355
+ "--system-prompt", PR_REVIEW_SYSTEM_PROMPT, "--config", configPath];
356
+ }
302
357
  if (options.modelPreset) {
303
358
  // Only named lane presets need the SDK's model resolver. HEAD launches
304
359
  // (including restored model settings) must not load it just to build argv.
@@ -341,7 +396,30 @@ export async function startHost(options: HostOptions, beforeSessionPrepare?: ()
341
396
  async function launchHost(options: HostOptions, beforeSessionPrepare?: () => void): Promise<{ pid: number }> {
342
397
  // Snapshot once before any awaits; an updater may activate a newer revision
343
398
  // during startup, but this Host must load one exact immutable package.
344
- const managedUlwPath = selectManagedUlw(options);
399
+ if (options.prReviewOnly) {
400
+ await assertPrReviewLaunch(options);
401
+ await privateDirectory(options.cwd);
402
+ const cwd = await fs.realpath(options.cwd);
403
+ if ((await fs.readdir(cwd)).length) throw new Error("Static PR review workspace must be empty");
404
+ // No Git invocation (including hooks or configuration) is needed to
405
+ // distinguish an empty directory from an empty subdirectory of a checkout.
406
+ for (let dir = cwd; ; dir = path.dirname(dir)) {
407
+ if (await fs.lstat(path.join(dir, ".git")).then(() => true, error => {
408
+ if (error instanceof Error && "code" in error && error.code === "ENOENT") return false;
409
+ throw error;
410
+ })) throw new Error("Static PR review workspace must be outside a Git checkout");
411
+ if (path.dirname(dir) === dir) break;
412
+ }
413
+ const { assertWorkerWorkspaceStartup } = await import("./worker-profile");
414
+ assertWorkerWorkspaceStartup(cwd, options.env.HOME ?? "");
415
+ const env = { ...options.env };
416
+ for (const name of [...PR_REVIEW_GITHUB_ENV,
417
+ MANAGED_ULW_ENV, MANAGED_ULW_FIXTURE_ENV, MANAGED_ULW_FIXTURE_ROOT_ENV]) delete env[name];
418
+ options = { ...options, cwd, env, managedUlwPath: undefined, managedUlwRoot: undefined };
419
+ }
420
+ // Do not discover, load or preflight Superkit (or persist a global memory
421
+ // fallback) for isolated review lanes.
422
+ const managedUlwPath = options.prReviewOnly ? undefined : selectManagedUlw(options);
345
423
  const fixture = options.managedUlwPath ?? options.env[MANAGED_ULW_FIXTURE_ENV];
346
424
  const hostOwnerExecutable = await requireHostOwner();
347
425
  const fixtureRoot = options.managedUlwRoot ?? options.env[MANAGED_ULW_FIXTURE_ROOT_ENV];
@@ -349,7 +427,7 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
349
427
  : Bun.which("bun", { PATH: options.env.PATH ?? process.env.PATH }));
350
428
  if (!bun || !path.isAbsolute(bun)) throw new Error("Managed Host launch requires an explicit installed Bun executable");
351
429
  options = { ...options, command: resolveOmpCommand(options.command, options.env.PATH ?? ""), managedUlwPath,
352
- env: { ...options.env, [MANAGED_ULW_ENV]: managedUlwPath,
430
+ env: { ...options.env, ...(managedUlwPath ? { [MANAGED_ULW_ENV]: managedUlwPath } : {}),
353
431
  OMP_SUPERAGENT_BUN: bun,
354
432
  ...(fixture ? { [MANAGED_ULW_FIXTURE_ENV]: fixture } : {}),
355
433
  ...(fixtureRoot ? { [MANAGED_ULW_FIXTURE_ROOT_ENV]: fixtureRoot } : {}) } };
@@ -382,6 +460,7 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
382
460
  ...options.worker?.config,
383
461
  task: { maxConcurrency: options.subagentConcurrency },
384
462
  goal: { continuationModes: [RPC_GOAL_CONTINUATION_MODE] },
463
+ ...(options.prReviewOnly ? prReviewSettings : {}),
385
464
  ...(options.modelPreset ? { modelPresets: { [options.modelPreset.name]: options.modelPreset.preset } } : {}),
386
465
  ...(initialSettings ? {
387
466
  modelRoles: {
@@ -398,36 +477,38 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
398
477
  throw new Error("Host log must be a private regular file owned by this user");
399
478
  }
400
479
  const manifestPath = path.join(launchDirectory, "owner.json");
401
- const extensionPaths = [fileURLToPath(new URL("../", import.meta.url)), managedUlwPath, options.extensionPath,
402
- fileURLToPath(new URL("./board-extension.ts", import.meta.url)),
480
+ const { env: _inheritedEnvironment, worker: _workerProfile, ...launchOptions } = options;
481
+ const helperPath = fileURLToPath(new URL("./host-sdk-helper.ts", import.meta.url));
482
+ let manifest: Record<string, unknown> | undefined;
483
+ const extensionPaths = managedUlwPath === undefined ? [] : [fileURLToPath(new URL("../", import.meta.url)),
484
+ managedUlwPath, options.extensionPath, fileURLToPath(new URL("./board-extension.ts", import.meta.url)),
403
485
  fileURLToPath(new URL("./host-extension.ts", import.meta.url))];
404
- const composition = await managedUlwLaunchExtensions({ cwd: options.cwd, managedUlwPath,
486
+ // The same helper discovers composition and then prepares the session.
487
+ // The worker launch fence is committed only immediately before the manifest
488
+ // is sent. Preparation and owner startup share the same deadline.
489
+ const { prepared, deadline } = await managedUlwLaunch({ cwd: options.cwd, managedUlwPath,
405
490
  extensionPaths, configPath, parentConfigPath: process.env.OMP_SUPERAGENT_HOST_CONFIG, commandArgs: options.command.slice(1),
406
491
  ...(options.worker ? { worker: { extensionPaths: options.worker.extensionPaths } } : {}),
407
- launchArgs: [...options.command.slice(1), ...await buildHostArgs(options, configPath)],
408
- env: options.env, bunCommand: [bun, "--no-env-file"] });
409
- const { env: _inheritedEnvironment, worker: _workerProfile, ...launchOptions } = options;
410
- const helperPath = fileURLToPath(new URL("./host-sdk-helper.ts", import.meta.url));
411
- const manifest = { options: launchOptions, args: await buildHostArgs(options, configPath, composition), configPath, memoryWriteDir: composition.memoryWriteDir,
412
- processBackend, helperPath, nativeSocket: path.join(path.dirname(options.socketPath), `.n-${crypto.randomUUID().slice(0, 8)}.sock`) };
413
- // Preparation used to run inside the owner; it shares the same startup budget.
414
- const deadline = Date.now() + START_TIMEOUT_MS;
415
- // The SDK helper is the first operation that can create or publish this
416
- // session. A worker must persist its launch fence before spawning it.
417
- beforeSessionPrepare?.();
418
- const prepare = Bun.spawn([bun, "--no-env-file", helperPath, "prepare"], {
419
- cwd: options.worker ? launchDirectory : options.cwd, env: options.env, stdin: new Blob([JSON.stringify(manifest)]), stdout: "pipe", stderr: log.fd,
420
- timeout: START_TIMEOUT_MS, killSignal: "SIGKILL",
492
+ launchArgs: managedUlwPath === undefined ? [] : [...options.command.slice(1), ...await buildHostArgs(options, configPath)],
493
+ env: options.env, bunCommand: [bun, "--no-env-file"] }, {
494
+ stderr: log.fd, timeoutMs: START_TIMEOUT_MS, beforeManifest: beforeSessionPrepare,
495
+ manifest: async composition => {
496
+ manifest = { options: launchOptions, args: await buildHostArgs(options, configPath, composition), configPath,
497
+ memoryWriteDir: composition.memoryWriteDir, processBackend, helperPath,
498
+ nativeSocket: path.join(path.dirname(options.socketPath), `.n-${crypto.randomUUID().slice(0, 8)}.sock`) };
499
+ return manifest;
500
+ },
421
501
  });
422
- const [prepared, code] = await Promise.all([new Response(prepare.stdout).text(), prepare.exited]);
423
- if (Date.now() >= deadline) throw new Error("Native session preparation timed out");
424
- if (code !== 0) throw new Error("Native session preparation failed");
502
+ if (deadline === undefined || prepared === undefined) throw new Error("Native session preparation did not confirm tool selection");
503
+ if (performance.now() >= deadline) throw new Error("Native session preparation timed out");
425
504
  const flags = JSON.parse(prepared);
426
505
  if (typeof flags?.toolsExplicitlySelected !== "boolean" || typeof flags.noTools !== "boolean")
427
506
  throw new Error("Native session preparation did not confirm tool selection");
507
+ if (options.prReviewOnly && (!flags.noTools || flags.toolsExplicitlySelected))
508
+ throw new Error("Native launch did not resolve the stock no-tools selection");
428
509
  await fs.writeFile(manifestPath, JSON.stringify({ ...manifest, toolsExplicitlySelected: flags.toolsExplicitlySelected,
429
510
  noTools: flags.noTools, inventory: flags.inventory }), { flag: "wx", mode: 0o600 });
430
- if (Date.now() >= deadline) throw new Error("Native Host startup timed out before launch");
511
+ if (performance.now() >= deadline) throw new Error("Native Host startup timed out before launch");
431
512
  child = spawn(hostOwnerExecutable, [manifestPath], {
432
513
  cwd: options.cwd, env: options.env,
433
514
  detached: true, stdio: ["ignore", log.fd, log.fd], shell: false,
@@ -441,7 +522,7 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
441
522
  await log.close();
442
523
  log = undefined;
443
524
  let startingSocket: Stats | undefined;
444
- while (Date.now() < deadline) {
525
+ while (performance.now() < deadline) {
445
526
  if (failure) throw failure;
446
527
  let observed: Stats;
447
528
  try {
@@ -466,7 +547,7 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
466
547
  await Bun.sleep(50);
467
548
  continue;
468
549
  }
469
- const { connection, identity } = await HostConnection.open(options.socketPath, Math.max(1, deadline - Date.now()));
550
+ const { connection, identity, state } = await HostConnection.open(options.socketPath, Math.max(1, deadline - performance.now()));
470
551
  try {
471
552
  if (identity.dev !== startingSocket.dev || identity.ino !== startingSocket.ino) {
472
553
  throw new Error("Launched RPC socket identity changed while connecting");
@@ -475,6 +556,7 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
475
556
  if (path.resolve(identity.sessionFile) !== path.resolve(options.sessionFile)) {
476
557
  throw new Error("Launched RPC host identified a different session file");
477
558
  }
559
+ if (options.prReviewOnly) await assertPrReviewState(state, options.cwd);
478
560
  if (failure) throw failure;
479
561
  return { pid: identity.pid };
480
562
  } finally { await connection.close(); }
@@ -1,5 +1,5 @@
1
- import { realpathSync } from "node:fs";
2
- import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
1
+ import { closeSync, constants, fstatSync, openSync, readSync, realpathSync, statSync } from "node:fs";
2
+ import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
 
5
5
  const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
@@ -27,14 +27,126 @@ export function resolveOmpCommand(command: string[], path = process.env.PATH ??
27
27
  return [executable, ...args];
28
28
  }
29
29
 
30
- /** Inspect CLI metadata only; never open an agent or provider session. */
30
+ type InstalledOmp = Awaited<ReturnType<typeof probeInstalledOmp>>;
31
+ const inspected = new Map<string, { identity: string; result: Promise<InstalledOmp> }>();
32
+ const EXECUTION_ENV_KEYS = [
33
+ "PATH",
34
+ "LD_LIBRARY_PATH",
35
+ "LD_PRELOAD",
36
+ "DYLD_LIBRARY_PATH",
37
+ "DYLD_FALLBACK_LIBRARY_PATH",
38
+ "DYLD_INSERT_LIBRARIES",
39
+ ] as const;
40
+
41
+ function fileIdentity(filePath: string): [string, ...string[]] {
42
+ const target = realpathSync(filePath);
43
+ const { dev, ino, size, mtimeNs, ctimeNs } = statSync(target, { bigint: true });
44
+ return [target, dev.toString(), ino.toString(), size.toString(), mtimeNs.toString(), ctimeNs.toString()];
45
+ }
46
+
47
+ function readShebangTokens(filePath: string): string[] | null {
48
+ const fd = openSync(filePath, constants.O_RDONLY | constants.O_NONBLOCK);
49
+ try {
50
+ if (!fstatSync(fd).isFile()) throw new Error("OMP executable must be a regular file");
51
+ const buffer = Buffer.allocUnsafe(256);
52
+ const bytes = readSync(fd, buffer, 0, buffer.length, 0);
53
+ if (bytes < 2 || buffer[0] !== 0x23 || buffer[1] !== 0x21) return null;
54
+ const line = buffer.subarray(2, bytes).toString("utf8");
55
+ const newline = line.indexOf("\n");
56
+ if (newline < 0 && bytes === buffer.length) return [];
57
+ const trimmed = (newline >= 0 ? line.slice(0, newline) : line).replace(/\r$/, "").trim();
58
+ return trimmed ? trimmed.split(/[ \t]+/) : [];
59
+ } finally {
60
+ closeSync(fd);
61
+ }
62
+ }
63
+
64
+ function resolveEnvCommand(tokens: readonly string[], path: string): string | null {
65
+ // Only cache forms whose interpreter search uses the provided PATH
66
+ // unchanged. env options, assignments, quoting and substitutions can
67
+ // change the interpreter; use the uncached real probe for those forms.
68
+ const target = tokens[1] === "-S" ? tokens[2] : tokens.length === 2 ? tokens[1] : undefined;
69
+ if (!target || target.startsWith("-") || !/^[\w./+-]+$/.test(target)) return null;
70
+ if (isAbsolute(target) || target.includes("/")) return resolve(target);
71
+ return Bun.which(target, { PATH: path });
72
+ }
73
+
74
+ /**
75
+ * The kernel-executed file plus its shebang interpreter and loader environment:
76
+ * replacing, rewriting or retargeting the binary/script, or changing PATH/LD_*
77
+ * changes this identity. Returns null when a required shebang target is missing.
78
+ */
79
+ function executionIdentity(
80
+ executable: string, path: string, credentials: readonly string[], environment: NodeJS.ProcessEnv,
81
+ ): string | null {
82
+ const files: [string, ...string[]][] = [];
83
+ const seen = new Set<string>();
84
+ let current: string | null = executable;
85
+ for (let depth = 0; current; depth++) {
86
+ if (depth === 4) return null;
87
+ const id = fileIdentity(current);
88
+ if (seen.has(id[0])) return null;
89
+ seen.add(id[0]);
90
+ files.push(id);
91
+ const tokens = readShebangTokens(id[0]);
92
+ if (!tokens) break;
93
+ const interpreter = tokens[0];
94
+ if (!interpreter) return null;
95
+ const resolvedInterp = isAbsolute(interpreter) || interpreter.includes("/")
96
+ ? resolve(interpreter)
97
+ : Bun.which(interpreter, { PATH: path });
98
+ if (!resolvedInterp) return null;
99
+ if (basename(interpreter) === "env") {
100
+ files.push(fileIdentity(resolvedInterp));
101
+ const target = resolveEnvCommand(tokens, path);
102
+ if (!target) return null;
103
+ current = target;
104
+ continue;
105
+ }
106
+ current = resolvedInterp;
107
+ }
108
+ const env = EXECUTION_ENV_KEYS.map(name => credentials.includes(name) ? null : environment[name] ?? null);
109
+ return JSON.stringify({ files, env });
110
+ }
111
+
112
+ /**
113
+ * Inspect CLI metadata only; never open an agent or provider session.
114
+ * Results are reused in this process while the configured executable's file
115
+ * identity, shebang interpreter, and execution environment are unchanged, so
116
+ * repeated Host starts do not respawn the probes.
117
+ */
31
118
  export async function inspectInstalledOmp(
32
119
  command: string[], credentials: string[] = [], environment: NodeJS.ProcessEnv = process.env,
33
- ) {
120
+ ): Promise<InstalledOmp> {
34
121
  const path = environment.PATH ?? "";
35
122
  const [entry] = resolveOmpCommand(command, path);
36
123
  const executable = entry && (isAbsolute(entry) ? entry : Bun.which(entry, { PATH: path }));
37
124
  if (!executable) throw new Error(`Cannot find the configured OMP executable ${entry ?? ""} on PATH`);
125
+ let identity: string | null;
126
+ try { identity = executionIdentity(executable, path, credentials, environment); }
127
+ catch { return probeInstalledOmp(executable, credentials, environment); }
128
+ if (identity === null) return probeInstalledOmp(executable, credentials, environment);
129
+ const cached = inspected.get(executable);
130
+ if (cached?.identity === identity) return cached.result;
131
+ const result = probeInstalledOmp(executable, credentials, environment);
132
+ inspected.set(executable, { identity, result });
133
+ const forget = () => { if (inspected.get(executable)?.result === result) inspected.delete(executable); };
134
+ try {
135
+ const value = await result;
136
+ // A file replaced while it was probed may not be the one that answered.
137
+ let unchanged = false;
138
+ try { unchanged = executionIdentity(executable, path, credentials, environment) === identity; } catch {}
139
+ if (!unchanged) forget();
140
+ return value;
141
+ } catch (error) {
142
+ forget();
143
+ throw error;
144
+ }
145
+ }
146
+
147
+ async function probeInstalledOmp(
148
+ executable: string, credentials: string[], environment: NodeJS.ProcessEnv,
149
+ ) {
38
150
  const env = { ...environment };
39
151
  for (const name of credentials) delete env[name];
40
152
  const probe = async (...args: string[]) => {
@@ -21,6 +21,14 @@ export function isLaneModel(value: unknown): value is LaneModel {
21
21
  typeof model.id === "string" && !!model.id.trim() && !model.id.includes("\0");
22
22
  }
23
23
 
24
+ // Match worker_rpc::model_id: Rust char::is_whitespace / char::is_control.
25
+ const invalidRestrictedSelector = /[\p{White_Space}\p{Cc}]/u;
26
+
27
+ /** The narrow exact-selector wire used by remote workers and static PR Hosts. */
28
+ export function acceptsRestrictedModelSelector(model: LaneModel): boolean {
29
+ return !!model.provider && !!model.id && !invalidRestrictedSelector.test(model.provider) && !invalidRestrictedSelector.test(model.id);
30
+ }
31
+
24
32
  /** Project native catalog facts only: endpoints, headers, credentials and opaque internals never leave here. */
25
33
  export function codingModels(value: unknown): LaneModelCandidate[] {
26
34
  if (!Array.isArray(value)) throw new Error("Native available-model response is missing its model list");
@@ -1,7 +1,7 @@
1
1
  // Finite native prompt-composition gate, not a model turn or workflow execution.
2
2
  import assert from "node:assert/strict";
3
3
  import { mkdir, readFile, realpath } from "node:fs/promises";
4
- import { dirname, join, resolve } from "node:path";
4
+ import { dirname, join, resolve, sep } from "node:path";
5
5
  import { getBundledModel, getBundledProviders } from "@oh-my-pi/pi-catalog";
6
6
  import { ModelRegistry, Settings, AuthStorage, SessionManager, createAgentSession } from "@oh-my-pi/pi-coding-agent";
7
7
  import { ExtensionRunner } from "@oh-my-pi/pi-coding-agent/extensibility/extensions/runner";
@@ -10,6 +10,7 @@ import { buildAvailableSlashCommands } from "@oh-my-pi/pi-coding-agent/slash-com
10
10
  import { buildSystemPrompt } from "@oh-my-pi/pi-coding-agent/system-prompt";
11
11
  import { WORKFLOW_NAMES } from "./contracts";
12
12
  import { readManagedUlwPackage } from "./managed-ulw";
13
+ import { canonicalSuperkitSkills, hasCanonicalSuperkitSkills, legacySuperkitSkills, superkitWorkflows as workflows } from "./superkit-skills";
13
14
  import { advertisedWorkflow } from "./workflow";
14
15
 
15
16
  const packageArg = process.argv[2];
@@ -23,18 +24,13 @@ let networkAttempts = 0;
23
24
  const refuseNetwork = () => { networkAttempts++; throw new Error("Managed Superkit probe forbids network and provider calls"); };
24
25
  globalThis.fetch = Object.assign(async () => refuseNetwork(), { preconnect: refuseNetwork });
25
26
 
26
- // Public command names changed; installed skill IDs (also legacy commands,
27
- // except ultrawork) and the prompt/journal protocol did not.
28
- const workflows = [
29
- ["super-plan", "ulw-plan"],
30
- ["super-run", "ulw-execute"],
31
- ["super-loop", "ulw-loop"],
32
- ["super-graph", "mass-ulw"],
33
- ["super-research", "ulw-research"],
34
- ] as const;
35
27
  const skillPath = (id: string) => join(packagePath, "skills", id, "SKILL.md");
36
- const directive = /<ultrawork-mode>([\s\S]*?)<\/ultrawork-mode>/.exec(await readFile(skillPath("ultrawork"), "utf8"))?.[1];
37
- assert(directive?.trim(), "Managed Superkit must ship a directive in its installed ultrawork skill");
28
+ const canonicalLayout = hasCanonicalSuperkitSkills(packagePath);
29
+ const directiveId = (canonicalLayout ? canonicalSuperkitSkills : legacySuperkitSkills)[0];
30
+ const directivePath = await realpath(skillPath(directiveId));
31
+ assert(directivePath.startsWith(packagePath + sep), `Managed Superkit skill leaves its package: ${directiveId}`);
32
+ const directive = /<ultrawork-mode>([\s\S]*?)<\/ultrawork-mode>/.exec(await readFile(directivePath, "utf8"))?.[1];
33
+ assert(directive?.trim(), `Managed Superkit must ship a directive in its installed ${directiveId} skill`);
38
34
 
39
35
  const modules = await listPackageExtensionModules([packagePath], process.cwd(), { plugins: false });
40
36
  assert.deepEqual(await Promise.all(modules.map(module => realpath(module.path))), extensionFiles,
@@ -113,7 +109,7 @@ try {
113
109
  if (workflow) {
114
110
  const policy = /<omp-ulw-policy>\s*<ultrawork-mode>([\s\S]*?)<\/ultrawork-mode>\s*<\/omp-ulw-policy>/.exec(text)?.[1];
115
111
  assert(policy && policy.trim().length > 200, "Activated SUPER policy must contain the workflow directive");
116
- assert.equal(policy, directive, "Activated SUPER policy must use the installed ultrawork directive");
112
+ assert.equal(policy, directive, `Activated SUPER policy must use the installed ${directiveId} directive`);
117
113
  assert(!nativeBase.join("\n\n").includes(policy), "Workflow policy must come from the candidate hook");
118
114
  }
119
115
  assert.deepEqual(errors, [], "Managed Superkit native hooks failed");
@@ -129,11 +125,15 @@ try {
129
125
  typeof message === "object" && "customType" in message && message.customType === "omo-ultrawork:directive" ? [message] : []);
130
126
  assert.equal(pointers.length, selected ? 1 : 0, "Only an explicitly selected specialized SUPER invocation may add a workflow directive");
131
127
  if (selected) {
132
- const [command, skill] = selected;
128
+ const [command, legacyId] = selected;
129
+ const skill = canonicalLayout ? command : legacyId;
130
+ const path = skillPath(skill);
133
131
  const content = pointers[0]?.content;
134
- assert(typeof content === "string" && content.startsWith(`<omp-${skill}-pointer>`) && content.endsWith(`</omp-${skill}-pointer>`)
135
- && content.includes(command) && content.includes(skillPath(skill)),
136
- `SUPER command /${command} must point to its installed ${skill} skill`);
132
+ // In the canonical layout the path already contains the command name.
133
+ // Check the invocation separately without prescribing pointer formatting.
134
+ assert(typeof content === "string" && content.startsWith(`<omp-${legacyId}-pointer>`) && content.endsWith(`</omp-${legacyId}-pointer>`)
135
+ && content.includes(path) && content.split(path).some(part => part.includes(command)),
136
+ `SUPER directive must name /${command} and point to its installed ${skill} skill`);
137
137
  }
138
138
  return blocks;
139
139
  };
@@ -190,18 +190,20 @@ try {
190
190
  }
191
191
  assert(resources.getEnabledToolNames().includes("read"), "Native read must remain available");
192
192
  assert(resources.getEnabledToolNames().includes("task"), "Native task must remain available");
193
- const skills = resources.skills.filter(skill => skill.filePath.startsWith(packagePath + "/"));
194
- for (const id of ["ultrawork", ...workflows.map(([, skill]) => skill)]) {
193
+ const skills = resources.skills.filter(skill => skill.filePath.startsWith(packagePath + sep));
194
+ for (const id of canonicalLayout ? [...canonicalSuperkitSkills, ...legacySuperkitSkills] : legacySuperkitSkills) {
195
195
  assert.equal(skills.find(skill => skill.name === id)?.filePath, skillPath(id),
196
196
  `Native Superkit skill discovery must retain skill://${id} and its installed path`);
197
197
  }
198
198
  const read = resources.getToolByName("read");
199
199
  assert(read, "Native read tool must be resolvable");
200
200
  for (const skill of skills) {
201
+ const target = await realpath(skill.filePath);
202
+ assert(target.startsWith(packagePath + sep), `Managed Superkit skill leaves its package: ${skill.name}`);
201
203
  const uri = `skill://${skill.name}:raw`;
202
204
  const output = await read.execute(`managed-ulw-resource-${resourceReads.length}`, { path: uri });
203
205
  const text = output.content.flatMap(block => block.type === "text" ? [block.text] : []).join("\n");
204
- assert.equal(text, await readFile(skill.filePath, "utf8"), `Native resource differs from ${skill.filePath}`);
206
+ assert.equal(text, await readFile(target, "utf8"), `Native resource differs from ${skill.filePath}`);
205
207
  resourceReads.push(uri);
206
208
  }
207
209
  assert.equal(resources.isStreaming, false);