@ankurhalder/codebase-snapshot 2.1.1 → 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 +739 -43
- package/dist/{chunk-SUOJL5EX.js → chunk-5I564BGX.js} +23 -15
- package/dist/cli.cjs +719 -27
- package/dist/cli.d.cts +5 -1
- package/dist/cli.d.ts +5 -1
- package/dist/cli.js +698 -13
- package/dist/index.cjs +21 -13
- 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 +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3943,11 +3943,12 @@ var PRESET_NAMES = [
|
|
|
3943
3943
|
"java-spring \xB7 dotnet \xB7 php-laravel \xB7 ruby-rails",
|
|
3944
3944
|
"monorepo \xB7 docs \xB7 infra \xB7 generic"
|
|
3945
3945
|
];
|
|
3946
|
+
var CONFIG_HEADER = `// Generated by codebase-snapshot. A plain object on purpose: this file must load
|
|
3947
|
+
// even when the package itself is only run through npx.
|
|
3948
|
+
`;
|
|
3946
3949
|
function renderConfig(answers) {
|
|
3947
3950
|
const { artifacts } = answers;
|
|
3948
|
-
return
|
|
3949
|
-
|
|
3950
|
-
export default defineConfig({
|
|
3951
|
+
return `${CONFIG_HEADER}export default {
|
|
3951
3952
|
// \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
|
|
3952
3953
|
// Which project shape to use. Detected from the repo when omitted.
|
|
3953
3954
|
// ${PRESET_NAMES.join("\n // ")}
|
|
@@ -4016,7 +4017,7 @@ export default defineConfig({
|
|
|
4016
4017
|
// \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
|
|
4017
4018
|
// afterGenerate: (manifest) => { /* write your own artifact */ }
|
|
4018
4019
|
hooks: {},
|
|
4019
|
-
}
|
|
4020
|
+
};
|
|
4020
4021
|
`;
|
|
4021
4022
|
}
|
|
4022
4023
|
function renderMinimalConfig(answers) {
|
|
@@ -4044,16 +4045,12 @@ ${entries},
|
|
|
4044
4045
|
},`);
|
|
4045
4046
|
}
|
|
4046
4047
|
if (lines.length === 0) {
|
|
4047
|
-
return
|
|
4048
|
-
|
|
4049
|
-
export default defineConfig({});
|
|
4048
|
+
return `${CONFIG_HEADER}export default {};
|
|
4050
4049
|
`;
|
|
4051
4050
|
}
|
|
4052
|
-
return
|
|
4053
|
-
|
|
4054
|
-
export default defineConfig({
|
|
4051
|
+
return `${CONFIG_HEADER}export default {
|
|
4055
4052
|
${lines.join("\n")}
|
|
4056
|
-
}
|
|
4053
|
+
};
|
|
4057
4054
|
`;
|
|
4058
4055
|
}
|
|
4059
4056
|
var PromptCancelled = class extends Error {
|
|
@@ -4314,6 +4311,17 @@ var CONFIG_CANDIDATES = [
|
|
|
4314
4311
|
".snapshotrc.json",
|
|
4315
4312
|
".snapshotrc"
|
|
4316
4313
|
];
|
|
4314
|
+
function chooseConfigFileName(cwd) {
|
|
4315
|
+
if (!supportsTypeScriptImports()) return "snapshot.config.mjs";
|
|
4316
|
+
const pkgPath = path10__namespace.join(cwd, "package.json");
|
|
4317
|
+
if (!fs9__namespace.existsSync(pkgPath)) return "snapshot.config.mjs";
|
|
4318
|
+
try {
|
|
4319
|
+
const parsed = JSON.parse(fs9__namespace.readFileSync(pkgPath, "utf8"));
|
|
4320
|
+
return parsed.type === "module" ? "snapshot.config.ts" : "snapshot.config.mjs";
|
|
4321
|
+
} catch {
|
|
4322
|
+
return "snapshot.config.mjs";
|
|
4323
|
+
}
|
|
4324
|
+
}
|
|
4317
4325
|
var SIZE_CHOICES = [
|
|
4318
4326
|
{ value: "60k", label: "Small", hint: "60 KB \xB7 ~15k tokens \xB7 tight context windows" },
|
|
4319
4327
|
{ value: "120k", label: "Medium", hint: "120 KB \xB7 ~30k tokens \xB7 recommended" },
|
|
@@ -4519,7 +4527,7 @@ async function runInit(options) {
|
|
|
4519
4527
|
if (!proceed) throw new PromptCancelled();
|
|
4520
4528
|
}
|
|
4521
4529
|
const configText = options.minimal ? renderMinimalConfig(answers) : renderConfig(answers);
|
|
4522
|
-
const configName =
|
|
4530
|
+
const configName = chooseConfigFileName(options.cwd);
|
|
4523
4531
|
const configPath = path10__namespace.join(options.cwd, configName);
|
|
4524
4532
|
if (options.dryRun) {
|
|
4525
4533
|
return {
|
|
@@ -4557,7 +4565,7 @@ async function runInit(options) {
|
|
|
4557
4565
|
|
|
4558
4566
|
// src/index.ts
|
|
4559
4567
|
var GENERATOR_NAME = "@ankurhalder/codebase-snapshot";
|
|
4560
|
-
var GENERATOR_VERSION = "2.
|
|
4568
|
+
var GENERATOR_VERSION = "2.2.0";
|
|
4561
4569
|
var SCHEMA_VERSION = "3.0.0";
|
|
4562
4570
|
function sha256Hex2(input) {
|
|
4563
4571
|
return crypto__namespace.createHash("sha256").update(input).digest("hex");
|
package/dist/index.d.cts
CHANGED
|
@@ -497,7 +497,7 @@ declare function matchesExclude(relativePath: string, pattern: string): boolean;
|
|
|
497
497
|
declare function collectFiles(cwd: string, options?: CollectOptions): CollectResult;
|
|
498
498
|
|
|
499
499
|
declare const GENERATOR_NAME = "@ankurhalder/codebase-snapshot";
|
|
500
|
-
declare const GENERATOR_VERSION = "2.
|
|
500
|
+
declare const GENERATOR_VERSION = "2.2.0";
|
|
501
501
|
declare const SCHEMA_VERSION = "3.0.0";
|
|
502
502
|
interface GenerateOptions {
|
|
503
503
|
/** Compute the full manifest but write nothing to disk. */
|
package/dist/index.d.ts
CHANGED
|
@@ -497,7 +497,7 @@ declare function matchesExclude(relativePath: string, pattern: string): boolean;
|
|
|
497
497
|
declare function collectFiles(cwd: string, options?: CollectOptions): CollectResult;
|
|
498
498
|
|
|
499
499
|
declare const GENERATOR_NAME = "@ankurhalder/codebase-snapshot";
|
|
500
|
-
declare const GENERATOR_VERSION = "2.
|
|
500
|
+
declare const GENERATOR_VERSION = "2.2.0";
|
|
501
501
|
declare const SCHEMA_VERSION = "3.0.0";
|
|
502
502
|
interface GenerateOptions {
|
|
503
503
|
/** Compute the full manifest but write nothing to disk. */
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
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, validateSnapshot } from './chunk-
|
|
1
|
+
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, validateSnapshot } from './chunk-5I564BGX.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/docs/agent.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Using this with an AI agent
|
|
2
|
+
|
|
3
|
+
The package ships two things that make it usable by an agent that has never heard of it:
|
|
4
|
+
a **machine-readable contract** and a **bundled skill**.
|
|
5
|
+
|
|
6
|
+
Nothing here needs to be installed globally, and no prior knowledge of the tool is
|
|
7
|
+
required.
|
|
8
|
+
|
|
9
|
+
## The three commands an agent needs
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# 1. Read the contract. This is the machine-readable replacement for --help.
|
|
13
|
+
npx @ankurhalder/codebase-snapshot@latest describe --format json
|
|
14
|
+
|
|
15
|
+
# 2. Write a commented config that lists every setting (non-interactive).
|
|
16
|
+
npx @ankurhalder/codebase-snapshot@latest init --yes
|
|
17
|
+
|
|
18
|
+
# 3. Generate and verify.
|
|
19
|
+
npx @ankurhalder/codebase-snapshot@latest generate
|
|
20
|
+
npx @ankurhalder/codebase-snapshot@latest validate
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`describe` returns the invocation that works, an ordered `workflow` array, every command,
|
|
24
|
+
every option with its default, the exit-code contract, all 25 presets, the artifact list,
|
|
25
|
+
the config file names, the output layout, safety rules and a troubleshooting table — all
|
|
26
|
+
as JSON on stdout.
|
|
27
|
+
|
|
28
|
+
**Always pin the tag** (`@latest` or `@2`). A bare scoped spec can resolve to a bin-less
|
|
29
|
+
placeholder manifest on some npm builds and exit 0 printing nothing; the pinned form
|
|
30
|
+
cannot.
|
|
31
|
+
|
|
32
|
+
## The skill
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx @ankurhalder/codebase-snapshot@latest skill # print it (stdout)
|
|
36
|
+
npx @ankurhalder/codebase-snapshot@latest skill --install # write it into the repo
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Printing goes to stdout deliberately, so it can be redirected:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx @ankurhalder/codebase-snapshot@latest skill > SKILL.md
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`--install` writes the same skill to every location agents look at by default:
|
|
46
|
+
|
|
47
|
+
| Target | Path | Read by |
|
|
48
|
+
| :--- | :--- | :--- |
|
|
49
|
+
| `agents` | `AGENTS.md` (a marked section) | most tools, by convention |
|
|
50
|
+
| `claude` | `.claude/skills/codebase-snapshot/SKILL.md` | Claude Code auto-discovery |
|
|
51
|
+
| `cursor` | `.cursor/rules/codebase-snapshot.mdc` | Cursor rules |
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
skill --install --target claude # one location
|
|
55
|
+
skill --install # all three (default)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The install is **idempotent and non-destructive**: re-running replaces only the block
|
|
59
|
+
between `<!-- codebase-snapshot:skill:start -->` and
|
|
60
|
+
`<!-- codebase-snapshot:skill:end -->`, so an `AGENTS.md` that already documents your
|
|
61
|
+
conventions keeps them. `--format json` reports what was created, updated or unchanged.
|
|
62
|
+
|
|
63
|
+
`snap init` prints a reminder about this; it never installs the skill on its own.
|
|
64
|
+
|
|
65
|
+
## Why both a contract and a skill
|
|
66
|
+
|
|
67
|
+
The contract is for **doing** — it is the data an agent needs to pick correct commands and
|
|
68
|
+
options, and it is asserted against the real defaults in the test suite so it cannot drift
|
|
69
|
+
into lying.
|
|
70
|
+
|
|
71
|
+
The skill is for **knowing when to act** — it carries the trigger conditions, the ordered
|
|
72
|
+
workflow, and the surprises (sensitive files excluded by default, secrets redacted, the
|
|
73
|
+
output directory being tool-owned) that an agent cannot infer from a schema.
|
|
74
|
+
|
|
75
|
+
## Keeping the contract honest
|
|
76
|
+
|
|
77
|
+
`describe` is generated from the same code the CLI runs — the preset list, artifact names,
|
|
78
|
+
schema version and generator version are read directly, and a test compares its documented
|
|
79
|
+
defaults against a real `generate --dry-run` manifest. If a default changes, the test fails
|
|
80
|
+
rather than the contract silently misleading an agent.
|
package/docs/install.md
CHANGED