@cortexkit/pi-magic-context 0.49.87 → 0.49.89

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 (28) hide show
  1. package/dist/auto-search-worker.js +3 -3
  2. package/dist/chunk-embedding-write-worker.js +5 -5
  3. package/dist/{embedding-backfill-za59jg6b.js → embedding-backfill-yydkxhrp.js} +6 -6
  4. package/dist/embedding-worker.js +2 -2
  5. package/dist/{index-wd5xfz8m.js → index-6x595qtk.js} +75 -12
  6. package/dist/{index-53fgdt6n.js → index-7xsbhw6m.js} +1 -1
  7. package/dist/{index-ex9te7tc.js → index-aahd8x9s.js} +1 -1
  8. package/dist/{index-rqdjb6j3.js → index-fsjsvq78.js} +1 -1
  9. package/dist/{index-xemjzc1v.js → index-hs862sjk.js} +2 -2
  10. package/dist/{index-94z1xzmr.js → index-kezt62gs.js} +1 -1
  11. package/dist/{index-8qdebv92.js → index-kn83b37d.js} +3 -3
  12. package/dist/{index-s3s4px1q.js → index-ndprcb9x.js} +11 -9
  13. package/dist/{index-bkagkxm5.js → index-qtfp61mq.js} +2 -2
  14. package/dist/{index-8x8wtn3t.js → index-rrm9ce0j.js} +108 -13
  15. package/dist/{index-gbc29ysq.js → index-rzwcmbww.js} +1 -1
  16. package/dist/{index-affz2pyv.js → index-w48rf3j6.js} +1 -1
  17. package/dist/{index-4c48169d.js → index-z2bdsba1.js} +9 -9
  18. package/dist/index.js +270 -105
  19. package/dist/migration-worker.js +4 -4
  20. package/dist/{project-embedding-registry-4kwf0m7j.js → project-embedding-registry-f9tzr12g.js} +5 -5
  21. package/dist/raw-ordinal-warmup-worker.js +2 -2
  22. package/dist/{render-2jzjgetc.js → render-mr2bb4yf.js} +6 -6
  23. package/dist/{search-archive-ze1567mj.js → search-archive-abtztrw5.js} +1 -1
  24. package/dist/{search-8dyn724d.js → search-rdqrskte.js} +9 -9
  25. package/dist/subagent-entry.js +13 -13
  26. package/dist/tag-snapshot-worker-pi.js +4 -4
  27. package/dist/{v2-archive-reader-vq596vh8.js → v2-archive-reader-qaecyb4y.js} +1 -1
  28. package/package.json +1 -1
@@ -27,11 +27,11 @@ serveWorkerJobs(async (initial, port) => {
27
27
  { Database, registerSqliteDiagnosticSink },
28
28
  { log }
29
29
  ] = await Promise.all([
30
- import("./embedding-backfill-za59jg6b.js"),
30
+ import("./embedding-backfill-yydkxhrp.js"),
31
31
  import("./embedding-cache-xft42rsb.js"),
32
32
  import("./storage-memory-2sed597w.js"),
33
- import("./project-embedding-registry-4kwf0m7j.js"),
34
- import("./search-8dyn724d.js"),
33
+ import("./project-embedding-registry-f9tzr12g.js"),
34
+ import("./search-rdqrskte.js"),
35
35
  import("./compartment-chunk-embedding-7pzb51r4.js"),
36
36
  import("./embedding-activity-ew6dshfd.js"),
37
37
  import("./harness-9872e0ym.js"),
@@ -30,15 +30,15 @@ import {
30
30
  acquireGitSweepLease,
31
31
  renewGitSweepLease,
32
32
  releaseGitSweepLease
33
- } from "./index-ex9te7tc.js";
34
- import"./index-8x8wtn3t.js";
35
- import"./index-94z1xzmr.js";
33
+ } from "./index-aahd8x9s.js";
34
+ import"./index-rrm9ce0j.js";
35
+ import"./index-kezt62gs.js";
36
36
  import {
37
37
  LATEST_SUPPORTED_VERSION,
38
38
  enforceSchemaFence
39
- } from "./index-wd5xfz8m.js";
39
+ } from "./index-6x595qtk.js";
40
40
  import"./index-3bb24eb6.js";
41
- import"./index-53fgdt6n.js";
41
+ import"./index-7xsbhw6m.js";
42
42
  import"./index-jhmz9tgv.js";
43
43
  import"./index-135e8hvg.js";
44
44
  import"./index-n0zjvs3h.js";
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  ensureMemoryEmbeddings2
3
- } from "./index-affz2pyv.js";
4
- import"./index-8qdebv92.js";
3
+ } from "./index-w48rf3j6.js";
4
+ import"./index-kn83b37d.js";
5
5
  import"./index-9p40dgkm.js";
6
6
  import"./index-hgd00nas.js";
7
7
  import"./index-hrwc50n3.js";
8
- import"./index-ex9te7tc.js";
8
+ import"./index-aahd8x9s.js";
9
9
  import"./index-464qhgjp.js";
10
- import"./index-rqdjb6j3.js";
10
+ import"./index-fsjsvq78.js";
11
11
  import"./index-5rcjs14a.js";
12
12
  import"./index-vcegxfwg.js";
13
- import"./index-94z1xzmr.js";
13
+ import"./index-kezt62gs.js";
14
14
  import"./index-ghp32f9m.js";
15
15
  import"./index-xjhq27z9.js";
16
16
  import"./index-wfqysrwq.js";
17
17
  import"./index-8sqebjzk.js";
18
18
  import"./index-1ts77n1b.js";
19
- import"./index-8x8wtn3t.js";
19
+ import"./index-rrm9ce0j.js";
20
20
  import"./index-pefn1gt5.js";
21
21
  import"./index-2qtx0q6h.js";
22
22
  import"./index-tm11k42a.js";
@@ -8,7 +8,7 @@ import {
8
8
  import"./index-dnp1jjar.js";
9
9
  import {
10
10
  setStoragePrivatePermissionEnforcement
11
- } from "./index-8x8wtn3t.js";
11
+ } from "./index-rrm9ce0j.js";
12
12
  import"./index-vcegxfwg.js";
13
13
  import"./index-5rcjs14a.js";
14
14
  import"./index-pefn1gt5.js";
@@ -18,7 +18,7 @@ import {
18
18
  resolveLocalEmbeddingWorkerRuntime,
19
19
  getLocalEmbeddingNativeMemoryStats,
20
20
  LocalEmbeddingProvider
21
- } from "./index-rqdjb6j3.js";
21
+ } from "./index-fsjsvq78.js";
22
22
 
23
23
  // ../plugin/src/features/magic-context/memory/embedding-worker.ts
24
24
  import { parentPort, workerData } from "node:worker_threads";
@@ -13,7 +13,7 @@ import {
13
13
  } from "./index-2qtx0q6h.js";
14
14
  import {
15
15
  scheduleAfterBootQuiet
16
- } from "./index-94z1xzmr.js";
16
+ } from "./index-kezt62gs.js";
17
17
  import {
18
18
  getHarness2,
19
19
  harnessOwnsOpenCodeStore2
@@ -41,7 +41,7 @@ import {
41
41
  copyStorageFileSync,
42
42
  copyStorageTreeSync,
43
43
  tightenStorageTreeSync
44
- } from "./index-8x8wtn3t.js";
44
+ } from "./index-rrm9ce0j.js";
45
45
  import {
46
46
  configureContextDatabasePragmas2
47
47
  } from "./index-fapenpch.js";
@@ -63,7 +63,7 @@ import {
63
63
  hasPendingMigrations,
64
64
  getMainThreadMigrationBodyCount,
65
65
  runMigrations
66
- } from "./index-53fgdt6n.js";
66
+ } from "./index-7xsbhw6m.js";
67
67
  import {
68
68
  setDatabase,
69
69
  loadToolDefinitionMeasurements,
@@ -104,6 +104,7 @@ function ensureContextStoreUuid(db) {
104
104
  // ../plugin/src/features/magic-context/storage-db.ts
105
105
  import {
106
106
  existsSync as existsSync2,
107
+ lstatSync,
107
108
  readdirSync,
108
109
  readFileSync,
109
110
  rmdirSync,
@@ -651,11 +652,73 @@ function getMigrationOnOpenRefusal() {
651
652
  }
652
653
  var LATEST_SUPPORTED_VERSION = 95;
653
654
  var BOOT_SQLITE_BUSY_TIMEOUT_MS = 5000;
654
- function ensureSecureStorageDir(dir) {
655
- ensureStorageDirectorySync(dir);
655
+ function isLinkedStorageRoot(dir) {
656
+ if (process.platform === "win32")
657
+ return false;
658
+ try {
659
+ return lstatSync(dir).isSymbolicLink();
660
+ } catch {
661
+ return false;
662
+ }
656
663
  }
657
- function tightenStorageTree(dbPath) {
658
- const { failures } = tightenStorageTreeSync(dirname(dbPath), dbPath);
664
+ function ensureSecureStorageDir(dir, dbPath) {
665
+ try {
666
+ ensureStorageDirectorySync(dir);
667
+ } catch (error) {
668
+ if (shouldEnforcePrivateStoragePermissions() && isLinkedStorageRoot(dir)) {
669
+ tightenStorageTree(dbPath, true);
670
+ }
671
+ throw error;
672
+ }
673
+ }
674
+ function describeLinkedStorageSkip(reason) {
675
+ switch (reason) {
676
+ case "filesystem-root":
677
+ return "it is a filesystem root";
678
+ case "home-folder":
679
+ return "it is your home folder";
680
+ case "mount-point":
681
+ return "it is a mount point";
682
+ default: {
683
+ const entries = reason === 1 ? "entry" : "entries";
684
+ return `it holds ${reason} ${entries} that Magic Context did not create`;
685
+ }
686
+ }
687
+ }
688
+ function describeLinkedStorageFailure(failure, nonDirectoryPath) {
689
+ if (nonDirectoryPath !== undefined)
690
+ return `${nonDirectoryPath} is not a directory`;
691
+ switch (failure) {
692
+ case "ENOENT":
693
+ return "ENOENT";
694
+ case "ELOOP":
695
+ return "ELOOP";
696
+ case "EACCES":
697
+ return "EACCES";
698
+ case "EPERM":
699
+ return "EPERM";
700
+ case "ENOTDIR":
701
+ return "ENOTDIR";
702
+ default:
703
+ return "could not resolve or inspect the linked target";
704
+ }
705
+ }
706
+ function tightenStorageTree(dbPath, reportResolvedLink = false) {
707
+ const { failures, rootLink } = tightenStorageTreeSync(dirname(dbPath), dbPath);
708
+ if (rootLink && "failure" in rootLink) {
709
+ log2(`[magic-context] storage permission tightening failures=${failures}: storage root link ${rootLink.path}: ${describeLinkedStorageFailure(rootLink.failure, rootLink.nonDirectoryTarget)}`);
710
+ return;
711
+ }
712
+ if (rootLink?.skipped !== undefined) {
713
+ if (reportResolvedLink) {
714
+ const { path: linkPath, target: targetPath } = rootLink;
715
+ log2(`[magic-context] linked storage folder ${linkPath} -> ${targetPath} was not made private because ${describeLinkedStorageSkip(rootLink.skipped)}. Move the store to a folder of its own so Magic Context can protect it.`);
716
+ }
717
+ return;
718
+ }
719
+ if (rootLink && reportResolvedLink) {
720
+ log2(`[magic-context] resolved storage root link ${rootLink.path} -> ${rootLink.target}`);
721
+ }
659
722
  log2(`[magic-context] storage permission tightening failures=${failures}`);
660
723
  }
661
724
  function resolveBootBusyTimeoutMs(value) {
@@ -691,7 +754,7 @@ function migrateLegacyStorageIfNeeded(targetDbPath, targetDbDir) {
691
754
  if (!existsSync2(legacyDbPath))
692
755
  return;
693
756
  log2(`[magic-context] migrating legacy plugin storage: ${legacyDir} -> ${targetDbDir} (legacy left in place as backup)`);
694
- ensureSecureStorageDir(targetDbDir);
757
+ ensureSecureStorageDir(targetDbDir, targetDbPath);
695
758
  try {
696
759
  const legacyDb = new Database2(legacyDbPath);
697
760
  try {
@@ -2414,8 +2477,8 @@ function openDatabase(dbPathOrOptions) {
2414
2477
  if (!explicitDbPath) {
2415
2478
  migrateLegacyStorageIfNeeded(dbPath, dbDir);
2416
2479
  }
2417
- ensureSecureStorageDir(dbDir);
2418
- tightenStorageTree(dbPath);
2480
+ ensureSecureStorageDir(dbDir, dbPath);
2481
+ tightenStorageTree(dbPath, true);
2419
2482
  if (!existsSync2(dbPath) && shouldEnforcePrivateStoragePermissions()) {
2420
2483
  try {
2421
2484
  writeStorageFileSync(dbPath, new Uint8Array, { flag: "wx" });
@@ -2511,8 +2574,8 @@ async function openDatabaseAsync(dbPathOrOptions) {
2511
2574
  try {
2512
2575
  if (!explicitDbPath)
2513
2576
  migrateLegacyStorageIfNeeded(dbPath, dbDir);
2514
- ensureSecureStorageDir(dbDir);
2515
- tightenStorageTree(dbPath);
2577
+ ensureSecureStorageDir(dbDir, dbPath);
2578
+ tightenStorageTree(dbPath, true);
2516
2579
  if (!existsSync2(dbPath) && shouldEnforcePrivateStoragePermissions()) {
2517
2580
  try {
2518
2581
  writeStorageFileSync(dbPath, new Uint8Array, { flag: "wx" });
@@ -20,7 +20,7 @@ import {
20
20
  import {
21
21
  normalizeStoredProjectPath,
22
22
  storedPathBelongsToIdentity
23
- } from "./index-94z1xzmr.js";
23
+ } from "./index-kezt62gs.js";
24
24
  import {
25
25
  logSlowWriteTransaction
26
26
  } from "./index-1ts77n1b.js";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./index-0h2mkab2.js";
4
4
  import {
5
5
  isUserHomeDirectory
6
- } from "./index-94z1xzmr.js";
6
+ } from "./index-kezt62gs.js";
7
7
  import {
8
8
  logSlowWriteTransaction
9
9
  } from "./index-1ts77n1b.js";
@@ -22,7 +22,7 @@ import {
22
22
  writeStorageFileAsync,
23
23
  writeStorageFileHandleAsync,
24
24
  createStorageFileHandleAsync
25
- } from "./index-8x8wtn3t.js";
25
+ } from "./index-rrm9ce0j.js";
26
26
  import {
27
27
  computeNormalizedHash
28
28
  } from "./index-9x1f96r8.js";
@@ -140,8 +140,8 @@ async function serveV2ArchiveReads2(port, openConnections) {
140
140
  import("./store-reader-vwphd51b.js"),
141
141
  import("./store-ekaexkvc.js"),
142
142
  import("./read-session-chunk-tec7t4vy.js"),
143
- import("./render-2jzjgetc.js"),
144
- import("./search-archive-ze1567mj.js"),
143
+ import("./render-mr2bb4yf.js"),
144
+ import("./search-archive-abtztrw5.js"),
145
145
  import("./expand-attachments-8sxeyj26.js")
146
146
  ]);
147
147
  const pool = new V2StoreReaderPool;
@@ -4,7 +4,7 @@ import {
4
4
  } from "./index-tm11k42a.js";
5
5
  import {
6
6
  writeStorageFileAtomicSync
7
- } from "./index-8x8wtn3t.js";
7
+ } from "./index-rrm9ce0j.js";
8
8
  import {
9
9
  inRootAsyncContext2
10
10
  } from "./index-2qtx0q6h.js";
@@ -56,7 +56,7 @@ import {
56
56
  getEmbeddingProviderIdentity,
57
57
  dominantEmbeddingFailure,
58
58
  LocalEmbeddingProvider
59
- } from "./index-rqdjb6j3.js";
59
+ } from "./index-fsjsvq78.js";
60
60
  import {
61
61
  embedPauseBySession,
62
62
  activeEmbeddingSessions,
@@ -67,7 +67,7 @@ import {
67
67
  } from "./index-hgd00nas.js";
68
68
  import {
69
69
  setBootQuietPeriodForTests
70
- } from "./index-94z1xzmr.js";
70
+ } from "./index-kezt62gs.js";
71
71
  import {
72
72
  isEmbeddingHostBusy2
73
73
  } from "./index-9p40dgkm.js";
@@ -78,7 +78,7 @@ import {
78
78
  acquireGitSweepLease,
79
79
  renewGitSweepLease,
80
80
  releaseGitSweepLease
81
- } from "./index-ex9te7tc.js";
81
+ } from "./index-aahd8x9s.js";
82
82
  import {
83
83
  saveEmbeddingIfHashMatches,
84
84
  getMemoryEmbedCoverage,
@@ -39,7 +39,7 @@ import {
39
39
  } from "./index-464qhgjp.js";
40
40
  import {
41
41
  LocalEmbeddingProvider
42
- } from "./index-rqdjb6j3.js";
42
+ } from "./index-fsjsvq78.js";
43
43
  import {
44
44
  OpenAICompatibleEmbeddingProvider,
45
45
  saveCommitEmbedding,
@@ -57,20 +57,20 @@ import {
57
57
  getProjectEmbeddingSnapshot2,
58
58
  embedTextForProject2,
59
59
  embedItemsForProject2
60
- } from "./index-8qdebv92.js";
60
+ } from "./index-kn83b37d.js";
61
61
  import {
62
62
  recordEmbeddingMeasurement
63
63
  } from "./index-hgd00nas.js";
64
64
  import {
65
65
  scheduleAfterBootQuiet
66
- } from "./index-94z1xzmr.js";
66
+ } from "./index-kezt62gs.js";
67
67
  import {
68
68
  saveEmbeddingIfHashMatches,
69
69
  getProjectEmbeddings2
70
70
  } from "./index-hrwc50n3.js";
71
71
  import {
72
72
  ensureMemoryEmbeddings2
73
- } from "./index-affz2pyv.js";
73
+ } from "./index-w48rf3j6.js";
74
74
  import {
75
75
  getMemorySelectColumns2,
76
76
  isMemoryRow2,
@@ -109,11 +109,11 @@ import {
109
109
  expandWorkspaceIdentitySetWithAliases,
110
110
  resolveStoredPathWorkspaceIdentity,
111
111
  sourceNameForMemory
112
- } from "./index-53fgdt6n.js";
112
+ } from "./index-7xsbhw6m.js";
113
113
  import {
114
114
  getNotes,
115
115
  getActivePrimers
116
- } from "./index-gbc29ysq.js";
116
+ } from "./index-rzwcmbww.js";
117
117
  import {
118
118
  computeNormalizedHash
119
119
  } from "./index-9x1f96r8.js";
@@ -399,10 +399,12 @@ var USER_FACING_FAILURES = {
399
399
  action: "Check the Magic Context log for the failing task and its error."
400
400
  }
401
401
  };
402
- function renderUserFacingFailure(key, style = "markdown") {
402
+ function renderUserFacingFailure(key, style = "markdown", overrides) {
403
403
  const failure = USER_FACING_FAILURES[key];
404
- const action = style === "plain" ? failure.action.replaceAll("`", "") : failure.action;
405
- return `${failure.sentence} ${action} (${failure.code})`;
404
+ const sentence = overrides?.sentence ?? failure.sentence;
405
+ const action = overrides?.action ?? failure.action;
406
+ const styledAction = style === "plain" ? action.replaceAll("`", "") : action;
407
+ return `${sentence}${styledAction ? ` ${styledAction}` : ""} (${failure.code})`;
406
408
  }
407
409
  function userFacingFailureCode(key) {
408
410
  return USER_FACING_FAILURES[key].code;
@@ -66,7 +66,7 @@ import {
66
66
  writeStorageFileAtomicSync,
67
67
  syncStorageDirectorySync,
68
68
  writeStorageFileDurableAtomicSync
69
- } from "./index-8x8wtn3t.js";
69
+ } from "./index-rrm9ce0j.js";
70
70
  import {
71
71
  withReadOnlySessionDb,
72
72
  expandToolPart,
@@ -90,7 +90,7 @@ import {
90
90
  import {
91
91
  layoutLkgPrefix,
92
92
  assembleLkgPrefix
93
- } from "./index-53fgdt6n.js";
93
+ } from "./index-7xsbhw6m.js";
94
94
  import {
95
95
  logSlowWriteTransaction
96
96
  } from "./index-1ts77n1b.js";
@@ -17,6 +17,7 @@ import {
17
17
  readdirSync,
18
18
  readlinkSync,
19
19
  readSync,
20
+ realpathSync,
20
21
  renameSync,
21
22
  rmdirSync,
22
23
  rmSync,
@@ -25,6 +26,7 @@ import {
25
26
  writeSync
26
27
  } from "node:fs";
27
28
  import { open as openAsync, writeFile as writeFileAsync } from "node:fs/promises";
29
+ import { homedir } from "node:os";
28
30
  import { basename, dirname, join, resolve } from "node:path";
29
31
 
30
32
  // ../plugin/src/shared/rpc-utils.ts
@@ -742,6 +744,36 @@ var STORAGE_PERMISSIONS_MARKER_BYTES = Buffer.from(`${STORAGE_PERMISSIONS_POLICY
742
744
  `);
743
745
  var STORAGE_PERMISSIONS_MARKER_MAX_AGE_MS = 24 * 60 * 60000;
744
746
  var LEGACY_FENCE_TEMP_MIN_AGE_MS = 10 * 60000;
747
+ var MAGIC_CONTEXT_STORAGE_ENTRIES = [
748
+ "context.db",
749
+ "context.db-wal",
750
+ "context.db-shm",
751
+ "context.db-journal",
752
+ "store.db",
753
+ "store.db-wal",
754
+ "store.db-shm",
755
+ "store.db-journal",
756
+ STORAGE_PERMISSIONS_MARKER,
757
+ "models",
758
+ "logs",
759
+ "backups",
760
+ "config-backups",
761
+ "lkg-recovery-fences",
762
+ "rpc",
763
+ "project-identities",
764
+ "heap-snapshots",
765
+ "host-profiler",
766
+ "pi-served-array-digests",
767
+ "pi-served-array-bodies",
768
+ "pi-served-tag-numbers",
769
+ "window-reports.jsonl",
770
+ "window-reports.jsonl.1",
771
+ /^(?: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)?$/,
772
+ /^identity-merge-backup-[A-Za-z0-9]{6}$/,
773
+ /^context\.db\.bak-\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z$/,
774
+ /^context\.db\.corrupt-(?:backup|original)-\d{8}T\d{9}Z(?:-[1-9]\d{0,3})?(?:-wal|-shm)?$/,
775
+ /^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)$/
776
+ ];
745
777
  var storagePermissionRoots = new Set;
746
778
  function invalidateStoragePermissionMarkers(directory) {
747
779
  for (let current = resolve(directory);; current = dirname(current)) {
@@ -913,11 +945,77 @@ function readStoragePermissionCertificate(marker) {
913
945
  closeSync(fd);
914
946
  }
915
947
  }
948
+ function inspectLinkedStorageRoot(root, rootStat) {
949
+ const parent = dirname(root);
950
+ if (root === parent)
951
+ return { skipped: "filesystem-root" };
952
+ try {
953
+ if (root === realpathSync(homedir()))
954
+ return { skipped: "home-folder" };
955
+ } catch (error) {
956
+ if (error.code !== "ENOENT")
957
+ throw error;
958
+ }
959
+ if (lstatSync(parent).dev !== rootStat.dev)
960
+ return { skipped: "mount-point" };
961
+ const entries = readdirSync(root);
962
+ const foreignEntries = entries.filter((name) => name !== ".DS_Store" && !MAGIC_CONTEXT_STORAGE_ENTRIES.some((entry) => typeof entry === "string" ? entry === name : entry.test(name))).length;
963
+ return foreignEntries === 0 ? { entries } : { skipped: foreignEntries };
964
+ }
916
965
  function tightenStorageTreeSync(directory, dbPath = join(directory, "context.db")) {
917
966
  if (process.platform === "win32") {
918
967
  return { tightened: 0, failures: 0 };
919
968
  }
920
- const root = resolve(directory);
969
+ const enforce = shouldEnforcePrivateStoragePermissions();
970
+ const startupPath = resolve(directory);
971
+ let root = startupPath;
972
+ let rootStat;
973
+ let rootLink;
974
+ let linkedEntries;
975
+ try {
976
+ rootStat = lstatSync(root);
977
+ } catch {
978
+ if (enforce)
979
+ return { tightened: 0, failures: 1 };
980
+ }
981
+ if (rootStat?.isSymbolicLink()) {
982
+ try {
983
+ root = realpathSync(startupPath);
984
+ rootStat = lstatSync(root);
985
+ if (rootStat.isDirectory() && enforce) {
986
+ const eligibility = inspectLinkedStorageRoot(root, rootStat);
987
+ if ("skipped" in eligibility) {
988
+ return {
989
+ tightened: 0,
990
+ failures: 0,
991
+ rootLink: { path: startupPath, target: root, skipped: eligibility.skipped }
992
+ };
993
+ }
994
+ linkedEntries = eligibility.entries;
995
+ }
996
+ } catch (error) {
997
+ if (!enforce)
998
+ return { tightened: 0, failures: 0 };
999
+ const failure = error.code ?? String(error);
1000
+ return { tightened: 0, failures: 1, rootLink: { path: startupPath, failure } };
1001
+ }
1002
+ if (!rootStat.isDirectory()) {
1003
+ if (!enforce)
1004
+ return { tightened: 0, failures: 0 };
1005
+ return {
1006
+ tightened: 0,
1007
+ failures: 1,
1008
+ rootLink: {
1009
+ path: startupPath,
1010
+ failure: "not a directory",
1011
+ nonDirectoryTarget: root
1012
+ }
1013
+ };
1014
+ }
1015
+ rootLink = { path: startupPath, target: root };
1016
+ dbPath = join(root, basename(dbPath));
1017
+ storagePermissionRoots.add(startupPath);
1018
+ }
921
1019
  const marker = join(root, STORAGE_PERMISSIONS_MARKER);
922
1020
  let tightened = 0;
923
1021
  let failures = 0;
@@ -930,20 +1028,14 @@ function tightenStorageTreeSync(directory, dbPath = join(directory, "context.db"
930
1028
  return false;
931
1029
  }
932
1030
  };
933
- if (!shouldEnforcePrivateStoragePermissions()) {
1031
+ if (!enforce) {
934
1032
  storagePermissionRoots.add(root);
935
1033
  if (!removeMarker())
936
1034
  failures++;
937
- return { tightened, failures };
1035
+ return { tightened, failures, ...rootLink && { rootLink } };
938
1036
  }
939
- let rootStat;
940
- try {
941
- rootStat = lstatSync(root);
942
- if (!rootStat.isDirectory())
943
- return { tightened, failures: 1 };
944
- } catch {
1037
+ if (!rootStat?.isDirectory())
945
1038
  return { tightened, failures: 1 };
946
- }
947
1039
  storagePermissionRoots.add(root);
948
1040
  let certificate;
949
1041
  let discardMarker = false;
@@ -1023,13 +1115,16 @@ function tightenStorageTreeSync(directory, dbPath = join(directory, "context.db"
1023
1115
  return;
1024
1116
  let entries;
1025
1117
  try {
1026
- entries = readdirSync(entryPath);
1118
+ entries = (entryPath === root ? linkedEntries : undefined) ?? readdirSync(entryPath);
1027
1119
  } catch {
1028
1120
  failures++;
1029
1121
  return;
1030
1122
  }
1031
- for (const entry of entries)
1123
+ for (const entry of entries) {
1124
+ if (entryPath === root && linkedEntries && markerRemoved && entry === STORAGE_PERMISSIONS_MARKER)
1125
+ continue;
1032
1126
  visit(join(entryPath, entry));
1127
+ }
1033
1128
  };
1034
1129
  if (certificate) {
1035
1130
  visit(root, false, false, rootStat);
@@ -1077,7 +1172,7 @@ function tightenStorageTreeSync(directory, dbPath = join(directory, "context.db"
1077
1172
  }
1078
1173
  }
1079
1174
  }
1080
- return { tightened, failures };
1175
+ return { tightened, failures, ...rootLink && { rootLink } };
1081
1176
  }
1082
1177
 
1083
1178
  export { piHarnessKindFromExecutable, isOwnRpcServerRecord, isPidAlive, readProcessStartTime, readProcessProbeEvidence, classifyProcessKind, isPidIdentityPlausible, inspectLivePiProcesses, parseRpcPortFile, inspectProcessesAsync, inspectWindowsProcessesSync, setStoragePrivatePermissionEnforcement, shouldEnforcePrivateStoragePermissions, ensureStorageDirectorySync, ensurePrivateStorageDirectorySync, writeStorageFileSync, writeStorageFileAtomicSync, syncStorageDirectorySync, writeStorageFileDurableAtomicSync, copyStorageFileSync, copyStorageTreeSync, writeStorageFileAsync, writeStorageFileHandleAsync, createStorageFileHandleAsync, tightenStorageTreeSync };
@@ -6,7 +6,7 @@ import {
6
6
  } from "./index-2qtx0q6h.js";
7
7
  import {
8
8
  managedAuthorityNoteRow
9
- } from "./index-53fgdt6n.js";
9
+ } from "./index-7xsbhw6m.js";
10
10
 
11
11
  // ../plugin/src/features/magic-context/storage-notes.ts
12
12
  var NOTE_TYPES = new Set(["session", "smart"]);
@@ -10,7 +10,7 @@ import {
10
10
  readSearchBackfillCursor2,
11
11
  writeSearchBackfillCursor2,
12
12
  embedItemsWindowBounded2
13
- } from "./index-8qdebv92.js";
13
+ } from "./index-kn83b37d.js";
14
14
  import {
15
15
  saveEmbeddingIfHashMatches
16
16
  } from "./index-hrwc50n3.js";
@@ -22,7 +22,7 @@ import {
22
22
  piHarnessKindFromExecutable,
23
23
  ensureStorageDirectorySync,
24
24
  writeStorageFileAtomicSync
25
- } from "./index-8x8wtn3t.js";
25
+ } from "./index-rrm9ce0j.js";
26
26
  import {
27
27
  piModelRefToCanonical,
28
28
  modelRefLookupOrder,
@@ -71,7 +71,7 @@ import {
71
71
  renderMessageByOrdinal2,
72
72
  renderVerboseRange2,
73
73
  renderItemByTag2
74
- } from "./index-bkagkxm5.js";
74
+ } from "./index-qtfp61mq.js";
75
75
  import {
76
76
  getLastIndexedOrdinal
77
77
  } from "./index-qpdh2aff.js";
@@ -118,7 +118,7 @@ import {
118
118
  } from "./index-hrwc50n3.js";
119
119
  import {
120
120
  preflightLocalEmbeddingPooling
121
- } from "./index-rqdjb6j3.js";
121
+ } from "./index-fsjsvq78.js";
122
122
  import {
123
123
  withQueryEmbeddingDeadline,
124
124
  markProjectLoadUntrusted2,
@@ -131,23 +131,23 @@ import {
131
131
  unregisterProjectEmbedding2,
132
132
  getProjectEmbeddingSnapshot2,
133
133
  embedTextForProject2
134
- } from "./index-8qdebv92.js";
134
+ } from "./index-kn83b37d.js";
135
135
  import {
136
136
  directoryHasGitMetadata,
137
137
  resolveProjectIdentityForSession,
138
138
  normalizeStoredProjectPath,
139
139
  storedPathBelongsToIdentity
140
- } from "./index-94z1xzmr.js";
140
+ } from "./index-kezt62gs.js";
141
141
  import {
142
142
  createUnifiedSearchDiagnostics2,
143
143
  parseIdShapedQuery2,
144
144
  resolveMemoriesByIdsForSearch2,
145
145
  unifiedSearch2,
146
146
  formatSearchResults2
147
- } from "./index-s3s4px1q.js";
147
+ } from "./index-ndprcb9x.js";
148
148
  import {
149
149
  getErrorMessage
150
- } from "./index-wd5xfz8m.js";
150
+ } from "./index-6x595qtk.js";
151
151
  import {
152
152
  resolveOpenCodeDbPath,
153
153
  assertOpenCodeStoreGeneration
@@ -164,7 +164,7 @@ import {
164
164
  resolveStoredPathWorkspaceIdentity,
165
165
  storedPathBelongsToWorkspace,
166
166
  sourceNameForMemory
167
- } from "./index-53fgdt6n.js";
167
+ } from "./index-7xsbhw6m.js";
168
168
  import {
169
169
  getNoteByIdInScope,
170
170
  getNotes,
@@ -175,7 +175,7 @@ import {
175
175
  updateNote,
176
176
  dismissNotes,
177
177
  dismissNote
178
- } from "./index-gbc29ysq.js";
178
+ } from "./index-rzwcmbww.js";
179
179
  import {
180
180
  isMarkerCandidateBasisCurrent2,
181
181
  invalidateMarkerCandidateBasis2,