@getchomp/cli 0.2.42 → 0.2.44
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/dist/commands/analyze.js +19 -2
- package/dist/commands/init.js +12 -7
- package/dist/commands/ui.d.ts +1 -0
- package/dist/commands/ui.js +47 -4
- package/dist/commands/uninstall.js +27 -13
- package/dist/ports/portHydrator.d.ts +5 -0
- package/dist/ports/portHydrator.js +175 -9
- package/dist/server/graphLayoutState.js +0 -2
- package/dist/server/hostedUiProxy.d.ts +13 -0
- package/dist/server/hostedUiProxy.js +137 -0
- package/dist/server/routes/authSourceRoutes.js +11 -0
- package/dist/server/routes/layoutRoutes.d.ts +5 -0
- package/dist/server/routes/layoutRoutes.js +32 -14
- package/dist/utils/branding.d.ts +56 -13
- package/dist/utils/branding.js +413 -222
- package/dist/utils/masterContext.d.ts +10 -0
- package/dist/utils/masterContext.js +84 -1
- package/dist/visualizer/cloudLayoutClient.d.ts +6 -1
- package/dist/visualizer/cloudLayoutClient.js +15 -1
- package/package.json +7 -6
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const MAX_CACHE_ENTRIES = 160;
|
|
2
|
+
const MUTABLE_TTL_MS = 60_000;
|
|
3
|
+
const PROXY_TIMEOUT_MS = 10_000;
|
|
4
|
+
/**
|
|
5
|
+
* Proxies static Visualizer UI assets (`index.html`, `/_next/static/*`, icons, fonts)
|
|
6
|
+
* from `https://app.getchomp.dev` when running the published `@getchomp/cli` package
|
|
7
|
+
* (where `apps/web/out` is not bundled in the NPM tarball).
|
|
8
|
+
*
|
|
9
|
+
* Why this exists:
|
|
10
|
+
* WebKit / Safari strictly blocks `https://app.getchomp.dev` from calling `fetch()`
|
|
11
|
+
* against `http://127.0.0.1:<port>` as Mixed Content with no user setting to override it.
|
|
12
|
+
* Serving the hosted static UI transparently on `http://localhost:<port>` (`127.0.0.1:<port>`)
|
|
13
|
+
* lets Safari run 100% same-origin over HTTP while adding 0 KB to the `@getchomp/cli` tarball.
|
|
14
|
+
*/
|
|
15
|
+
export function createHostedUiProxyMiddleware(hostedUiBaseUrl, fetchImpl = fetch) {
|
|
16
|
+
let upstreamOrigin;
|
|
17
|
+
try {
|
|
18
|
+
upstreamOrigin = new URL(hostedUiBaseUrl.trim()).origin;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
upstreamOrigin = "https://app.getchomp.dev";
|
|
22
|
+
}
|
|
23
|
+
const assetCache = new Map();
|
|
24
|
+
const setBoundedCache = (key, entry) => {
|
|
25
|
+
if (assetCache.has(key)) {
|
|
26
|
+
assetCache.delete(key);
|
|
27
|
+
}
|
|
28
|
+
else if (assetCache.size >= MAX_CACHE_ENTRIES) {
|
|
29
|
+
const oldestKey = assetCache.keys().next().value;
|
|
30
|
+
if (oldestKey !== undefined) {
|
|
31
|
+
assetCache.delete(oldestKey);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
assetCache.set(key, entry);
|
|
35
|
+
};
|
|
36
|
+
const fetchUpstreamAsset = async (pathname) => {
|
|
37
|
+
const normalizedPath = pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
38
|
+
const immutable = normalizedPath.startsWith("/_next/static/");
|
|
39
|
+
const now = Date.now();
|
|
40
|
+
const cached = assetCache.get(normalizedPath);
|
|
41
|
+
if (cached &&
|
|
42
|
+
(cached.immutable || now - cached.cachedAt < MUTABLE_TTL_MS)) {
|
|
43
|
+
return cached;
|
|
44
|
+
}
|
|
45
|
+
let targetUrl;
|
|
46
|
+
try {
|
|
47
|
+
targetUrl = new URL(normalizedPath, `${upstreamOrigin}/`);
|
|
48
|
+
if (targetUrl.origin !== upstreamOrigin) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
const timer = setTimeout(() => controller.abort(), PROXY_TIMEOUT_MS);
|
|
57
|
+
try {
|
|
58
|
+
const upstreamRes = await fetchImpl(targetUrl.toString(), {
|
|
59
|
+
method: "GET",
|
|
60
|
+
headers: {
|
|
61
|
+
"User-Agent": "chomp-cli-ui-proxy",
|
|
62
|
+
Accept: "*/*",
|
|
63
|
+
},
|
|
64
|
+
signal: controller.signal,
|
|
65
|
+
});
|
|
66
|
+
if (!upstreamRes.ok) {
|
|
67
|
+
if (upstreamRes.status === 404) {
|
|
68
|
+
return {
|
|
69
|
+
status: 404,
|
|
70
|
+
contentType: upstreamRes.headers.get("content-type") ||
|
|
71
|
+
"text/plain; charset=utf-8",
|
|
72
|
+
body: Buffer.from("Not Found", "utf-8"),
|
|
73
|
+
cachedAt: now,
|
|
74
|
+
immutable: false,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return cached ?? null;
|
|
78
|
+
}
|
|
79
|
+
const arrayBuf = await upstreamRes.arrayBuffer();
|
|
80
|
+
const entry = {
|
|
81
|
+
status: upstreamRes.status,
|
|
82
|
+
contentType: upstreamRes.headers.get("content-type") ||
|
|
83
|
+
"application/octet-stream",
|
|
84
|
+
body: Buffer.from(arrayBuf),
|
|
85
|
+
cachedAt: now,
|
|
86
|
+
immutable,
|
|
87
|
+
};
|
|
88
|
+
setBoundedCache(normalizedPath, entry);
|
|
89
|
+
return entry;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// Serve stale cached copy when briefly offline
|
|
93
|
+
return cached ?? null;
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return async (req, res) => {
|
|
100
|
+
const rawPath = req.path || "/";
|
|
101
|
+
if (rawPath === "/api" ||
|
|
102
|
+
rawPath.startsWith("/api/") ||
|
|
103
|
+
(req.method !== "GET" && req.method !== "HEAD")) {
|
|
104
|
+
return res.status(404).json({ error: "Not Found" });
|
|
105
|
+
}
|
|
106
|
+
if (rawPath.includes("..")) {
|
|
107
|
+
return res.status(400).send("Bad Request");
|
|
108
|
+
}
|
|
109
|
+
const normalizedPath = rawPath === "" ? "/" : rawPath;
|
|
110
|
+
let entry = await fetchUpstreamAsset(normalizedPath);
|
|
111
|
+
const hasExtension = /\/[^/]+\.[a-z0-9]{1,8}$/i.test(normalizedPath);
|
|
112
|
+
const acceptsHtml = (req.headers.accept ?? "").includes("text/html");
|
|
113
|
+
if (entry &&
|
|
114
|
+
entry.status === 404 &&
|
|
115
|
+
normalizedPath !== "/" &&
|
|
116
|
+
!hasExtension &&
|
|
117
|
+
acceptsHtml) {
|
|
118
|
+
entry = await fetchUpstreamAsset("/");
|
|
119
|
+
}
|
|
120
|
+
if (!entry) {
|
|
121
|
+
return res
|
|
122
|
+
.status(502)
|
|
123
|
+
.type("text/plain; charset=utf-8")
|
|
124
|
+
.send(`Unable to reach hosted Chomp Map assets at ${upstreamOrigin}. Check your internet connection and reload.`);
|
|
125
|
+
}
|
|
126
|
+
res.status(entry.status);
|
|
127
|
+
res.setHeader("Content-Type", entry.contentType);
|
|
128
|
+
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
129
|
+
res.setHeader("Cache-Control", entry.immutable
|
|
130
|
+
? "public, max-age=31536000, immutable"
|
|
131
|
+
: "no-cache");
|
|
132
|
+
if (req.method === "HEAD") {
|
|
133
|
+
return res.end();
|
|
134
|
+
}
|
|
135
|
+
return res.send(entry.body);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -101,6 +101,17 @@ export function registerAuthAndSourceRoutes(app, state) {
|
|
|
101
101
|
const { dbPath: activeDbPath } = getActiveUiTarget(state);
|
|
102
102
|
invalidateAuthCachesOnly(state, activeDbPath);
|
|
103
103
|
const redirectTarget = resolveSafeAuthReturnUrl(state, rawReturnTo, githubHandle);
|
|
104
|
+
if (req.query.mode === "popup") {
|
|
105
|
+
const safePayload = JSON.stringify({
|
|
106
|
+
type: "chomp:auth-success",
|
|
107
|
+
githubHandle: githubHandle ?? "",
|
|
108
|
+
redirectTarget,
|
|
109
|
+
}).replace(/</g, "\\u003c");
|
|
110
|
+
return res
|
|
111
|
+
.status(200)
|
|
112
|
+
.type("text/html; charset=utf-8")
|
|
113
|
+
.send(`<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Chomp — Signed In</title></head><body style="background:#0b0f15;color:#e8eef5;font-family:system-ui,sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0"><p>Signed in — returning to Chomp Map…</p><script>(function(){var d=${safePayload};try{if(window.opener&&!window.opener.closed){window.opener.postMessage({type:d.type,githubHandle:d.githubHandle},"*");}}catch(_e){}try{window.close();}catch(_e){}setTimeout(function(){if(!document.hidden){window.location.replace(d.redirectTarget);}},350);})();</script></body></html>`);
|
|
114
|
+
}
|
|
104
115
|
return res.redirect(302, redirectTarget);
|
|
105
116
|
}
|
|
106
117
|
catch (err) {
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import type { Express } from "express";
|
|
2
2
|
import { type UiServerState } from "../graphLayoutState.js";
|
|
3
|
+
/**
|
|
4
|
+
* Coalesces concurrent layout computations for the same `cacheKey` onto a single
|
|
5
|
+
* in-flight Promise and removes the entry inside `finally` once settled.
|
|
6
|
+
*/
|
|
7
|
+
export declare function runSingleFlightLayoutBuild<T>(inFlightMap: Map<string, Promise<T>>, cacheKey: string, factory: () => Promise<T>): Promise<T>;
|
|
3
8
|
export declare function registerLayoutRoutes(app: Express, state: UiServerState): void;
|
|
@@ -11,6 +11,33 @@ import { computePluginFingerprint } from "../../visualizer/pluginPresentationApi
|
|
|
11
11
|
import { getRulesFingerprint, loadRulesConfig, } from "../../visualizer/rulesConfig.js";
|
|
12
12
|
import { buildLayout, getActiveUiTarget, getAuthModeFingerprint, getCurrentDbMtime, getLocalShimsFileFp, getPluginRegistryMeta, hasGitCommitForDiff, hydratePluginRunsForRepo, invalidateAllServerCaches, loadBaseGraphCached, readGitBlobForDiff, resolveCommittedRefGraph, resolveScopedDiffPaths, resolveWorkingTreeSnapshotGraph, scheduleBackgroundPortHydration, triggerInitialPortHydrationAfterLayout, } from "../graphLayoutState.js";
|
|
13
13
|
import { buildAuthStatusPayload } from "./authSourceRoutes.js";
|
|
14
|
+
/**
|
|
15
|
+
* Coalesces concurrent layout computations for the same `cacheKey` onto a single
|
|
16
|
+
* in-flight Promise and removes the entry inside `finally` once settled.
|
|
17
|
+
*/
|
|
18
|
+
export function runSingleFlightLayoutBuild(inFlightMap, cacheKey, factory) {
|
|
19
|
+
const existing = inFlightMap.get(cacheKey);
|
|
20
|
+
if (existing) {
|
|
21
|
+
return existing;
|
|
22
|
+
}
|
|
23
|
+
let settled = false;
|
|
24
|
+
let promise;
|
|
25
|
+
promise = (async () => {
|
|
26
|
+
try {
|
|
27
|
+
return await factory();
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
settled = true;
|
|
31
|
+
if (promise && inFlightMap.get(cacheKey) === promise) {
|
|
32
|
+
inFlightMap.delete(cacheKey);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
if (!settled) {
|
|
37
|
+
inFlightMap.set(cacheKey, promise);
|
|
38
|
+
}
|
|
39
|
+
return promise;
|
|
40
|
+
}
|
|
14
41
|
export function registerLayoutRoutes(app, state) {
|
|
15
42
|
// GET /api/status — JSON snapshot or Server-Sent Events stream
|
|
16
43
|
app.get("/api/status", (req, res) => {
|
|
@@ -301,13 +328,13 @@ export function registerLayoutRoutes(app, state) {
|
|
|
301
328
|
};
|
|
302
329
|
}
|
|
303
330
|
else {
|
|
304
|
-
cacheKey = `${activeDbPath}:${dbMtime}:${rulesFp}:${authModeFp}:normal`;
|
|
331
|
+
cacheKey = `${activeDbPath}:${structureFp || dbMtime}:${rulesFp}:${authModeFp}:normal`;
|
|
305
332
|
}
|
|
306
333
|
}
|
|
307
334
|
else {
|
|
308
335
|
cacheKey = diffMode
|
|
309
|
-
? `${activeDbPath}:${dbMtime}:${rulesFp}:${authModeFp}:diff:fallback`
|
|
310
|
-
: `${activeDbPath}:${dbMtime}:${rulesFp}:${authModeFp}:normal`;
|
|
336
|
+
? `${activeDbPath}:${structureFp || dbMtime}:${rulesFp}:${authModeFp}:diff:fallback`
|
|
337
|
+
: `${activeDbPath}:${structureFp || dbMtime}:${rulesFp}:${authModeFp}:normal`;
|
|
311
338
|
}
|
|
312
339
|
const stampLiveGitMetadata = (targetLayout) => {
|
|
313
340
|
if (!diffMode &&
|
|
@@ -403,12 +430,7 @@ export function registerLayoutRoutes(app, state) {
|
|
|
403
430
|
return res.json(diskHit);
|
|
404
431
|
}
|
|
405
432
|
}
|
|
406
|
-
|
|
407
|
-
const pending = await state.layoutInFlight.get(cacheKey);
|
|
408
|
-
triggerInitialPortHydrationAfterLayout(state);
|
|
409
|
-
return res.json(pending);
|
|
410
|
-
}
|
|
411
|
-
const buildPromise = (async () => {
|
|
433
|
+
const resultLayout = await runSingleFlightLayoutBuild(state.layoutInFlight, cacheKey, async () => {
|
|
412
434
|
if (hydrateRefGraphsForBuild) {
|
|
413
435
|
await hydrateRefGraphsForBuild();
|
|
414
436
|
}
|
|
@@ -476,7 +498,7 @@ export function registerLayoutRoutes(app, state) {
|
|
|
476
498
|
state.layoutCache.delete(oldestKey);
|
|
477
499
|
}
|
|
478
500
|
state.layoutCache.set(cacheKey, layout);
|
|
479
|
-
const revisionLogKey = `${activeDbPath}:${dbMtime}:${rulesFp}:${authModeFp}`;
|
|
501
|
+
const revisionLogKey = `${activeDbPath}:${structureFp || dbMtime}:${rulesFp}:${authModeFp}`;
|
|
480
502
|
if (state.debug || process.env.CHOMP_DEBUG_LAYOUT === "1") {
|
|
481
503
|
console.log(`✅ Layout complete — ${layout.nodes.length} positioned nodes, ` +
|
|
482
504
|
`${layout.islandNodes.length} islands, ${layout.badgeNodes.length} badge hubs`);
|
|
@@ -523,11 +545,7 @@ export function registerLayoutRoutes(app, state) {
|
|
|
523
545
|
}
|
|
524
546
|
}
|
|
525
547
|
return layout;
|
|
526
|
-
})().finally(() => {
|
|
527
|
-
state.layoutInFlight.delete(cacheKey);
|
|
528
548
|
});
|
|
529
|
-
state.layoutInFlight.set(cacheKey, buildPromise);
|
|
530
|
-
const resultLayout = await buildPromise;
|
|
531
549
|
triggerInitialPortHydrationAfterLayout(state);
|
|
532
550
|
return res.json(resultLayout);
|
|
533
551
|
}
|
package/dist/utils/branding.d.ts
CHANGED
|
@@ -20,11 +20,20 @@ export declare const CHOMP_UNICODE_LOGO_LINES: readonly string[];
|
|
|
20
20
|
*/
|
|
21
21
|
export declare const CHOMP_CHOMPING_FRAME_LINES: readonly string[];
|
|
22
22
|
export type ChompLogoFrame = "open" | "chomp";
|
|
23
|
+
/**
|
|
24
|
+
* Resolves the safe horizontal column budget for stacked CLI sections so output
|
|
25
|
+
* never wraps on default 80-column terminals (while adapting down to narrower panes).
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveMaxTerminalCols(overrideCols?: number): number;
|
|
28
|
+
/**
|
|
29
|
+
* Truncates an ANSI-colored string so its visible terminal column width never exceeds `maxCols`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function truncateAnsiToCols(str: string, maxCols: number): string;
|
|
23
32
|
/**
|
|
24
33
|
* Renders the Chomp Unicode logo mark (or chomping frame) in brand yellow
|
|
25
|
-
*
|
|
34
|
+
* stacked cleanly above the wordmark and tagline so output stays <80 columns.
|
|
26
35
|
*/
|
|
27
|
-
export declare function renderChompBanner(subtitle?: string, frame?: ChompLogoFrame): string;
|
|
36
|
+
export declare function renderChompBanner(subtitle?: string, frame?: ChompLogoFrame, maxColsOverride?: number): string;
|
|
28
37
|
export declare function printChompBanner(subtitle?: string, frame?: ChompLogoFrame): void;
|
|
29
38
|
/**
|
|
30
39
|
* Plays a live terminal chomping animation that alternates between the open-mouth
|
|
@@ -85,31 +94,65 @@ export declare function printWelcomeMessage(repoName: string, isDryRun?: boolean
|
|
|
85
94
|
export declare function runDiscoveryTicker(repoName: string, customMessages?: string[]): Promise<void>;
|
|
86
95
|
/**
|
|
87
96
|
* Renders the detected repository & package configuration inside a structured
|
|
88
|
-
* read-only box table
|
|
97
|
+
* read-only box table constrained to <80 terminal columns.
|
|
98
|
+
*/
|
|
99
|
+
export declare function printDetectedWorkspaceTable(repoName: string, packages: DetectedWorkspacePackage[], vaultNotes?: string[], maxColsOverride?: number): void;
|
|
100
|
+
export declare const LARGE_REPO_FILE_THRESHOLD = 150;
|
|
101
|
+
export declare const LARGE_REPO_PACKAGE_THRESHOLD = 6;
|
|
102
|
+
/**
|
|
103
|
+
* Fast pre-flight file discovery (~5–15ms) matching `analyzeTarget`'s workspace exclusion rules.
|
|
89
104
|
*/
|
|
90
|
-
export declare function
|
|
91
|
-
export
|
|
105
|
+
export declare function countAnalyzableFiles(targetPath: string, excludeWorkspaces?: string[]): number;
|
|
106
|
+
export declare function shouldShowLargeRepoScaleNotice(fileCount: number, packageCount: number): boolean;
|
|
107
|
+
export declare function formatLargeRepoScaleNotice(fileCount: number, packageCount: number, maxColsOverride?: number): string;
|
|
108
|
+
export interface ChompExtractionAnimationOptions<T extends {
|
|
109
|
+
graph: RepresentationGraph;
|
|
110
|
+
durationMs: number;
|
|
111
|
+
} = {
|
|
112
|
+
graph: RepresentationGraph;
|
|
113
|
+
durationMs: number;
|
|
114
|
+
}> {
|
|
92
115
|
repoName: string;
|
|
93
116
|
repoPath: string;
|
|
117
|
+
targetPath?: string;
|
|
118
|
+
preFlightFileCount?: number;
|
|
94
119
|
dbPath: string;
|
|
95
120
|
commitSha?: string;
|
|
96
121
|
branchName?: string;
|
|
97
122
|
excludeWorkspaces?: string[];
|
|
98
123
|
isSandbox?: boolean;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
durationMs: number;
|
|
102
|
-
}>;
|
|
124
|
+
writeOutput?: (payload: string) => void;
|
|
125
|
+
executeExtraction: (onProgress?: (statusText: string) => void) => Promise<T>;
|
|
103
126
|
}
|
|
127
|
+
export interface CompletedBiteSummaryInput {
|
|
128
|
+
repoName: string;
|
|
129
|
+
repoPath: string;
|
|
130
|
+
dbPath: string;
|
|
131
|
+
gitTag: string;
|
|
132
|
+
fileCount: number;
|
|
133
|
+
packagesToDisplay: DetectedWorkspacePackage[];
|
|
134
|
+
graph: RepresentationGraph;
|
|
135
|
+
durationMs: number;
|
|
136
|
+
maxColsOverride?: number;
|
|
137
|
+
timestamp?: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Renders the settled open-mouth Chomp logo mark stacked vertically above the
|
|
141
|
+
* package progress breakdown and Bite Report summary (<80 columns per line).
|
|
142
|
+
*/
|
|
143
|
+
export declare function renderCompletedBiteSummary(input: CompletedBiteSummaryInput): string;
|
|
104
144
|
/**
|
|
105
145
|
* Runs the 2-frame Chomp mouth animation continuously during code analysis
|
|
106
|
-
*
|
|
107
|
-
*
|
|
146
|
+
* using a fixed-height <80-column animated block (preventing terminal line-wrap cursor drift)
|
|
147
|
+
* and settles onto a clean vertically stacked Bite Report summary.
|
|
108
148
|
*/
|
|
109
|
-
export declare function runChompExtractionWithAnimation
|
|
149
|
+
export declare function runChompExtractionWithAnimation<T extends {
|
|
150
|
+
graph: RepresentationGraph;
|
|
151
|
+
durationMs: number;
|
|
152
|
+
} = {
|
|
110
153
|
graph: RepresentationGraph;
|
|
111
154
|
durationMs: number;
|
|
112
|
-
}>;
|
|
155
|
+
}>(opts: ChompExtractionAnimationOptions<T>): Promise<T>;
|
|
113
156
|
export declare function confirmPrompt(question: string, defaultYes?: boolean, description?: string): Promise<boolean>;
|
|
114
157
|
export interface MultiSelectOption<T = string> {
|
|
115
158
|
value: T;
|