@cortexkit/opencode-magic-context 0.49.87 → 0.49.90

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 (104) hide show
  1. package/dist/{announcement-fnyxaahs.js → announcement-4ynkaf0d.js} +2 -2
  2. package/dist/auto-search-worker.js +3 -3
  3. package/dist/chunk-embedding-write-worker.js +5 -5
  4. package/dist/{context-gnk68pyy.js → context-cdds0gjj.js} +219 -41
  5. package/dist/{derive-budgets-90869322.js → derive-budgets-hzzq71rm.js} +2 -2
  6. package/dist/{embedding-backfill-9khxv6a9.js → embedding-backfill-qjkaee9s.js} +6 -6
  7. package/dist/embedding-worker.js +2 -2
  8. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  9. package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
  10. package/dist/hooks/magic-context/compartment-runner-recomp-carry.d.ts +4 -0
  11. package/dist/hooks/magic-context/compartment-runner-recomp-carry.d.ts.map +1 -0
  12. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts +8 -2
  13. package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
  14. package/dist/hooks/magic-context/history-boundary-repair.d.ts +2 -0
  15. package/dist/hooks/magic-context/history-boundary-repair.d.ts.map +1 -1
  16. package/dist/hooks/magic-context/recomp-orchestrator.d.ts +3 -5
  17. package/dist/hooks/magic-context/recomp-orchestrator.d.ts.map +1 -1
  18. package/dist/{index-watde7a1.js → index-2pdgy88n.js} +3 -3
  19. package/dist/{index-c1s40xmj.js → index-39rzef89.js} +7 -5
  20. package/dist/{index-c5tmzym6.js → index-5df2fw5b.js} +108 -13
  21. package/dist/{index-7svecf3m.js → index-5pgyqgmx.js} +1 -1
  22. package/dist/{index-k50xhjw1.js → index-60x5d68t.js} +1 -1
  23. package/dist/{index-jka4y6mv.js → index-61knrt52.js} +1 -1
  24. package/dist/{index-74sh122g.js → index-9d3qgwq0.js} +1 -1
  25. package/dist/{index-2kf73btc.js → index-cr483vx6.js} +1 -1
  26. package/dist/{index-5nmqgvz2.js → index-dk3hy2a2.js} +6 -6
  27. package/dist/{index-awyqqnd8.js → index-g0mb2kb4.js} +6 -6
  28. package/dist/{index-kmrv1fw3.js → index-h9hybzr5.js} +2 -2
  29. package/dist/{index-vyfrgwhk.js → index-jzfsnbmm.js} +2 -2
  30. package/dist/{index-rvf1726x.js → index-mrjat4eq.js} +75 -12
  31. package/dist/{index-b364vr04.js → index-n1ty0vd3.js} +22 -22
  32. package/dist/{index-csztadkj.js → index-q7msfgwz.js} +272 -101
  33. package/dist/{index-pmcvg3k1.js → index-qfcjrnpe.js} +6 -5
  34. package/dist/{index-3dtzyred.js → index-r4y0dczp.js} +1 -1
  35. package/dist/{index-bxrfq3mv.js → index-tt0vs4x5.js} +1 -1
  36. package/dist/{index-3x4qvp29.js → index-w51n3576.js} +1 -1
  37. package/dist/{index-3jgzd7nz.js → index-wmb2mcdw.js} +3 -3
  38. package/dist/{index-zmqx48vt.js → index-xsqw8kbd.js} +1 -1
  39. package/dist/{index-hdyfvdag.js → index-zxhev8ze.js} +1 -1
  40. package/dist/index.js +26 -26
  41. package/dist/migration-worker.js +4 -4
  42. package/dist/{project-embedding-registry-8t0gwf59.js → project-embedding-registry-m3fp1pa4.js} +5 -5
  43. package/dist/raw-ordinal-warmup-worker.js +2 -2
  44. package/dist/{recomp-orchestrator-2ztmtxt2.js → recomp-orchestrator-dgyb394j.js} +14 -14
  45. package/dist/{render-d6q6h9hy.js → render-d014e603.js} +6 -6
  46. package/dist/{search-d5aajhs3.js → search-9gceftb9.js} +11 -11
  47. package/dist/{search-archive-g96jn6p0.js → search-archive-gybn6q7s.js} +2 -2
  48. package/dist/shared/recomp-outcome.d.ts +4 -0
  49. package/dist/shared/recomp-outcome.d.ts.map +1 -0
  50. package/dist/shared/storage-permissions.d.ts +16 -2
  51. package/dist/shared/storage-permissions.d.ts.map +1 -1
  52. package/dist/shared/user-facing-codes.d.ts +4 -1
  53. package/dist/shared/user-facing-codes.d.ts.map +1 -1
  54. package/dist/{transform-postprocess-phase-b2yjw8by.js → transform-postprocess-phase-34k1zwsy.js} +15 -15
  55. package/dist/v2/auto-search-worker.js +3 -3
  56. package/dist/v2/chunk-embedding-write-worker.js +5 -5
  57. package/dist/v2/{context-s86114yy.js → context-satgm752.js} +218 -41
  58. package/dist/v2/{derive-budgets-ecjy1aqh.js → derive-budgets-hr4qqrnv.js} +3 -3
  59. package/dist/v2/{embedding-backfill-tazkbpyg.js → embedding-backfill-0ar1bm97.js} +6 -6
  60. package/dist/v2/embedding-worker.js +2 -2
  61. package/dist/v2/fold/native-replay.d.ts +11 -2
  62. package/dist/v2/fold/native-replay.d.ts.map +1 -1
  63. package/dist/v2/hooks/context.d.ts.map +1 -1
  64. package/dist/v2/hooks/revert-message-state.d.ts +19 -1
  65. package/dist/v2/hooks/revert-message-state.d.ts.map +1 -1
  66. package/dist/v2/migration-worker.js +4 -4
  67. package/dist/v2/{project-embedding-registry-ah3gsg48.js → project-embedding-registry-gx2waee8.js} +5 -5
  68. package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
  69. package/dist/v2/{recomp-orchestrator-kc62xgb9.js → recomp-orchestrator-wq7gbkqa.js} +15 -15
  70. package/dist/v2/{render-j05per51.js → render-2dan17xc.js} +6 -6
  71. package/dist/v2/{search-archive-b4ptw02k.js → search-archive-89hdy0a2.js} +2 -2
  72. package/dist/v2/{search-kg31ad2s.js → search-nyqykx7q.js} +10 -10
  73. package/dist/v2/{server-ct0gs8fc.js → server-09h2vyvs.js} +2 -2
  74. package/dist/v2/{server-r2es6zt7.js → server-0tv6kytx.js} +108 -13
  75. package/dist/v2/{server-rz4snd3x.js → server-1rrmxhd1.js} +1 -1
  76. package/dist/v2/{server-xa8fefhw.js → server-96nm9vk4.js} +1 -1
  77. package/dist/v2/{server-2p0qayr1.js → server-a85j3kam.js} +1 -1
  78. package/dist/v2/{server-gwhj0362.js → server-add0j5n3.js} +7 -5
  79. package/dist/v2/{server-ff5wcfy4.js → server-b0a9h3ds.js} +2 -2
  80. package/dist/v2/{server-xn7zqs4j.js → server-dgjqvpgd.js} +3 -3
  81. package/dist/v2/{server-2r9btf0g.js → server-dtcwkdqj.js} +274 -103
  82. package/dist/v2/{server-axdmkvd5.js → server-f7tzvmzs.js} +1 -1
  83. package/dist/v2/{server-yh2z4gg2.js → server-fb5hvvfc.js} +75 -12
  84. package/dist/v2/{server-pbp58w5x.js → server-fn4ky6mn.js} +1 -1
  85. package/dist/v2/{server-3p6b0qya.js → server-gqkdfdvw.js} +1 -1
  86. package/dist/v2/{server-cwtehwbb.js → server-j4jjtdc5.js} +1 -1
  87. package/dist/v2/{server-b93f0bqh.js → server-pjk9spbf.js} +1 -1
  88. package/dist/v2/{server-gqrw0br5.js → server-ta4h0fch.js} +6 -6
  89. package/dist/v2/{server-e2k9mt86.js → server-tj65pgvg.js} +1 -1
  90. package/dist/v2/{server-6vnbz81n.js → server-vy0beygw.js} +1 -1
  91. package/dist/v2/server.js +5 -5
  92. package/dist/v2/{v2-archive-reader-2ayz16s4.js → v2-archive-reader-gh1jghf7.js} +1 -1
  93. package/dist/v2/{wrapup-orchestrator-e20sjbdz.js → wrapup-orchestrator-2h7ayss9.js} +15 -15
  94. package/dist/{v2-archive-reader-x39mzvwn.js → v2-archive-reader-8158kyfd.js} +1 -1
  95. package/dist/{wrapup-orchestrator-h3s905vs.js → wrapup-orchestrator-ct59br0c.js} +15 -15
  96. package/package.json +1 -1
  97. package/src/shared/recomp-outcome.ts +8 -0
  98. package/src/shared/storage-permissions-startup.test.ts +296 -6
  99. package/src/shared/storage-permissions.ts +143 -18
  100. package/src/shared/user-facing-codes.ts +5 -2
  101. package/src/tui/dialogs/status-dialog.tsx +3 -0
  102. package/src/tui/slots/sidebar-content.tsx +6 -2
  103. package/src/tui-compiled/dialogs/status-dialog.tsx +12 -0
  104. package/src/tui-compiled/slots/sidebar-content.tsx +7 -2
@@ -1,6 +1,7 @@
1
1
  import { afterEach, describe, expect, it, spyOn } from "bun:test";
2
2
  import * as fs from "node:fs";
3
- import { join } from "node:path";
3
+ import * as os from "node:os";
4
+ import * as path from "node:path";
4
5
  import { withStorageFileMutex } from "./storage-file-mutex";
5
6
  import {
6
7
  __resetStoragePrivatePermissionEnforcementForTests,
@@ -13,11 +14,46 @@ import { cleanupTestTempDir, createTestTempDir } from "./test-temp-dir";
13
14
 
14
15
  const roots: string[] = [];
15
16
  const markerName = ".storage-permissions-v1";
17
+ const { join } = path;
18
+
19
+ function linkedFixture(name: string): { parent: string; root: string; alias: string } {
20
+ const { dir } = createTestTempDir(`mc-storage-link-${name}-`);
21
+ roots.push(dir);
22
+ const parent = fs.realpathSync(dir);
23
+ const root = join(parent, "storage");
24
+ const alias = join(parent, "alias");
25
+ fs.mkdirSync(root);
26
+ fs.chmodSync(root, 0o755);
27
+ fs.symlinkSync(root, alias);
28
+ return { parent, root, alias };
29
+ }
30
+
31
+ function mode(file: string): number {
32
+ return fs.lstatSync(file).mode & 0o777;
33
+ }
34
+
35
+ function writeLooseOwnedTree(root: string): void {
36
+ const models = join(root, "models");
37
+ fs.mkdirSync(models);
38
+ fs.writeFileSync(join(root, "context.db"), "");
39
+ fs.writeFileSync(join(models, "weights"), "cache fixture");
40
+ for (const [file, permissions] of [
41
+ [root, 0o755],
42
+ [models, 0o755],
43
+ [join(root, "context.db"), 0o644],
44
+ [join(models, "weights"), 0o755],
45
+ ] as const)
46
+ fs.chmodSync(file, permissions);
47
+ }
48
+
49
+ function ownedTreeModes(root: string): number[] {
50
+ return [".", "context.db", "models", "models/weights"].map((name) => mode(join(root, name)));
51
+ }
16
52
 
17
53
  function fixture(): string {
18
54
  const { dir: parent } = createTestTempDir("mc-storage-startup-");
19
55
  roots.push(parent);
20
- const root = join(parent, "storage");
56
+ const root = join(fs.realpathSync(parent), "storage");
21
57
  fs.mkdirSync(root, { mode: 0o700 });
22
58
  fs.mkdirSync(join(root, "lkg-recovery-fences"), { mode: 0o700 });
23
59
  for (let i = 0; i < 2000; i++) {
@@ -203,14 +239,248 @@ describe.skipIf(process.platform === "win32")("startup permission certificate",
203
239
  expect(fs.lstatSync(loose).mode & 0o777).toBe(0o600);
204
240
  });
205
241
 
206
- it("does not certify a storage root that is a symbolic link", () => {
242
+ it("tightens and certifies the target of a linked storage root", () => {
243
+ const root = fixture();
244
+ const alias = join(root, "..", "alias");
245
+ fs.symlinkSync("storage", alias);
246
+ const before = fs.lstatSync(alias);
247
+ const db = join(root, "context.db");
248
+ const fence = join(root, "lkg-recovery-fences", "5.json");
249
+ fs.chmodSync(root, 0o755);
250
+ fs.chmodSync(db, 0o644);
251
+ fs.chmodSync(fence, 0o644);
252
+
253
+ tightenStorageTreeSync(alias);
254
+
255
+ expect(fs.lstatSync(root).mode & 0o777).toBe(0o700);
256
+ expect(fs.lstatSync(db).mode & 0o777).toBe(0o600);
257
+ expect(fs.lstatSync(fence).mode & 0o777).toBe(0o600);
258
+ expect(fs.readFileSync(join(root, markerName), "utf8")).toBe("1\n");
259
+ expect(fs.lstatSync(join(root, markerName)).mode & 0o777).toBe(0o600);
260
+ const after = fs.lstatSync(alias);
261
+ expect(after.isSymbolicLink()).toBe(true);
262
+ expect(after.ino).toBe(before.ino);
263
+ expect(after.mode).toBe(before.mode);
264
+ expect(fs.readlinkSync(alias)).toBe("storage");
265
+ });
266
+
267
+ it("uses the bounded check on the target of a certified root link chain", () => {
268
+ const root = fixture();
269
+ const alias = join(root, "..", "alias");
270
+ const intermediate = join(root, "..", "intermediate");
271
+ fs.symlinkSync(intermediate, alias);
272
+ fs.symlinkSync(root, intermediate);
273
+ expect(tightenStorageTreeSync(alias).failures).toBe(0);
274
+
275
+ const lstat = spyOn(fs, "lstatSync");
276
+ try {
277
+ expect(tightenStorageTreeSync(alias, join(alias, "context.db")).failures).toBe(0);
278
+ expect(lstat.mock.calls.map(([path]) => path)).toContain(join(root, "context.db"));
279
+ expect(lstat.mock.calls.length).toBeLessThanOrEqual(10);
280
+ } finally {
281
+ lstat.mockRestore();
282
+ }
283
+ });
284
+
285
+ it("retarget between starts: new target fully walked, old untouched", () => {
286
+ const { root, alias } = linkedFixture("retarget-between");
287
+ const { root: next } = linkedFixture("retarget-next");
288
+ writeLooseOwnedTree(root);
289
+ writeLooseOwnedTree(next);
290
+ expect(tightenStorageTreeSync(alias).failures).toBe(0);
291
+ const before = ownedTreeModes(root);
292
+ const oldMarker = fs.lstatSync(join(root, markerName));
293
+ fs.unlinkSync(alias);
294
+ fs.symlinkSync(next, alias);
295
+
296
+ expect(tightenStorageTreeSync(alias).failures).toBe(0);
297
+ expect(ownedTreeModes(next)).toEqual([0o700, 0o600, 0o700, 0o600]);
298
+ expect(fs.existsSync(join(next, markerName))).toBe(true);
299
+ expect(ownedTreeModes(root)).toEqual(before);
300
+ expect(fs.lstatSync(join(root, markerName))).toMatchObject({
301
+ ino: oldMarker.ino,
302
+ mtimeMs: oldMarker.mtimeMs,
303
+ });
304
+ });
305
+
306
+ it("retarget during the walk: marker and every chmod stay in the first target", () => {
307
+ const { root, alias } = linkedFixture("retarget-during");
308
+ const { root: next } = linkedFixture("retarget-during-next");
309
+ writeLooseOwnedTree(root);
310
+ writeLooseOwnedTree(next);
311
+ const before = ownedTreeModes(next);
312
+ const realReaddir = fs.readdirSync;
313
+ let swapped = false;
314
+ const readdir = spyOn(fs, "readdirSync").mockImplementation((...args) => {
315
+ // The top-level eligibility probe is read-only. Redirect from inside the walk.
316
+ if (!swapped && args[0] === join(root, "models")) {
317
+ swapped = true;
318
+ fs.unlinkSync(alias);
319
+ fs.symlinkSync(next, alias);
320
+ }
321
+ return realReaddir(...args);
322
+ });
323
+ const chmod = spyOn(fs, "chmodSync");
324
+ try {
325
+ expect(tightenStorageTreeSync(alias, join(alias, "context.db")).failures).toBe(0);
326
+ expect(swapped).toBe(true);
327
+ expect(chmod.mock.calls.length).toBeGreaterThan(1);
328
+ expect(
329
+ chmod.mock.calls.every(
330
+ ([file]) => file === root || String(file).startsWith(`${root}/`),
331
+ ),
332
+ ).toBe(true);
333
+ } finally {
334
+ readdir.mockRestore();
335
+ chmod.mockRestore();
336
+ }
337
+ expect(fs.existsSync(join(root, markerName))).toBe(true);
338
+ expect(fs.existsSync(join(next, markerName))).toBe(false);
339
+ expect(ownedTreeModes(next)).toEqual(before);
340
+ });
341
+
342
+ it("does not follow an interior link to a loose directory outside storage", () => {
207
343
  const root = fixture();
208
- const alias = join(root, "alias");
344
+ const outside = join(root, "..", "outside");
345
+ const outsideFile = join(outside, "private.json");
346
+ const link = join(root, "models");
347
+ fs.mkdirSync(outside);
348
+ fs.writeFileSync(outsideFile, "{}");
349
+ fs.chmodSync(outside, 0o755);
350
+ fs.chmodSync(outsideFile, 0o644);
351
+ fs.symlinkSync(outside, link);
352
+ const linkMode = fs.lstatSync(link).mode;
353
+
354
+ for (let start = 0; start < 2; start++) {
355
+ expect(tightenStorageTreeSync(root).failures).toBe(0);
356
+ expect(fs.lstatSync(link).mode).toBe(linkMode);
357
+ expect(fs.readlinkSync(link)).toBe(outside);
358
+ expect(fs.lstatSync(outside).mode & 0o777).toBe(0o755);
359
+ expect(fs.lstatSync(outsideFile).mode & 0o777).toBe(0o644);
360
+ }
361
+ });
362
+
363
+ it("does not tighten through a root link with enforcement off", () => {
364
+ const root = fixture();
365
+ const alias = join(root, "..", "alias");
366
+ const file = join(root, "context.db");
209
367
  fs.symlinkSync(root, alias);
210
- expect(tightenStorageTreeSync(alias).failures).toBe(1);
368
+ fs.chmodSync(root, 0o755);
369
+ fs.chmodSync(file, 0o644);
370
+ fs.writeFileSync(join(root, markerName), "1\n", { mode: 0o600 });
371
+ setStoragePrivatePermissionEnforcement(false);
372
+
373
+ expect(tightenStorageTreeSync(alias)).toMatchObject({ tightened: 0, failures: 0 });
374
+ expect(fs.lstatSync(root).mode & 0o777).toBe(0o755);
375
+ expect(fs.lstatSync(file).mode & 0o777).toBe(0o644);
211
376
  expect(fs.existsSync(join(root, markerName))).toBe(false);
212
377
  });
213
378
 
379
+ it("does not tighten a linked filesystem root", () => {
380
+ const { root, alias } = linkedFixture("filesystem-root");
381
+ const realDirname = path.dirname;
382
+ // Model the root predicate without pointing the link at a real filesystem root.
383
+ const dirname = spyOn(path, "dirname").mockImplementation((file) =>
384
+ file === root ? root : realDirname(file),
385
+ );
386
+ try {
387
+ expect(tightenStorageTreeSync(alias)).toMatchObject({ tightened: 0, failures: 0 });
388
+ } finally {
389
+ dirname.mockRestore();
390
+ }
391
+ expect(mode(root)).toBe(0o755);
392
+ expect(fs.existsSync(join(root, markerName))).toBe(false);
393
+ });
394
+
395
+ it("does not tighten a linked target that resolves to the user's home folder", () => {
396
+ const { parent, root, alias } = linkedFixture("home");
397
+ const homePath = join(parent, "home-link");
398
+ fs.symlinkSync(root, homePath);
399
+ const home = spyOn(os, "homedir").mockReturnValue(homePath);
400
+ try {
401
+ expect(tightenStorageTreeSync(alias)).toMatchObject({ tightened: 0, failures: 0 });
402
+ } finally {
403
+ home.mockRestore();
404
+ }
405
+ expect(mode(root)).toBe(0o755);
406
+ expect(fs.existsSync(join(root, markerName))).toBe(false);
407
+ });
408
+
409
+ it("does not tighten a linked mount point on a different device from its parent", () => {
410
+ const { parent, root, alias } = linkedFixture("mount");
411
+ const realLstat = fs.lstatSync;
412
+ const lstat = spyOn(fs, "lstatSync").mockImplementation((...args) => {
413
+ const stat = realLstat(...args);
414
+ if (args[0] === parent) stat.dev = realLstat(root).dev + 1;
415
+ return stat;
416
+ });
417
+ try {
418
+ expect(tightenStorageTreeSync(alias)).toMatchObject({ tightened: 0, failures: 0 });
419
+ } finally {
420
+ lstat.mockRestore();
421
+ }
422
+ expect(mode(root)).toBe(0o755);
423
+ expect(fs.existsSync(join(root, markerName))).toBe(false);
424
+ });
425
+
426
+ it("leaves a linked target with only foreign entries alone", () => {
427
+ const { root, alias } = linkedFixture("foreign-only");
428
+ const foreign = join(root, "other-executable");
429
+ fs.writeFileSync(foreign, "other");
430
+ fs.chmodSync(foreign, 0o755);
431
+
432
+ expect(tightenStorageTreeSync(alias)).toMatchObject({ tightened: 0, failures: 0 });
433
+ expect(mode(foreign)).toBe(0o755);
434
+ expect(mode(root)).toBe(0o755);
435
+ expect(fs.existsSync(join(root, markerName))).toBe(false);
436
+ });
437
+
438
+ it("rechecks a linked target even with a marker and rejects lookalike entries", () => {
439
+ const { root, alias } = linkedFixture("foreign-with-marker");
440
+ writeLooseOwnedTree(root);
441
+ expect(tightenStorageTreeSync(alias).failures).toBe(0);
442
+ const marker = join(root, markerName);
443
+ const oldMarker = fs.lstatSync(marker);
444
+ const foreign = [
445
+ "context.db-wal-unrelated",
446
+ "context.db.corrupt-backup-20260811T123656789Z-not-a-backup",
447
+ "last_announced_version.123.not-hex-temp.tmp",
448
+ "identity-merge-backup-too-long",
449
+ "opencode.db",
450
+ "run-index.db",
451
+ ];
452
+ for (const name of foreign) fs.writeFileSync(join(root, name), "unrelated");
453
+ fs.chmodSync(root, 0o755);
454
+
455
+ expect(tightenStorageTreeSync(alias)).toMatchObject({
456
+ tightened: 0,
457
+ failures: 0,
458
+ rootLink: { skipped: foreign.length },
459
+ });
460
+ expect(mode(root)).toBe(0o755);
461
+ expect(fs.lstatSync(marker)).toMatchObject({
462
+ ino: oldMarker.ino,
463
+ mtimeMs: oldMarker.mtimeMs,
464
+ });
465
+ });
466
+
467
+ it("tightens a linked target containing only Finder's .DS_Store", () => {
468
+ const { root, alias } = linkedFixture("finder");
469
+ fs.writeFileSync(join(root, ".DS_Store"), "Finder fixture");
470
+ fs.chmodSync(join(root, ".DS_Store"), 0o600);
471
+ expect(tightenStorageTreeSync(alias)).toMatchObject({ tightened: 1, failures: 0 });
472
+ expect(mode(root)).toBe(0o700);
473
+ expect(fs.existsSync(join(root, markerName))).toBe(true);
474
+ });
475
+
476
+ it("does not count unresolved linked roots when enforcement is off", () => {
477
+ const { parent, alias } = linkedFixture("broken-off");
478
+ fs.unlinkSync(alias);
479
+ fs.symlinkSync(join(parent, "missing"), alias);
480
+ setStoragePrivatePermissionEnforcement(false);
481
+ expect(tightenStorageTreeSync(alias)).toEqual({ tightened: 0, failures: 0 });
482
+ });
483
+
214
484
  for (const target of ["context.db", ".", "context.db-wal", "context.db-shm"]) {
215
485
  it(`invalidates after repairing ${target}, then walks fully on the next open`, () => {
216
486
  const root = fixture();
@@ -239,7 +509,10 @@ describe.skipIf(process.platform === "win32")("startup permission certificate",
239
509
  const root = fixture();
240
510
  const marker = join(root, markerName);
241
511
  if (kind === "symlink") fs.symlinkSync("context.db", marker);
242
- else fs.writeFileSync(marker, "1\n", { mode: 0o644 });
512
+ else {
513
+ fs.writeFileSync(marker, "1\n", { mode: 0o600 });
514
+ fs.chmodSync(marker, 0o644);
515
+ }
243
516
  const lstat = spyOn(fs, "lstatSync");
244
517
  try {
245
518
  tightenStorageTreeSync(root);
@@ -403,6 +676,23 @@ describe.skipIf(process.platform === "win32")("startup permission certificate",
403
676
  expect(fs.existsSync(decoy)).toBe(true);
404
677
  });
405
678
 
679
+ it("stops marker invalidation at the linked storage boundary", () => {
680
+ const root = fixture();
681
+ const alias = join(root, "..", "alias");
682
+ const decoy = join(root, "..", markerName);
683
+ fs.symlinkSync(root, alias);
684
+ expect(tightenStorageTreeSync(alias).failures).toBe(0);
685
+ expect(fs.existsSync(join(root, markerName))).toBe(true);
686
+ fs.writeFileSync(decoy, "1\n", { mode: 0o600 });
687
+
688
+ const directory = join(alias, "lkg-recovery-fences");
689
+ fs.chmodSync(directory, 0o755);
690
+ ensurePrivateStorageDirectorySync(directory);
691
+
692
+ expect(fs.existsSync(join(root, markerName))).toBe(false);
693
+ expect(fs.existsSync(decoy)).toBe(true);
694
+ });
695
+
406
696
  it("removes certification while enforcement is off before a later private open", () => {
407
697
  const root = fixture();
408
698
  fs.writeFileSync(join(root, markerName), "1\n", { mode: 0o600 });
@@ -19,6 +19,7 @@ import {
19
19
  readdirSync,
20
20
  readlinkSync,
21
21
  readSync,
22
+ realpathSync,
22
23
  renameSync,
23
24
  rmdirSync,
24
25
  rmSync,
@@ -28,6 +29,7 @@ import {
28
29
  } from "node:fs";
29
30
  import type { FileHandle } from "node:fs/promises";
30
31
  import { open as openAsync, writeFile as writeFileAsync } from "node:fs/promises";
32
+ import { homedir } from "node:os";
31
33
  import { basename, dirname, join, resolve } from "node:path";
32
34
  import { isPidAlive } from "./rpc-utils";
33
35
 
@@ -38,10 +40,46 @@ const STORAGE_PERMISSIONS_MARKER_BYTES = Buffer.from(`${STORAGE_PERMISSIONS_POLI
38
40
  const STORAGE_PERMISSIONS_MARKER_MAX_AGE_MS = 24 * 60 * 60_000;
39
41
  const LEGACY_FENCE_TEMP_MIN_AGE_MS = 10 * 60_000;
40
42
 
43
+ /** Top-level names that Magic Context creates in its data folder. */
44
+ export const MAGIC_CONTEXT_STORAGE_ENTRIES: readonly (string | RegExp)[] = [
45
+ "context.db",
46
+ "context.db-wal",
47
+ "context.db-shm",
48
+ "context.db-journal",
49
+ "store.db", // The 0.49 Magic Context module's companion database.
50
+ "store.db-wal",
51
+ "store.db-shm",
52
+ "store.db-journal",
53
+ STORAGE_PERMISSIONS_MARKER,
54
+ "models",
55
+ "logs",
56
+ "backups",
57
+ "config-backups",
58
+ "lkg-recovery-fences",
59
+ "rpc",
60
+ "project-identities",
61
+ "heap-snapshots",
62
+ "host-profiler",
63
+ "pi-served-array-digests",
64
+ "pi-served-array-bodies",
65
+ "pi-served-tag-numbers",
66
+ "window-reports.jsonl",
67
+ "window-reports.jsonl.1",
68
+ // Atomic storage writes add .<pid>.<12 hex digits>.tmp to these root files.
69
+ /^(?:last_announced_version|last-update-check\.json|pending-plugin-update\.json|model-context-limits-(?:opencode|opencode2)\.json)(?:\.[1-9]\d*\.[a-f0-9]{12}\.tmp)?$/,
70
+ /^identity-merge-backup-[A-Za-z0-9]{6}$/,
71
+ // Session migration snapshot and database-repair copies/staging bundles.
72
+ /^context\.db\.bak-\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z$/,
73
+ /^context\.db\.corrupt-(?:backup|original)-\d{8}T\d{9}Z(?:-[1-9]\d{0,3})?(?:-wal|-shm)?$/,
74
+ /^context\.db\.recovering-\d{8}T\d{9}Z-[1-9]\d*(?:-[1-9]\d{0,3})?(?:\.(?:count-source|recover-source|(?:fresh\.)?db)(?:-wal|-shm)?|\.sql)$/,
75
+ ];
76
+
41
77
  /**
42
- * Storage roots that this process checked with tightenStorageTreeSync. Only a
43
- * root has a marker. Each database open checks its root, so a process that
44
- * writes storage files knows its root.
78
+ * Storage roots and their configured aliases. When a writer finds a loose
79
+ * mode in the tree, it deletes the marker file that certifies the tree as
80
+ * private, looking upward from the path it wrote. That search must stop at
81
+ * the storage root, whether the writer reached it by its real path or
82
+ * through a link.
45
83
  */
46
84
  const storagePermissionRoots = new Set<string>();
47
85
 
@@ -299,15 +337,97 @@ function readStoragePermissionCertificate(marker: string): Stats | undefined {
299
337
  }
300
338
  }
301
339
 
302
- /** Tighten existing entries during storage startup; symlinks are never followed. */
340
+ type LinkedRootSkip = "filesystem-root" | "home-folder" | "mount-point" | number;
341
+
342
+ function inspectLinkedStorageRoot(
343
+ root: string,
344
+ rootStat: Stats,
345
+ ): { skipped: LinkedRootSkip } | { entries: string[] } {
346
+ const parent = dirname(root);
347
+ if (root === parent) return { skipped: "filesystem-root" };
348
+ try {
349
+ if (root === realpathSync(homedir())) return { skipped: "home-folder" };
350
+ } catch (error) {
351
+ // A missing home cannot be the existing target. Other errors prevent the safety check.
352
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
353
+ }
354
+ if (lstatSync(parent).dev !== rootStat.dev) return { skipped: "mount-point" };
355
+ const entries = readdirSync(root);
356
+ const foreignEntries = entries.filter(
357
+ (name) =>
358
+ name !== ".DS_Store" &&
359
+ !MAGIC_CONTEXT_STORAGE_ENTRIES.some((entry) =>
360
+ typeof entry === "string" ? entry === name : entry.test(name),
361
+ ),
362
+ ).length;
363
+ return foreignEntries === 0 ? { entries } : { skipped: foreignEntries };
364
+ }
365
+
366
+ type StoragePermissionCheck = {
367
+ tightened: number;
368
+ failures: number;
369
+ rootLink?:
370
+ | { path: string; target: string; skipped?: LinkedRootSkip }
371
+ | { path: string; failure: string; nonDirectoryTarget?: string };
372
+ };
373
+
374
+ /** Tighten existing entries during startup. Follow a linked storage root, but no links inside it. */
303
375
  export function tightenStorageTreeSync(
304
376
  directory: string,
305
377
  dbPath = join(directory, "context.db"),
306
- ): { tightened: number; failures: number } {
378
+ ): StoragePermissionCheck {
307
379
  if (process.platform === "win32") {
308
380
  return { tightened: 0, failures: 0 };
309
381
  }
310
- const root = resolve(directory);
382
+ const enforce = shouldEnforcePrivateStoragePermissions();
383
+ const startupPath = resolve(directory);
384
+ let root = startupPath;
385
+ let rootStat: Stats | undefined;
386
+ let rootLink: StoragePermissionCheck["rootLink"];
387
+ let linkedEntries: string[] | undefined;
388
+ try {
389
+ rootStat = lstatSync(root);
390
+ } catch {
391
+ if (enforce) return { tightened: 0, failures: 1 };
392
+ }
393
+ if (rootStat?.isSymbolicLink()) {
394
+ try {
395
+ root = realpathSync(startupPath);
396
+ rootStat = lstatSync(root);
397
+ if (rootStat.isDirectory() && enforce) {
398
+ const eligibility = inspectLinkedStorageRoot(root, rootStat);
399
+ if ("skipped" in eligibility) {
400
+ return {
401
+ tightened: 0,
402
+ failures: 0,
403
+ rootLink: { path: startupPath, target: root, skipped: eligibility.skipped },
404
+ };
405
+ }
406
+ linkedEntries = eligibility.entries;
407
+ }
408
+ } catch (error) {
409
+ if (!enforce) return { tightened: 0, failures: 0 };
410
+ const failure = (error as NodeJS.ErrnoException).code ?? String(error);
411
+ return { tightened: 0, failures: 1, rootLink: { path: startupPath, failure } };
412
+ }
413
+ if (!rootStat.isDirectory()) {
414
+ if (!enforce) return { tightened: 0, failures: 0 };
415
+ return {
416
+ tightened: 0,
417
+ failures: 1,
418
+ rootLink: {
419
+ path: startupPath,
420
+ failure: "not a directory",
421
+ nonDirectoryTarget: root,
422
+ },
423
+ };
424
+ }
425
+ rootLink = { path: startupPath, target: root };
426
+ // Check the DB and sidecars in the same directory as the walk and marker,
427
+ // even if the configured link is redirected during the check.
428
+ dbPath = join(root, basename(dbPath));
429
+ storagePermissionRoots.add(startupPath);
430
+ }
311
431
  const marker = join(root, STORAGE_PERMISSIONS_MARKER);
312
432
  let tightened = 0;
313
433
  let failures = 0;
@@ -320,18 +440,12 @@ export function tightenStorageTreeSync(
320
440
  return false;
321
441
  }
322
442
  };
323
- if (!shouldEnforcePrivateStoragePermissions()) {
443
+ if (!enforce) {
324
444
  storagePermissionRoots.add(root);
325
445
  if (!removeMarker()) failures++;
326
- return { tightened, failures };
327
- }
328
- let rootStat: Stats;
329
- try {
330
- rootStat = lstatSync(root);
331
- if (!rootStat.isDirectory()) return { tightened, failures: 1 };
332
- } catch {
333
- return { tightened, failures: 1 };
446
+ return { tightened, failures, ...(rootLink && { rootLink }) };
334
447
  }
448
+ if (!rootStat?.isDirectory()) return { tightened, failures: 1 };
335
449
  storagePermissionRoots.add(root);
336
450
  let certificate: Stats | undefined;
337
451
  let discardMarker = false;
@@ -413,12 +527,23 @@ export function tightenStorageTreeSync(
413
527
  if (!recursive || !stat.isDirectory()) return;
414
528
  let entries: string[];
415
529
  try {
416
- entries = readdirSync(entryPath);
530
+ // Do not walk any root entry that was not included in the eligibility check.
531
+ entries = (entryPath === root ? linkedEntries : undefined) ?? readdirSync(entryPath);
417
532
  } catch {
418
533
  failures++;
419
534
  return;
420
535
  }
421
- for (const entry of entries) visit(join(entryPath, entry));
536
+ for (const entry of entries) {
537
+ // The snapshot may still list the marker file this check just removed.
538
+ if (
539
+ entryPath === root &&
540
+ linkedEntries &&
541
+ markerRemoved &&
542
+ entry === STORAGE_PERMISSIONS_MARKER
543
+ )
544
+ continue;
545
+ visit(join(entryPath, entry));
546
+ }
422
547
  };
423
548
  if (certificate) {
424
549
  visit(root, false, false, rootStat);
@@ -469,5 +594,5 @@ export function tightenStorageTreeSync(
469
594
  }
470
595
  }
471
596
  }
472
- return { tightened, failures };
597
+ return { tightened, failures, ...(rootLink && { rootLink }) };
473
598
  }
@@ -299,10 +299,13 @@ export type UserFacingTextStyle = "markdown" | "plain";
299
299
  export function renderUserFacingFailure(
300
300
  key: UserFacingFailureKey,
301
301
  style: UserFacingTextStyle = "markdown",
302
+ overrides?: { sentence?: string; action?: string },
302
303
  ): string {
303
304
  const failure = USER_FACING_FAILURES[key];
304
- const action = style === "plain" ? failure.action.replaceAll("`", "") : failure.action;
305
- return `${failure.sentence} ${action} (${failure.code})`;
305
+ const sentence = overrides?.sentence ?? failure.sentence;
306
+ const action = overrides?.action ?? failure.action;
307
+ const styledAction = style === "plain" ? action.replaceAll("`", "") : action;
308
+ return `${sentence}${styledAction ? ` ${styledAction}` : ""} (${failure.code})`;
306
309
  }
307
310
 
308
311
  export function userFacingFailureCode(key: UserFacingFailureKey): string {
@@ -12,6 +12,7 @@
12
12
  import { createMemo, createSignal, onCleanup } from "solid-js"
13
13
  import type { TuiPluginApi, TuiThemeCurrent } from "@opencode-ai/plugin/tui"
14
14
  import packageJson from "../../../package.json"
15
+ import { pausedRecompReason } from "../../shared/recomp-outcome"
15
16
  import {
16
17
  buildStatusViewFor,
17
18
  distributeBarWidths,
@@ -229,6 +230,8 @@ export const StatusDialog = (props: { api: TuiPluginApi; status: StatusDetailRes
229
230
  if (p.phase === "migration") return <R t={t()} l="Status" v={p.note ?? "Migrating memories ⟳"} fg={t().warning} />
230
231
  if (p.phase === "done") return <R t={t()} l="Status" v={`✓ ${verb} complete`} fg={t().accent} />
231
232
  if (p.phase === "skipped") return <R t={t()} l="Status" v={p.message ?? `${verb} stopped early`} fg={t().textMuted} />
233
+ const paused = pausedRecompReason(p.message)
234
+ if (paused !== null) return <R t={t()} l="Status" v={`${verb} paused: ${paused}`} fg={t().warning} />
232
235
  return <R t={t()} l="Status" v={`✗ ${verb} failed${p.message ? `: ${p.message}` : ""}`} fg={t().error} />
233
236
  })()}
234
237
  </box>
@@ -6,6 +6,7 @@ import { badgeTextColor } from '../badge-contrast';
6
6
  import { loadSidebarSnapshot, type SidebarSnapshot } from "../data/context-db"
7
7
  import { directoryForSession } from "../data/session-directory"
8
8
  import { formatThresholdPercent } from "../../shared/format-threshold"
9
+ import { pausedRecompReason } from "../../shared/recomp-outcome"
9
10
  import { renderUserFacingFailure } from "../../shared/user-facing-codes"
10
11
  import { compactionOffSidebarRows, nativeCompactionContextLabel } from "../compaction-off"
11
12
  import {
@@ -416,6 +417,7 @@ const RecompProgressSection = (props: {
416
417
  : props.progress.kind === "wrapup"
417
418
  ? "wrapping ⟳"
418
419
  : "comparting ⟳"
420
+ const paused = createMemo(() => pausedRecompReason(props.progress.message))
419
421
  const label = createMemo(() => {
420
422
  switch (props.progress.phase) {
421
423
  case "recomp":
@@ -436,7 +438,9 @@ const RecompProgressSection = (props: {
436
438
  // "retry shortly" (wrong for a partial stall).
437
439
  return { text: "stopped", color: props.theme.textMuted }
438
440
  case "failed":
439
- return { text: `✗ ${verb()} failed`, color: props.theme.error }
441
+ return paused() === null
442
+ ? { text: `✗ ${verb()} failed`, color: props.theme.error }
443
+ : { text: `${verb()} paused`, color: props.theme.warning }
440
444
  }
441
445
  })
442
446
 
@@ -480,7 +484,7 @@ const RecompProgressSection = (props: {
480
484
  {/* Terminal reason (failed/skipped) — kept visible so the user sees
481
485
  WHY (a failure, or the transient "retry shortly" skip cause). */}
482
486
  {(phase() === "failed" || phase() === "skipped") && props.progress.message && (
483
- <text fg={props.theme.textMuted}>{props.progress.message}</text>
487
+ <text fg={props.theme.textMuted}>{paused() ?? props.progress.message}</text>
484
488
  )}
485
489
  </>
486
490
  )
@@ -22,6 +22,7 @@ import { createElement as _$createElement } from "opentui:runtime-module:%40open
22
22
  */
23
23
  import { createMemo, createSignal, onCleanup } from "opentui:runtime-module:solid-js";
24
24
  import packageJson from "../../../package.json";
25
+ import { pausedRecompReason } from "../../shared/recomp-outcome";
25
26
  import { buildStatusViewFor, distributeBarWidths, statusColumnsFor } from "../../shared/status-view";
26
27
  import { RUST_MODE_HOST_PATHS_LINE } from "../../shared/rust-mode-status";
27
28
  const R = props => (() => {
@@ -413,6 +414,17 @@ export const StatusDialog = props => {
413
414
  return t().textMuted;
414
415
  }
415
416
  });
417
+ const paused = pausedRecompReason(p.message);
418
+ if (paused !== null) return _$createComponent(R, {
419
+ get t() {
420
+ return t();
421
+ },
422
+ l: "Status",
423
+ v: `${verb} paused: ${paused}`,
424
+ get fg() {
425
+ return t().warning;
426
+ }
427
+ });
416
428
  return _$createComponent(R, {
417
429
  get t() {
418
430
  return t();