omp-superagent 0.1.11 → 0.1.15

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 (82) hide show
  1. package/DESIGN.md +21 -5
  2. package/README.ko.md +3 -1
  3. package/README.md +3 -1
  4. package/THIRD_PARTY_NOTICES.md +6 -0
  5. package/assets/architecture-dark.svg +4 -4
  6. package/assets/architecture.ko-dark.svg +4 -4
  7. package/assets/architecture.ko.svg +4 -4
  8. package/assets/architecture.mmd +5 -5
  9. package/assets/architecture.svg +4 -4
  10. package/config.example.json +1 -0
  11. package/docs/OPERATIONS.en.md +242 -31
  12. package/docs/OPERATIONS.md +225 -25
  13. package/docs/design/execution.md +161 -43
  14. package/docs/design/messaging.md +45 -9
  15. package/docs/releases/0.1.11.md +4 -2
  16. package/docs/releases/0.1.13.md +13 -0
  17. package/docs/releases/0.1.15.md +13 -0
  18. package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
  19. package/gateway/bin/omp-gateway-darwin-x64 +0 -0
  20. package/gateway/bin/omp-gateway-linux-arm64 +0 -0
  21. package/gateway/bin/omp-gateway-linux-x64 +0 -0
  22. package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
  23. package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
  24. package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
  25. package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
  26. package/package.json +9 -3
  27. package/scripts/prepare-worker-memory.ts +37 -0
  28. package/scripts/upgrade-evidence-files.mjs +100 -0
  29. package/scripts/upgrade-evidence.mjs +192 -0
  30. package/scripts/upgrade-host-wire.mjs +162 -0
  31. package/skills/head/SKILL.md +22 -47
  32. package/skills/head/references/routing.md +11 -12
  33. package/skills/head/references/supervision.md +10 -14
  34. package/skills/lane/SKILL.md +14 -16
  35. package/skills/lane/references/workflow.md +14 -27
  36. package/src/cli.ts +59 -79
  37. package/src/config/config.ts +4 -0
  38. package/src/contracts.ts +34 -27
  39. package/src/cron/cron-jobs.ts +4 -3
  40. package/src/cron/cron-pr-intake.ts +1 -2
  41. package/src/extension.ts +57 -14
  42. package/src/gateway/gateway-client.ts +14 -12
  43. package/src/group/group-runner.ts +3 -2
  44. package/src/group-runner-extension.ts +7 -3
  45. package/src/host-extension.ts +109 -2
  46. package/src/host-sdk-helper.ts +12 -3
  47. package/src/lane/decision-tool.ts +2 -3
  48. package/src/lane/lane-report.ts +8 -30
  49. package/src/lane/lane-rows.ts +1 -1
  50. package/src/lane/workflow.ts +44 -3
  51. package/src/lane-extension.ts +5 -46
  52. package/src/messaging/discord-context.ts +8 -6
  53. package/src/omp/host-protocol.ts +4 -3
  54. package/src/omp/host.ts +24 -7
  55. package/src/omp/managed-super.ts +43 -27
  56. package/src/omp/native-sessions.ts +12 -0
  57. package/src/omp/worker-memory-import.ts +410 -0
  58. package/src/omp/worker-memory-sdk.ts +8 -0
  59. package/src/operator/setup.ts +8 -13
  60. package/src/operator/stop-lane.ts +25 -0
  61. package/src/pr/pr-github-schema.ts +9 -0
  62. package/src/pr/pr-github.ts +6 -2
  63. package/src/pr/pr-intake-automation.ts +11 -8
  64. package/src/pr/pr-intake-fix.ts +2 -5
  65. package/src/pr/pr-intake-review.ts +7 -7
  66. package/src/routing/topic-history.ts +2 -2
  67. package/src/runtime/controller.ts +444 -408
  68. package/src/runtime/head-recovery.ts +7 -7
  69. package/src/runtime/worker-memory.ts +156 -0
  70. package/src/storage/deferred-routing.ts +1 -7
  71. package/src/storage/store.ts +441 -375
  72. package/src/worker/worker-host.ts +3 -2
  73. package/src/worker/worker-ledger.ts +20 -11
  74. package/src/worker/worker-memory-page.ts +83 -0
  75. package/src/worker/worker-memory-proofs.ts +260 -0
  76. package/src/worker/worker-memory-source.ts +305 -0
  77. package/src/worker/worker-memory-storage.ts +130 -0
  78. package/src/worker/worker-profile.ts +2 -0
  79. package/src/worker/worker-repository.ts +92 -7
  80. package/src/worker/worker-request.ts +1 -0
  81. package/src/worker/worker-service.ts +25 -8
  82. package/src/worker/worker-wire.ts +20 -6
@@ -88,31 +88,33 @@ function state(store: Metadata): Purposes {
88
88
  return parsed;
89
89
  }
90
90
 
91
- export function discordPurposeNotes(store: Metadata, route: Route): readonly DiscordPurposeNote[] {
92
- const notes = state(store).notes;
91
+ function notesForRoute(notes: Purposes["notes"], route: Route): readonly DiscordPurposeNote[] {
93
92
  const parent = { ...physicalRoute(route), threadId: null };
94
93
  const keys = [...new Set([physicalRouteKey(parent), physicalRouteKey(route)])];
95
94
  return keys.flatMap(key => notes[key] ? [notes[key]] : []);
96
95
  }
97
96
 
97
+ export function discordPurposeNotes(store: Metadata, route: Route): readonly DiscordPurposeNote[] {
98
+ return notesForRoute(state(store).notes, route);
99
+ }
100
+
98
101
  /** One synchronous metadata write atomically preserves the note and its source-bound receipt. */
99
102
  export function changeDiscordPurpose(store: Metadata, request: DiscordPurposeRequest): readonly DiscordPurposeNote[] {
100
103
  if (request.action === "list") return discordPurposeNotes(store, request.route);
101
104
  const previous = state(store);
102
- const receiptKey = JSON.stringify([request.sourceId, physicalRouteKey(request.route)]);
105
+ const key = physicalRouteKey(request.route);
106
+ const receiptKey = JSON.stringify([request.sourceId, key]);
103
107
  const saved = previous.receipts[receiptKey];
104
108
  if (saved) {
105
109
  if (!isDeepStrictEqual(saved.request, request)) throw new DeliveryError("Discord purpose source identity conflict", "rejected");
106
110
  return saved.result;
107
111
  }
108
112
  const notes = { ...previous.notes };
109
- const key = physicalRouteKey(request.route);
110
113
  switch (request.action) {
111
114
  case "set": notes[key] = { route: physicalRoute(request.route), purpose: request.purpose }; break;
112
115
  case "clear": delete notes[key]; break;
113
116
  }
114
- const parent = { ...physicalRoute(request.route), threadId: null };
115
- const result = [...new Set([physicalRouteKey(parent), key])].flatMap(id => notes[id] ? [notes[id]] : []);
117
+ const result = notesForRoute(notes, request.route);
116
118
  store.setMeta(PURPOSES, JSON.stringify({ notes, receipts: { ...previous.receipts, [receiptKey]: { request, result } } }));
117
119
  return result;
118
120
  }
@@ -31,6 +31,7 @@ export type HostState = RpcSessionState & {
31
31
  readonly loadedSuperkitPath?: string;
32
32
  readonly prReviewPolicy?: { readonly version: 1; readonly cwd: string; readonly modelApi: string };
33
33
  readonly journalCursorVersion?: 1;
34
+ readonly memorySyncVersion?: 1;
34
35
  readonly replyVoiceVersion?: 1 | 2;
35
36
  readonly fastMode?: FastModeState;
36
37
  readonly serviceTier?: Readonly<ServiceTierByFamily>;
@@ -70,7 +71,7 @@ export const serviceGenerationKey = (value: Frame | ServiceUnit) =>
70
71
  const hasValidGeneration = (daemon: Frame | ServiceUnit) =>
71
72
  !("generation" in daemon) || typeof daemon.generation === "string" && daemon.generation.length > 0;
72
73
  const isFrame = (value: unknown): value is Frame => value !== null && typeof value === "object";
73
- const isTerminal = (state: unknown): state is "exited" | "failed" => state === "exited" || state === "failed";
74
+ export const terminalService = (state: unknown): state is "exited" | "failed" => state === "exited" || state === "failed";
74
75
 
75
76
  function launchCompletions(value: unknown): readonly unknown[] | undefined {
76
77
  if (!isFrame(value) || value.type !== "custom_message" || value.customType !== "launch-completion") return;
@@ -98,7 +99,7 @@ export function indexServiceCompletions(entries: readonly unknown[]) {
98
99
  for (const observed of daemons) {
99
100
  // The historical generation lookup could not cross an unreadable row.
100
101
  if (observed === null || observed === undefined) generationEvidenceBlocked = true;
101
- if (!isFrame(observed) || !isTerminal(observed.state)) continue;
102
+ if (!isFrame(observed) || !terminalService(observed.state)) continue;
102
103
  const key = serviceExitKey(observed);
103
104
  if (key === undefined) continue;
104
105
  exact[observed.state].add(key);
@@ -108,7 +109,7 @@ export function indexServiceCompletions(entries: readonly unknown[]) {
108
109
  return {
109
110
  hasGeneration: (key: string) => byGeneration.has(key),
110
111
  hasCompletion: (daemon: Frame | ServiceUnit) => {
111
- if (!isTerminal(daemon.state) || !hasValidGeneration(daemon)) return false;
112
+ if (!terminalService(daemon.state) || !hasValidGeneration(daemon)) return false;
112
113
  const key = serviceExitKey(daemon);
113
114
  return key !== undefined && exact[daemon.state].has(key);
114
115
  },
package/src/omp/host.ts CHANGED
@@ -16,6 +16,7 @@ import { requireHostOwner } from "./host-owner-path";
16
16
  import { inspectInstalledOmp, resolveOmpCommand } from "./installed-omp";
17
17
  import type { DialogResponse, LanePresetSnapshot } from "../contracts";
18
18
  import type { WorkerHostProfile } from "../worker/worker-profile";
19
+ import { WORKER_MEMORY_PROFILE_ENV, type WorkerMemoryBinding } from "../worker/worker-memory-storage";
19
20
  import { activeManagedUlw, managedUlwLaunch, MANAGED_ULW_ENV, MANAGED_ULW_FIXTURE_ENV, MANAGED_ULW_FIXTURE_ROOT_ENV, validateManagedUlwPackage } from "./managed-super";
20
21
 
21
22
  const CONNECT_TIMEOUT_MS = 5_000;
@@ -390,7 +391,7 @@ function selectManagedUlw(options: HostOptions): string {
390
391
  }
391
392
 
392
393
  /** Launch only a new host. Existing endpoints require the caller's explicit adoption decision. */
393
- export async function startHost(options: HostOptions, beforeSessionPrepare?: () => void): Promise<{ pid: number }> {
394
+ export async function startHost(options: HostOptions, beforeSessionPrepare?: (memory?: WorkerMemoryBinding) => void): Promise<{ pid: number }> {
394
395
  try { return await launchHost(options, beforeSessionPrepare); }
395
396
  catch (cause) {
396
397
  // Never read child output into errors: logs can contain credentials or prompt content.
@@ -398,7 +399,7 @@ export async function startHost(options: HostOptions, beforeSessionPrepare?: ()
398
399
  }
399
400
  }
400
401
 
401
- async function launchHost(options: HostOptions, beforeSessionPrepare?: () => void): Promise<{ pid: number }> {
402
+ async function launchHost(options: HostOptions, beforeSessionPrepare?: (memory?: WorkerMemoryBinding) => void): Promise<{ pid: number }> {
402
403
  // Snapshot once before any awaits; an updater may activate a newer revision
403
404
  // during startup, but this Host must load one exact immutable package.
404
405
  if (options.prReviewOnly) {
@@ -461,7 +462,7 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
461
462
  const cleanLaunch = () => cleanup ??= fs.rm(launchDirectory, { recursive: true });
462
463
  try {
463
464
  const initialSettings = options.modelPreset?.preset ?? options.modelSettings;
464
- await fs.writeFile(configPath, JSON.stringify({
465
+ const hostSettings = {
465
466
  ...options.worker?.config,
466
467
  task: { maxConcurrency: options.subagentConcurrency },
467
468
  goal: { continuationModes: [RPC_GOAL_CONTINUATION_MODE] },
@@ -475,7 +476,8 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
475
476
  ...(initialSettings.defaultThinkingLevel !== undefined
476
477
  ? { defaultThinkingLevel: initialSettings.defaultThinkingLevel } : {}),
477
478
  } : options.model ? { modelRoles: { default: options.model } } : {}),
478
- }), { flag: "wx", mode: 0o600 });
479
+ };
480
+ await fs.writeFile(configPath, JSON.stringify(hostSettings), { flag: "wx", mode: 0o600 });
479
481
  log = await fs.open(options.logPath, constants.O_WRONLY | constants.O_APPEND | constants.O_CREAT | constants.O_NOFOLLOW, 0o600);
480
482
  const stat = await log.stat();
481
483
  if (!stat.isFile() || stat.uid !== process.getuid?.() || (stat.mode & 0o077) !== 0) {
@@ -485,6 +487,7 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
485
487
  const { env: _inheritedEnvironment, worker: _workerProfile, ...launchOptions } = options;
486
488
  const helperPath = fileURLToPath(new URL("../host-sdk-helper.ts", import.meta.url));
487
489
  let manifest: Record<string, unknown> | undefined;
490
+ let workerMemory: { binding: WorkerMemoryBinding; env: Record<string, string> } | undefined;
488
491
  const extensionPaths = managedUlwPath === undefined ? [] : [fileURLToPath(new URL("../../", import.meta.url)),
489
492
  managedUlwPath, options.extensionPath,
490
493
  fileURLToPath(new URL("../host-extension.ts", import.meta.url))];
@@ -493,13 +496,26 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
493
496
  // is sent. Preparation and owner startup share the same deadline.
494
497
  const { composition, prepared, deadline } = await managedUlwLaunch({ cwd: options.cwd, managedUlwPath,
495
498
  extensionPaths, configPath, parentConfigPath: process.env.OMP_SUPERAGENT_HOST_CONFIG, commandArgs: options.command.slice(1),
496
- ...(options.worker ? { worker: { extensionPaths: options.worker.extensionPaths } } : {}),
499
+ ...(options.worker ? { worker: { extensionPaths: options.worker.extensionPaths, memory: options.worker.memory } } : {}),
497
500
  launchArgs: managedUlwPath === undefined ? [] : [...options.command.slice(1), ...await buildHostArgs(options, configPath)],
498
501
  env: options.env, bunCommand: [bun, "--no-env-file"] }, {
499
- stderr: log.fd, timeoutMs: START_TIMEOUT_MS, beforeManifest: beforeSessionPrepare,
502
+ stderr: log.fd, timeoutMs: START_TIMEOUT_MS, beforeManifest: () => beforeSessionPrepare?.(workerMemory?.binding),
500
503
  manifest: async composition => {
504
+ if (options.worker?.memory?.previous && !composition.workerMemory && !composition.workerMemoryDormant)
505
+ throw new Error("Worker memory cannot resume without its verified private bank");
506
+ if (composition.workerMemory && options.worker?.memory) {
507
+ const { prepareWorkerMemory } = await import("../worker/worker-memory-storage");
508
+ const privateMemory = prepareWorkerMemory(options.worker.memory, options, composition.workerMemory);
509
+ // Discovery verified the actual native backend and scope with no overlay
510
+ // override. Only redirect the opted-in native bank before journal preparation.
511
+ const overlay = await fs.open(configPath, constants.O_WRONLY | constants.O_NOFOLLOW | constants.O_TRUNC);
512
+ try { await overlay.writeFile(JSON.stringify({ ...hostSettings, ...privateMemory.config })); }
513
+ finally { await overlay.close(); }
514
+ workerMemory = privateMemory;
515
+ }
501
516
  manifest = { options: launchOptions, args: await buildHostArgs(options, configPath, composition), configPath,
502
517
  memoryWriteDir: composition.memoryWriteDir, processBackend, helperPath,
518
+ ...(workerMemory && { workerMemoryProfile: composition.workerMemory?.profile }),
503
519
  nativeSocket: path.join(path.dirname(options.socketPath), `.n-${crypto.randomUUID().slice(0, 8)}.sock`) };
504
520
  return manifest;
505
521
  },
@@ -519,7 +535,8 @@ async function launchHost(options: HostOptions, beforeSessionPrepare?: () => voi
519
535
  inventory: flags.inventory, nativeProfileBinding: flags.nativeProfileBinding, replayableArgvHash: flags.replayableArgvHash }), { flag: "wx", mode: 0o600 });
520
536
  if (performance.now() >= deadline) throw new Error("Native Host startup timed out before launch");
521
537
  child = spawn(hostOwnerExecutable, [manifestPath], {
522
- cwd: options.cwd, env: options.env,
538
+ cwd: options.cwd, env: workerMemory ? { ...options.env, ...workerMemory.env,
539
+ [WORKER_MEMORY_PROFILE_ENV]: JSON.stringify(flags.workerMemoryProfileBinding ?? null) } : options.env,
523
540
  detached: true, stdio: ["ignore", log.fd, log.fd], shell: false,
524
541
  });
525
542
  child.once("error", error => { failure = error; });
@@ -4,6 +4,7 @@ import { chmod, link, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rename
4
4
  import { dirname, isAbsolute, join, resolve, sep } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import type { WorkerHostProfile } from "../worker/worker-profile";
7
+ import type { WorkerMemoryPlan } from "../worker/worker-memory-storage";
7
8
  import type { NativeProfile, NativeProfileBinding, NativeProfilePaths } from "./native-sessions";
8
9
 
9
10
  const projectRoot = fileURLToPath(new URL("../../", import.meta.url));
@@ -200,7 +201,7 @@ export type ManagedUlwLaunchInput = {
200
201
  commandArgs: string[];
201
202
  /** Exact native OMP argv, including the original command's flags and generated Host args; no executable prefix. */
202
203
  launchArgs: string[];
203
- worker?: Pick<WorkerHostProfile, "extensionPaths">;
204
+ worker?: Pick<WorkerHostProfile, "extensionPaths" | "memory">;
204
205
  expectedNativeProfile?: NativeProfile;
205
206
  };
206
207
  type ManagedUlwLaunchOptions = Omit<ManagedUlwLaunchInput, "managedUlwPath"> & {
@@ -216,6 +217,8 @@ export type ManagedUlwLaunchComposition = {
216
217
  nativeProfile?: NativeProfile;
217
218
  nativeProfilePaths?: NativeProfilePaths;
218
219
  nativeDotenvPaths?: string[];
220
+ workerMemory?: WorkerMemoryPlan;
221
+ workerMemoryDormant?: true;
219
222
  };
220
223
 
221
224
  const LAUNCH_DISCOVERY_TIMEOUT_MS = 30_000;
@@ -345,7 +348,9 @@ export async function managedUlwLaunchComposition(input: ManagedUlwLaunchInput):
345
348
  return input.worker ? workerLaunchComposition({ ...input, worker: input.worker }) : launchComposition(input);
346
349
  }
347
350
 
348
- async function workerLaunchComposition(input: ManagedUlwLaunchInput & { worker: Pick<WorkerHostProfile, "extensionPaths"> }): Promise<ManagedUlwLaunchComposition> {
351
+ async function workerLaunchComposition(input: ManagedUlwLaunchInput & {
352
+ worker: Pick<WorkerHostProfile, "extensionPaths" | "memory">;
353
+ }): Promise<ManagedUlwLaunchComposition> {
349
354
  const { assertWorkerWorkspaceStartup } = await import("../worker/worker-profile");
350
355
  const { homedir } = await import("node:os");
351
356
  assertWorkerWorkspaceStartup(input.cwd, homedir());
@@ -358,11 +363,27 @@ async function workerLaunchComposition(input: ManagedUlwLaunchInput & { worker:
358
363
  const { effectiveManagedMemory, memoryBlockReason } = await import("./managed-memory");
359
364
  const memory = await effectiveManagedMemory(settings, null);
360
365
  if (memory.status !== "enabled") throw new Error(memoryBlockReason(memory));
366
+ let workerMemory: WorkerMemoryPlan | undefined;
367
+ if (input.worker.memory && memory.backend === "mnemopi") {
368
+ const { cfgMnemopiBank, cfgMnemopiScoping } = await import("@oh-my-pi/pi-coding-agent/mnemopi/settings");
369
+ const { computeMnemopiBankScope } = await import("@oh-my-pi/pi-coding-agent/mnemopi/config");
370
+ const configured = settings.rawValue(cfgMnemopiScoping);
371
+ if ((configured === undefined || cfgMnemopiScoping.accepts(configured)) && cfgMnemopiScoping.get(settings) === "per-project") {
372
+ const { nativeMemoryProjectCwd, resolveNativeProfile, sdkNativeProfilePaths } = await import("./native-sessions");
373
+ workerMemory = {
374
+ bank: computeMnemopiBankScope(cfgMnemopiBank.get(settings), nativeMemoryProjectCwd(input.cwd), "per-project").retainBank,
375
+ profile: resolveNativeProfile(sdkNativeProfilePaths(parsed.launchAgentDir)),
376
+ };
377
+ }
378
+ }
379
+ if (input.worker.memory?.previous && memory.backend === "mnemopi" && !workerMemory)
380
+ throw new Error("Worker memory cannot resume with a different native backend or bank scope");
361
381
  // Do not enumerate ambient packages/hooks for a worker. The operator pins
362
382
  // opt-in modules as files, while managed packages retain their own resources.
363
383
  const managed = validateManagedUlwPackage(input.managedUlwPath);
364
384
  const extensionPaths = [...new Set([...input.extensionPaths, managed, ...input.worker.extensionPaths])];
365
- return { extensionPaths, noExtensions: true, memoryWriteDir: null };
385
+ return { extensionPaths, noExtensions: true, memoryWriteDir: null, workerMemory,
386
+ ...(input.worker.memory?.previous && memory.backend !== "mnemopi" && { workerMemoryDormant: true }) };
366
387
  }
367
388
 
368
389
  async function launchComposition(input: ManagedUlwLaunchInput): Promise<ManagedUlwLaunchComposition> {
@@ -587,20 +608,26 @@ export async function updateManagedUlw(options: ManagedUlwOptions = {}): Promise
587
608
  preparedRepository = provenance.repository;
588
609
  } catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
589
610
  const provenance: ActiveRevision = { revision: upstreamRevision, repository: manifest.repository, branch, preparedAt: new Date().toISOString() };
590
- if (!preparedRepository) {
591
- stage = await mkdtemp(join(root, ".stage-"));
592
- const source = join(stage, "source");
593
- const distribution = join(stage, "distribution");
594
- const packagePath = join(distribution, "package");
595
- await mkdir(packagePath, { recursive: true, mode: 0o700 });
611
+ stage = await mkdtemp(join(root, ".stage-"));
612
+ const source = join(stage, preparedRepository ? "ancestry" : "source");
613
+ const distribution = join(stage, "distribution");
614
+ const packagePath = join(preparedRepository ? revisionRoot : distribution, "package");
615
+ if (!preparedRepository) await mkdir(packagePath, { recursive: true, mode: 0o700 });
616
+ // A previously prepared revision may have been active before a remote
617
+ // rewind. Do not bypass ancestry merely because its files already exist.
618
+ if (!preparedRepository || active) {
596
619
  await git(["clone", "--no-checkout", "--no-local", manifest.repository, source]);
597
620
  await git(["fetch", "origin", upstreamRevision], source);
621
+ }
622
+ if (!preparedRepository) {
598
623
  await git(["checkout", "--detach", upstreamRevision], source);
599
624
  if (await git(["rev-parse", "HEAD"], source) !== upstreamRevision) throw new Error("ULW checkout revision changed while staging");
600
- if (active) {
601
- try { await git(["merge-base", "--is-ancestor", active.revision, upstreamRevision], source); }
602
- catch { throw new Error("ULW upstream update is not a provable fast-forward; explicit operator reconciliation required"); }
603
- }
625
+ }
626
+ if (active) {
627
+ try { await git(["merge-base", "--is-ancestor", active.revision, upstreamRevision], source); }
628
+ catch { throw new Error("ULW upstream update is not a provable fast-forward; explicit operator reconciliation required"); }
629
+ }
630
+ if (!preparedRepository) {
604
631
  await git(["submodule", "update", "--init", "--recursive", "--depth=1"], source);
605
632
  await checkLinks(source);
606
633
  // Export tracked runtime/resources, not .git, dev node_modules, or the
@@ -622,25 +649,14 @@ export async function updateManagedUlw(options: ManagedUlwOptions = {}): Promise
622
649
  }
623
650
  validateManagedUlwPackage(packagePath);
624
651
  await checkLinks(packagePath);
625
- await probe(packagePath, stage, manifest);
652
+ }
653
+ await probe(packagePath, stage, manifest);
654
+ if (!preparedRepository) {
626
655
  await writeFile(join(distribution, "provenance.json"), JSON.stringify(provenance, null, 2) + "\n", { mode: 0o444 });
627
656
  await immutableTree(packagePath);
628
657
  await mkdir(join(root, "revisions"), { recursive: true, mode: 0o700 });
629
658
  await rename(distribution, revisionRoot);
630
659
  }
631
- if (preparedRepository) {
632
- // A previously prepared revision may have been active before a remote
633
- // rewind. Do not bypass ancestry merely because its files already exist.
634
- stage = await mkdtemp(join(root, ".stage-"));
635
- if (active) {
636
- const source = join(stage, "ancestry");
637
- await git(["clone", "--no-checkout", "--no-local", manifest.repository, source]);
638
- await git(["fetch", "origin", upstreamRevision], source);
639
- try { await git(["merge-base", "--is-ancestor", active.revision, upstreamRevision], source); }
640
- catch { throw new Error("ULW upstream update is not a provable fast-forward; explicit operator reconciliation required"); }
641
- }
642
- await probe(join(revisionRoot, "package"), stage, manifest);
643
- }
644
660
  nextActive = { ...provenance, repository: preparedRepository ?? provenance.repository };
645
661
  }
646
662
  // Finish fallible staging cleanup/status publication before committing the
@@ -37,6 +37,18 @@ function isMissing(error: unknown): boolean {
37
37
  return error instanceof Error && "code" in error && error.code === "ENOENT";
38
38
  }
39
39
 
40
+ /** Match stock getProjectDir's Darwin spelling for bank hashing, never an arbitrary alias. */
41
+ export function nativeMemoryProjectCwd(canonical: string): string {
42
+ if (!isAbsolute(canonical) || realpathSync(canonical) !== canonical)
43
+ throw new Error("Worker memory requires a physically canonical checkout");
44
+ if (process.platform === "darwin" && canonical.startsWith("/private/")) {
45
+ const alias = canonical.slice("/private".length);
46
+ try { if (realpathSync(alias) === canonical) return alias; }
47
+ catch (error) { if (!isMissing(error)) throw error; }
48
+ }
49
+ return canonical;
50
+ }
51
+
40
52
  /** Resolve through existing ancestors without creating directories or accepting dangling symlinks. */
41
53
  function canonicalDirectory(path: string): string {
42
54
  if (!isAbsolute(path)) throw new Error("Native profile paths must be absolute");