codebase-snapshot 0.10.2 → 0.12.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 +102 -0
- package/README.md +10 -1
- package/SECURITY.md +2 -2
- package/dist/bin.js +1282 -296
- package/dist/{chunk-5EYBTBFY.js → chunk-5FPYVWP3.js} +50 -3
- package/dist/{chunk-5AV7OR3J.js → chunk-6HXDYIJS.js} +1204 -338
- package/dist/cli.cjs +1423 -443
- package/dist/cli.d.cts +36 -3
- package/dist/cli.d.ts +36 -3
- package/dist/cli.js +71 -5
- package/dist/index.cjs +1199 -333
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +206 -4
- package/dist/mcp.js +2 -2
- package/dist/{types-BoWneA7n.d.cts → types-c0tLF2WC.d.cts} +91 -1
- package/dist/{types-BoWneA7n.d.ts → types-c0tLF2WC.d.ts} +91 -1
- package/docs/cli.md +8 -3
- package/docs/configuration.md +108 -0
- package/docs/how-to-feed-a-repo-to-claude.md +40 -9
- package/docs/mcp.md +3 -3
- package/docs/output.md +58 -2
- package/package.json +1 -1
package/dist/bin.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
4
|
import { spawnSync } from "child_process";
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
5
|
+
import * as fs21 from "fs";
|
|
6
|
+
import * as path22 from "path";
|
|
7
7
|
import { parseArgs } from "util";
|
|
8
8
|
|
|
9
9
|
// src/diff.ts
|
|
@@ -2191,7 +2191,7 @@ function applySpansKeepingQuotes(line, spans) {
|
|
|
2191
2191
|
|
|
2192
2192
|
// src/version.ts
|
|
2193
2193
|
var GENERATOR_NAME = "codebase-snapshot";
|
|
2194
|
-
var GENERATOR_VERSION = "0.
|
|
2194
|
+
var GENERATOR_VERSION = "0.12.0";
|
|
2195
2195
|
var SCHEMA_VERSION = "3.0.0";
|
|
2196
2196
|
var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
|
|
2197
2197
|
function isOurGeneratorName(name) {
|
|
@@ -2639,6 +2639,35 @@ function defaultIgnoreReason(relativePath, toolDirNames = DEFAULT_TOOL_DIR_NAMES
|
|
|
2639
2639
|
}
|
|
2640
2640
|
return null;
|
|
2641
2641
|
}
|
|
2642
|
+
var COMMIT_BODY_LIMIT = 400;
|
|
2643
|
+
function recentCommits(cwd, limit = 10) {
|
|
2644
|
+
try {
|
|
2645
|
+
const stdout = childProcess.execFileSync(
|
|
2646
|
+
"git",
|
|
2647
|
+
// \x1f between fields and \x1e between records: neither can appear in a commit message, so
|
|
2648
|
+
// the parse cannot be confused by a message that contains a newline or a dash.
|
|
2649
|
+
["log", "-n", String(limit), "--pretty=format:%s%x1f%b%x1e", "--no-color"],
|
|
2650
|
+
{
|
|
2651
|
+
cwd,
|
|
2652
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
2653
|
+
encoding: "utf8",
|
|
2654
|
+
maxBuffer: GIT_OUTPUT_LIMIT
|
|
2655
|
+
}
|
|
2656
|
+
);
|
|
2657
|
+
return stdout.split("").map((record) => record.replace(/^\n+/, "")).filter((record) => record.length > 0).map((record) => {
|
|
2658
|
+
const separator = record.indexOf("");
|
|
2659
|
+
const subject = separator === -1 ? record : record.slice(0, separator);
|
|
2660
|
+
const rawBody = separator === -1 ? "" : record.slice(separator + 1);
|
|
2661
|
+
const body = rawBody.split("\n").map((line) => line.trim()).filter((line) => line.length > 0).join(" ");
|
|
2662
|
+
return {
|
|
2663
|
+
subject: subject.trim(),
|
|
2664
|
+
body: body.length > COMMIT_BODY_LIMIT ? body.slice(0, COMMIT_BODY_LIMIT - 1) + "\u2026" : body
|
|
2665
|
+
};
|
|
2666
|
+
}).filter((commit) => commit.subject.length > 0);
|
|
2667
|
+
} catch {
|
|
2668
|
+
return [];
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2642
2671
|
function listIgnoredPaths(cwd) {
|
|
2643
2672
|
try {
|
|
2644
2673
|
const stdout = childProcess.execFileSync(
|
|
@@ -3082,7 +3111,7 @@ import * as path6 from "path";
|
|
|
3082
3111
|
|
|
3083
3112
|
// src/config.ts
|
|
3084
3113
|
import * as fs3 from "fs";
|
|
3085
|
-
import { createHash } from "crypto";
|
|
3114
|
+
import { createHash as createHash2 } from "crypto";
|
|
3086
3115
|
import { createRequire } from "module";
|
|
3087
3116
|
import * as path3 from "path";
|
|
3088
3117
|
import { pathToFileURL } from "url";
|
|
@@ -3259,6 +3288,80 @@ function summarizeMarkdown(content) {
|
|
|
3259
3288
|
};
|
|
3260
3289
|
}
|
|
3261
3290
|
|
|
3291
|
+
// src/generator/brief.ts
|
|
3292
|
+
import { createHash } from "crypto";
|
|
3293
|
+
var OWNER_SECTIONS = ["Stakes", "The system", "What came before", "The bar", "Calibration"];
|
|
3294
|
+
var RESERVED_SECTIONS = [
|
|
3295
|
+
"The job",
|
|
3296
|
+
"What you have",
|
|
3297
|
+
"Coverage",
|
|
3298
|
+
"What a useful answer contains",
|
|
3299
|
+
"This snapshot",
|
|
3300
|
+
"Attaching this",
|
|
3301
|
+
"Your task"
|
|
3302
|
+
];
|
|
3303
|
+
function parseOwnerBrief(filePath, text2) {
|
|
3304
|
+
const problems = [];
|
|
3305
|
+
const source = text2.replace(/^\uFEFF/, "");
|
|
3306
|
+
const preamble = [];
|
|
3307
|
+
const sections = [];
|
|
3308
|
+
let current = null;
|
|
3309
|
+
for (const line of source.split(/\r?\n/)) {
|
|
3310
|
+
const heading = /^##\s+(.+?)\s*$/.exec(line);
|
|
3311
|
+
if (heading) {
|
|
3312
|
+
current = { heading: heading[1], body: [] };
|
|
3313
|
+
sections.push(current);
|
|
3314
|
+
continue;
|
|
3315
|
+
}
|
|
3316
|
+
if (current) current.body.push(line);
|
|
3317
|
+
else preamble.push(line);
|
|
3318
|
+
}
|
|
3319
|
+
const recognised = {};
|
|
3320
|
+
const notes = [];
|
|
3321
|
+
const canonical = (heading) => heading.trim().toLowerCase().replace(/\s+/g, " ");
|
|
3322
|
+
const canonicalOwner = new Map(OWNER_SECTIONS.map((name) => [canonical(name), name]));
|
|
3323
|
+
const canonicalReserved = new Set(RESERVED_SECTIONS.map(canonical));
|
|
3324
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3325
|
+
for (const section of sections) {
|
|
3326
|
+
const body = section.body.join("\n").trim();
|
|
3327
|
+
const key = canonical(section.heading);
|
|
3328
|
+
if (seen.has(key)) {
|
|
3329
|
+
problems.push(
|
|
3330
|
+
`the brief defines "${section.heading}" twice; a section cannot say two things.`
|
|
3331
|
+
);
|
|
3332
|
+
continue;
|
|
3333
|
+
}
|
|
3334
|
+
seen.add(key);
|
|
3335
|
+
if (canonicalReserved.has(key)) {
|
|
3336
|
+
problems.push(
|
|
3337
|
+
`the brief may not define "${section.heading}": that section is rendered from the manifest, and letting prose overwrite a measured section would make the document lie.`
|
|
3338
|
+
);
|
|
3339
|
+
continue;
|
|
3340
|
+
}
|
|
3341
|
+
const ownerName = canonicalOwner.get(key);
|
|
3342
|
+
if (ownerName !== void 0) {
|
|
3343
|
+
recognised[ownerName] = body;
|
|
3344
|
+
continue;
|
|
3345
|
+
}
|
|
3346
|
+
notes.push({ heading: section.heading, body });
|
|
3347
|
+
}
|
|
3348
|
+
const preambleText = preamble.join("\n").trim();
|
|
3349
|
+
return {
|
|
3350
|
+
brief: {
|
|
3351
|
+
path: filePath,
|
|
3352
|
+
digest: createHash("sha256").update(text2, "utf8").digest("hex"),
|
|
3353
|
+
...recognised["Stakes"] ? { stakes: recognised["Stakes"] } : {},
|
|
3354
|
+
...recognised["The system"] ? { system: recognised["The system"] } : {},
|
|
3355
|
+
...recognised["What came before"] ? { history: recognised["What came before"] } : {},
|
|
3356
|
+
...recognised["The bar"] ? { bar: recognised["The bar"] } : {},
|
|
3357
|
+
...recognised["Calibration"] ? { calibration: recognised["Calibration"] } : {},
|
|
3358
|
+
notes,
|
|
3359
|
+
...preambleText.length > 0 ? { preamble: preambleText } : {}
|
|
3360
|
+
},
|
|
3361
|
+
problems
|
|
3362
|
+
};
|
|
3363
|
+
}
|
|
3364
|
+
|
|
3262
3365
|
// src/tokenize.ts
|
|
3263
3366
|
var WORD_RUN = /[A-Za-z0-9_]+/g;
|
|
3264
3367
|
var SINGLE_TOKEN = /[^\sA-Za-z0-9_]/g;
|
|
@@ -3369,6 +3472,12 @@ function normalizeResolvedConfig(config) {
|
|
|
3369
3472
|
return markResolvedConfig({
|
|
3370
3473
|
...config,
|
|
3371
3474
|
discovery,
|
|
3475
|
+
// A spread copy built before the field existed carries no value; the default applies, and it
|
|
3476
|
+
// is re-validated because the number reaches a rendered artifact.
|
|
3477
|
+
attachmentSlots: resolveAttachmentSlots(config.attachmentSlots),
|
|
3478
|
+
maxParts: resolveMaxParts(config.maxParts),
|
|
3479
|
+
promptTask: resolvePromptTask(config.promptTask),
|
|
3480
|
+
...config.brief === void 0 ? {} : { brief: config.brief },
|
|
3372
3481
|
includeMonolith: artifacts.monolith,
|
|
3373
3482
|
secretRules: compileSecretRules(config.secretRules),
|
|
3374
3483
|
artifacts,
|
|
@@ -3437,7 +3546,9 @@ function describeValue2(value) {
|
|
|
3437
3546
|
var isThenable = (value) => typeof value.then === "function";
|
|
3438
3547
|
var CONFIG_KEY_NAMES = [
|
|
3439
3548
|
"artifacts",
|
|
3549
|
+
"attachmentSlots",
|
|
3440
3550
|
"branch",
|
|
3551
|
+
"brief",
|
|
3441
3552
|
"budgets",
|
|
3442
3553
|
"changedSince",
|
|
3443
3554
|
"cwd",
|
|
@@ -3454,10 +3565,12 @@ var CONFIG_KEY_NAMES = [
|
|
|
3454
3565
|
"layersMode",
|
|
3455
3566
|
"maxMonolithBytes",
|
|
3456
3567
|
"maxPartBytes",
|
|
3568
|
+
"maxParts",
|
|
3457
3569
|
"maxPartTokens",
|
|
3458
3570
|
"outDir",
|
|
3459
3571
|
"preset",
|
|
3460
3572
|
"previewHeadLines",
|
|
3573
|
+
"promptTask",
|
|
3461
3574
|
"staged",
|
|
3462
3575
|
"previewTailLines",
|
|
3463
3576
|
"secretRules",
|
|
@@ -3508,7 +3621,7 @@ function readConfigExport(exported, file) {
|
|
|
3508
3621
|
var lastModuleConfig = null;
|
|
3509
3622
|
function moduleConfigKey(fullPath) {
|
|
3510
3623
|
try {
|
|
3511
|
-
return
|
|
3624
|
+
return createHash2("sha256").update(fs3.readFileSync(fullPath)).digest("hex").slice(0, 24);
|
|
3512
3625
|
} catch {
|
|
3513
3626
|
try {
|
|
3514
3627
|
const stats = fs3.statSync(fullPath);
|
|
@@ -3652,6 +3765,7 @@ var MIN_MAX_PART_BYTES = 4096;
|
|
|
3652
3765
|
var MIN_MAX_PART_TOKENS = MIN_MAX_PART_BYTES / 4;
|
|
3653
3766
|
var ARTIFACT_NAMES = [
|
|
3654
3767
|
"readme",
|
|
3768
|
+
"prompt",
|
|
3655
3769
|
"manifest",
|
|
3656
3770
|
"parts",
|
|
3657
3771
|
"navigation",
|
|
@@ -3661,6 +3775,7 @@ var ARTIFACT_NAMES = [
|
|
|
3661
3775
|
];
|
|
3662
3776
|
var DEFAULT_ARTIFACTS = {
|
|
3663
3777
|
readme: true,
|
|
3778
|
+
prompt: true,
|
|
3664
3779
|
manifest: true,
|
|
3665
3780
|
parts: true,
|
|
3666
3781
|
navigation: true,
|
|
@@ -3721,6 +3836,57 @@ function resolveArtifacts(requested, skipped, includeMonolith, monolithOverride,
|
|
|
3721
3836
|
}
|
|
3722
3837
|
return artifacts;
|
|
3723
3838
|
}
|
|
3839
|
+
var DEFAULT_ATTACHMENT_SLOTS = 10;
|
|
3840
|
+
function resolveAttachmentSlots(value) {
|
|
3841
|
+
if (value === void 0 || value === null) return DEFAULT_ATTACHMENT_SLOTS;
|
|
3842
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
3843
|
+
throw new Error(
|
|
3844
|
+
"attachmentSlots must be a whole number, with 0 meaning no limit (received " + describeValue2(value) + ")."
|
|
3845
|
+
);
|
|
3846
|
+
}
|
|
3847
|
+
return value;
|
|
3848
|
+
}
|
|
3849
|
+
function resolveMaxParts(value) {
|
|
3850
|
+
if (value === void 0 || value === null) return null;
|
|
3851
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
3852
|
+
throw new Error(
|
|
3853
|
+
"maxParts must be a whole number of parts, or null to disable it (received " + describeValue2(value) + ")."
|
|
3854
|
+
);
|
|
3855
|
+
}
|
|
3856
|
+
return value;
|
|
3857
|
+
}
|
|
3858
|
+
function resolvePromptTask(value) {
|
|
3859
|
+
if (value === void 0 || value === null) return "audit";
|
|
3860
|
+
if (value === "audit" || value === "review" || value === "explain") return value;
|
|
3861
|
+
throw new Error(
|
|
3862
|
+
'promptTask must be one of "audit", "review" or "explain" (received ' + describeValue2(value) + ")."
|
|
3863
|
+
);
|
|
3864
|
+
}
|
|
3865
|
+
function readConfiguredBrief(cwd, value) {
|
|
3866
|
+
if (value === void 0 || value === null) return void 0;
|
|
3867
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
3868
|
+
throw new Error(
|
|
3869
|
+
"brief must be a path to a markdown file (received " + describeValue2(value) + ")."
|
|
3870
|
+
);
|
|
3871
|
+
}
|
|
3872
|
+
const filePath = path3.resolve(cwd, value);
|
|
3873
|
+
let text2;
|
|
3874
|
+
try {
|
|
3875
|
+
if (!fs3.statSync(filePath).isFile()) throw new Error("not a file");
|
|
3876
|
+
text2 = fs3.readFileSync(filePath, "utf8");
|
|
3877
|
+
} catch {
|
|
3878
|
+
throw new Error(
|
|
3879
|
+
'brief "' + value + '" could not be read as a file; a snapshot must not ship without the half of the brief the owner wrote.'
|
|
3880
|
+
);
|
|
3881
|
+
}
|
|
3882
|
+
const parsed = parseOwnerBrief(value, text2);
|
|
3883
|
+
if (parsed.problems.length > 0) {
|
|
3884
|
+
throw new Error(
|
|
3885
|
+
'brief "' + value + '" cannot be used:\n - ' + parsed.problems.join("\n - ")
|
|
3886
|
+
);
|
|
3887
|
+
}
|
|
3888
|
+
return parsed.brief;
|
|
3889
|
+
}
|
|
3724
3890
|
function strictPositiveInteger(value, fallback, label) {
|
|
3725
3891
|
if (value === void 0) return fallback;
|
|
3726
3892
|
if (typeof value !== "number" || !Number.isInteger(value) || value <= 0) {
|
|
@@ -4080,6 +4246,10 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
4080
4246
|
configuredSensitiveFiles,
|
|
4081
4247
|
"`includeSensitiveFiles`"
|
|
4082
4248
|
);
|
|
4249
|
+
const configuredBrief = readConfiguredBrief(
|
|
4250
|
+
cwd,
|
|
4251
|
+
cliOptions?.brief ?? userConfig?.brief
|
|
4252
|
+
);
|
|
4083
4253
|
const presetExclude = [
|
|
4084
4254
|
.../* @__PURE__ */ new Set([...preset.exclude, ...outputExcludePatterns(cwd, outDir, tmpDir)])
|
|
4085
4255
|
];
|
|
@@ -4099,6 +4269,12 @@ function resolveConfig(userConfig, cliOptions, baseDir) {
|
|
|
4099
4269
|
"maxMonolithBytes"
|
|
4100
4270
|
),
|
|
4101
4271
|
includeSensitiveFiles,
|
|
4272
|
+
attachmentSlots: resolveAttachmentSlots(
|
|
4273
|
+
cliOptions?.attachmentSlots ?? userConfig?.attachmentSlots
|
|
4274
|
+
),
|
|
4275
|
+
maxParts: resolveMaxParts(cliOptions?.maxParts ?? userConfig?.maxParts),
|
|
4276
|
+
promptTask: resolvePromptTask(cliOptions?.promptTask ?? userConfig?.promptTask),
|
|
4277
|
+
...configuredBrief === void 0 ? {} : { brief: configuredBrief },
|
|
4102
4278
|
...changedSince === void 0 ? {} : { changedSince },
|
|
4103
4279
|
...staged ? { staged } : {},
|
|
4104
4280
|
...withDependents ? { withDependents } : {},
|
|
@@ -4181,6 +4357,15 @@ function configDigest(config) {
|
|
|
4181
4357
|
includeMonolith: config.includeMonolith,
|
|
4182
4358
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
4183
4359
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
4360
|
+
// Only when the experimental mode is on: `null` is the off switch, and writing it into the
|
|
4361
|
+
// material would change the digest of every snapshot taken before the setting existed.
|
|
4362
|
+
...config.maxParts === null ? {} : { maxParts: config.maxParts },
|
|
4363
|
+
// The default value is omitted for the same reason: a snapshot taken before the setting
|
|
4364
|
+
// existed kept the audit job, so it must keep the digest it was written with.
|
|
4365
|
+
...config.promptTask === "audit" ? {} : { promptTask: config.promptTask },
|
|
4366
|
+
// The owner brief is instruction, not payload, but it changes what the snapshot tells a
|
|
4367
|
+
// reader to do, so a changed brief is drift exactly like a changed budget.
|
|
4368
|
+
...config.brief === void 0 ? {} : { brief: config.brief.digest },
|
|
4184
4369
|
artifacts: config.artifacts,
|
|
4185
4370
|
include: config.include,
|
|
4186
4371
|
excludePatterns: config.excludePatterns,
|
|
@@ -4219,7 +4404,7 @@ function configDigest(config) {
|
|
|
4219
4404
|
(rule) => `${rule.rule}:${rule.pattern.source}/${rule.pattern.flags}:${rule.valueGroup ?? ""}`
|
|
4220
4405
|
).sort()
|
|
4221
4406
|
};
|
|
4222
|
-
return
|
|
4407
|
+
return createHash2("sha256").update(JSON.stringify(material)).digest("hex");
|
|
4223
4408
|
}
|
|
4224
4409
|
|
|
4225
4410
|
// src/scanner/changed.ts
|
|
@@ -4267,7 +4452,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
4267
4452
|
const descriptions = [];
|
|
4268
4453
|
if (request.changedSince !== void 0) {
|
|
4269
4454
|
assertUsableRef(request.changedSince);
|
|
4270
|
-
for (const
|
|
4455
|
+
for (const path23 of gitPaths(cwd, [
|
|
4271
4456
|
"diff",
|
|
4272
4457
|
"--name-only",
|
|
4273
4458
|
"-z",
|
|
@@ -4275,9 +4460,9 @@ function resolveChangedScope(cwd, request) {
|
|
|
4275
4460
|
`${request.changedSince}...HEAD`,
|
|
4276
4461
|
"--"
|
|
4277
4462
|
])) {
|
|
4278
|
-
paths.add(
|
|
4463
|
+
paths.add(path23);
|
|
4279
4464
|
}
|
|
4280
|
-
for (const
|
|
4465
|
+
for (const path23 of gitPaths(cwd, [
|
|
4281
4466
|
"diff",
|
|
4282
4467
|
"--name-only",
|
|
4283
4468
|
"-z",
|
|
@@ -4285,15 +4470,15 @@ function resolveChangedScope(cwd, request) {
|
|
|
4285
4470
|
"HEAD",
|
|
4286
4471
|
"--"
|
|
4287
4472
|
])) {
|
|
4288
|
-
paths.add(
|
|
4473
|
+
paths.add(path23);
|
|
4289
4474
|
}
|
|
4290
|
-
for (const
|
|
4291
|
-
paths.add(
|
|
4475
|
+
for (const path23 of gitPaths(cwd, ["ls-files", "--others", "--exclude-standard", "-z", "--"])) {
|
|
4476
|
+
paths.add(path23);
|
|
4292
4477
|
}
|
|
4293
4478
|
descriptions.push(`changed since ${request.changedSince}`);
|
|
4294
4479
|
}
|
|
4295
4480
|
if (request.staged === true) {
|
|
4296
|
-
for (const
|
|
4481
|
+
for (const path23 of gitPaths(cwd, [
|
|
4297
4482
|
"diff",
|
|
4298
4483
|
"--cached",
|
|
4299
4484
|
"--name-only",
|
|
@@ -4301,10 +4486,10 @@ function resolveChangedScope(cwd, request) {
|
|
|
4301
4486
|
"--relative",
|
|
4302
4487
|
"--"
|
|
4303
4488
|
])) {
|
|
4304
|
-
paths.add(
|
|
4305
|
-
stagedPaths.add(
|
|
4489
|
+
paths.add(path23);
|
|
4490
|
+
stagedPaths.add(path23);
|
|
4306
4491
|
}
|
|
4307
|
-
for (const
|
|
4492
|
+
for (const path23 of gitPaths(cwd, [
|
|
4308
4493
|
"diff",
|
|
4309
4494
|
"--cached",
|
|
4310
4495
|
"--name-only",
|
|
@@ -4313,7 +4498,7 @@ function resolveChangedScope(cwd, request) {
|
|
|
4313
4498
|
"--diff-filter=D",
|
|
4314
4499
|
"--"
|
|
4315
4500
|
])) {
|
|
4316
|
-
deletedPaths.add(
|
|
4501
|
+
deletedPaths.add(path23);
|
|
4317
4502
|
}
|
|
4318
4503
|
descriptions.push("staged");
|
|
4319
4504
|
}
|
|
@@ -5139,9 +5324,9 @@ var JAVA_METHOD = /^\s+(?:public|private|protected)\s+(?:static\s+)?(?:final\s+)
|
|
|
5139
5324
|
var jvmProfile = {
|
|
5140
5325
|
id: "jvm",
|
|
5141
5326
|
extensions: [".java", ".kt", ".kts", ".scala"],
|
|
5142
|
-
summarize(
|
|
5327
|
+
summarize(path23, content) {
|
|
5143
5328
|
const summary = emptySummary();
|
|
5144
|
-
const lower =
|
|
5329
|
+
const lower = path23.toLowerCase();
|
|
5145
5330
|
const isJava = lower.endsWith(".java");
|
|
5146
5331
|
const isKotlin = lower.endsWith(".kt") || lower.endsWith(".kts");
|
|
5147
5332
|
eachLine(content, (line) => {
|
|
@@ -5462,17 +5647,17 @@ var rustProfile = {
|
|
|
5462
5647
|
var SCRIPT_BLOCK = /<script([^>]*)>([\s\S]*?)<\/script>/gi;
|
|
5463
5648
|
var JSX_LANG = /\blang\s*=\s*["']?[tj]sx\b/i;
|
|
5464
5649
|
var ASTRO_FRONTMATTER = /^\uFEFF?---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?=\r?\n|$)/;
|
|
5465
|
-
function componentName(
|
|
5466
|
-
const base =
|
|
5650
|
+
function componentName(path23) {
|
|
5651
|
+
const base = path23.split("/").pop() ?? path23;
|
|
5467
5652
|
return base.replace(/\.[^.]+$/, "");
|
|
5468
5653
|
}
|
|
5469
5654
|
var sfcProfile = {
|
|
5470
5655
|
id: "sfc",
|
|
5471
5656
|
extensions: [".vue", ".svelte", ".astro"],
|
|
5472
|
-
summarize(
|
|
5657
|
+
summarize(path23, content) {
|
|
5473
5658
|
let script = "";
|
|
5474
|
-
let usesJsx =
|
|
5475
|
-
if (
|
|
5659
|
+
let usesJsx = path23.toLowerCase().endsWith(".astro");
|
|
5660
|
+
if (path23.toLowerCase().endsWith(".astro")) {
|
|
5476
5661
|
const frontmatter = ASTRO_FRONTMATTER.exec(content);
|
|
5477
5662
|
if (frontmatter) script += `${frontmatter[1]}
|
|
5478
5663
|
`;
|
|
@@ -5482,7 +5667,7 @@ var sfcProfile = {
|
|
|
5482
5667
|
script += `${match[2]}
|
|
5483
5668
|
`;
|
|
5484
5669
|
}
|
|
5485
|
-
const name = componentName(
|
|
5670
|
+
const name = componentName(path23);
|
|
5486
5671
|
if (!script.trim()) {
|
|
5487
5672
|
const summary2 = emptySummary();
|
|
5488
5673
|
if (name) {
|
|
@@ -5673,15 +5858,15 @@ for (const profile of LANGUAGE_PROFILES) {
|
|
|
5673
5858
|
BY_EXTENSION.set(extension.toLowerCase(), profile);
|
|
5674
5859
|
}
|
|
5675
5860
|
}
|
|
5676
|
-
function profileForPath(
|
|
5677
|
-
const lower =
|
|
5861
|
+
function profileForPath(path23) {
|
|
5862
|
+
const lower = path23.toLowerCase();
|
|
5678
5863
|
const dot = lower.lastIndexOf(".");
|
|
5679
5864
|
if (dot === -1) return null;
|
|
5680
5865
|
return BY_EXTENSION.get(lower.slice(dot)) ?? null;
|
|
5681
5866
|
}
|
|
5682
|
-
function summarizeWithProfile(
|
|
5683
|
-
const profile = profileForPath(
|
|
5684
|
-
return profile ? profile.summarize(
|
|
5867
|
+
function summarizeWithProfile(path23, content) {
|
|
5868
|
+
const profile = profileForPath(path23);
|
|
5869
|
+
return profile ? profile.summarize(path23, content) : null;
|
|
5685
5870
|
}
|
|
5686
5871
|
|
|
5687
5872
|
// src/scanner/binary.ts
|
|
@@ -6790,7 +6975,8 @@ function validateSnapshot(configInput) {
|
|
|
6790
6975
|
);
|
|
6791
6976
|
}
|
|
6792
6977
|
}
|
|
6793
|
-
|
|
6978
|
+
const ceilingDerivedByMaxParts = (manifest.config?.maxParts ?? null) !== null;
|
|
6979
|
+
if (!ceilingDerivedByMaxParts && manifest.budgets && manifest.budgets.maxPartBytes !== config.maxPartBytes) {
|
|
6794
6980
|
totalsMismatches.push(
|
|
6795
6981
|
`budgets.maxPartBytes: manifest ${manifest.budgets.maxPartBytes} vs current ${config.maxPartBytes}`
|
|
6796
6982
|
);
|
|
@@ -6819,6 +7005,7 @@ function validateSnapshot(configInput) {
|
|
|
6819
7005
|
}
|
|
6820
7006
|
const declaredArtifacts = [
|
|
6821
7007
|
["README.md", manifest.artifacts?.readme],
|
|
7008
|
+
["PROMPT.md", manifest.artifacts?.prompt],
|
|
6822
7009
|
["reports/navigation.md", manifest.artifacts?.navigation],
|
|
6823
7010
|
["reports/project-tree.md", manifest.artifacts?.projectTree],
|
|
6824
7011
|
["reports/audit.md", manifest.artifacts?.audit],
|
|
@@ -7770,6 +7957,7 @@ var DEFAULT_ANSWERS = {
|
|
|
7770
7957
|
excludePatterns: [],
|
|
7771
7958
|
artifacts: {
|
|
7772
7959
|
readme: true,
|
|
7960
|
+
prompt: true,
|
|
7773
7961
|
manifest: true,
|
|
7774
7962
|
parts: true,
|
|
7775
7963
|
navigation: true,
|
|
@@ -7886,6 +8074,7 @@ function renderConfig(answers) {
|
|
|
7886
8074
|
// \u2500\u2500 Artifacts \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
7887
8075
|
artifacts: {
|
|
7888
8076
|
readme: ${artifacts.readme}, // README.md
|
|
8077
|
+
prompt: ${artifacts.prompt}, // PROMPT.md \u2014 the instruction sheet a model is given
|
|
7889
8078
|
manifest: ${artifacts.manifest}, // manifest.json \u2014 required by validate and report
|
|
7890
8079
|
parts: ${artifacts.parts}, // parts/part-XXX.md
|
|
7891
8080
|
navigation: ${artifacts.navigation}, // reports/navigation.md
|
|
@@ -7901,6 +8090,15 @@ function renderConfig(answers) {
|
|
|
7901
8090
|
includeMonolith: ${artifacts.monolith},
|
|
7902
8091
|
|
|
7903
8092
|
// \u2500\u2500 Advanced \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
8093
|
+
// Files your destination accepts in one message, used by PROMPT.md to plan the delivery.
|
|
8094
|
+
// attachmentSlots: 10,
|
|
8095
|
+
// Experimental: grow the per-part budget until the snapshot fits this many parts, instead of
|
|
8096
|
+
// adding a part as the code grows. The plan in PROMPT.md becomes a fixed-length attachment list.
|
|
8097
|
+
// maxParts: 10,
|
|
8098
|
+
// The owner-written half of PROMPT.md: Stakes, The system, What came before, The bar, Calibration.
|
|
8099
|
+
// brief: "docs/brief.md",
|
|
8100
|
+
// Which job the brief is written for: audit, review or explain.
|
|
8101
|
+
// promptTask: "audit",
|
|
7904
8102
|
// afterGenerate: (manifest) => { /* write your own artifact */ }
|
|
7905
8103
|
hooks: {},
|
|
7906
8104
|
};
|
|
@@ -8594,6 +8792,7 @@ async function runInit(options) {
|
|
|
8594
8792
|
let lastScope = "all";
|
|
8595
8793
|
const artifactChoices = [
|
|
8596
8794
|
{ value: "readme", label: "README.md", hint: "orientation page" },
|
|
8795
|
+
{ value: "prompt", label: "PROMPT.md", hint: "instruction sheet for the model" },
|
|
8597
8796
|
{ value: "manifest", label: "manifest.json", hint: "required by validate and report" },
|
|
8598
8797
|
{ value: "parts", label: "parts/", hint: "the code payload" },
|
|
8599
8798
|
{ value: "navigation", label: "reports/navigation.md", hint: "file \u2192 part index" },
|
|
@@ -8938,9 +9137,9 @@ async function runWithStdoutCapture(fn) {
|
|
|
8938
9137
|
}
|
|
8939
9138
|
|
|
8940
9139
|
// src/index.ts
|
|
8941
|
-
import * as
|
|
9140
|
+
import * as fs16 from "fs";
|
|
8942
9141
|
import * as os2 from "os";
|
|
8943
|
-
import * as
|
|
9142
|
+
import * as path17 from "path";
|
|
8944
9143
|
|
|
8945
9144
|
// src/generator/audit.ts
|
|
8946
9145
|
function generateAuditReport(manifest, secretFindings, secretRules) {
|
|
@@ -9709,10 +9908,509 @@ function generateNavigation(manifest) {
|
|
|
9709
9908
|
return lines.join("\n");
|
|
9710
9909
|
}
|
|
9711
9910
|
|
|
9911
|
+
// src/generator/prompt.ts
|
|
9912
|
+
var MAX_PART_ROWS = 16;
|
|
9913
|
+
var MAX_LAYER_ROWS = 8;
|
|
9914
|
+
var MAX_INCOMPLETE_ROWS = 50;
|
|
9915
|
+
var MAX_CENTRAL_FILES = 5;
|
|
9916
|
+
var MAX_ENTRY_POINTS = 4;
|
|
9917
|
+
var MAX_LARGEST_FILES = 3;
|
|
9918
|
+
var partWord = (count) => count === 1 ? "part" : "parts";
|
|
9919
|
+
var UNLIMITED_SLOTS = 0;
|
|
9920
|
+
var ENTRY_POINT = /(^|\/)(index|cli|main|bin|server|app|mod)\.[cm]?[jt]sx?$/;
|
|
9921
|
+
var TEST_PATH = /(^|\/)(tests?|__tests__)\//;
|
|
9922
|
+
var TEST_FILE = /\.(test|spec)\.[^.]+$/;
|
|
9923
|
+
function generatePrompt(manifest, artifacts, context = {}) {
|
|
9924
|
+
const slots = context.slots ?? DEFAULT_ATTACHMENT_SLOTS;
|
|
9925
|
+
const task = context.task ?? "audit";
|
|
9926
|
+
const history = context.history ?? [];
|
|
9927
|
+
const overview = context.overview ?? { releases: [] };
|
|
9928
|
+
const brief = context.brief;
|
|
9929
|
+
const wrote = (name) => artifacts?.[name] !== false;
|
|
9930
|
+
const code = (value) => inlineCode(escapeControls(value));
|
|
9931
|
+
const hasOwnerHistory = (brief?.history ?? "").trim().length > 0;
|
|
9932
|
+
const lines = [
|
|
9933
|
+
"# PROMPT.md",
|
|
9934
|
+
"",
|
|
9935
|
+
"The brief and the apparatus for this snapshot. Paste this file first, then the parts it names.",
|
|
9936
|
+
"",
|
|
9937
|
+
"It is generated rather than written once: the system map, the omissions, the fingerprint and",
|
|
9938
|
+
"the history below are read from `manifest.json` and this repository, so they describe this run.",
|
|
9939
|
+
"Regenerate it after the code moves.",
|
|
9940
|
+
"",
|
|
9941
|
+
"---",
|
|
9942
|
+
"",
|
|
9943
|
+
"```text",
|
|
9944
|
+
"You are working on a codebase you cannot clone, run or grep. Everything you know about it comes",
|
|
9945
|
+
"from the snapshot that follows this instruction. Where these notes and the snapshot disagree,",
|
|
9946
|
+
"the snapshot is what exists.",
|
|
9947
|
+
""
|
|
9948
|
+
];
|
|
9949
|
+
if (brief?.preamble !== void 0) lines.push(brief.preamble, "");
|
|
9950
|
+
lines.push(...jobSection(task, history.length > 0 || hasOwnerHistory), "");
|
|
9951
|
+
lines.push(...stakesSection(brief, code));
|
|
9952
|
+
lines.push(...haveSection(wrote), "");
|
|
9953
|
+
lines.push(...whatThisIsSection(overview), "");
|
|
9954
|
+
lines.push(...systemSection(manifest, code, brief), "");
|
|
9955
|
+
lines.push(...historySection(history, brief, code), "");
|
|
9956
|
+
lines.push(...barSection(brief, code), "");
|
|
9957
|
+
lines.push(...coverageSection(manifest, code, wrote("audit")), "");
|
|
9958
|
+
lines.push(...answerSection(), "");
|
|
9959
|
+
lines.push(...calibrationSection(brief, code), "");
|
|
9960
|
+
lines.push(...ownerNotesSection(brief, code));
|
|
9961
|
+
lines.push(...snapshotSection(manifest, code), "");
|
|
9962
|
+
lines.push(...deliverySection(manifest, wrote("parts"), slots));
|
|
9963
|
+
lines.push(
|
|
9964
|
+
"## Your task",
|
|
9965
|
+
"",
|
|
9966
|
+
"<replace with the question, the area to review, or the subsystem to audit>",
|
|
9967
|
+
"```"
|
|
9968
|
+
);
|
|
9969
|
+
lines.push(
|
|
9970
|
+
"",
|
|
9971
|
+
"---",
|
|
9972
|
+
"",
|
|
9973
|
+
"## Why this file exists",
|
|
9974
|
+
"",
|
|
9975
|
+
"Parts on their own are a dump: the model receives text, has no idea what was left out of it,",
|
|
9976
|
+
"and fills the gap by invention. A brief on its own is a wish list: it cannot say which files",
|
|
9977
|
+
"are present, which are partial or which part holds what. This file is both halves, and the",
|
|
9978
|
+
"facts in it move with the snapshot.",
|
|
9979
|
+
"",
|
|
9980
|
+
"## Keeping it true",
|
|
9981
|
+
"",
|
|
9982
|
+
"- It is one of the artifacts recorded in `manifest.json` under `artifacts.prompt`, so deleting",
|
|
9983
|
+
" or editing `PROMPT.md` makes `snapshot validate` fail.",
|
|
9984
|
+
"- `--skip-artifacts prompt`, or `artifacts: { prompt: false }` in the config, turns it off.",
|
|
9985
|
+
"- The history section disappears when git cannot be read, rather than being invented.",
|
|
9986
|
+
"- If the code moves, regenerate. A brief naming the previous run parts is worse than no",
|
|
9987
|
+
" brief, because it reads as current.",
|
|
9988
|
+
""
|
|
9989
|
+
);
|
|
9990
|
+
return lines.join("\n");
|
|
9991
|
+
}
|
|
9992
|
+
function haveSection(wrote) {
|
|
9993
|
+
const out = ["## What you have", ""];
|
|
9994
|
+
const bullets = [];
|
|
9995
|
+
if (wrote("readme")) {
|
|
9996
|
+
bullets.push("- `README.md` - orientation: metrics, the part table, and the fingerprint.");
|
|
9997
|
+
}
|
|
9998
|
+
if (wrote("manifest")) {
|
|
9999
|
+
bullets.push(
|
|
10000
|
+
"- `manifest.json` - the index. Per file: `relativePath`, `layer`, `kind`, `language`,",
|
|
10001
|
+
" `part`, `sha256`, `inclusionMode`, `truncationReason`, `omittedRanges`. It also carries",
|
|
10002
|
+
" every excluded path under `skipped[]` with its reason, and `incomplete[]`, which names",
|
|
10003
|
+
" every included file whose emitted body is not the whole file."
|
|
10004
|
+
);
|
|
10005
|
+
}
|
|
10006
|
+
if (wrote("navigation")) {
|
|
10007
|
+
bullets.push("- `reports/navigation.md` - file to part. Locate here before you read anything.");
|
|
10008
|
+
}
|
|
10009
|
+
if (wrote("projectTree")) {
|
|
10010
|
+
bullets.push("- `reports/project-tree.md` - the directory shape of what was included.");
|
|
10011
|
+
}
|
|
10012
|
+
if (wrote("audit")) {
|
|
10013
|
+
bullets.push(
|
|
10014
|
+
"- `reports/audit.md` - secret findings, the files whose lines were redacted, large files,",
|
|
10015
|
+
" parse diagnostics and the git state the snapshot was taken from."
|
|
10016
|
+
);
|
|
10017
|
+
}
|
|
10018
|
+
if (wrote("parts")) {
|
|
10019
|
+
bullets.push(
|
|
10020
|
+
"- `parts/part-NNN.md` - the code itself, split to a fixed byte budget. Each part states its",
|
|
10021
|
+
" own number, the files it contains, and the fingerprint it was built from."
|
|
10022
|
+
);
|
|
10023
|
+
}
|
|
10024
|
+
if (wrote("monolith")) {
|
|
10025
|
+
bullets.push(
|
|
10026
|
+
"- `full-codebase.json` and `full-codebase.md` - the entire payload in one file each.",
|
|
10027
|
+
" Where they are present, they supersede the parts: nothing was left out of them."
|
|
10028
|
+
);
|
|
10029
|
+
}
|
|
10030
|
+
if (bullets.length === 0) {
|
|
10031
|
+
bullets.push(
|
|
10032
|
+
"- Nothing but this brief: every code artifact was disabled for this run. Ask for a snapshot",
|
|
10033
|
+
" generated with the artifacts you need, and do not answer from memory."
|
|
10034
|
+
);
|
|
10035
|
+
}
|
|
10036
|
+
out.push(...bullets);
|
|
10037
|
+
return out;
|
|
10038
|
+
}
|
|
10039
|
+
function systemSection(manifest, code, brief) {
|
|
10040
|
+
const out = ["## The system", ""];
|
|
10041
|
+
if (brief?.system !== void 0) {
|
|
10042
|
+
out.push(...ownerBlock(brief.system, brief.path, code), "", "What the index records:", "");
|
|
10043
|
+
}
|
|
10044
|
+
const layers = Object.entries(manifest.layers).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
10045
|
+
if (layers.length > 0) {
|
|
10046
|
+
const shown = layers.slice(0, MAX_LAYER_ROWS).map(([name, count]) => code(name) + " " + formatNumber(count));
|
|
10047
|
+
const rest = layers.length > MAX_LAYER_ROWS ? ", and " + formatNumber(layers.length - MAX_LAYER_ROWS) + " more" : "";
|
|
10048
|
+
out.push("- Layers, by file count: " + shown.join(", ") + rest + ".");
|
|
10049
|
+
}
|
|
10050
|
+
const central = manifest.indexes.imports.centralFiles;
|
|
10051
|
+
if (central.length > 0) {
|
|
10052
|
+
const shown = central.slice(0, MAX_CENTRAL_FILES).map((entry) => code(entry.path) + " (" + formatNumber(entry.importedByCount) + ")").join(", ");
|
|
10053
|
+
out.push(
|
|
10054
|
+
"- Load-bearing modules, by how many files import them: " + shown + ".",
|
|
10055
|
+
" A change here reaches the most call sites; read it before judging anything that uses it."
|
|
10056
|
+
);
|
|
10057
|
+
}
|
|
10058
|
+
const entryPoints = manifest.files.map((file) => file.relativePath).filter((path23) => ENTRY_POINT.test(path23)).sort((a, b) => a.split("/").length - b.split("/").length || a.length - b.length).slice(0, MAX_ENTRY_POINTS);
|
|
10059
|
+
out.push(
|
|
10060
|
+
entryPoints.length > 0 ? "- Entry points by convention: " + entryPoints.map(code).join(", ") + "." : "- No entry point was identifiable by name. The largest files below are where execution"
|
|
10061
|
+
);
|
|
10062
|
+
if (entryPoints.length === 0) out.push(" starts, and the call graph in `manifest.json` is the map.");
|
|
10063
|
+
const routes = manifest.indexes.routes.length;
|
|
10064
|
+
const handlers = manifest.indexes.handlers.length;
|
|
10065
|
+
const components = manifest.indexes.components.length;
|
|
10066
|
+
const routesShown = manifest.indexes.routes.slice(0, 4).map((route) => code(route.path));
|
|
10067
|
+
const componentsShown = manifest.indexes.components.slice(0, 4).map((entry) => code(entry.path));
|
|
10068
|
+
if (routes + handlers + components === 0) {
|
|
10069
|
+
out.push(
|
|
10070
|
+
"- No routes, handlers or UI components were recorded: this snapshot indexes no HTTP or",
|
|
10071
|
+
" component surface. Do not go looking for one, and do not infer one from a file name."
|
|
10072
|
+
);
|
|
10073
|
+
} else {
|
|
10074
|
+
const parts = [];
|
|
10075
|
+
if (routes > 0) parts.push(formatNumber(routes) + " route(s), e.g. " + routesShown.join(", "));
|
|
10076
|
+
if (handlers > 0) parts.push(formatNumber(handlers) + " handler(s)");
|
|
10077
|
+
if (components > 0) parts.push(formatNumber(components) + " component(s), e.g. " + componentsShown.join(", "));
|
|
10078
|
+
out.push("- Surfaces the index found: " + parts.join("; ") + ".");
|
|
10079
|
+
}
|
|
10080
|
+
const largest = [...manifest.files].sort((a, b) => b.includedBytes - a.includedBytes).slice(0, MAX_LARGEST_FILES);
|
|
10081
|
+
if (largest.length > 0) {
|
|
10082
|
+
out.push(
|
|
10083
|
+
"- Largest files: " + largest.map((file) => code(file.relativePath) + " (" + formatNumber(Math.round(file.includedBytes / 1024)) + " KB)").join(", ") + "."
|
|
10084
|
+
);
|
|
10085
|
+
}
|
|
10086
|
+
const tests = manifest.files.filter(
|
|
10087
|
+
(file) => TEST_PATH.test(file.relativePath) || TEST_FILE.test(file.relativePath)
|
|
10088
|
+
);
|
|
10089
|
+
if (tests.length > 0) {
|
|
10090
|
+
const testBytes = tests.reduce((total, file) => total + file.includedBytes, 0);
|
|
10091
|
+
const allBytes = manifest.files.reduce((total, file) => total + file.includedBytes, 0);
|
|
10092
|
+
const share = allBytes === 0 ? 0 : Math.round(testBytes / allBytes * 100);
|
|
10093
|
+
out.push(
|
|
10094
|
+
"- Tests: " + formatNumber(tests.length) + " file(s), " + share + "% of the included bytes.",
|
|
10095
|
+
" They are evidence of intent, not of behaviour: a fixture can encode a payload shape the",
|
|
10096
|
+
" real system never sends."
|
|
10097
|
+
);
|
|
10098
|
+
}
|
|
10099
|
+
return out;
|
|
10100
|
+
}
|
|
10101
|
+
function historySection(history, brief, code) {
|
|
10102
|
+
const out = ["## What came before", ""];
|
|
10103
|
+
if (brief?.history !== void 0) out.push(...ownerBlock(brief.history, brief.path, code), "");
|
|
10104
|
+
if (history.length === 0) {
|
|
10105
|
+
out.push(
|
|
10106
|
+
"No history was readable: this is not a git checkout, or git could not be run. Nothing about",
|
|
10107
|
+
"what came before can be claimed from here, and that is not evidence that the code is new."
|
|
10108
|
+
);
|
|
10109
|
+
return out;
|
|
10110
|
+
}
|
|
10111
|
+
out.push(
|
|
10112
|
+
"The last " + formatNumber(history.length) + " commit(s), newest first. Subjects and bodies are",
|
|
10113
|
+
"claims by whoever wrote them, not evidence - the code beside them is the evidence. If one of",
|
|
10114
|
+
"these fixes looks incomplete, quote the lines and say which call site it missed.",
|
|
10115
|
+
""
|
|
10116
|
+
);
|
|
10117
|
+
for (const commit of history) {
|
|
10118
|
+
out.push("- " + commit.subject);
|
|
10119
|
+
if (commit.body.length > 0) out.push(" " + commit.body);
|
|
10120
|
+
}
|
|
10121
|
+
return out;
|
|
10122
|
+
}
|
|
10123
|
+
function barSection(brief, code) {
|
|
10124
|
+
if (brief?.bar !== void 0) {
|
|
10125
|
+
return ["## The bar", "", ...ownerBlock(brief.bar, brief.path, code), ""];
|
|
10126
|
+
}
|
|
10127
|
+
return [
|
|
10128
|
+
"## The bar",
|
|
10129
|
+
"",
|
|
10130
|
+
"A finding is a concrete way the code breaks or lies, supported by quoted lines: the path and",
|
|
10131
|
+
"line, the input or state that reaches it, what happens next, and why the guard that appears to",
|
|
10132
|
+
"stop it does not. A comment is not behaviour. A passing test is evidence of intent, not of",
|
|
10133
|
+
"behaviour.",
|
|
10134
|
+
"",
|
|
10135
|
+
"- No style, naming, formatting, add-types, add-tests, consider-X or speculative rewrites.",
|
|
10136
|
+
"- Never invent a finding to fill a section. A clean surface is proven by quoting the guard",
|
|
10137
|
+
" that makes it clean.",
|
|
10138
|
+
"- Mark confidence, and name the check - a test, a run, an input - that would settle anything",
|
|
10139
|
+
" you cannot decide by reading.",
|
|
10140
|
+
"- Separate what the code does from what the deployment or configuration does. Both are",
|
|
10141
|
+
" findings; they have different owners and different fixes."
|
|
10142
|
+
];
|
|
10143
|
+
}
|
|
10144
|
+
function coverageSection(manifest, code, auditWritten) {
|
|
10145
|
+
const out = ["## Coverage", ""];
|
|
10146
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
10147
|
+
for (const record of manifest.skipped) {
|
|
10148
|
+
reasons.set(record.reason, (reasons.get(record.reason) ?? 0) + 1);
|
|
10149
|
+
}
|
|
10150
|
+
const tally = [...reasons.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([reason, count]) => code(reason) + " " + formatNumber(count)).join(", ");
|
|
10151
|
+
out.push(
|
|
10152
|
+
"- " + formatNumber(manifest.totals.candidateFiles) + " path(s) were found; " + formatNumber(manifest.totals.includedFiles) + " are in the parts and " + formatNumber(manifest.counts.skippedCount) + " were skipped" + (tally.length > 0 ? " (" + tally + ")" : "") + ".",
|
|
10153
|
+
" `manifest.skipped[]` names each one and why. An absent path is not a clean path."
|
|
10154
|
+
);
|
|
10155
|
+
out.push(...incompleteSection(manifest, code));
|
|
10156
|
+
out.push(...redactionSection(manifest, auditWritten));
|
|
10157
|
+
out.push(
|
|
10158
|
+
"- Everything unseen is unread, never clean. If you were given only some of the parts, say",
|
|
10159
|
+
" which ones are missing before you answer. A file the index names but the parts do not carry",
|
|
10160
|
+
" is an input defect, not a code finding - report it as one."
|
|
10161
|
+
);
|
|
10162
|
+
return out;
|
|
10163
|
+
}
|
|
10164
|
+
function answerSection() {
|
|
10165
|
+
return [
|
|
10166
|
+
"## What a useful answer contains",
|
|
10167
|
+
"",
|
|
10168
|
+
"- An opening line, filled from This snapshot below:",
|
|
10169
|
+
"",
|
|
10170
|
+
" snapshot <fingerprint> generated <generatedAt>",
|
|
10171
|
+
"",
|
|
10172
|
+
"- What you read and what you did not, named by path or by part.",
|
|
10173
|
+
"- Findings ordered by consequence, each with the lines quoted.",
|
|
10174
|
+
"- The checks or attacks that failed, and the line or guard that blocked them. A failed attack",
|
|
10175
|
+
" is how anyone knows an invariant is real rather than asserted.",
|
|
10176
|
+
"- What you retracted after re-reading.",
|
|
10177
|
+
"- What only a run, a test or a host can settle, and the check that would settle each.",
|
|
10178
|
+
"- One paragraph on the failure you would bet on next.",
|
|
10179
|
+
"- A closing line: Needed but not received: <paths>, or none. That line is not decoration -",
|
|
10180
|
+
" an invented function is indistinguishable from a real one, and this is where you name",
|
|
10181
|
+
" the gap you filled by asking instead of guessing."
|
|
10182
|
+
];
|
|
10183
|
+
}
|
|
10184
|
+
function calibrationSection(brief, code) {
|
|
10185
|
+
if (brief?.calibration !== void 0) {
|
|
10186
|
+
return ["## Calibration", "", ...ownerBlock(brief.calibration, brief.path, code), ""];
|
|
10187
|
+
}
|
|
10188
|
+
return [
|
|
10189
|
+
"## Calibration",
|
|
10190
|
+
"",
|
|
10191
|
+
"The findings that matter here do not crash. They look like:",
|
|
10192
|
+
"",
|
|
10193
|
+
"- a guard applied at one call site and not its twin - the route checks, the timer does not;",
|
|
10194
|
+
"- a budget shorter than the work it guards, so the caller gives up while the work continues;",
|
|
10195
|
+
"- a success flag that means the call returned, consumed as the change happened;",
|
|
10196
|
+
"- a document that describes a different run than the one beside it;",
|
|
10197
|
+
"- a default that fabricates a number when the measurement failed.",
|
|
10198
|
+
"",
|
|
10199
|
+
"None of these throw. All are invisible in a summary."
|
|
10200
|
+
];
|
|
10201
|
+
}
|
|
10202
|
+
function jobSection(task, hasHistory) {
|
|
10203
|
+
const out = ["## The job", ""];
|
|
10204
|
+
if (task === "audit") {
|
|
10205
|
+
out.push(
|
|
10206
|
+
"Find what is still wrong or will break. How you read the code is yours to decide - by",
|
|
10207
|
+
"subsystem, by data flow, by the invariants you derive yourself. What you owe in return is an",
|
|
10208
|
+
"honest account of what you covered and what you did not.",
|
|
10209
|
+
""
|
|
10210
|
+
);
|
|
10211
|
+
if (hasHistory) {
|
|
10212
|
+
out.push(
|
|
10213
|
+
"Another pass of the same findings is worth nothing. This repository carries a record of",
|
|
10214
|
+
"what was already fixed, below. Verify that those fixes hold instead of rediscovering them,",
|
|
10215
|
+
"and treat a variant of one at a different call site as a new finding."
|
|
10216
|
+
);
|
|
10217
|
+
} else {
|
|
10218
|
+
out.push(
|
|
10219
|
+
"Another pass of the same findings is worth nothing, but no earlier round is readable here,",
|
|
10220
|
+
"so you cannot tell what has already been tried. Do not assume this is the first attempt."
|
|
10221
|
+
);
|
|
10222
|
+
}
|
|
10223
|
+
out.push(
|
|
10224
|
+
"",
|
|
10225
|
+
"If the task at the end asks for something narrower - explain a file, review a change, answer",
|
|
10226
|
+
"a question - that task wins. The standard and the coverage duty below still apply to it."
|
|
10227
|
+
);
|
|
10228
|
+
} else if (task === "review") {
|
|
10229
|
+
out.push(
|
|
10230
|
+
"Review the change or the area named in the task against this snapshot. Report what breaks,",
|
|
10231
|
+
"what the change claims but does not do, and what a reader would believe that the code does",
|
|
10232
|
+
"not support. Restating the diff is not a review; the standard and the coverage duty below",
|
|
10233
|
+
"still apply."
|
|
10234
|
+
);
|
|
10235
|
+
} else {
|
|
10236
|
+
out.push(
|
|
10237
|
+
"Explain how the part of the system named in the task works: the data flow, the boundaries",
|
|
10238
|
+
"and the invariants it depends on. Cite the lines. If the snapshot does not contain what you",
|
|
10239
|
+
"need, say which file you need rather than reconstructing it from the shape of the names."
|
|
10240
|
+
);
|
|
10241
|
+
}
|
|
10242
|
+
return out;
|
|
10243
|
+
}
|
|
10244
|
+
function stakesSection(brief, code) {
|
|
10245
|
+
if (brief?.stakes === void 0) return [];
|
|
10246
|
+
return ["## Stakes", "", ...ownerBlock(brief.stakes, brief.path, code), ""];
|
|
10247
|
+
}
|
|
10248
|
+
function whatThisIsSection(overview) {
|
|
10249
|
+
const body = [];
|
|
10250
|
+
if (overview.description !== void 0) {
|
|
10251
|
+
body.push("- Declared in `package.json`: " + overview.description);
|
|
10252
|
+
}
|
|
10253
|
+
if (overview.summary !== void 0) {
|
|
10254
|
+
body.push("- From the `README.md` first paragraph: " + overview.summary);
|
|
10255
|
+
}
|
|
10256
|
+
if (overview.releases.length > 0) {
|
|
10257
|
+
body.push("- Most recent releases: " + overview.releases.join("; ") + ".");
|
|
10258
|
+
}
|
|
10259
|
+
if (body.length === 0) return [];
|
|
10260
|
+
return [
|
|
10261
|
+
"## What this is",
|
|
10262
|
+
"",
|
|
10263
|
+
...body,
|
|
10264
|
+
"",
|
|
10265
|
+
"Those are the project's own claims, not evidence about the code.",
|
|
10266
|
+
""
|
|
10267
|
+
];
|
|
10268
|
+
}
|
|
10269
|
+
function ownerNotesSection(brief, code) {
|
|
10270
|
+
if (brief === void 0 || brief.notes.length === 0) return [];
|
|
10271
|
+
const out = ["## Owner notes", ""];
|
|
10272
|
+
for (const note of brief.notes) {
|
|
10273
|
+
out.push("### " + note.heading, "", ...ownerBlock(note.body, brief.path, code), "");
|
|
10274
|
+
}
|
|
10275
|
+
return out;
|
|
10276
|
+
}
|
|
10277
|
+
function ownerBlock(text2, path23, code) {
|
|
10278
|
+
return ["> Written by the project owner in " + code(path23) + ", not generated.", "", text2];
|
|
10279
|
+
}
|
|
10280
|
+
function snapshotSection(manifest, code) {
|
|
10281
|
+
const out = ["## This snapshot", ""];
|
|
10282
|
+
out.push("- Fingerprint: " + code(manifest.fingerprint) + " - quote it verbatim in your answer.");
|
|
10283
|
+
out.push(
|
|
10284
|
+
"- Generated: " + code(manifest.generatedAt) + " from branch " + code(manifest.git.branch) + " at commit " + code(manifest.git.commit.slice(0, 8)) + "."
|
|
10285
|
+
);
|
|
10286
|
+
out.push(
|
|
10287
|
+
manifest.git.isDirty ? " The working tree had uncommitted changes at generation time." : " The working tree was clean at generation time."
|
|
10288
|
+
);
|
|
10289
|
+
out.push(
|
|
10290
|
+
"- Validation: `manifest.validation.status` was " + code(manifest.validation.status) + " at generation time.",
|
|
10291
|
+
" That describes the run, not now: if the tree may have moved since, the snapshot is a",
|
|
10292
|
+
" claim that needs re-checking, not a fact."
|
|
10293
|
+
);
|
|
10294
|
+
if (manifest.parts.length > 0) {
|
|
10295
|
+
out.push(
|
|
10296
|
+
"- Parts: " + formatNumber(manifest.parts.length) + " at a " + formatNumber(Math.round(manifest.budgets.maxPartBytes / 1024)) + " KB ceiling" + (manifest.parts.length === 1 ? ":" : " each:")
|
|
10297
|
+
);
|
|
10298
|
+
for (const part of manifest.parts.slice(0, MAX_PART_ROWS)) {
|
|
10299
|
+
out.push(" - " + code(part.filename) + " - " + formatNumber(part.fileCount) + " file(s)");
|
|
10300
|
+
}
|
|
10301
|
+
if (manifest.parts.length > MAX_PART_ROWS) {
|
|
10302
|
+
out.push(
|
|
10303
|
+
" - and " + formatNumber(manifest.parts.length - MAX_PART_ROWS) + " more, tabled in `README.md`"
|
|
10304
|
+
);
|
|
10305
|
+
}
|
|
10306
|
+
}
|
|
10307
|
+
return out;
|
|
10308
|
+
}
|
|
10309
|
+
function incompleteSection(manifest, code) {
|
|
10310
|
+
const out = [];
|
|
10311
|
+
const list2 = manifest.incomplete;
|
|
10312
|
+
if (list2.length === 0) {
|
|
10313
|
+
out.push("- Partial files: none. Every included file is present in full.");
|
|
10314
|
+
return out;
|
|
10315
|
+
}
|
|
10316
|
+
out.push(
|
|
10317
|
+
"- Partial files: " + formatNumber(list2.length) + ". These are present only in part, and the",
|
|
10318
|
+
" missing lines are named, not implied:"
|
|
10319
|
+
);
|
|
10320
|
+
for (const entry of list2.slice(0, MAX_INCOMPLETE_ROWS)) {
|
|
10321
|
+
const ranges = entry.omittedRanges.map(([start, end]) => start === end ? String(start) : start + "-" + end).join(", ");
|
|
10322
|
+
out.push(
|
|
10323
|
+
" - " + code(entry.relativePath) + " in " + code(entry.part) + " - " + entry.reason + ", lines " + ranges + " (" + formatNumber(entry.omittedLines) + " of " + formatNumber(entry.lines) + " missing)"
|
|
10324
|
+
);
|
|
10325
|
+
}
|
|
10326
|
+
if (list2.length > MAX_INCOMPLETE_ROWS) {
|
|
10327
|
+
out.push(
|
|
10328
|
+
" - and " + formatNumber(list2.length - MAX_INCOMPLETE_ROWS) + " more, all named in `manifest.json` under `incomplete[]`"
|
|
10329
|
+
);
|
|
10330
|
+
}
|
|
10331
|
+
return out;
|
|
10332
|
+
}
|
|
10333
|
+
function redactionSection(manifest, auditWritten) {
|
|
10334
|
+
const redacted = manifest.totals.redactedLines;
|
|
10335
|
+
if (redacted === 0) {
|
|
10336
|
+
return ["- Redacted: no line matched a secret rule."];
|
|
10337
|
+
}
|
|
10338
|
+
const where = auditWritten ? "`reports/audit.md` names the files; the values are not recoverable from it." : "`reports/audit.md` was disabled for this run, so only the count is available.";
|
|
10339
|
+
return [
|
|
10340
|
+
"- Redacted: " + formatNumber(redacted) + " line(s) had values masked before you received them.",
|
|
10341
|
+
" A masked span is a deliberate redaction, not an empty value.",
|
|
10342
|
+
" " + where
|
|
10343
|
+
];
|
|
10344
|
+
}
|
|
10345
|
+
function deliverySection(manifest, partsWritten, slots) {
|
|
10346
|
+
if (!partsWritten || manifest.parts.length === 0) return [];
|
|
10347
|
+
const parts = manifest.parts.length;
|
|
10348
|
+
const wholeSet = parts + 5;
|
|
10349
|
+
const unlimited = slots <= UNLIMITED_SLOTS;
|
|
10350
|
+
const out = ["## Attaching this", ""];
|
|
10351
|
+
out.push(
|
|
10352
|
+
"Paste this file as text: instructions cost no attachment slot. Attach the files it names.",
|
|
10353
|
+
"",
|
|
10354
|
+
"- Every part opens with `# Codebase Snapshot Part NNN of MMM` and repeats the fingerprint",
|
|
10355
|
+
" above, so check both before relying on one. A part you were not given is not an empty part."
|
|
10356
|
+
);
|
|
10357
|
+
if (unlimited) {
|
|
10358
|
+
out.push(
|
|
10359
|
+
"- No attachment limit is configured, so every file can travel: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports (" + wholeSet + " files)."
|
|
10360
|
+
);
|
|
10361
|
+
} else if (wholeSet <= slots) {
|
|
10362
|
+
out.push(
|
|
10363
|
+
"- A " + slots + "-file destination carries the whole set: " + parts + " " + partWord(parts) + " plus `manifest.json`, `README.md` and the three reports - " + wholeSet + " of " + slots + "."
|
|
10364
|
+
);
|
|
10365
|
+
} else if (parts + 1 <= slots) {
|
|
10366
|
+
out.push(
|
|
10367
|
+
"- A " + slots + "-file destination carries " + parts + " " + partWord(parts) + " and",
|
|
10368
|
+
" `manifest.json` (" + (parts + 1) + " of " + slots + "); `README.md` and",
|
|
10369
|
+
" `reports/` stay behind - the brief above carries what they add."
|
|
10370
|
+
);
|
|
10371
|
+
} else if (parts <= slots) {
|
|
10372
|
+
out.push(
|
|
10373
|
+
parts === 1 ? "- The only part fills a " + slots + "-file destination, so `manifest.json` and" : "- The " + parts + " parts fill a " + slots + "-file destination, so `manifest.json` and",
|
|
10374
|
+
" `reports/` stay behind. The brief above carries what they add."
|
|
10375
|
+
);
|
|
10376
|
+
if (parts > 1) {
|
|
10377
|
+
out.push(
|
|
10378
|
+
" Either raise `--max-part-bytes` to merge the parts, or set `--max-parts " + slots + "` and let the parts grow to the count instead."
|
|
10379
|
+
);
|
|
10380
|
+
}
|
|
10381
|
+
} else {
|
|
10382
|
+
out.push(
|
|
10383
|
+
"- The " + parts + " parts do not fit a " + slots + "-file destination: at most " + slots + " can be attached.",
|
|
10384
|
+
" Choose by task - `reports/navigation.md` maps a file to its part - and name the parts",
|
|
10385
|
+
" you left out, or regenerate with `--max-part-bytes " + suggestBudgetBytes(manifest, slots) + "` for about " + (slots - 1) + " parts. `--max-parts " + slots + "` grows the parts until",
|
|
10386
|
+
" they fit instead, and says so when they end up larger than maxPartBytes."
|
|
10387
|
+
);
|
|
10388
|
+
}
|
|
10389
|
+
out.push(
|
|
10390
|
+
"- If you were given only some of them, say which parts are missing before you answer, and",
|
|
10391
|
+
" name the files you needed. Do not infer the contents of a part you did not receive.",
|
|
10392
|
+
""
|
|
10393
|
+
);
|
|
10394
|
+
return out;
|
|
10395
|
+
}
|
|
10396
|
+
function suggestBudgetBytes(manifest, slots) {
|
|
10397
|
+
const total = manifest.parts.reduce((sum, part) => sum + part.byteSize, 0);
|
|
10398
|
+
const target = Math.max(1, slots - 1);
|
|
10399
|
+
const estimated = Math.ceil(total / target * 1.15);
|
|
10400
|
+
const rounded = Math.ceil(estimated / 16384) * 16384;
|
|
10401
|
+
const budget = Math.max(rounded, manifest.budgets.maxPartBytes);
|
|
10402
|
+
return Math.round(budget / 1024) + "k";
|
|
10403
|
+
}
|
|
10404
|
+
|
|
9712
10405
|
// src/generator/readme.ts
|
|
9713
10406
|
function generateReadme(manifest, artifacts) {
|
|
9714
10407
|
const wrote = (name) => artifacts?.[name] !== false;
|
|
9715
10408
|
const reportLinks = [];
|
|
10409
|
+
if (wrote("prompt")) {
|
|
10410
|
+
reportLinks.push(
|
|
10411
|
+
"- [PROMPT.md](PROMPT.md) \u2014 The instruction sheet to paste with this snapshot: what it contains, what it left out, and the rules for citing it."
|
|
10412
|
+
);
|
|
10413
|
+
}
|
|
9716
10414
|
if (wrote("navigation")) {
|
|
9717
10415
|
reportLinks.push(
|
|
9718
10416
|
"- [reports/navigation.md](reports/navigation.md) \u2014 Comprehensive file directory mapping files to chunk files."
|
|
@@ -9782,6 +10480,11 @@ function generateReadme(manifest, artifacts) {
|
|
|
9782
10480
|
lines.push("", "## Snapshot Parts", "", "No parts were written for this run.");
|
|
9783
10481
|
}
|
|
9784
10482
|
const readOrder = [];
|
|
10483
|
+
if (wrote("prompt")) {
|
|
10484
|
+
readOrder.push(
|
|
10485
|
+
"1. Hand `PROMPT.md` to the model that receives this snapshot: it names the parts, the partial files and the fingerprint of this run."
|
|
10486
|
+
);
|
|
10487
|
+
}
|
|
9785
10488
|
if (wrote("navigation") || wrote("projectTree")) {
|
|
9786
10489
|
const first = [wrote("navigation") ? "`reports/navigation.md`" : null, wrote("projectTree") ? "`reports/project-tree.md`" : null].filter(Boolean).join(" or ");
|
|
9787
10490
|
readOrder.push(`1. Read ${first} first to locate target features or files.`);
|
|
@@ -9887,12 +10590,68 @@ function treeTruncationWarnings(treeText) {
|
|
|
9887
10590
|
return warnings;
|
|
9888
10591
|
}
|
|
9889
10592
|
|
|
9890
|
-
// src/
|
|
10593
|
+
// src/generator/overview.ts
|
|
9891
10594
|
import * as fs13 from "fs";
|
|
10595
|
+
import * as path13 from "path";
|
|
10596
|
+
var SUMMARY_LIMIT = 400;
|
|
10597
|
+
var MAX_RELEASES = 2;
|
|
10598
|
+
function readProjectOverview(cwd) {
|
|
10599
|
+
return {
|
|
10600
|
+
...readDescription(cwd),
|
|
10601
|
+
...readSummary(cwd),
|
|
10602
|
+
releases: readReleases(cwd)
|
|
10603
|
+
};
|
|
10604
|
+
}
|
|
10605
|
+
function readText(file) {
|
|
10606
|
+
try {
|
|
10607
|
+
return fs13.readFileSync(file, "utf8");
|
|
10608
|
+
} catch {
|
|
10609
|
+
return null;
|
|
10610
|
+
}
|
|
10611
|
+
}
|
|
10612
|
+
function readDescription(cwd) {
|
|
10613
|
+
const raw = readText(path13.join(cwd, "package.json"));
|
|
10614
|
+
if (raw === null) return {};
|
|
10615
|
+
try {
|
|
10616
|
+
const parsed = JSON.parse(stripJsonComments(raw));
|
|
10617
|
+
return typeof parsed.description === "string" && parsed.description.trim().length > 0 ? { description: parsed.description.trim() } : {};
|
|
10618
|
+
} catch {
|
|
10619
|
+
return {};
|
|
10620
|
+
}
|
|
10621
|
+
}
|
|
10622
|
+
function readSummary(cwd) {
|
|
10623
|
+
const raw = readText(path13.join(cwd, "README.md"));
|
|
10624
|
+
if (raw === null) return {};
|
|
10625
|
+
const lines = raw.split(/\r?\n/);
|
|
10626
|
+
const paragraph = [];
|
|
10627
|
+
for (const line of lines) {
|
|
10628
|
+
const trimmed = line.trim();
|
|
10629
|
+
if (paragraph.length === 0) {
|
|
10630
|
+
if (trimmed.length === 0) continue;
|
|
10631
|
+
if (/^#/.test(trimmed) || /^!\[/.test(trimmed) || /^</.test(trimmed) || /^[-*|]/.test(trimmed)) continue;
|
|
10632
|
+
if (/^\[[^\]]+\]:/.test(trimmed)) continue;
|
|
10633
|
+
} else if (trimmed.length === 0 || /^#/.test(trimmed)) {
|
|
10634
|
+
break;
|
|
10635
|
+
}
|
|
10636
|
+
paragraph.push(trimmed);
|
|
10637
|
+
}
|
|
10638
|
+
const summary = paragraph.join(" ").replace(/\s+/g, " ").trim();
|
|
10639
|
+
if (summary.length === 0) return {};
|
|
10640
|
+
return { summary: summary.length > SUMMARY_LIMIT ? summary.slice(0, SUMMARY_LIMIT - 1) + "\u2026" : summary };
|
|
10641
|
+
}
|
|
10642
|
+
function readReleases(cwd) {
|
|
10643
|
+
const raw = readText(path13.join(cwd, "CHANGELOG.md"));
|
|
10644
|
+
if (raw === null) return [];
|
|
10645
|
+
const headings = raw.split(/\r?\n/).filter((line) => /^##\s+\S/.test(line)).map((line) => line.replace(/^##\s+/, "").trim());
|
|
10646
|
+
return headings.slice(0, MAX_RELEASES);
|
|
10647
|
+
}
|
|
10648
|
+
|
|
10649
|
+
// src/update-check.ts
|
|
10650
|
+
import * as fs14 from "fs";
|
|
9892
10651
|
import * as http from "http";
|
|
9893
10652
|
import * as https from "https";
|
|
9894
10653
|
import * as os from "os";
|
|
9895
|
-
import * as
|
|
10654
|
+
import * as path14 from "path";
|
|
9896
10655
|
var PACKAGE_LATEST_URL = "https://registry.npmjs.org/codebase-snapshot/latest";
|
|
9897
10656
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
9898
10657
|
var UP_TO_DATE_INTERVAL_MS = 60 * 60 * 1e3;
|
|
@@ -9941,17 +10700,17 @@ function isNewer(candidate, current) {
|
|
|
9941
10700
|
}
|
|
9942
10701
|
function cacheDirectory(env = process.env, platform = process.platform) {
|
|
9943
10702
|
if (platform === "win32") {
|
|
9944
|
-
const base2 = env.LOCALAPPDATA ??
|
|
9945
|
-
return
|
|
10703
|
+
const base2 = env.LOCALAPPDATA ?? path14.join(os.homedir(), "AppData", "Local");
|
|
10704
|
+
return path14.join(base2, "codebase-snapshot");
|
|
9946
10705
|
}
|
|
9947
10706
|
if (platform === "darwin") {
|
|
9948
|
-
return
|
|
10707
|
+
return path14.join(os.homedir(), "Library", "Caches", "codebase-snapshot");
|
|
9949
10708
|
}
|
|
9950
|
-
const base = env.XDG_CACHE_HOME ??
|
|
9951
|
-
return
|
|
10709
|
+
const base = env.XDG_CACHE_HOME ?? path14.join(os.homedir(), ".cache");
|
|
10710
|
+
return path14.join(base, "codebase-snapshot");
|
|
9952
10711
|
}
|
|
9953
10712
|
function cacheFilePath(env = process.env) {
|
|
9954
|
-
return
|
|
10713
|
+
return path14.join(cacheDirectory(env), "update-check.json");
|
|
9955
10714
|
}
|
|
9956
10715
|
function shouldCheck(argv, env) {
|
|
9957
10716
|
const disabled = ["1", "true", "yes"].includes(
|
|
@@ -9981,7 +10740,7 @@ function shouldCheck(argv, env) {
|
|
|
9981
10740
|
function readCache(file) {
|
|
9982
10741
|
let raw;
|
|
9983
10742
|
try {
|
|
9984
|
-
raw =
|
|
10743
|
+
raw = fs14.readFileSync(file, "utf8");
|
|
9985
10744
|
} catch {
|
|
9986
10745
|
return null;
|
|
9987
10746
|
}
|
|
@@ -9998,8 +10757,8 @@ function readCache(file) {
|
|
|
9998
10757
|
}
|
|
9999
10758
|
function writeCache(file, entry) {
|
|
10000
10759
|
try {
|
|
10001
|
-
|
|
10002
|
-
|
|
10760
|
+
fs14.mkdirSync(path14.dirname(file), { recursive: true });
|
|
10761
|
+
fs14.writeFileSync(file, `${JSON.stringify(entry)}
|
|
10003
10762
|
`, "utf8");
|
|
10004
10763
|
} catch {
|
|
10005
10764
|
}
|
|
@@ -10092,8 +10851,8 @@ function formatUpdateNotice(notice, kind) {
|
|
|
10092
10851
|
|
|
10093
10852
|
// src/agent/hook.ts
|
|
10094
10853
|
import * as childProcess2 from "child_process";
|
|
10095
|
-
import * as
|
|
10096
|
-
import * as
|
|
10854
|
+
import * as fs15 from "fs";
|
|
10855
|
+
import * as path15 from "path";
|
|
10097
10856
|
var HOOK_MARKER = `# ${GENERATOR_NAME}: pre-commit snapshot check`;
|
|
10098
10857
|
function shellQuote(value) {
|
|
10099
10858
|
return value.replace(/[\\"`$]/g, (character) => `\\${character}`);
|
|
@@ -10135,36 +10894,36 @@ fi
|
|
|
10135
10894
|
`;
|
|
10136
10895
|
}
|
|
10137
10896
|
function gitDirectory(cwd) {
|
|
10138
|
-
const dotGit =
|
|
10897
|
+
const dotGit = path15.join(cwd, ".git");
|
|
10139
10898
|
let stats;
|
|
10140
10899
|
try {
|
|
10141
|
-
stats =
|
|
10900
|
+
stats = fs15.statSync(dotGit);
|
|
10142
10901
|
} catch {
|
|
10143
10902
|
return null;
|
|
10144
10903
|
}
|
|
10145
10904
|
if (stats.isDirectory()) return dotGit;
|
|
10146
10905
|
if (!stats.isFile()) return null;
|
|
10147
10906
|
try {
|
|
10148
|
-
const contents =
|
|
10907
|
+
const contents = fs15.readFileSync(dotGit, "utf8");
|
|
10149
10908
|
const match = /^gitdir:\s*(.+)$/m.exec(contents);
|
|
10150
10909
|
if (!match) return null;
|
|
10151
10910
|
const target = match[1];
|
|
10152
|
-
const resolved =
|
|
10153
|
-
if (!
|
|
10154
|
-
if (isInside2(
|
|
10155
|
-
return isRegisteredWorktree(
|
|
10911
|
+
const resolved = path15.isAbsolute(target.trim()) ? target.trim() : path15.join(cwd, target.trim());
|
|
10912
|
+
if (!fs15.statSync(resolved).isDirectory()) return null;
|
|
10913
|
+
if (isInside2(path15.resolve(cwd), path15.resolve(resolved))) return resolved;
|
|
10914
|
+
return isRegisteredWorktree(path15.resolve(resolved), cwd) ? resolved : null;
|
|
10156
10915
|
} catch {
|
|
10157
10916
|
return null;
|
|
10158
10917
|
}
|
|
10159
10918
|
}
|
|
10160
10919
|
function isInside2(parent, child) {
|
|
10161
|
-
const relative15 =
|
|
10162
|
-
return relative15 === "" || !relative15.startsWith("..") && !
|
|
10920
|
+
const relative15 = path15.relative(parent, child);
|
|
10921
|
+
return relative15 === "" || !relative15.startsWith("..") && !path15.isAbsolute(relative15);
|
|
10163
10922
|
}
|
|
10164
10923
|
function isRegisteredWorktree(gitDir, cwd) {
|
|
10165
10924
|
try {
|
|
10166
|
-
const back =
|
|
10167
|
-
return
|
|
10925
|
+
const back = fs15.readFileSync(path15.join(gitDir, "gitdir"), "utf8").trim();
|
|
10926
|
+
return path15.resolve(gitDir, back) === path15.join(path15.resolve(cwd), ".git");
|
|
10168
10927
|
} catch {
|
|
10169
10928
|
return false;
|
|
10170
10929
|
}
|
|
@@ -10185,10 +10944,10 @@ function gitOutput(cwd, args) {
|
|
|
10185
10944
|
function configuredHooksDirectory(cwd) {
|
|
10186
10945
|
const hooks = gitOutput(cwd, ["rev-parse", "--git-path", "hooks"]);
|
|
10187
10946
|
if (hooks === null) return null;
|
|
10188
|
-
const resolved =
|
|
10947
|
+
const resolved = path15.resolve(cwd, hooks);
|
|
10189
10948
|
const common = gitOutput(cwd, ["rev-parse", "--git-common-dir"]);
|
|
10190
|
-
const commonDir = common === null ? null :
|
|
10191
|
-
if (isInside2(
|
|
10949
|
+
const commonDir = common === null ? null : path15.resolve(cwd, common);
|
|
10950
|
+
if (isInside2(path15.resolve(cwd), resolved)) return { dir: resolved };
|
|
10192
10951
|
if (commonDir !== null && isInside2(commonDir, resolved)) return { dir: resolved };
|
|
10193
10952
|
return {
|
|
10194
10953
|
refusal: `The hooks directory git reports (${resolved}) is outside this repository, so no hook was written. Add \`npx ${GENERATOR_NAME} validate\` to the hook manager that owns it instead.`
|
|
@@ -10209,10 +10968,10 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10209
10968
|
]
|
|
10210
10969
|
};
|
|
10211
10970
|
}
|
|
10212
|
-
const hooksDir = configured === null ?
|
|
10213
|
-
const hookPath =
|
|
10971
|
+
const hooksDir = configured === null ? path15.join(gitDir, "hooks") : configured.dir;
|
|
10972
|
+
const hookPath = path15.join(hooksDir, "pre-commit");
|
|
10214
10973
|
try {
|
|
10215
|
-
|
|
10974
|
+
fs15.mkdirSync(hooksDir, { recursive: true });
|
|
10216
10975
|
} catch (err) {
|
|
10217
10976
|
return {
|
|
10218
10977
|
path: hookPath,
|
|
@@ -10222,7 +10981,7 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10222
10981
|
}
|
|
10223
10982
|
let existing = null;
|
|
10224
10983
|
try {
|
|
10225
|
-
existing =
|
|
10984
|
+
existing = fs15.readFileSync(hookPath, "utf8");
|
|
10226
10985
|
} catch {
|
|
10227
10986
|
existing = null;
|
|
10228
10987
|
}
|
|
@@ -10237,8 +10996,8 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10237
10996
|
};
|
|
10238
10997
|
}
|
|
10239
10998
|
try {
|
|
10240
|
-
|
|
10241
|
-
|
|
10999
|
+
fs15.writeFileSync(hookPath, hookScript(outDir), "utf8");
|
|
11000
|
+
fs15.chmodSync(hookPath, 493);
|
|
10242
11001
|
} catch (err) {
|
|
10243
11002
|
return {
|
|
10244
11003
|
path: hookPath,
|
|
@@ -10256,11 +11015,11 @@ function installPreCommitHook(cwd, outDir = "snapshot") {
|
|
|
10256
11015
|
}
|
|
10257
11016
|
|
|
10258
11017
|
// src/mcp/generate-worker.ts
|
|
10259
|
-
import * as
|
|
11018
|
+
import * as path16 from "path";
|
|
10260
11019
|
import { fileURLToPath, pathToFileURL as pathToFileURL2 } from "url";
|
|
10261
11020
|
import { Worker } from "worker_threads";
|
|
10262
11021
|
function workerEntry(directory, isCjs) {
|
|
10263
|
-
const entry =
|
|
11022
|
+
const entry = path16.join(directory, isCjs ? "index.cjs" : "index.js");
|
|
10264
11023
|
return { path: entry, url: pathToFileURL2(entry).href };
|
|
10265
11024
|
}
|
|
10266
11025
|
var WORKER_SOURCE = `
|
|
@@ -10327,7 +11086,7 @@ function generateInWorker(cwd, cliOptions, options = {}) {
|
|
|
10327
11086
|
resolve12(result);
|
|
10328
11087
|
};
|
|
10329
11088
|
const isCjs = typeof __dirname !== "undefined";
|
|
10330
|
-
const directory = isCjs ? __dirname :
|
|
11089
|
+
const directory = isCjs ? __dirname : path16.dirname(fileURLToPath(import.meta.url));
|
|
10331
11090
|
try {
|
|
10332
11091
|
worker = new Worker(WORKER_SOURCE, {
|
|
10333
11092
|
eval: true,
|
|
@@ -10362,23 +11121,23 @@ var SUMMARY_MAX_SOURCE_BYTES2 = SUMMARY_MAX_SOURCE_BYTES;
|
|
|
10362
11121
|
var FILE_DERIVATIONS = /* @__PURE__ */ new Map();
|
|
10363
11122
|
var FILE_DERIVATION_LIMIT_BYTES = 64 * 1024 * 1024;
|
|
10364
11123
|
var fileDerivationBytes = 0;
|
|
10365
|
-
function takeDerivation(
|
|
10366
|
-
const cached = FILE_DERIVATIONS.get(
|
|
11124
|
+
function takeDerivation(path23, hash, settings) {
|
|
11125
|
+
const cached = FILE_DERIVATIONS.get(path23);
|
|
10367
11126
|
if (cached === void 0 || cached.hash !== hash || cached.settings !== settings) return void 0;
|
|
10368
|
-
FILE_DERIVATIONS.delete(
|
|
10369
|
-
FILE_DERIVATIONS.set(
|
|
11127
|
+
FILE_DERIVATIONS.delete(path23);
|
|
11128
|
+
FILE_DERIVATIONS.set(path23, cached);
|
|
10370
11129
|
return cached;
|
|
10371
11130
|
}
|
|
10372
|
-
function rememberDerivation(
|
|
11131
|
+
function rememberDerivation(path23, hash, settings, derivation) {
|
|
10373
11132
|
const bodyBytes = derivation.finalContent === derivation.redacted ? derivation.redacted.length : derivation.redacted.length + derivation.finalContent.length;
|
|
10374
11133
|
const bytes = bodyBytes * 2 + 512;
|
|
10375
11134
|
if (bytes > FILE_DERIVATION_LIMIT_BYTES / 4) return;
|
|
10376
|
-
const previous = FILE_DERIVATIONS.get(
|
|
11135
|
+
const previous = FILE_DERIVATIONS.get(path23);
|
|
10377
11136
|
if (previous !== void 0) {
|
|
10378
|
-
FILE_DERIVATIONS.delete(
|
|
11137
|
+
FILE_DERIVATIONS.delete(path23);
|
|
10379
11138
|
fileDerivationBytes -= previous.bytes;
|
|
10380
11139
|
} else {
|
|
10381
|
-
FILE_DERIVATIONS.delete(
|
|
11140
|
+
FILE_DERIVATIONS.delete(path23);
|
|
10382
11141
|
}
|
|
10383
11142
|
while (fileDerivationBytes + bytes > FILE_DERIVATION_LIMIT_BYTES) {
|
|
10384
11143
|
const oldest = FILE_DERIVATIONS.keys().next();
|
|
@@ -10387,7 +11146,7 @@ function rememberDerivation(path22, hash, settings, derivation) {
|
|
|
10387
11146
|
FILE_DERIVATIONS.delete(oldest.value);
|
|
10388
11147
|
if (evicted !== void 0) fileDerivationBytes -= evicted.bytes;
|
|
10389
11148
|
}
|
|
10390
|
-
FILE_DERIVATIONS.set(
|
|
11149
|
+
FILE_DERIVATIONS.set(path23, { ...derivation, hash, settings, bytes });
|
|
10391
11150
|
fileDerivationBytes += bytes;
|
|
10392
11151
|
}
|
|
10393
11152
|
function derivationSettings(config) {
|
|
@@ -10639,11 +11398,11 @@ function verifyInMemory(files, parts, unaccounted) {
|
|
|
10639
11398
|
return errors;
|
|
10640
11399
|
}
|
|
10641
11400
|
function resolveSafeOutputDirs(config) {
|
|
10642
|
-
const cwd =
|
|
10643
|
-
const outDir =
|
|
10644
|
-
const tmpDir =
|
|
10645
|
-
const root =
|
|
10646
|
-
const contains = (parent, child) => child === parent || child.startsWith(`${parent}${
|
|
11401
|
+
const cwd = path17.resolve(config.cwd);
|
|
11402
|
+
const outDir = path17.resolve(cwd, config.outDir);
|
|
11403
|
+
const tmpDir = path17.resolve(cwd, config.tmpDir);
|
|
11404
|
+
const root = path17.parse(cwd).root;
|
|
11405
|
+
const contains = (parent, child) => child === parent || child.startsWith(`${parent}${path17.sep}`);
|
|
10647
11406
|
const reject = (reason) => {
|
|
10648
11407
|
throw new Error(
|
|
10649
11408
|
`Refusing to generate: ${reason}. outDir=${outDir} tmpDir=${tmpDir} cwd=${cwd}`
|
|
@@ -10683,6 +11442,28 @@ function maskSummaryStrings(value, secretRules) {
|
|
|
10683
11442
|
function maskPathText(value, secretRules) {
|
|
10684
11443
|
return findSecretInPath(value, secretRules)?.masked ?? value;
|
|
10685
11444
|
}
|
|
11445
|
+
function maskOwnerBrief(brief, secretRules) {
|
|
11446
|
+
if (brief === void 0) return void 0;
|
|
11447
|
+
const mask = (value) => maskPathText(value, secretRules);
|
|
11448
|
+
return {
|
|
11449
|
+
...brief,
|
|
11450
|
+
...brief.stakes === void 0 ? {} : { stakes: mask(brief.stakes) },
|
|
11451
|
+
...brief.system === void 0 ? {} : { system: mask(brief.system) },
|
|
11452
|
+
...brief.history === void 0 ? {} : { history: mask(brief.history) },
|
|
11453
|
+
...brief.bar === void 0 ? {} : { bar: mask(brief.bar) },
|
|
11454
|
+
...brief.calibration === void 0 ? {} : { calibration: mask(brief.calibration) },
|
|
11455
|
+
...brief.preamble === void 0 ? {} : { preamble: mask(brief.preamble) },
|
|
11456
|
+
notes: brief.notes.map((note) => ({ heading: note.heading, body: mask(note.body) }))
|
|
11457
|
+
};
|
|
11458
|
+
}
|
|
11459
|
+
function maskOverview(overview, secretRules) {
|
|
11460
|
+
const mask = (value) => maskPathText(value, secretRules);
|
|
11461
|
+
return {
|
|
11462
|
+
...overview.description === void 0 ? {} : { description: mask(overview.description) },
|
|
11463
|
+
...overview.summary === void 0 ? {} : { summary: mask(overview.summary) },
|
|
11464
|
+
releases: overview.releases.map(mask)
|
|
11465
|
+
};
|
|
11466
|
+
}
|
|
10686
11467
|
function maskSkipRecords(records, secretRules) {
|
|
10687
11468
|
return maskSkipPaths(records, secretRules);
|
|
10688
11469
|
}
|
|
@@ -10703,14 +11484,14 @@ function listEntries(dir) {
|
|
|
10703
11484
|
const walk = (absolute, prefix) => {
|
|
10704
11485
|
let children;
|
|
10705
11486
|
try {
|
|
10706
|
-
children =
|
|
11487
|
+
children = fs16.readdirSync(absolute, { withFileTypes: true });
|
|
10707
11488
|
} catch {
|
|
10708
11489
|
return;
|
|
10709
11490
|
}
|
|
10710
11491
|
for (const child of children) {
|
|
10711
11492
|
const relative15 = prefix === "" ? child.name : `${prefix}/${child.name}`;
|
|
10712
11493
|
entries.push(relative15);
|
|
10713
|
-
if (child.isDirectory()) walk(
|
|
11494
|
+
if (child.isDirectory()) walk(path17.join(absolute, child.name), relative15);
|
|
10714
11495
|
}
|
|
10715
11496
|
};
|
|
10716
11497
|
walk(dir, "");
|
|
@@ -10722,10 +11503,10 @@ function markerInventory(dir, written) {
|
|
|
10722
11503
|
for (const entry of entries) {
|
|
10723
11504
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10724
11505
|
if (isIgnorableEntry(entry)) continue;
|
|
10725
|
-
const full =
|
|
11506
|
+
const full = path17.join(dir, ...entry.split("/"));
|
|
10726
11507
|
let stats;
|
|
10727
11508
|
try {
|
|
10728
|
-
stats =
|
|
11509
|
+
stats = fs16.lstatSync(full);
|
|
10729
11510
|
} catch {
|
|
10730
11511
|
continue;
|
|
10731
11512
|
}
|
|
@@ -10737,7 +11518,7 @@ function markerInventory(dir, written) {
|
|
|
10737
11518
|
}
|
|
10738
11519
|
let digest;
|
|
10739
11520
|
try {
|
|
10740
|
-
digest = sha256Hex2(
|
|
11521
|
+
digest = sha256Hex2(fs16.readFileSync(full));
|
|
10741
11522
|
} catch {
|
|
10742
11523
|
continue;
|
|
10743
11524
|
}
|
|
@@ -10758,15 +11539,15 @@ function markerPayload(dir, state, id, createdAt, written) {
|
|
|
10758
11539
|
entries,
|
|
10759
11540
|
files
|
|
10760
11541
|
};
|
|
10761
|
-
const manifestPath =
|
|
10762
|
-
if (
|
|
10763
|
-
marker2.manifestSha256 = sha256Hex2(
|
|
11542
|
+
const manifestPath = path17.join(dir, "manifest.json");
|
|
11543
|
+
if (fs16.existsSync(manifestPath)) {
|
|
11544
|
+
marker2.manifestSha256 = sha256Hex2(fs16.readFileSync(manifestPath));
|
|
10764
11545
|
}
|
|
10765
11546
|
return marker2;
|
|
10766
11547
|
}
|
|
10767
11548
|
function writeOwnershipMarker(dir, marker2) {
|
|
10768
|
-
|
|
10769
|
-
|
|
11549
|
+
fs16.writeFileSync(
|
|
11550
|
+
path17.join(dir, OWNERSHIP_MARKER),
|
|
10770
11551
|
`${JSON.stringify(marker2, null, 2)}
|
|
10771
11552
|
`,
|
|
10772
11553
|
"utf8"
|
|
@@ -10778,13 +11559,13 @@ function markerBelongsTo(dir, id) {
|
|
|
10778
11559
|
return evidence.marker.id === id;
|
|
10779
11560
|
}
|
|
10780
11561
|
function readOwnershipMarker(dir) {
|
|
10781
|
-
const markerPath =
|
|
10782
|
-
if (!
|
|
11562
|
+
const markerPath = path17.join(dir, OWNERSHIP_MARKER);
|
|
11563
|
+
if (!fs16.existsSync(markerPath)) {
|
|
10783
11564
|
return { marker: null, problem: "it holds no .codebase-snapshot marker" };
|
|
10784
11565
|
}
|
|
10785
11566
|
let raw;
|
|
10786
11567
|
try {
|
|
10787
|
-
raw =
|
|
11568
|
+
raw = fs16.readFileSync(markerPath, "utf8");
|
|
10788
11569
|
} catch {
|
|
10789
11570
|
return { marker: null, problem: "its .codebase-snapshot marker could not be read" };
|
|
10790
11571
|
}
|
|
@@ -10884,10 +11665,10 @@ function verifyMarkerInventory(dir, entries, files) {
|
|
|
10884
11665
|
for (const entry of entries) {
|
|
10885
11666
|
if (entry === OWNERSHIP_MARKER) continue;
|
|
10886
11667
|
if (IGNORABLE_ENTRIES.has(entry.slice(entry.lastIndexOf("/") + 1))) continue;
|
|
10887
|
-
const full =
|
|
11668
|
+
const full = path17.join(dir, ...entry.split("/"));
|
|
10888
11669
|
let stats;
|
|
10889
11670
|
try {
|
|
10890
|
-
stats =
|
|
11671
|
+
stats = fs16.lstatSync(full);
|
|
10891
11672
|
} catch {
|
|
10892
11673
|
return `its .codebase-snapshot inventory lists ${entry}, which cannot be read`;
|
|
10893
11674
|
}
|
|
@@ -10912,7 +11693,7 @@ function verifyMarkerInventory(dir, entries, files) {
|
|
|
10912
11693
|
}
|
|
10913
11694
|
let digest;
|
|
10914
11695
|
try {
|
|
10915
|
-
digest = sha256Hex2(
|
|
11696
|
+
digest = sha256Hex2(fs16.readFileSync(full));
|
|
10916
11697
|
} catch {
|
|
10917
11698
|
return `its .codebase-snapshot inventory cannot verify ${entry}: the file could not be read`;
|
|
10918
11699
|
}
|
|
@@ -10933,12 +11714,12 @@ function assessSnapshotDirectory(dir) {
|
|
|
10933
11714
|
marker: marker2
|
|
10934
11715
|
};
|
|
10935
11716
|
}
|
|
10936
|
-
const manifestPath =
|
|
10937
|
-
const hasManifest =
|
|
11717
|
+
const manifestPath = path17.join(dir, "manifest.json");
|
|
11718
|
+
const hasManifest = fs16.existsSync(manifestPath);
|
|
10938
11719
|
if (hasManifest) {
|
|
10939
11720
|
let raw;
|
|
10940
11721
|
try {
|
|
10941
|
-
raw =
|
|
11722
|
+
raw = fs16.readFileSync(manifestPath, "utf8");
|
|
10942
11723
|
} catch {
|
|
10943
11724
|
return {
|
|
10944
11725
|
owned: false,
|
|
@@ -11033,13 +11814,13 @@ function containsNoFiles(dir) {
|
|
|
11033
11814
|
const current = pending.pop();
|
|
11034
11815
|
let entries;
|
|
11035
11816
|
try {
|
|
11036
|
-
entries =
|
|
11817
|
+
entries = fs16.readdirSync(current, { withFileTypes: true });
|
|
11037
11818
|
} catch {
|
|
11038
11819
|
return false;
|
|
11039
11820
|
}
|
|
11040
11821
|
for (const entry of entries) {
|
|
11041
11822
|
if (entry.isDirectory()) {
|
|
11042
|
-
pending.push(
|
|
11823
|
+
pending.push(path17.join(current, entry.name));
|
|
11043
11824
|
} else if (!IGNORABLE_ENTRIES.has(entry.name)) {
|
|
11044
11825
|
return false;
|
|
11045
11826
|
}
|
|
@@ -11048,13 +11829,13 @@ function containsNoFiles(dir) {
|
|
|
11048
11829
|
return true;
|
|
11049
11830
|
}
|
|
11050
11831
|
function assertReplaceable(target, label, secretRules) {
|
|
11051
|
-
if (!
|
|
11052
|
-
if (!
|
|
11832
|
+
if (!fs16.existsSync(target)) return;
|
|
11833
|
+
if (!fs16.statSync(target).isDirectory()) {
|
|
11053
11834
|
throw new Error(
|
|
11054
11835
|
`Refusing to write into ${label} ${target}: it exists but is not a directory.`
|
|
11055
11836
|
);
|
|
11056
11837
|
}
|
|
11057
|
-
const entries =
|
|
11838
|
+
const entries = fs16.readdirSync(target);
|
|
11058
11839
|
if (entries.length === 0) return;
|
|
11059
11840
|
if (entries.every((name) => IGNORABLE_ENTRIES.has(name))) return;
|
|
11060
11841
|
if (containsNoFiles(target)) return;
|
|
@@ -11074,18 +11855,18 @@ function assertReplaceable(target, label, secretRules) {
|
|
|
11074
11855
|
);
|
|
11075
11856
|
}
|
|
11076
11857
|
function assertStagingRootUsable(tmpDir, secretRules) {
|
|
11077
|
-
if (!
|
|
11078
|
-
if (!
|
|
11858
|
+
if (!fs16.existsSync(tmpDir)) return;
|
|
11859
|
+
if (!fs16.statSync(tmpDir).isDirectory()) {
|
|
11079
11860
|
throw new Error(`Refusing to write into tmpDir ${tmpDir}: it exists but is not a directory.`);
|
|
11080
11861
|
}
|
|
11081
|
-
const entries =
|
|
11862
|
+
const entries = fs16.readdirSync(tmpDir);
|
|
11082
11863
|
if (entries.length === 0) return;
|
|
11083
11864
|
const foreign = entries.filter((name) => {
|
|
11084
|
-
const full =
|
|
11865
|
+
const full = path17.join(tmpDir, name);
|
|
11085
11866
|
if (!name.startsWith(RUN_DIR_PREFIX)) return true;
|
|
11086
11867
|
let stats;
|
|
11087
11868
|
try {
|
|
11088
|
-
stats =
|
|
11869
|
+
stats = fs16.statSync(full);
|
|
11089
11870
|
} catch {
|
|
11090
11871
|
return true;
|
|
11091
11872
|
}
|
|
@@ -11093,7 +11874,7 @@ function assertStagingRootUsable(tmpDir, secretRules) {
|
|
|
11093
11874
|
const { marker: marker2 } = readOwnershipMarker(full);
|
|
11094
11875
|
if (marker2) return false;
|
|
11095
11876
|
try {
|
|
11096
|
-
return
|
|
11877
|
+
return fs16.readdirSync(full).length > 0;
|
|
11097
11878
|
} catch {
|
|
11098
11879
|
return true;
|
|
11099
11880
|
}
|
|
@@ -11108,13 +11889,13 @@ function assertStagingRootUsable(tmpDir, secretRules) {
|
|
|
11108
11889
|
function cleanStaleRunDirs(tmpDir) {
|
|
11109
11890
|
let entries;
|
|
11110
11891
|
try {
|
|
11111
|
-
entries =
|
|
11892
|
+
entries = fs16.readdirSync(tmpDir);
|
|
11112
11893
|
} catch {
|
|
11113
11894
|
return;
|
|
11114
11895
|
}
|
|
11115
11896
|
for (const name of entries) {
|
|
11116
11897
|
if (!name.startsWith(RUN_DIR_PREFIX)) continue;
|
|
11117
|
-
const full =
|
|
11898
|
+
const full = path17.join(tmpDir, name);
|
|
11118
11899
|
const { marker: marker2 } = readOwnershipMarker(full);
|
|
11119
11900
|
if (marker2) {
|
|
11120
11901
|
const created = Date.parse(marker2.createdAt);
|
|
@@ -11122,33 +11903,33 @@ function cleanStaleRunDirs(tmpDir) {
|
|
|
11122
11903
|
const abandoned = typeof marker2.pid === "number" && !isProcessAlive(marker2.pid);
|
|
11123
11904
|
if (aged || abandoned) {
|
|
11124
11905
|
try {
|
|
11125
|
-
|
|
11906
|
+
fs16.rmSync(full, { recursive: true, force: true });
|
|
11126
11907
|
} catch {
|
|
11127
11908
|
}
|
|
11128
11909
|
}
|
|
11129
11910
|
continue;
|
|
11130
11911
|
}
|
|
11131
11912
|
try {
|
|
11132
|
-
if (
|
|
11913
|
+
if (fs16.readdirSync(full).length === 0) fs16.rmSync(full, { recursive: true, force: true });
|
|
11133
11914
|
} catch {
|
|
11134
11915
|
}
|
|
11135
11916
|
}
|
|
11136
11917
|
}
|
|
11137
11918
|
function removeIfEmpty(dir) {
|
|
11138
11919
|
try {
|
|
11139
|
-
if (
|
|
11920
|
+
if (fs16.readdirSync(dir).length === 0) fs16.rmSync(dir, { recursive: true, force: true });
|
|
11140
11921
|
} catch {
|
|
11141
11922
|
}
|
|
11142
11923
|
}
|
|
11143
11924
|
function ensureParentDirectory(target, label) {
|
|
11144
|
-
const parent =
|
|
11145
|
-
if (
|
|
11925
|
+
const parent = path17.dirname(target);
|
|
11926
|
+
if (fs16.existsSync(parent) && !fs16.statSync(parent).isDirectory()) {
|
|
11146
11927
|
throw new Error(
|
|
11147
11928
|
`Refusing to create ${label} ${target}: ${parent} exists but is not a directory.`
|
|
11148
11929
|
);
|
|
11149
11930
|
}
|
|
11150
11931
|
try {
|
|
11151
|
-
|
|
11932
|
+
fs16.mkdirSync(parent, { recursive: true });
|
|
11152
11933
|
} catch (err) {
|
|
11153
11934
|
throw new Error(
|
|
11154
11935
|
`Refusing to create ${label} ${target}: its parent ${parent} could not be created (${err.message}).`
|
|
@@ -11206,17 +11987,17 @@ function acquireRunLock(stagingRoot) {
|
|
|
11206
11987
|
`;
|
|
11207
11988
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
11208
11989
|
try {
|
|
11209
|
-
const handle =
|
|
11990
|
+
const handle = fs16.openSync(lockPath, "wx");
|
|
11210
11991
|
try {
|
|
11211
|
-
|
|
11992
|
+
fs16.writeSync(handle, payload);
|
|
11212
11993
|
} finally {
|
|
11213
|
-
|
|
11994
|
+
fs16.closeSync(handle);
|
|
11214
11995
|
}
|
|
11215
11996
|
const stopHeartbeat = startLockHeartbeat(lockPath);
|
|
11216
11997
|
return () => {
|
|
11217
11998
|
stopHeartbeat();
|
|
11218
11999
|
try {
|
|
11219
|
-
|
|
12000
|
+
fs16.rmSync(lockPath, { force: true });
|
|
11220
12001
|
} catch {
|
|
11221
12002
|
}
|
|
11222
12003
|
};
|
|
@@ -11236,26 +12017,26 @@ function lockKeyFor(stagingRoot) {
|
|
|
11236
12017
|
return sha256Hex2(key).slice(0, 16);
|
|
11237
12018
|
}
|
|
11238
12019
|
function canonicalLockTarget(targetPath2) {
|
|
11239
|
-
const resolved =
|
|
12020
|
+
const resolved = path17.resolve(targetPath2);
|
|
11240
12021
|
let existing = resolved;
|
|
11241
12022
|
const tail = [];
|
|
11242
12023
|
for (; ; ) {
|
|
11243
12024
|
try {
|
|
11244
|
-
return
|
|
12025
|
+
return path17.join(fs16.realpathSync(existing), ...tail);
|
|
11245
12026
|
} catch {
|
|
11246
|
-
const parent =
|
|
12027
|
+
const parent = path17.dirname(existing);
|
|
11247
12028
|
if (parent === existing) return resolved;
|
|
11248
|
-
tail.unshift(
|
|
12029
|
+
tail.unshift(path17.basename(existing));
|
|
11249
12030
|
existing = parent;
|
|
11250
12031
|
}
|
|
11251
12032
|
}
|
|
11252
12033
|
}
|
|
11253
12034
|
function lockPathFor(stagingRoot) {
|
|
11254
|
-
return
|
|
12035
|
+
return path17.join(os2.tmpdir(), `codebase-snapshot-${lockKeyFor(stagingRoot)}.lock`);
|
|
11255
12036
|
}
|
|
11256
12037
|
function lockHeartbeatAgeMs(lockPath) {
|
|
11257
12038
|
try {
|
|
11258
|
-
return Date.now() -
|
|
12039
|
+
return Date.now() - fs16.statSync(lockPath).mtimeMs;
|
|
11259
12040
|
} catch {
|
|
11260
12041
|
return Number.POSITIVE_INFINITY;
|
|
11261
12042
|
}
|
|
@@ -11263,7 +12044,7 @@ function lockHeartbeatAgeMs(lockPath) {
|
|
|
11263
12044
|
function lockOwnerIsGone(lockPath) {
|
|
11264
12045
|
let raw;
|
|
11265
12046
|
try {
|
|
11266
|
-
raw =
|
|
12047
|
+
raw = fs16.readFileSync(lockPath, "utf8");
|
|
11267
12048
|
} catch {
|
|
11268
12049
|
return false;
|
|
11269
12050
|
}
|
|
@@ -11285,16 +12066,16 @@ function lockOwnerIsGone(lockPath) {
|
|
|
11285
12066
|
function reclaimStaleLock(lockPath) {
|
|
11286
12067
|
let before;
|
|
11287
12068
|
try {
|
|
11288
|
-
before =
|
|
12069
|
+
before = fs16.statSync(lockPath);
|
|
11289
12070
|
} catch {
|
|
11290
12071
|
return true;
|
|
11291
12072
|
}
|
|
11292
12073
|
if (!lockOwnerIsGone(lockPath)) return false;
|
|
11293
12074
|
try {
|
|
11294
|
-
const current =
|
|
12075
|
+
const current = fs16.statSync(lockPath);
|
|
11295
12076
|
const sameFile = current.ino === before.ino && current.birthtimeMs === before.birthtimeMs && current.mtimeMs === before.mtimeMs;
|
|
11296
12077
|
if (!sameFile) return false;
|
|
11297
|
-
|
|
12078
|
+
fs16.rmSync(lockPath, { force: true });
|
|
11298
12079
|
return true;
|
|
11299
12080
|
} catch {
|
|
11300
12081
|
return false;
|
|
@@ -11305,12 +12086,12 @@ function lockFileIsAncient(lockPath) {
|
|
|
11305
12086
|
}
|
|
11306
12087
|
function writeManifestAtomically(manifestPath, manifest) {
|
|
11307
12088
|
const tempPath = `${manifestPath}.${process.pid}.tmp`;
|
|
11308
|
-
|
|
12089
|
+
fs16.writeFileSync(tempPath, JSON.stringify(manifest, null, 2), "utf8");
|
|
11309
12090
|
try {
|
|
11310
|
-
|
|
12091
|
+
fs16.renameSync(tempPath, manifestPath);
|
|
11311
12092
|
} catch (err) {
|
|
11312
12093
|
try {
|
|
11313
|
-
|
|
12094
|
+
fs16.rmSync(tempPath, { force: true });
|
|
11314
12095
|
} catch {
|
|
11315
12096
|
}
|
|
11316
12097
|
throw err;
|
|
@@ -11335,21 +12116,21 @@ function swapIntoPlace(stagingDir, outDir, beforeSwap) {
|
|
|
11335
12116
|
}
|
|
11336
12117
|
}
|
|
11337
12118
|
function recoverInterruptedPublish(outDir) {
|
|
11338
|
-
if (
|
|
11339
|
-
const parent =
|
|
11340
|
-
const base =
|
|
12119
|
+
if (fs16.existsSync(outDir)) return;
|
|
12120
|
+
const parent = path17.dirname(outDir);
|
|
12121
|
+
const base = path17.basename(outDir);
|
|
11341
12122
|
let backups;
|
|
11342
12123
|
try {
|
|
11343
|
-
backups =
|
|
12124
|
+
backups = fs16.readdirSync(parent).filter((name) => name.startsWith(`${base}.backup-`));
|
|
11344
12125
|
} catch {
|
|
11345
12126
|
return;
|
|
11346
12127
|
}
|
|
11347
12128
|
if (backups.length !== 1) return;
|
|
11348
|
-
const backupDir =
|
|
12129
|
+
const backupDir = path17.join(parent, backups[0]);
|
|
11349
12130
|
const { marker: marker2, problem } = readOwnershipMarker(backupDir);
|
|
11350
12131
|
if (problem !== null || marker2 === null || marker2.state !== "complete") return;
|
|
11351
12132
|
try {
|
|
11352
|
-
|
|
12133
|
+
fs16.renameSync(backupDir, outDir);
|
|
11353
12134
|
process.stderr.write(
|
|
11354
12135
|
`\u26A0 Recovered ${outDir} from ${backupDir}, left by an interrupted run. That snapshot is the one from before the interrupted run.
|
|
11355
12136
|
`
|
|
@@ -11359,16 +12140,16 @@ function recoverInterruptedPublish(outDir) {
|
|
|
11359
12140
|
}
|
|
11360
12141
|
function swapOnce(stagingDir, outDir, beforeSwap) {
|
|
11361
12142
|
const backupDir = `${outDir}.backup-${process.pid}-${Date.now()}`;
|
|
11362
|
-
const hadPrevious =
|
|
12143
|
+
const hadPrevious = fs16.existsSync(outDir);
|
|
11363
12144
|
if (hadPrevious) beforeSwap?.();
|
|
11364
12145
|
let movedAside = false;
|
|
11365
12146
|
if (hadPrevious) {
|
|
11366
12147
|
try {
|
|
11367
|
-
|
|
12148
|
+
fs16.renameSync(outDir, backupDir);
|
|
11368
12149
|
movedAside = true;
|
|
11369
12150
|
} catch (err) {
|
|
11370
12151
|
if (!isLockError(err)) throw err;
|
|
11371
|
-
|
|
12152
|
+
fs16.rmSync(outDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
11372
12153
|
process.stderr.write(
|
|
11373
12154
|
`\u26A0 ${outDir} could not be moved aside (${err.message}), so it was replaced in place. Close anything holding the old snapshot open to avoid this next time.
|
|
11374
12155
|
`
|
|
@@ -11377,26 +12158,26 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
|
|
|
11377
12158
|
}
|
|
11378
12159
|
try {
|
|
11379
12160
|
try {
|
|
11380
|
-
|
|
12161
|
+
fs16.renameSync(stagingDir, outDir);
|
|
11381
12162
|
} catch (err) {
|
|
11382
12163
|
if (err.code !== "EXDEV") throw err;
|
|
11383
12164
|
const partialDir = `${outDir}.partial-${process.pid}-${Date.now()}`;
|
|
11384
12165
|
try {
|
|
11385
|
-
|
|
11386
|
-
|
|
11387
|
-
|
|
12166
|
+
fs16.cpSync(stagingDir, partialDir, { recursive: true });
|
|
12167
|
+
fs16.renameSync(partialDir, outDir);
|
|
12168
|
+
fs16.rmSync(stagingDir, { recursive: true, force: true });
|
|
11388
12169
|
} catch (copyErr) {
|
|
11389
12170
|
try {
|
|
11390
|
-
|
|
12171
|
+
fs16.rmSync(partialDir, { recursive: true, force: true });
|
|
11391
12172
|
} catch {
|
|
11392
12173
|
}
|
|
11393
12174
|
throw copyErr;
|
|
11394
12175
|
}
|
|
11395
12176
|
}
|
|
11396
12177
|
} catch (err) {
|
|
11397
|
-
if (hadPrevious && movedAside &&
|
|
11398
|
-
if (
|
|
11399
|
-
|
|
12178
|
+
if (hadPrevious && movedAside && fs16.existsSync(backupDir)) {
|
|
12179
|
+
if (fs16.existsSync(outDir)) fs16.rmSync(outDir, { recursive: true, force: true });
|
|
12180
|
+
fs16.renameSync(backupDir, outDir);
|
|
11400
12181
|
} else if (hadPrevious && !movedAside) {
|
|
11401
12182
|
process.stderr.write(
|
|
11402
12183
|
`\u26A0 The previous snapshot at ${outDir} was removed and the new one could not be moved into place. It is complete at ${stagingDir}.
|
|
@@ -11407,7 +12188,7 @@ function swapOnce(stagingDir, outDir, beforeSwap) {
|
|
|
11407
12188
|
}
|
|
11408
12189
|
if (hadPrevious) {
|
|
11409
12190
|
try {
|
|
11410
|
-
|
|
12191
|
+
fs16.rmSync(backupDir, { recursive: true, force: true });
|
|
11411
12192
|
} catch (err) {
|
|
11412
12193
|
process.stderr.write(
|
|
11413
12194
|
`\u26A0 The previous snapshot could not be removed from ${backupDir} (${err.message}). The new snapshot is in place; delete that directory by hand when convenient.
|
|
@@ -11466,7 +12247,55 @@ function runAfterGenerate(config, manifest) {
|
|
|
11466
12247
|
return Promise.resolve(returned).finally(releaseRedirect);
|
|
11467
12248
|
}
|
|
11468
12249
|
function partitionByBudget(files, config, fingerprint) {
|
|
11469
|
-
const
|
|
12250
|
+
const configured = {
|
|
12251
|
+
parts: partitionWithBudgets(files, config.budgets, fingerprint),
|
|
12252
|
+
budgets: config.budgets,
|
|
12253
|
+
maxPartBytes: config.maxPartBytes,
|
|
12254
|
+
warnings: []
|
|
12255
|
+
};
|
|
12256
|
+
const limit = config.maxParts;
|
|
12257
|
+
if (limit === null || !config.artifacts.parts || configured.parts.length <= limit) return configured;
|
|
12258
|
+
const totalBytes = files.reduce((total, file) => total + file.includedBytes, 0);
|
|
12259
|
+
let target = Math.max(config.budgets.default, Math.ceil(totalBytes * 1.15 / limit));
|
|
12260
|
+
const seen = [];
|
|
12261
|
+
let low = config.budgets.default;
|
|
12262
|
+
let fitting = null;
|
|
12263
|
+
for (let pass = 0; pass < 6; pass += 1) {
|
|
12264
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, target), fingerprint);
|
|
12265
|
+
if (parts2.length <= limit) {
|
|
12266
|
+
fitting = { target, parts: parts2 };
|
|
12267
|
+
break;
|
|
12268
|
+
}
|
|
12269
|
+
seen.push(parts2.length);
|
|
12270
|
+
low = target;
|
|
12271
|
+
target = Math.ceil(target * 1.3);
|
|
12272
|
+
}
|
|
12273
|
+
if (fitting === null) {
|
|
12274
|
+
throw new Error(
|
|
12275
|
+
`maxParts ${limit} could not be met: ${seen.join(", ")} part(s) at budgets up to ${formatNumber(target)} B. Raise maxParts, include fewer files, or drop the setting.`
|
|
12276
|
+
);
|
|
12277
|
+
}
|
|
12278
|
+
for (let step = 0; step < 3 && fitting.target - low > 8192; step += 1) {
|
|
12279
|
+
const middle = Math.round((low + fitting.target) / 2);
|
|
12280
|
+
const parts2 = partitionWithBudgets(files, scaleBudgets(config.budgets, middle), fingerprint);
|
|
12281
|
+
if (parts2.length <= limit) fitting = { target: middle, parts: parts2 };
|
|
12282
|
+
else low = middle;
|
|
12283
|
+
}
|
|
12284
|
+
const { target: chosen, parts } = fitting;
|
|
12285
|
+
const budgets = scaleBudgets(config.budgets, chosen);
|
|
12286
|
+
const maxPartBytes = Math.max(config.maxPartBytes, chosen);
|
|
12287
|
+
const warnings = [
|
|
12288
|
+
`maxParts ${limit}: the part budget grew from ${formatNumber(config.maxPartBytes)} B to ${formatNumber(maxPartBytes)} B, and the snapshot now has ${formatNumber(parts.length)} part(s).`
|
|
12289
|
+
];
|
|
12290
|
+
if (maxPartBytes > config.maxPartBytes) {
|
|
12291
|
+
warnings.push(
|
|
12292
|
+
`maxParts ${limit}: parts are now above the configured maxPartBytes (${formatNumber(config.maxPartBytes)} B). A larger part is more tokens for the destination to take at once, and some destinations cap a single file.`
|
|
12293
|
+
);
|
|
12294
|
+
}
|
|
12295
|
+
return { parts, budgets, maxPartBytes, warnings };
|
|
12296
|
+
}
|
|
12297
|
+
function partitionWithBudgets(files, budgets, fingerprint) {
|
|
12298
|
+
const budgetFor = (file) => budgets.byLayer[file.layer] ?? budgets.default;
|
|
11470
12299
|
const buckets = /* @__PURE__ */ new Map();
|
|
11471
12300
|
for (const file of files) {
|
|
11472
12301
|
const budget = budgetFor(file);
|
|
@@ -11483,6 +12312,18 @@ function partitionByBudget(files, config, fingerprint) {
|
|
|
11483
12312
|
fingerprint
|
|
11484
12313
|
);
|
|
11485
12314
|
}
|
|
12315
|
+
function scaleBudgets(budgets, targetDefault) {
|
|
12316
|
+
const factor = targetDefault / budgets.default;
|
|
12317
|
+
return {
|
|
12318
|
+
default: Math.max(budgets.default, Math.round(targetDefault)),
|
|
12319
|
+
byLayer: Object.fromEntries(
|
|
12320
|
+
Object.entries(budgets.byLayer).map(([name, bytes]) => [
|
|
12321
|
+
name,
|
|
12322
|
+
Math.max(bytes, Math.round(bytes * factor))
|
|
12323
|
+
])
|
|
12324
|
+
)
|
|
12325
|
+
};
|
|
12326
|
+
}
|
|
11486
12327
|
function generateSnapshot(configInput, options) {
|
|
11487
12328
|
assertUsableConfigInput(configInput);
|
|
11488
12329
|
const config = isResolvedConfig(configInput) ? normalizeResolvedConfig(configInput) : resolveConfig(configInput ?? null);
|
|
@@ -11505,7 +12346,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11505
12346
|
// first run cannot have marked them yet, so the name alone keeps a run from recording its own
|
|
11506
12347
|
// output — but only at these exact paths, not at every directory that shares the name.
|
|
11507
12348
|
toolOwnedPaths: [config.outDir, config.tmpDir].map(
|
|
11508
|
-
(directory) =>
|
|
12349
|
+
(directory) => path17.relative(config.cwd, path17.resolve(config.cwd, directory)).replace(/\\/g, "/")
|
|
11509
12350
|
).filter((relative15) => relative15.length > 0 && !relative15.startsWith("..")),
|
|
11510
12351
|
// A staged path can be absent from the working tree while its index blob exists. Discovery
|
|
11511
12352
|
// lists the working tree, so those paths would never reach the scan at all.
|
|
@@ -11534,7 +12375,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11534
12375
|
let totalSizeBytes = 0;
|
|
11535
12376
|
let largeFileCount = 0;
|
|
11536
12377
|
for (const relativePath of candidateFiles) {
|
|
11537
|
-
const absolutePath =
|
|
12378
|
+
const absolutePath = path17.join(config.cwd, relativePath);
|
|
11538
12379
|
const fromIndex = stagedPaths.has(relativePath);
|
|
11539
12380
|
let buffer;
|
|
11540
12381
|
let sizeBytes;
|
|
@@ -11565,9 +12406,9 @@ function generateSnapshot(configInput, options) {
|
|
|
11565
12406
|
} else {
|
|
11566
12407
|
let stats;
|
|
11567
12408
|
try {
|
|
11568
|
-
stats =
|
|
12409
|
+
stats = fs16.statSync(absolutePath);
|
|
11569
12410
|
if (!stats.isFile()) {
|
|
11570
|
-
const nestedRepository = stats.isDirectory() &&
|
|
12411
|
+
const nestedRepository = stats.isDirectory() && fs16.existsSync(path17.join(absolutePath, ".git"));
|
|
11571
12412
|
skipped.push(
|
|
11572
12413
|
nestedRepository ? {
|
|
11573
12414
|
path: relativePath,
|
|
@@ -11603,7 +12444,7 @@ function generateSnapshot(configInput, options) {
|
|
|
11603
12444
|
continue;
|
|
11604
12445
|
}
|
|
11605
12446
|
try {
|
|
11606
|
-
buffer =
|
|
12447
|
+
buffer = fs16.readFileSync(absolutePath);
|
|
11607
12448
|
} catch (err) {
|
|
11608
12449
|
const code = err.code;
|
|
11609
12450
|
skipped.push({
|
|
@@ -11732,14 +12573,14 @@ function generateSnapshot(configInput, options) {
|
|
|
11732
12573
|
(finding) => finding.path === void 0 || keep.has(finding.path)
|
|
11733
12574
|
);
|
|
11734
12575
|
retain(encodingNotes, (note) => keep.has(note.path));
|
|
11735
|
-
retain(oversizeSummaryPaths, (
|
|
11736
|
-
retain(previewSummaryPaths, (
|
|
12576
|
+
retain(oversizeSummaryPaths, (path23) => keep.has(path23));
|
|
12577
|
+
retain(previewSummaryPaths, (path23) => keep.has(path23));
|
|
11737
12578
|
retain(fileWarnings, (warning) => keep.has(warning.path));
|
|
11738
|
-
for (const
|
|
11739
|
-
if (!keep.has(
|
|
12579
|
+
for (const path23 of [...monolithBodies.keys()]) {
|
|
12580
|
+
if (!keep.has(path23)) monolithBodies.delete(path23);
|
|
11740
12581
|
}
|
|
11741
|
-
for (const
|
|
11742
|
-
if (!keep.has(
|
|
12582
|
+
for (const path23 of [...skippedSummaryImports.keys()]) {
|
|
12583
|
+
if (!keep.has(path23)) skippedSummaryImports.delete(path23);
|
|
11743
12584
|
}
|
|
11744
12585
|
}
|
|
11745
12586
|
if (changedScope !== null) {
|
|
@@ -11811,7 +12652,8 @@ function generateSnapshot(configInput, options) {
|
|
|
11811
12652
|
);
|
|
11812
12653
|
}
|
|
11813
12654
|
}
|
|
11814
|
-
const
|
|
12655
|
+
const partitioned = partitionByBudget(files, config, fingerprint);
|
|
12656
|
+
const parts = partitioned.parts;
|
|
11815
12657
|
const truncatedPreviewCount = files.filter((file) => file.isPreviewTruncated).length;
|
|
11816
12658
|
const incomplete = files.flatMap((file) => {
|
|
11817
12659
|
if (file.truncationReason === void 0) return [];
|
|
@@ -11848,7 +12690,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11848
12690
|
// the README and the audit report.
|
|
11849
12691
|
git: { ...gitInfo, branch: maskPathText(gitInfo.branch, config.secretRules) },
|
|
11850
12692
|
budgets: {
|
|
11851
|
-
|
|
12693
|
+
// The ceiling the parts actually honour. It equals the configured one unless `maxParts`
|
|
12694
|
+
// grew it; `config.maxPartBytes` below keeps the configured value, because that is what
|
|
12695
|
+
// `validate` compares against the config on disk.
|
|
12696
|
+
maxPartBytes: partitioned.maxPartBytes,
|
|
11852
12697
|
largeFileBytes: config.largeFileBytes
|
|
11853
12698
|
},
|
|
11854
12699
|
config: {
|
|
@@ -11866,6 +12711,16 @@ function generateSnapshot(configInput, options) {
|
|
|
11866
12711
|
// invisible in the manifest that is supposed to describe the run.
|
|
11867
12712
|
maxMonolithBytes: config.maxMonolithBytes ?? null,
|
|
11868
12713
|
includeSensitiveFiles: config.includeSensitiveFiles,
|
|
12714
|
+
// The destination the instructions were written for. Not part of `digest`: the payload is
|
|
12715
|
+
// identical whatever this says, and a new delivery preference must not make an existing
|
|
12716
|
+
// snapshot fail `validate` as configuration drift.
|
|
12717
|
+
attachmentSlots: config.attachmentSlots,
|
|
12718
|
+
// The part-count ceiling the run enforced. Recorded because it decided the part sizes, and
|
|
12719
|
+
// omitted from `digest` when it is off so an existing snapshot does not start reporting
|
|
12720
|
+
// configuration drift.
|
|
12721
|
+
maxParts: config.maxParts ?? null,
|
|
12722
|
+
promptTask: config.promptTask,
|
|
12723
|
+
...config.brief === void 0 ? {} : { brief: { path: config.brief.path, digest: config.brief.digest } },
|
|
11869
12724
|
discovery: config.discovery ?? "auto",
|
|
11870
12725
|
// A changed-files scope decides which files are in the snapshot, so the manifest that
|
|
11871
12726
|
// describes the run has to name it.
|
|
@@ -11936,6 +12791,10 @@ function generateSnapshot(configInput, options) {
|
|
|
11936
12791
|
incomplete,
|
|
11937
12792
|
warnings
|
|
11938
12793
|
};
|
|
12794
|
+
if (partitioned.warnings.length > 0) {
|
|
12795
|
+
manifest.warnings.push(...partitioned.warnings);
|
|
12796
|
+
manifest.totals.warningCount = manifest.warnings.length;
|
|
12797
|
+
}
|
|
11939
12798
|
manifest.totals.redactedLines = secretFindings.length;
|
|
11940
12799
|
manifest.totals.warningCount = manifest.warnings.length;
|
|
11941
12800
|
if (files.some((file) => file.isPreviewTruncated) && config.largeFileBytes < config.maxPartBytes) {
|
|
@@ -11992,6 +12851,17 @@ function generateSnapshot(configInput, options) {
|
|
|
11992
12851
|
if (auditText !== null) manifest.artifacts.audit = artifactRecord(auditText);
|
|
11993
12852
|
const readmeText = artifacts.readme ? generateReadme(manifest, artifacts) : null;
|
|
11994
12853
|
if (readmeText !== null) manifest.artifacts.readme = artifactRecord(readmeText);
|
|
12854
|
+
const promptText = artifacts.prompt ? generatePrompt(manifest, artifacts, {
|
|
12855
|
+
slots: config.attachmentSlots,
|
|
12856
|
+
task: config.promptTask,
|
|
12857
|
+
brief: maskOwnerBrief(config.brief, config.secretRules),
|
|
12858
|
+
history: recentCommits(config.cwd).map((commit) => ({
|
|
12859
|
+
subject: maskPathText(commit.subject, config.secretRules),
|
|
12860
|
+
body: maskPathText(commit.body, config.secretRules)
|
|
12861
|
+
})),
|
|
12862
|
+
overview: maskOverview(readProjectOverview(config.cwd), config.secretRules)
|
|
12863
|
+
}) : null;
|
|
12864
|
+
if (promptText !== null) manifest.artifacts.prompt = artifactRecord(promptText);
|
|
11995
12865
|
if (projectTree !== null) manifest.artifacts.projectTree = artifactRecord(projectTree);
|
|
11996
12866
|
let monolithJson = null;
|
|
11997
12867
|
let monolithMarkdown = null;
|
|
@@ -12066,12 +12936,12 @@ function generateSnapshot(configInput, options) {
|
|
|
12066
12936
|
let releaseDeferred = false;
|
|
12067
12937
|
try {
|
|
12068
12938
|
ensureParentDirectory(outDir, "outDir");
|
|
12069
|
-
|
|
12939
|
+
fs16.mkdirSync(tmpDir, { recursive: true });
|
|
12070
12940
|
cleanStaleRunDirs(tmpDir);
|
|
12071
12941
|
const snapshotId = crypto4.randomUUID();
|
|
12072
12942
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
12073
|
-
stagingDir =
|
|
12074
|
-
|
|
12943
|
+
stagingDir = path17.join(tmpDir, `${RUN_DIR_PREFIX}${process.pid}-${snapshotId.slice(0, 8)}`);
|
|
12944
|
+
fs16.mkdirSync(stagingDir);
|
|
12075
12945
|
writeOwnershipMarker(stagingDir, {
|
|
12076
12946
|
generator: GENERATOR_NAME,
|
|
12077
12947
|
version: GENERATOR_VERSION,
|
|
@@ -12081,30 +12951,30 @@ function generateSnapshot(configInput, options) {
|
|
|
12081
12951
|
id: snapshotId,
|
|
12082
12952
|
pid: process.pid
|
|
12083
12953
|
});
|
|
12084
|
-
const partsDir =
|
|
12085
|
-
const reportsDir =
|
|
12086
|
-
if (artifacts.parts)
|
|
12954
|
+
const partsDir = path17.join(stagingDir, "parts");
|
|
12955
|
+
const reportsDir = path17.join(stagingDir, "reports");
|
|
12956
|
+
if (artifacts.parts) fs16.mkdirSync(partsDir, { recursive: true });
|
|
12087
12957
|
if (artifacts.navigation || artifacts.projectTree || artifacts.audit || config.sarif === true) {
|
|
12088
|
-
|
|
12958
|
+
fs16.mkdirSync(reportsDir, { recursive: true });
|
|
12089
12959
|
}
|
|
12090
12960
|
const writtenArtifacts = /* @__PURE__ */ new Map();
|
|
12091
12961
|
const writeArtifact = (targetDir, relativeEntry, data) => {
|
|
12092
|
-
const full =
|
|
12093
|
-
|
|
12094
|
-
const stats =
|
|
12962
|
+
const full = path17.join(targetDir, ...relativeEntry.split("/"));
|
|
12963
|
+
fs16.writeFileSync(full, data, "utf8");
|
|
12964
|
+
const stats = fs16.statSync(full);
|
|
12095
12965
|
writtenArtifacts.set(relativeEntry, {
|
|
12096
12966
|
digest: { path: relativeEntry, bytes: stats.size, sha256: sha256Hex2(data) },
|
|
12097
12967
|
mtimeMs: stats.mtimeMs
|
|
12098
12968
|
});
|
|
12099
12969
|
};
|
|
12100
12970
|
const recordArtifact = (targetDir, relativeEntry) => {
|
|
12101
|
-
const full =
|
|
12102
|
-
const stats =
|
|
12971
|
+
const full = path17.join(targetDir, ...relativeEntry.split("/"));
|
|
12972
|
+
const stats = fs16.statSync(full);
|
|
12103
12973
|
writtenArtifacts.set(relativeEntry, {
|
|
12104
12974
|
digest: {
|
|
12105
12975
|
path: relativeEntry,
|
|
12106
12976
|
bytes: stats.size,
|
|
12107
|
-
sha256: sha256Hex2(
|
|
12977
|
+
sha256: sha256Hex2(fs16.readFileSync(full))
|
|
12108
12978
|
},
|
|
12109
12979
|
mtimeMs: stats.mtimeMs
|
|
12110
12980
|
});
|
|
@@ -12129,6 +12999,9 @@ function generateSnapshot(configInput, options) {
|
|
|
12129
12999
|
if (readmeText !== null) {
|
|
12130
13000
|
writeArtifact(stagingDir, "README.md", readmeText);
|
|
12131
13001
|
}
|
|
13002
|
+
if (promptText !== null) {
|
|
13003
|
+
writeArtifact(stagingDir, "PROMPT.md", promptText);
|
|
13004
|
+
}
|
|
12132
13005
|
if (artifacts.manifest) {
|
|
12133
13006
|
writeArtifact(stagingDir, "manifest.json", JSON.stringify(manifest, null, 2));
|
|
12134
13007
|
}
|
|
@@ -12149,7 +13022,7 @@ function generateSnapshot(configInput, options) {
|
|
|
12149
13022
|
const shipHookState = () => {
|
|
12150
13023
|
if (!markerBelongsTo(outDir, snapshotId)) return;
|
|
12151
13024
|
if (artifacts.manifest && manifest.warnings.length !== warningsBeforeHook) {
|
|
12152
|
-
writeManifestAtomically(
|
|
13025
|
+
writeManifestAtomically(path17.join(outDir, "manifest.json"), manifest);
|
|
12153
13026
|
recordArtifact(outDir, "manifest.json");
|
|
12154
13027
|
}
|
|
12155
13028
|
writeOwnershipMarker(
|
|
@@ -12192,7 +13065,7 @@ function generateSnapshot(configInput, options) {
|
|
|
12192
13065
|
} catch (err) {
|
|
12193
13066
|
if (stagingDir !== null) {
|
|
12194
13067
|
try {
|
|
12195
|
-
|
|
13068
|
+
fs16.rmSync(stagingDir, { recursive: true, force: true });
|
|
12196
13069
|
} catch {
|
|
12197
13070
|
}
|
|
12198
13071
|
}
|
|
@@ -12207,8 +13080,8 @@ function generateSnapshot(configInput, options) {
|
|
|
12207
13080
|
var pendingHooks = /* @__PURE__ */ new Map();
|
|
12208
13081
|
|
|
12209
13082
|
// src/mcp/tools.ts
|
|
12210
|
-
import * as
|
|
12211
|
-
import * as
|
|
13083
|
+
import * as fs18 from "fs";
|
|
13084
|
+
import * as path19 from "path";
|
|
12212
13085
|
|
|
12213
13086
|
// src/mcp/part.ts
|
|
12214
13087
|
var FILE_HEADING = "### FILE: ";
|
|
@@ -12290,8 +13163,8 @@ function findSection(sections, relativePath) {
|
|
|
12290
13163
|
if (exact) return exact;
|
|
12291
13164
|
const foldedPath = rendered.toLowerCase();
|
|
12292
13165
|
const folded = sections.filter((section) => {
|
|
12293
|
-
const
|
|
12294
|
-
return
|
|
13166
|
+
const path23 = section.path.toLowerCase();
|
|
13167
|
+
return path23 === relativePath.toLowerCase() || path23 === foldedPath;
|
|
12295
13168
|
});
|
|
12296
13169
|
return folded.length === 1 ? folded[0] : null;
|
|
12297
13170
|
}
|
|
@@ -12315,15 +13188,15 @@ function windowText(body, fromLine, lineCount) {
|
|
|
12315
13188
|
}
|
|
12316
13189
|
|
|
12317
13190
|
// src/mcp/workspace.ts
|
|
12318
|
-
import * as
|
|
12319
|
-
import * as
|
|
13191
|
+
import * as fs17 from "fs";
|
|
13192
|
+
import * as path18 from "path";
|
|
12320
13193
|
function foldForComparison(value) {
|
|
12321
13194
|
return process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
|
|
12322
13195
|
}
|
|
12323
13196
|
function canonicalPath(value) {
|
|
12324
|
-
const absolute =
|
|
13197
|
+
const absolute = path18.resolve(value);
|
|
12325
13198
|
try {
|
|
12326
|
-
return
|
|
13199
|
+
return fs17.realpathSync(absolute);
|
|
12327
13200
|
} catch {
|
|
12328
13201
|
return absolute;
|
|
12329
13202
|
}
|
|
@@ -12331,29 +13204,29 @@ function canonicalPath(value) {
|
|
|
12331
13204
|
function isInside3(parent, child) {
|
|
12332
13205
|
const foldedParent = foldForComparison(parent);
|
|
12333
13206
|
const foldedChild = foldForComparison(child);
|
|
12334
|
-
return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${
|
|
13207
|
+
return foldedChild === foldedParent || foldedChild.startsWith(`${foldedParent}${path18.sep}`);
|
|
12335
13208
|
}
|
|
12336
13209
|
function resolveThroughExistingAncestor(target) {
|
|
12337
13210
|
let existing = target;
|
|
12338
13211
|
const missing = [];
|
|
12339
|
-
while (!
|
|
12340
|
-
missing.unshift(
|
|
12341
|
-
const parent =
|
|
13212
|
+
while (!fs17.existsSync(existing)) {
|
|
13213
|
+
missing.unshift(path18.basename(existing));
|
|
13214
|
+
const parent = path18.dirname(existing);
|
|
12342
13215
|
if (parent === existing) break;
|
|
12343
13216
|
existing = parent;
|
|
12344
13217
|
}
|
|
12345
13218
|
const resolved = canonicalPath(existing);
|
|
12346
|
-
return missing.length === 0 ? resolved :
|
|
13219
|
+
return missing.length === 0 ? resolved : path18.join(resolved, ...missing);
|
|
12347
13220
|
}
|
|
12348
13221
|
function resolveRoot(requested, context) {
|
|
12349
13222
|
if (requested !== void 0 && (typeof requested !== "string" || requested.trim().length === 0)) {
|
|
12350
13223
|
return { ok: false, message: '"root" must be a non-empty string when provided.' };
|
|
12351
13224
|
}
|
|
12352
13225
|
const wanted = typeof requested === "string" ? requested.trim() : context.cwd;
|
|
12353
|
-
const absolute =
|
|
13226
|
+
const absolute = path18.resolve(context.cwd, wanted);
|
|
12354
13227
|
let stats;
|
|
12355
13228
|
try {
|
|
12356
|
-
stats =
|
|
13229
|
+
stats = fs17.statSync(absolute);
|
|
12357
13230
|
} catch {
|
|
12358
13231
|
return { ok: false, message: `"${wanted}" does not exist, so it cannot be a repository root.` };
|
|
12359
13232
|
}
|
|
@@ -12405,7 +13278,7 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
12405
13278
|
}
|
|
12406
13279
|
const requested = overrides.outDir.trim();
|
|
12407
13280
|
const permitted = allowedRoots !== void 0 && allowedRoots.length > 0 ? allowedRoots : [root];
|
|
12408
|
-
const resolved = resolveThroughExistingAncestor(
|
|
13281
|
+
const resolved = resolveThroughExistingAncestor(path18.resolve(root, requested));
|
|
12409
13282
|
if (!permitted.some((allowed) => isInside3(canonicalPath(allowed), resolved))) {
|
|
12410
13283
|
const shown = permitted.map((allowed) => canonicalPath(allowed)).join(", ");
|
|
12411
13284
|
return {
|
|
@@ -12438,25 +13311,25 @@ async function openWorkspace(root, overrides = {}, allowedRoots, options = {}) {
|
|
|
12438
13311
|
var MANIFEST_CACHE_LIMIT = 8;
|
|
12439
13312
|
var manifestCache = /* @__PURE__ */ new Map();
|
|
12440
13313
|
function manifestPathFor(workspace) {
|
|
12441
|
-
return
|
|
13314
|
+
return path18.resolve(workspace.root, workspace.config.outDir, "manifest.json");
|
|
12442
13315
|
}
|
|
12443
13316
|
function partPathFor(workspace, filename) {
|
|
12444
13317
|
if (filename.length === 0 || filename.includes("\0")) return null;
|
|
12445
|
-
const partsDir =
|
|
12446
|
-
const resolved =
|
|
12447
|
-
const relative15 =
|
|
12448
|
-
if (relative15.length === 0 || relative15.includes(
|
|
13318
|
+
const partsDir = path18.resolve(workspace.root, workspace.config.outDir, "parts");
|
|
13319
|
+
const resolved = path18.resolve(partsDir, filename);
|
|
13320
|
+
const relative15 = path18.relative(partsDir, resolved);
|
|
13321
|
+
if (relative15.length === 0 || relative15.includes(path18.sep) || relative15.includes("/") || relative15.includes("\\") || path18.isAbsolute(relative15)) {
|
|
12449
13322
|
return null;
|
|
12450
13323
|
}
|
|
12451
13324
|
let stats;
|
|
12452
13325
|
try {
|
|
12453
|
-
stats =
|
|
13326
|
+
stats = fs17.lstatSync(resolved);
|
|
12454
13327
|
} catch {
|
|
12455
13328
|
return null;
|
|
12456
13329
|
}
|
|
12457
13330
|
if (!stats.isFile()) return null;
|
|
12458
13331
|
try {
|
|
12459
|
-
if (
|
|
13332
|
+
if (path18.dirname(fs17.realpathSync(resolved)) !== fs17.realpathSync(partsDir)) return null;
|
|
12460
13333
|
} catch {
|
|
12461
13334
|
return null;
|
|
12462
13335
|
}
|
|
@@ -12464,10 +13337,10 @@ function partPathFor(workspace, filename) {
|
|
|
12464
13337
|
}
|
|
12465
13338
|
function readManifest3(workspace) {
|
|
12466
13339
|
const file = manifestPathFor(workspace);
|
|
12467
|
-
const shown =
|
|
13340
|
+
const shown = path18.relative(workspace.root, file).split(path18.sep).join("/") || file;
|
|
12468
13341
|
let stats;
|
|
12469
13342
|
try {
|
|
12470
|
-
stats =
|
|
13343
|
+
stats = fs17.statSync(file);
|
|
12471
13344
|
} catch {
|
|
12472
13345
|
return {
|
|
12473
13346
|
ok: false,
|
|
@@ -12481,7 +13354,7 @@ function readManifest3(workspace) {
|
|
|
12481
13354
|
}
|
|
12482
13355
|
let raw;
|
|
12483
13356
|
try {
|
|
12484
|
-
raw =
|
|
13357
|
+
raw = fs17.readFileSync(file, "utf8");
|
|
12485
13358
|
} catch (error) {
|
|
12486
13359
|
return {
|
|
12487
13360
|
ok: false,
|
|
@@ -12593,7 +13466,7 @@ function formatBytes(bytes) {
|
|
|
12593
13466
|
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
12594
13467
|
}
|
|
12595
13468
|
function relativeFor(workspace, absolute) {
|
|
12596
|
-
return
|
|
13469
|
+
return path19.relative(workspace.root, absolute).split(path19.sep).join("/");
|
|
12597
13470
|
}
|
|
12598
13471
|
function capped(values, limit = 20) {
|
|
12599
13472
|
return { count: values.length, sample: values.slice(0, limit) };
|
|
@@ -12612,13 +13485,13 @@ function summarizeDrift(drift) {
|
|
|
12612
13485
|
function toRelativePath(root, value) {
|
|
12613
13486
|
const cleaned = value.trim();
|
|
12614
13487
|
if (cleaned.length === 0 || cleaned.includes("\0")) return null;
|
|
12615
|
-
const resolvedRoot =
|
|
12616
|
-
const absolute =
|
|
12617
|
-
const relative15 =
|
|
12618
|
-
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${
|
|
13488
|
+
const resolvedRoot = path19.resolve(root);
|
|
13489
|
+
const absolute = path19.resolve(resolvedRoot, cleaned);
|
|
13490
|
+
const relative15 = path19.relative(resolvedRoot, absolute);
|
|
13491
|
+
if (relative15 === "" || relative15 === ".." || relative15.startsWith(`..${path19.sep}`) || path19.isAbsolute(relative15)) {
|
|
12619
13492
|
return null;
|
|
12620
13493
|
}
|
|
12621
|
-
return relative15.split(
|
|
13494
|
+
return relative15.split(path19.sep).join("/");
|
|
12622
13495
|
}
|
|
12623
13496
|
function symbolsOf(entry) {
|
|
12624
13497
|
const summary = entry.summary;
|
|
@@ -12848,7 +13721,7 @@ var generateTool = {
|
|
|
12848
13721
|
if (!result.ok) return failure(result.message);
|
|
12849
13722
|
const summary = result.summary;
|
|
12850
13723
|
forgetManifest(manifestPathFor(workspace));
|
|
12851
|
-
const written = relativeFor(workspace,
|
|
13724
|
+
const written = relativeFor(workspace, path19.resolve(workspace.root, workspace.config.outDir));
|
|
12852
13725
|
const lines = [
|
|
12853
13726
|
`Wrote ${written}/`,
|
|
12854
13727
|
`Files: ${summary.totalFiles} included, ${summary.skippedCount} skipped, ${plural(summary.partsCount, "part")}`,
|
|
@@ -13249,7 +14122,7 @@ var readTool = {
|
|
|
13249
14122
|
}
|
|
13250
14123
|
let partText;
|
|
13251
14124
|
try {
|
|
13252
|
-
partText =
|
|
14125
|
+
partText = fs18.readFileSync(partPath, "utf8");
|
|
13253
14126
|
} catch {
|
|
13254
14127
|
return failure(
|
|
13255
14128
|
`${entry.part} could not be read, so the snapshot is damaged. Run snapshot_generate to rebuild it.`
|
|
@@ -13557,6 +14430,9 @@ var VALIDATE_OPTIONS = [
|
|
|
13557
14430
|
"max-part-tokens",
|
|
13558
14431
|
"large-file-bytes",
|
|
13559
14432
|
"max-monolith-bytes",
|
|
14433
|
+
"max-parts",
|
|
14434
|
+
"brief",
|
|
14435
|
+
"prompt-task",
|
|
13560
14436
|
"include-monolith",
|
|
13561
14437
|
"include-sensitive-files",
|
|
13562
14438
|
"skip-artifacts",
|
|
@@ -13582,6 +14458,10 @@ var COMMAND_OPTION_SCOPE = {
|
|
|
13582
14458
|
"max-part-tokens",
|
|
13583
14459
|
"large-file-bytes",
|
|
13584
14460
|
"max-monolith-bytes",
|
|
14461
|
+
"attachment-slots",
|
|
14462
|
+
"max-parts",
|
|
14463
|
+
"brief",
|
|
14464
|
+
"prompt-task",
|
|
13585
14465
|
"include-monolith",
|
|
13586
14466
|
"include-sensitive-files",
|
|
13587
14467
|
"skip-artifacts",
|
|
@@ -13727,6 +14607,7 @@ var PACKAGE_NAME = "codebase-snapshot";
|
|
|
13727
14607
|
var MAJOR_VERSION = GENERATOR_VERSION.split(".")[0];
|
|
13728
14608
|
var ARTIFACT_SUMMARY = {
|
|
13729
14609
|
readme: "README.md describing the snapshot at the output root.",
|
|
14610
|
+
prompt: "PROMPT.md: the instruction sheet to paste with the snapshot, rendered from its manifest.",
|
|
13730
14611
|
manifest: "manifest.json: machine-readable index of every file, part, hash and config.",
|
|
13731
14612
|
parts: "parts/*.md: the packed, budget-limited markdown parts that carry the code.",
|
|
13732
14613
|
navigation: "reports/navigation.md: links between parts and layers.",
|
|
@@ -13736,6 +14617,7 @@ var ARTIFACT_SUMMARY = {
|
|
|
13736
14617
|
};
|
|
13737
14618
|
var ARTIFACT_DEFAULTS = {
|
|
13738
14619
|
readme: true,
|
|
14620
|
+
prompt: true,
|
|
13739
14621
|
manifest: true,
|
|
13740
14622
|
parts: true,
|
|
13741
14623
|
navigation: true,
|
|
@@ -13876,9 +14758,9 @@ function buildAgentContract() {
|
|
|
13876
14758
|
{
|
|
13877
14759
|
step: 6,
|
|
13878
14760
|
id: "consume",
|
|
13879
|
-
run: "read ./snapshot/
|
|
14761
|
+
run: "read ./snapshot/PROMPT.md first, then ./snapshot/parts/*.md, ./snapshot/manifest.json and ./snapshot/reports/audit.md",
|
|
13880
14762
|
expect: "the code, the index of what was included, and the risk findings",
|
|
13881
|
-
notes: "manifest.json.files[] lists every included file with layer, kind, language, part and summary. manifest.skipped[] explains every file that was left out and why; manifest.incomplete[] lists every included file that is not present in full, with its missing line ranges."
|
|
14763
|
+
notes: "manifest.json.files[] lists every included file with layer, kind, language, part and summary. manifest.skipped[] explains every file that was left out and why; manifest.incomplete[] lists every included file that is not present in full, with its missing line ranges. PROMPT.md is the instruction sheet for whoever reads the snapshot; it is rendered from the manifest, so it names this run's omissions rather than describing snapshots in general."
|
|
13882
14764
|
}
|
|
13883
14765
|
],
|
|
13884
14766
|
commands: [
|
|
@@ -14015,6 +14897,34 @@ function buildAgentContract() {
|
|
|
14015
14897
|
appliesTo: optionAppliesTo("discovery"),
|
|
14016
14898
|
summary: "How files are discovered: auto (git when usable), git (require git), walk (read .gitignore files directly, including nested ones; the escape hatch for a .git that cannot be listed)."
|
|
14017
14899
|
},
|
|
14900
|
+
{
|
|
14901
|
+
flag: "--attachment-slots",
|
|
14902
|
+
type: "number",
|
|
14903
|
+
default: "10",
|
|
14904
|
+
appliesTo: optionAppliesTo("attachment-slots"),
|
|
14905
|
+
summary: "Files the destination accepts in one message (0 = no limit). PROMPT.md plans the delivery against it: which parts to attach, what to leave behind, and the part budget that would merge them. It does not change the payload."
|
|
14906
|
+
},
|
|
14907
|
+
{
|
|
14908
|
+
flag: "--brief",
|
|
14909
|
+
type: "string",
|
|
14910
|
+
default: "unset",
|
|
14911
|
+
appliesTo: optionAppliesTo("brief"),
|
|
14912
|
+
summary: "Path to the owner-written half of PROMPT.md: Stakes, The system, What came before, The bar and Calibration replace or extend the generated prose; any other heading is kept as Owner notes. The measured headings cannot be redefined. A missing file is an error and an edited file is config drift."
|
|
14913
|
+
},
|
|
14914
|
+
{
|
|
14915
|
+
flag: "--prompt-task",
|
|
14916
|
+
type: "string",
|
|
14917
|
+
default: "audit",
|
|
14918
|
+
appliesTo: optionAppliesTo("prompt-task"),
|
|
14919
|
+
summary: "Which job the brief is written for: audit (default), review or explain. It changes the opening section, not the standard."
|
|
14920
|
+
},
|
|
14921
|
+
{
|
|
14922
|
+
flag: "--max-parts",
|
|
14923
|
+
type: "number",
|
|
14924
|
+
default: "unset",
|
|
14925
|
+
appliesTo: optionAppliesTo("max-parts"),
|
|
14926
|
+
summary: "Experimental: grow the per-part budget until the snapshot has at most this many parts. The budget it settles on is recorded in manifest.budgets.maxPartBytes and may exceed maxPartBytes; a warning says so."
|
|
14927
|
+
},
|
|
14018
14928
|
{
|
|
14019
14929
|
flag: "--skip-artifacts",
|
|
14020
14930
|
type: "string",
|
|
@@ -14228,6 +15138,10 @@ function buildAgentContract() {
|
|
|
14228
15138
|
{ key: "includeSensitiveFiles", type: "boolean", default: false, summary: "Emit .env / *.pem / credential files." },
|
|
14229
15139
|
{ key: "include", type: "string[]", default: "[]", summary: "Allow-list of globs; empty means everything." },
|
|
14230
15140
|
{ key: "excludePatterns", type: "string[]", default: "[]", summary: "Extra exclude globs." },
|
|
15141
|
+
{ key: "brief", type: "string", default: "unset", summary: "Path to the owner-written half of PROMPT.md. Recognised headings: Stakes, The system, What came before, The bar, Calibration; unknown headings are kept as Owner notes; measured headings are refused. The file is digested, so editing it is drift." },
|
|
15142
|
+
{ key: "promptTask", type: "string", default: "audit", summary: "Which job the brief is written for: audit, review or explain. The standard and the coverage duty are the same in all three." },
|
|
15143
|
+
{ key: "maxParts", type: "number | null", default: null, summary: "Experimental: the most parts a snapshot may have. The per-part budget grows to fit, up to the run's own needs; the effective ceiling is recorded in manifest.budgets.maxPartBytes and may exceed maxPartBytes." },
|
|
15144
|
+
{ key: "attachmentSlots", type: "number", default: 10, summary: "Files the destination accepts in one message (0 = no limit); PROMPT.md plans the delivery to fit. It does not change the payload, and it is not part of the config digest." },
|
|
14231
15145
|
{ key: "discovery", type: '"auto" | "git" | "walk"', default: "auto", summary: "How files are discovered; `walk` scans the tree and reads .gitignore directly when a .git directory cannot be listed." },
|
|
14232
15146
|
{ key: "artifacts", type: "object", default: "all on except monolith", summary: "Per-artifact opt-out." },
|
|
14233
15147
|
{ key: "budgets", type: "object", default: "{ default, byLayer }", summary: "Per-layer byte budgets." },
|
|
@@ -14242,6 +15156,7 @@ function buildAgentContract() {
|
|
|
14242
15156
|
output: {
|
|
14243
15157
|
layout: [
|
|
14244
15158
|
"<outDir>/README.md",
|
|
15159
|
+
"<outDir>/PROMPT.md",
|
|
14245
15160
|
"<outDir>/manifest.json",
|
|
14246
15161
|
"<outDir>/parts/part-NNN.md",
|
|
14247
15162
|
"<outDir>/reports/project-tree.md",
|
|
@@ -14255,6 +15170,7 @@ function buildAgentContract() {
|
|
|
14255
15170
|
"indexes.imports.byFile includes previewed files (their import specifiers are still extracted); such an entry carries `exportsOmitted: true` instead of pretending it exports nothing.",
|
|
14256
15171
|
"validate re-checks manifest.incomplete[] against files[] and refuses a manifest whose two statements of what is missing disagree.",
|
|
14257
15172
|
"manifest.skipped[] carries the path and the exact reason it was excluded.",
|
|
15173
|
+
"PROMPT.md is rendered from the manifest of the run that wrote it \u2014 its parts, partial files, skip tallies and fingerprint are that run's \u2014 and manifest.artifacts.prompt records its digest, so an edited prompt fails validate.",
|
|
14258
15174
|
`The output directory is replaced atomically; ${MIN_MAX_PART_BYTES} bytes is the smallest legal budget.`
|
|
14259
15175
|
]
|
|
14260
15176
|
},
|
|
@@ -14325,8 +15241,8 @@ function buildAgentContract() {
|
|
|
14325
15241
|
}
|
|
14326
15242
|
|
|
14327
15243
|
// src/agent/install-skill.ts
|
|
14328
|
-
import * as
|
|
14329
|
-
import * as
|
|
15244
|
+
import * as fs19 from "fs";
|
|
15245
|
+
import * as path20 from "path";
|
|
14330
15246
|
|
|
14331
15247
|
// src/agent/skill.ts
|
|
14332
15248
|
var PACKAGE_NAME2 = "codebase-snapshot";
|
|
@@ -14429,6 +15345,10 @@ do not assume the repository is broken.
|
|
|
14429
15345
|
- \`snapshot/reports/audit.md\` \u2014 secrets found, large files, parse diagnostics, git
|
|
14430
15346
|
state. Read this before you quote code back to a user.
|
|
14431
15347
|
- \`snapshot/reports/project-tree.md\` and \`navigation.md\` \u2014 structure and cross-links.
|
|
15348
|
+
- \`snapshot/PROMPT.md\` \u2014 the instruction sheet to hand to the model that receives the
|
|
15349
|
+
snapshot: paste it with the parts. It is rendered from this run's manifest and names the
|
|
15350
|
+
parts, the partial files and the fingerprint, so do not rewrite it by hand \u2014 \`validate\`
|
|
15351
|
+
fails when it was edited.
|
|
14432
15352
|
|
|
14433
15353
|
## Project types
|
|
14434
15354
|
|
|
@@ -14491,17 +15411,17 @@ var LEGACY_AGENTS_MARKER = "<!-- codebase-snapshot:skill:start -->";
|
|
|
14491
15411
|
function targetPath(cwd, target) {
|
|
14492
15412
|
switch (target) {
|
|
14493
15413
|
case "claude":
|
|
14494
|
-
return
|
|
15414
|
+
return path20.join(cwd, ".claude", "skills", SKILL_NAME, "SKILL.md");
|
|
14495
15415
|
case "cursor":
|
|
14496
|
-
return
|
|
15416
|
+
return path20.join(cwd, ".cursor", "rules", `${SKILL_NAME}.mdc`);
|
|
14497
15417
|
}
|
|
14498
15418
|
}
|
|
14499
15419
|
function assertWritableInsideRepository(cwd, filePath) {
|
|
14500
|
-
const root =
|
|
14501
|
-
const shown =
|
|
15420
|
+
const root = fs19.realpathSync(cwd);
|
|
15421
|
+
const shown = path20.relative(root, filePath) || filePath;
|
|
14502
15422
|
let stat = null;
|
|
14503
15423
|
try {
|
|
14504
|
-
stat =
|
|
15424
|
+
stat = fs19.lstatSync(filePath);
|
|
14505
15425
|
} catch {
|
|
14506
15426
|
stat = null;
|
|
14507
15427
|
}
|
|
@@ -14517,32 +15437,32 @@ function assertWritableInsideRepository(cwd, filePath) {
|
|
|
14517
15437
|
}
|
|
14518
15438
|
let existing = filePath;
|
|
14519
15439
|
const missing = [];
|
|
14520
|
-
while (!
|
|
14521
|
-
missing.unshift(
|
|
14522
|
-
const parent =
|
|
15440
|
+
while (!fs19.existsSync(existing)) {
|
|
15441
|
+
missing.unshift(path20.basename(existing));
|
|
15442
|
+
const parent = path20.dirname(existing);
|
|
14523
15443
|
if (parent === existing) break;
|
|
14524
15444
|
existing = parent;
|
|
14525
15445
|
}
|
|
14526
|
-
const realAncestor =
|
|
14527
|
-
const resolved = missing.length === 0 ? realAncestor :
|
|
14528
|
-
if (resolved !== root && !resolved.startsWith(`${root}${
|
|
15446
|
+
const realAncestor = fs19.realpathSync(existing);
|
|
15447
|
+
const resolved = missing.length === 0 ? realAncestor : path20.join(realAncestor, ...missing);
|
|
15448
|
+
if (resolved !== root && !resolved.startsWith(`${root}${path20.sep}`)) {
|
|
14529
15449
|
throw new Error(
|
|
14530
15450
|
`${REFUSED}: ${shown} resolves outside the repository (${resolved}). Move it back inside ${root}, or remove the link, and run again.`
|
|
14531
15451
|
);
|
|
14532
15452
|
}
|
|
14533
15453
|
}
|
|
14534
15454
|
function writeIfChanged(target, filePath, content) {
|
|
14535
|
-
const existing =
|
|
15455
|
+
const existing = fs19.existsSync(filePath) ? fs19.readFileSync(filePath, "utf8") : null;
|
|
14536
15456
|
if (existing === content) return { target, path: filePath, action: "unchanged" };
|
|
14537
|
-
|
|
14538
|
-
|
|
15457
|
+
fs19.mkdirSync(path20.dirname(filePath), { recursive: true });
|
|
15458
|
+
fs19.writeFileSync(filePath, content, "utf8");
|
|
14539
15459
|
return { target, path: filePath, action: existing === null ? "created" : "updated" };
|
|
14540
15460
|
}
|
|
14541
15461
|
function legacyAgentsNote(cwd) {
|
|
14542
|
-
const filePath =
|
|
15462
|
+
const filePath = path20.join(cwd, "AGENTS.md");
|
|
14543
15463
|
try {
|
|
14544
|
-
if (!
|
|
14545
|
-
if (!
|
|
15464
|
+
if (!fs19.existsSync(filePath)) return null;
|
|
15465
|
+
if (!fs19.readFileSync(filePath, "utf8").includes(LEGACY_AGENTS_MARKER)) return null;
|
|
14546
15466
|
} catch {
|
|
14547
15467
|
return null;
|
|
14548
15468
|
}
|
|
@@ -14554,9 +15474,9 @@ function installSkill(cwd, target = "all") {
|
|
|
14554
15474
|
const notes = [];
|
|
14555
15475
|
const wanted = target === "all" ? ["claude", "cursor"] : [target];
|
|
14556
15476
|
for (const item of wanted) assertWritableInsideRepository(cwd, targetPath(cwd, item));
|
|
14557
|
-
const createsSomething = wanted.some((item) => !
|
|
15477
|
+
const createsSomething = wanted.some((item) => !fs19.existsSync(targetPath(cwd, item)));
|
|
14558
15478
|
if (createsSomething) {
|
|
14559
|
-
assertWritableInsideRepository(cwd,
|
|
15479
|
+
assertWritableInsideRepository(cwd, path20.join(cwd, ".gitignore"));
|
|
14560
15480
|
}
|
|
14561
15481
|
for (const item of wanted) {
|
|
14562
15482
|
written.push(writeIfChanged(item, targetPath(cwd, item), skill));
|
|
@@ -14670,8 +15590,8 @@ function negotiateLegacyVersion(requested) {
|
|
|
14670
15590
|
}
|
|
14671
15591
|
|
|
14672
15592
|
// src/mcp/resources.ts
|
|
14673
|
-
import * as
|
|
14674
|
-
import * as
|
|
15593
|
+
import * as fs20 from "fs";
|
|
15594
|
+
import * as path21 from "path";
|
|
14675
15595
|
var MAX_RESOURCE_BYTES = 512 * 1024;
|
|
14676
15596
|
var ResourceTooLargeError = class extends Error {
|
|
14677
15597
|
constructor(uri, bytes, limit, message) {
|
|
@@ -14721,7 +15641,7 @@ async function workspaceFor(context) {
|
|
|
14721
15641
|
}
|
|
14722
15642
|
function readFileIfPresent(file) {
|
|
14723
15643
|
try {
|
|
14724
|
-
return
|
|
15644
|
+
return fs20.readFileSync(file, "utf8");
|
|
14725
15645
|
} catch {
|
|
14726
15646
|
return null;
|
|
14727
15647
|
}
|
|
@@ -14817,7 +15737,7 @@ function buildResourceProvider() {
|
|
|
14817
15737
|
const report = REPORT_URIS.get(uri);
|
|
14818
15738
|
if (report) {
|
|
14819
15739
|
const text2 = readFileIfPresent(
|
|
14820
|
-
|
|
15740
|
+
path21.resolve(workspace.root, workspace.config.outDir, "reports", report.file)
|
|
14821
15741
|
);
|
|
14822
15742
|
if (text2 === null) return null;
|
|
14823
15743
|
return { uri, mimeType: "text/markdown", text: ensureSingleRead(uri, text2, REPORT_ADVICE) };
|
|
@@ -14839,7 +15759,7 @@ function buildResourceProvider() {
|
|
|
14839
15759
|
if (partPath === null) return null;
|
|
14840
15760
|
let partBytes;
|
|
14841
15761
|
try {
|
|
14842
|
-
partBytes =
|
|
15762
|
+
partBytes = fs20.statSync(partPath).size;
|
|
14843
15763
|
} catch {
|
|
14844
15764
|
return null;
|
|
14845
15765
|
}
|
|
@@ -14875,52 +15795,52 @@ function validateArguments(schema, value) {
|
|
|
14875
15795
|
}
|
|
14876
15796
|
return problems;
|
|
14877
15797
|
}
|
|
14878
|
-
function checkValue(
|
|
15798
|
+
function checkValue(path23, schema, value) {
|
|
14879
15799
|
if (schema.enum && !schema.enum.includes(value)) {
|
|
14880
|
-
return [`"${
|
|
15800
|
+
return [`"${path23}" must be one of: ${schema.enum.join(", ")}`];
|
|
14881
15801
|
}
|
|
14882
15802
|
switch (schema.type) {
|
|
14883
15803
|
case "string": {
|
|
14884
|
-
if (typeof value !== "string") return [`"${
|
|
15804
|
+
if (typeof value !== "string") return [`"${path23}" must be a string`];
|
|
14885
15805
|
const problems = [];
|
|
14886
15806
|
if (schema.minLength !== void 0 && value.length < schema.minLength) {
|
|
14887
|
-
problems.push(`"${
|
|
15807
|
+
problems.push(`"${path23}" must be at least ${schema.minLength} character(s)`);
|
|
14888
15808
|
}
|
|
14889
15809
|
if (schema.maxLength !== void 0 && value.length > schema.maxLength) {
|
|
14890
|
-
problems.push(`"${
|
|
15810
|
+
problems.push(`"${path23}" must be at most ${schema.maxLength} character(s)`);
|
|
14891
15811
|
}
|
|
14892
15812
|
return problems;
|
|
14893
15813
|
}
|
|
14894
15814
|
case "number":
|
|
14895
15815
|
case "integer": {
|
|
14896
15816
|
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
14897
|
-
return [`"${
|
|
15817
|
+
return [`"${path23}" must be a number`];
|
|
14898
15818
|
}
|
|
14899
15819
|
if (schema.type === "integer" && !Number.isInteger(value)) {
|
|
14900
|
-
return [`"${
|
|
15820
|
+
return [`"${path23}" must be an integer`];
|
|
14901
15821
|
}
|
|
14902
15822
|
const problems = [];
|
|
14903
15823
|
if (schema.minimum !== void 0 && value < schema.minimum) {
|
|
14904
|
-
problems.push(`"${
|
|
15824
|
+
problems.push(`"${path23}" must be >= ${schema.minimum}`);
|
|
14905
15825
|
}
|
|
14906
15826
|
if (schema.maximum !== void 0 && value > schema.maximum) {
|
|
14907
|
-
problems.push(`"${
|
|
15827
|
+
problems.push(`"${path23}" must be <= ${schema.maximum}`);
|
|
14908
15828
|
}
|
|
14909
15829
|
return problems;
|
|
14910
15830
|
}
|
|
14911
15831
|
case "boolean":
|
|
14912
|
-
return typeof value === "boolean" ? [] : [`"${
|
|
15832
|
+
return typeof value === "boolean" ? [] : [`"${path23}" must be a boolean`];
|
|
14913
15833
|
case "array": {
|
|
14914
|
-
if (!Array.isArray(value)) return [`"${
|
|
15834
|
+
if (!Array.isArray(value)) return [`"${path23}" must be an array`];
|
|
14915
15835
|
if (!schema.items) return [];
|
|
14916
15836
|
const problems = [];
|
|
14917
15837
|
value.forEach((item, index) => {
|
|
14918
|
-
problems.push(...checkValue(`${
|
|
15838
|
+
problems.push(...checkValue(`${path23}[${index}]`, schema.items, item));
|
|
14919
15839
|
});
|
|
14920
15840
|
return problems;
|
|
14921
15841
|
}
|
|
14922
15842
|
case "object":
|
|
14923
|
-
return isJsonObject(value) ? [] : [`"${
|
|
15843
|
+
return isJsonObject(value) ? [] : [`"${path23}" must be an object`];
|
|
14924
15844
|
default:
|
|
14925
15845
|
return [];
|
|
14926
15846
|
}
|
|
@@ -15496,6 +16416,10 @@ var CLI_OPTIONS = {
|
|
|
15496
16416
|
"max-part-bytes": { type: "string" },
|
|
15497
16417
|
"large-file-bytes": { type: "string" },
|
|
15498
16418
|
"max-monolith-bytes": { type: "string" },
|
|
16419
|
+
"attachment-slots": { type: "string" },
|
|
16420
|
+
"max-parts": { type: "string" },
|
|
16421
|
+
brief: { type: "string" },
|
|
16422
|
+
"prompt-task": { type: "string" },
|
|
15499
16423
|
"include-monolith": { type: "boolean" },
|
|
15500
16424
|
"include-sensitive-files": { type: "boolean" },
|
|
15501
16425
|
"skip-artifacts": { type: "string" },
|
|
@@ -15570,6 +16494,13 @@ Options:
|
|
|
15570
16494
|
--skeleton Emit TypeScript signatures instead of bodies
|
|
15571
16495
|
--sarif Also write reports/audit.sarif for GitHub Code Scanning
|
|
15572
16496
|
--include-sensitive-files Emit .env / *.pem / .npmrc / credential files
|
|
16497
|
+
--attachment-slots <n> Files the destination takes in one message (default: 10,
|
|
16498
|
+
0 = no limit); PROMPT.md plans the delivery to fit
|
|
16499
|
+
--max-parts <n> Experimental: grow the part budget until the snapshot has at
|
|
16500
|
+
most n parts, instead of adding parts as the code grows
|
|
16501
|
+
--brief <path> Owner-written half of PROMPT.md (stakes, system, history,
|
|
16502
|
+
bar, calibration); merged at fixed slots
|
|
16503
|
+
--prompt-task <task> audit | review | explain - which job the brief is for
|
|
15573
16504
|
--skip-artifacts <names> Comma-separated artifacts to omit
|
|
15574
16505
|
(readme, manifest, parts, navigation,
|
|
15575
16506
|
projectTree, audit, monolith)
|
|
@@ -15628,6 +16559,27 @@ function parseByteOption(raw, optionName, minimum, unit = "byte count") {
|
|
|
15628
16559
|
}
|
|
15629
16560
|
return value;
|
|
15630
16561
|
}
|
|
16562
|
+
function parseCountOption(raw, optionName, minimum = 0) {
|
|
16563
|
+
if (raw === void 0) return void 0;
|
|
16564
|
+
const trimmed = raw.trim();
|
|
16565
|
+
if (!/^\d+$/.test(trimmed) || !Number.isSafeInteger(Number(trimmed))) {
|
|
16566
|
+
throw new UsageError(
|
|
16567
|
+
`--${optionName} expects a whole number such as 10 or 20, received "${raw}".`
|
|
16568
|
+
);
|
|
16569
|
+
}
|
|
16570
|
+
const value = Number(trimmed);
|
|
16571
|
+
if (value < minimum) {
|
|
16572
|
+
throw new UsageError(`--${optionName} must be at least ${minimum}, received "${raw}".`);
|
|
16573
|
+
}
|
|
16574
|
+
return value;
|
|
16575
|
+
}
|
|
16576
|
+
function parsePromptTask(value) {
|
|
16577
|
+
if (value === void 0) return void 0;
|
|
16578
|
+
if (value === "audit" || value === "review" || value === "explain") return value;
|
|
16579
|
+
throw new UsageError(
|
|
16580
|
+
'--prompt-task expects audit, review or explain, received "' + value + '".'
|
|
16581
|
+
);
|
|
16582
|
+
}
|
|
15631
16583
|
function parseArtifactList(raw, flag) {
|
|
15632
16584
|
const names = raw.split(",").map((name) => name.trim()).filter(Boolean);
|
|
15633
16585
|
if (names.length === 0) {
|
|
@@ -15692,10 +16644,10 @@ function parseCliArgs(argv) {
|
|
|
15692
16644
|
}
|
|
15693
16645
|
if (values.cwd !== void 0) {
|
|
15694
16646
|
const target = String(values.cwd);
|
|
15695
|
-
if (!
|
|
16647
|
+
if (!fs21.existsSync(target)) {
|
|
15696
16648
|
throw new UsageError(`--cwd directory does not exist: ${target}`);
|
|
15697
16649
|
}
|
|
15698
|
-
if (!
|
|
16650
|
+
if (!fs21.statSync(target).isDirectory()) {
|
|
15699
16651
|
throw new UsageError(`--cwd is not a directory: ${target}`);
|
|
15700
16652
|
}
|
|
15701
16653
|
}
|
|
@@ -15841,7 +16793,7 @@ function parseCliArgs(argv) {
|
|
|
15841
16793
|
install: values.install === true,
|
|
15842
16794
|
noInstall: values["no-install"] === true,
|
|
15843
16795
|
target: values.target === void 0 ? void 0 : String(values.target),
|
|
15844
|
-
cwd: values.cwd === void 0 ? process.cwd() :
|
|
16796
|
+
cwd: values.cwd === void 0 ? process.cwd() : path22.resolve(String(values.cwd)),
|
|
15845
16797
|
outDir: values["out-dir"] === void 0 ? void 0 : String(values["out-dir"]),
|
|
15846
16798
|
includeMonolith: values["include-monolith"] === true || onlyNamesMonolith === true ? true : void 0,
|
|
15847
16799
|
includeSensitiveFiles: values["include-sensitive-files"] === true ? true : void 0,
|
|
@@ -15869,6 +16821,13 @@ function parseCliArgs(argv) {
|
|
|
15869
16821
|
"max-monolith-bytes",
|
|
15870
16822
|
1
|
|
15871
16823
|
),
|
|
16824
|
+
attachmentSlots: parseCountOption(
|
|
16825
|
+
values["attachment-slots"],
|
|
16826
|
+
"attachment-slots"
|
|
16827
|
+
),
|
|
16828
|
+
maxParts: parseCountOption(values["max-parts"], "max-parts", 1),
|
|
16829
|
+
brief: values.brief === void 0 ? void 0 : String(values.brief),
|
|
16830
|
+
promptTask: parsePromptTask(values["prompt-task"]),
|
|
15872
16831
|
skipArtifacts,
|
|
15873
16832
|
onlyArtifacts,
|
|
15874
16833
|
discovery: isDiscoveryMode(rawDiscovery) ? rawDiscovery : void 0,
|
|
@@ -15922,9 +16881,9 @@ function splitList(value) {
|
|
|
15922
16881
|
return value.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
15923
16882
|
}
|
|
15924
16883
|
function displayOutPath(cwd, outDir, ...segments) {
|
|
15925
|
-
const absolute =
|
|
15926
|
-
const relative15 =
|
|
15927
|
-
if (relative15 && !relative15.startsWith("..") && !
|
|
16884
|
+
const absolute = path22.resolve(cwd, outDir, ...segments);
|
|
16885
|
+
const relative15 = path22.relative(cwd, absolute);
|
|
16886
|
+
if (relative15 && !relative15.startsWith("..") && !path22.isAbsolute(relative15)) return relative15;
|
|
15928
16887
|
return absolute;
|
|
15929
16888
|
}
|
|
15930
16889
|
function nextStepHint(cwd, scriptsAddedNow) {
|
|
@@ -15932,7 +16891,7 @@ function nextStepHint(cwd, scriptsAddedNow) {
|
|
|
15932
16891
|
if (!hasScript) {
|
|
15933
16892
|
try {
|
|
15934
16893
|
const parsed = JSON.parse(
|
|
15935
|
-
stripJsonComments(
|
|
16894
|
+
stripJsonComments(fs21.readFileSync(path22.join(cwd, "package.json"), "utf8"))
|
|
15936
16895
|
);
|
|
15937
16896
|
hasScript = typeof parsed.scripts?.snapshot === "string";
|
|
15938
16897
|
} catch {
|
|
@@ -15940,8 +16899,8 @@ function nextStepHint(cwd, scriptsAddedNow) {
|
|
|
15940
16899
|
}
|
|
15941
16900
|
}
|
|
15942
16901
|
if (!hasScript) return `npx ${GENERATOR_NAME} generate`;
|
|
15943
|
-
const bin =
|
|
15944
|
-
const installed =
|
|
16902
|
+
const bin = path22.join(cwd, "node_modules", ".bin", "codebase-snapshot");
|
|
16903
|
+
const installed = fs21.existsSync(bin) || fs21.existsSync(`${bin}.cmd`);
|
|
15945
16904
|
return installed ? "npm run snapshot" : "npm install && npm run snapshot";
|
|
15946
16905
|
}
|
|
15947
16906
|
function presetSummary(init) {
|
|
@@ -15977,7 +16936,7 @@ async function runInitCommand(invocation) {
|
|
|
15977
16936
|
if (hook) for (const note of hook.notes) info(` ${note}`);
|
|
15978
16937
|
return 0;
|
|
15979
16938
|
}
|
|
15980
|
-
info(`\u2705 Created ${
|
|
16939
|
+
info(`\u2705 Created ${path22.basename(result.configPath)} (${presetSummary(result)})`);
|
|
15981
16940
|
if (result.scripts.length > 0) info(` Added npm scripts: ${result.scripts.join(", ")}`);
|
|
15982
16941
|
if (result.dependency.added && result.dependency.range !== null) {
|
|
15983
16942
|
info(` Added devDependency: ${result.dependency.name} ${result.dependency.range}`);
|
|
@@ -16000,18 +16959,18 @@ async function runInitCommand(invocation) {
|
|
|
16000
16959
|
function generatorOrigin(cwd) {
|
|
16001
16960
|
try {
|
|
16002
16961
|
const pkg = JSON.parse(
|
|
16003
|
-
stripJsonComments(
|
|
16962
|
+
stripJsonComments(fs21.readFileSync(path22.join(cwd, "package.json"), "utf8"))
|
|
16004
16963
|
);
|
|
16005
16964
|
const spec = pkg.dependencies?.["codebase-snapshot"] ?? pkg.devDependencies?.["codebase-snapshot"];
|
|
16006
16965
|
if (typeof spec === "string") return `project dependency ${spec}`;
|
|
16007
16966
|
} catch {
|
|
16008
16967
|
}
|
|
16009
16968
|
const entry = process.argv[1] ?? "";
|
|
16010
|
-
if (entry.includes("_npx") || entry.includes(`${
|
|
16969
|
+
if (entry.includes("_npx") || entry.includes(`${path22.sep}npx${path22.sep}`)) return "via npx";
|
|
16011
16970
|
return "global or direct install";
|
|
16012
16971
|
}
|
|
16013
16972
|
function detectPackageManager(cwd) {
|
|
16014
|
-
const has = (name) =>
|
|
16973
|
+
const has = (name) => fs21.existsSync(path22.join(cwd, name));
|
|
16015
16974
|
if (has("bun.lockb") || has("bun.lock")) return { name: "bun", command: "bun", args: ["install"] };
|
|
16016
16975
|
if (has("pnpm-lock.yaml")) return { name: "pnpm", command: "pnpm", args: ["install"] };
|
|
16017
16976
|
if (has("yarn.lock")) return { name: "yarn", command: "yarn", args: ["install"] };
|
|
@@ -16128,7 +17087,7 @@ async function runSetupCommand(invocation, options = {}) {
|
|
|
16128
17087
|
}
|
|
16129
17088
|
info("\n\u{1F9EA} Dry run \u2014 setup would:");
|
|
16130
17089
|
info(
|
|
16131
|
-
` 1. ${init.reused ? `keep ${
|
|
17090
|
+
` 1. ${init.reused ? `keep ${path22.basename(keptConfigPath)}` : `write ${path22.basename(keptConfigPath)} (preset: ${appliedPreset})`}`
|
|
16132
17091
|
);
|
|
16133
17092
|
info(" 2. add the npm scripts, the devDependency and the .gitignore entries");
|
|
16134
17093
|
if (manager !== null) info(` 3. install with ${manager}`);
|
|
@@ -16141,9 +17100,9 @@ async function runSetupCommand(invocation, options = {}) {
|
|
|
16141
17100
|
if (invocation.format !== "json") {
|
|
16142
17101
|
if (!interactive) info(`\u{1F680} Setup for: ${invocation.cwd}`);
|
|
16143
17102
|
if (init.reused) {
|
|
16144
|
-
info(`\u267B Keeping ${
|
|
17103
|
+
info(`\u267B Keeping ${path22.basename(keptConfigPath)}`);
|
|
16145
17104
|
} else {
|
|
16146
|
-
info(`\u2705 Created ${
|
|
17105
|
+
info(`\u2705 Created ${path22.basename(keptConfigPath)} (${presetSummary(init)})`);
|
|
16147
17106
|
}
|
|
16148
17107
|
if (init.scripts.length > 0) info(` Added npm scripts: ${init.scripts.join(", ")}`);
|
|
16149
17108
|
if (init.dependency.added && init.dependency.range !== null) {
|
|
@@ -16157,7 +17116,7 @@ async function runSetupCommand(invocation, options = {}) {
|
|
|
16157
17116
|
info(` \u26A0 --preset ${invocation.preset} was not applied: the existing config is kept.`);
|
|
16158
17117
|
}
|
|
16159
17118
|
}
|
|
16160
|
-
const hasManifest =
|
|
17119
|
+
const hasManifest = fs21.existsSync(path22.join(invocation.cwd, "package.json"));
|
|
16161
17120
|
let install = null;
|
|
16162
17121
|
if (invocation.noInstall) {
|
|
16163
17122
|
if (invocation.format !== "json") info(" Skipped the install (--no-install)");
|
|
@@ -16194,6 +17153,16 @@ async function runSetupCommand(invocation, options = {}) {
|
|
|
16194
17153
|
if (invocation.maxPartTokens !== void 0) {
|
|
16195
17154
|
generateArgs.push("--max-part-tokens", String(invocation.maxPartTokens));
|
|
16196
17155
|
}
|
|
17156
|
+
if (invocation.attachmentSlots !== void 0) {
|
|
17157
|
+
generateArgs.push("--attachment-slots", String(invocation.attachmentSlots));
|
|
17158
|
+
}
|
|
17159
|
+
if (invocation.maxParts !== void 0) {
|
|
17160
|
+
generateArgs.push("--max-parts", String(invocation.maxParts));
|
|
17161
|
+
}
|
|
17162
|
+
if (invocation.brief !== void 0) generateArgs.push("--brief", invocation.brief);
|
|
17163
|
+
if (invocation.promptTask !== void 0) {
|
|
17164
|
+
generateArgs.push("--prompt-task", invocation.promptTask);
|
|
17165
|
+
}
|
|
16197
17166
|
if (invocation.skeleton === true) generateArgs.push("--skeleton");
|
|
16198
17167
|
if (invocation.sarif === true) generateArgs.push("--sarif");
|
|
16199
17168
|
if (invocation.noUpdateCheck) generateArgs.push("--no-update-check");
|
|
@@ -16279,7 +17248,7 @@ function runSkillCommand(invocation) {
|
|
|
16279
17248
|
}
|
|
16280
17249
|
info(`\u2705 Agent skill installed (${SKILL_NAME}):`);
|
|
16281
17250
|
for (const item of result.written) {
|
|
16282
|
-
const shown =
|
|
17251
|
+
const shown = path22.relative(invocation.cwd, item.path) || item.path;
|
|
16283
17252
|
info(` - ${item.action.padEnd(9)} ${shown}`);
|
|
16284
17253
|
}
|
|
16285
17254
|
if (result.gitignored.length > 0) {
|
|
@@ -16400,7 +17369,7 @@ ${USAGE}
|
|
|
16400
17369
|
return runSkillCommand(invocation);
|
|
16401
17370
|
}
|
|
16402
17371
|
if (invocation.command === "mcp") {
|
|
16403
|
-
return await runStdioServer({ cwd:
|
|
17372
|
+
return await runStdioServer({ cwd: path22.resolve(invocation.cwd) });
|
|
16404
17373
|
}
|
|
16405
17374
|
if (invocation.command === "setup") {
|
|
16406
17375
|
return runSetupCommand(invocation);
|
|
@@ -16419,7 +17388,7 @@ ${USAGE}
|
|
|
16419
17388
|
);
|
|
16420
17389
|
}
|
|
16421
17390
|
for (const warning of loaded.warnings) warn(`\u26A0 Config: ${warning}`);
|
|
16422
|
-
if (loaded.file) info(`\u2699 Using config ${
|
|
17391
|
+
if (loaded.file) info(`\u2699 Using config ${path22.relative(process.cwd(), loaded.file) || loaded.file}`);
|
|
16423
17392
|
let resolved;
|
|
16424
17393
|
try {
|
|
16425
17394
|
resolved = resolveConfig(
|
|
@@ -16436,6 +17405,10 @@ ${USAGE}
|
|
|
16436
17405
|
maxPartTokens: invocation.maxPartTokens,
|
|
16437
17406
|
largeFileBytes: invocation.largeFileBytes,
|
|
16438
17407
|
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
17408
|
+
attachmentSlots: invocation.attachmentSlots,
|
|
17409
|
+
maxParts: invocation.maxParts,
|
|
17410
|
+
brief: invocation.brief,
|
|
17411
|
+
promptTask: invocation.promptTask,
|
|
16439
17412
|
skipArtifacts: invocation.skipArtifacts,
|
|
16440
17413
|
// `--only-artifacts` is forwarded as itself, not only as the derived suppression list:
|
|
16441
17414
|
// suppression cannot switch an artifact *on*, so a config that had turned one of the
|
|
@@ -16459,13 +17432,13 @@ ${USAGE}
|
|
|
16459
17432
|
return result.valid ? 0 : 1;
|
|
16460
17433
|
}
|
|
16461
17434
|
if (invocation.command === "report") {
|
|
16462
|
-
const manifestPath =
|
|
16463
|
-
if (!
|
|
17435
|
+
const manifestPath = path22.resolve(resolved.cwd, resolved.outDir, "manifest.json");
|
|
17436
|
+
if (!fs21.existsSync(manifestPath)) {
|
|
16464
17437
|
return fail(invocation.format, `Manifest not found at ${manifestPath}. Run generate first.`);
|
|
16465
17438
|
}
|
|
16466
17439
|
let manifest;
|
|
16467
17440
|
try {
|
|
16468
|
-
manifest = JSON.parse(
|
|
17441
|
+
manifest = JSON.parse(fs21.readFileSync(manifestPath, "utf8"));
|
|
16469
17442
|
} catch (err) {
|
|
16470
17443
|
return fail(invocation.format, `Could not read ${manifestPath}: ${err.message}`);
|
|
16471
17444
|
}
|
|
@@ -16608,7 +17581,16 @@ ${USAGE}
|
|
|
16608
17581
|
);
|
|
16609
17582
|
}
|
|
16610
17583
|
}
|
|
16611
|
-
|
|
17584
|
+
const orientation = [
|
|
17585
|
+
artifacts.readme ? "README.md" : null,
|
|
17586
|
+
artifacts.prompt ? "PROMPT.md" : null
|
|
17587
|
+
].filter((name) => name !== null);
|
|
17588
|
+
if (orientation.length > 0) {
|
|
17589
|
+
info(
|
|
17590
|
+
` - Orientation: ${orientation.map((name) => displayOutPath(resolved.cwd, resolved.outDir, name)).join(", ")}`
|
|
17591
|
+
);
|
|
17592
|
+
}
|
|
17593
|
+
if (reports.length === 0 && !artifacts.parts && !artifacts.manifest && !artifacts.monolith && orientation.length === 0) {
|
|
16612
17594
|
info(` - Artifacts: all disabled (only the ownership marker was written)`);
|
|
16613
17595
|
}
|
|
16614
17596
|
info(` - Fingerprint: ${manifest.fingerprint}`);
|
|
@@ -16660,19 +17642,19 @@ function finishWatchRun(state, now) {
|
|
|
16660
17642
|
};
|
|
16661
17643
|
}
|
|
16662
17644
|
function comparablePath(value) {
|
|
16663
|
-
const absolute =
|
|
17645
|
+
const absolute = path22.resolve(value);
|
|
16664
17646
|
return process.platform === "win32" ? absolute.toLowerCase() : absolute;
|
|
16665
17647
|
}
|
|
16666
17648
|
function isSameOrInside(parent, candidate) {
|
|
16667
|
-
const relative15 =
|
|
16668
|
-
return relative15 === "" || relative15 !== ".." && !relative15.startsWith(`..${
|
|
17649
|
+
const relative15 = path22.relative(parent, candidate);
|
|
17650
|
+
return relative15 === "" || relative15 !== ".." && !relative15.startsWith(`..${path22.sep}`) && !path22.isAbsolute(relative15);
|
|
16669
17651
|
}
|
|
16670
17652
|
function isGeneratedWatchPath(candidate, paths) {
|
|
16671
|
-
const absolute = comparablePath(
|
|
16672
|
-
const outDir = comparablePath(
|
|
16673
|
-
const tmpDir = comparablePath(
|
|
17653
|
+
const absolute = comparablePath(path22.resolve(paths.cwd, candidate));
|
|
17654
|
+
const outDir = comparablePath(path22.resolve(paths.cwd, paths.outDir));
|
|
17655
|
+
const tmpDir = comparablePath(path22.resolve(paths.cwd, paths.tmpDir));
|
|
16674
17656
|
if (isSameOrInside(outDir, absolute) || isSameOrInside(tmpDir, absolute)) return true;
|
|
16675
|
-
const offsets = [
|
|
17657
|
+
const offsets = [path22.basename(outDir), path22.basename(tmpDir)].filter((name) => name.length > 0);
|
|
16676
17658
|
const leftover = absolute.split(/[\\/]+/).some(
|
|
16677
17659
|
(segment) => offsets.some(
|
|
16678
17660
|
(name) => segment.startsWith(`${name}.backup-`) || segment.startsWith(`${name}.partial-`)
|
|
@@ -16695,8 +17677,8 @@ function decideWatchEvent(state, event, paths) {
|
|
|
16695
17677
|
function watchPathsFor(config) {
|
|
16696
17678
|
return {
|
|
16697
17679
|
cwd: config.cwd,
|
|
16698
|
-
outDir:
|
|
16699
|
-
tmpDir:
|
|
17680
|
+
outDir: path22.resolve(config.cwd, config.outDir),
|
|
17681
|
+
tmpDir: path22.resolve(config.cwd, config.tmpDir)
|
|
16700
17682
|
};
|
|
16701
17683
|
}
|
|
16702
17684
|
function watchSupportProblem(platform = process.platform, version = process.versions.node) {
|
|
@@ -16752,6 +17734,10 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
16752
17734
|
maxPartTokens: invocation.maxPartTokens,
|
|
16753
17735
|
largeFileBytes: invocation.largeFileBytes,
|
|
16754
17736
|
maxMonolithBytes: invocation.maxMonolithBytes,
|
|
17737
|
+
attachmentSlots: invocation.attachmentSlots,
|
|
17738
|
+
maxParts: invocation.maxParts,
|
|
17739
|
+
brief: invocation.brief,
|
|
17740
|
+
promptTask: invocation.promptTask,
|
|
16755
17741
|
skipArtifacts: invocation.skipArtifacts,
|
|
16756
17742
|
onlyArtifacts: invocation.onlyArtifacts,
|
|
16757
17743
|
discovery: invocation.discovery,
|
|
@@ -16781,11 +17767,11 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
16781
17767
|
if (!options.generatedAlready) void regenerate();
|
|
16782
17768
|
let watcher;
|
|
16783
17769
|
try {
|
|
16784
|
-
watcher =
|
|
17770
|
+
watcher = fs21.watch(resolved.cwd, { recursive: true }, (_event, filename) => {
|
|
16785
17771
|
const decision = decideWatchEvent(
|
|
16786
17772
|
state,
|
|
16787
17773
|
{
|
|
16788
|
-
path: filename ?
|
|
17774
|
+
path: filename ? path22.resolve(resolved.cwd, filename.toString()) : null,
|
|
16789
17775
|
now: performance.now()
|
|
16790
17776
|
},
|
|
16791
17777
|
paths
|
|
@@ -16824,7 +17810,7 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
16824
17810
|
return 0;
|
|
16825
17811
|
}
|
|
16826
17812
|
var entryFile = process.argv[1] ?? "";
|
|
16827
|
-
var entryName =
|
|
17813
|
+
var entryName = path22.basename(entryFile).toLowerCase();
|
|
16828
17814
|
var invokedDirectly = entryName === "cli.js" || entryName === "cli.cjs";
|
|
16829
17815
|
if (invokedDirectly) {
|
|
16830
17816
|
void main().then(
|