@opencodehub/cli 0.1.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/LICENSE +202 -0
- package/README.md +85 -0
- package/dist/agent-context.d.ts +54 -0
- package/dist/agent-context.d.ts.map +1 -0
- package/dist/agent-context.js +122 -0
- package/dist/agent-context.js.map +1 -0
- package/dist/cobol-proleap-setup.d.ts +77 -0
- package/dist/cobol-proleap-setup.d.ts.map +1 -0
- package/dist/cobol-proleap-setup.js +289 -0
- package/dist/cobol-proleap-setup.js.map +1 -0
- package/dist/commands/analyze.d.ts +234 -0
- package/dist/commands/analyze.d.ts.map +1 -0
- package/dist/commands/analyze.js +1096 -0
- package/dist/commands/analyze.js.map +1 -0
- package/dist/commands/augment.d.ts +48 -0
- package/dist/commands/augment.d.ts.map +1 -0
- package/dist/commands/augment.js +249 -0
- package/dist/commands/augment.js.map +1 -0
- package/dist/commands/baseline.d.ts +68 -0
- package/dist/commands/baseline.d.ts.map +1 -0
- package/dist/commands/baseline.js +110 -0
- package/dist/commands/baseline.js.map +1 -0
- package/dist/commands/bench.d.ts +54 -0
- package/dist/commands/bench.d.ts.map +1 -0
- package/dist/commands/bench.js +283 -0
- package/dist/commands/bench.js.map +1 -0
- package/dist/commands/ci-init.d.ts +37 -0
- package/dist/commands/ci-init.d.ts.map +1 -0
- package/dist/commands/ci-init.js +115 -0
- package/dist/commands/ci-init.js.map +1 -0
- package/dist/commands/clean.d.ts +13 -0
- package/dist/commands/clean.d.ts.map +1 -0
- package/dist/commands/clean.js +38 -0
- package/dist/commands/clean.js.map +1 -0
- package/dist/commands/code-pack.d.ts +105 -0
- package/dist/commands/code-pack.d.ts.map +1 -0
- package/dist/commands/code-pack.js +187 -0
- package/dist/commands/code-pack.js.map +1 -0
- package/dist/commands/context.d.ts +30 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +237 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/detect-changes.d.ts +26 -0
- package/dist/commands/detect-changes.d.ts.map +1 -0
- package/dist/commands/detect-changes.js +73 -0
- package/dist/commands/detect-changes.js.map +1 -0
- package/dist/commands/doctor.d.ts +52 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +472 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/find-enclosing-symbol.d.ts +67 -0
- package/dist/commands/find-enclosing-symbol.d.ts.map +1 -0
- package/dist/commands/find-enclosing-symbol.js +106 -0
- package/dist/commands/find-enclosing-symbol.js.map +1 -0
- package/dist/commands/group.d.ts +123 -0
- package/dist/commands/group.d.ts.map +1 -0
- package/dist/commands/group.js +448 -0
- package/dist/commands/group.js.map +1 -0
- package/dist/commands/impact.d.ts +23 -0
- package/dist/commands/impact.d.ts.map +1 -0
- package/dist/commands/impact.js +91 -0
- package/dist/commands/impact.js.map +1 -0
- package/dist/commands/index-repo.d.ts +39 -0
- package/dist/commands/index-repo.d.ts.map +1 -0
- package/dist/commands/index-repo.js +148 -0
- package/dist/commands/index-repo.js.map +1 -0
- package/dist/commands/ingest-sarif.d.ts +64 -0
- package/dist/commands/ingest-sarif.d.ts.map +1 -0
- package/dist/commands/ingest-sarif.js +381 -0
- package/dist/commands/ingest-sarif.js.map +1 -0
- package/dist/commands/init.d.ts +75 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +315 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/list.d.ts +17 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +79 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/mcp.d.ts +8 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +28 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/open-store.d.ts +25 -0
- package/dist/commands/open-store.d.ts.map +1 -0
- package/dist/commands/open-store.js +47 -0
- package/dist/commands/open-store.js.map +1 -0
- package/dist/commands/pack.d.ts +35 -0
- package/dist/commands/pack.d.ts.map +1 -0
- package/dist/commands/pack.js +83 -0
- package/dist/commands/pack.js.map +1 -0
- package/dist/commands/query.d.ts +85 -0
- package/dist/commands/query.d.ts.map +1 -0
- package/dist/commands/query.js +309 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/scan.d.ts +81 -0
- package/dist/commands/scan.d.ts.map +1 -0
- package/dist/commands/scan.js +407 -0
- package/dist/commands/scan.js.map +1 -0
- package/dist/commands/setup.d.ts +178 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +370 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/sql.d.ts +19 -0
- package/dist/commands/sql.d.ts.map +1 -0
- package/dist/commands/sql.js +51 -0
- package/dist/commands/sql.js.map +1 -0
- package/dist/commands/status.d.ts +13 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +66 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/verdict-render.d.ts +33 -0
- package/dist/commands/verdict-render.d.ts.map +1 -0
- package/dist/commands/verdict-render.js +123 -0
- package/dist/commands/verdict-render.js.map +1 -0
- package/dist/commands/verdict.d.ts +61 -0
- package/dist/commands/verdict.d.ts.map +1 -0
- package/dist/commands/verdict.js +146 -0
- package/dist/commands/verdict.js.map +1 -0
- package/dist/commands/wiki.d.ts +26 -0
- package/dist/commands/wiki.d.ts.map +1 -0
- package/dist/commands/wiki.js +74 -0
- package/dist/commands/wiki.js.map +1 -0
- package/dist/editors/claude-code.d.ts +23 -0
- package/dist/editors/claude-code.d.ts.map +1 -0
- package/dist/editors/claude-code.js +58 -0
- package/dist/editors/claude-code.js.map +1 -0
- package/dist/editors/codex.d.ts +22 -0
- package/dist/editors/codex.d.ts.map +1 -0
- package/dist/editors/codex.js +59 -0
- package/dist/editors/codex.js.map +1 -0
- package/dist/editors/cursor.d.ts +13 -0
- package/dist/editors/cursor.d.ts.map +1 -0
- package/dist/editors/cursor.js +21 -0
- package/dist/editors/cursor.js.map +1 -0
- package/dist/editors/index.d.ts +12 -0
- package/dist/editors/index.d.ts.map +1 -0
- package/dist/editors/index.js +11 -0
- package/dist/editors/index.js.map +1 -0
- package/dist/editors/opencode.d.ts +23 -0
- package/dist/editors/opencode.d.ts.map +1 -0
- package/dist/editors/opencode.js +61 -0
- package/dist/editors/opencode.js.map +1 -0
- package/dist/editors/types.d.ts +33 -0
- package/dist/editors/types.d.ts.map +1 -0
- package/dist/editors/types.js +19 -0
- package/dist/editors/types.js.map +1 -0
- package/dist/editors/windows-wrap.d.ts +19 -0
- package/dist/editors/windows-wrap.d.ts.map +1 -0
- package/dist/editors/windows-wrap.js +28 -0
- package/dist/editors/windows-wrap.js.map +1 -0
- package/dist/editors/windsurf.d.ts +12 -0
- package/dist/editors/windsurf.d.ts.map +1 -0
- package/dist/editors/windsurf.js +21 -0
- package/dist/editors/windsurf.js.map +1 -0
- package/dist/embedder-downloader.d.ts +87 -0
- package/dist/embedder-downloader.d.ts.map +1 -0
- package/dist/embedder-downloader.js +261 -0
- package/dist/embedder-downloader.js.map +1 -0
- package/dist/fs-atomic.d.ts +22 -0
- package/dist/fs-atomic.d.ts.map +1 -0
- package/dist/fs-atomic.js +28 -0
- package/dist/fs-atomic.js.map +1 -0
- package/dist/groups.d.ts +64 -0
- package/dist/groups.d.ts.map +1 -0
- package/dist/groups.js +172 -0
- package/dist/groups.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +703 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/is-indexed.d.ts +20 -0
- package/dist/lib/is-indexed.d.ts.map +1 -0
- package/dist/lib/is-indexed.js +35 -0
- package/dist/lib/is-indexed.js.map +1 -0
- package/dist/registry.d.ts +64 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +145 -0
- package/dist/registry.js.map +1 -0
- package/dist/scip-downloader.d.ts +138 -0
- package/dist/scip-downloader.d.ts.map +1 -0
- package/dist/scip-downloader.js +372 -0
- package/dist/scip-downloader.js.map +1 -0
- package/dist/scip-pins.d.ts +99 -0
- package/dist/scip-pins.d.ts.map +1 -0
- package/dist/scip-pins.js +195 -0
- package/dist/scip-pins.js.map +1 -0
- package/dist/skills-gen.d.ts +47 -0
- package/dist/skills-gen.d.ts.map +1 -0
- package/dist/skills-gen.js +292 -0
- package/dist/skills-gen.js.map +1 -0
- package/package.json +81 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,703 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `codehub` CLI entrypoint.
|
|
4
|
+
*
|
|
5
|
+
* Every subcommand is loaded lazily via `await import(...)` so that
|
|
6
|
+
* `codehub --help` (and `codehub <command> --help`) stays fast: no DuckDB
|
|
7
|
+
* native binding, no pipeline, no MCP SDK unless we are actually going to
|
|
8
|
+
* run that subcommand.
|
|
9
|
+
*/
|
|
10
|
+
import { cpus } from "node:os";
|
|
11
|
+
import { Command } from "commander";
|
|
12
|
+
const program = new Command()
|
|
13
|
+
.name("codehub")
|
|
14
|
+
.version("0.0.0")
|
|
15
|
+
.description("OpenCodeHub — code-graph indexer and MCP server for coding agents");
|
|
16
|
+
program
|
|
17
|
+
.command("analyze [path]")
|
|
18
|
+
.description("Index a repository at [path] (default: current directory)")
|
|
19
|
+
.option("--force", "Ignore registry cache and re-run the pipeline")
|
|
20
|
+
.option("--embeddings", "Embed symbols and populate the DuckDB embeddings table")
|
|
21
|
+
.option("--embeddings-int8", "Use the int8 embedder variant (~23 MB) instead of fp32")
|
|
22
|
+
.option("--granularity <csv>", "Hierarchical embedding tiers to emit, comma-separated. Values: symbol, file, community. Default: symbol. Example: --granularity symbol,file,community")
|
|
23
|
+
.option("--embeddings-workers <n|auto>", 'Parallel ONNX embedder workers (each ~300 MB RSS on fp32). "auto" = os.cpus().length - 1, min 1. Default: "auto" when --embeddings is on (was 1 until 2026-04-27; single-threaded ONNX inference on a 100k-node repo took ~45 min, so CLI now opts into parallel by default). Pass --embeddings-workers 1 for the legacy in-process path.')
|
|
24
|
+
.option("--embeddings-batch-size <n>", "Chunks per embedBatch() call. Default 32. Set to 1 to restore the legacy one-node-per-call pattern.")
|
|
25
|
+
.option("--offline", "Assert no network access during analyze")
|
|
26
|
+
.option("--verbose", "Emit per-phase pipeline progress")
|
|
27
|
+
.option("--skip-agents-md", "Do not write the AGENTS.md / CLAUDE.md stanza")
|
|
28
|
+
.option("--sbom", "Emit .codehub/sbom.cyclonedx.json + .codehub/sbom.spdx.json from Dependency nodes")
|
|
29
|
+
.option("--coverage", "Overlay lcov/cobertura/jacoco/coverage.py report onto File nodes")
|
|
30
|
+
.option("--summaries", "Enable the summarize phase (default ON: structured Bedrock summaries per callable). Use --no-summaries to disable.")
|
|
31
|
+
.option("--no-summaries", "Disable the summarize phase entirely (equivalent to CODEHUB_BEDROCK_DISABLED=1).")
|
|
32
|
+
.option("--max-summaries <n|auto>", 'Cap on Bedrock summarize calls per run. "auto" (default) scales the cap to 10% of the SCIP-confirmed callable count (max 500).', "auto")
|
|
33
|
+
.option("--summary-model <id>", "Override the Bedrock model id used by the summarize phase (defaults to DEFAULT_MODEL_ID).")
|
|
34
|
+
.option("--skills", "After analyze, emit one SKILL.md per Community (symbolCount >= 5) under .codehub/skills/")
|
|
35
|
+
.option("--native-parser", "Opt into the native tree-sitter (N-API) runtime. Default is web-tree-sitter (WASM) for deterministic cross-platform behavior; pass --native-parser on Node 22 dev boxes where native parsing is measurably faster.")
|
|
36
|
+
.option("--strict-detectors", "Drop heuristic-only matches from the route / ORM detectors — emit edges only when the receiver's module origin was confirmed (DET-O-001)")
|
|
37
|
+
.option("--allow-build-scripts <list>", "Comma-separated opt-ins that enable build-script-driven indexers. Current value: `proleap` (JVM COBOL deep-parse). Unset → regex hot path only.")
|
|
38
|
+
.action(async (path, opts) => {
|
|
39
|
+
const mod = await import("./commands/analyze.js");
|
|
40
|
+
// `--native-parser` is honored by the parse worker via the
|
|
41
|
+
// `OCH_NATIVE_PARSER` env var; set it here before the worker pool
|
|
42
|
+
// spawns. WASM is the default runtime — native is opt-in.
|
|
43
|
+
if (opts["nativeParser"] === true) {
|
|
44
|
+
process.env["OCH_NATIVE_PARSER"] = "1";
|
|
45
|
+
}
|
|
46
|
+
// Pass the raw flag straight through to `runAnalyze`. The env
|
|
47
|
+
// kill-switch (`CODEHUB_BEDROCK_DISABLED=1`) is re-checked inside
|
|
48
|
+
// `runAnalyze` via `resolveSummariesEnabled` so tests that call
|
|
49
|
+
// `runAnalyze` directly honor the same truth table.
|
|
50
|
+
const summaries = opts["summaries"] === false ? false : undefined;
|
|
51
|
+
// --max-summaries accepts either a positive integer or the literal
|
|
52
|
+
// string "auto". Unknown strings fall back to "auto" so the CLI never
|
|
53
|
+
// refuses a run over flag syntax.
|
|
54
|
+
const rawMax = opts["maxSummaries"];
|
|
55
|
+
let maxSummariesPerRun;
|
|
56
|
+
if (rawMax === "auto" || rawMax === undefined) {
|
|
57
|
+
maxSummariesPerRun = "auto";
|
|
58
|
+
}
|
|
59
|
+
else if (typeof rawMax === "number" && Number.isFinite(rawMax)) {
|
|
60
|
+
maxSummariesPerRun = Math.max(0, Math.floor(rawMax));
|
|
61
|
+
}
|
|
62
|
+
else if (typeof rawMax === "string") {
|
|
63
|
+
const parsed = Number.parseInt(rawMax, 10);
|
|
64
|
+
maxSummariesPerRun = Number.isFinite(parsed) ? Math.max(0, parsed) : "auto";
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
maxSummariesPerRun = "auto";
|
|
68
|
+
}
|
|
69
|
+
const granularity = parseGranularityCsv(opts["granularity"]);
|
|
70
|
+
const allowBuildScripts = parseAllowBuildScripts(opts["allowBuildScripts"]);
|
|
71
|
+
// When --embeddings is on and the user didn't pick a worker count, default
|
|
72
|
+
// to "auto" — single-threaded ONNX inference on 100k+ nodes takes ~45 min
|
|
73
|
+
// vs ~6–8 min with all cores busy. Power users can still pass
|
|
74
|
+
// `--embeddings-workers 1` for the legacy path.
|
|
75
|
+
const workersRaw = opts["embeddings"] === true && opts["embeddingsWorkers"] === undefined
|
|
76
|
+
? "auto"
|
|
77
|
+
: opts["embeddingsWorkers"];
|
|
78
|
+
const embeddingsWorkers = parseWorkerCount(workersRaw);
|
|
79
|
+
const embeddingsBatchSize = parsePositiveInt(opts["embeddingsBatchSize"]);
|
|
80
|
+
await mod.runAnalyze(path ?? process.cwd(), {
|
|
81
|
+
force: opts["force"] === true,
|
|
82
|
+
embeddings: opts["embeddings"] === true,
|
|
83
|
+
embeddingsVariant: opts["embeddingsInt8"] === true ? "int8" : "fp32",
|
|
84
|
+
...(granularity !== undefined ? { embeddingsGranularity: granularity } : {}),
|
|
85
|
+
...(embeddingsWorkers !== undefined ? { embeddingsWorkers } : {}),
|
|
86
|
+
...(embeddingsBatchSize !== undefined ? { embeddingsBatchSize } : {}),
|
|
87
|
+
offline: opts["offline"] === true,
|
|
88
|
+
verbose: opts["verbose"] === true,
|
|
89
|
+
skipAgentsMd: opts["skipAgentsMd"] === true,
|
|
90
|
+
sbom: opts["sbom"] === true,
|
|
91
|
+
coverage: opts["coverage"] === true,
|
|
92
|
+
...(summaries === false ? { summaries } : {}),
|
|
93
|
+
maxSummariesPerRun,
|
|
94
|
+
...(typeof opts["summaryModel"] === "string" ? { summaryModel: opts["summaryModel"] } : {}),
|
|
95
|
+
skills: opts["skills"] === true,
|
|
96
|
+
strictDetectors: opts["strictDetectors"] === true,
|
|
97
|
+
...(allowBuildScripts !== undefined ? { allowBuildScripts } : {}),
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
program
|
|
101
|
+
.command("index [paths...]")
|
|
102
|
+
.description("Register an existing .codehub/ folder into the registry (no re-analysis). " +
|
|
103
|
+
"With no [paths], registers the current directory.")
|
|
104
|
+
.option("--force", "Stamp a minimal meta.json stub when .codehub/meta.json is missing")
|
|
105
|
+
.option("--allow-non-git", "Allow registering folders that are not git repositories")
|
|
106
|
+
.action(async (paths, opts) => {
|
|
107
|
+
const mod = await import("./commands/index-repo.js");
|
|
108
|
+
await mod.runIndexRepo(paths ?? [], {
|
|
109
|
+
force: opts["force"] === true,
|
|
110
|
+
allowNonGit: opts["allowNonGit"] === true,
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
program
|
|
114
|
+
.command("init [path]")
|
|
115
|
+
.description("Bootstrap a repo for OpenCodeHub — copies the Claude Code plugin assets into .claude/ (project-scope), writes .mcp.json, appends .codehub/ to .gitignore, seeds opencodehub.policy.yaml")
|
|
116
|
+
.option("--force", "Overwrite conflicting files under .claude/")
|
|
117
|
+
.option("--skip-mcp", "Skip writing .mcp.json")
|
|
118
|
+
.option("--skip-policy", "Skip seeding opencodehub.policy.yaml")
|
|
119
|
+
.action(async (path, opts) => {
|
|
120
|
+
const mod = await import("./commands/init.js");
|
|
121
|
+
const result = await mod.runInit({
|
|
122
|
+
...(path !== undefined ? { repo: path } : {}),
|
|
123
|
+
force: opts["force"] === true,
|
|
124
|
+
skipMcp: opts["skipMcp"] === true,
|
|
125
|
+
skipPolicy: opts["skipPolicy"] === true,
|
|
126
|
+
});
|
|
127
|
+
// One-line recap so the user knows what changed.
|
|
128
|
+
const bits = [`${result.filesCopied} file(s) into .claude/`];
|
|
129
|
+
if (result.mcpResult)
|
|
130
|
+
bits.push(`.mcp.json (${result.mcpResult.action})`);
|
|
131
|
+
if (result.gitignoreUpdated)
|
|
132
|
+
bits.push(".gitignore updated");
|
|
133
|
+
if (result.policySeeded)
|
|
134
|
+
bits.push("opencodehub.policy.yaml seeded");
|
|
135
|
+
console.warn(`codehub init: ${bits.join(" · ")}`);
|
|
136
|
+
console.warn("Next: run 'codehub analyze' to build the graph, then restart Claude Code.");
|
|
137
|
+
});
|
|
138
|
+
program
|
|
139
|
+
.command("setup")
|
|
140
|
+
.description("Write MCP config entries for supported editors, download embedder weights, or install SCIP adapter binaries")
|
|
141
|
+
.option("--editors <list>", "Comma-separated editor ids (claude-code,cursor,codex,windsurf,opencode). Default: all")
|
|
142
|
+
.option("--force", "Overwrite an existing codehub entry without prompting; re-download weights")
|
|
143
|
+
.option("--undo", "Restore the most recent .bak next to each config")
|
|
144
|
+
.option("--embeddings", "Download gte-modernbert-base ONNX weights (SHA256-pinned)")
|
|
145
|
+
.option("--int8", "Use the int8 weight variant (~150 MB) instead of fp32 (~596 MB)")
|
|
146
|
+
.option("--model-dir <path>", "Override the target directory for embedder weights")
|
|
147
|
+
.option("--plugin", "Install the Claude Code plugin to ~/.claude/plugins/opencodehub/")
|
|
148
|
+
.option("--scip <tool>", "Install an external SCIP adapter binary (clang|ruby|dotnet|kotlin) or 'all'. SHA256-pinned; dotnet requires .NET SDK 8+ on PATH")
|
|
149
|
+
.option("--cobol-proleap", "Build the uwol/cobol-parser library from source (git clone + mvn install) and compile the bridge wrapper. Requires git, mvn, JDK 17+ on PATH. Installs under ~/.codehub/vendor/proleap/")
|
|
150
|
+
.action(async (opts) => {
|
|
151
|
+
const mod = await import("./commands/setup.js");
|
|
152
|
+
if (opts["plugin"] === true) {
|
|
153
|
+
await mod.runSetupPlugin({});
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (opts["cobolProleap"] === true) {
|
|
157
|
+
await mod.runSetupCobolProleap({
|
|
158
|
+
force: opts["force"] === true,
|
|
159
|
+
});
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (typeof opts["scip"] === "string") {
|
|
163
|
+
const tool = mod.parseScipFlag(opts["scip"]);
|
|
164
|
+
await mod.runSetupScip({
|
|
165
|
+
tool,
|
|
166
|
+
force: opts["force"] === true,
|
|
167
|
+
});
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (opts["embeddings"] === true) {
|
|
171
|
+
const modelDir = typeof opts["modelDir"] === "string" ? opts["modelDir"] : undefined;
|
|
172
|
+
await mod.runSetupEmbeddings({
|
|
173
|
+
variant: opts["int8"] === true ? "int8" : "fp32",
|
|
174
|
+
...(modelDir !== undefined ? { modelDir } : {}),
|
|
175
|
+
force: opts["force"] === true,
|
|
176
|
+
});
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const editors = typeof opts["editors"] === "string" ? parseEditors(opts["editors"]) : undefined;
|
|
180
|
+
await mod.runSetup({
|
|
181
|
+
...(editors !== undefined ? { editors } : {}),
|
|
182
|
+
force: opts["force"] === true,
|
|
183
|
+
undo: opts["undo"] === true,
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
program
|
|
187
|
+
.command("mcp")
|
|
188
|
+
.description("Launch the codehub stdio MCP server")
|
|
189
|
+
.action(async () => {
|
|
190
|
+
const mod = await import("./commands/mcp.js");
|
|
191
|
+
await mod.runMcp();
|
|
192
|
+
});
|
|
193
|
+
program
|
|
194
|
+
.command("list")
|
|
195
|
+
.description("List all repos indexed on this machine")
|
|
196
|
+
.action(async () => {
|
|
197
|
+
const mod = await import("./commands/list.js");
|
|
198
|
+
await mod.runList();
|
|
199
|
+
});
|
|
200
|
+
program
|
|
201
|
+
.command("status [path]")
|
|
202
|
+
.description("Show index metadata for [path] (default: current directory)")
|
|
203
|
+
.action(async (path) => {
|
|
204
|
+
const mod = await import("./commands/status.js");
|
|
205
|
+
await mod.runStatus(path ?? process.cwd());
|
|
206
|
+
});
|
|
207
|
+
program
|
|
208
|
+
.command("clean [path]")
|
|
209
|
+
.description("Delete the index at [path]. --all deletes every registered index.")
|
|
210
|
+
.option("--all", "Delete every registered index")
|
|
211
|
+
.action(async (path, opts) => {
|
|
212
|
+
const mod = await import("./commands/clean.js");
|
|
213
|
+
await mod.runClean(path ?? process.cwd(), { all: opts["all"] === true });
|
|
214
|
+
});
|
|
215
|
+
program
|
|
216
|
+
.command("pack [path]")
|
|
217
|
+
.description("Produce a single-file LLM-ready snapshot of the repo via repomix (AST-compressed).")
|
|
218
|
+
.option("--style <style>", "Output style: xml|markdown|json|plain", "xml")
|
|
219
|
+
.option("--no-compress", "Disable tree-sitter AST compression (keeps full source)")
|
|
220
|
+
.option("--remove-comments", "Strip comments from the packed output")
|
|
221
|
+
.option("--out <path>", "Custom output path (default: <repo>/.codehub/pack/repo.<ext>)")
|
|
222
|
+
.action(async (path, opts) => {
|
|
223
|
+
const mod = await import("./commands/pack.js");
|
|
224
|
+
const style = opts["style"];
|
|
225
|
+
const result = await mod.runPack(path ?? process.cwd(), {
|
|
226
|
+
...(style !== undefined ? { style } : {}),
|
|
227
|
+
compress: opts["compress"] !== false,
|
|
228
|
+
removeComments: opts["removeComments"] === true,
|
|
229
|
+
...(typeof opts["out"] === "string" ? { outputPath: opts["out"] } : {}),
|
|
230
|
+
});
|
|
231
|
+
console.warn(`codehub pack: wrote ${result.bytes} bytes to ${result.outputPath} in ${result.durationMs}ms`);
|
|
232
|
+
});
|
|
233
|
+
program
|
|
234
|
+
.command("code-pack [path]")
|
|
235
|
+
.description("Produce the deterministic 9-item code-pack BOM (manifest + skeleton + file-tree + deps + " +
|
|
236
|
+
"ast-chunks + xrefs + findings + licenses + readme + optional embeddings.parquet) at " +
|
|
237
|
+
"<repo>/.codehub/packs/<packHash>/. Default engine is the new @opencodehub/pack BOM; " +
|
|
238
|
+
"--engine repomix opts into the legacy single-file snapshot (drop deferred to M7).")
|
|
239
|
+
.option("--budget <n>", "AST-chunker token budget (default 100000)", (v) => Number.parseInt(v, 10))
|
|
240
|
+
.option("--tokenizer <id>", 'Tokenizer pin "<vendor>:<name>@<pin>" (default openai:o200k_base@tiktoken-0.8.0)')
|
|
241
|
+
.option("--out-dir <dir>", "Override the .codehub/packs/<packHash>/ default output directory (the directory still " +
|
|
242
|
+
"contains the manifest + BOM bodies; supplying this flag lets you put the artifacts " +
|
|
243
|
+
"under a non-standard path, e.g. /tmp/my-pack)")
|
|
244
|
+
.option("--engine <engine>", "Engine: pack (default — 9-item BOM via @opencodehub/pack) or repomix (legacy single-file)", "pack")
|
|
245
|
+
.action(async (path, opts) => {
|
|
246
|
+
const mod = await import("./commands/code-pack.js");
|
|
247
|
+
const rawEngine = typeof opts["engine"] === "string" ? opts["engine"] : "pack";
|
|
248
|
+
const engine = rawEngine === "repomix" ? "repomix" : rawEngine === "pack" ? "pack" : "pack";
|
|
249
|
+
if (rawEngine !== engine && rawEngine !== "pack") {
|
|
250
|
+
throw new Error(`Unknown --engine value: "${rawEngine}". Expected one of: pack, repomix`);
|
|
251
|
+
}
|
|
252
|
+
const budget = typeof opts["budget"] === "number" && Number.isFinite(opts["budget"])
|
|
253
|
+
? opts["budget"]
|
|
254
|
+
: undefined;
|
|
255
|
+
const result = await mod.runCodePack({
|
|
256
|
+
...(path !== undefined ? { repo: path } : {}),
|
|
257
|
+
...(budget !== undefined ? { budget } : {}),
|
|
258
|
+
...(typeof opts["tokenizer"] === "string" ? { tokenizer: opts["tokenizer"] } : {}),
|
|
259
|
+
...(typeof opts["outDir"] === "string" ? { outDir: opts["outDir"] } : {}),
|
|
260
|
+
engine,
|
|
261
|
+
});
|
|
262
|
+
if (result.engine === "pack") {
|
|
263
|
+
console.warn(`codehub code-pack: wrote ${result.bomItemCount} BOM items to ${result.outDir} ` +
|
|
264
|
+
`(packHash=${result.packHash.slice(0, 12)})`);
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
console.warn(`codehub code-pack: wrote repomix snapshot to ${result.repomixOutputPath ?? result.outDir} ` +
|
|
268
|
+
`(packHash=${result.packHash.slice(0, 12)})`);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
program
|
|
272
|
+
.command("query <text>")
|
|
273
|
+
.description("Direct hybrid search against a repo's graph")
|
|
274
|
+
.option("--limit <n>", "Max results", (v) => Number.parseInt(v, 10), 10)
|
|
275
|
+
.option("--repo <name>", "Registered repo name (default: current directory)")
|
|
276
|
+
.option("--json", "Emit JSON on stdout")
|
|
277
|
+
.option("--content", "Attach full symbol source to each hit (capped at 2000 chars)")
|
|
278
|
+
.option("--context <text>", "What you are working on — prefixed to the query text to steer ranking")
|
|
279
|
+
.option("--goal <text>", "What you want to find — prefixed alongside --context to steer ranking")
|
|
280
|
+
.option("--max-symbols <n>", "Max symbols in process-grouped output (default 50)", (v) => Number.parseInt(v, 10))
|
|
281
|
+
.option("--bm25-only", "Skip the embedder probe and run BM25 search only")
|
|
282
|
+
.option("--rerank-top-k <n>", "RRF top-k passed to hybrid fusion (default 50)", (v) => Number.parseInt(v, 10))
|
|
283
|
+
.option("--zoom", "Enable coarse-to-fine retrieval (file tier → symbol tier). Requires an embedder and a hierarchical index (see `analyze --granularity symbol,file,community`).")
|
|
284
|
+
.option("--fanout <n>", "Files to shortlist at the coarse step when --zoom is on", (v) => Number.parseInt(v, 10))
|
|
285
|
+
.option("--granularity <tier>", "Restrict ANN to one hierarchical tier: symbol (default), file, or community")
|
|
286
|
+
.option("--force-backend-mismatch", "Bypass the embedder fingerprint check. Lets a query run when the persisted embedder model_id differs from the current one. Vectors may be stale.")
|
|
287
|
+
.action(async (text, opts) => {
|
|
288
|
+
const mod = await import("./commands/query.js");
|
|
289
|
+
const granularity = parseQueryGranularity(opts["granularity"]);
|
|
290
|
+
await mod.runQuery(text, {
|
|
291
|
+
limit: typeof opts["limit"] === "number" ? opts["limit"] : 10,
|
|
292
|
+
...(typeof opts["repo"] === "string" ? { repo: opts["repo"] } : {}),
|
|
293
|
+
json: opts["json"] === true,
|
|
294
|
+
content: opts["content"] === true,
|
|
295
|
+
...(typeof opts["context"] === "string" ? { context: opts["context"] } : {}),
|
|
296
|
+
...(typeof opts["goal"] === "string" ? { goal: opts["goal"] } : {}),
|
|
297
|
+
...(typeof opts["maxSymbols"] === "number" ? { maxSymbols: opts["maxSymbols"] } : {}),
|
|
298
|
+
bm25Only: opts["bm25Only"] === true,
|
|
299
|
+
...(typeof opts["rerankTopK"] === "number" ? { rerankTopK: opts["rerankTopK"] } : {}),
|
|
300
|
+
zoom: opts["zoom"] === true,
|
|
301
|
+
...(typeof opts["fanout"] === "number" ? { fanout: opts["fanout"] } : {}),
|
|
302
|
+
...(granularity !== undefined ? { granularity } : {}),
|
|
303
|
+
forceBackendMismatch: opts["forceBackendMismatch"] === true,
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
program
|
|
307
|
+
.command("context <symbol>")
|
|
308
|
+
.description("360° view of a symbol (callers, callees, flows)")
|
|
309
|
+
.option("--repo <name>", "Registered repo name (default: current directory)")
|
|
310
|
+
.option("--json", "Emit JSON on stdout")
|
|
311
|
+
.option("--target-uid <id>", "Exact node id from a prior result; bypasses name-based disambiguation")
|
|
312
|
+
.option("--file-path <hint>", "File path (or suffix) to disambiguate same-named symbols")
|
|
313
|
+
.option("--kind <kind>", "Kind filter (Function, Method, Class, Interface, …)")
|
|
314
|
+
.action(async (symbol, opts) => {
|
|
315
|
+
const mod = await import("./commands/context.js");
|
|
316
|
+
await mod.runContext(symbol, {
|
|
317
|
+
...(typeof opts["repo"] === "string" ? { repo: opts["repo"] } : {}),
|
|
318
|
+
json: opts["json"] === true,
|
|
319
|
+
...(typeof opts["targetUid"] === "string" ? { targetUid: opts["targetUid"] } : {}),
|
|
320
|
+
...(typeof opts["filePath"] === "string" ? { filePath: opts["filePath"] } : {}),
|
|
321
|
+
...(typeof opts["kind"] === "string" ? { kind: opts["kind"] } : {}),
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
program
|
|
325
|
+
.command("impact <symbol>")
|
|
326
|
+
.description("Blast-radius analysis for a symbol")
|
|
327
|
+
.option("--depth <n>", "Max traversal depth", (v) => Number.parseInt(v, 10), 3)
|
|
328
|
+
.option("--direction <dir>", "up | down | both", "both")
|
|
329
|
+
.option("--repo <name>", "Registered repo name (default: current directory)")
|
|
330
|
+
.option("--json", "Emit JSON on stdout")
|
|
331
|
+
.option("--target-uid <id>", "Exact node id from a prior result; bypasses name-based disambiguation")
|
|
332
|
+
.option("--file-path <hint>", "File path (or suffix) to disambiguate same-named symbols")
|
|
333
|
+
.option("--kind <kind>", "Kind filter (Function, Method, Class, Interface, …)")
|
|
334
|
+
.action(async (symbol, opts) => {
|
|
335
|
+
const mod = await import("./commands/impact.js");
|
|
336
|
+
const directionRaw = typeof opts["direction"] === "string" ? opts["direction"] : "both";
|
|
337
|
+
const direction = directionRaw === "up" || directionRaw === "down" ? directionRaw : "both";
|
|
338
|
+
await mod.runImpact(symbol, {
|
|
339
|
+
depth: typeof opts["depth"] === "number" ? opts["depth"] : 3,
|
|
340
|
+
direction,
|
|
341
|
+
...(typeof opts["repo"] === "string" ? { repo: opts["repo"] } : {}),
|
|
342
|
+
json: opts["json"] === true,
|
|
343
|
+
...(typeof opts["targetUid"] === "string" ? { targetUid: opts["targetUid"] } : {}),
|
|
344
|
+
...(typeof opts["filePath"] === "string" ? { filePath: opts["filePath"] } : {}),
|
|
345
|
+
...(typeof opts["kind"] === "string" ? { kind: opts["kind"] } : {}),
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
program
|
|
349
|
+
.command("detect-changes")
|
|
350
|
+
.description("Map an uncommitted or committed diff onto affected graph symbols + processes. Useful in CI without launching the MCP server.")
|
|
351
|
+
.option("--scope <scope>", "unstaged | staged | all | compare (default: all = working tree + index)", "all")
|
|
352
|
+
.option("--compare-ref <ref>", "Git ref to compare against (required when --scope=compare, e.g. origin/main)")
|
|
353
|
+
.option("--repo <name>", "Registered repo name (default: current directory)")
|
|
354
|
+
.option("--json", "Emit JSON on stdout")
|
|
355
|
+
.option("--strict", "Exit 1 on MEDIUM+ risk (default: exit 1 only on HIGH / CRITICAL)")
|
|
356
|
+
.action(async (opts) => {
|
|
357
|
+
const mod = await import("./commands/detect-changes.js");
|
|
358
|
+
const rawScope = typeof opts["scope"] === "string" ? opts["scope"] : "all";
|
|
359
|
+
const scope = rawScope === "unstaged" || rawScope === "staged" || rawScope === "compare" ? rawScope : "all";
|
|
360
|
+
if (rawScope !== scope && rawScope !== "all") {
|
|
361
|
+
throw new Error(`Unknown --scope value: "${rawScope}". Expected one of: unstaged, staged, all, compare`);
|
|
362
|
+
}
|
|
363
|
+
await mod.runDetectChangesCmd({
|
|
364
|
+
scope,
|
|
365
|
+
...(typeof opts["compareRef"] === "string" ? { compareRef: opts["compareRef"] } : {}),
|
|
366
|
+
...(typeof opts["repo"] === "string" ? { repo: opts["repo"] } : {}),
|
|
367
|
+
json: opts["json"] === true,
|
|
368
|
+
strict: opts["strict"] === true,
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
program
|
|
372
|
+
.command("verdict")
|
|
373
|
+
.description("5-tier PR verdict (auto_merge|single_review|dual_review|expert_review|block)")
|
|
374
|
+
.option("--base <ref>", "Base git ref", "main")
|
|
375
|
+
.option("--head <ref>", "Head git ref", "HEAD")
|
|
376
|
+
.option("--repo <name>", "Registered repo name (default: current directory)")
|
|
377
|
+
.option("--json", "Emit JSON on stdout instead of Markdown")
|
|
378
|
+
.action(async (opts) => {
|
|
379
|
+
const mod = await import("./commands/verdict.js");
|
|
380
|
+
await mod.runVerdict({
|
|
381
|
+
base: typeof opts["base"] === "string" ? opts["base"] : "main",
|
|
382
|
+
head: typeof opts["head"] === "string" ? opts["head"] : "HEAD",
|
|
383
|
+
...(typeof opts["repo"] === "string" ? { repo: opts["repo"] } : {}),
|
|
384
|
+
json: opts["json"] === true,
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
// `codehub group ...` — cross-repo groups. We register placeholder
|
|
388
|
+
// subcommands so `commander` routes the invocation correctly, and load the
|
|
389
|
+
// real handler lazily on .action(). This keeps `codehub --help` snappy.
|
|
390
|
+
{
|
|
391
|
+
const group = program.command("group").description("Manage named cross-repo groups");
|
|
392
|
+
group
|
|
393
|
+
.command("create <name> <repos...>")
|
|
394
|
+
.description("Create a group from registered repo names")
|
|
395
|
+
.option("--description <text>", "Short human-readable description")
|
|
396
|
+
.action(async (name, repos, opts) => {
|
|
397
|
+
const mod = await import("./commands/group.js");
|
|
398
|
+
await mod.runGroupCreate(name, repos, {
|
|
399
|
+
...(typeof opts["description"] === "string" ? { description: opts["description"] } : {}),
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
group
|
|
403
|
+
.command("list")
|
|
404
|
+
.description("List all groups")
|
|
405
|
+
.action(async () => {
|
|
406
|
+
const mod = await import("./commands/group.js");
|
|
407
|
+
await mod.runGroupList();
|
|
408
|
+
});
|
|
409
|
+
group
|
|
410
|
+
.command("delete <name>")
|
|
411
|
+
.description("Delete a group")
|
|
412
|
+
.action(async (name) => {
|
|
413
|
+
const mod = await import("./commands/group.js");
|
|
414
|
+
await mod.runGroupDelete(name);
|
|
415
|
+
});
|
|
416
|
+
group
|
|
417
|
+
.command("status <name>")
|
|
418
|
+
.description("Per-repo index freshness within a group")
|
|
419
|
+
.action(async (name) => {
|
|
420
|
+
const mod = await import("./commands/group.js");
|
|
421
|
+
await mod.runGroupStatus(name);
|
|
422
|
+
});
|
|
423
|
+
group
|
|
424
|
+
.command("query <name> <text>")
|
|
425
|
+
.description("BM25 over every repo in the group, fused with RRF")
|
|
426
|
+
.option("--limit <n>", "Max results (default 20)", (v) => Number.parseInt(v, 10), 20)
|
|
427
|
+
.option("--json", "Emit JSON on stdout")
|
|
428
|
+
.action(async (name, text, opts) => {
|
|
429
|
+
const mod = await import("./commands/group.js");
|
|
430
|
+
await mod.runGroupQuery(name, text, {
|
|
431
|
+
limit: typeof opts["limit"] === "number" ? opts["limit"] : 20,
|
|
432
|
+
json: opts["json"] === true,
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
group
|
|
436
|
+
.command("sync <name>")
|
|
437
|
+
.description("Extract cross-repo HTTP / gRPC / topic contracts and write ~/.codehub/groups/<name>/contracts.json")
|
|
438
|
+
.option("--json", "Emit the written registry on stdout")
|
|
439
|
+
.action(async (name, opts) => {
|
|
440
|
+
const mod = await import("./commands/group.js");
|
|
441
|
+
await mod.runGroupSyncCmd(name, {
|
|
442
|
+
json: opts["json"] === true,
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
program
|
|
447
|
+
.command("ingest-sarif <sarifFile>")
|
|
448
|
+
.description("Ingest a SARIF 2.1.0 log into the graph as Finding nodes + FOUND_IN edges")
|
|
449
|
+
.option("--repo <name>", "Registered repo name (default: current directory)")
|
|
450
|
+
.action(async (sarifFile, opts) => {
|
|
451
|
+
const mod = await import("./commands/ingest-sarif.js");
|
|
452
|
+
await mod.runIngestSarif(sarifFile, {
|
|
453
|
+
...(typeof opts["repo"] === "string" ? { repo: opts["repo"] } : {}),
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
program
|
|
457
|
+
.command("scan [path]")
|
|
458
|
+
.description("Run Priority-1 scanners and ingest findings into the graph")
|
|
459
|
+
.option("--scanners <list>", "Comma-separated scanner ids (overrides profile gating)")
|
|
460
|
+
.option("--with <list>", "Additional scanner ids to include (comma-separated)")
|
|
461
|
+
.option("--output <file>", "SARIF output path (default: <repo>/.codehub/scan.sarif)")
|
|
462
|
+
.option("--severity <list>", "Severity levels that fail the run (default: HIGH,CRITICAL)")
|
|
463
|
+
.option("--repo <name>", "Registered repo name (default: [path] or current directory)")
|
|
464
|
+
.option("--concurrency <n>", "Max parallel scanners", (v) => Number.parseInt(v, 10))
|
|
465
|
+
.option("--timeout <ms>", "Per-scanner timeout in ms", (v) => Number.parseInt(v, 10))
|
|
466
|
+
.action(async (path, opts) => {
|
|
467
|
+
const mod = await import("./commands/scan.js");
|
|
468
|
+
const scanners = typeof opts["scanners"] === "string" ? splitList(opts["scanners"]) : undefined;
|
|
469
|
+
const withScanners = typeof opts["with"] === "string" ? splitList(opts["with"]) : undefined;
|
|
470
|
+
const severity = typeof opts["severity"] === "string" ? splitList(opts["severity"]) : undefined;
|
|
471
|
+
const summary = await mod.runScan(path ?? process.cwd(), {
|
|
472
|
+
...(scanners !== undefined ? { scanners } : {}),
|
|
473
|
+
...(withScanners !== undefined ? { withScanners } : {}),
|
|
474
|
+
...(severity !== undefined ? { severity } : {}),
|
|
475
|
+
...(typeof opts["output"] === "string" ? { output: opts["output"] } : {}),
|
|
476
|
+
...(typeof opts["repo"] === "string" ? { repo: opts["repo"] } : {}),
|
|
477
|
+
...(typeof opts["concurrency"] === "number" ? { concurrency: opts["concurrency"] } : {}),
|
|
478
|
+
...(typeof opts["timeout"] === "number" ? { timeoutMs: opts["timeout"] } : {}),
|
|
479
|
+
});
|
|
480
|
+
if (summary.exitCode !== 0) {
|
|
481
|
+
process.exitCode = summary.exitCode;
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
program
|
|
485
|
+
.command("doctor")
|
|
486
|
+
.description("Probe the local environment (node/pnpm/native bindings/scanners/registry) and print actionable hints")
|
|
487
|
+
.option("--skip-native", "Skip checks that require native bindings (duckdb / tree-sitter)")
|
|
488
|
+
.option("--repoRoot <path>", "Override the workspace root used as a fallback for native-binding resolution")
|
|
489
|
+
.action(async (opts) => {
|
|
490
|
+
const mod = await import("./commands/doctor.js");
|
|
491
|
+
await mod.runDoctor({
|
|
492
|
+
skipNative: opts["skipNative"] === true,
|
|
493
|
+
...(typeof opts["repoRoot"] === "string" && opts["repoRoot"].length > 0
|
|
494
|
+
? { repoRoot: opts["repoRoot"] }
|
|
495
|
+
: {}),
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
program
|
|
499
|
+
.command("bench")
|
|
500
|
+
.description("Run the acceptance gate suite (scripts/acceptance.sh) and render a pass/fail dashboard")
|
|
501
|
+
.option("--acceptance <path>", "Override the path to scripts/acceptance.sh")
|
|
502
|
+
.option("--silent", "Suppress the listr2 progress renderer (useful in CI)")
|
|
503
|
+
.action(async (opts) => {
|
|
504
|
+
const mod = await import("./commands/bench.js");
|
|
505
|
+
await mod.runBench({
|
|
506
|
+
...(typeof opts["acceptance"] === "string" ? { acceptanceScript: opts["acceptance"] } : {}),
|
|
507
|
+
silent: opts["silent"] === true,
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
program
|
|
511
|
+
.command("wiki")
|
|
512
|
+
.description("Emit a Markdown wiki under --output (deterministic by default; --llm for LLM prose)")
|
|
513
|
+
.requiredOption("--output <dir>", "Target directory for rendered pages")
|
|
514
|
+
.option("--repo <name>", "Registered repo name (default: current directory)")
|
|
515
|
+
.option("--json", "Emit a JSON summary on stdout")
|
|
516
|
+
.option("--offline", "Assert no network access (incompatible with --llm)")
|
|
517
|
+
.option("--llm", "Route top-ranked modules through @opencodehub/summarizer for narrative prose")
|
|
518
|
+
.option("--max-llm-calls <n>", "Cap on Bedrock summarizer calls when --llm is set. 0 (default) runs in dry-run mode", (v) => Number.parseInt(v, 10), 0)
|
|
519
|
+
.option("--llm-model <id>", "Override the Bedrock model id passed to the summarizer")
|
|
520
|
+
.action(async (opts) => {
|
|
521
|
+
const mod = await import("./commands/wiki.js");
|
|
522
|
+
const output = typeof opts["output"] === "string" ? opts["output"] : "";
|
|
523
|
+
if (output.length === 0) {
|
|
524
|
+
throw new Error("--output <dir> is required");
|
|
525
|
+
}
|
|
526
|
+
const maxLlmCallsRaw = opts["maxLlmCalls"];
|
|
527
|
+
const maxLlmCalls = typeof maxLlmCallsRaw === "number" && Number.isFinite(maxLlmCallsRaw)
|
|
528
|
+
? Math.max(0, Math.floor(maxLlmCallsRaw))
|
|
529
|
+
: 0;
|
|
530
|
+
await mod.runWiki({
|
|
531
|
+
output,
|
|
532
|
+
...(typeof opts["repo"] === "string" ? { repo: opts["repo"] } : {}),
|
|
533
|
+
json: opts["json"] === true,
|
|
534
|
+
offline: opts["offline"] === true,
|
|
535
|
+
llm: opts["llm"] === true,
|
|
536
|
+
maxLlmCalls,
|
|
537
|
+
...(typeof opts["llmModel"] === "string" ? { llmModel: opts["llmModel"] } : {}),
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
program
|
|
541
|
+
.command("ci-init")
|
|
542
|
+
.description("Emit opinionated CI workflow files for GitHub Actions and/or GitLab CI")
|
|
543
|
+
.option("--platform <p>", "Target platform: github | gitlab | both (default: auto-detect)")
|
|
544
|
+
.option("--main-branch <b>", "Name of the main branch", "main")
|
|
545
|
+
.option("--repo <path>", "Repo root (default: current directory)")
|
|
546
|
+
.option("--force", "Overwrite existing workflow files")
|
|
547
|
+
.action(async (opts) => {
|
|
548
|
+
const mod = await import("./commands/ci-init.js");
|
|
549
|
+
const rawPlatform = typeof opts["platform"] === "string" ? opts["platform"] : undefined;
|
|
550
|
+
const platform = rawPlatform === "github" || rawPlatform === "gitlab" || rawPlatform === "both"
|
|
551
|
+
? rawPlatform
|
|
552
|
+
: undefined;
|
|
553
|
+
if (rawPlatform !== undefined && platform === undefined) {
|
|
554
|
+
throw new Error(`Unknown --platform value: ${rawPlatform}. Expected one of: github, gitlab, both.`);
|
|
555
|
+
}
|
|
556
|
+
await mod.runCiInit({
|
|
557
|
+
...(typeof opts["repo"] === "string" ? { repo: opts["repo"] } : {}),
|
|
558
|
+
...(platform !== undefined ? { platform } : {}),
|
|
559
|
+
...(typeof opts["mainBranch"] === "string" ? { mainBranch: opts["mainBranch"] } : {}),
|
|
560
|
+
force: opts["force"] === true,
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
program
|
|
564
|
+
.command("augment <pattern>")
|
|
565
|
+
.description("Fast-path BM25 enrichment for editor PreToolUse hooks — writes a compact context block to stderr")
|
|
566
|
+
.option("--limit <n>", "Max hits to enrich (default 5)", (v) => Number.parseInt(v, 10), 5)
|
|
567
|
+
.action(async (pattern, opts) => {
|
|
568
|
+
const mod = await import("./commands/augment.js");
|
|
569
|
+
await mod.runAugment(pattern, {
|
|
570
|
+
limit: typeof opts["limit"] === "number" ? opts["limit"] : 5,
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
program
|
|
574
|
+
.command("sql <query>")
|
|
575
|
+
.description("Run a read-only SQL query against the graph store")
|
|
576
|
+
.option("--repo <name>", "Registered repo name (default: current directory)")
|
|
577
|
+
.option("--timeout <ms>", "Per-query timeout in ms", (v) => Number.parseInt(v, 10), 5_000)
|
|
578
|
+
.option("--json", "Emit JSON on stdout")
|
|
579
|
+
.action(async (query, opts) => {
|
|
580
|
+
const mod = await import("./commands/sql.js");
|
|
581
|
+
await mod.runSql(query, {
|
|
582
|
+
...(typeof opts["repo"] === "string" ? { repo: opts["repo"] } : {}),
|
|
583
|
+
timeoutMs: typeof opts["timeout"] === "number" ? opts["timeout"] : 5_000,
|
|
584
|
+
json: opts["json"] === true,
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
function splitList(raw) {
|
|
588
|
+
return raw
|
|
589
|
+
.split(",")
|
|
590
|
+
.map((s) => s.trim())
|
|
591
|
+
.filter((s) => s.length > 0);
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Parse the single-value `--granularity` flag used by `codehub query`.
|
|
595
|
+
* Accepts exactly one tier (symbol/file/community); rejects CSV lists.
|
|
596
|
+
*/
|
|
597
|
+
function parseQueryGranularity(raw) {
|
|
598
|
+
if (typeof raw !== "string" || raw.trim() === "")
|
|
599
|
+
return undefined;
|
|
600
|
+
const trimmed = raw.trim();
|
|
601
|
+
if (trimmed === "symbol" || trimmed === "file" || trimmed === "community")
|
|
602
|
+
return trimmed;
|
|
603
|
+
throw new Error(`Unknown --granularity value: "${trimmed}". Expected one of: symbol, file, community`);
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Parse a comma-separated `--granularity` value into the narrow set of
|
|
607
|
+
* hierarchical embedding tiers the ingestion phase accepts. Returns
|
|
608
|
+
* `undefined` when the flag was not supplied so callers can preserve the
|
|
609
|
+
* upstream default (`["symbol"]`). Unknown tokens throw so users see the
|
|
610
|
+
* typo rather than a silent fallback.
|
|
611
|
+
*/
|
|
612
|
+
function parseGranularityCsv(raw) {
|
|
613
|
+
if (typeof raw !== "string" || raw.trim() === "")
|
|
614
|
+
return undefined;
|
|
615
|
+
const valid = new Set(["symbol", "file", "community"]);
|
|
616
|
+
const out = [];
|
|
617
|
+
const seen = new Set();
|
|
618
|
+
for (const token of splitList(raw)) {
|
|
619
|
+
if (!valid.has(token)) {
|
|
620
|
+
throw new Error(`Unknown granularity tier: "${token}". Expected one of: ${[...valid].join(", ")}`);
|
|
621
|
+
}
|
|
622
|
+
if (seen.has(token))
|
|
623
|
+
continue;
|
|
624
|
+
seen.add(token);
|
|
625
|
+
out.push(token);
|
|
626
|
+
}
|
|
627
|
+
return out;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Parse the `--allow-build-scripts` CSV flag for `codehub analyze`. Today
|
|
631
|
+
* the only recognized token is `proleap` (JVM COBOL deep-parse); unknown
|
|
632
|
+
* tokens throw so a typo surfaces immediately instead of silently leaving
|
|
633
|
+
* the build-script path disabled.
|
|
634
|
+
*
|
|
635
|
+
* Returns `undefined` when the flag is not supplied so the analyze pipeline
|
|
636
|
+
* preserves its own default ("regex hot path only, no JVM").
|
|
637
|
+
*/
|
|
638
|
+
function parseAllowBuildScripts(raw) {
|
|
639
|
+
if (typeof raw !== "string" || raw.trim() === "")
|
|
640
|
+
return undefined;
|
|
641
|
+
const valid = new Set(["proleap"]);
|
|
642
|
+
const out = [];
|
|
643
|
+
const seen = new Set();
|
|
644
|
+
for (const token of splitList(raw)) {
|
|
645
|
+
if (!valid.has(token)) {
|
|
646
|
+
throw new Error(`Unknown --allow-build-scripts value: "${token}". Expected one of: ${[...valid].join(", ")}`);
|
|
647
|
+
}
|
|
648
|
+
if (seen.has(token))
|
|
649
|
+
continue;
|
|
650
|
+
seen.add(token);
|
|
651
|
+
out.push(token);
|
|
652
|
+
}
|
|
653
|
+
return out;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Parse `--embeddings-workers`. Accepts a positive integer or the literal
|
|
657
|
+
* "auto" (resolves to `os.cpus().length - 1`, floor 1). Returns undefined
|
|
658
|
+
* when the flag wasn't supplied so the pipeline picks its own default.
|
|
659
|
+
*/
|
|
660
|
+
function parseWorkerCount(raw) {
|
|
661
|
+
if (raw === undefined)
|
|
662
|
+
return undefined;
|
|
663
|
+
if (raw === "auto") {
|
|
664
|
+
return Math.max(1, cpus().length - 1);
|
|
665
|
+
}
|
|
666
|
+
const parsed = typeof raw === "number" ? raw : Number.parseInt(String(raw), 10);
|
|
667
|
+
if (!Number.isFinite(parsed) || parsed < 1) {
|
|
668
|
+
throw new Error(`--embeddings-workers must be a positive integer or "auto"; got "${String(raw)}"`);
|
|
669
|
+
}
|
|
670
|
+
return Math.floor(parsed);
|
|
671
|
+
}
|
|
672
|
+
/** Parse a positive integer CLI flag, returning undefined when omitted. */
|
|
673
|
+
function parsePositiveInt(raw) {
|
|
674
|
+
if (raw === undefined)
|
|
675
|
+
return undefined;
|
|
676
|
+
const parsed = typeof raw === "number" ? raw : Number.parseInt(String(raw), 10);
|
|
677
|
+
if (!Number.isFinite(parsed) || parsed < 1) {
|
|
678
|
+
throw new Error(`expected a positive integer; got "${String(raw)}"`);
|
|
679
|
+
}
|
|
680
|
+
return Math.floor(parsed);
|
|
681
|
+
}
|
|
682
|
+
function parseEditors(raw) {
|
|
683
|
+
const valid = new Set(["claude-code", "cursor", "codex", "windsurf", "opencode"]);
|
|
684
|
+
const out = [];
|
|
685
|
+
for (const token of raw
|
|
686
|
+
.split(",")
|
|
687
|
+
.map((s) => s.trim())
|
|
688
|
+
.filter(Boolean)) {
|
|
689
|
+
if (valid.has(token)) {
|
|
690
|
+
out.push(token);
|
|
691
|
+
}
|
|
692
|
+
else {
|
|
693
|
+
throw new Error(`Unknown editor id: ${token}. Expected one of: ${[...valid].join(", ")}`);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return out;
|
|
697
|
+
}
|
|
698
|
+
program.parseAsync(process.argv).catch((err) => {
|
|
699
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
700
|
+
console.error(`codehub: ${message}`);
|
|
701
|
+
process.exitCode = 1;
|
|
702
|
+
});
|
|
703
|
+
//# sourceMappingURL=index.js.map
|