@cortexkit/opencode-magic-context 0.49.47 → 0.49.49
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-g789dmt6.js → announcement-9pr71hd5.js} +3 -2
- package/dist/auto-search-worker.js +5 -5
- package/dist/chunk-embedding-write-worker.js +14 -15
- package/dist/{compaction-marker-candidates-dkfp1q9j.js → compaction-marker-candidates-8hazqfvj.js} +2 -3
- package/dist/compaction-marker-candidates-worker.js +1 -1
- package/dist/{compartment-chunk-embedding-snj51nmg.js → compartment-chunk-embedding-gfd093f8.js} +7 -8
- package/dist/{conflict-warning-hook-w1aw6w5t.js → conflict-warning-hook-56qpq7ws.js} +7 -8
- package/dist/{context-hvkjxqhs.js → context-bwf57gnh.js} +41 -43
- package/dist/{derive-budgets-nkw09vq7.js → derive-budgets-z53424qx.js} +2 -3
- package/dist/{embedding-backfill-kpy5shsa.js → embedding-backfill-d9x9q2e2.js} +12 -13
- package/dist/embedding-worker-process.js +2 -3
- package/dist/embedding-worker.js +5 -6
- package/dist/features/magic-context/dreamer/docs-proposals.d.ts.map +1 -1
- package/dist/{history-owner-0z620wgz.js → history-owner-n50e0e8y.js} +2 -3
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +5 -3
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/todo-view.d.ts +29 -17
- package/dist/hooks/magic-context/todo-view.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/{index-txs8tce6.js → index-0k283v27.js} +2 -4
- package/dist/{index-s79g172v.js → index-0mdh2cke.js} +10 -10
- package/dist/{index-ak11t3gm.js → index-0tz2fzpq.js} +1 -1
- package/dist/{index-2qbtqg1w.js → index-25tm250q.js} +1 -1
- package/dist/{index-h9m41624.js → index-2ny9xwdn.js} +2 -2
- package/dist/{index-xa9mmq6c.js → index-36wseasx.js} +1 -1
- package/dist/{index-sd2s4t4p.js → index-3n9ee4jh.js} +2 -2
- package/dist/{index-xgczbhyx.js → index-5850zme4.js} +3 -3
- package/dist/{index-5jk4h64j.js → index-5bksfv58.js} +13 -15
- package/dist/{index-esr8qcc4.js → index-7n2n3v92.js} +5 -5
- package/dist/{index-jrfre9ah.js → index-82dfe8en.js} +146 -5
- package/dist/{index-gn6gfz4y.js → index-90z05d0p.js} +1 -1
- package/dist/{index-9wnbnx8f.js → index-a6aqpfp6.js} +1 -1
- package/dist/{index-b0xt5qz9.js → index-agfh931z.js} +11 -13
- package/dist/{index-d4qw2h43.js → index-arxg51bj.js} +4 -4
- package/dist/{index-x53gnmce.js → index-bkg4hdyh.js} +6 -28
- package/dist/{index-gp3kcpc4.js → index-cd3vp8xa.js} +1 -1
- package/dist/{index-44pp3vrj.js → index-cs7pmwt6.js} +4 -4
- package/dist/{index-brj6was5.js → index-em92bp7f.js} +2 -2
- package/dist/{index-2p37txes.js → index-ga5q492k.js} +1 -1
- package/dist/{index-8cfnaagj.js → index-gapnh6tk.js} +2 -4
- package/dist/{index-fw42ms3m.js → index-gz001bx7.js} +1 -1
- package/dist/{index-kw7azjmy.js → index-h3p558ec.js} +3 -3
- package/dist/{index-qcz1fy7h.js → index-hexdee98.js} +4 -4
- package/dist/{index-smtbdmc3.js → index-hsv31e69.js} +2 -2
- package/dist/{index-dj2p8653.js → index-hsyczpn7.js} +2 -2
- package/dist/{index-c99tqfge.js → index-j7verehm.js} +93 -73
- package/dist/{index-etn2hmb5.js → index-jedbxq6n.js} +4 -4
- package/dist/{index-2x3kd999.js → index-k47v0tmk.js} +16 -18
- package/dist/{index-1hwn96x1.js → index-kn1bx21r.js} +3 -3
- package/dist/{index-nj360hcs.js → index-pb8ysnq2.js} +4 -4
- package/dist/{index-xgnh498s.js → index-qb75tv9j.js} +8 -8
- package/dist/{index-jz5bk7xd.js → index-qperbvjn.js} +2 -2
- package/dist/{index-25ka1jza.js → index-r9agn061.js} +4 -4
- package/dist/{index-hacf2tyx.js → index-reyws9fy.js} +1 -1
- package/dist/{index-fxbk7gk3.js → index-tad3can2.js} +1 -1
- package/dist/{index-hkh8x221.js → index-tj5gz396.js} +3 -5
- package/dist/{index-bqhjzhv4.js → index-va9x7y48.js} +35 -31
- package/dist/{index-37a9bfta.js → index-vbmh68fb.js} +6 -6
- package/dist/{index-1qmv26ga.js → index-vyv4tame.js} +12 -14
- package/dist/{index-eej9kwad.js → index-wdmfnmv1.js} +5 -5
- package/dist/index.js +53 -55
- package/dist/{logger-qwnbcfj9.js → logger-sw7z6sjz.js} +1 -2
- package/dist/{message-fts-rowid-map-msffhkve.js → message-fts-rowid-map-kx1bsdyg.js} +4 -5
- package/dist/{message-index-bounded-3qpg8dq5.js → message-index-bounded-2shxmht9.js} +11 -12
- package/dist/{message-time-backfill-39bm498k.js → message-time-backfill-hp2jgn49.js} +2 -3
- package/dist/migration-worker.js +12 -13
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/{project-embedding-registry-r6xfsrbe.js → project-embedding-registry-nzgkq61z.js} +11 -12
- package/dist/raw-ordinal-warmup-worker.js +8 -8
- package/dist/{read-session-chunk-7h9f32sz.js → read-session-chunk-c15y8yg6.js} +9 -10
- package/dist/{read-session-raw-x7a9b3jm.js → read-session-raw-04ger9zt.js} +2 -3
- package/dist/{recomp-orchestrator-43g9tjya.js → recomp-orchestrator-gfxqqpph.js} +30 -31
- package/dist/{render-4m7x9cq4.js → render-5tx8r0me.js} +20 -21
- package/dist/{safe-notification-target-wztd7bgk.js → safe-notification-target-mx5khyxf.js} +2 -3
- package/dist/{search-archive-f6kwv02s.js → search-archive-6tgh88xp.js} +11 -12
- package/dist/{search-0a3hh5x6.js → search-k2n5bvsk.js} +23 -24
- package/dist/{send-session-notification-j93pn2hn.js → send-session-notification-gamjee2f.js} +5 -6
- package/dist/shared/data-path.d.ts +7 -13
- package/dist/shared/data-path.d.ts.map +1 -1
- package/dist/{storage-tags-q8erkn48.js → storage-tags-kdb4qsyq.js} +4 -5
- package/dist/{transform-postprocess-phase-5746a5b6.js → transform-postprocess-phase-36dw4kxb.js} +31 -32
- package/dist/v2/auto-search-worker.js +5 -5
- package/dist/v2/chunk-embedding-write-worker.js +14 -14
- package/dist/v2/{compaction-marker-candidates-y737qb1v.js → compaction-marker-candidates-re14353a.js} +2 -2
- package/dist/v2/compaction-marker-candidates-worker.js +1 -1
- package/dist/v2/{compartment-chunk-embedding-nj5nrnbj.js → compartment-chunk-embedding-0pxsrzrt.js} +7 -7
- package/dist/v2/{context-e9n2mxax.js → context-td3jyze3.js} +90 -68
- package/dist/v2/{derive-budgets-b5cgrtp8.js → derive-budgets-w0815q82.js} +3 -3
- package/dist/v2/{embedding-backfill-360efh1t.js → embedding-backfill-5dqdm3ff.js} +12 -12
- package/dist/v2/embedding-worker-process.js +1 -1
- package/dist/v2/embedding-worker.js +4 -4
- package/dist/v2/{history-owner-fpka43cn.js → history-owner-ep91wgqj.js} +2 -2
- package/dist/v2/{logger-4cj6d03m.js → logger-xnscpj6w.js} +1 -1
- package/dist/v2/{message-fts-rowid-map-qe7cpksd.js → message-fts-rowid-map-57jh6xpb.js} +4 -4
- package/dist/v2/{message-index-bounded-na8debr6.js → message-index-bounded-j1jskn8a.js} +11 -11
- package/dist/v2/{message-time-backfill-0c4h7sg6.js → message-time-backfill-baxebka0.js} +2 -2
- package/dist/v2/migration-worker.js +11 -11
- package/dist/v2/{project-embedding-registry-ek0cy0d5.js → project-embedding-registry-swm4mw1t.js} +11 -11
- package/dist/v2/raw-ordinal-warmup-worker.js +8 -8
- package/dist/v2/{read-session-chunk-x33xeg2g.js → read-session-chunk-carzw3m8.js} +9 -9
- package/dist/v2/{read-session-raw-yss2ev98.js → read-session-raw-3e482h3c.js} +2 -2
- package/dist/v2/{recomp-orchestrator-jyjpn5jm.js → recomp-orchestrator-e7vrs932.js} +31 -31
- package/dist/v2/{render-mp82ns36.js → render-e9mh9y1d.js} +20 -20
- package/dist/v2/{safe-notification-target-gphhast7.js → safe-notification-target-9r79xnbt.js} +2 -2
- package/dist/v2/{search-archive-d0fcqch9.js → search-archive-j3kb9ggd.js} +11 -11
- package/dist/v2/{search-ebd0yr40.js → search-sr23g316.js} +22 -22
- package/dist/v2/{send-session-notification-na3q825m.js → send-session-notification-95p89k7q.js} +5 -5
- package/dist/v2/{server-pej5rnye.js → server-0qxb8r8q.js} +2 -2
- package/dist/v2/{server-sg2qjkrb.js → server-1ppcpsdw.js} +2 -2
- package/dist/v2/{server-c43zxc9k.js → server-2qxt6qv0.js} +8 -8
- package/dist/v2/{server-7vb38e51.js → server-3jc6qmdz.js} +1 -1
- package/dist/v2/{server-69m30b21.js → server-3yk44ddz.js} +1 -1
- package/dist/v2/{server-wwmaqtxy.js → server-4y2pcckw.js} +3 -3
- package/dist/v2/{server-3schkz95.js → server-58h6rrnx.js} +4 -4
- package/dist/v2/{server-af1rmkyn.js → server-5kgesxck.js} +2 -2
- package/dist/v2/{server-mfn1yf9d.js → server-7vrtk78d.js} +1 -1
- package/dist/v2/{server-f0j864ma.js → server-91gb0vh8.js} +1 -1
- package/dist/v2/{server-131h608x.js → server-966dq3pd.js} +2 -2
- package/dist/v2/{server-jb6tjyeb.js → server-bb6kf05j.js} +23 -20
- package/dist/v2/{server-zypeavf0.js → server-c5kq8d5n.js} +4 -4
- package/dist/v2/{server-gwxys0d0.js → server-c8z2grq0.js} +1 -1
- package/dist/v2/{server-gy26cwvw.js → server-e14c3hd6.js} +10 -10
- package/dist/v2/{server-epvj1cey.js → server-e20kfytm.js} +11 -11
- package/dist/v2/{server-2gjqhmn9.js → server-fw49gc57.js} +8 -8
- package/dist/v2/{server-y8n33d9j.js → server-g61hgy1y.js} +4 -4
- package/dist/v2/{server-2j87594q.js → server-kgq2e2hh.js} +2 -2
- package/dist/v2/{server-ddw42d76.js → server-mxsy9h1d.js} +2 -2
- package/dist/v2/{server-qmmkhz2z.js → server-np27dgyt.js} +1 -1
- package/dist/v2/{server-dcws5831.js → server-qp5sj6n5.js} +2 -2
- package/dist/v2/{server-sr8tf5dt.js → server-r7y35vm9.js} +4 -4
- package/dist/v2/{server-t4hk02v1.js → server-rcchadw0.js} +6 -28
- package/dist/v2/{server-b3r080cm.js → server-rz5jnhnv.js} +1 -1
- package/dist/v2/{server-zt1m5rwj.js → server-sa1fdt41.js} +1 -1
- package/dist/v2/{server-fhxe5jgm.js → server-t5cgb15n.js} +5 -5
- package/dist/v2/{server-ypf1ap0v.js → server-t8n27rbt.js} +1 -1
- package/dist/v2/{server-sefxj8k1.js → server-tmf0ayqp.js} +1 -1
- package/dist/v2/{server-wa4qhryh.js → server-ttrrh27h.js} +2 -2
- package/dist/v2/{server-bez34e60.js → server-vqq3g1t7.js} +4 -4
- package/dist/v2/{server-tpt7bwq8.js → server-ww7xbxxf.js} +1 -1
- package/dist/v2/{server-1f03b92k.js → server-y7q8cds3.js} +3 -3
- package/dist/v2/{server-xsrykjkj.js → server-yxe0gh3v.js} +11 -11
- package/dist/v2/{server-rg92e592.js → server-z7n3n1ra.js} +34 -28
- package/dist/v2/server.js +5 -5
- package/dist/v2/{storage-tags-ztar1k0g.js → storage-tags-rzv7y0n3.js} +4 -4
- package/dist/v2/{v2-archive-reader-gm6mygag.js → v2-archive-reader-jnzjavzr.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-y9a02xpd.js → wrapup-orchestrator-jw4nre49.js} +31 -31
- package/dist/{v2-archive-reader-yp9956t8.js → v2-archive-reader-b76tfeje.js} +1 -1
- package/dist/wrapup-orchestrator-fhfazjkq.js +55 -0
- package/package.json +1 -1
- package/src/shared/data-path.test.ts +104 -56
- package/src/shared/data-path.ts +30 -30
- package/dist/index-g2q4htwp.js +0 -146
- package/dist/wrapup-orchestrator-ese0epyk.js +0 -56
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
-
import {
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
rmSync,
|
|
7
|
+
statSync,
|
|
8
|
+
symlinkSync,
|
|
9
|
+
writeFileSync,
|
|
10
|
+
} from "node:fs";
|
|
3
11
|
import * as os from "node:os";
|
|
4
12
|
import * as path from "node:path";
|
|
5
13
|
import {
|
|
@@ -16,6 +24,7 @@ import {
|
|
|
16
24
|
getProjectMagicContextHistorianDir,
|
|
17
25
|
isMagicContextStorageOutsideEngram,
|
|
18
26
|
} from "./data-path";
|
|
27
|
+
import * as logger from "./logger";
|
|
19
28
|
import { createTestTempDirFromPath } from "./test-temp-dir";
|
|
20
29
|
|
|
21
30
|
const savedEnv = {
|
|
@@ -320,63 +329,102 @@ describe("data-path", () => {
|
|
|
320
329
|
});
|
|
321
330
|
|
|
322
331
|
describe("ensureCortexKitArtifactGitignore", () => {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
ensureCortexKitArtifactGitignore(dir);
|
|
327
|
-
const gi = readFileSync(path.join(dir, ".cortexkit", ".gitignore"), "utf8");
|
|
328
|
-
expect(gi).toContain("# >>> cortexkit:magic-context");
|
|
329
|
-
expect(gi).toContain("magic-context/");
|
|
330
|
-
expect(gi).toContain("# <<< cortexkit:magic-context");
|
|
331
|
-
} finally {
|
|
332
|
-
rmSync(dir, { recursive: true, force: true });
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
test("is idempotent — a second call does not duplicate the block", () => {
|
|
337
|
-
const dir = createTestTempDirFromPath(path.join(os.tmpdir(), "mc-gi-"));
|
|
338
|
-
try {
|
|
339
|
-
ensureCortexKitArtifactGitignore(dir);
|
|
340
|
-
ensureCortexKitArtifactGitignore(dir);
|
|
341
|
-
const gi = readFileSync(path.join(dir, ".cortexkit", ".gitignore"), "utf8");
|
|
342
|
-
const occurrences = gi.split("# >>> cortexkit:magic-context").length - 1;
|
|
343
|
-
expect(occurrences).toBe(1);
|
|
344
|
-
} finally {
|
|
345
|
-
rmSync(dir, { recursive: true, force: true });
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
test("preserves a sibling module's existing entries (appends, never clobbers)", () => {
|
|
350
|
-
const dir = createTestTempDirFromPath(path.join(os.tmpdir(), "mc-gi-"));
|
|
351
|
-
try {
|
|
352
|
-
const ckDir = path.join(dir, ".cortexkit");
|
|
353
|
-
mkdirSync(ckDir, { recursive: true });
|
|
354
|
-
// Simulate a sibling (e.g. AFT) already owning a fenced block.
|
|
355
|
-
writeFileSync(
|
|
356
|
-
path.join(ckDir, ".gitignore"),
|
|
357
|
-
"# >>> cortexkit:aft\naft/scratch/\n# <<< cortexkit:aft\n",
|
|
358
|
-
);
|
|
359
|
-
ensureCortexKitArtifactGitignore(dir);
|
|
360
|
-
const gi = readFileSync(path.join(ckDir, ".gitignore"), "utf8");
|
|
361
|
-
expect(gi).toContain("# >>> cortexkit:aft");
|
|
362
|
-
expect(gi).toContain("aft/scratch/");
|
|
363
|
-
expect(gi).toContain("# >>> cortexkit:magic-context");
|
|
364
|
-
expect(gi).toContain("magic-context/");
|
|
365
|
-
} finally {
|
|
366
|
-
rmSync(dir, { recursive: true, force: true });
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
test("does not ignore the project config — only the artifact dir", () => {
|
|
332
|
+
const dirs: string[] = [];
|
|
333
|
+
const legacy = "# >>> cortexkit:magic-context\nmagic-context/\n# <<< cortexkit:magic-context\n";
|
|
334
|
+
function fixture() {
|
|
371
335
|
const dir = createTestTempDirFromPath(path.join(os.tmpdir(), "mc-gi-"));
|
|
336
|
+
dirs.push(dir);
|
|
337
|
+
mkdirSync(path.join(dir, ".cortexkit"), { recursive: true });
|
|
338
|
+
return {
|
|
339
|
+
dir,
|
|
340
|
+
shared: path.join(dir, ".cortexkit/.gitignore"),
|
|
341
|
+
nested: path.join(dir, ".cortexkit/magic-context/.gitignore"),
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
afterEach(() => {
|
|
345
|
+
for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
test("creates only the self-ignoring nested file and does not rewrite matching bytes", () => {
|
|
349
|
+
const { dir, nested, shared } = fixture();
|
|
350
|
+
ensureCortexKitArtifactGitignore(dir);
|
|
351
|
+
expect(readFileSync(nested, "utf8")).toBe("*\n");
|
|
352
|
+
const before = statSync(nested).mtimeMs;
|
|
353
|
+
ensureCortexKitArtifactGitignore(dir);
|
|
354
|
+
expect(statSync(nested).mtimeMs).toBe(before);
|
|
355
|
+
expect(existsSync(shared)).toBe(false);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test.each([
|
|
359
|
+
"",
|
|
360
|
+
"*",
|
|
361
|
+
"*\r\n",
|
|
362
|
+
"artifacts/\n",
|
|
363
|
+
])("repairs differing nested bytes %j", (existing) => {
|
|
364
|
+
const { dir, nested } = fixture();
|
|
365
|
+
mkdirSync(path.dirname(nested), { recursive: true });
|
|
366
|
+
writeFileSync(nested, existing);
|
|
367
|
+
ensureCortexKitArtifactGitignore(dir);
|
|
368
|
+
expect(readFileSync(nested, "utf8")).toBe("*\n");
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test.each([
|
|
372
|
+
legacy,
|
|
373
|
+
` \r\n\t\n${legacy}\n `,
|
|
374
|
+
legacy.replaceAll("\n", "\r\n"),
|
|
375
|
+
legacy.trimEnd(),
|
|
376
|
+
])("deletes the old shared file when only our block and whitespace remain %j", (existing) => {
|
|
377
|
+
const { dir, nested, shared } = fixture();
|
|
378
|
+
writeFileSync(shared, existing);
|
|
379
|
+
ensureCortexKitArtifactGitignore(dir);
|
|
380
|
+
expect(readFileSync(nested, "utf8")).toBe("*\n");
|
|
381
|
+
expect(existsSync(shared)).toBe(false);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
test("removes our complete blocks while preserving every other byte", () => {
|
|
385
|
+
const { dir, shared } = fixture();
|
|
386
|
+
const prefix = "# café\r\n# >>> cortexkit:aft\r\naft/scratch/\r\n# <<< cortexkit:aft\r\n\n";
|
|
387
|
+
const suffix = "# >>> cortexkit:other\nother/\n# <<< cortexkit:other\nlast-without-newline";
|
|
388
|
+
writeFileSync(shared, prefix + legacy.replaceAll("\n", "\r\n") + legacy + suffix);
|
|
389
|
+
ensureCortexKitArtifactGitignore(dir);
|
|
390
|
+
ensureCortexKitArtifactGitignore(dir);
|
|
391
|
+
expect(readFileSync(shared)).toEqual(Buffer.from(prefix + suffix));
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
test("shared cleanup preserves non-UTF8 bytes outside our block", () => {
|
|
395
|
+
const { dir, shared } = fixture();
|
|
396
|
+
const prefix = Buffer.from([0xff, 0x80, 0x0a]);
|
|
397
|
+
const suffix = Buffer.from("# >>> cortexkit:aft\naft/\n# <<< cortexkit:aft\n");
|
|
398
|
+
writeFileSync(shared, Buffer.concat([prefix, Buffer.from(legacy), suffix]));
|
|
399
|
+
ensureCortexKitArtifactGitignore(dir);
|
|
400
|
+
expect(readFileSync(shared)).toEqual(Buffer.concat([prefix, suffix]));
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
test.each([
|
|
404
|
+
"# >>> cortexkit:aft\naft/scratch/\n# <<< cortexkit:aft\n",
|
|
405
|
+
"# >>> cortexkit:magic-context\nmagic-context/\n# >>> cortexkit:aft\naft/\n# <<< cortexkit:aft\n# <<< cortexkit:magic-context\n",
|
|
406
|
+
"prefix # >>> cortexkit:magic-context\nmagic-context/\n# <<< cortexkit:magic-context\n",
|
|
407
|
+
])("leaves unowned or incomplete shared blocks unchanged %j", (existing) => {
|
|
408
|
+
const { dir, shared } = fixture();
|
|
409
|
+
writeFileSync(shared, existing);
|
|
410
|
+
ensureCortexKitArtifactGitignore(dir);
|
|
411
|
+
expect(readFileSync(shared)).toEqual(Buffer.from(existing));
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
test("logs a nested write failure without throwing or retiring the shared rule", () => {
|
|
415
|
+
const { dir, nested, shared } = fixture();
|
|
416
|
+
mkdirSync(nested, { recursive: true });
|
|
417
|
+
writeFileSync(shared, legacy);
|
|
418
|
+
const logged = spyOn(logger, "log").mockImplementation(() => {});
|
|
372
419
|
try {
|
|
373
|
-
ensureCortexKitArtifactGitignore(dir);
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
420
|
+
expect(() => ensureCortexKitArtifactGitignore(dir)).not.toThrow();
|
|
421
|
+
expect(readFileSync(shared, "utf8")).toBe(legacy);
|
|
422
|
+
expect(logged).toHaveBeenCalledWith("Failed to ensure project artifact gitignore", {
|
|
423
|
+
directory: dir,
|
|
424
|
+
error: expect.any(String),
|
|
425
|
+
});
|
|
378
426
|
} finally {
|
|
379
|
-
|
|
427
|
+
logged.mockRestore();
|
|
380
428
|
}
|
|
381
429
|
});
|
|
382
430
|
});
|
package/src/shared/data-path.ts
CHANGED
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
readFileSync,
|
|
6
6
|
readlinkSync,
|
|
7
7
|
realpathSync,
|
|
8
|
+
unlinkSync,
|
|
8
9
|
writeFileSync,
|
|
9
10
|
} from "node:fs";
|
|
10
11
|
import * as os from "node:os";
|
|
11
12
|
import * as path from "node:path";
|
|
12
13
|
import { getHarness, type HarnessId } from "./harness";
|
|
14
|
+
import { log } from "./logger";
|
|
13
15
|
import { createTestTempDir } from "./test-temp-dir";
|
|
14
16
|
|
|
15
17
|
export function getDataDir(): string {
|
|
@@ -90,8 +92,8 @@ export function getMagicContextHistorianDir(harness: HarnessId = getHarness()):
|
|
|
90
92
|
*
|
|
91
93
|
* `.cortexkit/` is the shared CortexKit per-project dir (also holds the
|
|
92
94
|
* project config `magic-context.jsonc`). Because these artifacts are transient
|
|
93
|
-
* debug dumps that shouldn't dirty the user's repo,
|
|
94
|
-
*
|
|
95
|
+
* debug dumps that shouldn't dirty the user's repo, each writer ensures a
|
|
96
|
+
* self-ignoring `.gitignore` inside this subdir (see
|
|
95
97
|
* ensureCortexKitArtifactGitignore) while leaving `*.jsonc` config tracked.
|
|
96
98
|
*
|
|
97
99
|
* Migration note: artifacts used to live under `.opencode/magic-context/`. We
|
|
@@ -106,47 +108,45 @@ export function getProjectMagicContextDir(directory: string): string {
|
|
|
106
108
|
return path.join(directory, ".cortexkit", "magic-context");
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
const GITIGNORE_GUARD_OPEN = "# >>> cortexkit:magic-context";
|
|
110
|
-
const GITIGNORE_GUARD_CLOSE = "# <<< cortexkit:magic-context";
|
|
111
|
-
|
|
112
111
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
* tracked, and any sibling module's (e.g. AFT's) entries are preserved.
|
|
117
|
-
*
|
|
118
|
-
* Uses the shared CortexKit fenced-block convention: each module owns exactly
|
|
119
|
-
* its `# >>> cortexkit:<module>` … `# <<< cortexkit:<module>` block and appends
|
|
120
|
-
* it idempotently (no-op when its own guard line is already present). This lets
|
|
121
|
-
* multiple cortexkit modules coexist in one `.gitignore` without clobbering.
|
|
112
|
+
* Hide artifacts and their ignore file without hiding the sibling project
|
|
113
|
+
* config. Retire our old shared-file block only after the nested rule is ready,
|
|
114
|
+
* preserving all bytes outside our complete fences.
|
|
122
115
|
*
|
|
123
116
|
* Best-effort: a write failure never blocks an artifact write (the caller
|
|
124
117
|
* already degrades gracefully on its own write failures).
|
|
125
118
|
*/
|
|
126
119
|
export function ensureCortexKitArtifactGitignore(directory: string): void {
|
|
127
120
|
try {
|
|
128
|
-
const
|
|
129
|
-
const gitignorePath = path.join(
|
|
130
|
-
|
|
131
|
-
if (existsSync(gitignorePath)) {
|
|
132
|
-
|
|
133
|
-
// Already fenced by us — nothing to do.
|
|
134
|
-
if (existing.includes(GITIGNORE_GUARD_OPEN)) return;
|
|
121
|
+
const artifactDir = getProjectMagicContextDir(directory);
|
|
122
|
+
const gitignorePath = path.join(artifactDir, ".gitignore");
|
|
123
|
+
mkdirSync(artifactDir, { recursive: true });
|
|
124
|
+
if (!existsSync(gitignorePath) || readFileSync(gitignorePath, "utf8") !== "*\n") {
|
|
125
|
+
writeFileSync(gitignorePath, "*\n", "utf8");
|
|
135
126
|
}
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
127
|
+
|
|
128
|
+
const sharedPath = path.join(directory, ".cortexkit", ".gitignore");
|
|
129
|
+
if (!existsSync(sharedPath)) return;
|
|
130
|
+
// A byte-preserving encoding keeps even non-UTF8 sibling entries intact.
|
|
131
|
+
const existing = readFileSync(sharedPath).toString("latin1");
|
|
132
|
+
// Do not cross another module's fence if an old block is incomplete.
|
|
133
|
+
const next = existing.replace(
|
|
134
|
+
/^# >>> cortexkit:magic-context\r?\n(?:(?!^# (?:>>>|<<<) cortexkit:)[\s\S])*?^# <<< cortexkit:magic-context(?:\r?\n|$)/gm,
|
|
135
|
+
"",
|
|
136
|
+
);
|
|
137
|
+
if (next === existing) return;
|
|
138
|
+
const remaining = Buffer.from(next, "latin1");
|
|
139
|
+
if (remaining.toString("utf8").trim() === "") unlinkSync(sharedPath);
|
|
140
|
+
else writeFileSync(sharedPath, remaining);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
log("Failed to ensure project artifact gitignore", { directory, error: String(error) });
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
147
|
* Project-local historian artifact directory.
|
|
148
148
|
*
|
|
149
|
-
* Layout: `<project-directory>/.
|
|
149
|
+
* Layout: `<project-directory>/.cortexkit/magic-context/historian/`
|
|
150
150
|
*
|
|
151
151
|
* Used for:
|
|
152
152
|
* - existing-state offload XMLs that long historian/recomp passes write
|
|
@@ -154,7 +154,7 @@ export function ensureCortexKitArtifactGitignore(directory: string): void {
|
|
|
154
154
|
* - validation-failure dump XMLs preserved for debugging
|
|
155
155
|
*
|
|
156
156
|
* Callers must `mkdirSync(dir, { recursive: true })` before writing — the
|
|
157
|
-
* `.
|
|
157
|
+
* `.cortexkit/` parent may not exist on a fresh project, and write failures
|
|
158
158
|
* here must degrade gracefully (e.g. historian falls back to inline state).
|
|
159
159
|
*/
|
|
160
160
|
export function getProjectMagicContextHistorianDir(directory: string): string {
|
package/dist/index-g2q4htwp.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getHarness2
|
|
3
|
-
} from "./index-pavzsdc6.js";
|
|
4
|
-
|
|
5
|
-
// src/shared/data-path.ts
|
|
6
|
-
import {
|
|
7
|
-
existsSync,
|
|
8
|
-
lstatSync,
|
|
9
|
-
mkdirSync,
|
|
10
|
-
readFileSync,
|
|
11
|
-
readlinkSync,
|
|
12
|
-
realpathSync,
|
|
13
|
-
writeFileSync
|
|
14
|
-
} from "node:fs";
|
|
15
|
-
import * as os from "node:os";
|
|
16
|
-
import * as path from "node:path";
|
|
17
|
-
|
|
18
|
-
// src/shared/test-temp-dir.ts
|
|
19
|
-
var STALE_TEMP_DIR_AGE_MS = 60 * 60 * 1000;
|
|
20
|
-
var registeredTempDirs = new Set;
|
|
21
|
-
|
|
22
|
-
// src/shared/data-path.ts
|
|
23
|
-
function getDataDir() {
|
|
24
|
-
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share");
|
|
25
|
-
}
|
|
26
|
-
function getMagicContextTempDir(harness = getHarness2()) {
|
|
27
|
-
return path.join(os.tmpdir(), harness, "magic-context");
|
|
28
|
-
}
|
|
29
|
-
function getMagicContextLogPath(harness = getHarness2()) {
|
|
30
|
-
const envPath = process.env.MAGIC_CONTEXT_LOG_PATH?.trim();
|
|
31
|
-
if (envPath)
|
|
32
|
-
return envPath;
|
|
33
|
-
return path.join(getMagicContextTempDir(harness), "magic-context.log");
|
|
34
|
-
}
|
|
35
|
-
function getProjectMagicContextDir(directory) {
|
|
36
|
-
return path.join(directory, ".cortexkit", "magic-context");
|
|
37
|
-
}
|
|
38
|
-
var GITIGNORE_GUARD_OPEN = "# >>> cortexkit:magic-context";
|
|
39
|
-
var GITIGNORE_GUARD_CLOSE = "# <<< cortexkit:magic-context";
|
|
40
|
-
function ensureCortexKitArtifactGitignore(directory) {
|
|
41
|
-
try {
|
|
42
|
-
const cortexKitDir = path.join(directory, ".cortexkit");
|
|
43
|
-
const gitignorePath = path.join(cortexKitDir, ".gitignore");
|
|
44
|
-
let existing = "";
|
|
45
|
-
if (existsSync(gitignorePath)) {
|
|
46
|
-
existing = readFileSync(gitignorePath, "utf8");
|
|
47
|
-
if (existing.includes(GITIGNORE_GUARD_OPEN))
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const block = `${GITIGNORE_GUARD_OPEN}
|
|
51
|
-
magic-context/
|
|
52
|
-
${GITIGNORE_GUARD_CLOSE}
|
|
53
|
-
`;
|
|
54
|
-
const needsLeadingNewline = existing.length > 0 && !existing.endsWith(`
|
|
55
|
-
`);
|
|
56
|
-
const next = existing + (needsLeadingNewline ? `
|
|
57
|
-
` : "") + block;
|
|
58
|
-
mkdirSync(cortexKitDir, { recursive: true });
|
|
59
|
-
writeFileSync(gitignorePath, next, "utf8");
|
|
60
|
-
} catch {}
|
|
61
|
-
}
|
|
62
|
-
function getProjectMagicContextHistorianDir(directory) {
|
|
63
|
-
return path.join(getProjectMagicContextDir(directory), "historian");
|
|
64
|
-
}
|
|
65
|
-
function getOpenCodeStorageDir() {
|
|
66
|
-
return path.join(getDataDir(), "opencode", "storage");
|
|
67
|
-
}
|
|
68
|
-
function getMagicContextStorageResolution() {
|
|
69
|
-
const testDataDir = process.env.MAGIC_CONTEXT_TEST_DATA_DIR?.trim();
|
|
70
|
-
if (testDataDir) {
|
|
71
|
-
const perTestDataHome = process.env.XDG_DATA_HOME?.trim();
|
|
72
|
-
if (perTestDataHome && path.resolve(perTestDataHome) !== path.resolve(testDataDir)) {
|
|
73
|
-
return {
|
|
74
|
-
path: path.join(perTestDataHome, "cortexkit", "magic-context"),
|
|
75
|
-
source: "test isolation"
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
return {
|
|
79
|
-
path: path.join(testDataDir, "cortexkit", "magic-context"),
|
|
80
|
-
source: "test isolation"
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
if (false) {}
|
|
84
|
-
const explicitStorageDir = process.env.MAGIC_CONTEXT_STORAGE_DIR?.trim();
|
|
85
|
-
if (explicitStorageDir) {
|
|
86
|
-
if (!path.isAbsolute(explicitStorageDir)) {
|
|
87
|
-
throw new Error("MAGIC_CONTEXT_STORAGE_DIR must be an absolute path");
|
|
88
|
-
}
|
|
89
|
-
return { path: explicitStorageDir, source: "environment override" };
|
|
90
|
-
}
|
|
91
|
-
const xdgDataHome = process.env.XDG_DATA_HOME?.trim();
|
|
92
|
-
if (xdgDataHome) {
|
|
93
|
-
return {
|
|
94
|
-
path: path.join(xdgDataHome, "cortexkit", "magic-context"),
|
|
95
|
-
source: "XDG_DATA_HOME"
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
path: path.join(os.homedir(), ".local", "share", "cortexkit", "magic-context"),
|
|
100
|
-
source: "platform default"
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function getMagicContextStorageDir() {
|
|
104
|
-
return getMagicContextStorageResolution().path;
|
|
105
|
-
}
|
|
106
|
-
function canonicalizeStoragePath(value, seen = new Set) {
|
|
107
|
-
const absolute = path.resolve(value);
|
|
108
|
-
if (seen.has(absolute))
|
|
109
|
-
return absolute;
|
|
110
|
-
seen.add(absolute);
|
|
111
|
-
try {
|
|
112
|
-
return realpathSync.native(absolute);
|
|
113
|
-
} catch {
|
|
114
|
-
try {
|
|
115
|
-
if (lstatSync(absolute).isSymbolicLink()) {
|
|
116
|
-
const target = readlinkSync(absolute);
|
|
117
|
-
const resolvedTarget = path.isAbsolute(target) ? target : path.resolve(path.dirname(absolute), target);
|
|
118
|
-
return canonicalizeStoragePath(resolvedTarget, seen);
|
|
119
|
-
}
|
|
120
|
-
} catch {}
|
|
121
|
-
const parent = path.dirname(absolute);
|
|
122
|
-
if (parent === absolute)
|
|
123
|
-
return absolute;
|
|
124
|
-
const resolvedParent = canonicalizeStoragePath(parent, seen);
|
|
125
|
-
return path.resolve(resolvedParent, path.basename(absolute));
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function isMagicContextStorageOutsideEngram(storageDir = getMagicContextStorageDir(), backupDir = path.join(os.homedir(), ".local", "share", "cortexkit", "magic-context")) {
|
|
129
|
-
const resolvedStorageDir = canonicalizeStoragePath(storageDir);
|
|
130
|
-
const resolvedBackupDir = canonicalizeStoragePath(backupDir);
|
|
131
|
-
const relative2 = path.relative(resolvedBackupDir, resolvedStorageDir);
|
|
132
|
-
return path.isAbsolute(relative2) || relative2 === ".." || relative2.startsWith(`..${path.sep}`);
|
|
133
|
-
}
|
|
134
|
-
var STORAGE_BACKUP_WARNING_CHECKED = Symbol.for("magic-context.storage-backup-warning-checked");
|
|
135
|
-
function claimStorageBackupWarningCheck() {
|
|
136
|
-
const processState = globalThis;
|
|
137
|
-
if (processState[STORAGE_BACKUP_WARNING_CHECKED])
|
|
138
|
-
return false;
|
|
139
|
-
processState[STORAGE_BACKUP_WARNING_CHECKED] = true;
|
|
140
|
-
return true;
|
|
141
|
-
}
|
|
142
|
-
function getLegacyOpenCodeMagicContextStorageDir() {
|
|
143
|
-
return path.join(getOpenCodeStorageDir(), "plugin", "magic-context");
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export { getDataDir, getMagicContextLogPath, ensureCortexKitArtifactGitignore, getProjectMagicContextHistorianDir, getOpenCodeStorageDir, getMagicContextStorageResolution, getMagicContextStorageDir, isMagicContextStorageOutsideEngram, claimStorageBackupWarningCheck, getLegacyOpenCodeMagicContextStorageDir };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
runManagedWrapup2
|
|
3
|
-
} from "./index-37a9bfta.js";
|
|
4
|
-
import"./index-eej9kwad.js";
|
|
5
|
-
import"./index-bqhjzhv4.js";
|
|
6
|
-
import"./index-gn6gfz4y.js";
|
|
7
|
-
import"./index-sd3egckz.js";
|
|
8
|
-
import"./index-sd2s4t4p.js";
|
|
9
|
-
import"./index-d4qw2h43.js";
|
|
10
|
-
import"./index-jjvbk92s.js";
|
|
11
|
-
import"./index-s79g172v.js";
|
|
12
|
-
import"./index-4dhv7mqz.js";
|
|
13
|
-
import"./index-1qmv26ga.js";
|
|
14
|
-
import"./index-2qbtqg1w.js";
|
|
15
|
-
import"./index-etn2hmb5.js";
|
|
16
|
-
import"./index-2amn2s73.js";
|
|
17
|
-
import"./index-6athgjba.js";
|
|
18
|
-
import"./index-8cfnaagj.js";
|
|
19
|
-
import"./index-25ka1jza.js";
|
|
20
|
-
import"./index-qt1qqasc.js";
|
|
21
|
-
import"./index-xgnh498s.js";
|
|
22
|
-
import"./index-x53gnmce.js";
|
|
23
|
-
import"./index-1zx87sdm.js";
|
|
24
|
-
import"./index-brj6was5.js";
|
|
25
|
-
import"./index-x8a7jmkh.js";
|
|
26
|
-
import"./index-fw42ms3m.js";
|
|
27
|
-
import"./index-hkh8x221.js";
|
|
28
|
-
import"./index-4dpvnp8k.js";
|
|
29
|
-
import"./index-jz5bk7xd.js";
|
|
30
|
-
import"./index-qcz1fy7h.js";
|
|
31
|
-
import"./index-dj2p8653.js";
|
|
32
|
-
import"./index-b0xt5qz9.js";
|
|
33
|
-
import"./index-fb3zxn06.js";
|
|
34
|
-
import"./index-nj360hcs.js";
|
|
35
|
-
import"./index-fr0wbhdn.js";
|
|
36
|
-
import"./index-txs8tce6.js";
|
|
37
|
-
import"./index-h9m41624.js";
|
|
38
|
-
import"./index-wh9fxds5.js";
|
|
39
|
-
import"./index-2p37txes.js";
|
|
40
|
-
import"./index-smtbdmc3.js";
|
|
41
|
-
import"./index-9wnbnx8f.js";
|
|
42
|
-
import"./index-xa9mmq6c.js";
|
|
43
|
-
import"./index-96ztjvkn.js";
|
|
44
|
-
import"./index-v0p37hm2.js";
|
|
45
|
-
import"./index-58e3y90n.js";
|
|
46
|
-
import"./index-fxbk7gk3.js";
|
|
47
|
-
import"./index-ak11t3gm.js";
|
|
48
|
-
import"./index-gzy5w8ya.js";
|
|
49
|
-
import"./index-jrfre9ah.js";
|
|
50
|
-
import"./index-g2q4htwp.js";
|
|
51
|
-
import"./index-pavzsdc6.js";
|
|
52
|
-
import"./index-z4p0ry94.js";
|
|
53
|
-
import"./index-1d042x6w.js";
|
|
54
|
-
export {
|
|
55
|
-
runManagedWrapup2 as runManagedWrapup
|
|
56
|
-
};
|