@cortexkit/opencode-magic-context 0.49.83 → 0.49.85
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.
- package/dist/{announcement-p41dde4h.js → announcement-fnyxaahs.js} +3 -1
- package/dist/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +5 -4
- package/dist/{context-xmyke353.js → context-bjfwzbts.js} +314 -107
- package/dist/{derive-budgets-2z6xxm7e.js → derive-budgets-90869322.js} +3 -1
- package/dist/{embedding-backfill-k994xdas.js → embedding-backfill-v6sw58m8.js} +7 -5
- package/dist/embedding-worker.js +15 -27
- package/dist/features/magic-context/memory/embedding-worker-boundary.test-support.d.ts +24 -0
- package/dist/features/magic-context/memory/embedding-worker-boundary.test-support.d.ts.map +1 -0
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts +35 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-worker-loop.d.ts +57 -0
- package/dist/features/magic-context/memory/embedding-worker-loop.d.ts.map +1 -0
- package/dist/features/magic-context/mural/render-trigger.d.ts +3 -3
- package/dist/features/magic-context/mural/render-trigger.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +6 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
- package/dist/{index-zzvd4a9z.js → index-05bm2ndp.js} +1 -1
- package/dist/{index-93rezfvc.js → index-08jfpny9.js} +37 -6
- package/dist/{index-dg5jvh9r.js → index-0rge5rkh.js} +8 -8
- package/dist/{index-2xhzmwf6.js → index-1pf5qrx4.js} +5 -5
- package/dist/{index-e21n48yd.js → index-1y4y98r1.js} +23 -0
- package/dist/{index-98qy103c.js → index-2kf73btc.js} +1 -1
- package/dist/{index-vpw46557.js → index-3dtzyred.js} +1 -1
- package/dist/{index-bd34njzg.js → index-4ntnt8ee.js} +1 -1
- package/dist/{index-w2wpx7t5.js → index-4w5rx7de.js} +1 -1
- package/dist/{index-twmeey4h.js → index-70cv85b0.js} +2 -2
- package/dist/{index-rnyaa7cj.js → index-798s7c8s.js} +2 -2
- package/dist/{index-2q0t43fy.js → index-7j2zv9nm.js} +1 -1
- package/dist/{index-fpqdbb67.js → index-7svecf3m.js} +3 -3
- package/dist/{index-eptthgkw.js → index-9fsxmjs6.js} +5 -5
- package/dist/{v2/server-fvnzcnww.js → index-c5tmzym6.js} +192 -11
- package/dist/{index-w8dcjt7f.js → index-k0tb2z28.js} +1 -1
- package/dist/{index-zb4h9nrk.js → index-k50xhjw1.js} +202 -14
- package/dist/{index-hz1xdb15.js → index-kqnef2tg.js} +4 -4
- package/dist/{index-2ygw6q5s.js → index-nny4gm06.js} +2 -2
- package/dist/{index-fgy6hnr3.js → index-pw279hmt.js} +2 -2
- package/dist/{index-eyk7msgw.js → index-qvn3q9f1.js} +41 -41
- package/dist/{index-shpyv8gq.js → index-s8ks5nz4.js} +16 -9
- package/dist/{index-wxxcfpxh.js → index-sbr58jaf.js} +8 -8
- package/dist/{index-b2787fk6.js → index-tzbcb8yt.js} +36 -20
- package/dist/{index-x8qgqnym.js → index-w6v4dw5f.js} +25 -25
- package/dist/{index-zvane1rq.js → index-xccywqdj.js} +16 -16
- package/dist/{index-y208s7zx.js → index-xrnhxkz7.js} +6 -1
- package/dist/{index-tky3j43e.js → index-zmqx48vt.js} +58 -14
- package/dist/index.js +37 -37
- package/dist/{message-index-bounded-cfkeyf72.js → message-index-bounded-6fr624zf.js} +3 -3
- package/dist/migration-worker.js +4 -3
- package/dist/{project-embedding-registry-y3z36mjy.js → project-embedding-registry-q80scexh.js} +6 -4
- package/dist/raw-ordinal-warmup-worker.js +4 -4
- package/dist/{read-session-chunk-s3qac56g.js → read-session-chunk-6wedfths.js} +2 -2
- package/dist/{recomp-orchestrator-fjdp3t1d.js → recomp-orchestrator-xzs0a455.js} +19 -18
- package/dist/{render-c9fjwrad.js → render-yqp7q79f.js} +12 -11
- package/dist/{search-archive-s2jas2jb.js → search-archive-r4h96j2z.js} +4 -4
- package/dist/{search-1jejx5cx.js → search-ztgy3ya6.js} +15 -13
- package/dist/shared/models-dev-cache.d.ts +6 -1
- package/dist/shared/models-dev-cache.d.ts.map +1 -1
- package/dist/shared/storage-file-mutex.d.ts.map +1 -1
- package/dist/shared/storage-permissions.d.ts +5 -3
- package/dist/shared/storage-permissions.d.ts.map +1 -1
- package/dist/shared/test-git-env.d.ts +3 -0
- package/dist/shared/test-git-env.d.ts.map +1 -0
- package/dist/{storage-tags-6e83pvff.js → storage-tags-y2mrb8e6.js} +1 -1
- package/dist/{store-ggrq9e14.js → store-n4yz3n66.js} +2 -2
- package/dist/{store-reader-tr64nxyy.js → store-reader-nf8z86n9.js} +1 -1
- package/dist/{transform-postprocess-phase-p2egg02g.js → transform-postprocess-phase-39a5hm2a.js} +20 -19
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/chunk-embedding-write-worker.js +6 -5
- package/dist/v2/{context-zn18k0yk.js → context-k2rrqzf4.js} +446 -248
- package/dist/v2/{derive-budgets-2eam671q.js → derive-budgets-ecjy1aqh.js} +4 -2
- package/dist/v2/{embedding-backfill-hjvjxp7d.js → embedding-backfill-k8kqnwfq.js} +7 -5
- package/dist/v2/embedding-worker.js +15 -27
- package/dist/v2/fold/restore.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/hooks/revert-message-state.d.ts +12 -0
- package/dist/v2/hooks/revert-message-state.d.ts.map +1 -0
- package/dist/v2/hooks/storage-notice.d.ts +12 -6
- package/dist/v2/hooks/storage-notice.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-0xy4dn04.js → message-index-bounded-jqy7283g.js} +4 -4
- package/dist/v2/migration-worker.js +5 -4
- package/dist/v2/{project-embedding-registry-mzsvyads.js → project-embedding-registry-2jp1antr.js} +6 -4
- package/dist/v2/raw-ordinal-warmup-worker.js +4 -4
- package/dist/v2/{read-session-chunk-6mt2t6dy.js → read-session-chunk-n3nhfvd7.js} +3 -3
- package/dist/v2/{recomp-orchestrator-jn39mxh0.js → recomp-orchestrator-jnbxbsc8.js} +21 -20
- package/dist/v2/{render-q2aj9bgy.js → render-fezgh7pa.js} +13 -12
- package/dist/v2/{search-archive-fj59gjv1.js → search-archive-zz1kza50.js} +5 -5
- package/dist/v2/{search-9xn6ds9x.js → search-h5w7510x.js} +15 -13
- package/dist/v2/{server-2gcfmd47.js → server-2k8tkbhz.js} +2 -2
- package/dist/v2/{server-4z964n1c.js → server-3p6b0qya.js} +1 -1
- package/dist/v2/{server-c8mqs0v5.js → server-4wwwm2ya.js} +32 -32
- package/dist/v2/{server-1cn3kryt.js → server-97w51d8n.js} +5 -5
- package/dist/v2/{server-gx1s06dx.js → server-98hsp35q.js} +2 -2
- package/dist/v2/{server-xepx8t43.js → server-a2f1bhyj.js} +1 -1
- package/dist/v2/{server-r00xyx66.js → server-ap81bk3c.js} +28 -28
- package/dist/v2/{server-d706s5xn.js → server-b93f0bqh.js} +205 -17
- package/dist/v2/{server-2w1rdttn.js → server-brgandk4.js} +2 -2
- package/dist/v2/{server-rp52f40v.js → server-cwtehwbb.js} +1 -1
- package/dist/v2/{server-bj779zmp.js → server-e2k9mt86.js} +1 -1
- package/dist/v2/{server-68q80y27.js → server-hn8b7sfe.js} +16 -9
- package/dist/v2/{server-pejjj0nv.js → server-mbkwcwgw.js} +1 -1
- package/dist/v2/{server-g1a0nhtk.js → server-n5zr7190.js} +18 -18
- package/dist/v2/{server-2ktxmtbd.js → server-ps6rz88g.js} +2 -2
- package/dist/v2/{server-5yfq912a.js → server-qyazxy92.js} +23 -0
- package/dist/{index-fvnzcnww.js → v2/server-r2es6zt7.js} +192 -11
- package/dist/v2/{server-bt546axy.js → server-rz4snd3x.js} +3 -3
- package/dist/v2/{server-xdh4r20h.js → server-s15knz0w.js} +642 -627
- package/dist/v2/{server-vt6nj2hn.js → server-s76ty4ws.js} +41 -25
- package/dist/v2/{server-0dmzr7f9.js → server-sxfbjdye.js} +2 -2
- package/dist/v2/{server-569he5mh.js → server-w7mpvkpj.js} +1 -1
- package/dist/v2/{server-53n8hv5q.js → server-x77hd658.js} +8 -8
- package/dist/v2/{server-nqdzv8b7.js → server-xa8fefhw.js} +58 -14
- package/dist/v2/{server-1efjj215.js → server-ytqps2xa.js} +37 -6
- package/dist/v2/server.js +6 -4
- package/dist/v2/{storage-tags-z8j8wq34.js → storage-tags-xq81zgt2.js} +2 -2
- package/dist/v2/{store-reader-83tka051.js → store-reader-2vhx33n6.js} +1 -1
- package/dist/v2/store-reader.d.ts +11 -0
- package/dist/v2/store-reader.d.ts.map +1 -1
- package/dist/v2/{store-qdgzd38f.js → store-y56y034s.js} +2 -2
- package/dist/v2/{v2-archive-reader-9z8z97db.js → v2-archive-reader-e2w39c3p.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-vd5zfp3v.js → wrapup-orchestrator-mmje3etf.js} +20 -19
- package/dist/{v2-archive-reader-r0xpxsb1.js → v2-archive-reader-8dsngf2j.js} +1 -1
- package/dist/{wrapup-orchestrator-k29zqfp9.js → wrapup-orchestrator-sm6pwf3p.js} +20 -19
- package/package.json +1 -1
- package/src/shared/models-dev-cache.ts +90 -21
- package/src/shared/reusable-worker.test.ts +31 -29
- package/src/shared/sqlite.test.ts +19 -6
- package/src/shared/storage-file-mutex-review.test.ts +125 -2
- package/src/shared/storage-file-mutex.ts +17 -8
- package/src/shared/storage-permissions-creators.test.ts +194 -0
- package/src/shared/storage-permissions-startup.test.ts +476 -0
- package/src/shared/storage-permissions.ts +227 -12
- package/src/shared/test-db.test.ts +5 -3
- package/src/shared/test-git-env.test.ts +38 -0
- package/src/shared/test-git-env.ts +10 -0
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from "./server-gzy5w8ya.js";
|
|
16
16
|
import {
|
|
17
17
|
setBootQuietPeriodForTests
|
|
18
|
-
} from "./server-
|
|
18
|
+
} from "./server-rz4snd3x.js";
|
|
19
19
|
import {
|
|
20
20
|
isEmbeddingHostBusy2
|
|
21
21
|
} from "./server-qt1qqasc.js";
|
|
@@ -68,7 +68,7 @@ import {
|
|
|
68
68
|
findMisScopedCompartmentChunkEmbeddingIdsForProject,
|
|
69
69
|
recordSessionProjectIdentity,
|
|
70
70
|
repairMisScopedCompartmentChunkEmbeddingsForProject
|
|
71
|
-
} from "./server-
|
|
71
|
+
} from "./server-3p6b0qya.js";
|
|
72
72
|
import {
|
|
73
73
|
saveEmbeddingIfHashMatches,
|
|
74
74
|
getMemoryEmbedCoverage,
|
|
@@ -83,7 +83,7 @@ import {
|
|
|
83
83
|
logLocalEmbeddingPoolingUnavailableOnce,
|
|
84
84
|
getEmbeddingProviderIdentity,
|
|
85
85
|
LocalEmbeddingProvider
|
|
86
|
-
} from "./server-
|
|
86
|
+
} from "./server-b93f0bqh.js";
|
|
87
87
|
import {
|
|
88
88
|
isKnownAutocommit
|
|
89
89
|
} from "./server-8ajstryz.js";
|
|
@@ -1407,12 +1407,17 @@ function snapshotFor(registration) {
|
|
|
1407
1407
|
...synapseDescriptor ? { synapseDescriptor } : {}
|
|
1408
1408
|
};
|
|
1409
1409
|
}
|
|
1410
|
+
var pendingProviderDisposals = new Set;
|
|
1410
1411
|
function disposeProvider(provider) {
|
|
1411
1412
|
if (!provider)
|
|
1412
|
-
return;
|
|
1413
|
-
provider.dispose().catch((error) => {
|
|
1413
|
+
return Promise.resolve();
|
|
1414
|
+
const disposal = provider.dispose().catch((error) => {
|
|
1414
1415
|
log2("[magic-context] embedding provider dispose failed:", error);
|
|
1416
|
+
}).finally(() => {
|
|
1417
|
+
pendingProviderDisposals.delete(disposal);
|
|
1415
1418
|
});
|
|
1419
|
+
pendingProviderDisposals.add(disposal);
|
|
1420
|
+
return disposal;
|
|
1416
1421
|
}
|
|
1417
1422
|
function getUpsertActiveIdentityStatement(db) {
|
|
1418
1423
|
let stmt = upsertActiveIdentityStatements.get(db);
|
|
@@ -1775,7 +1780,7 @@ function registerProjectShadowEmbedding2(db, projectIdentity, config, sourceDire
|
|
|
1775
1780
|
return null;
|
|
1776
1781
|
const prior = shadowRegistrations.get(projectIdentity);
|
|
1777
1782
|
if (prior && prior.providerIdentity === providerIdentity) {
|
|
1778
|
-
provider
|
|
1783
|
+
disposeProvider(provider);
|
|
1779
1784
|
dbForShadowQueue.set(projectIdentity, db);
|
|
1780
1785
|
persistShadowDescriptor(db, prior);
|
|
1781
1786
|
const backfillAlreadyArmed = hasPendingShadowBackfill(projectIdentity) || shadowQueue.some((item) => item.projectIdentity === projectIdentity);
|
|
@@ -2428,13 +2433,15 @@ function unregisterProjectEmbedding2(projectIdentity) {
|
|
|
2428
2433
|
const prior = projectRegistrations.get(projectIdentity);
|
|
2429
2434
|
const shadow = shadowRegistrations.get(projectIdentity);
|
|
2430
2435
|
if (!prior && !shadow)
|
|
2431
|
-
return;
|
|
2436
|
+
return Promise.resolve();
|
|
2432
2437
|
projectRegistrations.delete(projectIdentity);
|
|
2433
2438
|
shadowRegistrations.delete(projectIdentity);
|
|
2434
2439
|
dbForShadowQueue.delete(projectIdentity);
|
|
2435
2440
|
globalRegistrationGeneration += 1;
|
|
2436
|
-
|
|
2437
|
-
|
|
2441
|
+
return Promise.all([
|
|
2442
|
+
disposeProvider(prior?.provider ?? null),
|
|
2443
|
+
disposeProvider(shadow?.provider ?? null)
|
|
2444
|
+
]).then(() => {});
|
|
2438
2445
|
}
|
|
2439
2446
|
function getProjectEmbeddingSnapshot2(projectIdentity) {
|
|
2440
2447
|
const registration = projectRegistrations.get(projectIdentity);
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "./server-gzy5w8ya.js";
|
|
14
14
|
import {
|
|
15
15
|
scheduleAfterBootQuiet
|
|
16
|
-
} from "./server-
|
|
16
|
+
} from "./server-rz4snd3x.js";
|
|
17
17
|
import {
|
|
18
18
|
getHarness2,
|
|
19
19
|
harnessOwnsOpenCodeStore2
|
|
@@ -39,6 +39,14 @@ import {
|
|
|
39
39
|
import {
|
|
40
40
|
configureContextDatabasePragmas2
|
|
41
41
|
} from "./server-fb3zxn06.js";
|
|
42
|
+
import {
|
|
43
|
+
shouldEnforcePrivateStoragePermissions,
|
|
44
|
+
ensureStorageDirectorySync,
|
|
45
|
+
writeStorageFileSync,
|
|
46
|
+
copyStorageFileSync,
|
|
47
|
+
copyStorageTreeSync,
|
|
48
|
+
tightenStorageTreeSync
|
|
49
|
+
} from "./server-r2es6zt7.js";
|
|
42
50
|
import {
|
|
43
51
|
attachFailClosedBlockingProcessEvidence
|
|
44
52
|
} from "./server-39bcszk4.js";
|
|
@@ -57,14 +65,14 @@ import {
|
|
|
57
65
|
hasPendingMigrations,
|
|
58
66
|
getMainThreadMigrationBodyCount,
|
|
59
67
|
runMigrations
|
|
60
|
-
} from "./server-
|
|
68
|
+
} from "./server-ps6rz88g.js";
|
|
61
69
|
import {
|
|
70
|
+
ensureColumn,
|
|
62
71
|
setDatabase,
|
|
63
72
|
loadToolDefinitionMeasurements,
|
|
64
|
-
ensureColumn,
|
|
65
73
|
installV95PerfSchema,
|
|
66
74
|
installTagIdentityRevisionTrigger
|
|
67
|
-
} from "./server-
|
|
75
|
+
} from "./server-a2f1bhyj.js";
|
|
68
76
|
import {
|
|
69
77
|
resolveOpenCodeDbPath,
|
|
70
78
|
hasV1MessageTables
|
|
@@ -78,14 +86,6 @@ import {
|
|
|
78
86
|
import {
|
|
79
87
|
logSlowWriteTransaction
|
|
80
88
|
} from "./server-5sbsnpkn.js";
|
|
81
|
-
import {
|
|
82
|
-
shouldEnforcePrivateStoragePermissions,
|
|
83
|
-
ensureStorageDirectorySync,
|
|
84
|
-
writeStorageFileSync,
|
|
85
|
-
copyStorageFileSync,
|
|
86
|
-
copyStorageTreeSync,
|
|
87
|
-
tightenStorageTreeSync
|
|
88
|
-
} from "./server-fvnzcnww.js";
|
|
89
89
|
|
|
90
90
|
// src/features/magic-context/storage-db.ts
|
|
91
91
|
import {
|
|
@@ -586,8 +586,8 @@ var BOOT_SQLITE_BUSY_TIMEOUT_MS = 5000;
|
|
|
586
586
|
function ensureSecureStorageDir(dir) {
|
|
587
587
|
ensureStorageDirectorySync(dir);
|
|
588
588
|
}
|
|
589
|
-
function tightenStorageTree(
|
|
590
|
-
const { failures } = tightenStorageTreeSync(
|
|
589
|
+
function tightenStorageTree(dbPath) {
|
|
590
|
+
const { failures } = tightenStorageTreeSync(dirname(dbPath), dbPath);
|
|
591
591
|
log2(`[magic-context] storage permission tightening failures=${failures}`);
|
|
592
592
|
}
|
|
593
593
|
function resolveBootBusyTimeoutMs(value) {
|
|
@@ -1021,7 +1021,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
1021
1021
|
state.running = startMessageFtsRowidMapBackfill2(db, signal).then(async () => {
|
|
1022
1022
|
if (signal.aborted || !readsOpenCodeStore)
|
|
1023
1023
|
return;
|
|
1024
|
-
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-
|
|
1024
|
+
const { readRawSessionMessagePage, readRawSessionMessages } = await importPluginModule(() => import("./read-session-chunk-n3nhfvd7.js"));
|
|
1025
1025
|
const { startMessageTimeBackfill } = await importPluginModule(() => import("./message-time-backfill-ynb3vg6r.js"));
|
|
1026
1026
|
if (signal.aborted)
|
|
1027
1027
|
return;
|
|
@@ -1047,7 +1047,7 @@ function finishDatabaseOpen(db, dbPath, explicitDbPath, latestSupportedVersion)
|
|
|
1047
1047
|
}
|
|
1048
1048
|
setDatabase(db);
|
|
1049
1049
|
loadToolDefinitionMeasurements(db);
|
|
1050
|
-
tightenStorageTree(
|
|
1050
|
+
tightenStorageTree(dbPath);
|
|
1051
1051
|
databases.set(dbPath, db);
|
|
1052
1052
|
pathByDatabase.set(db, dbPath);
|
|
1053
1053
|
persistenceByDatabase.set(db, true);
|
|
@@ -2347,7 +2347,7 @@ function openDatabase(dbPathOrOptions) {
|
|
|
2347
2347
|
migrateLegacyStorageIfNeeded(dbPath, dbDir);
|
|
2348
2348
|
}
|
|
2349
2349
|
ensureSecureStorageDir(dbDir);
|
|
2350
|
-
tightenStorageTree(
|
|
2350
|
+
tightenStorageTree(dbPath);
|
|
2351
2351
|
if (!existsSync2(dbPath) && shouldEnforcePrivateStoragePermissions()) {
|
|
2352
2352
|
try {
|
|
2353
2353
|
writeStorageFileSync(dbPath, new Uint8Array, { flag: "wx" });
|
|
@@ -2444,7 +2444,7 @@ async function openDatabaseAsync(dbPathOrOptions) {
|
|
|
2444
2444
|
if (!explicitDbPath)
|
|
2445
2445
|
migrateLegacyStorageIfNeeded(dbPath, dbDir);
|
|
2446
2446
|
ensureSecureStorageDir(dbDir);
|
|
2447
|
-
tightenStorageTree(
|
|
2447
|
+
tightenStorageTree(dbPath);
|
|
2448
2448
|
if (!existsSync2(dbPath) && shouldEnforcePrivateStoragePermissions()) {
|
|
2449
2449
|
try {
|
|
2450
2450
|
writeStorageFileSync(dbPath, new Uint8Array, { flag: "wx" });
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
ensureColumn,
|
|
9
9
|
healAllNullColumns,
|
|
10
10
|
installV95PerfSchema
|
|
11
|
-
} from "./server-
|
|
11
|
+
} from "./server-a2f1bhyj.js";
|
|
12
12
|
import {
|
|
13
13
|
resolveOpenCodeDbPath,
|
|
14
14
|
openCodeDbPathExists,
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import {
|
|
21
21
|
normalizeStoredProjectPath,
|
|
22
22
|
storedPathBelongsToIdentity
|
|
23
|
-
} from "./server-
|
|
23
|
+
} from "./server-rz4snd3x.js";
|
|
24
24
|
import {
|
|
25
25
|
logSlowWriteTransaction
|
|
26
26
|
} from "./server-5sbsnpkn.js";
|
|
@@ -736,6 +736,29 @@ class V2StoreReader2 {
|
|
|
736
736
|
return null;
|
|
737
737
|
}
|
|
738
738
|
}
|
|
739
|
+
revertSuffix(sessionID, cutoff, limit) {
|
|
740
|
+
const rows = this.prepare(`WITH target AS (SELECT seq FROM session_message WHERE session_id = ? AND id = ?),
|
|
741
|
+
preceding AS (SELECT MAX(seq) AS seq FROM session_message
|
|
742
|
+
WHERE session_id = ? AND seq < (SELECT seq FROM target))
|
|
743
|
+
SELECT id, seq FROM session_message
|
|
744
|
+
WHERE session_id = ? AND seq >= (SELECT seq FROM preceding)
|
|
745
|
+
ORDER BY seq ASC LIMIT ?`).all(sessionID, cutoff, sessionID, sessionID, limit + 2);
|
|
746
|
+
const [predecessor, boundary] = rows;
|
|
747
|
+
if (!predecessor || boundary?.id !== cutoff || rows.length > limit + 1)
|
|
748
|
+
return;
|
|
749
|
+
return { predecessor, messageIDs: rows.slice(1).map(({ id }) => id) };
|
|
750
|
+
}
|
|
751
|
+
removedRevertMessages(sessionID, suffix) {
|
|
752
|
+
const { predecessor, messageIDs } = suffix;
|
|
753
|
+
const result = this.prepare(`SELECT CASE WHEN EXISTS (SELECT 1 FROM session_v2 WHERE id = ?)
|
|
754
|
+
AND EXISTS (SELECT 1 FROM session_message
|
|
755
|
+
WHERE session_id = ? AND id = ? AND seq = ?)
|
|
756
|
+
THEN (SELECT json_group_array(value) FROM json_each(?) AS staged
|
|
757
|
+
WHERE NOT EXISTS (SELECT 1 FROM session_message AS retained
|
|
758
|
+
WHERE retained.session_id = ? AND retained.id = staged.value))
|
|
759
|
+
END AS missing`).get(sessionID, sessionID, predecessor.id, predecessor.seq, JSON.stringify(messageIDs), sessionID);
|
|
760
|
+
return result.missing === null ? undefined : new Set(JSON.parse(result.missing));
|
|
761
|
+
}
|
|
739
762
|
sessionExists(sessionID) {
|
|
740
763
|
return this.prepare("SELECT 1 FROM session_v2 WHERE id = ?").get(sessionID) != null;
|
|
741
764
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPidAlive
|
|
3
|
+
} from "./server-jdfe07mp.js";
|
|
4
|
+
|
|
1
5
|
// src/shared/storage-permissions.ts
|
|
2
6
|
import { randomBytes } from "node:crypto";
|
|
3
7
|
import {
|
|
4
8
|
chmodSync,
|
|
5
9
|
closeSync,
|
|
10
|
+
constants,
|
|
6
11
|
createWriteStream,
|
|
12
|
+
fstatSync,
|
|
7
13
|
fsyncSync,
|
|
8
14
|
lstatSync,
|
|
9
15
|
mkdirSync,
|
|
@@ -12,16 +18,46 @@ import {
|
|
|
12
18
|
readlinkSync,
|
|
13
19
|
readSync,
|
|
14
20
|
renameSync,
|
|
21
|
+
rmdirSync,
|
|
15
22
|
rmSync,
|
|
16
23
|
symlinkSync,
|
|
17
24
|
writeFileSync,
|
|
18
25
|
writeSync
|
|
19
26
|
} from "node:fs";
|
|
20
27
|
import { open as openAsync, writeFile as writeFileAsync } from "node:fs/promises";
|
|
21
|
-
import { dirname, join } from "node:path";
|
|
28
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
22
29
|
var enforcePrivateStoragePermissions = true;
|
|
30
|
+
var STORAGE_PERMISSIONS_POLICY_VERSION = 1;
|
|
31
|
+
var STORAGE_PERMISSIONS_MARKER = `.storage-permissions-v${STORAGE_PERMISSIONS_POLICY_VERSION}`;
|
|
32
|
+
var STORAGE_PERMISSIONS_MARKER_BYTES = Buffer.from(`${STORAGE_PERMISSIONS_POLICY_VERSION}
|
|
33
|
+
`);
|
|
34
|
+
var STORAGE_PERMISSIONS_MARKER_MAX_AGE_MS = 24 * 60 * 60000;
|
|
35
|
+
var LEGACY_FENCE_TEMP_MIN_AGE_MS = 10 * 60000;
|
|
36
|
+
var storagePermissionRoots = new Set;
|
|
37
|
+
function invalidateStoragePermissionMarkers(directory) {
|
|
38
|
+
for (let current = resolve(directory);; current = dirname(current)) {
|
|
39
|
+
const marker = join(current, STORAGE_PERMISSIONS_MARKER);
|
|
40
|
+
try {
|
|
41
|
+
rmSync(marker, { force: true });
|
|
42
|
+
} catch (error) {
|
|
43
|
+
const stat = lstatSync(marker, { throwIfNoEntry: false });
|
|
44
|
+
if (stat?.isFile() || !stat && error.code !== "EROFS") {
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (storagePermissionRoots.has(current) || dirname(current) === current)
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
23
52
|
function setStoragePrivatePermissionEnforcement(enforce) {
|
|
24
53
|
enforcePrivateStoragePermissions = enforce;
|
|
54
|
+
if (enforce || process.platform === "win32")
|
|
55
|
+
return;
|
|
56
|
+
for (const root of storagePermissionRoots) {
|
|
57
|
+
try {
|
|
58
|
+
rmSync(join(root, STORAGE_PERMISSIONS_MARKER), { force: true });
|
|
59
|
+
} catch {}
|
|
60
|
+
}
|
|
25
61
|
}
|
|
26
62
|
function shouldEnforcePrivateStoragePermissions() {
|
|
27
63
|
return enforcePrivateStoragePermissions;
|
|
@@ -38,8 +74,11 @@ function ensurePrivateStorageDirectorySync(directory) {
|
|
|
38
74
|
const stat = lstatSync(directory);
|
|
39
75
|
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
40
76
|
throw new Error("Private storage directory is not a real directory");
|
|
41
|
-
if (process.platform !== "win32")
|
|
77
|
+
if (process.platform !== "win32") {
|
|
78
|
+
if ((stat.mode & 511) !== 448)
|
|
79
|
+
invalidateStoragePermissionMarkers(directory);
|
|
42
80
|
chmodSync(directory, 448);
|
|
81
|
+
}
|
|
43
82
|
}
|
|
44
83
|
function writeStorageFileSync(filePath, content, options = {}) {
|
|
45
84
|
const { forcePrivate = false, ...writeOptions } = options;
|
|
@@ -68,10 +107,9 @@ function syncStorageDirectorySync(directory) {
|
|
|
68
107
|
closeSync(fd);
|
|
69
108
|
}
|
|
70
109
|
}
|
|
71
|
-
function writeStorageFileDurableAtomicSync(filePath, content, afterTempSync) {
|
|
110
|
+
function writeStorageFileDurableAtomicSync(filePath, content, afterTempSync, tempPath = `${filePath}.${process.pid}.${randomBytes(12).toString("hex")}.tmp`) {
|
|
72
111
|
const directory = dirname(filePath);
|
|
73
112
|
ensurePrivateStorageDirectorySync(directory);
|
|
74
|
-
const tempPath = `${filePath}.${process.pid}.${randomBytes(12).toString("hex")}.tmp`;
|
|
75
113
|
let fd;
|
|
76
114
|
try {
|
|
77
115
|
fd = openStorageFileSync(tempPath, "wx", true);
|
|
@@ -153,24 +191,122 @@ async function createStorageFileHandleAsync(filePath, flags, forcePrivate = fals
|
|
|
153
191
|
const privateMode = forcePrivate || shouldEnforcePrivateStoragePermissions();
|
|
154
192
|
return openAsync(filePath, flags, privateMode ? 384 : undefined);
|
|
155
193
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
194
|
+
function readStoragePermissionCertificate(marker) {
|
|
195
|
+
const fd = openSync(marker, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
196
|
+
try {
|
|
197
|
+
const stat = fstatSync(fd);
|
|
198
|
+
const age = Date.now() - Math.floor(stat.mtimeMs);
|
|
199
|
+
if (!stat.isFile() || (stat.mode & 4095) !== 384 || stat.uid !== process.getuid?.() || stat.size !== STORAGE_PERMISSIONS_MARKER_BYTES.length || age < 0 || age >= STORAGE_PERMISSIONS_MARKER_MAX_AGE_MS) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const buffer = Buffer.alloc(STORAGE_PERMISSIONS_MARKER_BYTES.length + 1);
|
|
203
|
+
const bytesRead = readSync(fd, buffer, 0, buffer.length, 0);
|
|
204
|
+
if (bytesRead === STORAGE_PERMISSIONS_MARKER_BYTES.length && buffer.subarray(0, bytesRead).equals(STORAGE_PERMISSIONS_MARKER_BYTES)) {
|
|
205
|
+
return stat;
|
|
206
|
+
}
|
|
207
|
+
} finally {
|
|
208
|
+
closeSync(fd);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function tightenStorageTreeSync(directory, dbPath = join(directory, "context.db")) {
|
|
212
|
+
if (process.platform === "win32") {
|
|
158
213
|
return { tightened: 0, failures: 0 };
|
|
159
214
|
}
|
|
215
|
+
const root = resolve(directory);
|
|
216
|
+
const marker = join(root, STORAGE_PERMISSIONS_MARKER);
|
|
160
217
|
let tightened = 0;
|
|
161
218
|
let failures = 0;
|
|
162
|
-
|
|
163
|
-
|
|
219
|
+
let keptLegacyTemp = false;
|
|
220
|
+
const removeMarker = () => {
|
|
164
221
|
try {
|
|
165
|
-
|
|
222
|
+
rmSync(marker, { force: true });
|
|
223
|
+
return true;
|
|
166
224
|
} catch {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
if (!shouldEnforcePrivateStoragePermissions()) {
|
|
229
|
+
storagePermissionRoots.add(root);
|
|
230
|
+
if (!removeMarker())
|
|
231
|
+
failures++;
|
|
232
|
+
return { tightened, failures };
|
|
233
|
+
}
|
|
234
|
+
let rootStat;
|
|
235
|
+
try {
|
|
236
|
+
rootStat = lstatSync(root);
|
|
237
|
+
if (!rootStat.isDirectory())
|
|
238
|
+
return { tightened, failures: 1 };
|
|
239
|
+
} catch {
|
|
240
|
+
return { tightened, failures: 1 };
|
|
241
|
+
}
|
|
242
|
+
storagePermissionRoots.add(root);
|
|
243
|
+
let certificate;
|
|
244
|
+
let discardMarker = false;
|
|
245
|
+
try {
|
|
246
|
+
certificate = readStoragePermissionCertificate(marker);
|
|
247
|
+
discardMarker = certificate === undefined;
|
|
248
|
+
} catch (error) {
|
|
249
|
+
discardMarker = error.code !== "ENOENT";
|
|
250
|
+
}
|
|
251
|
+
let markerRemoved;
|
|
252
|
+
const fenceDirectory = join(root, "lkg-recovery-fences");
|
|
253
|
+
const visit = (entryPath, recursive = true, optional = false, stat) => {
|
|
254
|
+
try {
|
|
255
|
+
stat ??= lstatSync(entryPath);
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (!optional || error.code !== "ENOENT")
|
|
258
|
+
failures++;
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (entryPath === root && !stat.isDirectory()) {
|
|
167
262
|
failures++;
|
|
168
263
|
return;
|
|
169
264
|
}
|
|
170
265
|
if (stat.isSymbolicLink())
|
|
171
266
|
return;
|
|
267
|
+
if (entryPath === marker && !stat.isDirectory())
|
|
268
|
+
return;
|
|
269
|
+
if (!certificate && dirname(entryPath) === fenceDirectory) {
|
|
270
|
+
const name = basename(entryPath);
|
|
271
|
+
const legacyTemp = stat.isFile() && /^.+\.json\..+\.tmp$/.test(name);
|
|
272
|
+
if (legacyTemp) {
|
|
273
|
+
const publisherPid = /^.+\.json\.([1-9]\d*)\.[a-f0-9]{24}\.tmp$/.exec(name)?.[1];
|
|
274
|
+
if (Date.now() - stat.mtimeMs <= LEGACY_FENCE_TEMP_MIN_AGE_MS || publisherPid && isPidAlive(Number(publisherPid)) !== "dead") {
|
|
275
|
+
keptLegacyTemp = true;
|
|
276
|
+
} else {
|
|
277
|
+
try {
|
|
278
|
+
rmSync(entryPath, { force: true });
|
|
279
|
+
} catch {
|
|
280
|
+
failures++;
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (stat.isDirectory() && name.endsWith(".json.locks")) {
|
|
286
|
+
try {
|
|
287
|
+
lstatSync(entryPath.slice(0, -".locks".length));
|
|
288
|
+
} catch (error) {
|
|
289
|
+
if (error.code === "ENOENT") {
|
|
290
|
+
try {
|
|
291
|
+
rmdirSync(entryPath);
|
|
292
|
+
return;
|
|
293
|
+
} catch (cleanupError) {
|
|
294
|
+
const code = cleanupError.code;
|
|
295
|
+
if (code === "ENOENT")
|
|
296
|
+
return;
|
|
297
|
+
if (code !== "ENOTEMPTY" && code !== "EEXIST")
|
|
298
|
+
failures++;
|
|
299
|
+
}
|
|
300
|
+
} else
|
|
301
|
+
failures++;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
172
305
|
const mode = stat.isDirectory() ? 448 : 384;
|
|
173
306
|
if ((stat.mode & 63) !== 0 || (stat.mode & 511) !== mode) {
|
|
307
|
+
if (certificate) {
|
|
308
|
+
markerRemoved ??= removeMarker();
|
|
309
|
+
}
|
|
174
310
|
try {
|
|
175
311
|
chmodSync(entryPath, mode);
|
|
176
312
|
tightened++;
|
|
@@ -178,7 +314,7 @@ function tightenStorageTreeSync(root) {
|
|
|
178
314
|
failures++;
|
|
179
315
|
}
|
|
180
316
|
}
|
|
181
|
-
if (!stat.isDirectory())
|
|
317
|
+
if (!recursive || !stat.isDirectory())
|
|
182
318
|
return;
|
|
183
319
|
let entries;
|
|
184
320
|
try {
|
|
@@ -190,7 +326,52 @@ function tightenStorageTreeSync(root) {
|
|
|
190
326
|
for (const entry of entries)
|
|
191
327
|
visit(join(entryPath, entry));
|
|
192
328
|
};
|
|
193
|
-
|
|
329
|
+
if (certificate) {
|
|
330
|
+
visit(root, false, false, rootStat);
|
|
331
|
+
visit(dbPath, false, true);
|
|
332
|
+
visit(`${dbPath}-wal`, false, true);
|
|
333
|
+
visit(`${dbPath}-shm`, false, true);
|
|
334
|
+
visit(join(root, "models"), true, true);
|
|
335
|
+
visit(join(root, "logs"), true, true);
|
|
336
|
+
if (markerRemoved !== undefined) {
|
|
337
|
+
certificate = undefined;
|
|
338
|
+
visit(root);
|
|
339
|
+
if (!markerRemoved && !removeMarker())
|
|
340
|
+
failures++;
|
|
341
|
+
} else if (failures > 0) {
|
|
342
|
+
if (!removeMarker())
|
|
343
|
+
failures++;
|
|
344
|
+
} else {
|
|
345
|
+
let markerChanged;
|
|
346
|
+
try {
|
|
347
|
+
const current = lstatSync(marker);
|
|
348
|
+
markerChanged = current.dev !== certificate.dev || current.ino !== certificate.ino || current.ctimeMs !== certificate.ctimeMs;
|
|
349
|
+
} catch (error) {
|
|
350
|
+
markerChanged = true;
|
|
351
|
+
discardMarker = error.code !== "ENOENT";
|
|
352
|
+
}
|
|
353
|
+
if (markerChanged) {
|
|
354
|
+
certificate = undefined;
|
|
355
|
+
visit(root);
|
|
356
|
+
if (discardMarker && !removeMarker())
|
|
357
|
+
failures++;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
} else {
|
|
361
|
+
visit(root, true, false, rootStat);
|
|
362
|
+
if (discardMarker && !removeMarker())
|
|
363
|
+
failures++;
|
|
364
|
+
if (failures === 0 && !keptLegacyTemp) {
|
|
365
|
+
try {
|
|
366
|
+
writeStorageFileSync(marker, STORAGE_PERMISSIONS_MARKER_BYTES, {
|
|
367
|
+
flag: "wx"
|
|
368
|
+
});
|
|
369
|
+
} catch (error) {
|
|
370
|
+
if (error.code !== "EEXIST")
|
|
371
|
+
failures++;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
194
375
|
return { tightened, failures };
|
|
195
376
|
}
|
|
196
377
|
|
|
@@ -2,15 +2,15 @@ import {
|
|
|
2
2
|
getMagicContextStorageDir,
|
|
3
3
|
log2
|
|
4
4
|
} from "./server-j8376q08.js";
|
|
5
|
+
import {
|
|
6
|
+
writeStorageFileAtomicSync
|
|
7
|
+
} from "./server-r2es6zt7.js";
|
|
5
8
|
import {
|
|
6
9
|
inRootAsyncContext2
|
|
7
10
|
} from "./server-gzy5w8ya.js";
|
|
8
11
|
import {
|
|
9
12
|
projectDirectoryKey
|
|
10
13
|
} from "./server-knvkbfvh.js";
|
|
11
|
-
import {
|
|
12
|
-
writeStorageFileAtomicSync
|
|
13
|
-
} from "./server-fvnzcnww.js";
|
|
14
14
|
|
|
15
15
|
// src/features/magic-context/memory/project-identity.ts
|
|
16
16
|
import { execFileSync } from "node:child_process";
|