@event4u/agent-config 14.19.0 → 14.20.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/.augment-plugin/marketplace.json +3 -3
- package/.augment-plugin/plugin.json +1 -1
- package/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +108 -156
- package/dist/agent-src/commands/agent-handoff.md +42 -41
- package/dist/agent-src/contexts/execution/host-capability-manifest.md +7 -1
- package/dist/agent-src/rules/untrusted-input-defense.md +0 -2
- package/dist/agent-src/skills/evaluate-llm-feature/SKILL.md +1 -1
- package/dist/agent-src/skills/markitdown/SKILL.md +1 -1
- package/dist/agent-src/skills/skill-improvement-pipeline/SKILL.md +28 -6
- package/dist/agent-src/skills/test-driven-development/SKILL.md +1 -3
- package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
- package/dist/agent-src/templates/roadmaps.md +14 -1
- package/dist/agent-src/templates/scripts/telemetry/mcp_lite.ts +213 -0
- package/dist/agent-src/templates/scripts/telemetry/report_renderer.ts +16 -0
- package/dist/agent-src/templates/scripts/telemetry_report.ts +22 -2
- package/dist/cli/mcp/dispatch.js +10 -0
- package/dist/cli/mcp/stdio.js +33 -2
- package/dist/cli/mcp/telemetry.js +227 -0
- package/dist/cli-delegate/{chunk-GZTMRYCN.js → chunk-C6IPZRDA.js} +79 -12
- package/dist/cli-delegate/{chunk-CYH5SP6M.js → chunk-I6RHFQEG.js} +151 -16
- package/dist/cli-delegate/{chunk-IDHUQIXP.js → chunk-NUMQHLS5.js} +21 -4
- package/dist/cli-delegate/{chunk-PMEKGDED.js → chunk-PI2GU3DP.js} +163 -1
- package/dist/cli-delegate/{chunk-7PRE6ZV2.js → chunk-YS6XTLEK.js} +199 -4
- package/dist/cli-delegate/chunk-ZVBOHSVF.js +1109 -0
- package/dist/cli-delegate/cmd_conformance.js +73 -109
- package/dist/cli-delegate/cmd_doctor.js +2 -2
- package/dist/cli-delegate/cmd_export.js +2 -2
- package/dist/cli-delegate/cmd_handoff.js +41 -11
- package/dist/cli-delegate/cmd_memory_get.js +1 -1
- package/dist/cli-delegate/cmd_prune.js +2 -2
- package/dist/cli-delegate/cmd_route_audit.js +1 -1
- package/dist/cli-delegate/cmd_session_recycle.js +59 -902
- package/dist/cli-delegate/cmd_settings_migrate.js +2 -2
- package/dist/cli-delegate/cmd_sync.js +2 -2
- package/dist/cli-delegate/cmd_uninstall.js +2 -2
- package/dist/cli-delegate/cmd_validate.js +2 -2
- package/dist/discovery/deprecation-report.md +1 -1
- package/dist/discovery/discovery-manifest.json +9 -9
- package/dist/discovery/discovery-manifest.json.sha256 +1 -1
- package/dist/discovery/discovery-manifest.summary.md +1 -1
- package/dist/discovery/dormancy-report.md +1 -1
- package/dist/discovery/orphan-report.md +1 -1
- package/dist/discovery/packs.json +2 -2
- package/dist/discovery/trust-report.md +1 -1
- package/dist/discovery/workspaces.json +2 -2
- package/dist/hooks/dispatch.js +7257 -6497
- package/dist/install/install.mjs +393 -168
- package/dist/mcp/registry-manifest.json +2 -2
- package/dist/mcp/server.json +2 -2
- package/dist/mcp/server.mjs +497 -118
- package/dist/scripts/mcp_server/telemetry.js +148 -0
- package/docs/guidelines/agent-infra/naming.md +1 -1
- package/docs/guidelines/agent-infra/security-lint-containment.md +46 -6
- package/docs/guidelines/agent-infra/self-improvement-pipeline.md +4 -4
- package/docs/guidelines/agent-infra/untrusted-input-spotlighting.md +1 -1
- package/docs/guidelines/redundancy-taxonomy.md +28 -0
- package/package.json +1 -1
- package/src/agent-src/templates/scripts/telemetry/mcp_lite.ts +213 -0
- package/src/agent-src/templates/scripts/telemetry/report_renderer.ts +16 -0
- package/src/agent-src/templates/scripts/telemetry_report.ts +22 -2
- package/src/config/assurance-capability-registry.json +9 -0
- package/src/config/gate-coverage.yml +55 -0
- package/src/config/gate-violation-baselines.json +15 -3
- package/src/scripts/_cli/cmd_session_recycle.ts +51 -3
- package/src/scripts/_lib/audit_field_provenance.ts +44 -3
- package/src/scripts/_lib/host_capability.ts +38 -0
- package/src/scripts/_lib/install_reach_checks.ts +33 -1
- package/src/scripts/_lib/mcp_bridge.ts +222 -10
- package/src/scripts/_lib/mcp_consent_residual.ts +173 -0
- package/src/scripts/_lib/orchestration_record.ts +23 -1
- package/src/scripts/_lib/recycle_envelope_paths.ts +190 -0
- package/src/scripts/_lib/release_position.ts +96 -0
- package/src/scripts/_lib/review_skipped_record.ts +17 -1
- package/src/scripts/_lib/security_lint.ts +179 -7
- package/src/scripts/_lib/self_repair.ts +141 -6
- package/src/scripts/_lib/self_repair_store.ts +273 -7
- package/src/scripts/_lib/subagent_capsule.ts +155 -3
- package/src/scripts/build_rule_trigger_matrix.ts +5 -0
- package/src/scripts/check_mcp_doc_drift.ts +217 -0
- package/src/scripts/check_pack_size.ts +321 -3
- package/src/scripts/handoff_context_hook.ts +54 -7
- package/src/scripts/hooks/session_eol_hook.ts +18 -7
- package/src/scripts/install.ts +4 -4
- package/src/scripts/lint_agent_security.ts +316 -25
- package/src/scripts/lint_confusables.ts +42 -6
- package/src/scripts/lint_handoffs.ts +0 -132
- package/src/scripts/lint_hidden_unicode.ts +49 -7
- package/src/scripts/lint_instruction_smuggling.ts +42 -6
- package/src/scripts/lint_mcp_config_security.ts +42 -6
- package/src/scripts/lint_roadmap_later_disposition.ts +217 -27
- package/src/scripts/lint_skill_frontmatter_safety.ts +43 -7
- package/src/scripts/mcp_server/resources.ts +41 -0
- package/src/scripts/mcp_server/telemetry.ts +19 -4
- package/src/scripts/orchestration_record.ts +12 -1
- package/src/scripts/release.ts +24 -24
- package/src/scripts/release_publication.ts +6 -2
- package/src/scripts/self_repair_cli.ts +31 -1
- package/src/scripts/skill_scout.ts +69 -0
- package/dist/cli-delegate/chunk-2GNWGMAL.js +0 -172
- package/dist/cli-delegate/chunk-LPPWO5CE.js +0 -161
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* The documented MCP client snippets must match the entry the installer writes.
|
|
4
|
+
*
|
|
5
|
+
* `docs/mcp-server.md` documented an absolute `tsx` path in four snippets while
|
|
6
|
+
* the installer wrote an `npx` invocation, so a consumer who followed the docs
|
|
7
|
+
* and a consumer who ran the installer landed on two different servers — for
|
|
8
|
+
* long enough that nobody noticed either was wrong.
|
|
9
|
+
*
|
|
10
|
+
* Scope is two literals in this tree. It asserts NOTHING about host behaviour:
|
|
11
|
+
* that a host reads the file at all is a separate question this gate does not
|
|
12
|
+
* touch and must not be cited for.
|
|
13
|
+
*
|
|
14
|
+
* Exit codes: 0 in sync · 1 drift · 2 a source is missing or unreadable.
|
|
15
|
+
*/
|
|
16
|
+
import * as fs from 'node:fs';
|
|
17
|
+
import * as os from 'node:os';
|
|
18
|
+
import * as path from 'node:path';
|
|
19
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
20
|
+
|
|
21
|
+
import { runGateCli, runSelfTest } from './_lib/gate_self_test.js';
|
|
22
|
+
import { MCP_PACKAGE_NAME, MCP_SERVER_KEY, mcpBridgeEntry } from './_lib/mcp_bridge.js';
|
|
23
|
+
import { reportScanned } from './_lib/scan_scope.js';
|
|
24
|
+
|
|
25
|
+
const _HERE = fileURLToPath(import.meta.url);
|
|
26
|
+
const ROOT = path.resolve(path.dirname(_HERE), '..', '..');
|
|
27
|
+
const DOC_REL = 'docs/mcp-server.md';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A snippet is any fenced block naming our server key.
|
|
31
|
+
*
|
|
32
|
+
* Deliberately not a JSON/YAML parse: the four documented clients use three
|
|
33
|
+
* different shapes (`command` as a string, `command` as an object with `path`,
|
|
34
|
+
* and a YAML list), and a parser per shape would drift from the docs as surely
|
|
35
|
+
* as the docs drifted from the installer. The two facts that matter — the
|
|
36
|
+
* runner and the package spec — are the same literals in all three.
|
|
37
|
+
*/
|
|
38
|
+
export function snippetBlocks(text: string): string[] {
|
|
39
|
+
const out: string[] = [];
|
|
40
|
+
const lines = text.split('\n');
|
|
41
|
+
let open: string[] | null = null;
|
|
42
|
+
for (const line of lines) {
|
|
43
|
+
if (line.startsWith('```')) {
|
|
44
|
+
if (open === null) open = [];
|
|
45
|
+
else {
|
|
46
|
+
const body = open.join('\n');
|
|
47
|
+
if (body.includes(MCP_SERVER_KEY) || body.includes('mcpServers')) out.push(body);
|
|
48
|
+
open = null;
|
|
49
|
+
}
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (open !== null) open.push(line);
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface DocFinding {
|
|
58
|
+
snippet: number;
|
|
59
|
+
reason: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function checkSnippets(text: string, packageRoot: string): DocFinding[] {
|
|
63
|
+
const server = (mcpBridgeEntry(packageRoot)['mcpServers'] as Record<string, unknown>)[
|
|
64
|
+
MCP_SERVER_KEY
|
|
65
|
+
] as { command: string; args: string[] };
|
|
66
|
+
const findings: DocFinding[] = [];
|
|
67
|
+
|
|
68
|
+
snippetBlocks(text).forEach((body, i) => {
|
|
69
|
+
// Only blocks that actually configure the server — a block that merely
|
|
70
|
+
// mentions `mcpServers` in prose is not a client configuration.
|
|
71
|
+
if (!body.includes('command')) return;
|
|
72
|
+
if (!body.includes(server.command)) {
|
|
73
|
+
findings.push({
|
|
74
|
+
snippet: i + 1,
|
|
75
|
+
reason: `does not use the installer's runner \`${server.command}\``,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (!body.includes(MCP_PACKAGE_NAME)) {
|
|
79
|
+
findings.push({
|
|
80
|
+
snippet: i + 1,
|
|
81
|
+
reason: `does not name the package \`${MCP_PACKAGE_NAME}\``,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// QUOTED, not a substring: `mcp-server` contains `serve`, so a plain
|
|
85
|
+
// `includes` reported a snippet as current after the entry had been
|
|
86
|
+
// changed to `serve` and the doc had not — measured, on this gate's own
|
|
87
|
+
// sensitivity probe. Every documented shape quotes the token.
|
|
88
|
+
const subcommand = server.args[server.args.length - 1] as string;
|
|
89
|
+
if (!body.includes(`"${subcommand}"`)) {
|
|
90
|
+
findings.push({
|
|
91
|
+
snippet: i + 1,
|
|
92
|
+
reason: `does not invoke \`${subcommand}\``,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (body.includes('node_modules/.bin/tsx')) {
|
|
96
|
+
findings.push({
|
|
97
|
+
snippet: i + 1,
|
|
98
|
+
reason: 'documents an absolute tsx path the installer never writes',
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return findings;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function main(): number {
|
|
106
|
+
if (process.argv.slice(2).includes('--self-test')) return selfTest();
|
|
107
|
+
const rootIdx = process.argv.indexOf('--root');
|
|
108
|
+
const root = rootIdx === -1 ? ROOT : (process.argv[rootIdx + 1] ?? ROOT);
|
|
109
|
+
const doc = path.join(root, DOC_REL);
|
|
110
|
+
if (!fs.existsSync(doc)) {
|
|
111
|
+
process.stderr.write(`❌ ${DOC_REL} not found under ${root}\n`);
|
|
112
|
+
return 2;
|
|
113
|
+
}
|
|
114
|
+
const text = fs.readFileSync(doc, 'utf-8');
|
|
115
|
+
const blocks = snippetBlocks(text).filter((b) => b.includes('command'));
|
|
116
|
+
const findings = checkSnippets(text, root);
|
|
117
|
+
|
|
118
|
+
reportScanned({
|
|
119
|
+
gate: 'check_mcp_doc_drift',
|
|
120
|
+
scanned: blocks.length,
|
|
121
|
+
units: 'documented client snippet(s)',
|
|
122
|
+
roots: [DOC_REL],
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (findings.length > 0) {
|
|
126
|
+
for (const f of findings) {
|
|
127
|
+
process.stdout.write(`❌ ${DOC_REL} snippet ${String(f.snippet)}: ${f.reason}\n`);
|
|
128
|
+
}
|
|
129
|
+
process.stdout.write(
|
|
130
|
+
`\n${String(findings.length)} finding(s). The documented entry and the entry ` +
|
|
131
|
+
'`mcpBridgeEntry()` writes have drifted apart.\n',
|
|
132
|
+
);
|
|
133
|
+
return 1;
|
|
134
|
+
}
|
|
135
|
+
process.stdout.write(
|
|
136
|
+
`✅ check_mcp_doc_drift: ${String(blocks.length)} documented snippet(s) match the ` +
|
|
137
|
+
'installer entry.\n',
|
|
138
|
+
);
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** One rejecting case per way the two literals can drift. */
|
|
143
|
+
function selfTest(): number {
|
|
144
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mcp-doc-drift-'));
|
|
145
|
+
const write = (name: string, doc: string): string => {
|
|
146
|
+
const dir = path.join(tmp, name);
|
|
147
|
+
fs.mkdirSync(path.join(dir, 'docs'), { recursive: true });
|
|
148
|
+
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({ version: '1.0.0' }));
|
|
149
|
+
fs.writeFileSync(path.join(dir, DOC_REL), doc, 'utf-8');
|
|
150
|
+
return dir;
|
|
151
|
+
};
|
|
152
|
+
const run = (root: string): number =>
|
|
153
|
+
runGateCli(ROOT, 'src/scripts/check_mcp_doc_drift.ts', ['--root', root], root);
|
|
154
|
+
|
|
155
|
+
const good = [
|
|
156
|
+
'```json',
|
|
157
|
+
'{ "mcpServers": { "agent-config": {',
|
|
158
|
+
' "command": "npx",',
|
|
159
|
+
' "args": ["-y", "@event4u/agent-config@<version>", "mcp-server"] } } }',
|
|
160
|
+
'```',
|
|
161
|
+
'',
|
|
162
|
+
].join('\n');
|
|
163
|
+
const tsxPath = good.replace('"npx"', '"/abs/agent-config/node_modules/.bin/tsx"');
|
|
164
|
+
const noPackage = good.replace('@event4u/agent-config@<version>', 'some-other-package');
|
|
165
|
+
const noSubcommand = good.replace('"mcp-server"', '"serve"');
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
return runSelfTest({
|
|
169
|
+
gate: 'check_mcp_doc_drift',
|
|
170
|
+
minCases: 4,
|
|
171
|
+
minRejectCases: 3,
|
|
172
|
+
cases: [
|
|
173
|
+
{
|
|
174
|
+
name: 'an absolute tsx path is rejected',
|
|
175
|
+
expect: 'reject',
|
|
176
|
+
run: () => run(write('tsx', tsxPath)),
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: 'a snippet naming another package is rejected',
|
|
180
|
+
expect: 'reject',
|
|
181
|
+
run: () => run(write('pkg', noPackage)),
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: 'a snippet invoking another subcommand is rejected',
|
|
185
|
+
expect: 'reject',
|
|
186
|
+
run: () => run(write('sub', noSubcommand)),
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'the installer-shaped snippet passes',
|
|
190
|
+
expect: 'accept',
|
|
191
|
+
run: () => run(write('good', good)),
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
});
|
|
195
|
+
} finally {
|
|
196
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function _isCliEntry(): boolean {
|
|
201
|
+
if (process.argv[1] === undefined) return false;
|
|
202
|
+
if (import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) return true;
|
|
203
|
+
try {
|
|
204
|
+
return (
|
|
205
|
+
fs.realpathSync(fileURLToPath(import.meta.url)) ===
|
|
206
|
+
fs.realpathSync(path.resolve(process.argv[1]))
|
|
207
|
+
);
|
|
208
|
+
} catch {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (_isCliEntry() || process.argv[1] === _HERE) {
|
|
214
|
+
process.exit(main());
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export { DOC_REL, main };
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import { execFileSync } from 'node:child_process';
|
|
26
|
+
import { createHash } from 'node:crypto';
|
|
26
27
|
import * as fs from 'node:fs';
|
|
27
28
|
import * as path from 'node:path';
|
|
28
29
|
import { fileURLToPath } from 'node:url';
|
|
@@ -206,6 +207,220 @@ export function classifyPayload(files: readonly PackFile[]): string[] {
|
|
|
206
207
|
return out;
|
|
207
208
|
}
|
|
208
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Payload TYPE classification — what an entry IS, not where it sits.
|
|
212
|
+
*
|
|
213
|
+
* `CONTENT_CLASSES` above matches PATHS. That catches the shapes with a naming
|
|
214
|
+
* convention (a `.pem`, a `.test.js`, a `.vscode/` directory) and is blind to
|
|
215
|
+
* everything else: a compiled binary named `helper`, an archive named
|
|
216
|
+
* `data.md`, an extensionless script nobody looked at. Extension is the
|
|
217
|
+
* attacker's choice; the first bytes are not.
|
|
218
|
+
*
|
|
219
|
+
* Priority is archive > binary > dotfile > no-extension > text, so each entry
|
|
220
|
+
* lands in exactly one class and a count is a partition of the payload.
|
|
221
|
+
*/
|
|
222
|
+
export type PayloadType = 'text' | 'dotfile' | 'no-extension' | 'binary' | 'archive';
|
|
223
|
+
|
|
224
|
+
export const PAYLOAD_TYPES: readonly PayloadType[] = [
|
|
225
|
+
'archive',
|
|
226
|
+
'binary',
|
|
227
|
+
'dotfile',
|
|
228
|
+
'no-extension',
|
|
229
|
+
'text',
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
/** Leading magic bytes for the archive container formats worth naming. */
|
|
233
|
+
const ARCHIVE_MAGIC: ReadonlyArray<readonly number[]> = [
|
|
234
|
+
[0x50, 0x4b, 0x03, 0x04], // zip / jar / docx / xlsx
|
|
235
|
+
[0x1f, 0x8b], // gzip
|
|
236
|
+
[0x42, 0x5a, 0x68], // bzip2
|
|
237
|
+
[0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00], // xz
|
|
238
|
+
[0x04, 0x22, 0x4d, 0x18], // lz4
|
|
239
|
+
[0x28, 0xb5, 0x2f, 0xfd], // zstd
|
|
240
|
+
[0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c], // 7z
|
|
241
|
+
[0x52, 0x61, 0x72, 0x21], // rar
|
|
242
|
+
];
|
|
243
|
+
|
|
244
|
+
/** How many leading bytes are read to decide. */
|
|
245
|
+
export const MAGIC_BYTES_READ = 512;
|
|
246
|
+
|
|
247
|
+
function startsWith(buf: Uint8Array, sig: readonly number[]): boolean {
|
|
248
|
+
if (buf.length < sig.length) return false;
|
|
249
|
+
return sig.every((b, i) => buf[i] === b);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Classify one entry from its name and its first bytes.
|
|
254
|
+
*
|
|
255
|
+
* `head` is null when the file could not be read. That is NOT text: an entry
|
|
256
|
+
* the check could not open is an entry it did not classify, and the caller
|
|
257
|
+
* treats it as a failure rather than letting it fall through to the class that
|
|
258
|
+
* needs no exception.
|
|
259
|
+
*/
|
|
260
|
+
export function classifyEntry(entryPath: string, head: Uint8Array | null): PayloadType | 'unreadable' {
|
|
261
|
+
if (head === null) return 'unreadable';
|
|
262
|
+
if (ARCHIVE_MAGIC.some((sig) => startsWith(head, sig))) return 'archive';
|
|
263
|
+
if (head.length > 0) {
|
|
264
|
+
// A NUL byte is decisive. Short of that, a high proportion of C0
|
|
265
|
+
// control bytes outside tab/newline/CR is what separates a compiled
|
|
266
|
+
// object from prose that happens to contain an unusual character.
|
|
267
|
+
if (head.includes(0)) return 'binary';
|
|
268
|
+
let control = 0;
|
|
269
|
+
for (const b of head) {
|
|
270
|
+
if (b < 0x09 || (b > 0x0d && b < 0x20)) control += 1;
|
|
271
|
+
}
|
|
272
|
+
if (control / head.length > 0.1) return 'binary';
|
|
273
|
+
}
|
|
274
|
+
const base = entryPath.split('/').pop() ?? entryPath;
|
|
275
|
+
if (base.startsWith('.')) return 'dotfile';
|
|
276
|
+
if (!base.includes('.')) return 'no-extension';
|
|
277
|
+
return 'text';
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* An entry admitted into a class that would otherwise be empty.
|
|
282
|
+
*
|
|
283
|
+
* BOUND, not allow-listed, and the distinction is the whole point. A count
|
|
284
|
+
* ratchet ("8 extensionless entries are fine") is satisfied by ANY eight
|
|
285
|
+
* extensionless entries, so swapping one for something else passes silently —
|
|
286
|
+
* the same key-lookup weakness the Phase 5 pragma work removed one layer up.
|
|
287
|
+
* Here the binding is `sha256(path + "\n" + size)`: change the file and the
|
|
288
|
+
* exception stops applying, which re-fires the check on the entry that changed.
|
|
289
|
+
*
|
|
290
|
+
* NOT a `*_allowlist.json`. There is no file to grow, each entry states its own
|
|
291
|
+
* reason next to the class it excepts, and adding one is a reviewed code change
|
|
292
|
+
* in the gate — the same shape `CONTENT_CLASSES` already uses for its ratchets.
|
|
293
|
+
*
|
|
294
|
+
* Recompute a fingerprint with:
|
|
295
|
+
* ./scripts-run src/scripts/check_pack_size (the failure names path and size)
|
|
296
|
+
*/
|
|
297
|
+
export interface BoundPayloadException {
|
|
298
|
+
readonly fingerprint: string;
|
|
299
|
+
readonly path: string;
|
|
300
|
+
readonly size: number;
|
|
301
|
+
readonly why: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export function payloadFingerprint(entryPath: string, size: number): string {
|
|
305
|
+
return createHash('sha256').update(`${entryPath}\n${String(size)}`).digest('hex');
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Measured on the BUILT payload, 2026-09-07: 3041 entries, of which 3026 are
|
|
310
|
+
* text and these 15 are not. `archive` is empty and stays a hard zero.
|
|
311
|
+
*
|
|
312
|
+
* The roadmap step that added this expected `binary` to be zero too. It is not:
|
|
313
|
+
* three 69-byte PNG placeholders ship as media-adapter fixtures. Recorded as a
|
|
314
|
+
* correction rather than resolved by redefining the class — they are genuinely
|
|
315
|
+
* binary, they genuinely ship, and dropping them from the published surface is
|
|
316
|
+
* a consumer-visible change that belongs to whoever owns those adapters.
|
|
317
|
+
*/
|
|
318
|
+
const BOUND_PAYLOAD_EXCEPTIONS: readonly BoundPayloadException[] = [
|
|
319
|
+
{ fingerprint: '955b5da399e14fb39cfe1f3279044061043e64e2bd1576871514db927e56d701', path: 'src/scripts/media/lib/fixtures/flux/asset-0001.png', size: 69, why: 'media-adapter response fixture — a 69-byte placeholder PNG the flux adapter test decodes; binary by construction' },
|
|
320
|
+
{ fingerprint: 'c2dd9743367ece8ffe0deef5e798d39967c22245749fd7f798edd8aa78b70f59', path: 'src/scripts/media/lib/fixtures/gemini-image/asset-0001.png', size: 69, why: 'media-adapter response fixture — same class as the flux placeholder' },
|
|
321
|
+
{ fingerprint: 'cbac44d021a1dc41b938e798eb9be4147fc9d35194c348dfe9acaa0596bc83a5', path: 'src/scripts/media/lib/fixtures/ideogram/asset-0001.png', size: 69, why: 'media-adapter response fixture — same class as the flux placeholder' },
|
|
322
|
+
{ fingerprint: 'fdf6334f2342a48faaea708fd43853066f7057e528dfd1dd6fb5dcf8c0f67845', path: 'agents/templates/.ai-council.yml.example', size: 29872, why: 'shipped council config TEMPLATE — a dotfile because the file it is copied to is one' },
|
|
323
|
+
{ fingerprint: 'd36a53951c184db7481139235056e90b53a853714b3a68b31ba1349ecb95ac1d', path: 'agents/templates/.ai-video.xml.example', size: 9209, why: 'shipped video-provider config template — same reason as the council template' },
|
|
324
|
+
{ fingerprint: 'f83229412cf8cceaadd0cb1934140a0c7c8277df43edc590f370572f6df6da98', path: 'dist/agent-src/templates/agents/.gitattributes.fragment', size: 2140, why: 'gitattributes fragment the installer appends to a consumer repo' },
|
|
325
|
+
{ fingerprint: 'a4f51dba3a66c0f2c3548e77961271ed4d7b5ec8a6661ea359ff044758f0d921', path: 'src/templates/minimal/.agent-settings.yml', size: 1042, why: 'the minimal-install settings template; the dot is the consumer-side filename' },
|
|
326
|
+
{ fingerprint: 'a9cb828c7f3e6ac62d3c55c2fd215779307bf695a065498b1d1e1188210ebea8', path: 'LICENSE', size: 1064, why: 'the licence npm requires in the tarball; extensionless by convention' },
|
|
327
|
+
{ fingerprint: 'e89a3d025a838e295838db68d0d832c701eeca01bb7e6c3983d3a48950f80017', path: 'NOTICE', size: 472, why: 'attribution notice shipped with the licence; extensionless by convention' },
|
|
328
|
+
{ fingerprint: 'c9da3c6e2476a6d2b9610a1fbf638ba9bb78ddd76fc0f799631d601774c32cab', path: 'dist/agent-src/templates/hooks/pre-commit-frontmatter', size: 2537, why: 'git hook template — git requires a hook file to carry no extension' },
|
|
329
|
+
{ fingerprint: 'aeffa474df3f805de07cdc9c6960c4918aa8e51e317fa1c30906d2f0267b7a16', path: 'dist/agent-src/templates/hooks/pre-commit-roadmap-progress', size: 3988, why: 'git hook template — same reason' },
|
|
330
|
+
{ fingerprint: '914f9c34551c5f4c42a70cd8bb0cd7b73078b0c4e7815b551833a3c64c8476d3', path: 'src/scripts/agent-config', size: 2391, why: 'the CLI entry script; an executable entry point carries no extension by convention' },
|
|
331
|
+
{ fingerprint: '0bb1cdd48ac2e9b6a2a56cde25de9fc221d75d42683680284c43118cff796e92', path: 'src/scripts/hooks/shims/php', size: 4439, why: 'shim invoked as the command name `php`; an extension would break the lookup' },
|
|
332
|
+
{ fingerprint: 'b14bdd3cd589848ad8e6d7e5f4ee633dc9005a2a97abba327a9426ce556714da', path: 'src/scripts/install', size: 22049, why: 'the installer entry script; same reason as the CLI entry' },
|
|
333
|
+
{ fingerprint: '1fb564019de468368e34941dffd5eb8bc994364313e02f476ff354ac0da464d7', path: 'src/templates/minimal/overrides-gitkeep', size: 164, why: 'placeholder that becomes .gitkeep on install; extensionless on purpose' },
|
|
334
|
+
];
|
|
335
|
+
|
|
336
|
+
/** Read the first bytes of a payload entry from the tree it was packed from. */
|
|
337
|
+
function readHead(entryPath: string, root: string): Uint8Array | null {
|
|
338
|
+
try {
|
|
339
|
+
const fd = fs.openSync(path.join(root, entryPath), 'r');
|
|
340
|
+
try {
|
|
341
|
+
const buf = Buffer.alloc(MAGIC_BYTES_READ);
|
|
342
|
+
const read = fs.readSync(fd, buf, 0, MAGIC_BYTES_READ, 0);
|
|
343
|
+
return buf.subarray(0, read);
|
|
344
|
+
} finally {
|
|
345
|
+
fs.closeSync(fd);
|
|
346
|
+
}
|
|
347
|
+
} catch {
|
|
348
|
+
return null;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export interface TypeClassification {
|
|
353
|
+
readonly counts: Record<PayloadType | 'unreadable', number>;
|
|
354
|
+
/** Entries in a non-`text` class with no bound exception. */
|
|
355
|
+
readonly unbound: Array<{ path: string; size: number; type: PayloadType | 'unreadable'; fingerprint: string }>;
|
|
356
|
+
/** Bound exceptions matching no entry in this payload. */
|
|
357
|
+
readonly unusedExceptions: string[];
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Classify the whole payload by type and report what is not accounted for.
|
|
362
|
+
*
|
|
363
|
+
* Every entry outside `text` needs a bound exception. `archive` has none and is
|
|
364
|
+
* meant to stay that way; `binary` has three, named; the dotfile and
|
|
365
|
+
* extensionless entries are each bound to a path AND a size, so replacing one
|
|
366
|
+
* with different content re-fires the check on that entry rather than passing
|
|
367
|
+
* inside a count.
|
|
368
|
+
*/
|
|
369
|
+
export function classifyPayloadTypes(
|
|
370
|
+
files: readonly PackFile[],
|
|
371
|
+
root = REPO_ROOT,
|
|
372
|
+
head: (p: string) => Uint8Array | null = (p) => readHead(p, root),
|
|
373
|
+
): TypeClassification {
|
|
374
|
+
const counts: Record<PayloadType | 'unreadable', number> = {
|
|
375
|
+
archive: 0,
|
|
376
|
+
binary: 0,
|
|
377
|
+
dotfile: 0,
|
|
378
|
+
'no-extension': 0,
|
|
379
|
+
text: 0,
|
|
380
|
+
unreadable: 0,
|
|
381
|
+
};
|
|
382
|
+
const byFingerprint = new Map(BOUND_PAYLOAD_EXCEPTIONS.map((e) => [e.fingerprint, e]));
|
|
383
|
+
const used = new Set<string>();
|
|
384
|
+
const unbound: TypeClassification['unbound'] = [];
|
|
385
|
+
for (const f of files) {
|
|
386
|
+
const type = classifyEntry(f.path, head(f.path));
|
|
387
|
+
counts[type] += 1;
|
|
388
|
+
if (type === 'text') continue;
|
|
389
|
+
const fingerprint = payloadFingerprint(f.path, f.size);
|
|
390
|
+
if (byFingerprint.has(fingerprint)) {
|
|
391
|
+
used.add(fingerprint);
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
unbound.push({ path: f.path, size: f.size, type, fingerprint });
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
counts,
|
|
398
|
+
unbound,
|
|
399
|
+
unusedExceptions: BOUND_PAYLOAD_EXCEPTIONS.filter((e) => !used.has(e.fingerprint)).map((e) => e.path),
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** One line naming every type class and its count. */
|
|
404
|
+
export function payloadTypeLine(c: TypeClassification): string {
|
|
405
|
+
const parts = [...PAYLOAD_TYPES, 'unreadable' as const]
|
|
406
|
+
.filter((t) => t !== 'unreadable' || c.counts.unreadable > 0)
|
|
407
|
+
.map((t) => `${t} ${String(c.counts[t])}`);
|
|
408
|
+
return `${parts.join(' · ')} — ${String(c.unbound.length)} unaccounted`;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** Violations from the type classification, as human-readable lines. */
|
|
412
|
+
export function typeClassViolations(c: TypeClassification): string[] {
|
|
413
|
+
return c.unbound.map(
|
|
414
|
+
(u) =>
|
|
415
|
+
`payload type \`${u.type}\`: ${u.path} (${String(u.size)} bytes) is not accounted for. ` +
|
|
416
|
+
(u.type === 'archive' || u.type === 'binary'
|
|
417
|
+
? 'This class is meant to be empty. '
|
|
418
|
+
: 'Every dotfile and extensionless entry is carried by a path-and-size-bound exception. ') +
|
|
419
|
+
`If it belongs in the published surface, add a BoundPayloadException with ` +
|
|
420
|
+
`fingerprint sha256:${u.fingerprint} and a reason; otherwise exclude it from package.json files[].`,
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
|
|
209
424
|
/** Per-class counts, for the green-path report. */
|
|
210
425
|
export function payloadClassCounts(
|
|
211
426
|
files: readonly PackFile[],
|
|
@@ -377,8 +592,8 @@ function selfTest(): number {
|
|
|
377
592
|
Array.from({ length: n }, (_, i) => `dist/hooks/chunk-${String(i)}.js.map`);
|
|
378
593
|
return runSelfTest({
|
|
379
594
|
gate: 'check_pack_size',
|
|
380
|
-
minCases:
|
|
381
|
-
minRejectCases:
|
|
595
|
+
minCases: 14,
|
|
596
|
+
minRejectCases: 9,
|
|
382
597
|
cases: [
|
|
383
598
|
{
|
|
384
599
|
name: 'credential-shaped: a .pem in the payload is refused',
|
|
@@ -410,6 +625,95 @@ function selfTest(): number {
|
|
|
410
625
|
expect: 'accept',
|
|
411
626
|
run: () => (classifyPayload(builtPayload(...maps(120))).length > 0 ? 1 : 0),
|
|
412
627
|
},
|
|
628
|
+
{
|
|
629
|
+
// MAGIC BYTES, NOT THE EXTENSION. This is the whole reason the
|
|
630
|
+
// type pass exists beside the path pass above: an archive named
|
|
631
|
+
// `.md` is invisible to every path pattern in CONTENT_CLASSES.
|
|
632
|
+
name: 'type/archive: a zip planted under a .md name is classified archive, not text',
|
|
633
|
+
expect: 'reject',
|
|
634
|
+
run: () =>
|
|
635
|
+
typeClassViolations(
|
|
636
|
+
classifyPayloadTypes(packFiles('src/skills/x/SKILL.md'), REPO_ROOT, () =>
|
|
637
|
+
Uint8Array.from([0x50, 0x4b, 0x03, 0x04, 0x14, 0x00]),
|
|
638
|
+
),
|
|
639
|
+
).length > 0
|
|
640
|
+
? 1
|
|
641
|
+
: 0,
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
name: 'type/archive: the SAME path with ordinary text is classified text and passes',
|
|
645
|
+
expect: 'accept',
|
|
646
|
+
run: () =>
|
|
647
|
+
typeClassViolations(
|
|
648
|
+
classifyPayloadTypes(packFiles('src/skills/x/SKILL.md'), REPO_ROOT, () =>
|
|
649
|
+
new TextEncoder().encode('# An ordinary skill\n'),
|
|
650
|
+
),
|
|
651
|
+
).length > 0
|
|
652
|
+
? 1
|
|
653
|
+
: 0,
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
name: 'type/binary: a NUL-bearing entry is refused however it is named',
|
|
657
|
+
expect: 'reject',
|
|
658
|
+
run: () =>
|
|
659
|
+
typeClassViolations(
|
|
660
|
+
classifyPayloadTypes(packFiles('src/scripts/helper.ts'), REPO_ROOT, () =>
|
|
661
|
+
Uint8Array.from([0x7f, 0x45, 0x4c, 0x46, 0x02, 0x00, 0x00]),
|
|
662
|
+
),
|
|
663
|
+
).length > 0
|
|
664
|
+
? 1
|
|
665
|
+
: 0,
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
name: 'type/extensionless: an unbound extensionless entry is refused',
|
|
669
|
+
expect: 'reject',
|
|
670
|
+
run: () =>
|
|
671
|
+
typeClassViolations(
|
|
672
|
+
classifyPayloadTypes(packFiles('src/scripts/newtool'), REPO_ROOT, () =>
|
|
673
|
+
new TextEncoder().encode('#!/bin/sh\n'),
|
|
674
|
+
),
|
|
675
|
+
).length > 0
|
|
676
|
+
? 1
|
|
677
|
+
: 0,
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
// The property a COUNT ratchet cannot have. LICENSE is bound at
|
|
681
|
+
// its measured size; the same path at a different size is a
|
|
682
|
+
// different artifact and the exception stops applying.
|
|
683
|
+
name: 'type/binding: a bound entry whose SIZE changed is refused again',
|
|
684
|
+
expect: 'reject',
|
|
685
|
+
run: () =>
|
|
686
|
+
typeClassViolations(
|
|
687
|
+
classifyPayloadTypes([{ path: 'LICENSE', size: 999999 }], REPO_ROOT, () =>
|
|
688
|
+
new TextEncoder().encode('MIT\n'),
|
|
689
|
+
),
|
|
690
|
+
).length > 0
|
|
691
|
+
? 1
|
|
692
|
+
: 0,
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
name: 'type/binding: that same entry at its recorded size passes',
|
|
696
|
+
expect: 'accept',
|
|
697
|
+
run: () =>
|
|
698
|
+
typeClassViolations(
|
|
699
|
+
classifyPayloadTypes([{ path: 'LICENSE', size: 1064 }], REPO_ROOT, () =>
|
|
700
|
+
new TextEncoder().encode('MIT\n'),
|
|
701
|
+
),
|
|
702
|
+
).length > 0
|
|
703
|
+
? 1
|
|
704
|
+
: 0,
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
// An entry the check could not open is one it did not classify.
|
|
708
|
+
name: 'type/unreadable: an entry that cannot be read is refused, never assumed text',
|
|
709
|
+
expect: 'reject',
|
|
710
|
+
run: () =>
|
|
711
|
+
typeClassViolations(
|
|
712
|
+
classifyPayloadTypes(packFiles('src/scripts/gone.ts'), REPO_ROOT, () => null),
|
|
713
|
+
).length > 0
|
|
714
|
+
? 1
|
|
715
|
+
: 0,
|
|
716
|
+
},
|
|
413
717
|
{
|
|
414
718
|
name: 'a plain payload passes — the classes are not firing on everything',
|
|
415
719
|
expect: 'accept',
|
|
@@ -477,7 +781,12 @@ export function main(argv: readonly string[] = process.argv.slice(2)): number {
|
|
|
477
781
|
// still knows the population it was red over.
|
|
478
782
|
process.stdout.write(`scanned: ${String(pack.files.length)}\n`);
|
|
479
783
|
|
|
480
|
-
const
|
|
784
|
+
const types = classifyPayloadTypes(pack.files);
|
|
785
|
+
const errors = [
|
|
786
|
+
...evaluate(budget, pack),
|
|
787
|
+
...classifyPayload(pack.files),
|
|
788
|
+
...typeClassViolations(types),
|
|
789
|
+
];
|
|
481
790
|
const { perSkill, total } = skillBytes(pack.files);
|
|
482
791
|
if (argv.includes('--json')) {
|
|
483
792
|
process.stdout.write(
|
|
@@ -485,6 +794,15 @@ export function main(argv: readonly string[] = process.argv.slice(2)): number {
|
|
|
485
794
|
);
|
|
486
795
|
return errors.length > 0 ? 1 : 0;
|
|
487
796
|
}
|
|
797
|
+
// Printed BEFORE the verdict and on EVERY path, red included. The counts are
|
|
798
|
+
// what a reader needs to judge a violation: "one unaccounted binary" reads
|
|
799
|
+
// very differently against a payload of 3 binaries than against one of 0.
|
|
800
|
+
process.stdout.write(` payload types: ${payloadTypeLine(types)}\n`);
|
|
801
|
+
for (const unused of types.unusedExceptions) {
|
|
802
|
+
// Not an error: an unbuilt tree legitimately packs fewer files. Named
|
|
803
|
+
// so a stale exception is visible rather than accumulating unread.
|
|
804
|
+
process.stdout.write(` bound exception matched no entry: ${unused}\n`);
|
|
805
|
+
}
|
|
488
806
|
if (errors.length > 0) {
|
|
489
807
|
for (const e of errors) process.stderr.write(`❌ pack size: ${e}\n`);
|
|
490
808
|
return 1;
|