@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,368 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { CORE_EXTRACTOR_VERSION, analyzeTarget } from "@getchomp/core";
|
|
3
|
+
import { auditDesignSystem, getChompPlugin, getPluginEnvStatus, getPluginStateDirRel, loadPluginSettings, readMergeDecisions, readPluginLastRun, removeMergeDecision, runChompPlugin, savePluginSettings, upsertMergeDecision, } from "@getchomp/mcp";
|
|
4
|
+
import { loadExcludeWorkspaces } from "../../utils/branding.js";
|
|
5
|
+
import { resolveRepoName } from "../../utils/git.js";
|
|
6
|
+
import { buildEntityPresentations, buildPluginsOverview, computePluginFingerprint, failPluginRun, finishPluginRun, getPluginRun, isPluginRunning, startPluginRun, } from "../../visualizer/pluginPresentationApi.js";
|
|
7
|
+
import { getActiveUiTarget, getPluginRegistryMeta, hydratePluginRunsForRepo, loadBaseGraphCached, } from "../graphLayoutState.js";
|
|
8
|
+
export function registerPluginRoutes(app, state) {
|
|
9
|
+
app.get("/api/plugins", async (req, res) => {
|
|
10
|
+
try {
|
|
11
|
+
const requestedEnv = typeof req.query.environment === "string"
|
|
12
|
+
? req.query.environment.trim()
|
|
13
|
+
: undefined;
|
|
14
|
+
const { target: activeTarget } = getActiveUiTarget(state);
|
|
15
|
+
const baseData = await loadBaseGraphCached(state);
|
|
16
|
+
if (!baseData) {
|
|
17
|
+
return res.json({
|
|
18
|
+
plugins: [],
|
|
19
|
+
environment: requestedEnv || "default",
|
|
20
|
+
fingerprint: {
|
|
21
|
+
structureFp: "",
|
|
22
|
+
pluginFp: computePluginFingerprint([], hydratePluginRunsForRepo(state, activeTarget), getPluginRegistryMeta(activeTarget)),
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const repoPath = baseData.repo.path || activeTarget;
|
|
27
|
+
return res.json(buildPluginsOverview({
|
|
28
|
+
pluginOverlays: baseData.pluginOverlays,
|
|
29
|
+
nodes: baseData.graph.nodes,
|
|
30
|
+
registry: getPluginRegistryMeta(repoPath),
|
|
31
|
+
runs: hydratePluginRunsForRepo(state, repoPath),
|
|
32
|
+
structureFp: baseData.structureFp,
|
|
33
|
+
environment: requestedEnv,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
console.error("Error building plugins overview:", e);
|
|
38
|
+
return res.status(500).json({ error: "Failed to load plugin data" });
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
app.get("/api/plugins/presentation", async (req, res) => {
|
|
42
|
+
try {
|
|
43
|
+
const entityId = typeof req.query.entityId === "string" ? req.query.entityId : "";
|
|
44
|
+
if (!entityId) {
|
|
45
|
+
return res.status(400).json({ error: "entityId is required" });
|
|
46
|
+
}
|
|
47
|
+
const requestedEnv = typeof req.query.environment === "string"
|
|
48
|
+
? req.query.environment.trim()
|
|
49
|
+
: undefined;
|
|
50
|
+
const { target: activeTarget } = getActiveUiTarget(state);
|
|
51
|
+
const baseData = await loadBaseGraphCached(state);
|
|
52
|
+
if (!baseData)
|
|
53
|
+
return res.json([]);
|
|
54
|
+
const repoPath = baseData.repo.path || activeTarget;
|
|
55
|
+
return res.json(buildEntityPresentations({
|
|
56
|
+
pluginOverlays: baseData.pluginOverlays,
|
|
57
|
+
entityId,
|
|
58
|
+
registry: getPluginRegistryMeta(repoPath),
|
|
59
|
+
nodes: baseData.graph.nodes,
|
|
60
|
+
environment: requestedEnv,
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.error("Error loading plugin presentation:", e);
|
|
65
|
+
return res
|
|
66
|
+
.status(500)
|
|
67
|
+
.json({ error: "Failed to load plugin presentation" });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
app.get("/api/plugins/:name/settings", async (req, res) => {
|
|
71
|
+
try {
|
|
72
|
+
const name = String(req.params.name);
|
|
73
|
+
const plugin = getChompPlugin(name);
|
|
74
|
+
if (!plugin) {
|
|
75
|
+
return res.status(404).json({ error: `Unknown plugin '${name}'` });
|
|
76
|
+
}
|
|
77
|
+
const { target: activeTarget } = getActiveUiTarget(state);
|
|
78
|
+
const baseData = await loadBaseGraphCached(state);
|
|
79
|
+
const repoPath = baseData?.repo.path || activeTarget;
|
|
80
|
+
const settings = loadPluginSettings(repoPath, plugin);
|
|
81
|
+
const envStatus = getPluginEnvStatus(plugin, settings);
|
|
82
|
+
return res.json({
|
|
83
|
+
plugin: plugin.name,
|
|
84
|
+
stateDir: getPluginStateDirRel(plugin.name),
|
|
85
|
+
settingsSchema: plugin.settingsSchema ?? [],
|
|
86
|
+
settings,
|
|
87
|
+
...(envStatus ? { envStatus } : {}),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
console.error("Error reading plugin settings:", e);
|
|
92
|
+
return res.status(500).json({ error: "Failed to read plugin settings" });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
app.put("/api/plugins/:name/settings", async (req, res) => {
|
|
96
|
+
try {
|
|
97
|
+
const name = String(req.params.name);
|
|
98
|
+
const plugin = getChompPlugin(name);
|
|
99
|
+
if (!plugin) {
|
|
100
|
+
return res.status(404).json({ error: `Unknown plugin '${name}'` });
|
|
101
|
+
}
|
|
102
|
+
const { target: activeTarget, dbPath: activeDbPath } = getActiveUiTarget(state);
|
|
103
|
+
const baseData = await loadBaseGraphCached(state);
|
|
104
|
+
const repoPath = baseData?.repo.path || activeTarget;
|
|
105
|
+
const patch = req.body && typeof req.body === "object" ? req.body : {};
|
|
106
|
+
const settings = savePluginSettings(repoPath, plugin, patch);
|
|
107
|
+
const envStatus = getPluginEnvStatus(plugin, settings);
|
|
108
|
+
state.layoutCache.clear();
|
|
109
|
+
if (baseData && !isPluginRunning(state.pluginRuns, plugin.name)) {
|
|
110
|
+
startPluginRun(state.pluginRuns, plugin.name);
|
|
111
|
+
void (async () => {
|
|
112
|
+
try {
|
|
113
|
+
await runChompPlugin(plugin, {
|
|
114
|
+
repoPath,
|
|
115
|
+
repoId: baseData.repo.id,
|
|
116
|
+
repoName: baseData.repo.name && baseData.repo.name !== basename(repoPath)
|
|
117
|
+
? baseData.repo.name
|
|
118
|
+
: resolveRepoName(repoPath),
|
|
119
|
+
dbPath: activeDbPath,
|
|
120
|
+
graph: baseData.graph,
|
|
121
|
+
excludeWorkspaces: loadExcludeWorkspaces(repoPath),
|
|
122
|
+
persist: true,
|
|
123
|
+
});
|
|
124
|
+
finishPluginRun(state.pluginRuns, plugin.name);
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
failPluginRun(state.pluginRuns, plugin.name, err?.message ?? String(err));
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
state.baseGraphCache = null;
|
|
131
|
+
state.layoutCache.clear();
|
|
132
|
+
}
|
|
133
|
+
})();
|
|
134
|
+
}
|
|
135
|
+
return res.json({
|
|
136
|
+
plugin: plugin.name,
|
|
137
|
+
stateDir: getPluginStateDirRel(plugin.name),
|
|
138
|
+
settings,
|
|
139
|
+
...(envStatus ? { envStatus } : {}),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
console.error("Error saving plugin settings:", e);
|
|
144
|
+
return res.status(500).json({ error: "Failed to save plugin settings" });
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
app.get("/api/plugins/:name/status", async (req, res) => {
|
|
148
|
+
const name = String(req.params.name);
|
|
149
|
+
const mem = getPluginRun(state.pluginRuns, name);
|
|
150
|
+
if (mem.state === "running") {
|
|
151
|
+
return res.json(mem);
|
|
152
|
+
}
|
|
153
|
+
const { target: activeTarget } = getActiveUiTarget(state);
|
|
154
|
+
const baseData = await loadBaseGraphCached(state);
|
|
155
|
+
const repoPath = baseData?.repo.path || activeTarget;
|
|
156
|
+
const disk = readPluginLastRun(repoPath, name);
|
|
157
|
+
if (disk && (!mem.finishedAt || disk.finishedAt >= mem.finishedAt)) {
|
|
158
|
+
return res.json({
|
|
159
|
+
state: disk.status === "error" ? "error" : "idle",
|
|
160
|
+
startedAt: disk.startedAt,
|
|
161
|
+
finishedAt: disk.finishedAt,
|
|
162
|
+
durationMs: disk.durationMs,
|
|
163
|
+
...(disk.presentationWarnings.length > 0
|
|
164
|
+
? { presentationWarnings: disk.presentationWarnings }
|
|
165
|
+
: {}),
|
|
166
|
+
...(disk.error ? { error: disk.error } : {}),
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return res.json(mem);
|
|
170
|
+
});
|
|
171
|
+
app.post("/api/plugins/:name/run", async (req, res) => {
|
|
172
|
+
try {
|
|
173
|
+
const name = String(req.params.name);
|
|
174
|
+
const plugin = getChompPlugin(name);
|
|
175
|
+
if (!plugin) {
|
|
176
|
+
return res.status(404).json({ error: `Unknown plugin '${name}'` });
|
|
177
|
+
}
|
|
178
|
+
if (isPluginRunning(state.pluginRuns, name)) {
|
|
179
|
+
return res.status(202).json(getPluginRun(state.pluginRuns, name));
|
|
180
|
+
}
|
|
181
|
+
const runEnv = typeof req.body?.environment === "string" &&
|
|
182
|
+
req.body.environment.trim()
|
|
183
|
+
? req.body.environment.trim()
|
|
184
|
+
: undefined;
|
|
185
|
+
const { target: activeTarget, dbPath: activeDbPath } = getActiveUiTarget(state);
|
|
186
|
+
const baseData = await loadBaseGraphCached(state);
|
|
187
|
+
if (!baseData) {
|
|
188
|
+
return res
|
|
189
|
+
.status(404)
|
|
190
|
+
.json({ error: "No repositories or graph found in database." });
|
|
191
|
+
}
|
|
192
|
+
const repoPath = baseData.repo.path || activeTarget;
|
|
193
|
+
const status = startPluginRun(state.pluginRuns, name);
|
|
194
|
+
void (async () => {
|
|
195
|
+
try {
|
|
196
|
+
await runChompPlugin(plugin, {
|
|
197
|
+
repoPath,
|
|
198
|
+
repoId: baseData.repo.id,
|
|
199
|
+
repoName: baseData.repo.name && baseData.repo.name !== basename(repoPath)
|
|
200
|
+
? baseData.repo.name
|
|
201
|
+
: resolveRepoName(repoPath),
|
|
202
|
+
dbPath: activeDbPath,
|
|
203
|
+
graph: baseData.graph,
|
|
204
|
+
excludeWorkspaces: loadExcludeWorkspaces(repoPath),
|
|
205
|
+
environment: runEnv,
|
|
206
|
+
persist: true,
|
|
207
|
+
});
|
|
208
|
+
finishPluginRun(state.pluginRuns, name);
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
failPluginRun(state.pluginRuns, name, err?.message ?? String(err));
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
state.baseGraphCache = null;
|
|
215
|
+
state.designSystemReportCache = null;
|
|
216
|
+
}
|
|
217
|
+
})();
|
|
218
|
+
return res.status(202).json(status);
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
console.error("Error starting plugin run:", e);
|
|
222
|
+
return res.status(500).json({ error: "Failed to start plugin run" });
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
// Design System Evaluation Catalog API (Live Audit + Merge Tracker)
|
|
226
|
+
app.get("/api/plugins/design-system/report", async (req, res) => {
|
|
227
|
+
try {
|
|
228
|
+
const refresh = req.query.refresh === "true";
|
|
229
|
+
const { target: activeTarget, dbPath: activeDbPath } = getActiveUiTarget(state);
|
|
230
|
+
const baseData = await loadBaseGraphCached(state);
|
|
231
|
+
if (!baseData) {
|
|
232
|
+
return res
|
|
233
|
+
.status(404)
|
|
234
|
+
.json({ error: "No repository graph found in database." });
|
|
235
|
+
}
|
|
236
|
+
const repoPath = baseData.repo.path || activeTarget;
|
|
237
|
+
const cacheKey = `${repoPath}:${baseData.mtime ?? ""}`;
|
|
238
|
+
if (!refresh &&
|
|
239
|
+
state.designSystemReportCache &&
|
|
240
|
+
state.designSystemReportCache.key === cacheKey) {
|
|
241
|
+
return res.json({
|
|
242
|
+
...state.designSystemReportCache.payload,
|
|
243
|
+
mergeDecisions: readMergeDecisions(repoPath),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
const targetGraph = refresh
|
|
247
|
+
? analyzeTarget(repoPath, CORE_EXTRACTOR_VERSION, undefined, loadExcludeWorkspaces(repoPath))
|
|
248
|
+
: baseData.graph;
|
|
249
|
+
const payload = await auditDesignSystem({
|
|
250
|
+
repoPath,
|
|
251
|
+
repoId: baseData.repo.id,
|
|
252
|
+
repoName: baseData.repo.name && baseData.repo.name !== basename(repoPath)
|
|
253
|
+
? baseData.repo.name
|
|
254
|
+
: resolveRepoName(repoPath),
|
|
255
|
+
dbPath: activeDbPath,
|
|
256
|
+
graph: targetGraph,
|
|
257
|
+
limit: 500,
|
|
258
|
+
persistOverlays: false,
|
|
259
|
+
autoPinCleanBaseline: false,
|
|
260
|
+
});
|
|
261
|
+
state.designSystemReportCache = { key: cacheKey, payload };
|
|
262
|
+
return res.json({
|
|
263
|
+
...payload,
|
|
264
|
+
mergeDecisions: readMergeDecisions(repoPath),
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
catch (e) {
|
|
268
|
+
console.error("Error running design-system catalog audit:", e);
|
|
269
|
+
return res
|
|
270
|
+
.status(500)
|
|
271
|
+
.json({ error: e?.message || "Failed to audit design system" });
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
app.get("/api/plugins/design-system/merges", async (_req, res) => {
|
|
275
|
+
try {
|
|
276
|
+
const { target: activeTarget } = getActiveUiTarget(state);
|
|
277
|
+
const baseData = await loadBaseGraphCached(state);
|
|
278
|
+
const repoPath = baseData?.repo.path || activeTarget;
|
|
279
|
+
return res.json({ mergeDecisions: readMergeDecisions(repoPath) });
|
|
280
|
+
}
|
|
281
|
+
catch (e) {
|
|
282
|
+
return res
|
|
283
|
+
.status(500)
|
|
284
|
+
.json({ error: e?.message || "Failed to read merge decisions" });
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
app.post("/api/plugins/design-system/merges", async (req, res) => {
|
|
288
|
+
try {
|
|
289
|
+
const { target: activeTarget } = getActiveUiTarget(state);
|
|
290
|
+
const baseData = await loadBaseGraphCached(state);
|
|
291
|
+
const repoPath = baseData?.repo.path || activeTarget;
|
|
292
|
+
const body = req.body ?? {};
|
|
293
|
+
const kind = body.kind;
|
|
294
|
+
if (kind !== "component" && kind !== "color" && kind !== "typography") {
|
|
295
|
+
return res.status(400).json({
|
|
296
|
+
error: "Invalid merge kind; expected component | color | typography.",
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
if (!body.sourceId ||
|
|
300
|
+
!body.sourceLabel ||
|
|
301
|
+
!body.targetId ||
|
|
302
|
+
!body.targetLabel) {
|
|
303
|
+
return res.status(400).json({
|
|
304
|
+
error: "sourceId, sourceLabel, targetId, and targetLabel are required.",
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
const { decision, decisions } = upsertMergeDecision(repoPath, {
|
|
308
|
+
kind,
|
|
309
|
+
sourceId: String(body.sourceId),
|
|
310
|
+
sourceLabel: String(body.sourceLabel),
|
|
311
|
+
...(typeof body.sourceFilePath === "string"
|
|
312
|
+
? { sourceFilePath: body.sourceFilePath }
|
|
313
|
+
: {}),
|
|
314
|
+
...(typeof body.sourceLineNumber === "number"
|
|
315
|
+
? { sourceLineNumber: body.sourceLineNumber }
|
|
316
|
+
: {}),
|
|
317
|
+
targetId: String(body.targetId),
|
|
318
|
+
targetLabel: String(body.targetLabel),
|
|
319
|
+
...(typeof body.targetFilePath === "string"
|
|
320
|
+
? { targetFilePath: body.targetFilePath }
|
|
321
|
+
: {}),
|
|
322
|
+
...(typeof body.similarity === "number"
|
|
323
|
+
? { similarity: body.similarity }
|
|
324
|
+
: {}),
|
|
325
|
+
...(Array.isArray(body.sharedSignals)
|
|
326
|
+
? { sharedSignals: body.sharedSignals.map(String) }
|
|
327
|
+
: {}),
|
|
328
|
+
...(typeof body.note === "string" ? { note: body.note } : {}),
|
|
329
|
+
});
|
|
330
|
+
state.designSystemReportCache = null;
|
|
331
|
+
return res.json({ decision, mergeDecisions: decisions });
|
|
332
|
+
}
|
|
333
|
+
catch (e) {
|
|
334
|
+
return res
|
|
335
|
+
.status(500)
|
|
336
|
+
.json({ error: e?.message || "Failed to save merge decision" });
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
app.delete("/api/plugins/design-system/merges", async (req, res) => {
|
|
340
|
+
try {
|
|
341
|
+
const { target: activeTarget } = getActiveUiTarget(state);
|
|
342
|
+
const baseData = await loadBaseGraphCached(state);
|
|
343
|
+
const repoPath = baseData?.repo.path || activeTarget;
|
|
344
|
+
const idOrSourceId = String(req.query.id ??
|
|
345
|
+
req.body?.id ??
|
|
346
|
+
req.query.sourceId ??
|
|
347
|
+
req.body?.sourceId ??
|
|
348
|
+
"").trim();
|
|
349
|
+
const rawKind = req.query.kind ?? req.body?.kind;
|
|
350
|
+
const kind = rawKind === "component" ||
|
|
351
|
+
rawKind === "color" ||
|
|
352
|
+
rawKind === "typography"
|
|
353
|
+
? rawKind
|
|
354
|
+
: undefined;
|
|
355
|
+
if (!idOrSourceId) {
|
|
356
|
+
return res.status(400).json({ error: "id or sourceId is required" });
|
|
357
|
+
}
|
|
358
|
+
const { removed, decisions } = removeMergeDecision(repoPath, idOrSourceId, kind);
|
|
359
|
+
state.designSystemReportCache = null;
|
|
360
|
+
return res.json({ removed, mergeDecisions: decisions });
|
|
361
|
+
}
|
|
362
|
+
catch (e) {
|
|
363
|
+
return res
|
|
364
|
+
.status(500)
|
|
365
|
+
.json({ error: e?.message || "Failed to remove merge decision" });
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { existsSync, readFileSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { applyActivePluginProjections } from "@getchomp/mcp";
|
|
4
|
+
import { getGitInfoAsync, getGitInfoFromFs } from "../../utils/git.js";
|
|
5
|
+
import { loadRulesConfig, saveRulesConfig, } from "../../visualizer/rulesConfig.js";
|
|
6
|
+
import { getActiveUiTarget, loadBaseGraphCached, } from "../graphLayoutState.js";
|
|
7
|
+
export function registerViewAndRulesRoutes(app, state) {
|
|
8
|
+
// GET /api/view — read agentic view state (with repoId, branch-awareness + node-existence failsafe)
|
|
9
|
+
app.get("/api/view", async (_req, res) => {
|
|
10
|
+
try {
|
|
11
|
+
const { target: activeTarget, repoName: activeRepoName, dbPath: activeDbPath, } = getActiveUiTarget(state);
|
|
12
|
+
const viewPath = join(dirname(activeDbPath), "current_view.json");
|
|
13
|
+
if (!existsSync(viewPath)) {
|
|
14
|
+
state.viewValidationCache = null;
|
|
15
|
+
return res.json(null);
|
|
16
|
+
}
|
|
17
|
+
const viewStat = statSync(viewPath);
|
|
18
|
+
const baseData = await loadBaseGraphCached(state);
|
|
19
|
+
if (!baseData) {
|
|
20
|
+
return res.json(null);
|
|
21
|
+
}
|
|
22
|
+
const repoPath = baseData.repo.path || activeTarget;
|
|
23
|
+
const fsGit = getGitInfoFromFs(repoPath);
|
|
24
|
+
const currentBranchName = fsGit.branchName ||
|
|
25
|
+
baseData.repo.branchName ||
|
|
26
|
+
baseData.graph.branchName;
|
|
27
|
+
const viewCacheKey = `${viewPath}:${viewStat.mtimeMs}:${viewStat.size}:${baseData.key}:${currentBranchName ?? ""}`;
|
|
28
|
+
if (state.viewValidationCache &&
|
|
29
|
+
state.viewValidationCache.key === viewCacheKey) {
|
|
30
|
+
return res.json(state.viewValidationCache.payload);
|
|
31
|
+
}
|
|
32
|
+
const data = JSON.parse(readFileSync(viewPath, "utf-8"));
|
|
33
|
+
if (!data || typeof data !== "object") {
|
|
34
|
+
state.viewValidationCache = { key: viewCacheKey, payload: null };
|
|
35
|
+
return res.json(null);
|
|
36
|
+
}
|
|
37
|
+
const resolvedRepoName = baseData.repo.name || activeRepoName;
|
|
38
|
+
const activeRepoId = baseData.repo.id ||
|
|
39
|
+
resolvedRepoName.toLowerCase().replace(/[^a-z0-9_-]/g, "_");
|
|
40
|
+
if (data.repoId && data.repoId !== activeRepoId) {
|
|
41
|
+
state.viewValidationCache = { key: viewCacheKey, payload: null };
|
|
42
|
+
return res.json(null);
|
|
43
|
+
}
|
|
44
|
+
if (data.repoName &&
|
|
45
|
+
data.repoName !== resolvedRepoName &&
|
|
46
|
+
data.repoName !== activeRepoName) {
|
|
47
|
+
state.viewValidationCache = { key: viewCacheKey, payload: null };
|
|
48
|
+
return res.json(null);
|
|
49
|
+
}
|
|
50
|
+
const isBranchMismatch = Boolean(data.branchName &&
|
|
51
|
+
currentBranchName &&
|
|
52
|
+
data.branchName !== currentBranchName);
|
|
53
|
+
if (!isBranchMismatch &&
|
|
54
|
+
Array.isArray(data.highlightNodeIds) &&
|
|
55
|
+
data.highlightNodeIds.length > 0) {
|
|
56
|
+
const projectedForView = applyActivePluginProjections(baseData.graph, {
|
|
57
|
+
repoPath,
|
|
58
|
+
overlays: baseData.structuralOverlays,
|
|
59
|
+
});
|
|
60
|
+
const graphNodeIdSet = new Set(projectedForView.nodes.map((n) => String(n.id).split("::")[0].split("@")[0]));
|
|
61
|
+
const hasAnyMatchingNode = data.highlightNodeIds.some((rawId) => graphNodeIdSet.has(String(rawId).split("::")[0].split("@")[0]));
|
|
62
|
+
if (!hasAnyMatchingNode) {
|
|
63
|
+
state.viewValidationCache = { key: viewCacheKey, payload: null };
|
|
64
|
+
return res.json(null);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const payload = {
|
|
68
|
+
...data,
|
|
69
|
+
repoId: activeRepoId,
|
|
70
|
+
repoName: resolvedRepoName,
|
|
71
|
+
...(currentBranchName ? { currentBranchName } : {}),
|
|
72
|
+
...(isBranchMismatch
|
|
73
|
+
? { expired: true, expiredReason: "branch_mismatch" }
|
|
74
|
+
: { expired: false }),
|
|
75
|
+
};
|
|
76
|
+
state.viewValidationCache = { key: viewCacheKey, payload };
|
|
77
|
+
return res.json(payload);
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
console.error("Error reading view:", e);
|
|
81
|
+
return res.json(null);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
// POST /api/view — activate an agentic or plugin spotlight view
|
|
85
|
+
app.post("/api/view", async (req, res) => {
|
|
86
|
+
try {
|
|
87
|
+
const { target: activeTarget, repoName: activeRepoName, dbPath: activeDbPath, } = getActiveUiTarget(state);
|
|
88
|
+
const baseData = await loadBaseGraphCached(state);
|
|
89
|
+
const resolvedRepoName = baseData?.repo.name || activeRepoName;
|
|
90
|
+
const activeRepoId = baseData?.repo.id ||
|
|
91
|
+
resolvedRepoName.toLowerCase().replace(/[^a-z0-9_-]/g, "_");
|
|
92
|
+
const repoPath = baseData?.repo.path || activeTarget;
|
|
93
|
+
const liveGit = await getGitInfoAsync(repoPath, { includeCommitMessage: false });
|
|
94
|
+
const currentBranchName = liveGit.branchName ||
|
|
95
|
+
baseData?.repo.branchName ||
|
|
96
|
+
baseData?.graph.branchName;
|
|
97
|
+
const body = req.body ?? {};
|
|
98
|
+
const payload = {
|
|
99
|
+
title: typeof body.title === "string" ? body.title : "Spotlight View",
|
|
100
|
+
description: typeof body.description === "string" ? body.description : "",
|
|
101
|
+
highlightNodeIds: Array.isArray(body.highlightNodeIds)
|
|
102
|
+
? body.highlightNodeIds.filter((id) => typeof id === "string")
|
|
103
|
+
: [],
|
|
104
|
+
...(body.viewLevel === "package" || body.viewLevel === "system"
|
|
105
|
+
? { viewLevel: body.viewLevel }
|
|
106
|
+
: {}),
|
|
107
|
+
...(typeof body.packageName === "string"
|
|
108
|
+
? { packageName: body.packageName }
|
|
109
|
+
: {}),
|
|
110
|
+
...(body.nodeAnnotations && typeof body.nodeAnnotations === "object"
|
|
111
|
+
? { nodeAnnotations: body.nodeAnnotations }
|
|
112
|
+
: {}),
|
|
113
|
+
...(typeof body.layer === "string" ? { layer: body.layer } : {}),
|
|
114
|
+
...(typeof body.source === "string" ? { source: body.source } : {}),
|
|
115
|
+
repoId: activeRepoId,
|
|
116
|
+
repoName: resolvedRepoName,
|
|
117
|
+
...(currentBranchName
|
|
118
|
+
? { branchName: currentBranchName, currentBranchName }
|
|
119
|
+
: {}),
|
|
120
|
+
createdAt: new Date().toISOString(),
|
|
121
|
+
expired: false,
|
|
122
|
+
};
|
|
123
|
+
const viewPath = join(dirname(activeDbPath), "current_view.json");
|
|
124
|
+
writeFileSync(viewPath, JSON.stringify(payload, null, 2), "utf-8");
|
|
125
|
+
state.viewValidationCache = null;
|
|
126
|
+
return res.json(payload);
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
console.error("Error writing view:", e);
|
|
130
|
+
return res.status(500).json({ error: "Failed to save view" });
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
// DELETE /api/view — clear agentic view state
|
|
134
|
+
app.delete("/api/view", (_req, res) => {
|
|
135
|
+
try {
|
|
136
|
+
const { dbPath: activeDbPath } = getActiveUiTarget(state);
|
|
137
|
+
const viewPath = join(dirname(activeDbPath), "current_view.json");
|
|
138
|
+
if (existsSync(viewPath)) {
|
|
139
|
+
unlinkSync(viewPath);
|
|
140
|
+
}
|
|
141
|
+
state.viewValidationCache = null;
|
|
142
|
+
return res.json({ success: true });
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
console.error("Error deleting view:", e);
|
|
146
|
+
return res.status(500).json({ error: "Failed to delete view" });
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
// GET /api/rules & PUT /api/rules — classification & folding rules (.chomp/rules.json)
|
|
150
|
+
app.get("/api/rules", (_req, res) => {
|
|
151
|
+
try {
|
|
152
|
+
const { dbPath: activeDbPath } = getActiveUiTarget(state);
|
|
153
|
+
const config = loadRulesConfig(activeDbPath);
|
|
154
|
+
return res.json(config);
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
console.error("Error reading rules config:", e);
|
|
158
|
+
return res.status(500).json({ error: "Failed to read rules config" });
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
app.put("/api/rules", (req, res) => {
|
|
162
|
+
try {
|
|
163
|
+
const { dbPath: activeDbPath } = getActiveUiTarget(state);
|
|
164
|
+
const saved = saveRulesConfig(activeDbPath, req.body);
|
|
165
|
+
state.layoutCache.clear();
|
|
166
|
+
return res.json(saved);
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
console.error("Error saving rules config:", e);
|
|
170
|
+
return res.status(500).json({ error: "Failed to save rules config" });
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Non-blocking interactive hotkey & signal controller for `chomp ui`.
|
|
3
|
+
*
|
|
4
|
+
* Spawns heavy CLI hotkey operations (`[a]` analyze, `[h]` health) in
|
|
5
|
+
* isolated child processes (`stdio: ["ignore", "inherit", "inherit"]`) so the UI
|
|
6
|
+
* Express server, SSE `/api/status`, and raw-mode keyboard handling (`[q]` / `Ctrl+C`)
|
|
7
|
+
* remain immediately responsive at all times.
|
|
8
|
+
*/
|
|
9
|
+
export interface UiHotkeyControllerOptions {
|
|
10
|
+
url: string;
|
|
11
|
+
dbOption?: string;
|
|
12
|
+
getActiveTarget: () => {
|
|
13
|
+
target: string;
|
|
14
|
+
repoName: string;
|
|
15
|
+
dbPath: string;
|
|
16
|
+
};
|
|
17
|
+
onPrintBanner: () => void;
|
|
18
|
+
onOpenBrowser: (url: string) => void;
|
|
19
|
+
onAfterAnalyze: () => void;
|
|
20
|
+
onShutdown: () => void;
|
|
21
|
+
}
|
|
22
|
+
export interface UiHotkeyController {
|
|
23
|
+
shutdown: () => void;
|
|
24
|
+
killActiveTask: () => void;
|
|
25
|
+
}
|
|
26
|
+
export declare function attachUiInteractiveHotkeys(options: UiHotkeyControllerOptions): UiHotkeyController;
|