@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
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codehub init` — bootstrap a repository for OpenCodeHub in one command.
|
|
3
|
+
*
|
|
4
|
+
* Project-scope installer. Copies plugin assets (skills/agents/commands/hooks)
|
|
5
|
+
* into `<repo>/.claude/`, writes `.mcp.json` so Claude Code launches the
|
|
6
|
+
* `codehub` MCP server, appends `.codehub/` to `.gitignore`, and seeds a
|
|
7
|
+
* starter `opencodehub.policy.yaml` (commented out; rules ship in spec 002).
|
|
8
|
+
*
|
|
9
|
+
* Why project scope:
|
|
10
|
+
* - Checking `.claude/` into git means every teammate's Claude Code
|
|
11
|
+
* auto-discovers the plugin on clone. No per-machine install.
|
|
12
|
+
* - Keeps the plugin pinned to the repo's graph schema; upgrades are
|
|
13
|
+
* explicit (`codehub init --upgrade`) rather than ambient.
|
|
14
|
+
*
|
|
15
|
+
* Hook rewrite note:
|
|
16
|
+
* The plugin's `hooks.json` uses `${CLAUDE_PLUGIN_ROOT}` which is only
|
|
17
|
+
* bound for user-scope plugins. Project-scope hooks must use
|
|
18
|
+
* `${CLAUDE_PROJECT_DIR}/.claude` for Claude Code to find the shell
|
|
19
|
+
* scripts. We rewrite the token at install time and write the result
|
|
20
|
+
* to `.claude/settings.json` (the project-scope equivalent of
|
|
21
|
+
* `hooks.json`).
|
|
22
|
+
*
|
|
23
|
+
* Idempotence: re-running with identical args produces byte-identical
|
|
24
|
+
* output. Re-running against an existing `.claude/` refuses unless
|
|
25
|
+
* `--force` is set, and the error lists every conflicting file.
|
|
26
|
+
*
|
|
27
|
+
* Filesystem access goes through the same `FsApi` seam used by
|
|
28
|
+
* `commands/setup.ts` so tests run against an in-memory implementation.
|
|
29
|
+
*/
|
|
30
|
+
import { statSync } from "node:fs";
|
|
31
|
+
import { access, copyFile as fsCopyFile, mkdir as fsMkdir, readdir as fsReaddir, readFile as fsReadFile, rename as fsRename, rm as fsRm, stat as fsStat, } from "node:fs/promises";
|
|
32
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
33
|
+
import { fileURLToPath } from "node:url";
|
|
34
|
+
import { writeFileAtomic as defaultWriteFileAtomic } from "../fs-atomic.js";
|
|
35
|
+
import { runSetup } from "./setup.js";
|
|
36
|
+
const DEFAULT_FS = {
|
|
37
|
+
async readFile(path) {
|
|
38
|
+
return await fsReadFile(path, "utf8");
|
|
39
|
+
},
|
|
40
|
+
async writeFileAtomic(path, contents) {
|
|
41
|
+
await defaultWriteFileAtomic(path, contents, { raw: true });
|
|
42
|
+
},
|
|
43
|
+
async copyFile(src, dest) {
|
|
44
|
+
await fsCopyFile(src, dest);
|
|
45
|
+
},
|
|
46
|
+
async mkdir(path) {
|
|
47
|
+
await fsMkdir(path, { recursive: true });
|
|
48
|
+
},
|
|
49
|
+
async exists(path) {
|
|
50
|
+
try {
|
|
51
|
+
await access(path);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
async readdir(path) {
|
|
59
|
+
return (await fsReaddir(path, { withFileTypes: false }));
|
|
60
|
+
},
|
|
61
|
+
async rename(src, dest) {
|
|
62
|
+
await fsRename(src, dest);
|
|
63
|
+
},
|
|
64
|
+
async rm(path, opts) {
|
|
65
|
+
await fsRm(path, opts);
|
|
66
|
+
},
|
|
67
|
+
async statIsDirectory(path) {
|
|
68
|
+
try {
|
|
69
|
+
const st = await fsStat(path);
|
|
70
|
+
return st.isDirectory();
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Entry point for `codehub init`. Returns a structured result; throws on
|
|
79
|
+
* unrecoverable error (e.g., plugin source missing, conflicts without
|
|
80
|
+
* `--force`).
|
|
81
|
+
*/
|
|
82
|
+
export async function runInit(opts = {}) {
|
|
83
|
+
const fs = opts.fs ?? DEFAULT_FS;
|
|
84
|
+
const log = opts.log ?? ((msg) => console.warn(msg));
|
|
85
|
+
const warn = opts.warn ?? ((msg) => console.warn(msg));
|
|
86
|
+
const repoRoot = resolve(opts.repo ?? process.cwd());
|
|
87
|
+
const sourceDir = opts.sourceDir ?? defaultPluginSourceDir();
|
|
88
|
+
const claudeDir = resolve(repoRoot, ".claude");
|
|
89
|
+
const force = opts.force === true;
|
|
90
|
+
if (!(await fs.exists(sourceDir))) {
|
|
91
|
+
throw new Error(`codehub init: plugin source not found at ${sourceDir}. Re-install the codehub CLI or run from a workspace checkout.`);
|
|
92
|
+
}
|
|
93
|
+
const plan = await buildInstallPlan(fs, sourceDir, claudeDir);
|
|
94
|
+
if (!force) {
|
|
95
|
+
const conflicts = await detectConflicts(fs, plan);
|
|
96
|
+
if (conflicts.length > 0) {
|
|
97
|
+
const lines = conflicts.map((p) => ` - ${relative(repoRoot, p)}`).join("\n");
|
|
98
|
+
throw new Error(`codehub init: refusing to overwrite ${conflicts.length} existing file(s):\n${lines}\nRe-run with --force to overwrite.`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
for (const step of plan) {
|
|
102
|
+
await fs.mkdir(dirname(step.targetPath));
|
|
103
|
+
if (step.source === "copy") {
|
|
104
|
+
await fs.copyFile(step.sourcePath, step.targetPath);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
await fs.writeFileAtomic(step.targetPath, step.contents);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const filesCopied = plan.length;
|
|
111
|
+
log(`codehub init: installed ${filesCopied} file(s) under ${relative(repoRoot, claudeDir)}/`);
|
|
112
|
+
// Write project-scope hooks — rewrite of the plugin's hooks.json.
|
|
113
|
+
const hooksTarget = resolve(claudeDir, "settings.json");
|
|
114
|
+
const hooksWritten = await writeProjectScopeHooks(fs, sourceDir, hooksTarget, log, warn);
|
|
115
|
+
// MCP entry via the existing setup pipeline (single editor: claude-code).
|
|
116
|
+
let mcpResult = null;
|
|
117
|
+
if (opts.skipMcp !== true) {
|
|
118
|
+
const setupOpts = {
|
|
119
|
+
editors: ["claude-code"],
|
|
120
|
+
projectRoot: repoRoot,
|
|
121
|
+
fs,
|
|
122
|
+
log,
|
|
123
|
+
warn,
|
|
124
|
+
...(opts.home !== undefined ? { home: opts.home } : {}),
|
|
125
|
+
};
|
|
126
|
+
const results = await runSetup(setupOpts);
|
|
127
|
+
mcpResult = results[0] ?? null;
|
|
128
|
+
}
|
|
129
|
+
// Append `.codehub/` to .gitignore (idempotent).
|
|
130
|
+
const gitignoreUpdated = await ensureGitignoreEntry(fs, repoRoot, ".codehub/", log);
|
|
131
|
+
// Seed opencodehub.policy.yaml (commented-out starter).
|
|
132
|
+
let policySeeded = false;
|
|
133
|
+
if (opts.skipPolicy !== true) {
|
|
134
|
+
policySeeded = await seedPolicyFile(fs, repoRoot, log);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
repoRoot,
|
|
138
|
+
sourceDir,
|
|
139
|
+
claudeDir,
|
|
140
|
+
filesCopied,
|
|
141
|
+
hooksWrittenTo: hooksWritten ? hooksTarget : null,
|
|
142
|
+
mcpResult,
|
|
143
|
+
gitignoreUpdated,
|
|
144
|
+
policySeeded,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
async function buildInstallPlan(fs, sourceDir, claudeDir) {
|
|
148
|
+
const plan = [];
|
|
149
|
+
// The plugin root maps onto `.claude/` directly: skills → .claude/skills,
|
|
150
|
+
// agents → .claude/agents, commands → .claude/commands, hooks → .claude/hooks.
|
|
151
|
+
for (const entry of ["skills", "agents", "commands", "hooks"]) {
|
|
152
|
+
const src = join(sourceDir, entry);
|
|
153
|
+
const dest = join(claudeDir, entry);
|
|
154
|
+
if (!(await fs.exists(src)))
|
|
155
|
+
continue;
|
|
156
|
+
await collectCopySteps(fs, src, dest, plan);
|
|
157
|
+
}
|
|
158
|
+
return plan;
|
|
159
|
+
}
|
|
160
|
+
async function collectCopySteps(fs, src, dest, out) {
|
|
161
|
+
if (!fs.readdir) {
|
|
162
|
+
throw new Error("FsApi.readdir is required for init plan building");
|
|
163
|
+
}
|
|
164
|
+
const entries = await fs.readdir(src);
|
|
165
|
+
for (const name of entries) {
|
|
166
|
+
const from = join(src, name);
|
|
167
|
+
const to = join(dest, name);
|
|
168
|
+
const isDir = fs.statIsDirectory ? await fs.statIsDirectory(from) : false;
|
|
169
|
+
if (isDir) {
|
|
170
|
+
await collectCopySteps(fs, from, to, out);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
out.push({ source: "copy", sourcePath: from, targetPath: to });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function detectConflicts(fs, plan) {
|
|
178
|
+
const conflicts = [];
|
|
179
|
+
for (const step of plan) {
|
|
180
|
+
if (await fs.exists(step.targetPath))
|
|
181
|
+
conflicts.push(step.targetPath);
|
|
182
|
+
}
|
|
183
|
+
return conflicts;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Convert the plugin's user-scope `hooks.json` into a project-scope
|
|
187
|
+
* `.claude/settings.json`. Claude Code resolves `${CLAUDE_PROJECT_DIR}` at
|
|
188
|
+
* runtime to the repo root, so we rewrite `${CLAUDE_PLUGIN_ROOT}` → that.
|
|
189
|
+
*/
|
|
190
|
+
async function writeProjectScopeHooks(fs, sourceDir, targetPath, log, warn) {
|
|
191
|
+
const pluginHooksPath = join(sourceDir, "hooks.json");
|
|
192
|
+
if (!(await fs.exists(pluginHooksPath))) {
|
|
193
|
+
warn(`codehub init: plugin hooks.json missing at ${pluginHooksPath}; skipping project-scope hook wire-up.`);
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
const raw = await fs.readFile(pluginHooksPath);
|
|
197
|
+
const rewritten = raw
|
|
198
|
+
// biome-ignore lint/suspicious/noTemplateCurlyInString: literal token to substitute
|
|
199
|
+
.replaceAll("${CLAUDE_PLUGIN_ROOT}", "${CLAUDE_PROJECT_DIR}/.claude");
|
|
200
|
+
const parsed = JSON.parse(rewritten);
|
|
201
|
+
// Merge into existing .claude/settings.json if present. Only the `hooks`
|
|
202
|
+
// key is upserted; every sibling key is preserved.
|
|
203
|
+
const existing = (await fs.exists(targetPath)) ? await fs.readFile(targetPath) : undefined;
|
|
204
|
+
const doc = existing && existing.trim().length > 0 ? JSON.parse(existing) : {};
|
|
205
|
+
doc["hooks"] = parsed["hooks"];
|
|
206
|
+
const merged = `${JSON.stringify(doc, null, 2)}\n`;
|
|
207
|
+
if (existing === merged) {
|
|
208
|
+
log(`codehub init: ${relative(dirname(dirname(targetPath)), targetPath)} already up to date`);
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
await fs.writeFileAtomic(targetPath, merged);
|
|
212
|
+
log(`codehub init: wrote hooks to ${targetPath}`);
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
async function ensureGitignoreEntry(fs, repoRoot, line, log) {
|
|
216
|
+
const target = join(repoRoot, ".gitignore");
|
|
217
|
+
const existing = (await fs.exists(target)) ? await fs.readFile(target) : "";
|
|
218
|
+
const lines = existing.split(/\r?\n/);
|
|
219
|
+
const alreadyPresent = lines.some((l) => l.trim() === line.trim());
|
|
220
|
+
if (alreadyPresent)
|
|
221
|
+
return false;
|
|
222
|
+
const suffix = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
223
|
+
const appended = `${existing}${suffix}# OpenCodeHub local state\n${line}\n`;
|
|
224
|
+
await fs.writeFileAtomic(target, appended);
|
|
225
|
+
log(`codehub init: appended "${line}" to .gitignore`);
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
const POLICY_STARTER = `# OpenCodeHub policy (v1 — starter, all rules commented out)
|
|
229
|
+
#
|
|
230
|
+
# Consumed by 'codehub verdict' (ships in spec 002 P1). Uncomment the
|
|
231
|
+
# rule types you want to enforce. Schema:
|
|
232
|
+
# packages/policy/schemas/policy-v1.json (once spec 002 lands)
|
|
233
|
+
#
|
|
234
|
+
# See ADR 0007 for scope rationale. Self-hosted OSS only — no calls
|
|
235
|
+
# to any OpenCodeHub-operated service from this file or from the CI
|
|
236
|
+
# actions that consume it.
|
|
237
|
+
#
|
|
238
|
+
# version: 1
|
|
239
|
+
#
|
|
240
|
+
# auto_approve:
|
|
241
|
+
# require:
|
|
242
|
+
# - blast_radius.tier: ">= 3" # only tier-3-or-safer PRs auto-approve
|
|
243
|
+
# - findings.severity_error: 0
|
|
244
|
+
# - license_audit.violations: 0
|
|
245
|
+
#
|
|
246
|
+
# rules:
|
|
247
|
+
# - id: no-disallowed-licenses
|
|
248
|
+
# type: license_allowlist
|
|
249
|
+
# deny: ["GPL-3.0", "AGPL-3.0"]
|
|
250
|
+
#
|
|
251
|
+
# - id: require-storage-owner
|
|
252
|
+
# type: ownership_required
|
|
253
|
+
# paths: ["packages/storage/**"]
|
|
254
|
+
# require_approval_from: ["@storage-team"]
|
|
255
|
+
#
|
|
256
|
+
# - id: blast-radius-cap
|
|
257
|
+
# type: blast_radius_max
|
|
258
|
+
# max_tier: 2
|
|
259
|
+
`;
|
|
260
|
+
async function seedPolicyFile(fs, repoRoot, log) {
|
|
261
|
+
const target = join(repoRoot, "opencodehub.policy.yaml");
|
|
262
|
+
if (await fs.exists(target))
|
|
263
|
+
return false;
|
|
264
|
+
await fs.writeFileAtomic(target, POLICY_STARTER);
|
|
265
|
+
log(`codehub init: seeded opencodehub.policy.yaml (all rules commented out)`);
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Resolve the bundled plugin source dir.
|
|
270
|
+
*
|
|
271
|
+
* When running from source inside the monorepo (e.g. `pnpm -F cli dev`),
|
|
272
|
+
* walk up to the repo root and read `plugins/opencodehub/`. When running
|
|
273
|
+
* from the published `dist/`, use the `dist/plugin-assets/` tree produced
|
|
274
|
+
* by `scripts/copy-plugin-assets.mjs`.
|
|
275
|
+
*/
|
|
276
|
+
function defaultPluginSourceDir() {
|
|
277
|
+
const thisFile = fileURLToPath(import.meta.url);
|
|
278
|
+
let dir = dirname(thisFile);
|
|
279
|
+
// First check: bundled dist assets (standard install case).
|
|
280
|
+
const bundled = join(dir, "..", "plugin-assets");
|
|
281
|
+
try {
|
|
282
|
+
const st = statSyncSafe(bundled);
|
|
283
|
+
if (st?.isDirectory())
|
|
284
|
+
return resolve(bundled);
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
// keep looking
|
|
288
|
+
}
|
|
289
|
+
// Fallback: walk up looking for `plugins/opencodehub/` (monorepo-source case).
|
|
290
|
+
for (let i = 0; i < 8; i += 1) {
|
|
291
|
+
const candidate = join(dir, "plugins", "opencodehub");
|
|
292
|
+
try {
|
|
293
|
+
const st = statSyncSafe(candidate);
|
|
294
|
+
if (st?.isDirectory())
|
|
295
|
+
return candidate;
|
|
296
|
+
}
|
|
297
|
+
catch {
|
|
298
|
+
// keep walking
|
|
299
|
+
}
|
|
300
|
+
const parent = dirname(dir);
|
|
301
|
+
if (parent === dir)
|
|
302
|
+
break;
|
|
303
|
+
dir = parent;
|
|
304
|
+
}
|
|
305
|
+
return resolve(dirname(thisFile), "..", "..", "..", "..", "plugins", "opencodehub");
|
|
306
|
+
}
|
|
307
|
+
function statSyncSafe(path) {
|
|
308
|
+
try {
|
|
309
|
+
return statSync(path);
|
|
310
|
+
}
|
|
311
|
+
catch {
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.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a plain-text table on stdout so users can pipe it through `awk`
|
|
5
|
+
* or similar. No JSON mode in MVP.
|
|
6
|
+
*
|
|
7
|
+
* Health check: each row gets an annotation column that flags dangling
|
|
8
|
+
* registry entries (path missing on disk) and missing graph DBs. A dangling
|
|
9
|
+
* entry happens when a repo is moved/deleted without running `codehub clean`
|
|
10
|
+
* — the registry keeps the stale pointer and every subsequent group / MCP
|
|
11
|
+
* lookup silently half-works. Surface it.
|
|
12
|
+
*/
|
|
13
|
+
export interface ListOptions {
|
|
14
|
+
readonly home?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function runList(opts?: ListOptions): Promise<void>;
|
|
17
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAsB,OAAO,CAAC,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CASnE"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codehub list` — print one row per registered repo.
|
|
3
|
+
*
|
|
4
|
+
* Output is a plain-text table on stdout so users can pipe it through `awk`
|
|
5
|
+
* or similar. No JSON mode in MVP.
|
|
6
|
+
*
|
|
7
|
+
* Health check: each row gets an annotation column that flags dangling
|
|
8
|
+
* registry entries (path missing on disk) and missing graph DBs. A dangling
|
|
9
|
+
* entry happens when a repo is moved/deleted without running `codehub clean`
|
|
10
|
+
* — the registry keeps the stale pointer and every subsequent group / MCP
|
|
11
|
+
* lookup silently half-works. Surface it.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync } from "node:fs";
|
|
14
|
+
import { codehubIsIndexed } from "../lib/is-indexed.js";
|
|
15
|
+
import { readRegistry } from "../registry.js";
|
|
16
|
+
export async function runList(opts = {}) {
|
|
17
|
+
const registryOpts = opts.home !== undefined ? { home: opts.home } : {};
|
|
18
|
+
const registry = await readRegistry(registryOpts);
|
|
19
|
+
const entries = Object.values(registry);
|
|
20
|
+
if (entries.length === 0) {
|
|
21
|
+
console.warn("No repos indexed yet. Run `codehub analyze` in a git repo.");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
printTable(entries);
|
|
25
|
+
}
|
|
26
|
+
function classifyHealth(entry) {
|
|
27
|
+
if (!existsSync(entry.path))
|
|
28
|
+
return "path-missing";
|
|
29
|
+
// Backend-aware probe: any of `meta.json`, `graph.duckdb`, or
|
|
30
|
+
// `graph.lbug` under `.codehub/` counts as "indexed". The legacy
|
|
31
|
+
// hard-coded `graph.duckdb` check pre-dated the M3 backend split and
|
|
32
|
+
// would have flagged every `CODEHUB_STORE=lbug` repo as broken.
|
|
33
|
+
if (!codehubIsIndexed(entry.path))
|
|
34
|
+
return "graph-missing";
|
|
35
|
+
return "ok";
|
|
36
|
+
}
|
|
37
|
+
function healthLabel(h) {
|
|
38
|
+
switch (h) {
|
|
39
|
+
case "ok":
|
|
40
|
+
return "ok";
|
|
41
|
+
case "path-missing":
|
|
42
|
+
return "⚠ missing path";
|
|
43
|
+
case "graph-missing":
|
|
44
|
+
return "⚠ no index";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function printTable(entries) {
|
|
48
|
+
const rows = entries.map((e) => {
|
|
49
|
+
const health = classifyHealth(e);
|
|
50
|
+
return {
|
|
51
|
+
name: e.name,
|
|
52
|
+
path: e.path,
|
|
53
|
+
lastCommit: e.lastCommit ? e.lastCommit.slice(0, 8) : "-",
|
|
54
|
+
indexedAt: e.indexedAt.slice(0, 19),
|
|
55
|
+
nodes: String(e.nodeCount),
|
|
56
|
+
health: healthLabel(health),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
const headers = ["NAME", "PATH", "COMMIT", "INDEXED_AT", "NODES", "HEALTH"];
|
|
60
|
+
const widths = headers.map((h) => h.length);
|
|
61
|
+
for (const r of rows) {
|
|
62
|
+
widths[0] = Math.max(widths[0] ?? 0, r.name.length);
|
|
63
|
+
widths[1] = Math.max(widths[1] ?? 0, r.path.length);
|
|
64
|
+
widths[2] = Math.max(widths[2] ?? 0, r.lastCommit.length);
|
|
65
|
+
widths[3] = Math.max(widths[3] ?? 0, r.indexedAt.length);
|
|
66
|
+
widths[4] = Math.max(widths[4] ?? 0, r.nodes.length);
|
|
67
|
+
widths[5] = Math.max(widths[5] ?? 0, r.health.length);
|
|
68
|
+
}
|
|
69
|
+
const line = (cols) => cols.map((c, i) => c.padEnd(widths[i] ?? 0)).join(" ");
|
|
70
|
+
console.log(line(headers));
|
|
71
|
+
for (const r of rows) {
|
|
72
|
+
console.log(line([r.name, r.path, r.lastCommit, r.indexedAt, r.nodes, r.health]));
|
|
73
|
+
}
|
|
74
|
+
const unhealthy = rows.filter((r) => r.health !== "ok");
|
|
75
|
+
if (unhealthy.length > 0) {
|
|
76
|
+
console.warn(`\n${unhealthy.length} of ${rows.length} entries need attention. Run \`codehub clean <path>\` to remove a dangling entry, or re-analyze a missing graph.`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/commands/list.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAkB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAM9D,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,OAAoB,EAAE;IAClD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CA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,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,IAAI,GAAG,CAAC,IAAuB,EAAU,EAAE,CAC/C,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3B,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACpF,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC;IACxD,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,CACV,KAAK,SAAS,CAAC,MAAM,OAAO,IAAI,CAAC,MAAM,kHAAkH,CAC1J,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codehub mcp` — launch the stdio MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Surfaces a friendly error instead of a cryptic import failure when
|
|
5
|
+
* `@opencodehub/mcp` has not been built yet.
|
|
6
|
+
*/
|
|
7
|
+
export declare function runMcp(): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAsB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CA2B5C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codehub mcp` — launch the stdio MCP server.
|
|
3
|
+
*
|
|
4
|
+
* Surfaces a friendly error instead of a cryptic import failure when
|
|
5
|
+
* `@opencodehub/mcp` has not been built yet.
|
|
6
|
+
*/
|
|
7
|
+
export async function runMcp() {
|
|
8
|
+
let mod;
|
|
9
|
+
try {
|
|
10
|
+
// Dynamic string import so TypeScript does not require the dependency to
|
|
11
|
+
// be built at CLI build time. The @opencodehub/mcp package owns startStdioServer.
|
|
12
|
+
const specifier = "@opencodehub/mcp";
|
|
13
|
+
mod = await import(specifier);
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.error(`codehub mcp: the @opencodehub/mcp package is not built yet. Build it first.\n` +
|
|
17
|
+
` cause: ${err.message}`);
|
|
18
|
+
process.exit(2);
|
|
19
|
+
}
|
|
20
|
+
const candidate = mod;
|
|
21
|
+
if (typeof candidate.startStdioServer !== "function") {
|
|
22
|
+
console.error("codehub mcp: @opencodehub/mcp does not export startStdioServer(). " +
|
|
23
|
+
"Rebuild @opencodehub/mcp so it exports startStdioServer().");
|
|
24
|
+
process.exit(2);
|
|
25
|
+
}
|
|
26
|
+
await candidate.startStdioServer();
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,IAAI,GAAY,CAAC;IACjB,IAAI,CAAC;QACH,yEAAyE;QACzE,kFAAkF;QAClF,MAAM,SAAS,GAAG,kBAAkB,CAAC;QACrC,GAAG,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CACX,+EAA+E;YAC7E,YAAa,GAAa,CAAC,OAAO,EAAE,CACvC,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,SAAS,GAAG,GAEjB,CAAC;IACF,IAAI,OAAO,SAAS,CAAC,gBAAgB,KAAK,UAAU,EAAE,CAAC;QACrD,OAAO,CAAC,KAAK,CACX,oEAAoE;YAClE,4DAA4D,CAC/D,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,SAAS,CAAC,gBAAgB,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a repo path — from `--repo <name>` if given, else from the CWD —
|
|
3
|
+
* and open a read-only `Store` (composed graph + temporal). Used by
|
|
4
|
+
* `query`, `context`, `impact`, `sql`, and `detect-changes`.
|
|
5
|
+
*
|
|
6
|
+
* Returns the canonical {@link Store} envelope from `@opencodehub/storage`
|
|
7
|
+
* so callers can route graph-tier queries through `store.graph` and
|
|
8
|
+
* temporal-tier queries (cochanges, summaries, `--sql` escape hatch)
|
|
9
|
+
* through `store.temporal`. Backend selection follows the standard
|
|
10
|
+
* `openStore` resolution (env-driven `CODEHUB_STORE`, with auto-detect
|
|
11
|
+
* when unset).
|
|
12
|
+
*/
|
|
13
|
+
import { type Store } from "@opencodehub/storage";
|
|
14
|
+
export interface OpenStoreOptions {
|
|
15
|
+
readonly repo?: string;
|
|
16
|
+
readonly home?: string;
|
|
17
|
+
readonly readOnly?: boolean;
|
|
18
|
+
readonly backend?: "auto" | "duck" | "lbug";
|
|
19
|
+
}
|
|
20
|
+
export interface OpenStoreResult {
|
|
21
|
+
readonly repoPath: string;
|
|
22
|
+
readonly store: Store;
|
|
23
|
+
}
|
|
24
|
+
export declare function openStoreForCommand(opts: OpenStoreOptions): Promise<OpenStoreResult>;
|
|
25
|
+
//# sourceMappingURL=open-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-store.d.ts","sourceRoot":"","sources":["../../src/commands/open-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAA4B,KAAK,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAG5E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAC7C;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;CACvB;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAkB1F"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve a repo path — from `--repo <name>` if given, else from the CWD —
|
|
3
|
+
* and open a read-only `Store` (composed graph + temporal). Used by
|
|
4
|
+
* `query`, `context`, `impact`, `sql`, and `detect-changes`.
|
|
5
|
+
*
|
|
6
|
+
* Returns the canonical {@link Store} envelope from `@opencodehub/storage`
|
|
7
|
+
* so callers can route graph-tier queries through `store.graph` and
|
|
8
|
+
* temporal-tier queries (cochanges, summaries, `--sql` escape hatch)
|
|
9
|
+
* through `store.temporal`. Backend selection follows the standard
|
|
10
|
+
* `openStore` resolution (env-driven `CODEHUB_STORE`, with auto-detect
|
|
11
|
+
* when unset).
|
|
12
|
+
*/
|
|
13
|
+
import { resolve } from "node:path";
|
|
14
|
+
import { openStore, resolveDbPath } from "@opencodehub/storage";
|
|
15
|
+
import { readRegistry } from "../registry.js";
|
|
16
|
+
export async function openStoreForCommand(opts) {
|
|
17
|
+
const repoPath = await resolveRepoPath(opts);
|
|
18
|
+
const dbPath = resolveDbPath(repoPath);
|
|
19
|
+
const store = await openStore({
|
|
20
|
+
path: dbPath,
|
|
21
|
+
backend: opts.backend ?? "auto",
|
|
22
|
+
readOnly: opts.readOnly ?? true,
|
|
23
|
+
});
|
|
24
|
+
// The legacy CLI entry point opened the DuckDB connection eagerly and
|
|
25
|
+
// every command consumed an already-open store. The `openStore` factory
|
|
26
|
+
// only constructs adapters; opening is the lifecycle owner's job. Keep
|
|
27
|
+
// that contract by opening both views here so command handlers stay a
|
|
28
|
+
// simple try/finally pair around the work.
|
|
29
|
+
await store.graph.open();
|
|
30
|
+
if (store.graphFile !== store.temporalFile) {
|
|
31
|
+
await store.temporal.open();
|
|
32
|
+
}
|
|
33
|
+
return { repoPath, store };
|
|
34
|
+
}
|
|
35
|
+
async function resolveRepoPath(opts) {
|
|
36
|
+
if (opts.repo !== undefined) {
|
|
37
|
+
const registryOpts = opts.home !== undefined ? { home: opts.home } : {};
|
|
38
|
+
const registry = await readRegistry(registryOpts);
|
|
39
|
+
const hit = registry[opts.repo];
|
|
40
|
+
if (hit)
|
|
41
|
+
return resolve(hit.path);
|
|
42
|
+
// Accept a raw path too.
|
|
43
|
+
return resolve(opts.repo);
|
|
44
|
+
}
|
|
45
|
+
return resolve(process.cwd());
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=open-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-store.js","sourceRoot":"","sources":["../../src/commands/open-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,C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AAC;QAClC,yBAAyB;QACzB,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `codehub pack [path]` — produce a single-file repo snapshot suitable
|
|
3
|
+
* for dropping into an LLM context window, via the `repomix` CLI.
|
|
4
|
+
*
|
|
5
|
+
* Repomix is invoked with `--style xml --compress` by default so the
|
|
6
|
+
* output is Anthropic-friendly and tree-sitter-signature-compressed. The
|
|
7
|
+
* command is an OUTPUT-side convenience; OpenCodeHub does NOT use
|
|
8
|
+
* repomix for indexing or embedding (see ADR 0004).
|
|
9
|
+
*
|
|
10
|
+
* This is a thin wrapper — we shell to `npx repomix@<pin>` so operators
|
|
11
|
+
* can override by running repomix directly. The wrapper exists to make
|
|
12
|
+
* the output path discoverable and to put the produced file under
|
|
13
|
+
* `.codehub/pack/` so it's ignored by the standard gitignore pattern.
|
|
14
|
+
*/
|
|
15
|
+
export interface PackOptions {
|
|
16
|
+
/** Output style: xml (default, Anthropic-friendly), markdown, json, or plain. */
|
|
17
|
+
readonly style?: "xml" | "markdown" | "json" | "plain";
|
|
18
|
+
/** When true (default) apply `--compress` for tree-sitter signature compression. */
|
|
19
|
+
readonly compress?: boolean;
|
|
20
|
+
/** When true, strip comments in the packed output. */
|
|
21
|
+
readonly removeComments?: boolean;
|
|
22
|
+
/** Custom output file path. Defaults to `<repo>/.codehub/pack/repo.<ext>`. */
|
|
23
|
+
readonly outputPath?: string;
|
|
24
|
+
/** Pin for `npx repomix@<pin>`. Defaults to the latest verified-compatible version. */
|
|
25
|
+
readonly repomixVersion?: string;
|
|
26
|
+
/** Timeout in ms. Defaults to 5 minutes. */
|
|
27
|
+
readonly timeoutMs?: number;
|
|
28
|
+
}
|
|
29
|
+
export interface PackResult {
|
|
30
|
+
readonly outputPath: string;
|
|
31
|
+
readonly bytes: number;
|
|
32
|
+
readonly durationMs: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function runPack(path: string, opts?: PackOptions): Promise<PackResult>;
|
|
35
|
+
//# sourceMappingURL=pack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../../src/commands/pack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAOH,MAAM,WAAW,WAAW;IAC1B,iFAAiF;IACjF,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;IACvD,oFAAoF;IACpF,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,sDAAsD;IACtD,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;IAClC,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,4CAA4C;IAC5C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAID,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,WAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CA+CvF"}
|