codebase-snapshot 0.21.0 → 0.22.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/dist/index.d.ts CHANGED
@@ -1,8 +1,184 @@
1
1
  import * as node_crypto from 'node:crypto';
2
- import { S as SecretRule, D as DiscoveryMode, a as SkipRecord, J as JsonSummary, M as MarkdownSummary, b as SourceSummary, c as SnapshotConfig, K as KindRule, L as LayerRule, R as ResolvedSnapshotConfig, B as ByteSize, C as CliOptions, d as PartMetadata, F as FileEntry, T as TextEncoding, e as SecretFinding, V as ValidationResult, f as Manifest, E as EdgeProvenance, g as TrustEnvelope, A as ArtifactSelection } from './types-D5XYzksd.js';
3
- export { h as BudgetConfig, i as CoverageStatus, j as DeclarationSpan, k as FreshnessStatus, H as HooksConfig, I as ImportBinding, l as InclusionMode, m as IncompleteFile, n as IndexSourceKind, o as ManifestArtifact, p as ManifestConfigSnapshot, q as ManifestIndexes, r as ManifestTotals, s as Mode, O as OutputFormat, t as OwnerBrief, u as PartFileEntry, P as PromptTask, v as ReExportBinding, w as ResolvedArtifacts, x as ResolvedBudgets, y as SecretRuleInput, z as SkipReason, G as SummaryQuality, N as TruncationReason, Q as ValidationDrift } from './types-D5XYzksd.js';
2
+ import { E as EdgeProvenance, M as Manifest, T as TrustEnvelope, S as SecretRule, D as DiscoveryMode, a as SkipRecord, J as JsonSummary, b as MarkdownSummary, c as SourceSummary, d as SnapshotConfig, K as KindRule, L as LayerRule, R as ResolvedSnapshotConfig, B as ByteSize, C as CliOptions, e as PartMetadata, F as FileEntry, f as TextEncoding, g as SecretFinding, V as ValidationResult, A as ArtifactSelection } from './types-DQXKiaXk.js';
3
+ export { h as BudgetConfig, i as CoverageStatus, j as DeclarationSpan, k as FreshnessStatus, H as HooksConfig, I as ImportBinding, l as InclusionMode, m as IncompleteFile, n as IndexSourceKind, o as ManifestArtifact, p as ManifestConfigSnapshot, q as ManifestIndexes, r as ManifestTotals, s as Mode, O as OutputFormat, t as OwnerBrief, u as PartFileEntry, P as PromptTask, v as ReExportBinding, w as ResolvedArtifacts, x as ResolvedBudgets, y as SecretRuleInput, z as SkipReason, G as SummaryQuality, N as TruncationReason, Q as ValidationDrift } from './types-DQXKiaXk.js';
4
4
  import ts from 'typescript';
5
- export { w as workerEntry } from './generate-worker-DakxZs-l.js';
5
+ export { w as workerEntry } from './generate-worker-TUMvHlgz.js';
6
+
7
+ declare const DEFAULT_MAX_PROGRAM_FILES = 2500;
8
+ type PrecisionMode = "ts-semantic" | "syntactic-fallback";
9
+ interface TsProgramFile {
10
+ relativePath: string;
11
+ content?: string;
12
+ }
13
+ interface ScopedProgramOptions {
14
+ root: string;
15
+ files: readonly TsProgramFile[];
16
+ maxProgramFiles?: number;
17
+ timeoutMs?: number;
18
+ }
19
+ interface ScopedProgram {
20
+ root: string;
21
+ program: ts.Program | null;
22
+ checker: ts.TypeChecker | null;
23
+ fileCount: number;
24
+ precisionMode: PrecisionMode;
25
+ coverage: "complete" | "partial";
26
+ reasons: string[];
27
+ deadline: number;
28
+ }
29
+ interface SymbolReference {
30
+ path: string;
31
+ line: number;
32
+ column: number;
33
+ name: string;
34
+ isDefinition: boolean;
35
+ confidence: "ts-semantic";
36
+ }
37
+ interface SymbolReferencesOptions extends ScopedProgramOptions {
38
+ symbolName: string;
39
+ targetPath?: string;
40
+ maxResults?: number;
41
+ }
42
+ interface SymbolReferencesResult {
43
+ symbol: string;
44
+ targetPath?: string;
45
+ precisionMode: PrecisionMode;
46
+ coverage: "complete" | "partial";
47
+ truncated: boolean;
48
+ reasons: string[];
49
+ references: SymbolReference[];
50
+ }
51
+ interface PreciseCallersOptions extends ScopedProgramOptions {
52
+ changedFiles: readonly string[];
53
+ changedSymbols: Readonly<Record<string, readonly string[]>>;
54
+ }
55
+ interface PreciseCallersResult {
56
+ precisionMode: PrecisionMode;
57
+ coverage: "complete" | "partial";
58
+ reasons: string[];
59
+ callers: Array<{
60
+ path: string;
61
+ symbol: string;
62
+ references: SymbolReference[];
63
+ }>;
64
+ }
65
+ interface SymbolQueryTarget {
66
+ symbolName: string;
67
+ targetPath?: string;
68
+ }
69
+ interface MultiSymbolReferencesOptions extends ScopedProgramOptions {
70
+ targets: readonly SymbolQueryTarget[];
71
+ maxResults?: number;
72
+ }
73
+ interface MultiSymbolReferencesResult {
74
+ precisionMode: PrecisionMode;
75
+ coverage: "complete" | "partial";
76
+ truncated: boolean;
77
+ reasons: string[];
78
+ results: Array<{
79
+ symbol: string;
80
+ targetPath?: string;
81
+ references: SymbolReference[];
82
+ }>;
83
+ }
84
+ declare function createScopedProgram(options: ScopedProgramOptions): ScopedProgram;
85
+ declare function findMultipleSymbolReferences(options: MultiSymbolReferencesOptions): MultiSymbolReferencesResult;
86
+ declare function findSymbolReferences(options: SymbolReferencesOptions): SymbolReferencesResult;
87
+ declare function resolvePreciseChangedCallers(options: PreciseCallersOptions): PreciseCallersResult;
88
+
89
+ type ImpactBaseKind = "diff" | "paths";
90
+ type ImpactLevel = "direct-symbol" | "file-import" | "type-only" | "reexport" | "namespace-or-cjs";
91
+ interface ImpactBase {
92
+ kind: ImpactBaseKind;
93
+ value: string;
94
+ }
95
+ interface ImpactChangeRequest {
96
+ diff?: string;
97
+ paths?: readonly string[];
98
+ }
99
+ interface ImpactChanges {
100
+ base: ImpactBase;
101
+ paths: string[];
102
+ detail: string;
103
+ }
104
+ interface ImpactChangedFile {
105
+ path: string;
106
+ inSnapshot: boolean;
107
+ deleted: boolean;
108
+ reason?: string;
109
+ }
110
+ interface ImpactAffectedFile {
111
+ path: string;
112
+ distance: number;
113
+ via: string;
114
+ specifier: string;
115
+ confidence?: EdgeProvenance;
116
+ impactKind?: ImpactLevel;
117
+ matchedSymbols?: string[];
118
+ }
119
+ interface ImpactTestFile {
120
+ path: string;
121
+ covers: string[];
122
+ reason: "imports-changed" | "imports-affected";
123
+ }
124
+ interface ImpactUnresolvedImport {
125
+ path: string;
126
+ specifier: string;
127
+ }
128
+ interface ImpactRoute {
129
+ path: string;
130
+ methods: string[];
131
+ }
132
+ interface ImpactReport {
133
+ schemaVersion: 1;
134
+ base: ImpactBase;
135
+ snapshot: {
136
+ manifest: string;
137
+ fingerprint: string;
138
+ generatedAt: string;
139
+ git: {
140
+ commit: string;
141
+ isDirty: boolean;
142
+ };
143
+ };
144
+ changed: ImpactChangedFile[];
145
+ affected: ImpactAffectedFile[];
146
+ tests: ImpactTestFile[];
147
+ unresolved: ImpactUnresolvedImport[];
148
+ routesAffected?: ImpactRoute[];
149
+ prunedByBarrel?: number;
150
+ cycles?: string[][];
151
+ imports?: Record<string, string[]>;
152
+ precise?: {
153
+ references: SymbolReference[];
154
+ coverage: "complete" | "partial";
155
+ reasons: string[];
156
+ };
157
+ trust: TrustEnvelope;
158
+ truncated: boolean;
159
+ limits: {
160
+ depth: number;
161
+ maxResults: number;
162
+ affected: number;
163
+ };
164
+ warnings: string[];
165
+ }
166
+ interface ImpactInput {
167
+ manifest: Manifest;
168
+ cwd: string;
169
+ changes: ImpactChanges;
170
+ manifestPath?: string;
171
+ depth?: number;
172
+ maxResults?: number;
173
+ symbols?: readonly string[];
174
+ changedLines?: ReadonlyMap<string, Array<[number, number]>>;
175
+ includeImports?: boolean;
176
+ includeCycles?: boolean;
177
+ trust?: TrustEnvelope;
178
+ }
179
+ declare function resolveImpactChanges(cwd: string, request: ImpactChangeRequest): ImpactChanges;
180
+ declare function computeImpact(input: ImpactInput): ImpactReport;
181
+ declare function renderImpactText(report: ImpactReport): string;
6
182
 
7
183
  interface GitInfo {
8
184
  branch: string;
@@ -566,7 +742,7 @@ declare function validateSnapshot(configInput: ResolvedSnapshotConfig | Snapshot
566
742
  * `package.json` carries the same version; `npm run verify` compares the two.
567
743
  */
568
744
  declare const GENERATOR_NAME = "codebase-snapshot";
569
- declare const GENERATOR_VERSION = "0.21.0";
745
+ declare const GENERATOR_VERSION = "0.22.0";
570
746
  /**
571
747
  * The manifest and ownership-marker schema this build writes and understands.
572
748
  *
@@ -1000,182 +1176,6 @@ declare function loadManifest(target: string): Manifest;
1000
1176
  /** Renders a diff for a terminal. */
1001
1177
  declare function renderDiffText(diff: ManifestDiff): string;
1002
1178
 
1003
- declare const DEFAULT_MAX_PROGRAM_FILES = 2500;
1004
- type PrecisionMode = "ts-semantic" | "syntactic-fallback";
1005
- interface TsProgramFile {
1006
- relativePath: string;
1007
- content?: string;
1008
- }
1009
- interface ScopedProgramOptions {
1010
- root: string;
1011
- files: readonly TsProgramFile[];
1012
- maxProgramFiles?: number;
1013
- timeoutMs?: number;
1014
- }
1015
- interface ScopedProgram {
1016
- root: string;
1017
- program: ts.Program | null;
1018
- checker: ts.TypeChecker | null;
1019
- fileCount: number;
1020
- precisionMode: PrecisionMode;
1021
- coverage: "complete" | "partial";
1022
- reasons: string[];
1023
- deadline: number;
1024
- }
1025
- interface SymbolReference {
1026
- path: string;
1027
- line: number;
1028
- column: number;
1029
- name: string;
1030
- isDefinition: boolean;
1031
- confidence: "ts-semantic";
1032
- }
1033
- interface SymbolReferencesOptions extends ScopedProgramOptions {
1034
- symbolName: string;
1035
- targetPath?: string;
1036
- maxResults?: number;
1037
- }
1038
- interface SymbolReferencesResult {
1039
- symbol: string;
1040
- targetPath?: string;
1041
- precisionMode: PrecisionMode;
1042
- coverage: "complete" | "partial";
1043
- truncated: boolean;
1044
- reasons: string[];
1045
- references: SymbolReference[];
1046
- }
1047
- interface PreciseCallersOptions extends ScopedProgramOptions {
1048
- changedFiles: readonly string[];
1049
- changedSymbols: Readonly<Record<string, readonly string[]>>;
1050
- }
1051
- interface PreciseCallersResult {
1052
- precisionMode: PrecisionMode;
1053
- coverage: "complete" | "partial";
1054
- reasons: string[];
1055
- callers: Array<{
1056
- path: string;
1057
- symbol: string;
1058
- references: SymbolReference[];
1059
- }>;
1060
- }
1061
- interface SymbolQueryTarget {
1062
- symbolName: string;
1063
- targetPath?: string;
1064
- }
1065
- interface MultiSymbolReferencesOptions extends ScopedProgramOptions {
1066
- targets: readonly SymbolQueryTarget[];
1067
- maxResults?: number;
1068
- }
1069
- interface MultiSymbolReferencesResult {
1070
- precisionMode: PrecisionMode;
1071
- coverage: "complete" | "partial";
1072
- truncated: boolean;
1073
- reasons: string[];
1074
- results: Array<{
1075
- symbol: string;
1076
- targetPath?: string;
1077
- references: SymbolReference[];
1078
- }>;
1079
- }
1080
- declare function createScopedProgram(options: ScopedProgramOptions): ScopedProgram;
1081
- declare function findMultipleSymbolReferences(options: MultiSymbolReferencesOptions): MultiSymbolReferencesResult;
1082
- declare function findSymbolReferences(options: SymbolReferencesOptions): SymbolReferencesResult;
1083
- declare function resolvePreciseChangedCallers(options: PreciseCallersOptions): PreciseCallersResult;
1084
-
1085
- type ImpactBaseKind = "diff" | "paths";
1086
- type ImpactLevel = "direct-symbol" | "file-import" | "type-only" | "reexport" | "namespace-or-cjs";
1087
- interface ImpactBase {
1088
- kind: ImpactBaseKind;
1089
- value: string;
1090
- }
1091
- interface ImpactChangeRequest {
1092
- diff?: string;
1093
- paths?: readonly string[];
1094
- }
1095
- interface ImpactChanges {
1096
- base: ImpactBase;
1097
- paths: string[];
1098
- detail: string;
1099
- }
1100
- interface ImpactChangedFile {
1101
- path: string;
1102
- inSnapshot: boolean;
1103
- deleted: boolean;
1104
- reason?: string;
1105
- }
1106
- interface ImpactAffectedFile {
1107
- path: string;
1108
- distance: number;
1109
- via: string;
1110
- specifier: string;
1111
- confidence?: EdgeProvenance;
1112
- impactKind?: ImpactLevel;
1113
- matchedSymbols?: string[];
1114
- }
1115
- interface ImpactTestFile {
1116
- path: string;
1117
- covers: string[];
1118
- reason: "imports-changed" | "imports-affected";
1119
- }
1120
- interface ImpactUnresolvedImport {
1121
- path: string;
1122
- specifier: string;
1123
- }
1124
- interface ImpactRoute {
1125
- path: string;
1126
- methods: string[];
1127
- }
1128
- interface ImpactReport {
1129
- schemaVersion: 1;
1130
- base: ImpactBase;
1131
- snapshot: {
1132
- manifest: string;
1133
- fingerprint: string;
1134
- generatedAt: string;
1135
- git: {
1136
- commit: string;
1137
- isDirty: boolean;
1138
- };
1139
- };
1140
- changed: ImpactChangedFile[];
1141
- affected: ImpactAffectedFile[];
1142
- tests: ImpactTestFile[];
1143
- unresolved: ImpactUnresolvedImport[];
1144
- routesAffected?: ImpactRoute[];
1145
- prunedByBarrel?: number;
1146
- cycles?: string[][];
1147
- imports?: Record<string, string[]>;
1148
- precise?: {
1149
- references: SymbolReference[];
1150
- coverage: "complete" | "partial";
1151
- reasons: string[];
1152
- };
1153
- trust: TrustEnvelope;
1154
- truncated: boolean;
1155
- limits: {
1156
- depth: number;
1157
- maxResults: number;
1158
- affected: number;
1159
- };
1160
- warnings: string[];
1161
- }
1162
- interface ImpactInput {
1163
- manifest: Manifest;
1164
- cwd: string;
1165
- changes: ImpactChanges;
1166
- manifestPath?: string;
1167
- depth?: number;
1168
- maxResults?: number;
1169
- symbols?: readonly string[];
1170
- changedLines?: ReadonlyMap<string, Array<[number, number]>>;
1171
- includeImports?: boolean;
1172
- includeCycles?: boolean;
1173
- trust?: TrustEnvelope;
1174
- }
1175
- declare function resolveImpactChanges(cwd: string, request: ImpactChangeRequest): ImpactChanges;
1176
- declare function computeImpact(input: ImpactInput): ImpactReport;
1177
- declare function renderImpactText(report: ImpactReport): string;
1178
-
1179
1179
  interface GitignoreUpdate {
1180
1180
  /** The entries this call appended, in the order written. */
1181
1181
  added: string[];
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { ARTIFACT_NAMES, CHECK_INTERVAL_MS, CONFIG_KEYS, DEFAULT_ANSWERS, DEFAULT_MAX_PROGRAM_FILES, DEFAULT_SECRET_PATTERNS, FAILURE_INTERVAL_MS, GENERATOR_NAME, GENERATOR_VERSION, HOOK_MARKER, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, MIN_MAX_PART_TOKENS, PACKAGE_LATEST_URL, PRESETS, PromptBack, PromptCancelled, REQUEST_TIMEOUT_MS, SCHEMA_VERSION, UP_TO_DATE_INTERVAL_MS, anchorForPath, appendGitignoreEntries, assertPublicHost, assertReplaceable, assertServerSafeConfig, assertUsableConfigInput, assertUsableRef, auditSnapshot, buildBrief, buildImportResolver, bytesForTokens, cacheDirectory, cacheFilePath, checkForUpdate, classifyKind, classifyLayer, cloneRepository, collectFiles, compareManifests, computeImpact, configDigest, countInvalidUtf8Bytes, countLines, crc32, createScopedProgram, decodeText, defineConfig, detectLanguage, detectPreset, displayPath, displayWidth, enforceBudget, estimateTokens, explainPath, fenceForContent, fenceForText, fetchLatestVersion, findMultipleSymbolReferences, findSecretInPath, findSymbolReferences, firstRunMessage, formatTokens, formatUpdateNotice, generateProjectTree, generateSarifReport, generateSnapshot, generateSnapshotAsync, getGitInfo, getPreset, gitignorePath, globToRegExp, hasPriorSnapshot, importsChangedFile, importsOfFile, importsOfText, installKind, installPreCommitHook, isBinaryBuffer, isBinaryExtension, isBinaryFile, isEffectivelyEmpty, isInteractive, isNewer, isPrivateHost, isResolvedConfig, isSensitivePath, isSkeletonizable, isTsxFileName, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, lockPathFor, makeCloneDirectory, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, parseRemoteSource, partitionFiles, planFirstRun, planTestRun, profileForPath, releaseAbandonedRun, renderConfig, renderDiffText, renderExplainText, renderImpactText, renumberParts, resolveChangedScope, resolveConfig, resolveDiffBase, resolveDiffChangedLines, resolveImpactChanges, resolveLatest, resolvePreciseChangedCallers, resolveSafeOutputDirs, resolveSpecifier, resolveSpecifierDetailed, runInit, runTestPlan, scanAndRedactSecrets, shouldCheck, skeletonizeTypeScript, startWebServer, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, tokenAllowedForHost, treeTruncationWarnings, truncatePreview, truncateToBytes, tsconfigFromWorkspace, tsconfigPathsFor, updateCommand, validateSnapshot, walkFiles, workerEntry, workspaceResolutionFor, wrapLines, writeZip } from './chunk-TDPYLX7X.js';
1
+ export { ARTIFACT_NAMES, CHECK_INTERVAL_MS, CONFIG_KEYS, DEFAULT_ANSWERS, DEFAULT_MAX_PROGRAM_FILES, DEFAULT_SECRET_PATTERNS, FAILURE_INTERVAL_MS, GENERATOR_NAME, GENERATOR_VERSION, HOOK_MARKER, LANGUAGE_PROFILES, MIN_MAX_PART_BYTES, MIN_MAX_PART_TOKENS, PACKAGE_LATEST_URL, PRESETS, PromptBack, PromptCancelled, REQUEST_TIMEOUT_MS, SCHEMA_VERSION, UP_TO_DATE_INTERVAL_MS, anchorForPath, appendGitignoreEntries, assertPublicHost, assertReplaceable, assertServerSafeConfig, assertUsableConfigInput, assertUsableRef, auditSnapshot, buildBrief, buildImportResolver, bytesForTokens, cacheDirectory, cacheFilePath, checkForUpdate, classifyKind, classifyLayer, cloneRepository, collectFiles, compareManifests, computeImpact, configDigest, countInvalidUtf8Bytes, countLines, crc32, createScopedProgram, decodeText, defineConfig, detectLanguage, detectPreset, displayPath, displayWidth, enforceBudget, estimateTokens, explainPath, fenceForContent, fenceForText, fetchLatestVersion, findMultipleSymbolReferences, findSecretInPath, findSymbolReferences, firstRunMessage, formatTokens, formatUpdateNotice, generateProjectTree, generateSarifReport, generateSnapshot, generateSnapshotAsync, getGitInfo, getPreset, gitignorePath, globToRegExp, hasPriorSnapshot, importsChangedFile, importsOfFile, importsOfText, installKind, installPreCommitHook, isBinaryBuffer, isBinaryExtension, isBinaryFile, isEffectivelyEmpty, isInteractive, isNewer, isPrivateHost, isResolvedConfig, isSensitivePath, isSkeletonizable, isTsxFileName, listPresetNames, loadConfigFile, loadConfigFileDetailed, loadManifest, lockPathFor, makeCloneDirectory, markResolvedConfig, matchRule, matchesExclude, normalizeResolvedConfig, parseByteSize, parseRemoteSource, partitionFiles, planFirstRun, planTestRun, profileForPath, releaseAbandonedRun, renderConfig, renderDiffText, renderExplainText, renderImpactText, renumberParts, resolveChangedScope, resolveConfig, resolveDiffBase, resolveDiffChangedLines, resolveImpactChanges, resolveLatest, resolvePreciseChangedCallers, resolveSafeOutputDirs, resolveSpecifier, resolveSpecifierDetailed, runInit, runTestPlan, scanAndRedactSecrets, shouldCheck, skeletonizeTypeScript, startWebServer, stripJsonComments, summarizeJson, summarizeMarkdown, summarizeTypeScriptSource, summarizeWithProfile, supportsTypeScriptImports, tokenAllowedForHost, treeTruncationWarnings, truncatePreview, truncateToBytes, tsconfigFromWorkspace, tsconfigPathsFor, updateCommand, validateSnapshot, walkFiles, workerEntry, workspaceResolutionFor, wrapLines, writeZip } from './chunk-NPCDJBE4.js';
package/dist/mcp.cjs CHANGED
@@ -2980,7 +2980,7 @@ function verifySnapshotSignature(snapshotDir) {
2980
2980
 
2981
2981
  // src/version.ts
2982
2982
  var GENERATOR_NAME = "codebase-snapshot";
2983
- var GENERATOR_VERSION = "0.21.0";
2983
+ var GENERATOR_VERSION = "0.22.0";
2984
2984
  var SCHEMA_VERSION = "3.0.0";
2985
2985
  var LEGACY_GENERATOR_NAMES = ["@ankurhalder/codebase-snapshot"];
2986
2986
  function isOurGeneratorName(name) {
@@ -14789,6 +14789,25 @@ var COMMAND_OPTION_SCOPE = {
14789
14789
  "help",
14790
14790
  "version"
14791
14791
  ],
14792
+ guard: [
14793
+ "hook",
14794
+ "changed",
14795
+ "max-chars",
14796
+ "diff",
14797
+ "paths",
14798
+ "depth",
14799
+ "max-results",
14800
+ "no-cache",
14801
+ "no-live",
14802
+ "cwd",
14803
+ "out-dir",
14804
+ "no-config",
14805
+ "format",
14806
+ "mode",
14807
+ "no-update-check",
14808
+ "help",
14809
+ "version"
14810
+ ],
14792
14811
  brief: [
14793
14812
  "diff",
14794
14813
  "paths",
@@ -14941,6 +14960,7 @@ var COMMAND_ORDER = [
14941
14960
  "health",
14942
14961
  "report",
14943
14962
  "impact",
14963
+ "guard",
14944
14964
  "brief",
14945
14965
  "explain",
14946
14966
  "update",
@@ -15094,6 +15114,13 @@ function buildAgentContract() {
15094
15114
  positionals: [],
15095
15115
  exits: [0, 1, 2]
15096
15116
  },
15117
+ {
15118
+ name: "guard",
15119
+ aliases: [],
15120
+ summary: "Check whether a change is complete: untouched consumers, candidate tests, affected routes, and a trust stamp, in one small report. With --hook <claude|copilot|codex|raw>, read one hook payload from stdin and emit the host-shaped additionalContext, or an empty object when there is nothing to say. Defaults to the working tree against HEAD.",
15121
+ positionals: [],
15122
+ exits: [0, 1, 2]
15123
+ },
15097
15124
  {
15098
15125
  name: "brief",
15099
15126
  aliases: [],
@@ -15255,6 +15282,27 @@ function buildAgentContract() {
15255
15282
  appliesTo: optionAppliesTo("include-cycles"),
15256
15283
  summary: "impact only: include import cycles in the impacted subgraph."
15257
15284
  },
15285
+ {
15286
+ flag: "--hook",
15287
+ type: "string",
15288
+ default: "unset",
15289
+ appliesTo: optionAppliesTo("hook"),
15290
+ summary: "guard only: read one hook payload from stdin and shape the response for claude, copilot, codex, or raw. Fail-open: an error returns an empty object and a stderr note."
15291
+ },
15292
+ {
15293
+ flag: "--changed",
15294
+ type: "boolean",
15295
+ default: false,
15296
+ appliesTo: optionAppliesTo("changed"),
15297
+ summary: "guard only: check the working tree against HEAD. This is the default when --hook is not given."
15298
+ },
15299
+ {
15300
+ flag: "--max-chars",
15301
+ type: "number",
15302
+ default: 1200,
15303
+ appliesTo: optionAppliesTo("max-chars"),
15304
+ summary: "guard only: cap on the model-facing hook text (minimum 200, maximum 10000)."
15305
+ },
15258
15306
  {
15259
15307
  flag: "--copy",
15260
15308
  type: "boolean",
package/dist/mcp.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-D56JeXwx.cjs';
1
+ export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-BUNhTXkj.cjs';
2
2
  import { Readable, Writable } from 'node:stream';
3
- import './types-D5XYzksd.cjs';
3
+ import './types-DQXKiaXk.cjs';
4
4
 
5
5
  /**
6
6
  * JSON-RPC 2.0 envelopes and the Model Context Protocol revisions this server speaks.
package/dist/mcp.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-DakxZs-l.js';
1
+ export { G as GenerateSummary, W as WorkerResults, g as generateInWorker } from './generate-worker-TUMvHlgz.js';
2
2
  import { Readable, Writable } from 'node:stream';
3
- import './types-D5XYzksd.js';
3
+ import './types-DQXKiaXk.js';
4
4
 
5
5
  /**
6
6
  * JSON-RPC 2.0 envelopes and the Model Context Protocol revisions this server speaks.
package/dist/mcp.js CHANGED
@@ -1,2 +1,2 @@
1
1
  import './chunk-WMEZFLUT.js';
2
- export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, REPORT_RESOURCE_URIS, RESOURCE_TEMPLATE_URIS, SERVER_INSTRUCTIONS, STATIC_RESOURCE_URIS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, generateInWorker, generateToken, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, startHttpTransport, stripComments, validateArguments, windowText } from './chunk-TDPYLX7X.js';
2
+ export { ERROR_CODES, LEGACY_PROTOCOL_VERSIONS, MAX_LINE_BYTES, METHOD, MODERN_PROTOCOL_VERSIONS, REPORT_RESOURCE_URIS, RESOURCE_TEMPLATE_URIS, SERVER_INSTRUCTIONS, STATIC_RESOURCE_URIS, SUPPORTED_PROTOCOL_VERSIONS, buildPrompts, buildResourceProvider, buildTools, classifyRequest, coerceNumericStrings, createLineReader, createMcpServer, createServer, createSession, createWriter, findSection, generateInWorker, generateToken, inspectModernMeta, isCommentStrippable, negotiateLegacyVersion, parsePartSections, runStdioServer, startHttpTransport, stripComments, validateArguments, windowText } from './chunk-NPCDJBE4.js';
@@ -1057,4 +1057,4 @@ interface ValidationResult {
1057
1057
  warnings: string[];
1058
1058
  }
1059
1059
 
1060
- export type { ArtifactSelection as A, ByteSize as B, CliOptions as C, DiscoveryMode as D, EdgeProvenance as E, FileEntry as F, SummaryQuality as G, HooksConfig as H, ImportBinding as I, JsonSummary as J, KindRule as K, LayerRule as L, MarkdownSummary as M, TruncationReason as N, OutputFormat as O, PromptTask as P, ValidationDrift as Q, ResolvedSnapshotConfig as R, SecretRule as S, TextEncoding as T, ValidationResult as V, SkipRecord as a, SourceSummary as b, SnapshotConfig as c, PartMetadata as d, SecretFinding as e, Manifest as f, TrustEnvelope as g, BudgetConfig as h, CoverageStatus as i, DeclarationSpan as j, FreshnessStatus as k, InclusionMode as l, IncompleteFile as m, IndexSourceKind as n, ManifestArtifact as o, ManifestConfigSnapshot as p, ManifestIndexes as q, ManifestTotals as r, Mode as s, OwnerBrief as t, PartFileEntry as u, ReExportBinding as v, ResolvedArtifacts as w, ResolvedBudgets as x, SecretRuleInput as y, SkipReason as z };
1060
+ export type { ArtifactSelection as A, ByteSize as B, CliOptions as C, DiscoveryMode as D, EdgeProvenance as E, FileEntry as F, SummaryQuality as G, HooksConfig as H, ImportBinding as I, JsonSummary as J, KindRule as K, LayerRule as L, Manifest as M, TruncationReason as N, OutputFormat as O, PromptTask as P, ValidationDrift as Q, ResolvedSnapshotConfig as R, SecretRule as S, TrustEnvelope as T, ValidationResult as V, SkipRecord as a, MarkdownSummary as b, SourceSummary as c, SnapshotConfig as d, PartMetadata as e, TextEncoding as f, SecretFinding as g, BudgetConfig as h, CoverageStatus as i, DeclarationSpan as j, FreshnessStatus as k, InclusionMode as l, IncompleteFile as m, IndexSourceKind as n, ManifestArtifact as o, ManifestConfigSnapshot as p, ManifestIndexes as q, ManifestTotals as r, Mode as s, OwnerBrief as t, PartFileEntry as u, ReExportBinding as v, ResolvedArtifacts as w, ResolvedBudgets as x, SecretRuleInput as y, SkipReason as z };
@@ -1057,4 +1057,4 @@ interface ValidationResult {
1057
1057
  warnings: string[];
1058
1058
  }
1059
1059
 
1060
- export type { ArtifactSelection as A, ByteSize as B, CliOptions as C, DiscoveryMode as D, EdgeProvenance as E, FileEntry as F, SummaryQuality as G, HooksConfig as H, ImportBinding as I, JsonSummary as J, KindRule as K, LayerRule as L, MarkdownSummary as M, TruncationReason as N, OutputFormat as O, PromptTask as P, ValidationDrift as Q, ResolvedSnapshotConfig as R, SecretRule as S, TextEncoding as T, ValidationResult as V, SkipRecord as a, SourceSummary as b, SnapshotConfig as c, PartMetadata as d, SecretFinding as e, Manifest as f, TrustEnvelope as g, BudgetConfig as h, CoverageStatus as i, DeclarationSpan as j, FreshnessStatus as k, InclusionMode as l, IncompleteFile as m, IndexSourceKind as n, ManifestArtifact as o, ManifestConfigSnapshot as p, ManifestIndexes as q, ManifestTotals as r, Mode as s, OwnerBrief as t, PartFileEntry as u, ReExportBinding as v, ResolvedArtifacts as w, ResolvedBudgets as x, SecretRuleInput as y, SkipReason as z };
1060
+ export type { ArtifactSelection as A, ByteSize as B, CliOptions as C, DiscoveryMode as D, EdgeProvenance as E, FileEntry as F, SummaryQuality as G, HooksConfig as H, ImportBinding as I, JsonSummary as J, KindRule as K, LayerRule as L, Manifest as M, TruncationReason as N, OutputFormat as O, PromptTask as P, ValidationDrift as Q, ResolvedSnapshotConfig as R, SecretRule as S, TrustEnvelope as T, ValidationResult as V, SkipRecord as a, MarkdownSummary as b, SourceSummary as c, SnapshotConfig as d, PartMetadata as e, TextEncoding as f, SecretFinding as g, BudgetConfig as h, CoverageStatus as i, DeclarationSpan as j, FreshnessStatus as k, InclusionMode as l, IncompleteFile as m, IndexSourceKind as n, ManifestArtifact as o, ManifestConfigSnapshot as p, ManifestIndexes as q, ManifestTotals as r, Mode as s, OwnerBrief as t, PartFileEntry as u, ReExportBinding as v, ResolvedArtifacts as w, ResolvedBudgets as x, SecretRuleInput as y, SkipReason as z };
package/docs/cli.md CHANGED
@@ -61,6 +61,7 @@ as it makes it.
61
61
  - [`health`](#health)
62
62
  - [`report`](#report)
63
63
  - [`impact`](#impact)
64
+ - [`guard`](#guard)
64
65
  - [`brief`](#brief)
65
66
  - [`setup`](#setup)
66
67
  - [`init`](#init)
@@ -103,7 +104,7 @@ Exit `0` when the snapshot passes its own integrity check, `1` when it does not.
103
104
 
104
105
  ```
105
106
  📸 Generating snapshot for: /path/to/repo
106
- Branch: main (fallback) | Part budget: 300 KB | Generator: 0.21.0 (project dependency ^0.21.0)
107
+ Branch: main (fallback) | Part budget: 300 KB | Generator: 0.22.0 (project dependency ^0.22.0)
107
108
 
108
109
  ✅ Snapshot generated in 0.14s:
109
110
  - Tracked files: 121 included of 128 paths found — 7 skipped (default-ignore 5, binary 1, sensitive-file 1); every one is listed in snapshot/reports/audit.md
@@ -239,6 +240,28 @@ human report to stderr, like every other human-facing command.
239
240
 
240
241
  → [Impact reports](impact.md): the field contract, resolution rules and what the report does not claim.
241
242
 
243
+ ### `guard`
244
+
245
+ ~~~bash
246
+ codebase-snapshot guard --changed
247
+ codebase-snapshot guard --paths src/auth.ts --format json
248
+ codebase-snapshot guard --hook claude < payload.json
249
+ ~~~
250
+
251
+ Checks whether a change is complete: untouched consumers, candidate tests and affected routes,
252
+ minus everything the change already touched. It uses the same live index and import resolver as
253
+ `impact`, so no `generate` run is required. The report is bounded to 10 consumers, 5 tests and
254
+ 5 routes; when it is cut, `truncated` is true and `omitted` records the counts.
255
+
256
+ `--hook <claude|copilot|codex|raw>` reads one JSON payload from stdin and writes the host-shaped
257
+ `additionalContext` to stdout, or `{}` when there is nothing to report. It is fail-open: an error
258
+ returns `{}` and a note on stderr, so a broken guard cannot fail an agent turn.
259
+
260
+ Exit `0` when the check ran (including a clean report and a hook returning `{}`), `1` when the
261
+ live index cannot be built or `--no-live` has no manifest, and `2` for a usage error.
262
+
263
+ → [Change Guard](guard.md): hook setup for Claude Code, Copilot and Codex, and what it does not claim.
264
+
242
265
  ### `brief`
243
266
 
244
267
  ```bash
@@ -279,7 +302,7 @@ The whole first run in one command, with defaults and no prompts. This is the sa
279
302
  🚀 Setup for: /path/to/repo
280
303
  ✅ Created snapshot.config.json (preset: nextjs)
281
304
  Added npm scripts: snapshot, snapshot:validate
282
- Added devDependency: codebase-snapshot ^0.21.0
305
+ Added devDependency: codebase-snapshot ^0.22.0
283
306
  Added to .gitignore: /snapshot/, /snapshot.tmp/
284
307
  ⏳ Installing dependencies…
285
308
  ✅ Installed dependencies (npm install, 2.1s)
@@ -331,7 +354,7 @@ It also has three side effects on files you own, and it says so when it does the
331
354
  ```
332
355
  ✅ Created snapshot.config.json (preset: node-lib)
333
356
  Added npm scripts: snapshot, snapshot:validate
334
- Added devDependency: codebase-snapshot ^0.21.0
357
+ Added devDependency: codebase-snapshot ^0.22.0
335
358
  Added to .gitignore: /snapshot/, /snapshot.tmp/
336
359
  ```
337
360
 
@@ -481,8 +504,8 @@ agent](agent.md).
481
504
  Ask the npm registry whether a newer release exists, and print the version it compared against:
482
505
 
483
506
  ```bash
484
- npx codebase-snapshot@0.21.0 update # is this build current? print the answer
485
- npx codebase-snapshot@0.21.0 update --format json
507
+ npx codebase-snapshot@0.22.0 update # is this build current? print the answer
508
+ npx codebase-snapshot@0.22.0 update --format json
486
509
  ```
487
510
 
488
511
  ```text
@@ -558,8 +581,8 @@ for the two install flags, and the init-and-setup flags list both commands.
558
581
 
559
582
  | Option | Type | Default | Applies to | Meaning |
560
583
  | :--- | :--- | :--- | :--- | :--- |
561
- | `--cwd <path>` | path | current directory | generate, validate, report, impact, brief, explain, init, setup, skill, mcp, health, serve | Repository to operate on. Must exist and be a directory. `diff` and `describe` take no `--cwd`; for `mcp` it chooses the one repository the server serves. |
562
- | `--out-dir <path>` | path | `snapshot` | generate, validate, report, impact, brief, explain, init, setup, health | Where the snapshot is written or read. May be absolute. |
584
+ | `--cwd <path>` | path | current directory | generate, validate, report, impact, guard, brief, explain, init, setup, skill, mcp, health, serve | Repository to operate on. Must exist and be a directory. `diff` and `describe` take no `--cwd`; for `mcp` it chooses the one repository the server serves. |
585
+ | `--out-dir <path>` | path | `snapshot` | generate, validate, report, impact, guard, brief, explain, init, setup, health | Where the snapshot is written or read. May be absolute. |
563
586
  | `--max-part-bytes <n>` | size | `307200` (300 KB) | generate, validate, init, setup | Hard ceiling per markdown part. Accepts `120k`, `1.5mb`. Minimum 4096. |
564
587
  | `--max-part-tokens <n>` | size | unset | generate, validate, setup | A per-part ceiling in **tokens**, for a context window rather than a disk. Narrows `--max-part-bytes` to the equivalent byte count (`tokens × 4`); the smaller of the two ceilings always wins, and both are recorded in the manifest. Accepts `32k`. Minimum 1024 — below that it is a usage error, not a value quietly raised to the floor. The byte ceiling is what is enforced: `estimatedTokens` is an estimate, and a part whose estimate exceeds the token ceiling is named in a warning rather than silently accepted. |
565
588
  | `--large-file-bytes <n>` | size | the part budget (307200) | generate, validate, explain, setup | Above this, a file becomes a head/tail preview. It may not exceed `--max-part-bytes`: a file between the two could not fit a part. |
@@ -578,7 +601,7 @@ for the two install flags, and the init-and-setup flags list both commands.
578
601
  | `--all-members` | flag | off | health | Audit every snapshot a `--workspace` run wrote, not only the one at `outDir`. The combined score is the weakest member. |
579
602
  | `--deep` | flag | off | health | Replay every full body from the source bytes on disk and compare it with the part. The only allowed difference is a redaction marker. Off by default because it re-reads the repository. |
580
603
  | `--strict` | flag | off | health | `health` only: exit 2 when a critical check fails, and 1 when a warning is the only thing left. Without it a critical check exits 1 and warnings exit 0. |
581
- | `--mode <command>` | string | unset | generate, validate, report, impact, brief, explain, init, setup, diff, describe, skill, mcp, health, update, serve | Select the command when no command word is given. A command word and `--mode` must name the same command; a contradiction is a usage error (exit 2). |
604
+ | `--mode <command>` | string | unset | generate, validate, report, impact, guard, brief, explain, init, setup, diff, describe, skill, mcp, health, update, serve | Select the command when no command word is given. A command word and `--mode` must name the same command; a contradiction is a usage error (exit 2). |
582
605
  | `--no-update-check` | flag | off | all commands except `update` | Skip the check for a newer published version. Already skipped when stdout is not a terminal, in CI, in a JSON invocation, and in `mcp`, which makes no network requests. `update` exists to contact the registry, so it has no check to skip. |
583
606
  | `--prompt-task <task>` | string | `audit` | generate, validate | `audit`, `review` or `explain` — which job the brief is written for. Changes the opening section, not the standard. |
584
607
  | `--budget-tokens <n>` | count | unset | generate | Fit the snapshot into n tokens by selecting whole files (entry points, then the most-imported). Records a `budget` block; the rest are `not-selected`. See [budget](budget.md). |
@@ -601,21 +624,24 @@ for the two install flags, and the init-and-setup flags list both commands.
601
624
  | `--include-sensitive-files` | flag | off | generate, validate, explain, init, setup | Emit `.env`, `*.pem`, `.npmrc` and similar. Off by default; they are reported as skipped. |
602
625
  | `--skip-artifacts <names>` | list | unset | generate, validate, init, setup | Comma-separated artifacts to omit. |
603
626
  | `--only-artifacts <names>` | list | unset | generate, validate, init, setup | Write *only* these, and **turn on** any this names: a config with `artifacts: { audit: false }` still gets `reports/audit.md` from `--only-artifacts audit`, because "only these" is a statement about the whole selection rather than a suppression list. Cannot be combined with `--skip-artifacts`. |
604
- | `--format <text\|json\|markdown\|pr-comment>` | enum | `text` | generate, validate, report, impact, brief, explain, init, setup, diff, describe, skill, health, update | `json` writes a pure JSON payload to stdout. `impact` and `brief` also accept `markdown`; `pr-comment` renders the same brief with collapsible sections. Every command except `mcp` and `serve` honours `--format` — stdout there is the JSON-RPC protocol stream. |
627
+ | `--format <text\|json\|markdown\|pr-comment>` | enum | `text` | generate, validate, report, impact, guard, brief, explain, init, setup, diff, describe, skill, health, update | `json` writes a pure JSON payload to stdout. `impact` and `brief` also accept `markdown`; `pr-comment` renders the same brief with collapsible sections. Every command except `mcp` and `serve` honours `--format` — stdout there is the JSON-RPC protocol stream. |
605
628
  | `--sarif` | flag | off | generate, validate, setup | Also write `reports/audit.sarif`: the redaction findings as SARIF 2.1.0, for upload to GitHub Code Scanning. The artefact carries the path, the line and the rule — never the value. Works with `--skip-artifacts audit`, because a CI gate does not read markdown. Rule ids are fixed per rule name, so adding a custom rule never re-points an existing alert. |
606
629
  | `--skeleton` | flag | off | generate, validate, setup | Emit signatures instead of bodies: each function or method body becomes `{ /* ... */ }` in place, so formatting and comments around it are untouched. Covers `.ts`, `.tsx`, `.mts`, `.cts`, `.js`, `.jsx`, `.mjs` and `.cjs`; `.d.ts` files are left alone because they are already declarations. The summary still describes the whole file, and affected entries carry `inclusionMode: "signatures"`. `--include-monolith` still writes the whole body, so the monolith's `inclusionMode: "full"` stays true. |
607
630
  | `--changed-since <ref>` | git ref | unset | generate, validate, explain | Include only files changed since this ref, plus untracked ones. Every other file is recorded in `manifest.skipped[]` with reason `unchanged` and is never opened. `validate` re-resolves the scope: a skipped file that has changed since is reported as drift, and one that has not is left alone — and with `--with-dependents`, so is a file that now imports one that changed. `explain` answers with the same rule. A ref beginning with `-` is refused. |
608
- | `--diff <ref>` | git ref | unset | impact, brief | Compare the working tree against this ref for the impact report or change brief. Includes committed, staged, unstaged and untracked changes relative to it. Mutually exclusive with `--paths`; a ref beginning with `-` is refused. |
609
- | `--paths <a,b>` | list | unset | impact, brief | Comma-separated repository-relative paths to treat as the change. Absolute paths and `..` segments are refused. Mutually exclusive with `--diff`. |
610
- | `--depth <n>` | count | `3` | impact, brief | Reverse-import hops to follow for the impact report or change brief. Minimum 1, maximum 8. |
611
- | `--max-results <n>` | count | `200` | impact, brief | Maximum files in `affected[]`. Minimum 1, maximum 1000; a hit sets `truncated` and adds a warning. |
612
- | `--no-cache` | flag | off | impact, brief | Bypass the optional OS live-index summary cache. No cache file is written, and nothing is ever written inside the repository. |
613
- | `--no-live` | flag | off | impact, brief | Require the generated snapshot instead of building or overlaying the live index. |
631
+ | `--diff <ref>` | git ref | unset | impact, guard, brief | Compare the working tree against this ref for the impact report or change brief. Includes committed, staged, unstaged and untracked changes relative to it. Mutually exclusive with `--paths`; a ref beginning with `-` is refused. |
632
+ | `--paths <a,b>` | list | unset | impact, guard, brief | Comma-separated repository-relative paths to treat as the change. Absolute paths and `..` segments are refused. Mutually exclusive with `--diff`. |
633
+ | `--depth <n>` | count | `3` | impact, guard, brief | Reverse-import hops to follow for the impact report or change brief. Minimum 1, maximum 8. |
634
+ | `--max-results <n>` | count | `200` | impact, guard, brief | Maximum files in `affected[]`. Minimum 1, maximum 1000; a hit sets `truncated` and adds a warning. |
635
+ | `--no-cache` | flag | off | impact, guard, brief | Bypass the optional OS live-index summary cache. No cache file is written, and nothing is ever written inside the repository. |
636
+ | `--no-live` | flag | off | impact, guard, brief | Require the generated snapshot instead of building or overlaying the live index. |
614
637
  | `--tests-paths` | flag | off | impact | Print candidate test paths, one per line, instead of the report. |
615
638
  | `--run` | flag | off | impact | Run the repository's own Vitest, Jest or `node --test` entry against the candidate tests. Uses `shell: false`; a build or test configuration change adds a full-suite warning. |
616
639
  | `--precise` | flag | off | impact | Add compiler-resolved symbol references to the report. Requires the live index. |
617
640
  | `--include-imports` | flag | off | impact | Add outgoing dependencies of every changed file. |
618
641
  | `--include-cycles` | flag | off | impact | Add import cycles in the impacted subgraph. |
642
+ | `--hook <client>` | enum | unset | guard | Read one hook payload from stdin and shape the response for `claude`, `copilot`, `codex` or `raw`. Fail-open: an error returns `{}` and a stderr note. |
643
+ | `--changed` | flag | off | guard | Check the working tree against `HEAD`. This is the default when `--hook` is not given. |
644
+ | `--max-chars <n>` | count | `1200` | guard | Cap the model-facing hook text. Minimum 200, maximum 10000. |
619
645
  | `--copy` | flag | off | brief | Copy the finished brief to the platform clipboard. |
620
646
  | `--out <path>` | path | unset | brief | Write the brief to this repository-relative path. A path that resolves outside the repository is refused. |
621
647
  | `--max-tokens <n>` | count | `12000` | brief | Token budget for the assembled brief. |
package/docs/contents.md CHANGED
@@ -16,6 +16,8 @@ Every page on this site, grouped by the job you are doing. If you are new, start
16
16
  ## Core workflows
17
17
 
18
18
  - [Impact reports](impact.md) — what a change reaches and which tests to run.
19
+ - [Change Guard](guard.md) — the untouched consumers, tests and routes after an edit, with a
20
+ hook mode for Claude Code, Copilot and Codex.
19
21
  - [Briefs](brief.md) — one redacted, bounded review pack.
20
22
  - [MCP server](mcp.md) — transports, sessions, resources and protocol details.
21
23
  - [MCP server for a codebase](mcp-server-for-codebase.md) — setup for Claude, Cursor and generic