@ankurhalder/codebase-snapshot 2.1.0 → 2.2.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/README.md +36 -0
- package/dist/bin.js +809 -49
- package/dist/{chunk-QEIOXPMU.js → chunk-5I564BGX.js} +43 -19
- package/dist/cli.cjs +791 -35
- package/dist/cli.d.cts +5 -1
- package/dist/cli.d.ts +5 -1
- package/dist/cli.js +750 -17
- package/dist/index.cjs +41 -17
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/docs/agent.md +80 -0
- package/docs/install.md +15 -1
- package/package.json +1 -1
|
@@ -1678,11 +1678,12 @@ function detectPreset(cwd, forced) {
|
|
|
1678
1678
|
}
|
|
1679
1679
|
function getGitInfo(cwd, fallbackBranch = "main") {
|
|
1680
1680
|
try {
|
|
1681
|
-
const
|
|
1681
|
+
const reported = childProcess.execSync("git rev-parse --abbrev-ref HEAD", {
|
|
1682
1682
|
cwd,
|
|
1683
1683
|
stdio: ["ignore", "pipe", "ignore"],
|
|
1684
1684
|
encoding: "utf8"
|
|
1685
|
-
}).trim()
|
|
1685
|
+
}).trim();
|
|
1686
|
+
const branch = !reported || reported === "HEAD" ? fallbackBranch : reported;
|
|
1686
1687
|
const commit = childProcess.execSync("git rev-parse HEAD", {
|
|
1687
1688
|
cwd,
|
|
1688
1689
|
stdio: ["ignore", "pipe", "ignore"],
|
|
@@ -2303,6 +2304,9 @@ async function loadConfigFileDetailed(cwd) {
|
|
|
2303
2304
|
if (snapshotKey && typeof snapshotKey === "object") {
|
|
2304
2305
|
return { config: snapshotKey, file: pkgJsonPath, warnings, errors };
|
|
2305
2306
|
}
|
|
2307
|
+
if (snapshotKey !== void 0) {
|
|
2308
|
+
warnings.push(`${pkgJsonPath}: the "snapshot" key must be an object; it was ignored.`);
|
|
2309
|
+
}
|
|
2306
2310
|
} catch (err) {
|
|
2307
2311
|
const message = err.message;
|
|
2308
2312
|
warnings.push(message);
|
|
@@ -3417,6 +3421,7 @@ function validateSnapshot(configInput) {
|
|
|
3417
3421
|
drift.missingOnDisk.push(snapshotFile);
|
|
3418
3422
|
}
|
|
3419
3423
|
}
|
|
3424
|
+
drift.missingOnDisk = [...new Set(drift.missingOnDisk)];
|
|
3420
3425
|
const maxEffectiveBudget = Math.max(
|
|
3421
3426
|
config.maxPartBytes,
|
|
3422
3427
|
config.budgets.default,
|
|
@@ -3828,7 +3833,13 @@ function compareManifests(before, after) {
|
|
|
3828
3833
|
};
|
|
3829
3834
|
}
|
|
3830
3835
|
function loadManifest(target) {
|
|
3831
|
-
|
|
3836
|
+
let isDirectory;
|
|
3837
|
+
try {
|
|
3838
|
+
isDirectory = fs9.statSync(target).isDirectory();
|
|
3839
|
+
} catch {
|
|
3840
|
+
throw new Error(`No snapshot found at ${target}: the path does not exist.`);
|
|
3841
|
+
}
|
|
3842
|
+
const manifestPath = isDirectory ? path10.join(target, "manifest.json") : target;
|
|
3832
3843
|
let raw;
|
|
3833
3844
|
try {
|
|
3834
3845
|
raw = fs9.readFileSync(manifestPath, "utf8");
|
|
@@ -3844,6 +3855,9 @@ function loadManifest(target) {
|
|
|
3844
3855
|
if (!parsed || !Array.isArray(parsed.files)) {
|
|
3845
3856
|
throw new Error(`${manifestPath} is not a snapshot manifest (no "files" array).`);
|
|
3846
3857
|
}
|
|
3858
|
+
if (!parsed.counts || typeof parsed.counts !== "object") {
|
|
3859
|
+
throw new Error(`${manifestPath} is not a snapshot manifest (no "counts" object).`);
|
|
3860
|
+
}
|
|
3847
3861
|
return parsed;
|
|
3848
3862
|
}
|
|
3849
3863
|
function renderDiffText(diff) {
|
|
@@ -3900,11 +3914,12 @@ var PRESET_NAMES = [
|
|
|
3900
3914
|
"java-spring \xB7 dotnet \xB7 php-laravel \xB7 ruby-rails",
|
|
3901
3915
|
"monorepo \xB7 docs \xB7 infra \xB7 generic"
|
|
3902
3916
|
];
|
|
3917
|
+
var CONFIG_HEADER = `// Generated by codebase-snapshot. A plain object on purpose: this file must load
|
|
3918
|
+
// even when the package itself is only run through npx.
|
|
3919
|
+
`;
|
|
3903
3920
|
function renderConfig(answers) {
|
|
3904
3921
|
const { artifacts } = answers;
|
|
3905
|
-
return
|
|
3906
|
-
|
|
3907
|
-
export default defineConfig({
|
|
3922
|
+
return `${CONFIG_HEADER}export default {
|
|
3908
3923
|
// \u2500\u2500 Project \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\u2500
|
|
3909
3924
|
// Which project shape to use. Detected from the repo when omitted.
|
|
3910
3925
|
// ${PRESET_NAMES.join("\n // ")}
|
|
@@ -3973,7 +3988,7 @@ export default defineConfig({
|
|
|
3973
3988
|
// \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
|
|
3974
3989
|
// afterGenerate: (manifest) => { /* write your own artifact */ }
|
|
3975
3990
|
hooks: {},
|
|
3976
|
-
}
|
|
3991
|
+
};
|
|
3977
3992
|
`;
|
|
3978
3993
|
}
|
|
3979
3994
|
function renderMinimalConfig(answers) {
|
|
@@ -4001,16 +4016,12 @@ ${entries},
|
|
|
4001
4016
|
},`);
|
|
4002
4017
|
}
|
|
4003
4018
|
if (lines.length === 0) {
|
|
4004
|
-
return
|
|
4005
|
-
|
|
4006
|
-
export default defineConfig({});
|
|
4019
|
+
return `${CONFIG_HEADER}export default {};
|
|
4007
4020
|
`;
|
|
4008
4021
|
}
|
|
4009
|
-
return
|
|
4010
|
-
|
|
4011
|
-
export default defineConfig({
|
|
4022
|
+
return `${CONFIG_HEADER}export default {
|
|
4012
4023
|
${lines.join("\n")}
|
|
4013
|
-
}
|
|
4024
|
+
};
|
|
4014
4025
|
`;
|
|
4015
4026
|
}
|
|
4016
4027
|
var PromptCancelled = class extends Error {
|
|
@@ -4271,6 +4282,17 @@ var CONFIG_CANDIDATES = [
|
|
|
4271
4282
|
".snapshotrc.json",
|
|
4272
4283
|
".snapshotrc"
|
|
4273
4284
|
];
|
|
4285
|
+
function chooseConfigFileName(cwd) {
|
|
4286
|
+
if (!supportsTypeScriptImports()) return "snapshot.config.mjs";
|
|
4287
|
+
const pkgPath = path10.join(cwd, "package.json");
|
|
4288
|
+
if (!fs9.existsSync(pkgPath)) return "snapshot.config.mjs";
|
|
4289
|
+
try {
|
|
4290
|
+
const parsed = JSON.parse(fs9.readFileSync(pkgPath, "utf8"));
|
|
4291
|
+
return parsed.type === "module" ? "snapshot.config.ts" : "snapshot.config.mjs";
|
|
4292
|
+
} catch {
|
|
4293
|
+
return "snapshot.config.mjs";
|
|
4294
|
+
}
|
|
4295
|
+
}
|
|
4274
4296
|
var SIZE_CHOICES = [
|
|
4275
4297
|
{ value: "60k", label: "Small", hint: "60 KB \xB7 ~15k tokens \xB7 tight context windows" },
|
|
4276
4298
|
{ value: "120k", label: "Medium", hint: "120 KB \xB7 ~30k tokens \xB7 recommended" },
|
|
@@ -4476,7 +4498,7 @@ async function runInit(options) {
|
|
|
4476
4498
|
if (!proceed) throw new PromptCancelled();
|
|
4477
4499
|
}
|
|
4478
4500
|
const configText = options.minimal ? renderMinimalConfig(answers) : renderConfig(answers);
|
|
4479
|
-
const configName =
|
|
4501
|
+
const configName = chooseConfigFileName(options.cwd);
|
|
4480
4502
|
const configPath = path10.join(options.cwd, configName);
|
|
4481
4503
|
if (options.dryRun) {
|
|
4482
4504
|
return {
|
|
@@ -4514,7 +4536,7 @@ async function runInit(options) {
|
|
|
4514
4536
|
|
|
4515
4537
|
// src/index.ts
|
|
4516
4538
|
var GENERATOR_NAME = "@ankurhalder/codebase-snapshot";
|
|
4517
|
-
var GENERATOR_VERSION = "2.
|
|
4539
|
+
var GENERATOR_VERSION = "2.2.0";
|
|
4518
4540
|
var SCHEMA_VERSION = "3.0.0";
|
|
4519
4541
|
function sha256Hex2(input) {
|
|
4520
4542
|
return crypto.createHash("sha256").update(input).digest("hex");
|
|
@@ -4758,7 +4780,9 @@ function artifactWarnings(artifacts) {
|
|
|
4758
4780
|
);
|
|
4759
4781
|
}
|
|
4760
4782
|
if (ARTIFACT_NAMES.every((name) => artifacts[name] === false)) {
|
|
4761
|
-
messages.push(
|
|
4783
|
+
messages.push(
|
|
4784
|
+
"every artifact is disabled: only the .codebase-snapshot ownership marker will be written."
|
|
4785
|
+
);
|
|
4762
4786
|
}
|
|
4763
4787
|
return messages;
|
|
4764
4788
|
}
|
|
@@ -5089,5 +5113,5 @@ async function generateSnapshotAsync(configInput, options) {
|
|
|
5089
5113
|
}
|
|
5090
5114
|
|
|
5091
5115
|
export { ARTIFACT_NAMES, DEFAULT_ANSWERS, DEFAULT_SECRET_PATTERNS, GENERATOR_NAME, GENERATOR_VERSION, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, PRESETS, PromptCancelled, SCHEMA_VERSION, anchorForPath, assertReplaceable, assertUsableConfigInput, collectFiles, compareManifests, countLines, defineConfig, detectLanguage, detectPreset, explainPath, fenceForContent, generateProjectTree, generateSnapshot, generateSnapshotAsync, getPreset, globToRegExp, isBinaryBuffer, isBinaryExtension, isBinaryFile, isInteractive, isResolvedConfig, isSensitivePath, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, partitionFiles, profileForPath, renderConfig, renderDiffText, renderExplainText, renderMinimalConfig, renumberParts, resolveConfig, resolveSafeOutputDirs, runInit, scanAndRedactSecrets, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, truncatePreview, truncateToBytes, unknownPresetMessage, validateSnapshot };
|
|
5092
|
-
//# sourceMappingURL=chunk-
|
|
5093
|
-
//# sourceMappingURL=chunk-
|
|
5116
|
+
//# sourceMappingURL=chunk-5I564BGX.js.map
|
|
5117
|
+
//# sourceMappingURL=chunk-5I564BGX.js.map
|