@claudexor/context 1.0.0
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/LICENSE +21 -0
- package/README.md +7 -0
- package/dist/agents.d.ts +15 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +37 -0
- package/dist/agents.js.map +1 -0
- package/dist/atlas.d.ts +24 -0
- package/dist/atlas.d.ts.map +1 -0
- package/dist/atlas.js +244 -0
- package/dist/atlas.js.map +1 -0
- package/dist/contextpack.d.ts +24 -0
- package/dist/contextpack.d.ts.map +1 -0
- package/dist/contextpack.js +60 -0
- package/dist/contextpack.js.map +1 -0
- package/dist/evidence.d.ts +33 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +98 -0
- package/dist/evidence.js.map +1 -0
- package/dist/glob.d.ts +4 -0
- package/dist/glob.d.ts.map +1 -0
- package/dist/glob.js +40 -0
- package/dist/glob.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 joi-lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @claudexor/context
|
|
2
|
+
|
|
3
|
+
Internal package of [Claudexor](https://github.com/razzant/claudexor) — AGENTS.md-first context: Scope Atlas (no silent truncation), hashable ContextPack, evidence packet.
|
|
4
|
+
|
|
5
|
+
Published as part of the Claudexor toolchain; it follows the monorepo's
|
|
6
|
+
lockstep version and has no separate semver contract. Use the `claudexor`
|
|
7
|
+
CLI (or `@claudexor/cli`) as the supported entry point.
|
package/dist/agents.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface AgentsDoc {
|
|
2
|
+
path: string;
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Discover AGENTS.md files from the repo root down to `startDir` (closest wins).
|
|
7
|
+
* Per directory, `AGENTS.override.md` beats `AGENTS.md`. Returns root-first order
|
|
8
|
+
* so concatenation lets deeper files override earlier guidance.
|
|
9
|
+
*/
|
|
10
|
+
export declare function discoverAgentsFiles(repoRoot: string, startDir?: string): AgentsDoc[];
|
|
11
|
+
export declare function loadAgentsInstructions(repoRoot: string, startDir?: string): {
|
|
12
|
+
text: string;
|
|
13
|
+
sources: string[];
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,EAAE,CAuBpF;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM,GAChB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAMrC"}
|
package/dist/agents.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { join, relative, sep } from "node:path";
|
|
2
|
+
import { readTextSafe } from "@claudexor/util";
|
|
3
|
+
/**
|
|
4
|
+
* Discover AGENTS.md files from the repo root down to `startDir` (closest wins).
|
|
5
|
+
* Per directory, `AGENTS.override.md` beats `AGENTS.md`. Returns root-first order
|
|
6
|
+
* so concatenation lets deeper files override earlier guidance.
|
|
7
|
+
*/
|
|
8
|
+
export function discoverAgentsFiles(repoRoot, startDir) {
|
|
9
|
+
const start = startDir ?? repoRoot;
|
|
10
|
+
const rel = relative(repoRoot, start);
|
|
11
|
+
const segments = rel && !rel.startsWith("..") ? rel.split(sep).filter(Boolean) : [];
|
|
12
|
+
const dirs = [repoRoot];
|
|
13
|
+
let dir = repoRoot;
|
|
14
|
+
for (const seg of segments) {
|
|
15
|
+
dir = join(dir, seg);
|
|
16
|
+
dirs.push(dir);
|
|
17
|
+
}
|
|
18
|
+
const docs = [];
|
|
19
|
+
for (const d of dirs) {
|
|
20
|
+
for (const name of ["AGENTS.override.md", "AGENTS.md"]) {
|
|
21
|
+
const content = readTextSafe(join(d, name));
|
|
22
|
+
if (content !== null && content.trim().length > 0) {
|
|
23
|
+
docs.push({ path: join(d, name), content });
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return docs;
|
|
29
|
+
}
|
|
30
|
+
export function loadAgentsInstructions(repoRoot, startDir) {
|
|
31
|
+
const docs = discoverAgentsFiles(repoRoot, startDir);
|
|
32
|
+
return {
|
|
33
|
+
text: docs.map((d) => d.content.trim()).join("\n\n---\n\n"),
|
|
34
|
+
sources: docs.map((d) => d.path),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=agents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAO/C;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAgB,EAAE,QAAiB;IACrE,MAAM,KAAK,GAAG,QAAQ,IAAI,QAAQ,CAAC;IACnC,MAAM,GAAG,GAAG,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACtC,MAAM,QAAQ,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAEpF,MAAM,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxB,IAAI,GAAG,GAAG,QAAQ,CAAC;IACnB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;IAED,MAAM,IAAI,GAAgB,EAAE,CAAC;IAC7B,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,KAAK,MAAM,IAAI,IAAI,CAAC,oBAAoB,EAAE,WAAW,CAAC,EAAE,CAAC;YACvD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;YAC5C,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAClD,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;gBAC5C,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,QAAgB,EAChB,QAAiB;IAEjB,MAAM,IAAI,GAAG,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrD,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC;QAC3D,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC"}
|
package/dist/atlas.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ContextFileRef, OmissionEntry, ScopeAtlasEntry } from "@claudexor/schema";
|
|
2
|
+
export interface AtlasOptions {
|
|
3
|
+
include?: string[];
|
|
4
|
+
exclude?: string[];
|
|
5
|
+
mandatory?: string[];
|
|
6
|
+
maxFileBytes?: number;
|
|
7
|
+
tokenLimit?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface AtlasResult {
|
|
10
|
+
atlas: ScopeAtlasEntry[];
|
|
11
|
+
mandatory: ContextFileRef[];
|
|
12
|
+
included: ContextFileRef[];
|
|
13
|
+
omitted: OmissionEntry[];
|
|
14
|
+
estimatedTokens: number;
|
|
15
|
+
tokenLimit: number;
|
|
16
|
+
missingMandatory: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Account for EVERY tracked path with a disposition (no silent truncation).
|
|
20
|
+
* Source files are inlined ("full") until the token budget is reached; the rest
|
|
21
|
+
* are recorded as omitted with a reason, plus an explicit OMISSIONS list.
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildScopeAtlas(repoRoot: string, opts?: AtlasOptions): Promise<AtlasResult>;
|
|
24
|
+
//# sourceMappingURL=atlas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atlas.d.ts","sourceRoot":"","sources":["../src/atlas.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AA4CxF,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AA+ED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAmHrG"}
|
package/dist/atlas.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { lstatSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { extname, join, relative, sep } from "node:path";
|
|
3
|
+
import { runCapture } from "@claudexor/core";
|
|
4
|
+
import { sha256 } from "@claudexor/util";
|
|
5
|
+
import { matchAny } from "./glob.js";
|
|
6
|
+
const SENSITIVE = [
|
|
7
|
+
"**/.env",
|
|
8
|
+
"**/.env.*",
|
|
9
|
+
".env",
|
|
10
|
+
".env.*",
|
|
11
|
+
"**/secrets/**",
|
|
12
|
+
"**/*.pem",
|
|
13
|
+
"**/*.key",
|
|
14
|
+
"**/id_rsa*",
|
|
15
|
+
"**/*.p12",
|
|
16
|
+
"**/credentials*.json",
|
|
17
|
+
];
|
|
18
|
+
const MANIFEST_ONLY = [
|
|
19
|
+
"**/pnpm-lock.yaml",
|
|
20
|
+
"pnpm-lock.yaml",
|
|
21
|
+
"**/package-lock.json",
|
|
22
|
+
"**/yarn.lock",
|
|
23
|
+
"**/Cargo.lock",
|
|
24
|
+
"**/poetry.lock",
|
|
25
|
+
"**/go.sum",
|
|
26
|
+
];
|
|
27
|
+
const VENDORED = [
|
|
28
|
+
"**/node_modules/**",
|
|
29
|
+
"**/dist/**",
|
|
30
|
+
"**/build/**",
|
|
31
|
+
"**/.next/**",
|
|
32
|
+
"**/vendor/**",
|
|
33
|
+
"**/.turbo/**",
|
|
34
|
+
"**/coverage/**",
|
|
35
|
+
"**/*.min.js",
|
|
36
|
+
"**/*.min.css",
|
|
37
|
+
"**/*.map",
|
|
38
|
+
];
|
|
39
|
+
const BINARY_EXT = new Set([
|
|
40
|
+
".png", ".jpg", ".jpeg", ".gif", ".webp", ".ico", ".pdf", ".zip", ".gz", ".tar",
|
|
41
|
+
".tgz", ".zst", ".woff", ".woff2", ".ttf", ".eot", ".mp4", ".mov", ".mp3", ".wav",
|
|
42
|
+
".bin", ".so", ".dylib", ".dll", ".node", ".class", ".jar", ".wasm", ".o", ".a",
|
|
43
|
+
]);
|
|
44
|
+
async function listFiles(repoRoot) {
|
|
45
|
+
try {
|
|
46
|
+
const r = await runCapture("git", ["-C", repoRoot, "ls-files", "--cached", "--others", "--exclude-standard"], { timeoutMs: 30_000 });
|
|
47
|
+
if (r.code === 0) {
|
|
48
|
+
const files = r.stdout.split("\n").map((s) => s.trim()).filter(Boolean);
|
|
49
|
+
if (files.length > 0)
|
|
50
|
+
return files;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
/* not a git repo or git missing — fall back to walk */
|
|
55
|
+
}
|
|
56
|
+
return walk(repoRoot, repoRoot);
|
|
57
|
+
}
|
|
58
|
+
function walk(root, dir, seenDirs = new Set()) {
|
|
59
|
+
const skip = new Set([".git", "node_modules", "dist", ".turbo", ".claudexor", "coverage"]);
|
|
60
|
+
const out = [];
|
|
61
|
+
// Symlink cycle guard: `ln -s . loop` used to recurse until stack
|
|
62
|
+
// overflow, and a symlink to / walked the filesystem into the ContextPack.
|
|
63
|
+
// Directory SYMLINKS are skipped entirely (the fallback walker only maps
|
|
64
|
+
// the real tree); real dirs are deduped by their resolved identity.
|
|
65
|
+
let realDir;
|
|
66
|
+
try {
|
|
67
|
+
realDir = realpathSync(dir);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
if (seenDirs.has(realDir))
|
|
73
|
+
return out;
|
|
74
|
+
seenDirs.add(realDir);
|
|
75
|
+
for (const name of readdirSync(dir)) {
|
|
76
|
+
if (skip.has(name))
|
|
77
|
+
continue;
|
|
78
|
+
const full = join(dir, name);
|
|
79
|
+
let l;
|
|
80
|
+
try {
|
|
81
|
+
l = lstatSync(full);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (l.isSymbolicLink()) {
|
|
87
|
+
// A symlinked DIR is skipped (cycle or out-of-tree). A symlinked FILE
|
|
88
|
+
// maps ONLY when its resolved target stays INSIDE the mapped tree —
|
|
89
|
+
// `ln -s ~/.ssh/id_rsa leak.txt` must never pull host files into the
|
|
90
|
+
// ContextPack (context collection is scoped to the target tree).
|
|
91
|
+
let resolved;
|
|
92
|
+
let rootReal;
|
|
93
|
+
try {
|
|
94
|
+
rootReal = realpathSync(root);
|
|
95
|
+
resolved = realpathSync(full);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
let s;
|
|
101
|
+
try {
|
|
102
|
+
s = statSync(full);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (s.isDirectory())
|
|
108
|
+
continue;
|
|
109
|
+
const insideTree = resolved === rootReal || resolved.startsWith(rootReal + sep);
|
|
110
|
+
if (!insideTree)
|
|
111
|
+
continue;
|
|
112
|
+
out.push(relative(root, full));
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (l.isDirectory())
|
|
116
|
+
out.push(...walk(root, full, seenDirs));
|
|
117
|
+
else
|
|
118
|
+
out.push(relative(root, full));
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
/** estimate tokens from byte/char length (~4 chars/token). */
|
|
123
|
+
function estTokens(n) {
|
|
124
|
+
return Math.ceil(n / 4);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Account for EVERY tracked path with a disposition (no silent truncation).
|
|
128
|
+
* Source files are inlined ("full") until the token budget is reached; the rest
|
|
129
|
+
* are recorded as omitted with a reason, plus an explicit OMISSIONS list.
|
|
130
|
+
*/
|
|
131
|
+
export async function buildScopeAtlas(repoRoot, opts = {}) {
|
|
132
|
+
const exclude = opts.exclude ?? [];
|
|
133
|
+
const include = opts.include ?? [];
|
|
134
|
+
const mandatorySet = new Set(opts.mandatory ?? []);
|
|
135
|
+
const maxFileBytes = opts.maxFileBytes ?? 256 * 1024;
|
|
136
|
+
const tokenLimit = opts.tokenLimit ?? 200_000;
|
|
137
|
+
const files = new Set(await listFiles(repoRoot));
|
|
138
|
+
const atlas = [];
|
|
139
|
+
const candidates = [];
|
|
140
|
+
// Symlink containment at the READ point (not just the fallback walker):
|
|
141
|
+
// `git ls-files` happily lists a TRACKED symlink like `leak.txt ->
|
|
142
|
+
// ~/.ssh/id_rsa`, and stat/readFile would follow it OUT of the tree.
|
|
143
|
+
// Context collection is scoped to the target tree — an out-of-tree
|
|
144
|
+
// symlink is accounted as excluded, never silently read.
|
|
145
|
+
let repoRootReal;
|
|
146
|
+
try {
|
|
147
|
+
repoRootReal = realpathSync(repoRoot);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
repoRootReal = repoRoot;
|
|
151
|
+
}
|
|
152
|
+
const escapesTree = (rel) => {
|
|
153
|
+
try {
|
|
154
|
+
if (!lstatSync(join(repoRoot, rel)).isSymbolicLink())
|
|
155
|
+
return false;
|
|
156
|
+
const resolved = realpathSync(join(repoRoot, rel));
|
|
157
|
+
return resolved !== repoRootReal && !resolved.startsWith(repoRootReal + sep);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return true; // unresolvable symlink: never read through it
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
for (const rel of files) {
|
|
164
|
+
if (escapesTree(rel)) {
|
|
165
|
+
atlas.push({ path: rel, disposition: "excluded", reason: "symlink resolves outside the tree" });
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
let bytes = 0;
|
|
169
|
+
try {
|
|
170
|
+
bytes = statSync(join(repoRoot, rel)).size;
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
atlas.push({ path: rel, disposition: "read_error", reason: "stat failed" });
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const mandatory = mandatorySet.has(rel);
|
|
177
|
+
if (!mandatory) {
|
|
178
|
+
if (matchAny(rel, SENSITIVE)) {
|
|
179
|
+
atlas.push({ path: rel, disposition: "sensitive", bytes });
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
if (BINARY_EXT.has(extname(rel).toLowerCase())) {
|
|
183
|
+
atlas.push({ path: rel, disposition: "binary", bytes });
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (matchAny(rel, MANIFEST_ONLY)) {
|
|
187
|
+
atlas.push({ path: rel, disposition: "manifest_only", bytes });
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (matchAny(rel, VENDORED)) {
|
|
191
|
+
atlas.push({ path: rel, disposition: "vendored", bytes });
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (exclude.length > 0 && matchAny(rel, exclude)) {
|
|
195
|
+
atlas.push({ path: rel, disposition: "excluded", bytes });
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (include.length > 0 && !matchAny(rel, include)) {
|
|
199
|
+
atlas.push({ path: rel, disposition: "excluded", bytes, reason: "not in include set" });
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (bytes > maxFileBytes) {
|
|
203
|
+
atlas.push({ path: rel, disposition: "oversized", bytes, reason: `> ${maxFileBytes} bytes` });
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
candidates.push({ rel, bytes, mandatory });
|
|
208
|
+
}
|
|
209
|
+
candidates.sort((a, b) => a.mandatory === b.mandatory ? a.rel.localeCompare(b.rel) : a.mandatory ? -1 : 1);
|
|
210
|
+
let used = 0;
|
|
211
|
+
const mandatory = [];
|
|
212
|
+
const included = [];
|
|
213
|
+
const omitted = [];
|
|
214
|
+
const missingMandatory = [];
|
|
215
|
+
for (const c of candidates) {
|
|
216
|
+
if (!c.mandatory && used + estTokens(c.bytes) > tokenLimit) {
|
|
217
|
+
atlas.push({ path: c.rel, disposition: "omitted", bytes: c.bytes, reason: "token_budget" });
|
|
218
|
+
omitted.push({ path: c.rel, reason: "token budget exceeded", replacement: "index" });
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
let content;
|
|
222
|
+
try {
|
|
223
|
+
content = readFileSync(join(repoRoot, c.rel), "utf8");
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
atlas.push({ path: c.rel, disposition: "read_error", bytes: c.bytes, reason: "read failed" });
|
|
227
|
+
if (c.mandatory)
|
|
228
|
+
missingMandatory.push(c.rel);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const hash = sha256(content);
|
|
232
|
+
used += estTokens(content.length);
|
|
233
|
+
atlas.push({ path: c.rel, disposition: "full", bytes: c.bytes, hash });
|
|
234
|
+
(c.mandatory ? mandatory : included).push({ path: c.rel, hash });
|
|
235
|
+
}
|
|
236
|
+
// mandatory files that were not found at all
|
|
237
|
+
for (const m of mandatorySet) {
|
|
238
|
+
if (!files.has(m))
|
|
239
|
+
missingMandatory.push(m);
|
|
240
|
+
}
|
|
241
|
+
atlas.sort((a, b) => a.path.localeCompare(b.path));
|
|
242
|
+
return { atlas, mandatory, included, omitted, estimatedTokens: used, tokenLimit, missingMandatory };
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=atlas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atlas.js","sourceRoot":"","sources":["../src/atlas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACvF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,MAAM,SAAS,GAAG;IAChB,SA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;QAC7B,IAAI,IAAI,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAClC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,6CAA6C;IAC7C,KAAK,MAAM,CAAC,IAAI,YAAY,EAAE,CAAC;QAC7B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACnD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC;AACtG,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ContextPack, TaskContract } from "@claudexor/schema";
|
|
2
|
+
import { type AtlasOptions } from "./atlas.js";
|
|
3
|
+
export interface ContextPackOptions extends AtlasOptions {
|
|
4
|
+
/** Fail closed if explicitly-requested mandatory files are missing/unreadable. Default true. */
|
|
5
|
+
failOnMissingMandatory?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const DEFAULT_MANDATORY_CONTEXT: string[];
|
|
8
|
+
/**
|
|
9
|
+
* Uniform fail-closed preflight for EXPLICITLY-configured mandatory context.
|
|
10
|
+
* Called by every run mode (ask/plan/audit/agent/orchestrate) so a versioned
|
|
11
|
+
* `mandatory_files` contract is honored identically — not just by the modes that
|
|
12
|
+
* happen to build a ContextPack (the bug where `audit` failed but `run`/`ask`
|
|
13
|
+
* silently passed the same repo). A no-op when the list is empty (the default,
|
|
14
|
+
* since `claudexor init` no longer seeds it), so fresh repos are never gated.
|
|
15
|
+
* Read-only: only checks file readability, never mutates.
|
|
16
|
+
*/
|
|
17
|
+
export declare function assertMandatoryContext(repoRoot: string, mandatoryFiles: readonly string[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* Build a deterministic, hashable ContextPack. Every tracked path is accounted
|
|
20
|
+
* for via the Scope Atlas; omissions are explicit. Fails closed when caller-
|
|
21
|
+
* specified mandatory files cannot be read (BIBLE P6: no silent truncation).
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildContextPack(repoRoot: string, contract: TaskContract, opts?: ContextPackOptions): Promise<ContextPack>;
|
|
24
|
+
//# sourceMappingURL=contextpack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextpack.d.ts","sourceRoot":"","sources":["../src/contextpack.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKnE,OAAO,EAAE,KAAK,YAAY,EAAmB,MAAM,YAAY,CAAC;AAEhE,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,gGAAgG;IAChG,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,eAAO,MAAM,yBAAyB,UAAwC,CAAC;AAE/E;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAiBhG;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,YAAY,EACtB,IAAI,GAAE,kBAAuB,GAC5B,OAAO,CAAC,WAAW,CAAC,CAqBtB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { isAbsolute, resolve, sep } from "node:path";
|
|
2
|
+
import { ContextPack as ContextPackSchema } from "@claudexor/schema";
|
|
3
|
+
import { ContextOverflowError } from "@claudexor/core";
|
|
4
|
+
import { hashJson, readTextSafe } from "@claudexor/util";
|
|
5
|
+
import { loadAgentsInstructions } from "./agents.js";
|
|
6
|
+
import { buildScopeAtlas } from "./atlas.js";
|
|
7
|
+
export const DEFAULT_MANDATORY_CONTEXT = ["README.md", "docs/ARCHITECTURE.md"];
|
|
8
|
+
/**
|
|
9
|
+
* Uniform fail-closed preflight for EXPLICITLY-configured mandatory context.
|
|
10
|
+
* Called by every run mode (ask/plan/audit/agent/orchestrate) so a versioned
|
|
11
|
+
* `mandatory_files` contract is honored identically — not just by the modes that
|
|
12
|
+
* happen to build a ContextPack (the bug where `audit` failed but `run`/`ask`
|
|
13
|
+
* silently passed the same repo). A no-op when the list is empty (the default,
|
|
14
|
+
* since `claudexor init` no longer seeds it), so fresh repos are never gated.
|
|
15
|
+
* Read-only: only checks file readability, never mutates.
|
|
16
|
+
*/
|
|
17
|
+
export function assertMandatoryContext(repoRoot, mandatoryFiles) {
|
|
18
|
+
if (mandatoryFiles.length === 0)
|
|
19
|
+
return;
|
|
20
|
+
const base = resolve(repoRoot);
|
|
21
|
+
const missing = [];
|
|
22
|
+
for (const rel of mandatoryFiles) {
|
|
23
|
+
// Versioned project config must not point mandatory context OUTSIDE the repo
|
|
24
|
+
// (absolute paths or `..` traversal): fail closed rather than read host files
|
|
25
|
+
// (versioned config never self-grants powers).
|
|
26
|
+
const abs = resolve(base, rel);
|
|
27
|
+
if (isAbsolute(rel) || (abs !== base && !abs.startsWith(base + sep))) {
|
|
28
|
+
throw new ContextOverflowError(`mandatory context path escapes the repo: ${rel}`);
|
|
29
|
+
}
|
|
30
|
+
if (readTextSafe(abs) === null)
|
|
31
|
+
missing.push(rel);
|
|
32
|
+
}
|
|
33
|
+
if (missing.length > 0) {
|
|
34
|
+
throw new ContextOverflowError(`mandatory context missing/unreadable: ${missing.join(", ")}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build a deterministic, hashable ContextPack. Every tracked path is accounted
|
|
39
|
+
* for via the Scope Atlas; omissions are explicit. Fails closed when caller-
|
|
40
|
+
* specified mandatory files cannot be read (BIBLE P6: no silent truncation).
|
|
41
|
+
*/
|
|
42
|
+
export async function buildContextPack(repoRoot, contract, opts = {}) {
|
|
43
|
+
const usingExplicitMandatory = opts.mandatory !== undefined;
|
|
44
|
+
const mandatory = opts.mandatory ?? DEFAULT_MANDATORY_CONTEXT;
|
|
45
|
+
const atlas = await buildScopeAtlas(repoRoot, { ...opts, mandatory });
|
|
46
|
+
if (usingExplicitMandatory && (opts.failOnMissingMandatory ?? true) && atlas.missingMandatory.length > 0) {
|
|
47
|
+
throw new ContextOverflowError(`mandatory context missing/unreadable: ${atlas.missingMandatory.join(", ")}`);
|
|
48
|
+
}
|
|
49
|
+
const agents = loadAgentsInstructions(repoRoot);
|
|
50
|
+
const taskHash = hashJson(contract);
|
|
51
|
+
const partial = {
|
|
52
|
+
task_contract_hash: taskHash,
|
|
53
|
+
files: { mandatory: atlas.mandatory, included: atlas.included, omitted: atlas.omitted },
|
|
54
|
+
atlas: atlas.atlas,
|
|
55
|
+
instructions: [...agents.sources, "TASK.md", "ACCEPTANCE.md"],
|
|
56
|
+
token_budget: { limit: atlas.tokenLimit, estimated_used: atlas.estimatedTokens },
|
|
57
|
+
};
|
|
58
|
+
return ContextPackSchema.parse({ ...partial, hash: hashJson(partial) });
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=contextpack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextpack.js","sourceRoot":"","sources":["../src/contextpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,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,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `.adversarial-review/` evidence packet that bridges clean-context
|
|
3
|
+
* reviewers: parent context is written to files on disk so critics with no
|
|
4
|
+
* chat history can read it. Critics read these files before producing
|
|
5
|
+
* findings; missing/empty mandatory files => fail closed.
|
|
6
|
+
*/
|
|
7
|
+
export interface EvidencePacket {
|
|
8
|
+
userIntent: string;
|
|
9
|
+
forbiddenFindings?: string;
|
|
10
|
+
planAccepted?: string;
|
|
11
|
+
diff: string;
|
|
12
|
+
filesToReadWhole?: string[];
|
|
13
|
+
tests?: string;
|
|
14
|
+
decidedTradeoffs?: string;
|
|
15
|
+
runtime?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare const MANDATORY_EVIDENCE_FILES: string[];
|
|
18
|
+
export interface DiffEvidence {
|
|
19
|
+
diffPath: string;
|
|
20
|
+
summaryPath: string;
|
|
21
|
+
diffSha256: string;
|
|
22
|
+
summary: string;
|
|
23
|
+
}
|
|
24
|
+
export declare function writeEvidencePacket(dir: string, packet: EvidencePacket): void;
|
|
25
|
+
export declare function writeDiffEvidence(dir: string, diff: string): DiffEvidence;
|
|
26
|
+
export interface PreflightResult {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
missing: string[];
|
|
29
|
+
empty: string[];
|
|
30
|
+
}
|
|
31
|
+
/** Fail-closed pre-flight: all mandatory evidence files must exist and be non-empty. */
|
|
32
|
+
export declare function preflightEvidence(dir: string): PreflightResult;
|
|
33
|
+
//# sourceMappingURL=evidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence.d.ts","sourceRoot":"","sources":["../src/evidence.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,wBAAwB,UAQpC,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,IAAI,CAmB7E;AAWD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAgBzE;AA8CD,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAS9D"}
|
package/dist/evidence.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { parseUnifiedDiff } from "@claudexor/core";
|
|
3
|
+
import { containsSecretLikeToken, readTextSafe, redactSecrets, sha256, writeText } from "@claudexor/util";
|
|
4
|
+
export const MANDATORY_EVIDENCE_FILES = [
|
|
5
|
+
"USER_INTENT.md",
|
|
6
|
+
"FORBIDDEN_FINDINGS.md",
|
|
7
|
+
"PLAN_ACCEPTED.md",
|
|
8
|
+
"DIFF.patch",
|
|
9
|
+
"DIFF_SUMMARY.md",
|
|
10
|
+
"TESTS.txt",
|
|
11
|
+
"DECIDED_TRADEOFFS.md",
|
|
12
|
+
];
|
|
13
|
+
export function writeEvidencePacket(dir, packet) {
|
|
14
|
+
writeText(join(dir, "USER_INTENT.md"), evidenceProse("USER_INTENT.md", packet.userIntent));
|
|
15
|
+
writeText(join(dir, "FORBIDDEN_FINDINGS.md"), evidenceProse("FORBIDDEN_FINDINGS.md", packet.forbiddenFindings, "(none — no approaches explicitly rejected)"));
|
|
16
|
+
writeText(join(dir, "PLAN_ACCEPTED.md"), evidenceProse("PLAN_ACCEPTED.md", packet.planAccepted, "(no formal plan — see USER_INTENT.md for requirements)"));
|
|
17
|
+
writeDiffEvidence(dir, packet.diff);
|
|
18
|
+
writeText(join(dir, "FILES_TO_READ_WHOLE.txt"), redactSecrets((packet.filesToReadWhole ?? []).join("\n")) + "\n");
|
|
19
|
+
writeText(join(dir, "TESTS.txt"), evidenceProse("TESTS.txt", packet.tests, "(tests not run)"));
|
|
20
|
+
writeText(join(dir, "DECIDED_TRADEOFFS.md"), evidenceProse("DECIDED_TRADEOFFS.md", packet.decidedTradeoffs, "(none)"));
|
|
21
|
+
if (packet.runtime !== undefined)
|
|
22
|
+
writeText(join(dir, "RUNTIME.md"), evidenceProse("RUNTIME.md", packet.runtime));
|
|
23
|
+
}
|
|
24
|
+
function evidenceProse(fileName, value, fallback = "") {
|
|
25
|
+
const raw = (value ?? fallback).trim();
|
|
26
|
+
const redacted = redactSecrets(raw);
|
|
27
|
+
if (containsSecretLikeToken(redacted)) {
|
|
28
|
+
throw new Error(`${fileName} evidence contains a secret-like token after redaction; refusing to persist evidence packet`);
|
|
29
|
+
}
|
|
30
|
+
return `${redacted}\n`;
|
|
31
|
+
}
|
|
32
|
+
export function writeDiffEvidence(dir, diff) {
|
|
33
|
+
const normalizedDiff = diff || "(empty diff)\n";
|
|
34
|
+
const diffText = normalizedDiff.endsWith("\n") ? normalizedDiff : `${normalizedDiff}\n`;
|
|
35
|
+
if (containsSecretLikeToken(diffText)) {
|
|
36
|
+
throw new Error("diff evidence contains a secret-like token; refusing to persist raw DIFF.patch");
|
|
37
|
+
}
|
|
38
|
+
const diffPath = join(dir, "DIFF.patch");
|
|
39
|
+
const summaryPath = join(dir, "DIFF_SUMMARY.md");
|
|
40
|
+
const diffSha256 = sha256(diffText);
|
|
41
|
+
const summary = summarizeDiff(diffText, redactSecrets(diffText));
|
|
42
|
+
writeText(diffPath, diffText);
|
|
43
|
+
writeText(summaryPath, `# Diff Summary\n\nDigest: ${diffSha256}\n\n${summary}\n`);
|
|
44
|
+
writeText(join(dir, "DIFF_SHA256.txt"), `${diffSha256}\n`);
|
|
45
|
+
return { diffPath, summaryPath, diffSha256, summary };
|
|
46
|
+
}
|
|
47
|
+
function summarizeDiff(diff, displayDiff = diff) {
|
|
48
|
+
// ONE parser owns diff structure (git-anchored AND plain GNU documents):
|
|
49
|
+
// counts come from the shared parseUnifiedDiff, never from local line
|
|
50
|
+
// scans — a `diff -ruN` patch must not summarize as "Files: 0" while the
|
|
51
|
+
// gates see its files.
|
|
52
|
+
const parsed = parseUnifiedDiff(diff);
|
|
53
|
+
const display = parseUnifiedDiff(displayDiff);
|
|
54
|
+
const fileLabel = (f) => `${f.oldPath ?? "/dev/null"} -> ${f.newPath ?? "/dev/null"}`;
|
|
55
|
+
const allFiles = parsed.files.filter((f) => f.oldPath || f.newPath);
|
|
56
|
+
const displayFiles = display.files.filter((f) => f.oldPath || f.newPath).map(fileLabel);
|
|
57
|
+
const files = displayFiles.slice(0, 80);
|
|
58
|
+
const lines = diff.split(/\r?\n/);
|
|
59
|
+
const fallbackHeaders = displayDiff
|
|
60
|
+
.split(/\r?\n/)
|
|
61
|
+
.filter((line) => /^#{1,6}\s+\S/.test(line) || line.startsWith("### ") || line.startsWith("## "))
|
|
62
|
+
.slice(0, 40);
|
|
63
|
+
const body = [
|
|
64
|
+
`- Patch bytes: ${Buffer.byteLength(diff, "utf8")}`,
|
|
65
|
+
`- Patch lines: ${lines.length}`,
|
|
66
|
+
`- Files: ${allFiles.length}`,
|
|
67
|
+
`- Hunks: ${parsed.hunks}`,
|
|
68
|
+
`- Additions: ${parsed.additions}`,
|
|
69
|
+
`- Deletions: ${parsed.deletions}`,
|
|
70
|
+
];
|
|
71
|
+
if (files.length) {
|
|
72
|
+
body.push("", "Files:", ...files.map((file) => `- ${file}`));
|
|
73
|
+
if (allFiles.length > files.length) {
|
|
74
|
+
body.push(`- ... ${allFiles.length - files.length} more file(s) omitted`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (fallbackHeaders.length) {
|
|
78
|
+
body.push("", "Text sections:", ...fallbackHeaders.map((line) => `- ${line.replace(/^#+\s*/, "")}`));
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
body.push("", "- No unified diff headers detected. Read DIFF.patch for the candidate content.");
|
|
82
|
+
}
|
|
83
|
+
return body.join("\n");
|
|
84
|
+
}
|
|
85
|
+
/** Fail-closed pre-flight: all mandatory evidence files must exist and be non-empty. */
|
|
86
|
+
export function preflightEvidence(dir) {
|
|
87
|
+
const missing = [];
|
|
88
|
+
const empty = [];
|
|
89
|
+
for (const file of MANDATORY_EVIDENCE_FILES) {
|
|
90
|
+
const text = readTextSafe(join(dir, file));
|
|
91
|
+
if (text === null)
|
|
92
|
+
missing.push(file);
|
|
93
|
+
else if (text.trim().length === 0)
|
|
94
|
+
empty.push(file);
|
|
95
|
+
}
|
|
96
|
+
return { ok: missing.length === 0 && empty.length === 0, missing, empty };
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=evidence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evidence.js","sourceRoot":"","sources":["../src/evidence.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAmB1G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IAAI,IAAI,wBAAwB,EAAE,CAAC;QAC5C,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;QAC3C,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aACjC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC5E,CAAC"}
|
package/dist/glob.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkCjD;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAElE"}
|
package/dist/glob.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Minimal glob → RegExp (supports `**`, `*`, `?`), enough for include/exclude lists. */
|
|
2
|
+
export function globToRegExp(glob) {
|
|
3
|
+
let re = "";
|
|
4
|
+
let i = 0;
|
|
5
|
+
while (i < glob.length) {
|
|
6
|
+
const c = glob[i] ?? "";
|
|
7
|
+
if (c === "*") {
|
|
8
|
+
if (glob[i + 1] === "*") {
|
|
9
|
+
if (glob[i + 2] === "/") {
|
|
10
|
+
re += "(?:.*/)?";
|
|
11
|
+
i += 3;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
re += ".*";
|
|
15
|
+
i += 2;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
re += "[^/]*";
|
|
19
|
+
i += 1;
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (c === "?") {
|
|
23
|
+
re += "[^/]";
|
|
24
|
+
i += 1;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if ("\\^$.|+()[]{}".includes(c)) {
|
|
28
|
+
re += "\\" + c;
|
|
29
|
+
i += 1;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
re += c;
|
|
33
|
+
i += 1;
|
|
34
|
+
}
|
|
35
|
+
return new RegExp("^" + re + "$");
|
|
36
|
+
}
|
|
37
|
+
export function matchAny(path, patterns) {
|
|
38
|
+
return patterns.some((p) => globToRegExp(p).test(path));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=glob.js.map
|
package/dist/glob.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../src/glob.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;YACd,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACxB,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;oBACxB,EAAE,IAAI,UAAU,CAAC;oBACjB,CAAC,IAAI,CAAC,CAAC;oBACP,SAAS;gBACX,CAAC;gBACD,EAAE,IAAI,IAAI,CAAC;gBACX,CAAC,IAAI,CAAC,CAAC;gBACP,SAAS;YACX,CAAC;YACD,EAAE,IAAI,OAAO,CAAC;YACd,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACX,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;YACd,EAAE,IAAI,MAAM,CAAC;YACb,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACX,CAAC;QACD,IAAI,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;YAChC,EAAE,IAAI,IAAI,GAAG,CAAC,CAAC;YACf,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACX,CAAC;QACD,EAAE,IAAI,CAAC,CAAC;QACR,CAAC,IAAI,CAAC,CAAC;IACT,CAAC;IACD,OAAO,IAAI,MAAM,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,QAAkB;IACvD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@claudexor/context",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "AGENTS.md-first context: Scope Atlas (no silent truncation), hashable ContextPack, evidence packet.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@claudexor/util": "1.0.0",
|
|
20
|
+
"@claudexor/core": "1.0.0",
|
|
21
|
+
"@claudexor/schema": "1.0.0"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/razzant/claudexor.git",
|
|
26
|
+
"directory": "packages/context"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/razzant/claudexor#readme",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/razzant/claudexor/issues"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20.19"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc",
|
|
40
|
+
"typecheck": "tsc --noEmit"
|
|
41
|
+
}
|
|
42
|
+
}
|