@cortexkit/opencode-magic-context 0.49.51 → 0.49.53
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/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +1 -1
- package/dist/{context-r77d4fdy.js → context-p6r0bk7a.js} +90 -51
- package/dist/{embedding-backfill-3wdjzrvs.js → embedding-backfill-qes2kf1c.js} +2 -2
- package/dist/features/magic-context/compartment-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/message-fts-session-filter.d.ts +1 -1
- package/dist/features/magic-context/message-fts-session-filter.d.ts.map +1 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts +8 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/storage-host-instruction-retention.d.ts +10 -3
- package/dist/features/magic-context/storage-host-instruction-retention.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +20 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta.d.ts +1 -1
- package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +1 -1
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -1
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts +6 -0
- package/dist/hooks/magic-context/active-anthropic-turn.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts +2 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/history-boundary-recovery.d.ts +15 -0
- package/dist/hooks/magic-context/history-boundary-recovery.d.ts.map +1 -0
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/host-served-rows.d.ts +12 -2
- package/dist/hooks/magic-context/host-served-rows.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +21 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts +43 -0
- package/dist/hooks/magic-context/latest-assistant-turn.d.ts.map +1 -1
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts +102 -26
- package/dist/hooks/magic-context/latest-thinking-recovery.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts +18 -2
- package/dist/hooks/magic-context/lkg-recovery-prefix.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-slot.d.ts.map +1 -1
- package/dist/hooks/magic-context/pass-outcome.d.ts.map +1 -1
- package/dist/hooks/magic-context/pending-marker-rearm.d.ts +20 -0
- package/dist/hooks/magic-context/pending-marker-rearm.d.ts.map +1 -0
- package/dist/hooks/magic-context/persist-filtered-noise.d.ts +1 -1
- package/dist/hooks/magic-context/persist-filtered-noise.d.ts.map +1 -1
- package/dist/hooks/magic-context/priced-pass-sizing.d.ts +7 -0
- package/dist/hooks/magic-context/priced-pass-sizing.d.ts.map +1 -1
- package/dist/hooks/magic-context/routine-cleanup-decision.d.ts +11 -1
- package/dist/hooks/magic-context/routine-cleanup-decision.d.ts.map +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts +1 -1
- package/dist/hooks/magic-context/rust-mode-transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/served-check.d.ts +127 -0
- package/dist/hooks/magic-context/served-check.d.ts.map +1 -0
- package/dist/hooks/magic-context/signed-thinking-hold.d.ts +32 -4
- package/dist/hooks/magic-context/signed-thinking-hold.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +37 -2
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/hooks/magic-context/unresolved-history-boundary.d.ts +21 -2
- package/dist/hooks/magic-context/unresolved-history-boundary.d.ts.map +1 -1
- package/dist/{index-n0twfvah.js → index-2ctn7q09.js} +531 -17
- package/dist/{index-bamnjp2t.js → index-2m54t4g1.js} +9 -5
- package/dist/{index-30sf7e5k.js → index-3b5k5vma.js} +27 -16
- package/dist/{index-ct3ettqt.js → index-3h0wyv22.js} +3 -3
- package/dist/{index-hkveze74.js → index-3hhq18q0.js} +1 -1
- package/dist/{index-kaqs6h31.js → index-52x68mj4.js} +1 -1
- package/dist/{index-wr2t8zb0.js → index-5684dzbv.js} +648 -69
- package/dist/{index-s131svmx.js → index-7wasafnb.js} +1 -1
- package/dist/{index-8d7gkgjs.js → index-85chg6fw.js} +1 -1
- package/dist/{index-z4832qfe.js → index-a6bxwv4a.js} +1 -1
- package/dist/{index-h8g08nxs.js → index-chjsdqg6.js} +104 -62
- package/dist/{index-5dptmnvd.js → index-esm4farg.js} +8 -7
- package/dist/{index-97bjd14c.js → index-fbs0f5ch.js} +4 -4
- package/dist/{index-cwj6qhmf.js → index-kwpweqzs.js} +8 -3
- package/dist/{index-07rp6xcn.js → index-n3rxwtwt.js} +48 -15
- package/dist/{index-gv7dwx5b.js → index-p7ssfv6p.js} +503 -395
- package/dist/{index-v4a1pnny.js → index-pgbmbtdq.js} +4 -4
- package/dist/{index-mjh63zvw.js → index-wpab17w4.js} +1 -1
- package/dist/index.js +53 -32
- package/dist/{message-index-bounded-k0ebpy3y.js → message-index-bounded-7p3064st.js} +2 -2
- package/dist/migration-worker.js +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/messages-transform.d.ts +6 -0
- package/dist/plugin/messages-transform.d.ts.map +1 -1
- package/dist/{project-embedding-registry-5dwh5zfn.js → project-embedding-registry-m8t547fb.js} +3 -1
- package/dist/raw-ordinal-warmup-worker.js +3 -3
- package/dist/{read-session-chunk-6712p893.js → read-session-chunk-cyks9yx4.js} +1 -1
- package/dist/{recomp-orchestrator-8ebydg5j.js → recomp-orchestrator-d4nks9da.js} +9 -9
- package/dist/{render-dtc4qkq4.js → render-gc1fn4nz.js} +5 -5
- package/dist/{search-75bj2430.js → search-1bjy7yhc.js} +8 -8
- package/dist/{search-archive-f6hjbnsa.js → search-archive-hdrfjgv8.js} +4 -4
- package/dist/shared/test-open-files.d.ts +17 -0
- package/dist/shared/test-open-files.d.ts.map +1 -0
- package/dist/shared/user-facing-codes.d.ts +7 -2
- package/dist/shared/user-facing-codes.d.ts.map +1 -1
- package/dist/tools/ctx-expand/search-archive.d.ts.map +1 -1
- package/dist/{transform-postprocess-phase-1bg25094.js → transform-postprocess-phase-9e53b1dr.js} +10 -10
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/chunk-embedding-write-worker.js +1 -1
- package/dist/v2/{context-cpbhpxks.js → context-1p22880w.js} +1084 -370
- package/dist/v2/{embedding-backfill-x1zpc04f.js → embedding-backfill-bwcmw1te.js} +2 -2
- package/dist/v2/fold/instruction-supersession.d.ts.map +1 -1
- package/dist/v2/hooks/context.d.ts.map +1 -1
- package/dist/v2/{message-index-bounded-a36rw93p.js → message-index-bounded-mjpxz7wp.js} +2 -2
- package/dist/v2/migration-worker.js +1 -1
- package/dist/v2/{project-embedding-registry-v2fxrs8b.js → project-embedding-registry-7qcs8c61.js} +3 -1
- package/dist/v2/raw-ordinal-warmup-worker.js +3 -3
- package/dist/v2/{read-session-chunk-hzhxvhyv.js → read-session-chunk-cxk2kssy.js} +1 -1
- package/dist/v2/{recomp-orchestrator-yzr49pd0.js → recomp-orchestrator-e560ryjm.js} +8 -8
- package/dist/v2/{render-rhaevxv1.js → render-rk17pvy0.js} +5 -5
- package/dist/v2/{search-archive-9924fyk8.js → search-archive-a51g9sp7.js} +4 -4
- package/dist/v2/{search-3yrdpr38.js → search-kvzyj2mf.js} +7 -7
- package/dist/v2/{server-scp3y4dh.js → server-28g1b00j.js} +1 -1
- package/dist/v2/{server-kaqs6h31.js → server-52x68mj4.js} +1 -1
- package/dist/v2/{server-0k586y7d.js → server-71bg2psk.js} +3 -3
- package/dist/v2/{server-3bfc26r7.js → server-77rvx3wn.js} +34 -15
- package/dist/v2/{server-jxrqsn84.js → server-ah1j996f.js} +1 -1
- package/dist/v2/{server-sgn61hht.js → server-bjsmb6zs.js} +8 -3
- package/dist/v2/{server-16kfxcxj.js → server-bzh1fkvd.js} +1 -1
- package/dist/v2/{server-vjadwb3j.js → server-d5zgah57.js} +1 -1
- package/dist/v2/{server-q93jdtz8.js → server-e37d2zt4.js} +8 -7
- package/dist/v2/{server-016a1whm.js → server-fh6dhx8c.js} +104 -62
- package/dist/v2/{server-eznem83k.js → server-jmrd7vwc.js} +26 -15
- package/dist/v2/{server-4h4acntc.js → server-k3vtc89v.js} +9 -5
- package/dist/v2/{server-88yvx6r9.js → server-zq704789.js} +531 -17
- package/dist/v2/server.js +2 -2
- package/dist/v2/{v2-archive-reader-5ggewg8q.js → v2-archive-reader-hsvddme0.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-36c5wyvq.js → wrapup-orchestrator-ckpj1yvj.js} +8 -8
- package/dist/{v2-archive-reader-gx5ke1d7.js → v2-archive-reader-qgqrxgrq.js} +1 -1
- package/dist/{wrapup-orchestrator-ya31knav.js → wrapup-orchestrator-6189f37j.js} +10 -10
- package/package.json +1 -1
- package/src/shared/escalation-bands.test.ts +16 -1
- package/src/shared/sqlite-placeholders.test.ts +103 -0
- package/src/shared/storage-file-mutex-review.test.ts +5 -7
- package/src/shared/test-open-files.test.ts +194 -0
- package/src/shared/test-open-files.ts +71 -0
- package/src/shared/user-facing-codes.ts +8 -2
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
releaseCompartmentLeaseBestEffort,
|
|
12
12
|
getCompartments,
|
|
13
13
|
getLastCompartmentEndMessage
|
|
14
|
-
} from "./server-
|
|
14
|
+
} from "./server-zq704789.js";
|
|
15
15
|
import"./server-2amn2s73.js";
|
|
16
16
|
import"./server-3jc6qmdz.js";
|
|
17
17
|
import"./server-mxsy9h1d.js";
|
|
@@ -24,7 +24,7 @@ import"./server-1d042x6w.js";
|
|
|
24
24
|
import"./server-rz5jnhnv.js";
|
|
25
25
|
import"./server-966dq3pd.js";
|
|
26
26
|
import"./server-g61hgy1y.js";
|
|
27
|
-
import"./server-
|
|
27
|
+
import"./server-bzh1fkvd.js";
|
|
28
28
|
import {
|
|
29
29
|
getWrapupInProgressState,
|
|
30
30
|
acquireWrapupInProgress,
|
|
@@ -33,9 +33,9 @@ import {
|
|
|
33
33
|
getHistorianFailureState,
|
|
34
34
|
clearEmergencyRecovery,
|
|
35
35
|
prepareRawSessionOrdinals2
|
|
36
|
-
} from "./server-
|
|
36
|
+
} from "./server-77rvx3wn.js";
|
|
37
37
|
import"./server-ww7xbxxf.js";
|
|
38
|
-
import"./server-
|
|
38
|
+
import"./server-28g1b00j.js";
|
|
39
39
|
import"./server-1zx87sdm.js";
|
|
40
40
|
import"./server-rcchadw0.js";
|
|
41
41
|
import"./server-0ms13pc8.js";
|
|
@@ -63,15 +63,15 @@ import {
|
|
|
63
63
|
registerActiveCompartmentRun,
|
|
64
64
|
setRecompStarting2,
|
|
65
65
|
setRecompTerminal2
|
|
66
|
-
} from "./server-
|
|
66
|
+
} from "./server-fh6dhx8c.js";
|
|
67
67
|
import"./server-qt1qqasc.js";
|
|
68
|
-
import"./server-
|
|
68
|
+
import"./server-k3vtc89v.js";
|
|
69
69
|
import"./server-qp5sj6n5.js";
|
|
70
70
|
import"./server-4dhv7mqz.js";
|
|
71
71
|
import"./server-brsx45r6.js";
|
|
72
|
-
import"./server-
|
|
72
|
+
import"./server-d5zgah57.js";
|
|
73
73
|
import"./server-jjvbk92s.js";
|
|
74
|
-
import"./server-
|
|
74
|
+
import"./server-bjsmb6zs.js";
|
|
75
75
|
import"./server-sb55ddgn.js";
|
|
76
76
|
import"./server-sa1fdt41.js";
|
|
77
77
|
import"./server-5kgesxck.js";
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
2
|
runManagedWrapup2
|
|
3
|
-
} from "./index-
|
|
4
|
-
import"./index-
|
|
5
|
-
import"./index-
|
|
3
|
+
} from "./index-pgbmbtdq.js";
|
|
4
|
+
import"./index-fbs0f5ch.js";
|
|
5
|
+
import"./index-chjsdqg6.js";
|
|
6
6
|
import"./index-90z05d0p.js";
|
|
7
7
|
import"./index-sd3egckz.js";
|
|
8
|
-
import"./index-
|
|
9
|
-
import"./index-
|
|
8
|
+
import"./index-kwpweqzs.js";
|
|
9
|
+
import"./index-85chg6fw.js";
|
|
10
10
|
import"./index-jjvbk92s.js";
|
|
11
|
-
import"./index-
|
|
11
|
+
import"./index-2m54t4g1.js";
|
|
12
12
|
import"./index-4dhv7mqz.js";
|
|
13
|
-
import"./index-
|
|
13
|
+
import"./index-2ctn7q09.js";
|
|
14
14
|
import"./index-25tm250q.js";
|
|
15
|
-
import"./index-
|
|
15
|
+
import"./index-3hhq18q0.js";
|
|
16
16
|
import"./index-2amn2s73.js";
|
|
17
17
|
import"./index-6athgjba.js";
|
|
18
18
|
import"./index-gapnh6tk.js";
|
|
19
19
|
import"./index-r9agn061.js";
|
|
20
20
|
import"./index-qt1qqasc.js";
|
|
21
|
-
import"./index-
|
|
21
|
+
import"./index-n3rxwtwt.js";
|
|
22
22
|
import"./index-bkg4hdyh.js";
|
|
23
23
|
import"./index-1zx87sdm.js";
|
|
24
24
|
import"./index-em92bp7f.js";
|
|
@@ -29,7 +29,7 @@ import"./index-jjy5a5w0.js";
|
|
|
29
29
|
import"./index-qperbvjn.js";
|
|
30
30
|
import"./index-hexdee98.js";
|
|
31
31
|
import"./index-hsyczpn7.js";
|
|
32
|
-
import"./index-
|
|
32
|
+
import"./index-a6bxwv4a.js";
|
|
33
33
|
import"./index-fb3zxn06.js";
|
|
34
34
|
import"./index-pb8ysnq2.js";
|
|
35
35
|
import"./index-fr0wbhdn.js";
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { escalationBands } from "./escalation-bands";
|
|
2
|
+
import { escalationBands, MAX_EXECUTE_THRESHOLD } from "./escalation-bands";
|
|
3
3
|
|
|
4
4
|
describe("escalationBands", () => {
|
|
5
5
|
test.each([
|
|
@@ -20,4 +20,19 @@ describe("escalationBands", () => {
|
|
|
20
20
|
expect(escalationBands(65).forceMaterializationPercentage).toBe(85);
|
|
21
21
|
expect(escalationBands(80).forceMaterializationPercentage).toBe(85);
|
|
22
22
|
});
|
|
23
|
+
|
|
24
|
+
// No threshold puts the force band at or above 95%. A pass held for signed
|
|
25
|
+
// thinking therefore never reaches 95% with compaction on (the hold ends in
|
|
26
|
+
// force-band pressure), and neither the OpenCode postprocess phase nor
|
|
27
|
+
// Pi's pipeline has a 95% release for a held turn any more: that removal
|
|
28
|
+
// rests on this bound. Raising the
|
|
29
|
+
// threshold clamp past 92% would let a reading in [95%, threshold + 2%) be
|
|
30
|
+
// held again.
|
|
31
|
+
test("the force band starts below 95% for every threshold", () => {
|
|
32
|
+
expect(escalationBands(Infinity).forceMaterializationPercentage).toBeLessThan(95);
|
|
33
|
+
expect(escalationBands(Number.MAX_VALUE).forceMaterializationPercentage).toBeLessThan(95);
|
|
34
|
+
expect(escalationBands(MAX_EXECUTE_THRESHOLD).forceMaterializationPercentage).toBeLessThan(
|
|
35
|
+
95,
|
|
36
|
+
);
|
|
37
|
+
});
|
|
23
38
|
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join, relative, resolve } from "node:path";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
|
|
6
|
+
const packagesRoot = resolve(import.meta.dir, "../../..");
|
|
7
|
+
const reason =
|
|
8
|
+
"node:sqlite on Node 22.16 to 22.19 and 24.0 to 24.6 rejects positional arguments for numbered placeholders; use plain ? and pass the value again";
|
|
9
|
+
const sqlStart =
|
|
10
|
+
/^\s*(?:SELECT|WITH|INSERT|UPDATE|DELETE|REPLACE|CREATE|ALTER|DROP|PRAGMA|EXPLAIN)\b/i;
|
|
11
|
+
|
|
12
|
+
function sourceFiles(directory: string): string[] {
|
|
13
|
+
return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
14
|
+
if (["node_modules", "dist", "target", ".git"].includes(entry.name)) return [];
|
|
15
|
+
const path = join(directory, entry.name);
|
|
16
|
+
return entry.isDirectory() ? sourceFiles(path) : path.endsWith(".ts") ? [path] : [];
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function numberedSqlPlaceholders(path: string, text = readFileSync(path, "utf8")): string[] {
|
|
21
|
+
if (!/\?[0-9]/.test(text)) return [];
|
|
22
|
+
const source = ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true);
|
|
23
|
+
const violations = new Set<number>();
|
|
24
|
+
function checkLiterals(node: ts.Node): void {
|
|
25
|
+
if (
|
|
26
|
+
(ts.isStringLiteralLike(node) || ts.isTemplateLiteralToken(node)) &&
|
|
27
|
+
/\?[0-9]/.test(node.text)
|
|
28
|
+
) {
|
|
29
|
+
violations.add(source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1);
|
|
30
|
+
}
|
|
31
|
+
ts.forEachChild(node, checkLiterals);
|
|
32
|
+
}
|
|
33
|
+
function visit(node: ts.Node): void {
|
|
34
|
+
// The AST excludes comments and regex literals. Inspect whole SQL expressions
|
|
35
|
+
// so a numbered placeholder inside a template interpolation is caught too.
|
|
36
|
+
if (ts.isCallExpression(node)) {
|
|
37
|
+
const callee = node.expression;
|
|
38
|
+
const name = ts.isPropertyAccessExpression(callee)
|
|
39
|
+
? callee.name.text
|
|
40
|
+
: ts.isIdentifier(callee)
|
|
41
|
+
? callee.text
|
|
42
|
+
: "";
|
|
43
|
+
if (["prepare", "exec", "query"].includes(name) && node.arguments[0])
|
|
44
|
+
checkLiterals(node.arguments[0]);
|
|
45
|
+
}
|
|
46
|
+
if (
|
|
47
|
+
ts.isVariableDeclaration(node) &&
|
|
48
|
+
ts.isIdentifier(node.name) &&
|
|
49
|
+
/sql/i.test(node.name.text) &&
|
|
50
|
+
node.initializer
|
|
51
|
+
) {
|
|
52
|
+
checkLiterals(node.initializer);
|
|
53
|
+
}
|
|
54
|
+
const head = ts.isTemplateExpression(node)
|
|
55
|
+
? node.head.text
|
|
56
|
+
: ts.isStringLiteralLike(node)
|
|
57
|
+
? node.text
|
|
58
|
+
: "";
|
|
59
|
+
if (sqlStart.test(head)) checkLiterals(node);
|
|
60
|
+
ts.forEachChild(node, visit);
|
|
61
|
+
}
|
|
62
|
+
visit(source);
|
|
63
|
+
return [...violations]
|
|
64
|
+
.sort((a, b) => a - b)
|
|
65
|
+
.map((line) => `${relative(packagesRoot, path)}:${line}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe("SQLite positional placeholders", () => {
|
|
69
|
+
test("rejects numbered SQL placeholders across every package", () => {
|
|
70
|
+
const violations = sourceFiles(packagesRoot).flatMap((path) =>
|
|
71
|
+
numberedSqlPlaceholders(path),
|
|
72
|
+
);
|
|
73
|
+
expect(violations, reason).toEqual([]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("finds SQL calls, named fragments, returned SQL and interpolated placeholders", () => {
|
|
77
|
+
const fixtures = [
|
|
78
|
+
'db.prepare("SELECT ?1").get(value)',
|
|
79
|
+
"db.query(`SELECT ${flag ? '?1' : '?'}`).get(value)",
|
|
80
|
+
'db.exec("INSERT INTO t VALUES (?2)")',
|
|
81
|
+
'const MESSAGE_FILTER_SQL = " AND session_id = ?1"',
|
|
82
|
+
'function select() { return "SELECT ?3"; }',
|
|
83
|
+
'db.prepare<{ x: string }>("SELECT ?1")',
|
|
84
|
+
];
|
|
85
|
+
for (const fixture of fixtures)
|
|
86
|
+
expect(numberedSqlPlaceholders("fixture.ts", fixture)).toHaveLength(1);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("ignores comments, regexes, prose and anonymous SQL bindings", () => {
|
|
90
|
+
expect(
|
|
91
|
+
numberedSqlPlaceholders(
|
|
92
|
+
"fixture.ts",
|
|
93
|
+
[
|
|
94
|
+
"// SELECT ?1",
|
|
95
|
+
"/* db.prepare('SELECT ?2') */",
|
|
96
|
+
"const model = /[-_.]?5[-_.]1/;",
|
|
97
|
+
'const prose = "Did you mean ?1 or ?2?";',
|
|
98
|
+
'db.prepare("SELECT ?, ?").get(x, x);',
|
|
99
|
+
].join("\n"),
|
|
100
|
+
),
|
|
101
|
+
).toEqual([]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { expect, spyOn, test } from "bun:test";
|
|
2
|
-
import { spawnSync } from "node:child_process";
|
|
3
2
|
import { readdirSync, readFileSync, rmdirSync, writeFileSync } from "node:fs";
|
|
4
3
|
import { join } from "node:path";
|
|
5
4
|
import { __resetRpcIdentityTestHooks, __setRpcIdentityTestHooks } from "./rpc-utils";
|
|
6
5
|
import { withStorageFileMutex } from "./storage-file-mutex";
|
|
7
6
|
import * as permissions from "./storage-permissions";
|
|
7
|
+
import { listOpenFiles } from "./test-open-files";
|
|
8
8
|
import { createTestTempDir } from "./test-temp-dir";
|
|
9
9
|
|
|
10
10
|
const mutex = join(import.meta.dir, "storage-file-mutex.ts");
|
|
@@ -54,12 +54,10 @@ withStorageFileMutex(${JSON.stringify(join(root, "locks"))}, () => {
|
|
|
54
54
|
expect(new TextDecoder().decode(first.value)).toContain("HELD");
|
|
55
55
|
reader.releaseLock();
|
|
56
56
|
if (process.platform === "darwin") {
|
|
57
|
-
const files =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
expect(files.status).toBe(0);
|
|
62
|
-
const names = files.stdout.split("\n").filter((line) => line.startsWith("n"));
|
|
57
|
+
const files = listOpenFiles(child.pid);
|
|
58
|
+
// A paused child's isolation cannot be established from a missing inventory.
|
|
59
|
+
if (!files.available) throw new Error(files.reason);
|
|
60
|
+
const names = files.paths;
|
|
63
61
|
expect(
|
|
64
62
|
names.some((line) =>
|
|
65
63
|
/\/(?:\.local\/share\/opencode|\.local\/share\/cortexkit\/magic-context|\.config\/(?:opencode|cortexkit))\//.test(
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { expect, spyOn, test } from "bun:test";
|
|
2
|
+
import * as childProcess from "node:child_process";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import { closeSync, openSync, realpathSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { listOpenFiles, parseLsofPaths } from "./test-open-files";
|
|
8
|
+
import { cleanupTestTempDir, createTestTempDirFromPath } from "./test-temp-dir";
|
|
9
|
+
|
|
10
|
+
test.skipIf(process.platform !== "linux" && process.platform !== "darwin")(
|
|
11
|
+
"open-file inventory sees a file only while its descriptor is open",
|
|
12
|
+
() => {
|
|
13
|
+
const root = createTestTempDirFromPath(join(tmpdir(), "mc-open-files-"));
|
|
14
|
+
const path = join(realpathSync(root), "file with spaces.db");
|
|
15
|
+
let descriptor: number | undefined;
|
|
16
|
+
try {
|
|
17
|
+
descriptor = openSync(path, "w");
|
|
18
|
+
const open = listOpenFiles();
|
|
19
|
+
if (!open.available) throw new Error(open.reason);
|
|
20
|
+
expect(open.paths).toContain(path);
|
|
21
|
+
if (process.platform === "linux")
|
|
22
|
+
expect(open.entries).toContainEqual({ descriptor, path });
|
|
23
|
+
closeSync(descriptor);
|
|
24
|
+
descriptor = undefined;
|
|
25
|
+
const closed = listOpenFiles();
|
|
26
|
+
if (!closed.available) throw new Error(closed.reason);
|
|
27
|
+
expect(closed.paths).not.toContain(path);
|
|
28
|
+
} finally {
|
|
29
|
+
if (descriptor !== undefined) closeSync(descriptor);
|
|
30
|
+
cleanupTestTempDir(root);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
test.skipIf(process.platform !== "linux")("Linux inventory never spawns lsof", () => {
|
|
36
|
+
const execute = spyOn(childProcess, "execFileSync").mockImplementation(() => {
|
|
37
|
+
throw new Error("subprocess forbidden during inventory");
|
|
38
|
+
});
|
|
39
|
+
const root = createTestTempDirFromPath(join(tmpdir(), "mc-open-files-path-"));
|
|
40
|
+
const path = join(realpathSync(root), "marker");
|
|
41
|
+
const descriptor = openSync(path, "w");
|
|
42
|
+
try {
|
|
43
|
+
const result = listOpenFiles();
|
|
44
|
+
if (!result.available) throw new Error(result.reason);
|
|
45
|
+
expect(result.paths).toContain(path);
|
|
46
|
+
expect(execute).not.toHaveBeenCalled();
|
|
47
|
+
} finally {
|
|
48
|
+
execute.mockRestore();
|
|
49
|
+
closeSync(descriptor);
|
|
50
|
+
cleanupTestTempDir(root);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test.skipIf(process.platform !== "linux" && process.platform !== "darwin")(
|
|
55
|
+
"inventory can observe a child process's open file",
|
|
56
|
+
async () => {
|
|
57
|
+
const root = createTestTempDirFromPath(join(tmpdir(), "mc-open-files-child-"));
|
|
58
|
+
const path = join(realpathSync(root), "child marker");
|
|
59
|
+
const child = Bun.spawn(
|
|
60
|
+
[
|
|
61
|
+
process.execPath,
|
|
62
|
+
"--eval",
|
|
63
|
+
`
|
|
64
|
+
import { openSync } from 'node:fs';
|
|
65
|
+
const descriptor = openSync(${JSON.stringify(path)}, 'w');
|
|
66
|
+
console.log('ready');
|
|
67
|
+
setInterval(() => {}, 1000);
|
|
68
|
+
`,
|
|
69
|
+
],
|
|
70
|
+
{ stdout: "pipe", stderr: "pipe", windowsHide: true },
|
|
71
|
+
);
|
|
72
|
+
try {
|
|
73
|
+
const reader = child.stdout.getReader();
|
|
74
|
+
const ready = await reader.read();
|
|
75
|
+
reader.releaseLock();
|
|
76
|
+
expect(new TextDecoder().decode(ready.value)).toContain("ready");
|
|
77
|
+
const inventory = listOpenFiles(child.pid);
|
|
78
|
+
if (!inventory.available) throw new Error(inventory.reason);
|
|
79
|
+
expect(inventory.paths).toContain(path);
|
|
80
|
+
} finally {
|
|
81
|
+
child.kill();
|
|
82
|
+
await child.exited;
|
|
83
|
+
cleanupTestTempDir(root);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
test.skipIf(process.platform !== "linux")("Linux inventory skips vanished descriptors", () => {
|
|
89
|
+
const readlink = fs.readlinkSync;
|
|
90
|
+
let raced = false;
|
|
91
|
+
const link = spyOn(fs, "readlinkSync").mockImplementation(((path: fs.PathLike) => {
|
|
92
|
+
if (!raced && String(path).startsWith("/proc/self/fd/")) {
|
|
93
|
+
raced = true;
|
|
94
|
+
throw Object.assign(new Error("closed during inventory"), { code: "ENOENT" });
|
|
95
|
+
}
|
|
96
|
+
return readlink(path);
|
|
97
|
+
}) as typeof fs.readlinkSync);
|
|
98
|
+
try {
|
|
99
|
+
expect(listOpenFiles().available).toBe(true);
|
|
100
|
+
expect(raced).toBe(true);
|
|
101
|
+
} finally {
|
|
102
|
+
link.mockRestore();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test.skipIf(process.platform !== "linux")(
|
|
107
|
+
"Linux inventory reports listing failures as unavailable",
|
|
108
|
+
() => {
|
|
109
|
+
const listing = spyOn(fs, "readdirSync").mockImplementation(() => {
|
|
110
|
+
throw new Error("inventory denied");
|
|
111
|
+
});
|
|
112
|
+
try {
|
|
113
|
+
expect(listOpenFiles()).toEqual({ available: false, reason: "inventory denied" });
|
|
114
|
+
} finally {
|
|
115
|
+
listing.mockRestore();
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
test.skipIf(process.platform !== "linux")(
|
|
121
|
+
"child exit during inventory is unavailable, not empty",
|
|
122
|
+
() => {
|
|
123
|
+
const read = fs.readFileSync;
|
|
124
|
+
let reads = 0;
|
|
125
|
+
const stat = spyOn(fs, "readFileSync").mockImplementation(((
|
|
126
|
+
path: fs.PathOrFileDescriptor,
|
|
127
|
+
) => {
|
|
128
|
+
if (String(path) !== "/proc/123456/stat") return read(path);
|
|
129
|
+
return `123456 (test process) ${reads++ === 0 ? "S" : "Z"} ${"0 ".repeat(18)}100`;
|
|
130
|
+
}) as typeof fs.readFileSync);
|
|
131
|
+
const listing = spyOn(fs, "readdirSync").mockReturnValue([]);
|
|
132
|
+
try {
|
|
133
|
+
expect(listOpenFiles(123456)).toEqual({
|
|
134
|
+
available: false,
|
|
135
|
+
reason: "Process 123456 has exited",
|
|
136
|
+
});
|
|
137
|
+
} finally {
|
|
138
|
+
stat.mockRestore();
|
|
139
|
+
listing.mockRestore();
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
test("macOS name parser ignores warnings and preserves paths with spaces", () => {
|
|
145
|
+
expect(
|
|
146
|
+
parseLsofPaths(
|
|
147
|
+
[
|
|
148
|
+
"lsof: WARNING: can't stat() overlay file system /container/one",
|
|
149
|
+
" Output information may be incomplete.",
|
|
150
|
+
"p123",
|
|
151
|
+
"n/private/var/test directory/context.db",
|
|
152
|
+
"n/private/var/test directory/context.db-wal",
|
|
153
|
+
"lsof: WARNING: can't stat() overlay file system /container/two",
|
|
154
|
+
"",
|
|
155
|
+
].join("\n"),
|
|
156
|
+
),
|
|
157
|
+
).toEqual([
|
|
158
|
+
"/private/var/test directory/context.db",
|
|
159
|
+
"/private/var/test directory/context.db-wal",
|
|
160
|
+
]);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("macOS name parser keeps paths beyond the old 1 MiB subprocess limit", () => {
|
|
164
|
+
const paths = Array.from(
|
|
165
|
+
{ length: 24_000 },
|
|
166
|
+
(_, index) => `/private/var/test directory/fixture-${index}.db`,
|
|
167
|
+
);
|
|
168
|
+
const output = `p123\n${paths.map((path) => `n${path}\n`).join("")}`;
|
|
169
|
+
expect(Buffer.byteLength(output)).toBeGreaterThan(1024 * 1024);
|
|
170
|
+
expect(parseLsofPaths(output)).toEqual(paths);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("macOS inventory requests name fields with a 64 MiB buffer", () => {
|
|
174
|
+
const platform = Object.getOwnPropertyDescriptor(process, "platform")!;
|
|
175
|
+
const execute = spyOn(childProcess, "execFileSync").mockReturnValue("p123\nn/test file.db\n");
|
|
176
|
+
try {
|
|
177
|
+
// Exercise command construction on every host without needing a macOS subprocess.
|
|
178
|
+
Object.defineProperty(process, "platform", { value: "darwin" });
|
|
179
|
+
expect(listOpenFiles(123)).toEqual({
|
|
180
|
+
available: true,
|
|
181
|
+
paths: ["/test file.db"],
|
|
182
|
+
entries: [{ path: "/test file.db" }],
|
|
183
|
+
});
|
|
184
|
+
expect(execute).toHaveBeenCalledWith("lsof", ["-p", "123", "-Fn"], {
|
|
185
|
+
encoding: "utf8",
|
|
186
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
187
|
+
timeout: 10_000,
|
|
188
|
+
windowsHide: true,
|
|
189
|
+
});
|
|
190
|
+
} finally {
|
|
191
|
+
Object.defineProperty(process, "platform", platform);
|
|
192
|
+
execute.mockRestore();
|
|
193
|
+
}
|
|
194
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { readdirSync, readFileSync, readlinkSync } from "node:fs";
|
|
3
|
+
|
|
4
|
+
export interface OpenFileEntry {
|
|
5
|
+
path: string;
|
|
6
|
+
descriptor?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type OpenFilesResult =
|
|
10
|
+
| { available: true; paths: string[]; entries: OpenFileEntry[] }
|
|
11
|
+
| { available: false; reason: string };
|
|
12
|
+
|
|
13
|
+
/** Parse lsof's name fields without interpreting its padded human-readable table. */
|
|
14
|
+
export function parseLsofPaths(output: string): string[] {
|
|
15
|
+
return output
|
|
16
|
+
.split("\n")
|
|
17
|
+
.filter((line) => line.startsWith("n"))
|
|
18
|
+
.map((line) => line.slice(1));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function processIdentity(pid: number): string {
|
|
22
|
+
const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
23
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
24
|
+
if (["Z", "X", "x"].includes(fields[0] ?? "")) throw new Error(`Process ${pid} has exited`);
|
|
25
|
+
const startTime = fields[19];
|
|
26
|
+
if (!startTime) throw new Error(`Cannot read identity for process ${pid}`);
|
|
27
|
+
return startTime; // Start time distinguishes a reused PID from the requested process.
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Test-only inventory; callers decide whether an unavailable check can be skipped. */
|
|
31
|
+
export function listOpenFiles(pid = process.pid): OpenFilesResult {
|
|
32
|
+
try {
|
|
33
|
+
if (process.platform === "linux") {
|
|
34
|
+
// /proc avoids subprocess output limits and lsof's overlay-mount warnings.
|
|
35
|
+
const directory = pid === process.pid ? "/proc/self/fd" : `/proc/${pid}/fd`;
|
|
36
|
+
const identity = pid === process.pid ? undefined : processIdentity(pid);
|
|
37
|
+
const entries: OpenFileEntry[] = [];
|
|
38
|
+
for (const descriptor of readdirSync(directory)) {
|
|
39
|
+
try {
|
|
40
|
+
entries.push({
|
|
41
|
+
descriptor: Number(descriptor),
|
|
42
|
+
path: readlinkSync(`${directory}/${descriptor}`),
|
|
43
|
+
});
|
|
44
|
+
} catch (error) {
|
|
45
|
+
// The listing's own directory handle, or any concurrent close, can vanish.
|
|
46
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (identity !== undefined && processIdentity(pid) !== identity)
|
|
50
|
+
throw new Error(`Process ${pid} changed during the inventory`);
|
|
51
|
+
return { available: true, paths: entries.map((entry) => entry.path), entries };
|
|
52
|
+
}
|
|
53
|
+
if (process.platform === "darwin") {
|
|
54
|
+
const paths = parseLsofPaths(
|
|
55
|
+
execFileSync("lsof", ["-p", String(pid), "-Fn"], {
|
|
56
|
+
encoding: "utf8",
|
|
57
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
58
|
+
timeout: 10_000,
|
|
59
|
+
windowsHide: true,
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
return { available: true, paths, entries: paths.map((path) => ({ path })) };
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
available: false,
|
|
66
|
+
reason: `Open-file inventory is unavailable on ${process.platform}`,
|
|
67
|
+
};
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return { available: false, reason: error instanceof Error ? error.message : String(error) };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -17,8 +17,14 @@ export const USER_FACING_FAILURES = {
|
|
|
17
17
|
history_boundary_unresolved: {
|
|
18
18
|
code: "MC-H04",
|
|
19
19
|
sentence:
|
|
20
|
-
"This request was not sent:
|
|
21
|
-
action: "
|
|
20
|
+
"This request was not sent: it is larger than the model's context window, and Magic Context could not cut the already-summarized history out of it.",
|
|
21
|
+
action: "Run /ctx-flush to compress the history now, then send your message again.",
|
|
22
|
+
},
|
|
23
|
+
history_boundary_recovering: {
|
|
24
|
+
code: "MC-H08",
|
|
25
|
+
sentence:
|
|
26
|
+
"This request was not sent: it is larger than the model's context window, and Magic Context could not cut the already-summarized history out of it.",
|
|
27
|
+
action: "Send your message again: Magic Context will first summarize more of the history and drop old tool output to make it fit.",
|
|
22
28
|
},
|
|
23
29
|
history_over_window_unmanaged: {
|
|
24
30
|
code: "MC-H06",
|