@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.
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/dist/commands/analyze.d.ts +49 -0
- package/dist/commands/analyze.js +280 -0
- package/dist/commands/connect.d.ts +12 -0
- package/dist/commands/connect.js +255 -0
- package/dist/commands/export.d.ts +29 -0
- package/dist/commands/export.js +356 -0
- package/dist/commands/health.d.ts +19 -0
- package/dist/commands/health.js +259 -0
- package/dist/commands/init.d.ts +40 -0
- package/dist/commands/init.js +659 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.js +12 -0
- package/dist/commands/plugin.d.ts +8 -0
- package/dist/commands/plugin.js +198 -0
- package/dist/commands/ui.d.ts +20 -0
- package/dist/commands/ui.js +252 -0
- package/dist/commands/uninstall.d.ts +8 -0
- package/dist/commands/uninstall.js +246 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +37 -0
- package/dist/ports/portHydrator.d.ts +63 -0
- package/dist/ports/portHydrator.js +954 -0
- package/dist/ports/portHydratorWorker.d.ts +22 -0
- package/dist/ports/portHydratorWorker.js +75 -0
- package/dist/server/buildStatusTracker.d.ts +45 -0
- package/dist/server/buildStatusTracker.js +122 -0
- package/dist/server/graphLayoutState.d.ts +205 -0
- package/dist/server/graphLayoutState.js +930 -0
- package/dist/server/loopbackSecurity.d.ts +18 -0
- package/dist/server/loopbackSecurity.js +57 -0
- package/dist/server/routes/authSourceRoutes.d.ts +18 -0
- package/dist/server/routes/authSourceRoutes.js +231 -0
- package/dist/server/routes/layoutRoutes.d.ts +3 -0
- package/dist/server/routes/layoutRoutes.js +857 -0
- package/dist/server/routes/pluginRoutes.d.ts +3 -0
- package/dist/server/routes/pluginRoutes.js +368 -0
- package/dist/server/routes/viewRulesRoutes.d.ts +3 -0
- package/dist/server/routes/viewRulesRoutes.js +173 -0
- package/dist/server/uiHotkeys.d.ts +26 -0
- package/dist/server/uiHotkeys.js +160 -0
- package/dist/utils/branding.d.ts +126 -0
- package/dist/utils/branding.js +978 -0
- package/dist/utils/credentials.d.ts +22 -0
- package/dist/utils/credentials.js +126 -0
- package/dist/utils/git.d.ts +95 -0
- package/dist/utils/git.js +780 -0
- package/dist/utils/masterContext.d.ts +112 -0
- package/dist/utils/masterContext.js +642 -0
- package/dist/visualizer/cloudLayoutClient.d.ts +84 -0
- package/dist/visualizer/cloudLayoutClient.js +1200 -0
- package/dist/visualizer/layoutCache.d.ts +25 -0
- package/dist/visualizer/layoutCache.js +406 -0
- package/dist/visualizer/localEngineBridge.d.ts +50 -0
- package/dist/visualizer/localEngineBridge.js +80 -0
- package/dist/visualizer/pluginPresentationApi.d.ts +111 -0
- package/dist/visualizer/pluginPresentationApi.js +432 -0
- package/dist/visualizer/rulesConfig.d.ts +11 -0
- package/dist/visualizer/rulesConfig.js +266 -0
- package/dist/visualizer/sourceAccess.d.ts +45 -0
- package/dist/visualizer/sourceAccess.js +204 -0
- package/package.json +52 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/cli/src/utils/credentials.ts
|
|
3
|
+
*
|
|
4
|
+
* Local Chomp credential persistence (`~/.chomp/credentials.json` with `0600` permissions)
|
|
5
|
+
* for GitHub 14-day Trial JWTs (`chomp_tok_...`) and Pro / Team SLA License Keys (`chomp_live_...`).
|
|
6
|
+
*/
|
|
7
|
+
export interface ChompLocalCredentials {
|
|
8
|
+
token?: string;
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
githubHandle?: string;
|
|
11
|
+
updatedAt?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function getChompCredentialsPath(): string;
|
|
14
|
+
export declare function decodeJwtPayloadUnsafe(token: string): Record<string, any> | null;
|
|
15
|
+
export declare function loadChompCredentials(): ChompLocalCredentials | null;
|
|
16
|
+
export declare function saveChompCredentials(patch: Partial<ChompLocalCredentials>): ChompLocalCredentials;
|
|
17
|
+
export declare function clearChompCredentials(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the active Bearer credential in precedence order:
|
|
20
|
+
* explicit option -> env `CHOMP_API_KEY` -> saved `apiKey` (`chomp_live_...`) -> saved `token` (`chomp_tok_...`).
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveActiveBearerToken(explicitApiKey?: string): string | undefined;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/cli/src/utils/credentials.ts
|
|
3
|
+
*
|
|
4
|
+
* Local Chomp credential persistence (`~/.chomp/credentials.json` with `0600` permissions)
|
|
5
|
+
* for GitHub 14-day Trial JWTs (`chomp_tok_...`) and Pro / Team SLA License Keys (`chomp_live_...`).
|
|
6
|
+
*/
|
|
7
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { dirname, resolve } from "node:path";
|
|
10
|
+
export function getChompCredentialsPath() {
|
|
11
|
+
const override = process.env.CHOMP_CREDENTIALS_PATH?.trim();
|
|
12
|
+
if (override) {
|
|
13
|
+
return resolve(override);
|
|
14
|
+
}
|
|
15
|
+
return resolve(homedir(), ".chomp", "credentials.json");
|
|
16
|
+
}
|
|
17
|
+
export function decodeJwtPayloadUnsafe(token) {
|
|
18
|
+
try {
|
|
19
|
+
const stripped = token.startsWith("chomp_tok_")
|
|
20
|
+
? token.slice("chomp_tok_".length)
|
|
21
|
+
: token;
|
|
22
|
+
const parts = stripped.split(".");
|
|
23
|
+
if (parts.length !== 3)
|
|
24
|
+
return null;
|
|
25
|
+
const json = Buffer.from(parts[1], "base64url").toString("utf8");
|
|
26
|
+
const parsed = JSON.parse(json);
|
|
27
|
+
return parsed && typeof parsed === "object" ? parsed : null;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function loadChompCredentials() {
|
|
34
|
+
const credPath = getChompCredentialsPath();
|
|
35
|
+
if (!existsSync(credPath))
|
|
36
|
+
return null;
|
|
37
|
+
try {
|
|
38
|
+
const raw = JSON.parse(readFileSync(credPath, "utf8"));
|
|
39
|
+
if (!raw || typeof raw !== "object")
|
|
40
|
+
return null;
|
|
41
|
+
const result = {};
|
|
42
|
+
if (typeof raw.token === "string" && raw.token.trim()) {
|
|
43
|
+
result.token = raw.token.trim();
|
|
44
|
+
}
|
|
45
|
+
if (typeof raw.apiKey === "string" && raw.apiKey.trim()) {
|
|
46
|
+
result.apiKey = raw.apiKey.trim();
|
|
47
|
+
}
|
|
48
|
+
if (typeof raw.githubHandle === "string" && raw.githubHandle.trim()) {
|
|
49
|
+
result.githubHandle = raw.githubHandle.trim();
|
|
50
|
+
}
|
|
51
|
+
else if (result.token) {
|
|
52
|
+
const payload = decodeJwtPayloadUnsafe(result.token);
|
|
53
|
+
if (typeof payload?.handle === "string" && payload.handle.trim()) {
|
|
54
|
+
result.githubHandle = payload.handle.trim();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (typeof raw.updatedAt === "string" && raw.updatedAt.trim()) {
|
|
58
|
+
result.updatedAt = raw.updatedAt.trim();
|
|
59
|
+
}
|
|
60
|
+
if (!result.token && !result.apiKey)
|
|
61
|
+
return null;
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export function saveChompCredentials(patch) {
|
|
69
|
+
const credPath = getChompCredentialsPath();
|
|
70
|
+
const dir = dirname(credPath);
|
|
71
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
72
|
+
const prev = loadChompCredentials() ?? {};
|
|
73
|
+
const next = {
|
|
74
|
+
...prev,
|
|
75
|
+
...patch,
|
|
76
|
+
updatedAt: new Date().toISOString(),
|
|
77
|
+
};
|
|
78
|
+
if (next.token && !next.githubHandle) {
|
|
79
|
+
const payload = decodeJwtPayloadUnsafe(next.token);
|
|
80
|
+
if (typeof payload?.handle === "string" && payload.handle.trim()) {
|
|
81
|
+
next.githubHandle = payload.handle.trim();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!next.token)
|
|
85
|
+
delete next.token;
|
|
86
|
+
if (!next.apiKey)
|
|
87
|
+
delete next.apiKey;
|
|
88
|
+
if (!next.githubHandle)
|
|
89
|
+
delete next.githubHandle;
|
|
90
|
+
writeFileSync(credPath, JSON.stringify(next, null, 2) + "\n", {
|
|
91
|
+
encoding: "utf8",
|
|
92
|
+
mode: 0o600,
|
|
93
|
+
});
|
|
94
|
+
try {
|
|
95
|
+
chmodSync(credPath, 0o600);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// Non-fatal on platforms without POSIX chmod
|
|
99
|
+
}
|
|
100
|
+
return next;
|
|
101
|
+
}
|
|
102
|
+
export function clearChompCredentials() {
|
|
103
|
+
const credPath = getChompCredentialsPath();
|
|
104
|
+
if (existsSync(credPath)) {
|
|
105
|
+
try {
|
|
106
|
+
unlinkSync(credPath);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// ignore
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Resolves the active Bearer credential in precedence order:
|
|
115
|
+
* explicit option -> env `CHOMP_API_KEY` -> saved `apiKey` (`chomp_live_...`) -> saved `token` (`chomp_tok_...`).
|
|
116
|
+
*/
|
|
117
|
+
export function resolveActiveBearerToken(explicitApiKey) {
|
|
118
|
+
if (explicitApiKey && explicitApiKey.trim()) {
|
|
119
|
+
return explicitApiKey.trim();
|
|
120
|
+
}
|
|
121
|
+
if (process.env.CHOMP_API_KEY && process.env.CHOMP_API_KEY.trim()) {
|
|
122
|
+
return process.env.CHOMP_API_KEY.trim();
|
|
123
|
+
}
|
|
124
|
+
const creds = loadChompCredentials();
|
|
125
|
+
return creds?.apiKey || creds?.token || undefined;
|
|
126
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export interface GitRepoIdentity {
|
|
2
|
+
repoRoot: string;
|
|
3
|
+
gitDir: string;
|
|
4
|
+
commonDir: string;
|
|
5
|
+
primaryRepoRoot: string;
|
|
6
|
+
isLinkedWorktree: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface GitInfo {
|
|
9
|
+
commitSha?: string;
|
|
10
|
+
branchName?: string;
|
|
11
|
+
commitMessage?: string;
|
|
12
|
+
remoteUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface GitBranchOption {
|
|
15
|
+
name: string;
|
|
16
|
+
commitSha: string;
|
|
17
|
+
fullCommitSha: string;
|
|
18
|
+
subject?: string;
|
|
19
|
+
committedAt?: string;
|
|
20
|
+
isCurrent: boolean;
|
|
21
|
+
isDefaultBase: boolean;
|
|
22
|
+
worktreePath?: string;
|
|
23
|
+
hasCachedGraphDb?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface GitDiffTargetsResponse {
|
|
26
|
+
currentBranch: string;
|
|
27
|
+
currentCommitSha: string;
|
|
28
|
+
defaultBaseBranch: string;
|
|
29
|
+
workingTreeDirty: boolean;
|
|
30
|
+
dirtyFileCount: number;
|
|
31
|
+
branches: GitBranchOption[];
|
|
32
|
+
}
|
|
33
|
+
export interface ResolvedGitRefCommit {
|
|
34
|
+
ref: string;
|
|
35
|
+
commitSha: string;
|
|
36
|
+
fullCommitSha: string;
|
|
37
|
+
branchName?: string;
|
|
38
|
+
commitMessage?: string;
|
|
39
|
+
}
|
|
40
|
+
export declare function cleanGitEnv(): NodeJS.ProcessEnv;
|
|
41
|
+
/**
|
|
42
|
+
* Resolves Git repository / worktree identity using pure filesystem reads (zero subprocesses).
|
|
43
|
+
* Distinguishes primary checkouts from linked Git worktrees (`git worktree add`) and maps
|
|
44
|
+
* linked worktrees back to their shared `commonDir` and `primaryRepoRoot`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getGitRepoIdentity(inputPath: string): GitRepoIdentity | null;
|
|
47
|
+
/**
|
|
48
|
+
* Returns `true` when `inputPath` resides inside a linked Git worktree (created via
|
|
49
|
+
* `git worktree add`) rather than the repository's primary checkout.
|
|
50
|
+
*/
|
|
51
|
+
export declare function isLinkedGitWorktree(inputPath: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Returns `true` when `pathA` and `pathB` belong to the same underlying Git repository
|
|
54
|
+
* (e.g., `main` and a linked Git worktree sharing the same `.git` common directory).
|
|
55
|
+
*/
|
|
56
|
+
export declare function sharesGitRepository(pathA: string, pathB: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Resolves the canonical repository name for `inputPath` (`[PAT-VIS-24]`, `[PAT-CLI-13]`).
|
|
59
|
+
*
|
|
60
|
+
* When running inside a Git worktree (where `.git` is a pointer file containing
|
|
61
|
+
* `gitdir: /path/to/<repo>/.git/worktrees/<worktree>`), resolves `commondir` back to
|
|
62
|
+
* the parent repository root (`<repo>`) instead of returning the worktree/branch directory name.
|
|
63
|
+
* Preserves standalone non-git fixture directories (`fixtures/cloned-repos/<name>`,
|
|
64
|
+
* `fixtures/test-repos/<name>`, or isolated `.chomp/` target directories).
|
|
65
|
+
*/
|
|
66
|
+
export declare function resolveRepoName(inputPath: string): string;
|
|
67
|
+
export declare function normalizeGitRemoteWebUrl(rawUrl: string | undefined): string | undefined;
|
|
68
|
+
export declare function getGitInfo(cwd: string): {
|
|
69
|
+
commitSha?: string;
|
|
70
|
+
branchName?: string;
|
|
71
|
+
commitMessage?: string;
|
|
72
|
+
remoteUrl?: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Fast, zero-subprocess branch/HEAD reader backed purely by `.git/HEAD` filesystem reads.
|
|
76
|
+
* Safe to invoke on high-frequency polling routes (`/api/view`, `/api/status`) without blocking.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getGitInfoFromFs(cwd: string): GitInfo;
|
|
79
|
+
/**
|
|
80
|
+
* Non-blocking, TTL-cached, single-flight equivalent of `getGitInfo` for HTTP server routes.
|
|
81
|
+
* Uses direct `.git/` filesystem reads first for `branchName`, `commitSha`, and `remoteUrl`,
|
|
82
|
+
* and only spawns async `git log -1` once per commit SHA (or falls back to async `git` when
|
|
83
|
+
* ref resolution isn't available directly on disk).
|
|
84
|
+
*/
|
|
85
|
+
export declare function getGitInfoAsync(cwd: string, options?: {
|
|
86
|
+
ttlMs?: number;
|
|
87
|
+
includeCommitMessage?: boolean;
|
|
88
|
+
}): Promise<GitInfo>;
|
|
89
|
+
/**
|
|
90
|
+
* Non-blocking discovery of local Git branches, linked Git worktrees, cached `.chomp/graph.db`
|
|
91
|
+
* availability, and working-tree dirty state (`GET /api/git/branches`).
|
|
92
|
+
*/
|
|
93
|
+
export declare function listGitBranchesAndWorktrees(repoPath: string): Promise<GitDiffTargetsResponse>;
|
|
94
|
+
export declare function resolveGitRefInfo(repoPath: string, refOrBranch: string, gitTargets?: GitDiffTargetsResponse | null): Promise<ResolvedGitRefCommit | null>;
|
|
95
|
+
export declare function resolveGitRefCommitAsync(repoPath: string, refOrBranch: string): Promise<ResolvedGitRefCommit | null>;
|