@getchomp/cli 0.0.0-stage → 0.2.43

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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -2
  3. package/dist/commands/analyze.d.ts +49 -0
  4. package/dist/commands/analyze.js +280 -0
  5. package/dist/commands/connect.d.ts +12 -0
  6. package/dist/commands/connect.js +255 -0
  7. package/dist/commands/export.d.ts +29 -0
  8. package/dist/commands/export.js +356 -0
  9. package/dist/commands/health.d.ts +19 -0
  10. package/dist/commands/health.js +259 -0
  11. package/dist/commands/init.d.ts +40 -0
  12. package/dist/commands/init.js +659 -0
  13. package/dist/commands/mcp.d.ts +2 -0
  14. package/dist/commands/mcp.js +12 -0
  15. package/dist/commands/plugin.d.ts +8 -0
  16. package/dist/commands/plugin.js +198 -0
  17. package/dist/commands/ui.d.ts +20 -0
  18. package/dist/commands/ui.js +252 -0
  19. package/dist/commands/uninstall.d.ts +8 -0
  20. package/dist/commands/uninstall.js +246 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.js +37 -0
  23. package/dist/ports/portHydrator.d.ts +63 -0
  24. package/dist/ports/portHydrator.js +954 -0
  25. package/dist/ports/portHydratorWorker.d.ts +22 -0
  26. package/dist/ports/portHydratorWorker.js +75 -0
  27. package/dist/server/buildStatusTracker.d.ts +45 -0
  28. package/dist/server/buildStatusTracker.js +122 -0
  29. package/dist/server/graphLayoutState.d.ts +205 -0
  30. package/dist/server/graphLayoutState.js +930 -0
  31. package/dist/server/loopbackSecurity.d.ts +18 -0
  32. package/dist/server/loopbackSecurity.js +57 -0
  33. package/dist/server/routes/authSourceRoutes.d.ts +18 -0
  34. package/dist/server/routes/authSourceRoutes.js +231 -0
  35. package/dist/server/routes/layoutRoutes.d.ts +3 -0
  36. package/dist/server/routes/layoutRoutes.js +857 -0
  37. package/dist/server/routes/pluginRoutes.d.ts +3 -0
  38. package/dist/server/routes/pluginRoutes.js +368 -0
  39. package/dist/server/routes/viewRulesRoutes.d.ts +3 -0
  40. package/dist/server/routes/viewRulesRoutes.js +173 -0
  41. package/dist/server/uiHotkeys.d.ts +26 -0
  42. package/dist/server/uiHotkeys.js +160 -0
  43. package/dist/utils/branding.d.ts +126 -0
  44. package/dist/utils/branding.js +978 -0
  45. package/dist/utils/credentials.d.ts +22 -0
  46. package/dist/utils/credentials.js +126 -0
  47. package/dist/utils/git.d.ts +95 -0
  48. package/dist/utils/git.js +780 -0
  49. package/dist/utils/masterContext.d.ts +112 -0
  50. package/dist/utils/masterContext.js +642 -0
  51. package/dist/visualizer/cloudLayoutClient.d.ts +84 -0
  52. package/dist/visualizer/cloudLayoutClient.js +1200 -0
  53. package/dist/visualizer/layoutCache.d.ts +25 -0
  54. package/dist/visualizer/layoutCache.js +406 -0
  55. package/dist/visualizer/localEngineBridge.d.ts +50 -0
  56. package/dist/visualizer/localEngineBridge.js +80 -0
  57. package/dist/visualizer/pluginPresentationApi.d.ts +111 -0
  58. package/dist/visualizer/pluginPresentationApi.js +432 -0
  59. package/dist/visualizer/rulesConfig.d.ts +11 -0
  60. package/dist/visualizer/rulesConfig.js +266 -0
  61. package/dist/visualizer/sourceAccess.d.ts +45 -0
  62. package/dist/visualizer/sourceAccess.js +204 -0
  63. package/package.json +52 -3
@@ -0,0 +1,246 @@
1
+ import { existsSync, readdirSync, readFileSync, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync, } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { ansi } from "../utils/branding.js";
4
+ import { clearRemovedChompTarget, } from "../utils/masterContext.js";
5
+ const HOOK_FILES = [
6
+ ".husky/post-commit",
7
+ ".husky/post-merge",
8
+ ".husky/post-checkout",
9
+ ".husky/pre-commit",
10
+ ".git/hooks/post-commit",
11
+ ".git/hooks/post-merge",
12
+ ".git/hooks/post-checkout",
13
+ ".git/hooks/pre-commit",
14
+ ];
15
+ const RULE_FILES = [
16
+ ".cursorrules",
17
+ ".windsurfrules",
18
+ "AGENTS.md",
19
+ "CLAUDE.md",
20
+ ".kiro/steering/chomp-architecture.md",
21
+ ];
22
+ const MCP_FILES = [
23
+ ".cursor/mcp.json",
24
+ ".mcp.json",
25
+ ".agents/mcp_config.json",
26
+ ".kiro/settings/mcp.json",
27
+ ];
28
+ function isDefaultKiroSteeringRemainder(text) {
29
+ const withoutFrontmatter = text
30
+ .replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "")
31
+ .replace(/^#\s+Chomp Architecture & Structural Navigation\s*$/m, "")
32
+ .trim();
33
+ return withoutFrontmatter.length === 0;
34
+ }
35
+ function pruneEmptyDir(dirPath) {
36
+ if (!existsSync(dirPath))
37
+ return false;
38
+ try {
39
+ if (!statSync(dirPath).isDirectory())
40
+ return false;
41
+ const entries = readdirSync(dirPath);
42
+ if (entries.length === 0) {
43
+ rmdirSync(dirPath);
44
+ return true;
45
+ }
46
+ }
47
+ catch {
48
+ // Ignore filesystem errors
49
+ }
50
+ return false;
51
+ }
52
+ function resolveGitExcludePaths(repoRoot) {
53
+ const dotGit = resolve(repoRoot, ".git");
54
+ if (!existsSync(dotGit))
55
+ return [];
56
+ const candidates = new Set();
57
+ try {
58
+ const stat = statSync(dotGit);
59
+ if (stat.isDirectory()) {
60
+ candidates.add(resolve(dotGit, "info", "exclude"));
61
+ }
62
+ else {
63
+ const pointer = readFileSync(dotGit, "utf8").trim();
64
+ const match = /^gitdir:\s*(.+)$/i.exec(pointer);
65
+ if (match) {
66
+ const gitDir = resolve(repoRoot, match[1].trim());
67
+ candidates.add(resolve(gitDir, "info", "exclude"));
68
+ const commondirFile = resolve(gitDir, "commondir");
69
+ if (existsSync(commondirFile)) {
70
+ const commonRel = readFileSync(commondirFile, "utf8").trim();
71
+ if (commonRel) {
72
+ candidates.add(resolve(gitDir, commonRel, "info", "exclude"));
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+ catch {
79
+ // Ignore
80
+ }
81
+ return [...candidates];
82
+ }
83
+ export function runUninstall(inputPath, options) {
84
+ const quiet = Boolean(options?.quiet);
85
+ const log = (msg) => {
86
+ if (!quiet)
87
+ console.log(msg);
88
+ };
89
+ const removed = [];
90
+ const updated = [];
91
+ const baseDir = process.env.INIT_CWD ?? process.cwd();
92
+ const cwd = resolve(baseDir, inputPath ?? ".");
93
+ const chompDir = resolve(cwd, ".chomp");
94
+ if (existsSync(chompDir)) {
95
+ rmSync(chompDir, { recursive: true, force: true });
96
+ removed.push(".chomp/");
97
+ log(` ${ansi.green("✓")} Removed ${ansi.cyan(".chomp/")}`);
98
+ }
99
+ // 1. Strip Chomp Harness blocks from rule & steering files
100
+ const harnessRegex = /# --- BEGIN CHOMP HARNESS ---\r?\n[\s\S]*?# --- END CHOMP HARNESS ---\r?\n?/g;
101
+ for (const file of RULE_FILES) {
102
+ const filePath = resolve(cwd, file);
103
+ if (existsSync(filePath)) {
104
+ const content = readFileSync(filePath, "utf8");
105
+ if (content.includes("# --- BEGIN CHOMP HARNESS ---")) {
106
+ const newContent = content.replace(harnessRegex, "").trim();
107
+ const isEmptySteering = file === ".kiro/steering/chomp-architecture.md" &&
108
+ isDefaultKiroSteeringRemainder(newContent);
109
+ if (newContent === "" || isEmptySteering) {
110
+ unlinkSync(filePath);
111
+ removed.push(file);
112
+ log(` ${ansi.green("✓")} Removed ${ansi.cyan(file)}`);
113
+ }
114
+ else {
115
+ writeFileSync(filePath, newContent + "\n", "utf8");
116
+ updated.push(file);
117
+ log(` ${ansi.green("✓")} Stripped Chomp Harness from ${ansi.cyan(file)}`);
118
+ }
119
+ }
120
+ }
121
+ }
122
+ // 2. Remove Kiro hook & Power bundle if present
123
+ const kiroHookRel = ".kiro/hooks/chomp-sync.kiro.hook";
124
+ const kiroHookPath = resolve(cwd, kiroHookRel);
125
+ if (existsSync(kiroHookPath)) {
126
+ unlinkSync(kiroHookPath);
127
+ removed.push(kiroHookRel);
128
+ log(` ${ansi.green("✓")} Removed ${ansi.cyan(kiroHookRel)}`);
129
+ }
130
+ const kiroPowerRel = ".kiro/powers/chomp";
131
+ const kiroPowerPath = resolve(cwd, kiroPowerRel);
132
+ if (existsSync(kiroPowerPath)) {
133
+ rmSync(kiroPowerPath, { recursive: true, force: true });
134
+ removed.push(kiroPowerRel);
135
+ log(` ${ansi.green("✓")} Removed ${ansi.cyan(kiroPowerRel)}`);
136
+ }
137
+ // 3. Strip Chomp Hook blocks from .husky/ and .git/hooks/
138
+ const hookRegex = /# --- BEGIN CHOMP HOOK ---\r?\n[\s\S]*?# --- END CHOMP HOOK ---\r?\n?/g;
139
+ for (const relHook of HOOK_FILES) {
140
+ const hookPath = resolve(cwd, relHook);
141
+ if (existsSync(hookPath)) {
142
+ const content = readFileSync(hookPath, "utf8");
143
+ if (content.includes("# --- BEGIN CHOMP HOOK ---")) {
144
+ const newContent = content.replace(hookRegex, "").trim();
145
+ if (newContent === "" ||
146
+ newContent === "#!/bin/sh" ||
147
+ newContent === "#!/usr/bin/env sh") {
148
+ unlinkSync(hookPath);
149
+ removed.push(relHook);
150
+ log(` ${ansi.green("✓")} Removed Chomp hook ${ansi.cyan(relHook)}`);
151
+ }
152
+ else {
153
+ writeFileSync(hookPath, newContent + "\n", "utf8");
154
+ updated.push(relHook);
155
+ log(` ${ansi.green("✓")} Stripped Chomp hook block from ${ansi.cyan(relHook)}`);
156
+ }
157
+ }
158
+ }
159
+ }
160
+ // 4. Remove chomp-server from workspace MCP config files (.cursor/mcp.json, .mcp.json, .kiro/settings/mcp.json)
161
+ for (const relMcp of MCP_FILES) {
162
+ const mcpPath = resolve(cwd, relMcp);
163
+ if (existsSync(mcpPath)) {
164
+ try {
165
+ const parsed = JSON.parse(readFileSync(mcpPath, "utf8"));
166
+ if (parsed?.mcpServers?.["chomp-server"]) {
167
+ delete parsed.mcpServers["chomp-server"];
168
+ const remainingKeys = Object.keys(parsed.mcpServers);
169
+ if (remainingKeys.length === 0 && Object.keys(parsed).length === 1) {
170
+ unlinkSync(mcpPath);
171
+ removed.push(relMcp);
172
+ log(` ${ansi.green("✓")} Removed empty ${ansi.cyan(relMcp)}`);
173
+ }
174
+ else {
175
+ writeFileSync(mcpPath, JSON.stringify(parsed, null, 2) + "\n", "utf8");
176
+ updated.push(relMcp);
177
+ log(` ${ansi.green("✓")} Removed chomp-server from ${ansi.cyan(relMcp)}`);
178
+ }
179
+ }
180
+ }
181
+ catch {
182
+ // ignore malformed JSON
183
+ }
184
+ }
185
+ }
186
+ // Prune empty IDE directories (.kiro/*, .kiro, .cursor)
187
+ for (const relDir of [
188
+ ".kiro/settings",
189
+ ".kiro/steering",
190
+ ".kiro/hooks",
191
+ ".kiro/powers",
192
+ ".kiro",
193
+ ".cursor",
194
+ ".agents",
195
+ ]) {
196
+ pruneEmptyDir(resolve(cwd, relDir));
197
+ }
198
+ // 5. Clean up Chomp block in .gitignore and .git/info/exclude
199
+ const ignoreRegex = /\n?# --- BEGIN CHOMP IGNORE ---\r?\n[\s\S]*?# --- END CHOMP IGNORE ---\r?\n?/g;
200
+ const gitignorePath = resolve(cwd, ".gitignore");
201
+ if (existsSync(gitignorePath)) {
202
+ const gitignoreContent = readFileSync(gitignorePath, "utf8");
203
+ if (gitignoreContent.includes("# --- BEGIN CHOMP IGNORE ---")) {
204
+ const cleaned = gitignoreContent.replace(ignoreRegex, "\n").trimEnd();
205
+ if (cleaned.trim().length === 0) {
206
+ unlinkSync(gitignorePath);
207
+ removed.push(".gitignore");
208
+ log(` ${ansi.green("✓")} Removed empty ${ansi.cyan(".gitignore")}`);
209
+ }
210
+ else {
211
+ writeFileSync(gitignorePath, cleaned + "\n", "utf8");
212
+ updated.push(".gitignore");
213
+ log(` ${ansi.green("✓")} Cleaned up ${ansi.cyan(".gitignore")}`);
214
+ }
215
+ }
216
+ }
217
+ for (const gitExcludePath of resolveGitExcludePaths(cwd)) {
218
+ if (existsSync(gitExcludePath)) {
219
+ const excludeContent = readFileSync(gitExcludePath, "utf8");
220
+ if (excludeContent.includes("# --- BEGIN CHOMP IGNORE ---")) {
221
+ const cleaned = excludeContent.replace(ignoreRegex, "\n").trimEnd();
222
+ writeFileSync(gitExcludePath, cleaned ? cleaned + "\n" : "", "utf8");
223
+ updated.push(".git/info/exclude");
224
+ log(` ${ansi.green("✓")} Cleaned up ${ansi.cyan(".git/info/exclude")}`);
225
+ }
226
+ }
227
+ }
228
+ // 6. Update or clear active repo tether cleanly (never writing _npx/.../node_modules)
229
+ const tetherUpdate = clearRemovedChompTarget(cwd);
230
+ if (tetherUpdate.switchedTo) {
231
+ log(` ${ansi.green("✓")} Switched active repo back to ${ansi.cyan(tetherUpdate.switchedTo)}`);
232
+ }
233
+ else if (tetherUpdate.cleared) {
234
+ log(` ${ansi.green("✓")} Cleared active repo from global Chomp context`);
235
+ }
236
+ log(`\n ${ansi.yellowBold("◆")} ${ansi.bold("Chomp has been cleanly removed. We left no trace.")}\n`);
237
+ return { removed, updated };
238
+ }
239
+ export function registerUninstallCommand(program) {
240
+ program
241
+ .command("uninstall [path]")
242
+ .description("Cleanly remove Chomp (.chomp/, agent harnesses, MCP entries, and git hooks) from the workspace.")
243
+ .action((inputPath) => {
244
+ runUninstall(inputPath);
245
+ });
246
+ }
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { type LayoutData, type WorkingNode, type SystemHealthSummary, type PackageHealthStats } from "@getchomp/core";
3
+ export type { LayoutData, WorkingNode, SystemHealthSummary, PackageHealthStats, };
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ // packages/cli/src/index.ts
3
+ // Chomp CLI entry point.
4
+ // Load .env from the package root, anchored to this file's location so it
5
+ // works whether invoked via `pnpm --filter @getchomp/cli dev` from the repo root
6
+ // or directly from inside packages/cli/.
7
+ import { config as dotenvConfig } from 'dotenv';
8
+ import { fileURLToPath } from 'node:url';
9
+ import { dirname, resolve } from 'node:path';
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
11
+ dotenvConfig({ path: resolve(__dirname, '../.env') }); // packages/cli/.env
12
+ import { Command } from "commander";
13
+ import { registerAnalyzeCommand } from "./commands/analyze.js";
14
+ import { registerHealthCommand } from "./commands/health.js";
15
+ import { registerMcpCommand } from "./commands/mcp.js";
16
+ import { registerUiCommand } from "./commands/ui.js";
17
+ import { registerExportCommand } from "./commands/export.js";
18
+ import { registerInitCommand } from "./commands/init.js";
19
+ import { registerConnectCommand } from "./commands/connect.js";
20
+ import { registerUninstallCommand } from "./commands/uninstall.js";
21
+ import { registerPluginCommand } from "./commands/plugin.js";
22
+ import { CORE_EXTRACTOR_VERSION, } from "@getchomp/core";
23
+ const program = new Command();
24
+ program
25
+ .name("chomp")
26
+ .description("Chomp CLI — The live map of your codebase")
27
+ .version(CORE_EXTRACTOR_VERSION);
28
+ registerAnalyzeCommand(program);
29
+ registerHealthCommand(program);
30
+ registerMcpCommand(program);
31
+ registerUiCommand(program);
32
+ registerExportCommand(program);
33
+ registerInitCommand(program);
34
+ registerConnectCommand(program);
35
+ registerUninstallCommand(program);
36
+ registerPluginCommand(program);
37
+ program.parse(process.argv);
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @fileoverview Speed 2 Incremental Port Valve Hydrator (`[PAT-VIS-14]`, `[PAT-DB-03]`, `[PAT-DB-05]`).
3
+ *
4
+ * Uses TypeScript's `ts.createIncrementalProgram` (persisting `.tsbuildinfo` inside `.chomp/cache/`)
5
+ * to resolve inferred return types, cross-file interface/type fields, and boundary port diagnostics
6
+ * (`TS_CALL_MISMATCH`, `TS_RETURN_MISMATCH`) into `entity_overlays` (`layer: "L1_PORTS"`,
7
+ * `source: "chomp-ports"`, `derivation: "EXTRACTED"`).
8
+ *
9
+ * Unchanged contracts (`stale === false` on both `bodyHash` and referenced `inputs` file hashes)
10
+ * are skipped in `<2ms` without constructing a TypeScript `Program`.
11
+ */
12
+ import type { RepresentationGraph } from '@getchomp/core';
13
+ import type { ChompStorage } from '@getchomp/db';
14
+ export declare const CHOMP_PORTS_LAYER = "L1_PORTS";
15
+ export declare const CHOMP_PORTS_SOURCE = "chomp-ports";
16
+ export interface HydratePortValvesOptions {
17
+ repoPath: string;
18
+ repoId: string;
19
+ storage: ChompStorage;
20
+ graph: RepresentationGraph;
21
+ /** Re-verify all contracts even when existing `L1_PORTS` cache rows are non-stale. */
22
+ force?: boolean;
23
+ /** Optional custom `.tsbuildinfo` directory, or `false` to disable writing `.tsbuildinfo` (e.g. in unit tests). */
24
+ cacheDir?: string | false;
25
+ }
26
+ export interface HydratePortValvesResult {
27
+ hydratedCount: number;
28
+ cachedCount: number;
29
+ prunedCount: number;
30
+ diagnosticCount: number;
31
+ durationMs: number;
32
+ }
33
+ /**
34
+ * Runs Speed 2 incremental TypeScript Port Valve verification on `graph` and persists
35
+ * `L1_PORTS` (`source: "chomp-ports"`) cache rows to `storage`.
36
+ *
37
+ * @param options Repository path, ID, storage adapter, and extracted Layer 0 `RepresentationGraph`.
38
+ * @returns Counts of hydrated, cached, and pruned `L1_PORTS` overlays plus boundary diagnostic totals.
39
+ */
40
+ export declare function hydrateRepositoryPortValves(options: HydratePortValvesOptions): Promise<HydratePortValvesResult>;
41
+ export interface RunPortHydrationInChildProcessOptions {
42
+ dbPath: string;
43
+ repoPath?: string;
44
+ force?: boolean;
45
+ cacheDir?: string | false;
46
+ timeoutMs?: number;
47
+ }
48
+ export interface PortHydrationChildHandle {
49
+ promise: Promise<HydratePortValvesResult | null>;
50
+ cancel: () => void;
51
+ }
52
+ /**
53
+ * Filters `process.execArgv` down to safe loader/runtime flags (`--require`, `--import`,
54
+ * `--loader`, `--conditions`, `--max-old-space-size`, etc.) so forked child workers inherit
55
+ * `tsx` loaders in dev mode without inheriting `--test`, `--eval`, or `--inspect` flags.
56
+ */
57
+ export declare function filterExecArgvForChild(execArgv?: readonly string[]): string[];
58
+ /**
59
+ * Runs Speed 2 Port Valve hydration inside an isolated forked child process so heavy
60
+ * TypeScript `Program` creation and semantic diagnostics never block the `chomp ui`
61
+ * main event loop, HTTP polling, or raw-mode terminal input (`[q]` / `Ctrl+C`).
62
+ */
63
+ export declare function runPortHydrationInChildProcess(options: RunPortHydrationInChildProcessOptions): PortHydrationChildHandle;