codebase-snapshot 0.12.14 → 0.13.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/CHANGELOG.md +950 -3
- package/README.md +15 -3
- package/SECURITY.md +2 -2
- package/dist/bin.js +9848 -5460
- package/dist/{chunk-UQHIG2KN.js → chunk-BOJYZQFB.js} +7651 -747
- package/dist/chunk-NESEHOPU.js +266 -0
- package/dist/cli.cjs +9954 -5619
- package/dist/cli.d.cts +120 -2
- package/dist/cli.d.ts +120 -2
- package/dist/cli.js +422 -8
- package/dist/{generate-worker-BK4uJx7Z.d.cts → generate-worker-B79yGkQO.d.cts} +16 -0
- package/dist/{generate-worker-BK4uJx7Z.d.ts → generate-worker-B79yGkQO.d.ts} +16 -0
- package/dist/index.cjs +7389 -680
- package/dist/index.d.cts +145 -6
- package/dist/index.d.ts +145 -6
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +3830 -1057
- package/dist/mcp.d.cts +86 -4
- package/dist/mcp.d.ts +86 -4
- package/dist/mcp.js +2 -2
- package/dist/{types-c0tLF2WC.d.cts → types-CbD8yQRZ.d.cts} +145 -1
- package/dist/{types-c0tLF2WC.d.ts → types-CbD8yQRZ.d.ts} +145 -1
- package/docs/agent.md +1 -1
- package/docs/benchmarks.md +80 -0
- package/docs/budget.md +59 -0
- package/docs/cli.md +56 -4
- package/docs/configuration.md +27 -0
- package/docs/delta.md +50 -0
- package/docs/deploy.md +75 -0
- package/docs/health.md +75 -0
- package/docs/mcp.md +112 -10
- package/docs/migration.md +68 -0
- package/docs/output.md +9 -3
- package/docs/remote.md +60 -0
- package/docs/security-review.md +117 -0
- package/docs/serve.md +66 -0
- package/docs/signing.md +61 -0
- package/docs/slice.md +57 -0
- package/docs/tools.md +161 -0
- package/docs/troubleshooting.md +63 -0
- package/docs/vs-repomix.md +1 -1
- package/docs/workspace.md +93 -0
- package/package.json +1 -1
- package/dist/chunk-6EGIFYWK.js +0 -3248
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { startHttpTransport } from './chunk-NESEHOPU.js';
|
|
2
|
+
import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, resolveConfig, validateSnapshot, auditSnapshot, describeManifestShapeProblem, explainPath, compareManifests, loadManifest, renderDiffText, generateSnapshot, signManifest, loadSigningKey, writeSignature, formatNumber, isDiscoveryMode, ARTIFACT_NAMES, COMMAND_OPTION_SCOPE, commandsForOption, getPreset, unknownPresetMessage, GENERATOR_NAME, runInit, installPreCommitHook, PromptCancelled, SKILL_NAME, renderSkill, findConfigFile, planFirstRun, isEffectivelyEmpty, isInteractive, defaultIO, hasPriorSnapshot, DEFAULT_ANSWERS, firstRunMessage, stripJsonComments, parseByteSize, gitignorePath, appendGitignoreEntries, escapeControls, runWithStdoutCapture, MIN_MAX_PART_TOKENS, MIN_MAX_PART_BYTES, renderContractText, renderExplainText } from './chunk-BOJYZQFB.js';
|
|
3
|
+
export { buildAgentContract } from './chunk-BOJYZQFB.js';
|
|
4
4
|
import { spawnSync } from 'child_process';
|
|
5
5
|
import * as fs2 from 'fs';
|
|
6
6
|
import * as path2 from 'path';
|
|
@@ -100,6 +100,7 @@ var COMMAND_ALIASES = /* @__PURE__ */ new Map([
|
|
|
100
100
|
["generate", "generate"],
|
|
101
101
|
["validate", "validate"],
|
|
102
102
|
["check", "validate"],
|
|
103
|
+
["health", "health"],
|
|
103
104
|
["report", "report"],
|
|
104
105
|
["init", "init"],
|
|
105
106
|
["setup", "setup"],
|
|
@@ -107,11 +108,13 @@ var COMMAND_ALIASES = /* @__PURE__ */ new Map([
|
|
|
107
108
|
["diff", "diff"],
|
|
108
109
|
["describe", "describe"],
|
|
109
110
|
["skill", "skill"],
|
|
110
|
-
["mcp", "mcp"]
|
|
111
|
+
["mcp", "mcp"],
|
|
112
|
+
["serve", "serve"]
|
|
111
113
|
]);
|
|
112
114
|
var COMMAND_ARITY = {
|
|
113
115
|
generate: 0,
|
|
114
116
|
validate: 0,
|
|
117
|
+
health: 0,
|
|
115
118
|
report: 0,
|
|
116
119
|
init: 0,
|
|
117
120
|
setup: 0,
|
|
@@ -119,7 +122,8 @@ var COMMAND_ARITY = {
|
|
|
119
122
|
diff: 2,
|
|
120
123
|
describe: 0,
|
|
121
124
|
skill: 0,
|
|
122
|
-
mcp: 0
|
|
125
|
+
mcp: 0,
|
|
126
|
+
serve: 0
|
|
123
127
|
};
|
|
124
128
|
var CLI_OPTIONS = {
|
|
125
129
|
cwd: { type: "string" },
|
|
@@ -158,6 +162,30 @@ var CLI_OPTIONS = {
|
|
|
158
162
|
staged: { type: "boolean" },
|
|
159
163
|
skeleton: { type: "boolean" },
|
|
160
164
|
sarif: { type: "boolean" },
|
|
165
|
+
strict: { type: "boolean" },
|
|
166
|
+
http: { type: "boolean" },
|
|
167
|
+
port: { type: "string" },
|
|
168
|
+
host: { type: "string" },
|
|
169
|
+
token: { type: "string" },
|
|
170
|
+
"no-auth": { type: "boolean" },
|
|
171
|
+
"allow-origin": { type: "string" },
|
|
172
|
+
remote: { type: "string" },
|
|
173
|
+
ref: { type: "string" },
|
|
174
|
+
"allow-private": { type: "boolean" },
|
|
175
|
+
"keep-clone": { type: "boolean" },
|
|
176
|
+
"include-diffs": { type: "boolean" },
|
|
177
|
+
"include-logs": { type: "string" },
|
|
178
|
+
"token-tree": { type: "boolean" },
|
|
179
|
+
delta: { type: "string" },
|
|
180
|
+
slice: { type: "string" },
|
|
181
|
+
"slice-tokens": { type: "string" },
|
|
182
|
+
pack: { type: "string" },
|
|
183
|
+
sign: { type: "boolean" },
|
|
184
|
+
"budget-tokens": { type: "string" },
|
|
185
|
+
workspace: { type: "string" },
|
|
186
|
+
"strip-comments": { type: "boolean" },
|
|
187
|
+
"remove-empty-lines": { type: "boolean" },
|
|
188
|
+
"all-members": { type: "boolean" },
|
|
161
189
|
help: { type: "boolean", short: "h" },
|
|
162
190
|
version: { type: "boolean", short: "v" }
|
|
163
191
|
};
|
|
@@ -182,13 +210,15 @@ Commands:
|
|
|
182
210
|
setup Everything at once: config, scripts, dependency, install, generate
|
|
183
211
|
generate (default) Generate a complete partitioned codebase snapshot
|
|
184
212
|
validate, check Validate snapshot integrity and check for drift
|
|
213
|
+
health Audit a snapshot for leaks, lies and wasted tokens (--strict, --format json)
|
|
185
214
|
init Generate a starter snapshot.config file
|
|
186
215
|
report Print codebase health, layer metrics, and secret audit
|
|
187
216
|
explain <path> Show how one path would be treated: layer, kind, part, skips
|
|
188
217
|
diff <a> <b> Compare two snapshots (directories or manifest.json files)
|
|
189
218
|
describe Print the machine-readable contract (--format json for agents)
|
|
190
219
|
skill Print the bundled agent skill; --install writes it into the repo
|
|
191
|
-
mcp Serve this repository to an MCP client
|
|
220
|
+
mcp Serve this repository to an MCP client (stdio, or --http for the web)
|
|
221
|
+
serve Open a browser UI: generate, preview, download a zip; MCP at /mcp
|
|
192
222
|
|
|
193
223
|
Options:
|
|
194
224
|
--cwd <path> Target repository directory (default: current directory)
|
|
@@ -209,6 +239,17 @@ Options:
|
|
|
209
239
|
0 = no limit); PROMPT.md plans the delivery to fit
|
|
210
240
|
--max-parts <n> Experimental: grow the part budget until the snapshot has at
|
|
211
241
|
most n parts, instead of adding parts as the code grows
|
|
242
|
+
--slice <question> Keep only what the planner picks for this question
|
|
243
|
+
--slice-tokens <n> Budget for --slice (default 30000)
|
|
244
|
+
--delta <path> Only what changed since this snapshot (plus its importers)
|
|
245
|
+
--sign Sign manifest.json (ed25519; SNAPSHOT_SIGNING_KEY or a fresh key)
|
|
246
|
+
--budget-tokens <n> Fit the snapshot into n tokens, highest value per token first
|
|
247
|
+
--workspace <a,b> One snapshot per member, plus WORKSPACE.json
|
|
248
|
+
--strip-comments Remove comment text from JS/TS bodies (line numbers preserved)
|
|
249
|
+
--pack <single|xml|json> Also write one full-repository file in that shape
|
|
250
|
+
--include-diffs Write reports/diff.md from the uncommitted diff
|
|
251
|
+
--include-logs <n> Write reports/log.md with the last n commits (1-500)
|
|
252
|
+
--token-tree Write reports/tokens.md with per-file token estimates
|
|
212
253
|
--brief <path> Owner-written half of PROMPT.md (stakes, system, history,
|
|
213
254
|
bar, calibration); merged at fixed slots
|
|
214
255
|
--prompt-task <task> audit | review | explain - which job the brief is for
|
|
@@ -224,6 +265,13 @@ Options:
|
|
|
224
265
|
auto: git when usable. git: require git. walk: read
|
|
225
266
|
.gitignore directly (escape hatch for a broken .git)
|
|
226
267
|
|
|
268
|
+
mcp --http:
|
|
269
|
+
--port <n> Port to bind (default 4789; 0 picks a free one)
|
|
270
|
+
--host <addr> Bind address (default 127.0.0.1). Non-loopback requires a token
|
|
271
|
+
--token <value> Bearer token clients must send (generated per run by default)
|
|
272
|
+
--no-auth Accept unauthenticated requests; refused on a non-loopback bind
|
|
273
|
+
--allow-origin <origins> Extra CORS origins, comma-separated (loopback always allowed)
|
|
274
|
+
|
|
227
275
|
generate only:
|
|
228
276
|
--autopilot Set the project up without asking, then generate: write the
|
|
229
277
|
config and .gitignore, add the npm scripts and devDependency,
|
|
@@ -567,7 +615,33 @@ function parseCliArgs(argv) {
|
|
|
567
615
|
staged: values.staged === true ? true : void 0,
|
|
568
616
|
withDependents: values["with-dependents"] === true ? true : void 0,
|
|
569
617
|
skeleton: values.skeleton === true ? true : void 0,
|
|
570
|
-
sarif: values.sarif === true ? true : void 0
|
|
618
|
+
sarif: values.sarif === true ? true : void 0,
|
|
619
|
+
strict: values.strict === true ? true : void 0,
|
|
620
|
+
http: values.http === true ? true : void 0,
|
|
621
|
+
port: parsePositiveInteger(values.port, "port", 1),
|
|
622
|
+
host: values.host === void 0 ? void 0 : String(values.host),
|
|
623
|
+
token: values.token === void 0 ? void 0 : String(values.token),
|
|
624
|
+
noAuth: values["no-auth"] === true ? true : void 0,
|
|
625
|
+
remote: values.remote === void 0 ? void 0 : String(values.remote),
|
|
626
|
+
ref: values.ref === void 0 ? void 0 : String(values.ref),
|
|
627
|
+
allowPrivate: values["allow-private"] === true ? true : void 0,
|
|
628
|
+
keepClone: values["keep-clone"] === true ? true : void 0,
|
|
629
|
+
includeDiffs: values["include-diffs"] === true ? true : void 0,
|
|
630
|
+
includeLogs: values["include-logs"] === void 0 ? void 0 : parsePositiveInteger(values["include-logs"], "include-logs", 1),
|
|
631
|
+
tokenTree: values["token-tree"] === true ? true : void 0,
|
|
632
|
+
sign: values.sign === true ? true : void 0,
|
|
633
|
+
workspace: values.workspace === void 0 ? void 0 : String(values.workspace),
|
|
634
|
+
stripComments: values["strip-comments"] === true ? true : void 0,
|
|
635
|
+
removeEmptyLines: values["remove-empty-lines"] === true ? true : void 0,
|
|
636
|
+
allMembers: values["all-members"] === true ? true : void 0,
|
|
637
|
+
budgetTokens: values["budget-tokens"] === void 0 ? void 0 : parsePositiveInteger(values["budget-tokens"], "budget-tokens", 500),
|
|
638
|
+
delta: values.delta === void 0 ? void 0 : String(values.delta),
|
|
639
|
+
slice: values.slice === void 0 ? void 0 : String(values.slice),
|
|
640
|
+
pack: values.pack === void 0 ? void 0 : values.pack === "single" || values.pack === "xml" || values.pack === "json" ? values.pack : (() => {
|
|
641
|
+
throw new UsageError("--pack must be one of: single, xml, json (received " + String(values.pack) + ").");
|
|
642
|
+
})(),
|
|
643
|
+
sliceTokens: values["slice-tokens"] === void 0 ? void 0 : parsePositiveInteger(values["slice-tokens"], "slice-tokens", 500),
|
|
644
|
+
allowOrigins: values["allow-origin"] === void 0 ? void 0 : String(values["allow-origin"]).split(",").map((origin) => origin.trim()).filter((origin) => origin.length > 0)
|
|
571
645
|
};
|
|
572
646
|
}
|
|
573
647
|
var HelpRequested = class extends Error {
|
|
@@ -686,6 +760,26 @@ async function runInitCommand(invocation) {
|
|
|
686
760
|
return fail(invocation.format, err.message);
|
|
687
761
|
}
|
|
688
762
|
}
|
|
763
|
+
function renderHealthText(report) {
|
|
764
|
+
const icon = (status) => status === "pass" ? "\u2705" : status === "warn" ? "\u26A0\uFE0F " : status === "fail" ? "\u274C" : "\u2022";
|
|
765
|
+
const order = { fail: 0, warn: 1, skip: 2, pass: 3 };
|
|
766
|
+
const sorted = [...report.checks].sort((a, b) => (order[a.status] ?? 9) - (order[b.status] ?? 9));
|
|
767
|
+
info(`\u{1FA7A} Snapshot health: ${report.score}/100`);
|
|
768
|
+
info(` ${report.counts.pass} passed, ${report.counts.warn} warning(s), ${report.counts.fail} failed, ${report.counts.skip} skipped`);
|
|
769
|
+
info("");
|
|
770
|
+
for (const item of sorted) {
|
|
771
|
+
info(` ${icon(item.status)} ${item.title}`);
|
|
772
|
+
info(` ${escapeControls(item.detail)}`);
|
|
773
|
+
}
|
|
774
|
+
info("");
|
|
775
|
+
if (report.counts.fail > 0) {
|
|
776
|
+
info(" A failed check means this snapshot is not safe to hand to a model as it stands.");
|
|
777
|
+
} else if (report.counts.warn > 0) {
|
|
778
|
+
info(" Warnings are judgement calls; read them before trusting the snapshot.");
|
|
779
|
+
} else {
|
|
780
|
+
info(" Nothing found: the snapshot matches its manifest and carries no unmasked secret.");
|
|
781
|
+
}
|
|
782
|
+
}
|
|
689
783
|
function generatorOrigin(cwd) {
|
|
690
784
|
try {
|
|
691
785
|
const pkg = JSON.parse(
|
|
@@ -1103,7 +1197,61 @@ ${USAGE}
|
|
|
1103
1197
|
if (invocation.command === "skill") {
|
|
1104
1198
|
return runSkillCommand(invocation);
|
|
1105
1199
|
}
|
|
1200
|
+
if (invocation.command === "serve") {
|
|
1201
|
+
const server = await startWebServer({
|
|
1202
|
+
cwd: path2.resolve(invocation.cwd),
|
|
1203
|
+
...invocation.host === void 0 ? {} : { host: invocation.host },
|
|
1204
|
+
...invocation.port === void 0 ? {} : { port: invocation.port },
|
|
1205
|
+
...invocation.noAuth === true ? { token: null } : {},
|
|
1206
|
+
...invocation.token === void 0 ? {} : { token: invocation.token },
|
|
1207
|
+
...invocation.allowPrivate === true ? { allowPrivate: true } : {},
|
|
1208
|
+
log: (line) => warn(line)
|
|
1209
|
+
});
|
|
1210
|
+
info("Serving " + server.url);
|
|
1211
|
+
info(" MCP endpoint: " + server.url + "mcp");
|
|
1212
|
+
if (server.token !== null) {
|
|
1213
|
+
info(" Token: " + server.token);
|
|
1214
|
+
info(" Open the page and paste the token once; it is kept in this browser only.");
|
|
1215
|
+
} else {
|
|
1216
|
+
warn(" WARNING: --no-auth is on. Any page on this machine can read the repository.");
|
|
1217
|
+
}
|
|
1218
|
+
await new Promise((resolve2) => {
|
|
1219
|
+
const stop = () => {
|
|
1220
|
+
void server.close().then(resolve2);
|
|
1221
|
+
};
|
|
1222
|
+
process.once("SIGINT", stop);
|
|
1223
|
+
process.once("SIGTERM", stop);
|
|
1224
|
+
});
|
|
1225
|
+
return 0;
|
|
1226
|
+
}
|
|
1106
1227
|
if (invocation.command === "mcp") {
|
|
1228
|
+
if (invocation.http === true) {
|
|
1229
|
+
const transport = await startHttpTransport({
|
|
1230
|
+
cwd: path2.resolve(invocation.cwd),
|
|
1231
|
+
...invocation.host === void 0 ? {} : { host: invocation.host },
|
|
1232
|
+
...invocation.port === void 0 ? {} : { port: invocation.port },
|
|
1233
|
+
...invocation.noAuth === true ? { token: null } : {},
|
|
1234
|
+
...invocation.token === void 0 ? {} : { token: invocation.token },
|
|
1235
|
+
...invocation.allowOrigins === void 0 ? {} : { allowedOrigins: invocation.allowOrigins },
|
|
1236
|
+
log: (line) => warn(line)
|
|
1237
|
+
});
|
|
1238
|
+
info("MCP over HTTP: " + transport.url);
|
|
1239
|
+
info(" tools: 12 (see describe --format json)");
|
|
1240
|
+
if (transport.token !== null) {
|
|
1241
|
+
info(" Authorization: Bearer " + transport.token);
|
|
1242
|
+
info(" (generated for this run; pass --token to choose one)");
|
|
1243
|
+
} else {
|
|
1244
|
+
warn(" WARNING: --no-auth is on. Any page on this machine can read the repository.");
|
|
1245
|
+
}
|
|
1246
|
+
await new Promise((resolve2) => {
|
|
1247
|
+
const stop = () => {
|
|
1248
|
+
void transport.close().then(resolve2);
|
|
1249
|
+
};
|
|
1250
|
+
process.once("SIGINT", stop);
|
|
1251
|
+
process.once("SIGTERM", stop);
|
|
1252
|
+
});
|
|
1253
|
+
return 0;
|
|
1254
|
+
}
|
|
1107
1255
|
return await runStdioServer({ cwd: path2.resolve(invocation.cwd) });
|
|
1108
1256
|
}
|
|
1109
1257
|
if (invocation.command === "setup") {
|
|
@@ -1113,6 +1261,45 @@ ${USAGE}
|
|
|
1113
1261
|
const decided = await firstRun(invocation);
|
|
1114
1262
|
if (decided !== null) return decided;
|
|
1115
1263
|
}
|
|
1264
|
+
let sourceProvenance;
|
|
1265
|
+
if (invocation.remote !== void 0) {
|
|
1266
|
+
if (invocation.command !== "generate") {
|
|
1267
|
+
return fail(invocation.format, "--remote is accepted by generate only.");
|
|
1268
|
+
}
|
|
1269
|
+
const parsed = parseRemoteSource(invocation.remote, { allowPrivate: invocation.allowPrivate === true });
|
|
1270
|
+
if (!parsed.ok) return fail(invocation.format, parsed.message);
|
|
1271
|
+
try {
|
|
1272
|
+
if (parsed.source.kind === "https") {
|
|
1273
|
+
await assertPublicHost(parsed.source.host, invocation.allowPrivate === true);
|
|
1274
|
+
}
|
|
1275
|
+
const clone = await cloneRepository(parsed.source, {
|
|
1276
|
+
dest: makeCloneDirectory(),
|
|
1277
|
+
token: process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN ?? null,
|
|
1278
|
+
ref: invocation.ref ?? null,
|
|
1279
|
+
allowPrivate: invocation.allowPrivate === true,
|
|
1280
|
+
log: (line) => info(" " + line)
|
|
1281
|
+
});
|
|
1282
|
+
sourceProvenance = clone.provenance;
|
|
1283
|
+
const outDir = path2.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
|
|
1284
|
+
invocation = { ...invocation, cwd: clone.directory, outDir, noConfig: true };
|
|
1285
|
+
info(
|
|
1286
|
+
" Source: " + parsed.source.owner + "/" + parsed.source.repo + "@" + clone.commit.slice(0, 12) + " (fetched " + clone.provenance.fetchedAt + ")"
|
|
1287
|
+
);
|
|
1288
|
+
if (invocation.keepClone === true) {
|
|
1289
|
+
info(" Clone kept at: " + clone.directory);
|
|
1290
|
+
} else {
|
|
1291
|
+
const directory = clone.directory;
|
|
1292
|
+
process.once("exit", () => {
|
|
1293
|
+
try {
|
|
1294
|
+
fs2.rmSync(directory, { recursive: true, force: true });
|
|
1295
|
+
} catch {
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
} catch (error) {
|
|
1300
|
+
return fail(invocation.format, "Remote fetch failed: " + error.message);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1116
1303
|
const skipConfig = invocation.noConfig || invocation.command === "diff";
|
|
1117
1304
|
const loaded = skipConfig ? { config: null, warnings: [], errors: [], file: null } : await loadConfigFileDetailed(invocation.cwd);
|
|
1118
1305
|
if (invocation.noConfig) info("\u2699 --no-config: using built-in defaults, config file ignored");
|
|
@@ -1142,6 +1329,12 @@ ${USAGE}
|
|
|
1142
1329
|
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
1143
1330
|
attachmentSlots: invocation.attachmentSlots,
|
|
1144
1331
|
maxParts: invocation.maxParts,
|
|
1332
|
+
...invocation.includeDiffs === true ? { includeDiffs: true } : {},
|
|
1333
|
+
...invocation.includeLogs === void 0 ? {} : { includeLogs: invocation.includeLogs },
|
|
1334
|
+
...invocation.tokenTree === true ? { tokenTree: true } : {},
|
|
1335
|
+
...invocation.stripComments === true ? { stripComments: true } : {},
|
|
1336
|
+
...invocation.removeEmptyLines === true ? { removeEmptyLines: true } : {},
|
|
1337
|
+
...invocation.pack === void 0 ? {} : { pack: invocation.pack },
|
|
1145
1338
|
brief: invocation.brief,
|
|
1146
1339
|
promptTask: invocation.promptTask,
|
|
1147
1340
|
skipArtifacts: invocation.skipArtifacts,
|
|
@@ -1166,6 +1359,66 @@ ${USAGE}
|
|
|
1166
1359
|
emit(invocation.format, result, () => renderValidateText(result));
|
|
1167
1360
|
return result.valid ? 0 : 1;
|
|
1168
1361
|
}
|
|
1362
|
+
if (invocation.command === "health") {
|
|
1363
|
+
if (invocation.allMembers === true) {
|
|
1364
|
+
const outRoot = path2.resolve(resolved.cwd, resolved.outDir);
|
|
1365
|
+
const indexPath = path2.join(outRoot, "WORKSPACE.json");
|
|
1366
|
+
if (!fs2.existsSync(indexPath)) {
|
|
1367
|
+
return fail(
|
|
1368
|
+
invocation.format,
|
|
1369
|
+
`No workspace index at ${indexPath}. Run generate --workspace <a,b> first, or drop --all-members.`
|
|
1370
|
+
);
|
|
1371
|
+
}
|
|
1372
|
+
let index;
|
|
1373
|
+
try {
|
|
1374
|
+
index = JSON.parse(fs2.readFileSync(indexPath, "utf8"));
|
|
1375
|
+
} catch (error) {
|
|
1376
|
+
return fail(invocation.format, `Could not read ${indexPath}: ${error.message}`);
|
|
1377
|
+
}
|
|
1378
|
+
const rows = [];
|
|
1379
|
+
for (const member of index.members ?? []) {
|
|
1380
|
+
const name = member.name ?? "?";
|
|
1381
|
+
const snapshotDir2 = path2.join(outRoot, name);
|
|
1382
|
+
const repoDir = path2.resolve(resolved.cwd, member.path ?? name);
|
|
1383
|
+
if (!fs2.existsSync(path2.join(snapshotDir2, "manifest.json"))) {
|
|
1384
|
+
rows.push({ name, score: 0, counts: { pass: 0, warn: 0, fail: 1 }, failed: [], error: "no snapshot at " + snapshotDir2 });
|
|
1385
|
+
continue;
|
|
1386
|
+
}
|
|
1387
|
+
const report2 = auditSnapshot({ snapshotDir: snapshotDir2, repoDir });
|
|
1388
|
+
rows.push({
|
|
1389
|
+
name,
|
|
1390
|
+
score: report2.score,
|
|
1391
|
+
counts: report2.counts,
|
|
1392
|
+
failed: report2.checks.filter((check) => check.status === "fail").map((check) => check.id)
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
const score = rows.length === 0 ? 100 : Math.min(...rows.map((row) => row.score));
|
|
1396
|
+
const totals = rows.reduce(
|
|
1397
|
+
(sum, row) => ({ pass: sum.pass + row.counts.pass, warn: sum.warn + row.counts.warn, fail: sum.fail + row.counts.fail }),
|
|
1398
|
+
{ pass: 0, warn: 0, fail: 0 }
|
|
1399
|
+
);
|
|
1400
|
+
emit(invocation.format, { outRoot, score, totals, members: rows }, () => {
|
|
1401
|
+
info(`
|
|
1402
|
+
\u{1F3E5} Workspace health (${outRoot})`);
|
|
1403
|
+
for (const row of rows) {
|
|
1404
|
+
info(
|
|
1405
|
+
" - " + row.name.padEnd(20) + (row.error !== void 0 ? "ERROR " + row.error : row.score + "/100 " + row.counts.pass + " passed, " + row.counts.warn + " warning(s), " + row.counts.fail + " failed")
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
info(`
|
|
1409
|
+
Combined score: ${score}/100 (the weakest member)`);
|
|
1410
|
+
});
|
|
1411
|
+
if (totals.fail > 0) return invocation.strict === true ? 2 : 1;
|
|
1412
|
+
if (invocation.strict === true && totals.warn > 0) return 1;
|
|
1413
|
+
return 0;
|
|
1414
|
+
}
|
|
1415
|
+
const snapshotDir = path2.resolve(resolved.cwd, resolved.outDir);
|
|
1416
|
+
const report = auditSnapshot({ snapshotDir, repoDir: resolved.cwd });
|
|
1417
|
+
emit(invocation.format, report, () => renderHealthText(report));
|
|
1418
|
+
if (report.counts.fail > 0) return invocation.strict === true ? 2 : 1;
|
|
1419
|
+
if (invocation.strict === true && report.counts.warn > 0) return 1;
|
|
1420
|
+
return 0;
|
|
1421
|
+
}
|
|
1169
1422
|
if (invocation.command === "report") {
|
|
1170
1423
|
const manifestPath = path2.resolve(resolved.cwd, resolved.outDir, "manifest.json");
|
|
1171
1424
|
if (!fs2.existsSync(manifestPath)) {
|
|
@@ -1202,6 +1455,30 @@ ${USAGE}
|
|
|
1202
1455
|
for (const [layer, count] of Object.entries(manifest.layers)) {
|
|
1203
1456
|
info(` - ${layer.padEnd(16)}: ${count} files`);
|
|
1204
1457
|
}
|
|
1458
|
+
if (manifest.slice !== void 0) {
|
|
1459
|
+
info("\n Selection (slice):");
|
|
1460
|
+
info(` - Question: ${manifest.slice.question}`);
|
|
1461
|
+
info(` - Used: ${formatNumber(manifest.slice.usedTokens)} of ${formatNumber(manifest.slice.budgetTokens)} tokens`);
|
|
1462
|
+
info(` - Not selected: ${manifest.slice.dropped} path(s)`);
|
|
1463
|
+
}
|
|
1464
|
+
if (manifest.budget !== void 0) {
|
|
1465
|
+
info("\n Selection (budget):");
|
|
1466
|
+
info(` - Used: ${formatNumber(manifest.budget.usedTokens)} of ${formatNumber(manifest.budget.maxTokens)} tokens`);
|
|
1467
|
+
info(` - Not selected: ${manifest.budget.dropped} path(s)`);
|
|
1468
|
+
if (manifest.budget.coverage !== void 0) {
|
|
1469
|
+
const coverage = manifest.budget.coverage;
|
|
1470
|
+
info(` - Entry points: ${coverage.entryPoints.kept} of ${coverage.entryPoints.total}`);
|
|
1471
|
+
info(` - Symbols: ${coverage.symbols.kept} of ${coverage.symbols.total}`);
|
|
1472
|
+
}
|
|
1473
|
+
}
|
|
1474
|
+
if (manifest.delta !== void 0) {
|
|
1475
|
+
const delta = manifest.delta;
|
|
1476
|
+
info("\n Selection (delta):");
|
|
1477
|
+
info(` - Against: ${path2.basename(delta.base.path)} (${delta.base.fingerprint.slice(0, 12)})`);
|
|
1478
|
+
info(
|
|
1479
|
+
` - Changed: ${delta.changed.length} changed, ${delta.added.length} added, ${delta.removed.length} removed, ${delta.unchanged.length} unchanged`
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1205
1482
|
});
|
|
1206
1483
|
return 0;
|
|
1207
1484
|
}
|
|
@@ -1224,17 +1501,154 @@ ${USAGE}
|
|
|
1224
1501
|
return fail(invocation.format, err.message);
|
|
1225
1502
|
}
|
|
1226
1503
|
}
|
|
1504
|
+
if (invocation.slice !== void 0 && invocation.delta !== void 0) {
|
|
1505
|
+
return fail(invocation.format, "--slice and --delta narrow in two different directions; pass one.");
|
|
1506
|
+
}
|
|
1507
|
+
if (invocation.slice !== void 0 && invocation.budgetTokens !== void 0) {
|
|
1508
|
+
return fail(
|
|
1509
|
+
invocation.format,
|
|
1510
|
+
"--slice and --budget-tokens both narrow the selection; pass one, or use --slice-tokens for the slice budget."
|
|
1511
|
+
);
|
|
1512
|
+
}
|
|
1227
1513
|
if (invocation.watch) {
|
|
1228
1514
|
const problem = watchSupportProblem();
|
|
1229
1515
|
if (problem !== null) return fail(invocation.format, problem);
|
|
1230
1516
|
}
|
|
1517
|
+
if (invocation.workspace !== void 0) {
|
|
1518
|
+
const members = invocation.workspace.split(",").map((member) => member.trim()).filter((member) => member.length > 0);
|
|
1519
|
+
if (members.length === 0) return fail(invocation.format, "--workspace needs at least one path.");
|
|
1520
|
+
if (invocation.remote !== void 0 || invocation.delta !== void 0 || invocation.slice !== void 0 || invocation.budgetTokens !== void 0 || invocation.sign === true) {
|
|
1521
|
+
return fail(
|
|
1522
|
+
invocation.format,
|
|
1523
|
+
"--workspace writes one snapshot per member; --remote, --delta, --slice, --budget-tokens and --sign do not combine with it."
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
const outRoot = path2.resolve(invocation.cwd, invocation.outDir ?? "snapshot");
|
|
1527
|
+
const records = [];
|
|
1528
|
+
let failed = 0;
|
|
1529
|
+
for (const member of members) {
|
|
1530
|
+
const directory = path2.resolve(invocation.cwd, member);
|
|
1531
|
+
const name = path2.basename(directory);
|
|
1532
|
+
let stat;
|
|
1533
|
+
try {
|
|
1534
|
+
stat = fs2.statSync(directory);
|
|
1535
|
+
} catch {
|
|
1536
|
+
warn("\u26A0 Workspace member missing: " + member);
|
|
1537
|
+
failed += 1;
|
|
1538
|
+
continue;
|
|
1539
|
+
}
|
|
1540
|
+
if (!stat.isDirectory()) {
|
|
1541
|
+
warn("\u26A0 Workspace member is not a directory: " + member);
|
|
1542
|
+
failed += 1;
|
|
1543
|
+
continue;
|
|
1544
|
+
}
|
|
1545
|
+
try {
|
|
1546
|
+
const manifest = generateSnapshot({ cwd: directory, outDir: path2.join(outRoot, name) });
|
|
1547
|
+
records.push({
|
|
1548
|
+
name,
|
|
1549
|
+
path: directory,
|
|
1550
|
+
fingerprint: manifest.fingerprint,
|
|
1551
|
+
files: manifest.counts.totalFiles,
|
|
1552
|
+
parts: manifest.counts.partsCount,
|
|
1553
|
+
tokens: manifest.totals.estimatedTokens ?? 0,
|
|
1554
|
+
imports: manifest.indexes.imports.byFile.map((entry) => ({ path: entry.path, imports: entry.imports }))
|
|
1555
|
+
});
|
|
1556
|
+
info(" " + name + ": " + manifest.counts.totalFiles + " files, " + manifest.counts.partsCount + " part(s)");
|
|
1557
|
+
} catch (error) {
|
|
1558
|
+
warn("\u26A0 " + name + ": " + error.message);
|
|
1559
|
+
failed += 1;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
fs2.mkdirSync(outRoot, { recursive: true });
|
|
1563
|
+
const links = [];
|
|
1564
|
+
for (const record of records) {
|
|
1565
|
+
const counts = /* @__PURE__ */ new Map();
|
|
1566
|
+
for (const entry of record.imports) {
|
|
1567
|
+
for (const specifier of entry.imports) {
|
|
1568
|
+
if (!specifier.startsWith(".")) continue;
|
|
1569
|
+
const resolved2 = path2.resolve(record.path, path2.dirname(entry.path), specifier);
|
|
1570
|
+
for (const other of records) {
|
|
1571
|
+
if (other === record) continue;
|
|
1572
|
+
const prefix = other.path + path2.sep;
|
|
1573
|
+
if (!resolved2.startsWith(prefix) && resolved2 !== other.path) continue;
|
|
1574
|
+
const bucket = counts.get(other.name) ?? { count: 0, examples: [] };
|
|
1575
|
+
bucket.count += 1;
|
|
1576
|
+
if (bucket.examples.length < 5) bucket.examples.push(entry.path);
|
|
1577
|
+
counts.set(other.name, bucket);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
for (const [to, bucket] of counts) {
|
|
1582
|
+
links.push({ from: record.name, to, specifiers: bucket.count, examples: bucket.examples });
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
links.sort((left, right) => (left.from + ">" + left.to).localeCompare(right.from + ">" + right.to));
|
|
1586
|
+
const document = {
|
|
1587
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1588
|
+
generator: GENERATOR_VERSION,
|
|
1589
|
+
members: records.map(({ imports: _imports, ...rest }) => rest),
|
|
1590
|
+
links
|
|
1591
|
+
};
|
|
1592
|
+
fs2.writeFileSync(path2.join(outRoot, "WORKSPACE.json"), JSON.stringify(document, null, 2) + "\n", "utf8");
|
|
1593
|
+
emit(invocation.format, document, () => {
|
|
1594
|
+
info("\n\u{1F5C2} Workspace: " + records.length + " of " + members.length + " member(s) written under " + outRoot);
|
|
1595
|
+
for (const record of records) {
|
|
1596
|
+
info(" - " + record.name + " (" + record.fingerprint.slice(0, 12) + ")");
|
|
1597
|
+
}
|
|
1598
|
+
for (const link of links) {
|
|
1599
|
+
info(" \u2192 " + link.from + " imports " + link.to + " (" + link.specifiers + " specifier(s))");
|
|
1600
|
+
}
|
|
1601
|
+
});
|
|
1602
|
+
return failed === 0 ? 0 : 1;
|
|
1603
|
+
}
|
|
1231
1604
|
const started = performance.now();
|
|
1232
1605
|
info(`\u{1F4F8} ${invocation.dryRun ? "Planning snapshot (dry run)" : "Generating snapshot"} for: ${resolved.cwd}`);
|
|
1233
1606
|
info(
|
|
1234
1607
|
` Branch: ${resolved.branch} | Part budget: ${(resolved.maxPartBytes / 1024).toFixed(0)} KB | Generator: ${GENERATOR_VERSION} (${generatorOrigin(resolved.cwd)})`
|
|
1235
1608
|
);
|
|
1236
1609
|
try {
|
|
1237
|
-
|
|
1610
|
+
let deltaBase;
|
|
1611
|
+
if (invocation.delta !== void 0) {
|
|
1612
|
+
const basePath = path2.resolve(invocation.cwd, invocation.delta);
|
|
1613
|
+
const manifestPath = fs2.existsSync(basePath) && fs2.statSync(basePath).isDirectory() ? path2.join(basePath, "manifest.json") : basePath;
|
|
1614
|
+
if (!fs2.existsSync(manifestPath)) {
|
|
1615
|
+
return fail(invocation.format, "No manifest at " + manifestPath + ". Point --delta at a snapshot directory or its manifest.json.");
|
|
1616
|
+
}
|
|
1617
|
+
let base;
|
|
1618
|
+
try {
|
|
1619
|
+
base = JSON.parse(fs2.readFileSync(manifestPath, "utf8"));
|
|
1620
|
+
} catch (error) {
|
|
1621
|
+
return fail(invocation.format, "Could not read " + manifestPath + ": " + error.message);
|
|
1622
|
+
}
|
|
1623
|
+
const shape = describeManifestShapeProblem(base);
|
|
1624
|
+
if (shape !== null) {
|
|
1625
|
+
return fail(invocation.format, manifestPath + " is not a snapshot manifest: " + shape);
|
|
1626
|
+
}
|
|
1627
|
+
deltaBase = { manifest: base, path: manifestPath };
|
|
1628
|
+
info(" Delta base: " + manifestPath + " (" + base.files.length + " files, fingerprint " + base.fingerprint.slice(0, 12) + ")");
|
|
1629
|
+
}
|
|
1630
|
+
const manifest = generateSnapshot(resolved, {
|
|
1631
|
+
dryRun: invocation.dryRun,
|
|
1632
|
+
...sourceProvenance === void 0 ? {} : { source: sourceProvenance },
|
|
1633
|
+
...deltaBase === void 0 ? {} : { deltaBase },
|
|
1634
|
+
...invocation.budgetTokens === void 0 ? {} : { budgetTokens: invocation.budgetTokens },
|
|
1635
|
+
...invocation.slice === void 0 ? {} : {
|
|
1636
|
+
slice: {
|
|
1637
|
+
question: invocation.slice,
|
|
1638
|
+
...invocation.sliceTokens === void 0 ? {} : { maxTokens: invocation.sliceTokens }
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
});
|
|
1642
|
+
if (invocation.sign === true && !invocation.dryRun) {
|
|
1643
|
+
const manifestPath = path2.resolve(resolved.cwd, resolved.outDir, "manifest.json");
|
|
1644
|
+
try {
|
|
1645
|
+
const record = signManifest(manifestPath, { key: loadSigningKey() });
|
|
1646
|
+
writeSignature(path2.dirname(manifestPath), record);
|
|
1647
|
+
info(" Signature: ed25519, " + record.keyOrigin + " key, " + record.fingerprint.slice(0, 12));
|
|
1648
|
+
} catch (error) {
|
|
1649
|
+
return fail(invocation.format, "Signing failed: " + error.message);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1238
1652
|
const elapsed = ((performance.now() - started) / 1e3).toFixed(2);
|
|
1239
1653
|
if (invocation.dryRun) {
|
|
1240
1654
|
info("\n\u{1F9EA} Dry run \u2014 nothing was written:");
|
|
@@ -16,6 +16,13 @@ interface WorkspaceCliOptions {
|
|
|
16
16
|
staged?: true;
|
|
17
17
|
withDependents?: true;
|
|
18
18
|
changedSince?: string;
|
|
19
|
+
/** Opt-in reports a client can ask for by name; absent means "whatever the configuration says". */
|
|
20
|
+
includeDiffs?: true;
|
|
21
|
+
includeLogs?: number;
|
|
22
|
+
tokenTree?: true;
|
|
23
|
+
stripComments?: true;
|
|
24
|
+
removeEmptyLines?: true;
|
|
25
|
+
pack?: "single" | "xml" | "json";
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
/** What the caller needs from a finished run; the whole manifest can be megabytes. */
|
|
@@ -77,6 +84,15 @@ declare function workerEntry(directory: string, isCjs: boolean): {
|
|
|
77
84
|
*/
|
|
78
85
|
declare function generateInWorker(cwd: string, cliOptions: WorkspaceCliOptions, options?: {
|
|
79
86
|
dryRun?: boolean;
|
|
87
|
+
signal?: AbortSignal;
|
|
88
|
+
/** `--slice` / `--budget-tokens`: narrowing is a generate option, not a config setting. */
|
|
89
|
+
narrow?: {
|
|
90
|
+
slice?: {
|
|
91
|
+
question: string;
|
|
92
|
+
maxTokens?: number;
|
|
93
|
+
};
|
|
94
|
+
budgetTokens?: number;
|
|
95
|
+
};
|
|
80
96
|
}): Promise<WorkerResults>;
|
|
81
97
|
|
|
82
98
|
export { type GenerateSummary as G, type WorkerResults as W, generateInWorker as g, workerEntry as w };
|
|
@@ -16,6 +16,13 @@ interface WorkspaceCliOptions {
|
|
|
16
16
|
staged?: true;
|
|
17
17
|
withDependents?: true;
|
|
18
18
|
changedSince?: string;
|
|
19
|
+
/** Opt-in reports a client can ask for by name; absent means "whatever the configuration says". */
|
|
20
|
+
includeDiffs?: true;
|
|
21
|
+
includeLogs?: number;
|
|
22
|
+
tokenTree?: true;
|
|
23
|
+
stripComments?: true;
|
|
24
|
+
removeEmptyLines?: true;
|
|
25
|
+
pack?: "single" | "xml" | "json";
|
|
19
26
|
}
|
|
20
27
|
|
|
21
28
|
/** What the caller needs from a finished run; the whole manifest can be megabytes. */
|
|
@@ -77,6 +84,15 @@ declare function workerEntry(directory: string, isCjs: boolean): {
|
|
|
77
84
|
*/
|
|
78
85
|
declare function generateInWorker(cwd: string, cliOptions: WorkspaceCliOptions, options?: {
|
|
79
86
|
dryRun?: boolean;
|
|
87
|
+
signal?: AbortSignal;
|
|
88
|
+
/** `--slice` / `--budget-tokens`: narrowing is a generate option, not a config setting. */
|
|
89
|
+
narrow?: {
|
|
90
|
+
slice?: {
|
|
91
|
+
question: string;
|
|
92
|
+
maxTokens?: number;
|
|
93
|
+
};
|
|
94
|
+
budgetTokens?: number;
|
|
95
|
+
};
|
|
80
96
|
}): Promise<WorkerResults>;
|
|
81
97
|
|
|
82
98
|
export { type GenerateSummary as G, type WorkerResults as W, generateInWorker as g, workerEntry as w };
|