codebase-snapshot 0.20.13 → 0.21.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 +33 -6
- package/README.md +41 -19
- package/SECURITY.md +2 -2
- package/dist/bin.js +12482 -10348
- package/dist/{chunk-GNVRD7XS.js → chunk-TDPYLX7X.js} +6062 -4438
- package/dist/cli.cjs +11759 -9645
- package/dist/cli.d.cts +76 -2
- package/dist/cli.d.ts +76 -2
- package/dist/cli.js +549 -14
- package/dist/{generate-worker-DMzNbsAW.d.cts → generate-worker-D56JeXwx.d.cts} +2 -2
- package/dist/{generate-worker-CRMESc0b.d.ts → generate-worker-DakxZs-l.d.ts} +2 -2
- package/dist/index.cjs +6037 -4435
- package/dist/index.d.cts +281 -63
- package/dist/index.d.ts +281 -63
- package/dist/index.js +1 -1
- package/dist/mcp.cjs +10231 -4354
- package/dist/mcp.d.cts +13 -7
- package/dist/mcp.d.ts +13 -7
- package/dist/mcp.js +1 -1
- package/dist/{types-C5ytHMYz.d.ts → types-D5XYzksd.d.cts} +50 -2
- package/dist/{types-C5ytHMYz.d.cts → types-D5XYzksd.d.ts} +50 -2
- package/docs/about.md +86 -0
- package/docs/agent.md +28 -6
- package/docs/answer.md +99 -48
- package/docs/benchmarks.md +34 -34
- package/docs/brief.md +80 -81
- package/docs/cli.md +100 -25
- package/docs/codebase-token-budget.md +14 -13
- package/docs/contents.md +66 -0
- package/docs/deploy.md +2 -2
- package/docs/faq.md +112 -0
- package/docs/glossary.md +152 -0
- package/docs/health.md +1 -1
- package/docs/how-to-feed-a-repo-to-claude.md +6 -0
- package/docs/impact.md +102 -0
- package/docs/install.md +4 -3
- package/docs/llm-codebase-context.md +166 -0
- package/docs/mcp-server-for-codebase.md +155 -0
- package/docs/mcp.md +43 -66
- package/docs/migration.md +83 -90
- package/docs/output.md +1 -3
- package/docs/security-review.md +8 -8
- package/docs/slice.md +1 -1
- package/docs/tools.md +159 -185
- package/docs/troubleshooting.md +11 -11
- package/docs/vs-code2prompt.md +7 -0
- package/docs/vs-gitingest.md +7 -0
- package/docs/vs-repomix.md +10 -1
- package/docs/workspace.md +1 -1
- package/package.json +8 -2
package/dist/cli.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import './chunk-WMEZFLUT.js';
|
|
2
|
-
import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, startHttpTransport, buildTools, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, resolveConfig, validateSnapshot, readConfinedText, auditSnapshot, describeManifestShapeProblem, explainPath, compareManifests,
|
|
3
|
-
export { buildAgentContract } from './chunk-
|
|
2
|
+
import { shouldCheck, checkForUpdate, GENERATOR_VERSION, cacheFilePath, formatUpdateNotice, installKind, buildAgentContract, startWebServer, startHttpTransport, buildTools, runStdioServer, parseRemoteSource, assertPublicHost, cloneRepository, makeCloneDirectory, loadConfigFileDetailed, resolveConfig, validateSnapshot, readConfinedText, auditSnapshot, describeManifestShapeProblem, loadManifest, buildLiveIndex, resolveImpactChanges, computeImpact, DEFAULT_MAX_PROGRAM_FILES, findMultipleSymbolReferences, planTestRun, renderImpactText, runTestPlan, briefFromPaths, resolveDiffBase, filterAndRedactDiff, matchesExclude, defaultIgnoreReason, isSensitivePath, findSection, parsePartSections, buildBrief, explainPath, compareManifests, renderDiffText, generateSnapshot, getGitInfo, loadSigningKey, SIGNATURE_FILE, formatNumber, isDiscoveryMode, ARTIFACT_NAMES, COMMAND_OPTION_SCOPE, commandsForOption, getPreset, unknownPresetMessage, GENERATOR_NAME, runInit, installPreCommitHook, PromptCancelled, SKILL_NAME, renderSkill, resolveLatest, isNewer, updateCommand, findConfigFile, planFirstRun, isEffectivelyEmpty, isInteractive, defaultIO, hasPriorSnapshot, DEFAULT_ANSWERS, firstRunMessage, escapeControls, stripJsonComments, parseByteSize, gitignorePath, appendGitignoreEntries, runWithStdoutCapture, inlineCode, findSecretInPath, MIN_MAX_PART_TOKENS, MIN_MAX_PART_BYTES, renderContractText, renderExplainText } from './chunk-TDPYLX7X.js';
|
|
3
|
+
export { buildAgentContract } from './chunk-TDPYLX7X.js';
|
|
4
4
|
import { spawnSync } from 'child_process';
|
|
5
5
|
import * as fs2 from 'fs';
|
|
6
6
|
import * as path2 from 'path';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
7
8
|
import { parseArgs } from 'util';
|
|
8
9
|
|
|
9
|
-
var SKILL_TARGETS = ["claude", "cursor", "all"];
|
|
10
|
+
var SKILL_TARGETS = ["agents", "claude", "cursor", "all"];
|
|
10
11
|
var REFUSED = "Refusing to install the agent skill";
|
|
11
12
|
var LEGACY_AGENTS_MARKER = "<!-- codebase-snapshot:skill:start -->";
|
|
12
13
|
function targetPath(cwd, target) {
|
|
13
14
|
switch (target) {
|
|
15
|
+
case "agents":
|
|
16
|
+
return path2.join(cwd, ".agents", "skills", SKILL_NAME, "SKILL.md");
|
|
14
17
|
case "claude":
|
|
15
18
|
return path2.join(cwd, ".claude", "skills", SKILL_NAME, "SKILL.md");
|
|
16
19
|
case "cursor":
|
|
@@ -69,16 +72,17 @@ function legacyAgentsNote(cwd) {
|
|
|
69
72
|
}
|
|
70
73
|
return `AGENTS.md still contains the section an earlier version installed (between the "${LEGACY_AGENTS_MARKER}" markers). This command no longer edits that file: it is your project's own agent instructions. Delete the block if you do not want it.`;
|
|
71
74
|
}
|
|
72
|
-
function installSkill(cwd, target = "all") {
|
|
75
|
+
function installSkill(cwd, target = "all", options = {}) {
|
|
73
76
|
const skill = renderSkill();
|
|
74
77
|
const written = [];
|
|
75
78
|
const notes = [];
|
|
76
|
-
const wanted = target === "all" ? ["claude", "cursor"] : [target];
|
|
79
|
+
const wanted = target === "all" ? ["agents", "claude", "cursor"] : [target];
|
|
77
80
|
for (const item of wanted) assertWritableInsideRepository(cwd, targetPath(cwd, item));
|
|
78
81
|
const createsSomething = wanted.some((item) => !fs2.existsSync(targetPath(cwd, item)));
|
|
79
82
|
if (createsSomething) {
|
|
80
83
|
assertWritableInsideRepository(cwd, path2.join(cwd, ".gitignore"));
|
|
81
84
|
}
|
|
85
|
+
const pendingMcp = options.withMcp === true ? prepareMcpConfig(cwd) : null;
|
|
82
86
|
for (const item of wanted) {
|
|
83
87
|
written.push(writeIfChanged(item, targetPath(cwd, item), skill));
|
|
84
88
|
}
|
|
@@ -87,7 +91,57 @@ function installSkill(cwd, target = "all") {
|
|
|
87
91
|
if (ignore.note !== null) notes.push(ignore.note);
|
|
88
92
|
const legacy = legacyAgentsNote(cwd);
|
|
89
93
|
if (legacy !== null) notes.push(legacy);
|
|
90
|
-
|
|
94
|
+
let mcp;
|
|
95
|
+
if (pendingMcp !== null) {
|
|
96
|
+
if (pendingMcp.note !== null) notes.push(pendingMcp.note);
|
|
97
|
+
if (pendingMcp.content !== null) {
|
|
98
|
+
fs2.writeFileSync(pendingMcp.filePath, pendingMcp.content, "utf8");
|
|
99
|
+
}
|
|
100
|
+
mcp = { path: pendingMcp.filePath, action: pendingMcp.action };
|
|
101
|
+
}
|
|
102
|
+
return { cwd, written, gitignored: ignore.added, notes, ...mcp === void 0 ? {} : { mcp } };
|
|
103
|
+
}
|
|
104
|
+
function prepareMcpConfig(cwd) {
|
|
105
|
+
const filePath = path2.join(cwd, ".mcp.json");
|
|
106
|
+
assertWritableInsideRepository(cwd, filePath);
|
|
107
|
+
const desired = { command: "npx", args: ["-y", "codebase-snapshot@latest", "mcp"] };
|
|
108
|
+
let parsed = {};
|
|
109
|
+
let existing = null;
|
|
110
|
+
if (fs2.existsSync(filePath)) {
|
|
111
|
+
existing = fs2.readFileSync(filePath, "utf8");
|
|
112
|
+
let candidate;
|
|
113
|
+
try {
|
|
114
|
+
candidate = JSON.parse(existing);
|
|
115
|
+
} catch {
|
|
116
|
+
throw new Error(REFUSED + ": .mcp.json is not valid JSON. Fix it or remove it, then run again.");
|
|
117
|
+
}
|
|
118
|
+
if (candidate === null || typeof candidate !== "object" || Array.isArray(candidate)) {
|
|
119
|
+
throw new Error(REFUSED + ": .mcp.json must contain a JSON object.");
|
|
120
|
+
}
|
|
121
|
+
parsed = candidate;
|
|
122
|
+
}
|
|
123
|
+
const servers = parsed.mcpServers;
|
|
124
|
+
if (servers !== void 0 && (servers === null || typeof servers !== "object" || Array.isArray(servers))) {
|
|
125
|
+
throw new Error(REFUSED + ": .mcp.json#mcpServers must be an object.");
|
|
126
|
+
}
|
|
127
|
+
const map = servers ?? {};
|
|
128
|
+
const current = map["codebase-snapshot"];
|
|
129
|
+
if (current !== void 0) {
|
|
130
|
+
if (JSON.stringify(current) === JSON.stringify(desired)) {
|
|
131
|
+
return { filePath, action: "unchanged", content: null, note: null };
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
filePath,
|
|
135
|
+
action: "unchanged",
|
|
136
|
+
content: null,
|
|
137
|
+
note: "Kept the existing codebase-snapshot entry in .mcp.json; it differs from the generated one."
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
map["codebase-snapshot"] = desired;
|
|
141
|
+
parsed.mcpServers = map;
|
|
142
|
+
const text = JSON.stringify(parsed, null, 2) + "\n";
|
|
143
|
+
if (text === existing) return { filePath, action: "unchanged", content: null, note: null };
|
|
144
|
+
return { filePath, action: existing === null ? "created" : "updated", content: text, note: null };
|
|
91
145
|
}
|
|
92
146
|
function isSkillTarget(value) {
|
|
93
147
|
return SKILL_TARGETS.includes(value);
|
|
@@ -102,6 +156,8 @@ var COMMAND_ALIASES = /* @__PURE__ */ new Map([
|
|
|
102
156
|
["check", "validate"],
|
|
103
157
|
["health", "health"],
|
|
104
158
|
["report", "report"],
|
|
159
|
+
["impact", "impact"],
|
|
160
|
+
["brief", "brief"],
|
|
105
161
|
["init", "init"],
|
|
106
162
|
["setup", "setup"],
|
|
107
163
|
["explain", "explain"],
|
|
@@ -117,6 +173,8 @@ var COMMAND_ARITY = {
|
|
|
117
173
|
validate: 0,
|
|
118
174
|
health: 0,
|
|
119
175
|
report: 0,
|
|
176
|
+
impact: 0,
|
|
177
|
+
brief: 1,
|
|
120
178
|
init: 0,
|
|
121
179
|
setup: 0,
|
|
122
180
|
explain: 1,
|
|
@@ -160,6 +218,23 @@ var CLI_OPTIONS = {
|
|
|
160
218
|
"no-update-check": { type: "boolean" },
|
|
161
219
|
"install-hook": { type: "boolean" },
|
|
162
220
|
"changed-since": { type: "string" },
|
|
221
|
+
diff: { type: "string" },
|
|
222
|
+
paths: { type: "string" },
|
|
223
|
+
depth: { type: "string" },
|
|
224
|
+
"max-results": { type: "string" },
|
|
225
|
+
"no-cache": { type: "boolean" },
|
|
226
|
+
"no-live": { type: "boolean" },
|
|
227
|
+
"tests-paths": { type: "boolean" },
|
|
228
|
+
run: { type: "boolean" },
|
|
229
|
+
precise: { type: "boolean" },
|
|
230
|
+
"include-imports": { type: "boolean" },
|
|
231
|
+
"include-cycles": { type: "boolean" },
|
|
232
|
+
copy: { type: "boolean" },
|
|
233
|
+
out: { type: "string" },
|
|
234
|
+
"max-tokens": { type: "string" },
|
|
235
|
+
"lines-per-file": { type: "string" },
|
|
236
|
+
"include-tests": { type: "boolean" },
|
|
237
|
+
"with-mcp": { type: "boolean" },
|
|
163
238
|
"with-dependents": { type: "boolean" },
|
|
164
239
|
staged: { type: "boolean" },
|
|
165
240
|
skeleton: { type: "boolean" },
|
|
@@ -218,6 +293,8 @@ Commands:
|
|
|
218
293
|
health Audit a snapshot for leaks, lies and wasted tokens (--strict, --format json)
|
|
219
294
|
init Generate a starter snapshot.config file
|
|
220
295
|
report Print codebase health, layer metrics, and secret audit
|
|
296
|
+
impact Report changed files, transitive importers, routes and candidate tests
|
|
297
|
+
brief One redacted review pack: impact, diff hunks and bounded source windows
|
|
221
298
|
explain <path> Show how one path would be treated: layer, kind, part, skips
|
|
222
299
|
diff <a> <b> Compare two snapshots (directories or manifest.json files)
|
|
223
300
|
describe Print the machine-readable contract (--format json for agents)
|
|
@@ -263,7 +340,8 @@ Options:
|
|
|
263
340
|
(readme, prompt, manifest, parts, navigation,
|
|
264
341
|
projectTree, audit, diff, log, tokenTree, monolith)
|
|
265
342
|
--only-artifacts <names> Write *only* these artifacts
|
|
266
|
-
--format <text|json>
|
|
343
|
+
--format <text|json|markdown|pr-comment>
|
|
344
|
+
CLI output format; markdown/pr-comment apply to impact and brief
|
|
267
345
|
--dry-run Compute the snapshot without writing anything
|
|
268
346
|
--watch Re-generate whenever the repository changes
|
|
269
347
|
--no-config Ignore snapshot.config.* and use the built-in defaults
|
|
@@ -303,9 +381,28 @@ Options:
|
|
|
303
381
|
--all-members Audit every snapshot a --workspace run wrote
|
|
304
382
|
--deep Replay every full body against the source on disk
|
|
305
383
|
|
|
384
|
+
impact and brief:
|
|
385
|
+
--diff <ref> Compare the working tree against this git ref
|
|
386
|
+
--paths <a,b> Treat these repository-relative paths as the change
|
|
387
|
+
--depth <n> Reverse-import hops to follow (default: 3, max: 8)
|
|
388
|
+
--max-results <n> Cap affected files (default: 200, max: 1000)
|
|
389
|
+
--tests-paths Print candidate test paths, one per line
|
|
390
|
+
--run Run the detected test runner (text format only)
|
|
391
|
+
--precise Add bounded compiler-resolved symbol references
|
|
392
|
+
--include-imports Include outgoing imports of changed files
|
|
393
|
+
--include-cycles Include import cycles in the impacted subgraph
|
|
394
|
+
--no-live Require the persisted snapshot instead of the live index
|
|
395
|
+
--no-cache Bypass the OS live-index summary cache
|
|
396
|
+
--max-tokens <n> Brief token budget (default: 12000, minimum: 500)
|
|
397
|
+
--lines-per-file <n> Brief lines per file (default: 80)
|
|
398
|
+
--include-tests Include candidate tests in the brief
|
|
399
|
+
--copy Copy the brief to the clipboard
|
|
400
|
+
--out <path> Write the brief inside the repository
|
|
401
|
+
|
|
306
402
|
skill only:
|
|
307
403
|
--install Write the skill into the repository instead of printing
|
|
308
|
-
--target <name> claude | cursor | all (default: all)
|
|
404
|
+
--target <name> agents | claude | cursor | all (default: all)
|
|
405
|
+
--with-mcp Also merge a server entry into .mcp.json
|
|
309
406
|
|
|
310
407
|
--no-update-check Skip the check for a newer published version
|
|
311
408
|
|
|
@@ -483,7 +580,10 @@ function parseCliArgs(argv) {
|
|
|
483
580
|
args = positionals.slice(1);
|
|
484
581
|
}
|
|
485
582
|
const expectedArgs = COMMAND_ARITY[command];
|
|
486
|
-
if (args.length
|
|
583
|
+
if (command === "brief" && args.length > 1) {
|
|
584
|
+
throw new UsageError("brief takes at most one question. Put a path or reference in --diff or --paths.");
|
|
585
|
+
}
|
|
586
|
+
if (args.length !== expectedArgs && !(command === "brief" && args.length === 0)) {
|
|
487
587
|
if (command === "explain") {
|
|
488
588
|
throw new UsageError("explain expects exactly one path.");
|
|
489
589
|
}
|
|
@@ -497,8 +597,46 @@ function parseCliArgs(argv) {
|
|
|
497
597
|
);
|
|
498
598
|
}
|
|
499
599
|
const rawFormat = values.format === void 0 ? "text" : String(values.format);
|
|
500
|
-
|
|
501
|
-
|
|
600
|
+
const allowedFormats = ["text", "json"];
|
|
601
|
+
if (command === "impact" || command === "brief") {
|
|
602
|
+
allowedFormats.push("markdown", "pr-comment");
|
|
603
|
+
}
|
|
604
|
+
if (!allowedFormats.includes(rawFormat)) {
|
|
605
|
+
throw new UsageError(
|
|
606
|
+
command === "impact" || command === "brief" ? `--format must be "text", "json", "markdown" or "pr-comment", received "${rawFormat}".` : `--format must be "text" or "json", received "${rawFormat}".`
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
const rawDiff = values.diff === void 0 ? void 0 : String(values.diff).trim();
|
|
610
|
+
if (rawDiff !== void 0 && rawDiff.startsWith("-")) {
|
|
611
|
+
throw new UsageError(
|
|
612
|
+
`--diff expects a git ref, not an option (received "${rawDiff}"). Name a branch, tag, or commit.`
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
const rawPaths = values.paths === void 0 ? void 0 : String(values.paths);
|
|
616
|
+
const paths = rawPaths === void 0 ? void 0 : rawPaths.split(",").map((item) => item.trim()).filter((item) => item.length > 0);
|
|
617
|
+
if (paths !== void 0 && paths.length === 0) {
|
|
618
|
+
throw new UsageError("--paths expects at least one repository-relative path.");
|
|
619
|
+
}
|
|
620
|
+
for (const item of paths ?? []) {
|
|
621
|
+
const normalized = item.replace(/\\/g, "/").replace(/^\.\/+/, "");
|
|
622
|
+
if (normalized.length === 0 || normalized.startsWith("/") || /^[A-Za-z]:\//.test(normalized) || normalized.split("/").includes("..")) {
|
|
623
|
+
throw new UsageError(
|
|
624
|
+
`--paths accepts repository-relative paths only; "${item}" is absolute or escapes the repository.`
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
if (command === "impact" || command === "brief") {
|
|
629
|
+
if (rawDiff !== void 0 && paths !== void 0) {
|
|
630
|
+
throw new UsageError("impact accepts either --diff <ref> or --paths <a,b>, not both.");
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
const depth = parseCountOption(values.depth, "depth", 1);
|
|
634
|
+
if (depth !== void 0 && depth > 8) {
|
|
635
|
+
throw new UsageError(`--depth must be at most 8, received ${depth}.`);
|
|
636
|
+
}
|
|
637
|
+
const maxResults = parseCountOption(values["max-results"], "max-results", 1);
|
|
638
|
+
if (maxResults !== void 0 && maxResults > 1e3) {
|
|
639
|
+
throw new UsageError(`--max-results must be at most 1000, received ${maxResults}.`);
|
|
502
640
|
}
|
|
503
641
|
const rawDiscovery = values.discovery === void 0 ? void 0 : String(values.discovery);
|
|
504
642
|
if (rawDiscovery !== void 0 && !isDiscoveryMode(rawDiscovery)) {
|
|
@@ -551,6 +689,14 @@ function parseCliArgs(argv) {
|
|
|
551
689
|
const requested = String(values.preset);
|
|
552
690
|
if (!getPreset(requested)) throw new UsageError(unknownPresetMessage(requested));
|
|
553
691
|
}
|
|
692
|
+
if (command === "skill" && values["with-mcp"] === true && values.install !== true) {
|
|
693
|
+
throw new UsageError("--with-mcp only applies to `skill --install`.");
|
|
694
|
+
}
|
|
695
|
+
if (command === "brief" && args.length > 0 && (values.diff !== void 0 || values.paths !== void 0 || values.depth !== void 0 || values["max-results"] !== void 0)) {
|
|
696
|
+
throw new UsageError(
|
|
697
|
+
"brief takes either a question or change options (--diff, --paths, --depth, --max-results), not both."
|
|
698
|
+
);
|
|
699
|
+
}
|
|
554
700
|
if (command === "skill" && values.target !== void 0 && !isSkillTarget(String(values.target))) {
|
|
555
701
|
throw new UsageError(
|
|
556
702
|
`--target must be one of: ${SKILL_TARGETS.join(", ")} (received "${String(values.target)}").`
|
|
@@ -577,6 +723,21 @@ function parseCliArgs(argv) {
|
|
|
577
723
|
include: values.include === void 0 ? void 0 : String(values.include),
|
|
578
724
|
exclude: values.exclude === void 0 ? void 0 : String(values.exclude),
|
|
579
725
|
yes: values.yes === true,
|
|
726
|
+
noCache: values["no-cache"] === true,
|
|
727
|
+
noLive: values["no-live"] === true,
|
|
728
|
+
testsPaths: values["tests-paths"] === true,
|
|
729
|
+
runTests: values.run === true,
|
|
730
|
+
precise: values.precise === true,
|
|
731
|
+
includeImports: values["include-imports"] === true,
|
|
732
|
+
includeCycles: values["include-cycles"] === true,
|
|
733
|
+
copy: values.copy === true,
|
|
734
|
+
out: values.out === void 0 ? void 0 : String(values.out),
|
|
735
|
+
maxTokens: parseCountOption(values["max-tokens"], "max-tokens", 500),
|
|
736
|
+
linesPerFile: parseCountOption(values["lines-per-file"], "lines-per-file", 10),
|
|
737
|
+
includeTestsOnly: values["include-tests"] === true,
|
|
738
|
+
withMcp: values["with-mcp"] === true,
|
|
739
|
+
markdown: rawFormat === "markdown" || rawFormat === "pr-comment",
|
|
740
|
+
prComment: rawFormat === "pr-comment",
|
|
580
741
|
force: values.force === true,
|
|
581
742
|
autopilot: values.autopilot === true,
|
|
582
743
|
install: values.install === true,
|
|
@@ -623,6 +784,10 @@ function parseCliArgs(argv) {
|
|
|
623
784
|
noUpdateCheck: values["no-update-check"] === true,
|
|
624
785
|
installHook: values["install-hook"] === true,
|
|
625
786
|
changedSince: values["changed-since"] === void 0 ? void 0 : String(values["changed-since"]),
|
|
787
|
+
diff: rawDiff,
|
|
788
|
+
paths,
|
|
789
|
+
depth,
|
|
790
|
+
maxResults,
|
|
626
791
|
// `undefined` when the flag was not given, never `false`.
|
|
627
792
|
//
|
|
628
793
|
// `resolveConfig` reads these as `cliOptions.x ?? config.x`, so a `false` here is an
|
|
@@ -694,6 +859,126 @@ function fail(format, message, exitCode = 1) {
|
|
|
694
859
|
}
|
|
695
860
|
return exitCode;
|
|
696
861
|
}
|
|
862
|
+
function markdownValue(value) {
|
|
863
|
+
return inlineCode(findSecretInPath(value)?.masked ?? value);
|
|
864
|
+
}
|
|
865
|
+
function renderImpactMarkdown(report) {
|
|
866
|
+
const lines = [];
|
|
867
|
+
lines.push("# Impact report");
|
|
868
|
+
lines.push("");
|
|
869
|
+
lines.push(
|
|
870
|
+
"Trust: source=" + report.trust.indexSource + " \xB7 freshness=" + report.trust.freshness + " \xB7 coverage=" + report.trust.coverage + " \xB7 redacted=" + report.trust.redactedLines
|
|
871
|
+
);
|
|
872
|
+
lines.push("");
|
|
873
|
+
lines.push("**Changed:** " + report.changed.length + " \xB7 **Affected:** " + report.affected.length + " \xB7 **Tests:** " + report.tests.length);
|
|
874
|
+
lines.push("");
|
|
875
|
+
lines.push("## Changed");
|
|
876
|
+
lines.push(report.changed.length === 0 ? "_None._" : report.changed.map((entry) => "- " + markdownValue(entry.path) + (entry.deleted ? " (deleted)" : "")).join("\n"));
|
|
877
|
+
lines.push("");
|
|
878
|
+
lines.push("## Affected");
|
|
879
|
+
lines.push(report.affected.length === 0 ? "_None._" : report.affected.map((entry) => "- " + markdownValue(entry.path) + " \u2014 " + entry.distance + " hop via " + markdownValue(entry.via) + " (" + markdownValue(entry.specifier) + ")").join("\n"));
|
|
880
|
+
lines.push("");
|
|
881
|
+
if (report.routesAffected !== void 0 && report.routesAffected.length > 0) {
|
|
882
|
+
lines.push("## Routes affected");
|
|
883
|
+
lines.push(report.routesAffected.map((route) => "- " + markdownValue(route.path) + " (" + route.methods.map(markdownValue).join(", ") + ")").join("\n"));
|
|
884
|
+
lines.push("");
|
|
885
|
+
}
|
|
886
|
+
lines.push("## Candidate tests");
|
|
887
|
+
lines.push(report.tests.length === 0 ? "_None._" : report.tests.map((test) => "- " + markdownValue(test.path) + " \u2014 covers " + test.covers.map(markdownValue).join(", ")).join("\n"));
|
|
888
|
+
if (report.unresolved.length > 0) {
|
|
889
|
+
lines.push("");
|
|
890
|
+
lines.push("## Unresolved internal imports");
|
|
891
|
+
lines.push(report.unresolved.map((entry) => "- " + markdownValue(entry.path) + ": " + markdownValue(entry.specifier)).join("\n"));
|
|
892
|
+
}
|
|
893
|
+
if (report.cycles !== void 0 && report.cycles.length > 0) {
|
|
894
|
+
lines.push("");
|
|
895
|
+
lines.push("## Import cycles");
|
|
896
|
+
lines.push(report.cycles.map((cycle) => "- " + cycle.map(markdownValue).join(" -> ")).join("\n"));
|
|
897
|
+
}
|
|
898
|
+
if (report.imports !== void 0) {
|
|
899
|
+
const entries = Object.entries(report.imports).filter(([, targets]) => targets.length > 0);
|
|
900
|
+
if (entries.length > 0) {
|
|
901
|
+
lines.push("");
|
|
902
|
+
lines.push("## Outgoing imports");
|
|
903
|
+
lines.push(entries.map(([source, targets]) => "- " + markdownValue(source) + " -> " + targets.map(markdownValue).join(", ")).join("\n"));
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
if (report.precise !== void 0) {
|
|
907
|
+
lines.push("");
|
|
908
|
+
lines.push("## Precise symbol references (" + report.precise.coverage + ")");
|
|
909
|
+
lines.push(
|
|
910
|
+
report.precise.references.length === 0 ? "_None._" : report.precise.references.slice(0, 25).map((reference) => "- " + markdownValue(reference.path + ":" + reference.line) + " (" + markdownValue(reference.name) + ")").join("\n")
|
|
911
|
+
);
|
|
912
|
+
if (report.precise.reasons.length > 0) {
|
|
913
|
+
lines.push(...report.precise.reasons.slice(0, 3).map((reason) => "- Note: " + escapeControls(reason)));
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
if (report.warnings.length > 0) {
|
|
917
|
+
lines.push("");
|
|
918
|
+
lines.push("## Warnings");
|
|
919
|
+
lines.push(report.warnings.map((warning) => "- " + escapeControls(warning)).join("\n"));
|
|
920
|
+
}
|
|
921
|
+
lines.push("");
|
|
922
|
+
return lines.join("\n");
|
|
923
|
+
}
|
|
924
|
+
function realPathInside(realRoot, candidate) {
|
|
925
|
+
const fold = (value) => process.platform === "win32" || process.platform === "darwin" ? value.toLowerCase() : value;
|
|
926
|
+
const relative3 = path2.relative(fold(realRoot), fold(candidate));
|
|
927
|
+
return relative3.length === 0 || relative3 !== ".." && !relative3.startsWith(".." + path2.sep) && !path2.isAbsolute(relative3);
|
|
928
|
+
}
|
|
929
|
+
function writeInside(root, relative3, content) {
|
|
930
|
+
const target = path2.resolve(root, relative3);
|
|
931
|
+
const rel = path2.relative(path2.resolve(root), target);
|
|
932
|
+
if (rel.length === 0 || rel === ".." || rel.startsWith(".." + path2.sep) || path2.isAbsolute(rel)) {
|
|
933
|
+
throw new Error("--out must resolve inside the repository.");
|
|
934
|
+
}
|
|
935
|
+
const parent = path2.dirname(target);
|
|
936
|
+
const realRoot = fs2.realpathSync(root);
|
|
937
|
+
let existingAncestor = parent;
|
|
938
|
+
while (!fs2.existsSync(existingAncestor)) {
|
|
939
|
+
const next = path2.dirname(existingAncestor);
|
|
940
|
+
if (next === existingAncestor) break;
|
|
941
|
+
existingAncestor = next;
|
|
942
|
+
}
|
|
943
|
+
if (!realPathInside(realRoot, fs2.realpathSync(existingAncestor))) {
|
|
944
|
+
throw new Error("--out resolves outside the repository through a link.");
|
|
945
|
+
}
|
|
946
|
+
fs2.mkdirSync(parent, { recursive: true });
|
|
947
|
+
if (!realPathInside(realRoot, fs2.realpathSync(parent))) {
|
|
948
|
+
throw new Error("--out resolves outside the repository through a link.");
|
|
949
|
+
}
|
|
950
|
+
try {
|
|
951
|
+
const existing = fs2.lstatSync(target);
|
|
952
|
+
if (existing.isSymbolicLink() || !existing.isFile() || existing.nlink > 1) {
|
|
953
|
+
throw new Error("--out must be a regular file that is not a symbolic or hard link.");
|
|
954
|
+
}
|
|
955
|
+
} catch (error) {
|
|
956
|
+
if (error.code !== "ENOENT") throw error;
|
|
957
|
+
}
|
|
958
|
+
const temporary = path2.join(parent, "." + path2.basename(target) + ".tmp-" + process.pid + "-" + Math.random().toString(16).slice(2));
|
|
959
|
+
fs2.writeFileSync(temporary, content, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
960
|
+
try {
|
|
961
|
+
fs2.renameSync(temporary, target);
|
|
962
|
+
} catch (error) {
|
|
963
|
+
try {
|
|
964
|
+
fs2.unlinkSync(temporary);
|
|
965
|
+
} catch (cleanupError) {
|
|
966
|
+
warn("Could not remove temporary file " + temporary + ": " + cleanupError.message);
|
|
967
|
+
}
|
|
968
|
+
throw error;
|
|
969
|
+
}
|
|
970
|
+
return target;
|
|
971
|
+
}
|
|
972
|
+
function copyToClipboard(text) {
|
|
973
|
+
const commands = process.platform === "win32" ? [["clip", []]] : process.platform === "darwin" ? [["pbcopy", []]] : [["wl-copy", []], ["xclip", ["-selection", "clipboard"]]];
|
|
974
|
+
let last = null;
|
|
975
|
+
for (const [command, args] of commands) {
|
|
976
|
+
const result = spawnSync(command, args, { input: text, stdio: ["pipe", "ignore", "pipe"], shell: false });
|
|
977
|
+
if (result.error === void 0 && result.status === 0) return;
|
|
978
|
+
last = result.error === void 0 ? command + " exited " + result.status : result.error.message;
|
|
979
|
+
}
|
|
980
|
+
throw new Error("Could not copy the brief to the clipboard: " + (last ?? "no clipboard command available"));
|
|
981
|
+
}
|
|
697
982
|
function splitList(value) {
|
|
698
983
|
if (value === void 0) return void 0;
|
|
699
984
|
return value.split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
@@ -1123,7 +1408,9 @@ function runSkillCommand(invocation) {
|
|
|
1123
1408
|
return 0;
|
|
1124
1409
|
}
|
|
1125
1410
|
try {
|
|
1126
|
-
const result = installSkill(invocation.cwd, invocation.target
|
|
1411
|
+
const result = installSkill(invocation.cwd, invocation.target, {
|
|
1412
|
+
withMcp: invocation.withMcp
|
|
1413
|
+
});
|
|
1127
1414
|
if (invocation.format === "json") {
|
|
1128
1415
|
process.stdout.write(`${JSON.stringify(result, null, 2)}
|
|
1129
1416
|
`);
|
|
@@ -1139,9 +1426,13 @@ function runSkillCommand(invocation) {
|
|
|
1139
1426
|
info(` Added to .gitignore: ${result.gitignored.join(", ")}`);
|
|
1140
1427
|
info(" These files are this tool's own documentation, so they stay out of git.");
|
|
1141
1428
|
}
|
|
1429
|
+
if (result.mcp !== void 0) {
|
|
1430
|
+
const shown = path2.relative(invocation.cwd, result.mcp.path) || result.mcp.path;
|
|
1431
|
+
info(` - ${result.mcp.action.padEnd(9)} ${shown} (codebase-snapshot MCP entry)`);
|
|
1432
|
+
}
|
|
1142
1433
|
for (const note of result.notes) info(` \u26A0 ${note}`);
|
|
1143
1434
|
info("");
|
|
1144
|
-
info(" Agents that read .claude/skills or .cursor/rules will pick this up automatically.");
|
|
1435
|
+
info(" Agents that read .agents/skills, .claude/skills or .cursor/rules will pick this up automatically.");
|
|
1145
1436
|
return 0;
|
|
1146
1437
|
} catch (err) {
|
|
1147
1438
|
return fail(invocation.format, `Could not install the skill: ${err.message}`);
|
|
@@ -1615,6 +1906,243 @@ ${USAGE}
|
|
|
1615
1906
|
});
|
|
1616
1907
|
return 0;
|
|
1617
1908
|
}
|
|
1909
|
+
if (invocation.command === "impact") {
|
|
1910
|
+
try {
|
|
1911
|
+
const manifestPath = path2.resolve(resolved.cwd, resolved.outDir, "manifest.json");
|
|
1912
|
+
let manifest;
|
|
1913
|
+
let live = null;
|
|
1914
|
+
if (invocation.noLive) {
|
|
1915
|
+
if (!fs2.existsSync(manifestPath)) {
|
|
1916
|
+
return fail(invocation.format, "Manifest not found at " + manifestPath + ". Run generate first, or omit --no-live.");
|
|
1917
|
+
}
|
|
1918
|
+
manifest = loadManifest(manifestPath);
|
|
1919
|
+
} else {
|
|
1920
|
+
live = await buildLiveIndex(resolved, { useDiskCache: !invocation.noCache });
|
|
1921
|
+
manifest = live.manifest;
|
|
1922
|
+
}
|
|
1923
|
+
const changes = resolveImpactChanges(resolved.cwd, {
|
|
1924
|
+
...invocation.diff !== void 0 ? { diff: invocation.diff } : invocation.paths !== void 0 ? { paths: invocation.paths } : { diff: "HEAD" }
|
|
1925
|
+
});
|
|
1926
|
+
const report = computeImpact({
|
|
1927
|
+
manifest,
|
|
1928
|
+
cwd: resolved.cwd,
|
|
1929
|
+
changes,
|
|
1930
|
+
manifestPath,
|
|
1931
|
+
...invocation.depth === void 0 ? {} : { depth: invocation.depth },
|
|
1932
|
+
...invocation.maxResults === void 0 ? {} : { maxResults: invocation.maxResults },
|
|
1933
|
+
...live === null ? {} : { trust: live.trust },
|
|
1934
|
+
includeImports: invocation.includeImports,
|
|
1935
|
+
includeCycles: invocation.includeCycles
|
|
1936
|
+
});
|
|
1937
|
+
if (invocation.precise) {
|
|
1938
|
+
const targets = [];
|
|
1939
|
+
const seenTargets = /* @__PURE__ */ new Set();
|
|
1940
|
+
for (const entry of report.changed) {
|
|
1941
|
+
const file = manifest.files.find((candidate) => candidate.relativePath === entry.path);
|
|
1942
|
+
const summary = file?.summary;
|
|
1943
|
+
const exportsList = summary && "exports" in summary && Array.isArray(summary.exports) ? summary.exports : [];
|
|
1944
|
+
for (const symbol of exportsList) {
|
|
1945
|
+
const name = String(symbol);
|
|
1946
|
+
const dedupeKey = entry.path + "\0" + name;
|
|
1947
|
+
if (seenTargets.has(dedupeKey)) continue;
|
|
1948
|
+
seenTargets.add(dedupeKey);
|
|
1949
|
+
targets.push({ symbolName: name, targetPath: entry.path });
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
const tsEntries = live === null ? [] : manifest.files.filter((entry) => /\.(?:[cm]?[jt]sx?)$/i.test(entry.relativePath));
|
|
1953
|
+
if (live === null || tsEntries.length === 0) {
|
|
1954
|
+
report.trust.coverage = "partial";
|
|
1955
|
+
report.trust.reasons = [...report.trust.reasons, "--precise needs the live index; pass without --no-live."];
|
|
1956
|
+
} else if (tsEntries.length > DEFAULT_MAX_PROGRAM_FILES) {
|
|
1957
|
+
const reason = "TypeScript compiler pass skipped: " + tsEntries.length + " TS/JS files exceed the " + DEFAULT_MAX_PROGRAM_FILES + "-file cap; fell back to import-binding results";
|
|
1958
|
+
report.trust.coverage = "partial";
|
|
1959
|
+
report.trust.reasons = [.../* @__PURE__ */ new Set([...report.trust.reasons, reason])];
|
|
1960
|
+
report.precise = { references: [], coverage: "partial", reasons: [reason] };
|
|
1961
|
+
} else if (targets.length === 0) {
|
|
1962
|
+
report.precise = { references: [], coverage: report.trust.coverage, reasons: [] };
|
|
1963
|
+
} else {
|
|
1964
|
+
const files = tsEntries.map((entry) => {
|
|
1965
|
+
const body = live?.readRedactedFile(entry.relativePath);
|
|
1966
|
+
return body === null || body === void 0 ? null : { relativePath: entry.relativePath, content: body.text };
|
|
1967
|
+
}).filter((entry) => entry !== null);
|
|
1968
|
+
const found = findMultipleSymbolReferences({
|
|
1969
|
+
root: resolved.cwd,
|
|
1970
|
+
files,
|
|
1971
|
+
targets
|
|
1972
|
+
});
|
|
1973
|
+
const references = [];
|
|
1974
|
+
for (const item of found.results) references.push(...item.references);
|
|
1975
|
+
if (found.coverage === "partial") {
|
|
1976
|
+
report.trust.coverage = "partial";
|
|
1977
|
+
report.trust.reasons = [.../* @__PURE__ */ new Set([...report.trust.reasons, ...found.reasons])];
|
|
1978
|
+
}
|
|
1979
|
+
report.precise = {
|
|
1980
|
+
references,
|
|
1981
|
+
coverage: report.trust.coverage,
|
|
1982
|
+
reasons: found.reasons
|
|
1983
|
+
};
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
if (invocation.testsPaths) {
|
|
1987
|
+
if (invocation.runTests && invocation.format !== "text") {
|
|
1988
|
+
return fail(invocation.format, "--run streams test output; use --format text.");
|
|
1989
|
+
}
|
|
1990
|
+
if (!invocation.runTests) {
|
|
1991
|
+
if (invocation.format === "json") {
|
|
1992
|
+
process.stdout.write(JSON.stringify(report.tests.map((entry) => entry.path), null, 2) + "\n");
|
|
1993
|
+
} else {
|
|
1994
|
+
for (const entry of report.tests) process.stdout.write(entry.path + "\n");
|
|
1995
|
+
}
|
|
1996
|
+
return 0;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
if (invocation.runTests) {
|
|
2000
|
+
if (invocation.format !== "text") {
|
|
2001
|
+
return fail(invocation.format, "--run streams test output; use --format text.");
|
|
2002
|
+
}
|
|
2003
|
+
const plan = planTestRun(resolved.cwd, {
|
|
2004
|
+
changedPaths: report.changed.map((entry) => entry.path),
|
|
2005
|
+
testPaths: report.tests.map((entry) => entry.path)
|
|
2006
|
+
});
|
|
2007
|
+
info(renderImpactText(report));
|
|
2008
|
+
if (plan.warning !== void 0) warn("Warning: " + plan.warning);
|
|
2009
|
+
if (plan.kind === "none") {
|
|
2010
|
+
info("No candidate tests were found; nothing was run.");
|
|
2011
|
+
return 0;
|
|
2012
|
+
}
|
|
2013
|
+
info("Running " + plan.kind + ": " + plan.command + " " + plan.args.join(" "));
|
|
2014
|
+
const result = runTestPlan(resolved.cwd, plan);
|
|
2015
|
+
if (result.timedOut) {
|
|
2016
|
+
warn("The test run exceeded its five-minute timeout and was terminated.");
|
|
2017
|
+
return 1;
|
|
2018
|
+
}
|
|
2019
|
+
return result.exitCode ?? 1;
|
|
2020
|
+
}
|
|
2021
|
+
if (invocation.format === "markdown" || invocation.format === "pr-comment") {
|
|
2022
|
+
process.stdout.write(renderImpactMarkdown(report) + "\n");
|
|
2023
|
+
return 0;
|
|
2024
|
+
}
|
|
2025
|
+
emit(invocation.format, report, () => info(renderImpactText(report)));
|
|
2026
|
+
return 0;
|
|
2027
|
+
} catch (err) {
|
|
2028
|
+
return fail(invocation.format, err.message);
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
if (invocation.command === "brief") {
|
|
2032
|
+
try {
|
|
2033
|
+
const manifestPath = path2.resolve(resolved.cwd, resolved.outDir, "manifest.json");
|
|
2034
|
+
let manifest;
|
|
2035
|
+
let live = null;
|
|
2036
|
+
if (invocation.noLive) {
|
|
2037
|
+
if (!fs2.existsSync(manifestPath)) {
|
|
2038
|
+
return fail(invocation.format, "Manifest not found at " + manifestPath + ". Run generate first, or omit --no-live.");
|
|
2039
|
+
}
|
|
2040
|
+
manifest = loadManifest(manifestPath);
|
|
2041
|
+
} else {
|
|
2042
|
+
live = await buildLiveIndex(resolved, { useDiskCache: !invocation.noCache });
|
|
2043
|
+
manifest = live.manifest;
|
|
2044
|
+
}
|
|
2045
|
+
const question = invocation.args[0];
|
|
2046
|
+
let changes;
|
|
2047
|
+
if (question === void 0) {
|
|
2048
|
+
changes = briefFromPaths(resolved.cwd, {
|
|
2049
|
+
...invocation.diff !== void 0 ? { diff: invocation.diff } : invocation.paths !== void 0 ? { paths: invocation.paths } : { diff: "HEAD" }
|
|
2050
|
+
});
|
|
2051
|
+
}
|
|
2052
|
+
let diffText;
|
|
2053
|
+
const diffNotes = [];
|
|
2054
|
+
if (invocation.diff !== void 0 || question === void 0 && invocation.paths === void 0) {
|
|
2055
|
+
const ref = invocation.diff ?? "HEAD";
|
|
2056
|
+
const resolvedBase = resolveDiffBase(resolved.cwd, ref);
|
|
2057
|
+
const diffArgs = resolvedBase === null ? ["-c", "core.quotepath=false", "-c", "diff.noprefix=false", "-c", "diff.mnemonicPrefix=false", "-c", "core.fsmonitor=false", "diff", "--cached", "--no-color", "--no-ext-diff", "--no-textconv", "-U3"] : ["-c", "core.quotepath=false", "-c", "diff.noprefix=false", "-c", "diff.mnemonicPrefix=false", "-c", "core.fsmonitor=false", "diff", "--no-color", "--no-ext-diff", "--no-textconv", "-U3", resolvedBase, "--"];
|
|
2058
|
+
const result = spawnSync("git", diffArgs, {
|
|
2059
|
+
cwd: resolved.cwd,
|
|
2060
|
+
encoding: "utf8",
|
|
2061
|
+
shell: false,
|
|
2062
|
+
maxBuffer: 64 * 1024 * 1024
|
|
2063
|
+
});
|
|
2064
|
+
if (result.status === 0) {
|
|
2065
|
+
const reportExcludes = [...resolved.excludePatterns, ...resolved.presetExclude];
|
|
2066
|
+
const filtered = filterAndRedactDiff(result.stdout, resolved.secretRules, {
|
|
2067
|
+
// The diff report generated by `generate` applies the repository's include/exclude
|
|
2068
|
+
// rules; `brief --diff` used to pass only the secret rules, so a tracked file the
|
|
2069
|
+
// config excluded still appeared in the review pack.
|
|
2070
|
+
excluded: (relativePath) => resolved.include.length > 0 && !resolved.include.some((pattern) => matchesExclude(relativePath, pattern)) || reportExcludes.some((pattern) => matchesExclude(relativePath, pattern)) || defaultIgnoreReason(relativePath) !== null
|
|
2071
|
+
});
|
|
2072
|
+
diffText = filtered.text;
|
|
2073
|
+
if (filtered.omittedSensitive > 0) {
|
|
2074
|
+
diffNotes.push(filtered.omittedSensitive + " sensitive file section(s) were omitted from the diff.");
|
|
2075
|
+
}
|
|
2076
|
+
if (filtered.omittedUnparseable > 0) {
|
|
2077
|
+
diffNotes.push(filtered.omittedUnparseable + " unparseable file section(s) were omitted from the diff.");
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
const readBody = (relativePath) => {
|
|
2082
|
+
if (live !== null) {
|
|
2083
|
+
const body = live.readRedactedFile(relativePath);
|
|
2084
|
+
return body === null ? null : body.text;
|
|
2085
|
+
}
|
|
2086
|
+
if (isSensitivePath(relativePath)) return null;
|
|
2087
|
+
const file = manifest.files.find((candidate) => candidate.relativePath === relativePath);
|
|
2088
|
+
if (file === void 0) return null;
|
|
2089
|
+
const snapshotDir = path2.resolve(resolved.cwd, resolved.outDir);
|
|
2090
|
+
const read = readConfinedText(
|
|
2091
|
+
snapshotDir,
|
|
2092
|
+
path2.posix.join("parts", file.part),
|
|
2093
|
+
16 * 1024 * 1024
|
|
2094
|
+
);
|
|
2095
|
+
if (!read.ok) return null;
|
|
2096
|
+
return findSection(parsePartSections(read.text), relativePath)?.body ?? null;
|
|
2097
|
+
};
|
|
2098
|
+
const brief = buildBrief({
|
|
2099
|
+
cwd: resolved.cwd,
|
|
2100
|
+
manifest,
|
|
2101
|
+
...question === void 0 ? {} : { question },
|
|
2102
|
+
...changes === void 0 ? {} : { changes },
|
|
2103
|
+
...diffText === void 0 ? {} : { diff: diffText },
|
|
2104
|
+
...diffNotes.length === 0 ? {} : { diffNotes },
|
|
2105
|
+
readBody,
|
|
2106
|
+
secretRules: resolved.secretRules,
|
|
2107
|
+
maxTokens: invocation.maxTokens,
|
|
2108
|
+
linesPerFile: invocation.linesPerFile,
|
|
2109
|
+
includeTests: invocation.includeTestsOnly,
|
|
2110
|
+
prComment: invocation.prComment,
|
|
2111
|
+
...invocation.depth === void 0 ? {} : { depth: invocation.depth },
|
|
2112
|
+
...invocation.maxResults === void 0 ? {} : { maxResults: invocation.maxResults },
|
|
2113
|
+
...live === null ? {} : { trust: live.trust }
|
|
2114
|
+
});
|
|
2115
|
+
if (invocation.out !== void 0) {
|
|
2116
|
+
const written = writeInside(resolved.cwd, invocation.out, brief.markdown);
|
|
2117
|
+
info("Wrote " + path2.relative(resolved.cwd, written));
|
|
2118
|
+
} else if (invocation.format !== "json") {
|
|
2119
|
+
process.stdout.write(brief.markdown);
|
|
2120
|
+
}
|
|
2121
|
+
if (invocation.copy) {
|
|
2122
|
+
copyToClipboard(brief.markdown);
|
|
2123
|
+
info("Copied the brief to the clipboard.");
|
|
2124
|
+
}
|
|
2125
|
+
if (invocation.format === "json") {
|
|
2126
|
+
const trust = live?.trust ?? brief.impact?.trust;
|
|
2127
|
+
process.stdout.write(
|
|
2128
|
+
JSON.stringify(
|
|
2129
|
+
{
|
|
2130
|
+
markdown: brief.markdown,
|
|
2131
|
+
usedTokens: brief.usedTokens,
|
|
2132
|
+
files: brief.files,
|
|
2133
|
+
omitted: brief.omitted,
|
|
2134
|
+
...trust === void 0 ? {} : { trust }
|
|
2135
|
+
},
|
|
2136
|
+
null,
|
|
2137
|
+
2
|
|
2138
|
+
) + "\n"
|
|
2139
|
+
);
|
|
2140
|
+
}
|
|
2141
|
+
return 0;
|
|
2142
|
+
} catch (err) {
|
|
2143
|
+
return fail(invocation.format, err.message);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
1618
2146
|
if (invocation.command === "explain") {
|
|
1619
2147
|
const result = explainPath(resolved, invocation.args[0]);
|
|
1620
2148
|
emit(invocation.format, result, () => info(renderExplainText(result)));
|
|
@@ -2153,8 +2681,15 @@ async function runWatchLoop(invocation, resolved, options) {
|
|
|
2153
2681
|
return 0;
|
|
2154
2682
|
}
|
|
2155
2683
|
var entryFile = process.argv[1] ?? "";
|
|
2684
|
+
var sameFile = (left, right) => {
|
|
2685
|
+
try {
|
|
2686
|
+
return fs2.realpathSync(path2.resolve(left)) === fs2.realpathSync(path2.resolve(right));
|
|
2687
|
+
} catch {
|
|
2688
|
+
return false;
|
|
2689
|
+
}
|
|
2690
|
+
};
|
|
2156
2691
|
var entryName = path2.basename(entryFile).toLowerCase();
|
|
2157
|
-
var invokedDirectly = entryName === "cli.js" || entryName === "cli.cjs";
|
|
2692
|
+
var invokedDirectly = (entryName === "cli.js" || entryName === "cli.cjs") && entryFile.length > 0 && sameFile(entryFile, fileURLToPath(import.meta.url));
|
|
2158
2693
|
if (invokedDirectly) {
|
|
2159
2694
|
void main().then(
|
|
2160
2695
|
(code) => {
|