@dimassetoid/septum-mcp 0.2.1 → 0.5.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/README.md +46 -45
- package/package.json +8 -6
- package/src/cli/commands/check.ts +41 -26
- package/src/cli/commands/hook.ts +77 -105
- package/src/cli/commands/init.ts +35 -9
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +35 -9
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +15 -51
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +51 -27
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +46 -35
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +299 -178
- package/src/core/boundary/staged-auditor.ts +188 -34
- package/src/core/config/domain-ownership.ts +47 -0
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +82 -54
- package/src/core/config/schema.ts +24 -46
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +326 -543
- package/src/core/database/repositories/domain.repository.ts +48 -4
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -259
- package/src/core/database/repository.ts +138 -24
- package/src/core/database/schema.ts +28 -33
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +269 -0
- package/src/core/discovery/topology-detector.ts +153 -170
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +378 -212
- package/src/core/parser/behavioral-analyzer.ts +26 -22
- package/src/core/parser/boundary-tracker.ts +15 -0
- package/src/core/parser/extractors/base.ts +16 -4
- package/src/core/parser/extractors/csharp.ts +9 -5
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +400 -516
- package/src/core/parser/extractors/elysia-semantic.ts +172 -496
- package/src/core/parser/extractors/express-semantic.ts +195 -398
- package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
- package/src/core/parser/extractors/fastify-semantic.ts +216 -732
- package/src/core/parser/extractors/flask-semantic.ts +92 -388
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +210 -508
- package/src/core/parser/extractors/go.ts +6 -3
- package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
- package/src/core/parser/extractors/hono-semantic.ts +132 -530
- package/src/core/parser/extractors/java.ts +7 -5
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +169 -333
- package/src/core/parser/extractors/manifest-helpers.ts +64 -0
- package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +84 -336
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
- package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
- package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
- package/src/core/parser/extractors/php.ts +17 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +9 -8
- package/src/core/parser/extractors/registry.ts +28 -5
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +10 -7
- package/src/core/parser/extractors/rust.ts +35 -17
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +75 -262
- package/src/core/parser/extractors/typescript-bindings.ts +333 -0
- package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
- package/src/core/parser/extractors/typescript-fallback.ts +207 -0
- package/src/core/parser/extractors/typescript-route-context.ts +58 -0
- package/src/core/parser/extractors/typescript.ts +36 -216
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +23 -7
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
- package/src/core/parser/schema/schema-provider-registry.ts +1 -3
- package/src/core/parser/schema/schema-provider.interface.ts +2 -1
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- package/src/core/parser/wasm-loader.ts +6 -2
- package/src/core/resolver/ast-method-tracer.ts +230 -0
- package/src/core/resolver/call-graph-helpers.ts +72 -0
- package/src/core/resolver/call-graph-tracer.ts +375 -311
- package/src/core/resolver/dependency-analysis.ts +593 -0
- package/src/core/resolver/import-candidates.ts +120 -0
- package/src/core/resolver/import-evidence.ts +88 -0
- package/src/core/resolver/import-resolver.ts +162 -181
- package/src/core/resolver/interpretation-inputs.ts +65 -0
- package/src/core/resolver/languages/go.ts +103 -0
- package/src/core/resolver/languages/managed.ts +200 -0
- package/src/core/resolver/languages/python.ts +133 -0
- package/src/core/resolver/languages/ruby.ts +40 -0
- package/src/core/resolver/languages/rust.ts +127 -0
- package/src/core/resolver/languages/shared.ts +74 -0
- package/src/core/resolver/module-resolver.ts +18 -7
- package/src/core/resolver/path-resolver.ts +6 -3
- package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
- package/src/core/resolver/slice-catalog.ts +94 -0
- package/src/core/resolver/slice-format.ts +22 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +477 -0
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +57 -278
- package/src/core/resources/ignore.ts +21 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +116 -0
- package/src/core/retrieval/context.ts +457 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/source-context.ts +448 -0
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +293 -0
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +225 -37
- package/src/index.ts +0 -3
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +253 -0
- package/src/mcp/schemas/boundary.ts +145 -0
- package/src/mcp/schemas/map.ts +250 -0
- package/src/mcp/schemas/shared.ts +52 -0
- package/src/mcp/schemas/slice.ts +60 -0
- package/src/mcp/schemas/symbol.ts +268 -0
- package/src/mcp/schemas.ts +5 -1105
- package/src/mcp/server.ts +263 -597
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +69 -4
- package/src/mcp/tools/map.ts +126 -0
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +480 -26
- package/src/mcp/ui/app-client.ts +899 -0
- package/src/mcp/ui/app.html +478 -0
- package/src/mcp/workflow-playbooks.ts +181 -0
- package/src/mcp/workspace-boundary.ts +50 -0
- package/src/mcp/workspace-manager.ts +102 -18
- package/src/mcp/workspace-watcher.ts +38 -19
- package/src/types/index.ts +47 -53
- package/src/cli/commands/topology.ts +0 -161
- package/src/core/database/repositories/environment.repository.ts +0 -207
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
- package/src/core/session/session-manager.ts +0 -107
- package/src/core/topology/environment-detector.ts +0 -973
- package/src/core/topology/types.ts +0 -83
- package/src/mcp/tools/check-boundary.ts +0 -387
- package/src/mcp/tools/domain.ts +0 -40
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-domain-catalog.ts +0 -226
- package/src/mcp/tools/get-environment-topology.ts +0 -138
- package/src/mcp/tools/get-feature-context.ts +0 -224
- package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
- package/src/mcp/tools/get-symbol-impact.ts +0 -64
- package/src/mcp/tools/get-symbol.ts +0 -175
- package/src/mcp/tools/locate-symbol.ts +0 -196
- package/src/mcp/tools/register-domain.ts +0 -75
- package/src/mcp/tools/register-feature.ts +0 -110
- package/src/mcp/tools/trace-vertical-slice.ts +0 -80
|
@@ -0,0 +1,899 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import {
|
|
3
|
+
App,
|
|
4
|
+
applyDocumentTheme,
|
|
5
|
+
applyHostStyleVariables,
|
|
6
|
+
} from "@modelcontextprotocol/ext-apps";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { version } from "../../../package.json" with { type: "json" };
|
|
9
|
+
|
|
10
|
+
type AnyRecord = Record<string, any>;
|
|
11
|
+
type TabKind = "map" | "slice" | "boundary";
|
|
12
|
+
|
|
13
|
+
interface WorkspaceViewState {
|
|
14
|
+
map: AnyRecord | null;
|
|
15
|
+
domainDetail: AnyRecord | null;
|
|
16
|
+
slice: AnyRecord | null;
|
|
17
|
+
boundary: AnyRecord | null;
|
|
18
|
+
selectedDomains: Set<string>;
|
|
19
|
+
selectedSliceNodes: Set<string>;
|
|
20
|
+
selectedViolations: Set<string>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const DEFAULT_WORKSPACE_KEY = "__default__";
|
|
24
|
+
const ToggleAuxPaneResultSchema = z.object({ isError: z.boolean().optional() }).passthrough();
|
|
25
|
+
|
|
26
|
+
const TAB_PRESETS: Record<TabKind, ReadonlyArray<{ label: string; prompt: string }>> = {
|
|
27
|
+
map: [
|
|
28
|
+
{ label: "Explain architecture", prompt: "Explain the architecture and responsibilities of these domains." },
|
|
29
|
+
{ label: "Audit domain coupling", prompt: "Audit cross-domain dependencies and highlight tight coupling or risky edges." },
|
|
30
|
+
],
|
|
31
|
+
slice: [
|
|
32
|
+
{ label: "Trace execution flow", prompt: "Trace and explain the step-by-step execution flow of this slice." },
|
|
33
|
+
{ label: "Check bugs / validation", prompt: "Inspect this execution chain for potential bugs, missing validation, or boundary issues." },
|
|
34
|
+
],
|
|
35
|
+
boundary: [
|
|
36
|
+
{ label: "Fix violations", prompt: "Propose and apply clean fixes for these boundary violations without breaking domain rules." },
|
|
37
|
+
{ label: "Explain forbidden rules", prompt: "Explain why these imports violate domain policies and what the intended alternative is." },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const DEFAULT_ASK_PROMPT: Record<TabKind, string> = {
|
|
42
|
+
map: "Analyze this Septum architecture context:",
|
|
43
|
+
slice: "Analyze this Septum execution slice:",
|
|
44
|
+
boundary: "Analyze this Septum boundary audit and suggest remediations:",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const app = new App({ name: "Septum Architecture", version });
|
|
48
|
+
|
|
49
|
+
let currentTab: TabKind = "map";
|
|
50
|
+
let activeWorkspace: string | undefined;
|
|
51
|
+
let pendingWorkspaceRoot: string | undefined;
|
|
52
|
+
const knownWorkspaces: string[] = [];
|
|
53
|
+
const workspaceStates = new Map<string, WorkspaceViewState>();
|
|
54
|
+
let promptDraft = "";
|
|
55
|
+
let lastError: string | null = null;
|
|
56
|
+
let statusMessage = "";
|
|
57
|
+
let loading = false;
|
|
58
|
+
|
|
59
|
+
function esc(value: unknown): string {
|
|
60
|
+
return String(value ?? "")
|
|
61
|
+
.replace(/&/g, "&")
|
|
62
|
+
.replace(/</g, "<")
|
|
63
|
+
.replace(/>/g, ">")
|
|
64
|
+
.replace(/"/g, """)
|
|
65
|
+
.replace(/'/g, "'");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getWorkspaceKey(root?: string): string {
|
|
69
|
+
const trimmed = root?.trim();
|
|
70
|
+
return trimmed || DEFAULT_WORKSPACE_KEY;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function createEmptyWorkspaceState(): WorkspaceViewState {
|
|
74
|
+
return {
|
|
75
|
+
map: null,
|
|
76
|
+
domainDetail: null,
|
|
77
|
+
slice: null,
|
|
78
|
+
boundary: null,
|
|
79
|
+
selectedDomains: new Set<string>(),
|
|
80
|
+
selectedSliceNodes: new Set<string>(),
|
|
81
|
+
selectedViolations: new Set<string>(),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function getWorkspaceState(root?: string): WorkspaceViewState {
|
|
86
|
+
const key = getWorkspaceKey(root);
|
|
87
|
+
let state = workspaceStates.get(key);
|
|
88
|
+
if (!state) {
|
|
89
|
+
state = createEmptyWorkspaceState();
|
|
90
|
+
workspaceStates.set(key, state);
|
|
91
|
+
}
|
|
92
|
+
return state;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function registerWorkspace(root?: string): void {
|
|
96
|
+
const trimmed = root?.trim();
|
|
97
|
+
if (!trimmed) return;
|
|
98
|
+
if (!knownWorkspaces.includes(trimmed)) {
|
|
99
|
+
knownWorkspaces.push(trimmed);
|
|
100
|
+
}
|
|
101
|
+
if (knownWorkspaces.length === 1 && workspaceStates.has(DEFAULT_WORKSPACE_KEY)) {
|
|
102
|
+
const fallback = workspaceStates.get(DEFAULT_WORKSPACE_KEY)!;
|
|
103
|
+
const target = getWorkspaceState(trimmed);
|
|
104
|
+
target.map ??= fallback.map;
|
|
105
|
+
target.domainDetail ??= fallback.domainDetail;
|
|
106
|
+
target.slice ??= fallback.slice;
|
|
107
|
+
target.boundary ??= fallback.boundary;
|
|
108
|
+
workspaceStates.delete(DEFAULT_WORKSPACE_KEY);
|
|
109
|
+
}
|
|
110
|
+
activeWorkspace = trimmed;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function shortWorkspaceLabel(root: string): string {
|
|
114
|
+
const parts = root.replace(/\\/g, "/").split("/").filter(Boolean);
|
|
115
|
+
return parts[parts.length - 1] ?? root;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function applyTheme(ctx: AnyRecord | undefined) {
|
|
119
|
+
if (!ctx) return;
|
|
120
|
+
if (ctx.theme) applyDocumentTheme(ctx.theme);
|
|
121
|
+
if (ctx.styles?.variables) applyHostStyleVariables(ctx.styles.variables);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function setStatus(msg: string) {
|
|
125
|
+
statusMessage = msg;
|
|
126
|
+
const el = document.getElementById("status-bar");
|
|
127
|
+
if (el) el.textContent = loading ? "Loading..." : msg;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function detectPayloadKind(data: AnyRecord): TabKind | null {
|
|
131
|
+
if (!data || typeof data !== "object") return null;
|
|
132
|
+
if (data.schema === "navigation/v1" || Array.isArray(data.domains) || Array.isArray(data.files)) return "map";
|
|
133
|
+
if ("entrypoint" in data || Array.isArray(data.chain)) return "slice";
|
|
134
|
+
if ("scope" in data && ("total_violations" in data || "violations" in data || "status" in data)) return "boundary";
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function ingestToolResult(result: AnyRecord, explicitWorkspace?: string) {
|
|
139
|
+
lastError = null;
|
|
140
|
+
let data: AnyRecord | null = (result?.structuredContent as AnyRecord) ?? null;
|
|
141
|
+
if (!data && Array.isArray(result?.content)) {
|
|
142
|
+
const textBlock = result.content.find((c: AnyRecord) => c?.type === "text" && typeof c.text === "string");
|
|
143
|
+
if (textBlock) {
|
|
144
|
+
try {
|
|
145
|
+
data = JSON.parse(textBlock.text);
|
|
146
|
+
} catch {
|
|
147
|
+
// Text-only response without JSON payload
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!data) {
|
|
152
|
+
if (result?.isError) {
|
|
153
|
+
const msg = result?.content?.[0]?.text ?? "Tool execution failed.";
|
|
154
|
+
lastError = String(msg);
|
|
155
|
+
}
|
|
156
|
+
setStatus("");
|
|
157
|
+
render();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const resolvedRoot =
|
|
162
|
+
typeof data.workspace_root === "string" && data.workspace_root.trim()
|
|
163
|
+
? data.workspace_root.trim()
|
|
164
|
+
: explicitWorkspace ?? pendingWorkspaceRoot ?? activeWorkspace;
|
|
165
|
+
if (resolvedRoot) {
|
|
166
|
+
registerWorkspace(resolvedRoot);
|
|
167
|
+
}
|
|
168
|
+
pendingWorkspaceRoot = undefined;
|
|
169
|
+
|
|
170
|
+
const kind = detectPayloadKind(data);
|
|
171
|
+
const wsState = getWorkspaceState(resolvedRoot ?? activeWorkspace);
|
|
172
|
+
if (kind === "map") {
|
|
173
|
+
if (Array.isArray(data.files) && data.files.length > 0 && !Array.isArray(data.domains)) {
|
|
174
|
+
wsState.domainDetail = data;
|
|
175
|
+
} else {
|
|
176
|
+
wsState.map = data;
|
|
177
|
+
wsState.domainDetail = null;
|
|
178
|
+
wsState.selectedDomains.clear();
|
|
179
|
+
}
|
|
180
|
+
currentTab = "map";
|
|
181
|
+
} else if (kind === "slice") {
|
|
182
|
+
wsState.slice = data;
|
|
183
|
+
wsState.selectedSliceNodes.clear();
|
|
184
|
+
currentTab = "slice";
|
|
185
|
+
} else if (kind === "boundary") {
|
|
186
|
+
wsState.boundary = data;
|
|
187
|
+
wsState.selectedViolations.clear();
|
|
188
|
+
currentTab = "boundary";
|
|
189
|
+
}
|
|
190
|
+
setStatus("");
|
|
191
|
+
render();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function toFileUri(filePath: string): string {
|
|
195
|
+
const norm = filePath.replace(/\\/g, "/");
|
|
196
|
+
return norm.startsWith("/") ? `file://${encodeURI(norm)}` : `file:///${encodeURI(norm)}`;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async function openFileInPane(relOrAbsPath: string) {
|
|
200
|
+
if (!relOrAbsPath) return;
|
|
201
|
+
const fullPath =
|
|
202
|
+
relOrAbsPath.startsWith("/") || !activeWorkspace
|
|
203
|
+
? relOrAbsPath
|
|
204
|
+
: `${activeWorkspace.replace(/\/+$/, "")}/${relOrAbsPath.replace(/^\/+/, "")}`;
|
|
205
|
+
try {
|
|
206
|
+
const res = await app.request(
|
|
207
|
+
{
|
|
208
|
+
method: "com.google.antigravity/toggle-aux-pane",
|
|
209
|
+
params: { tabType: "fileView", uri: toFileUri(fullPath) },
|
|
210
|
+
},
|
|
211
|
+
ToggleAuxPaneResultSchema
|
|
212
|
+
);
|
|
213
|
+
if (res?.isError) {
|
|
214
|
+
setStatus(`Cannot open side pane for ${relOrAbsPath} on this surface.`);
|
|
215
|
+
}
|
|
216
|
+
} catch (err: unknown) {
|
|
217
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
218
|
+
if (msg.includes("-32601")) {
|
|
219
|
+
setStatus(`Side pane navigation is unavailable in this host (${relOrAbsPath}).`);
|
|
220
|
+
} else {
|
|
221
|
+
setStatus(`Open file failed: ${msg}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function sliceNodeKey(node: AnyRecord, idx: number): string {
|
|
227
|
+
return `${idx}:${node.symbol ?? ""}:${node.file ?? ""}:${node.line ?? ""}`;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function violationKey(v: AnyRecord, idx: number): string {
|
|
231
|
+
return `${idx}:${v.rule ?? ""}:${v.file ?? ""}:${v.line ?? ""}`;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function getSelectionCount(tab: TabKind, wsState: WorkspaceViewState): number {
|
|
235
|
+
if (tab === "map") return wsState.selectedDomains.size;
|
|
236
|
+
if (tab === "slice") return wsState.selectedSliceNodes.size;
|
|
237
|
+
return wsState.selectedViolations.size;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function clearSelection(tab: TabKind, wsState: WorkspaceViewState): void {
|
|
241
|
+
if (tab === "map") wsState.selectedDomains.clear();
|
|
242
|
+
else if (tab === "slice") wsState.selectedSliceNodes.clear();
|
|
243
|
+
else wsState.selectedViolations.clear();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function buildCompactContext(tab: TabKind, wsState: WorkspaceViewState): string | null {
|
|
247
|
+
const lines: string[] = [];
|
|
248
|
+
if (activeWorkspace) lines.push(`Workspace: ${activeWorkspace}`);
|
|
249
|
+
|
|
250
|
+
if (tab === "map" && wsState.map) {
|
|
251
|
+
const d = wsState.map;
|
|
252
|
+
const allDomains: AnyRecord[] = d.domains ?? [];
|
|
253
|
+
const selected = wsState.selectedDomains;
|
|
254
|
+
const focusedDomains = selected.size > 0
|
|
255
|
+
? allDomains.filter((dom) => selected.has(String(dom.name)))
|
|
256
|
+
: allDomains;
|
|
257
|
+
|
|
258
|
+
const health = d.health ?? {};
|
|
259
|
+
lines.push(`# Septum Architecture (index=${health.index ?? d.status ?? "unknown"}, coverage=${health.coverage ?? "unknown"}, unresolved=${health.unresolved_imports ?? 0})`);
|
|
260
|
+
|
|
261
|
+
if (wsState.domainDetail) {
|
|
262
|
+
const dd = wsState.domainDetail;
|
|
263
|
+
const files: AnyRecord[] = dd.files ?? [];
|
|
264
|
+
lines.push(`\n## Focused Domain Files (${files.length})`);
|
|
265
|
+
for (const f of files.slice(0, 30)) {
|
|
266
|
+
lines.push(`- ${f.path}${f.archetype ? ` [${f.archetype}]` : ""}`);
|
|
267
|
+
}
|
|
268
|
+
if (files.length > 30) lines.push(`- ... +${files.length - 30} more files`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (focusedDomains.length > 0) {
|
|
272
|
+
lines.push(`\n## Domains (${selected.size > 0 ? `${focusedDomains.length} selected` : focusedDomains.length})`);
|
|
273
|
+
for (const dom of focusedDomains) {
|
|
274
|
+
const allow = dom.allowed_dependencies?.length ? ` allow=[${dom.allowed_dependencies.join(",")}]` : "";
|
|
275
|
+
const forbid = dom.forbidden_dependencies?.length ? ` forbid=[${dom.forbidden_dependencies.join(",")}]` : "";
|
|
276
|
+
lines.push(`- ${dom.name} (${dom.root}, ${dom.file_count ?? 0} files)${allow}${forbid}`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const deps: AnyRecord[] = (d.dependencies ?? []).filter((dep: AnyRecord) =>
|
|
281
|
+
selected.size === 0 || selected.has(String(dep.from)) || selected.has(String(dep.to))
|
|
282
|
+
);
|
|
283
|
+
if (deps.length > 0) {
|
|
284
|
+
lines.push(`\n## Dependencies (${deps.length})`);
|
|
285
|
+
for (const dep of deps.slice(0, 20)) {
|
|
286
|
+
lines.push(`- ${dep.from} -> ${dep.to} (x${dep.count ?? 1})`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const entrypoints: AnyRecord[] = d.entrypoints ?? [];
|
|
291
|
+
if (entrypoints.length > 0 && selected.size === 0) {
|
|
292
|
+
lines.push(`\n## Entrypoints (${entrypoints.length})`);
|
|
293
|
+
for (const ep of entrypoints.slice(0, 15)) {
|
|
294
|
+
lines.push(`- [${ep.method}] ${ep.target} (${ep.file})`);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return lines.join("\n");
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (tab === "slice" && wsState.slice) {
|
|
301
|
+
const s = wsState.slice;
|
|
302
|
+
const ep = s.entrypoint;
|
|
303
|
+
const chain: AnyRecord[] = s.chain ?? [];
|
|
304
|
+
lines.push(`# Septum Slice: ${s.query ?? "entrypoint"} [status=${s.status ?? "unknown"}, confidence=${s.confidence ?? "-"}, style=${s.architecture_style ?? "-"}]`);
|
|
305
|
+
if (ep) {
|
|
306
|
+
lines.push(`Entrypoint: [${ep.method}] ${ep.uri} -> ${ep.controller}::${ep.action} (${ep.file}:${ep.line})`);
|
|
307
|
+
}
|
|
308
|
+
const selected = wsState.selectedSliceNodes;
|
|
309
|
+
const nodes = selected.size > 0
|
|
310
|
+
? chain.filter((n, idx) => selected.has(sliceNodeKey(n, idx)))
|
|
311
|
+
: chain;
|
|
312
|
+
if (nodes.length > 0) {
|
|
313
|
+
lines.push(`\n## Execution Chain (${selected.size > 0 ? `${nodes.length} selected` : nodes.length})`);
|
|
314
|
+
for (const n of nodes.slice(0, 20)) {
|
|
315
|
+
lines.push(`- [${n.stage}] ${n.symbol}${n.file ? ` @ ${n.file}:${n.line ?? ""}` : ""}${n.description ? ` — ${n.description}` : ""}`);
|
|
316
|
+
}
|
|
317
|
+
} else if (s.message) {
|
|
318
|
+
lines.push(s.message);
|
|
319
|
+
}
|
|
320
|
+
return lines.join("\n");
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (tab === "boundary" && wsState.boundary) {
|
|
324
|
+
const b = wsState.boundary;
|
|
325
|
+
const violations: AnyRecord[] = b.violations ?? [];
|
|
326
|
+
const selected = wsState.selectedViolations;
|
|
327
|
+
const focused = selected.size > 0
|
|
328
|
+
? violations.filter((v, idx) => selected.has(violationKey(v, idx)))
|
|
329
|
+
: violations;
|
|
330
|
+
lines.push(`# Septum Boundary Audit [verdict=${b.status}, scope=${b.scope ?? "-"}, violations=${b.total_violations ?? violations.length}, cycles=${b.circular_dependencies_count ?? 0}]`);
|
|
331
|
+
if (focused.length > 0) {
|
|
332
|
+
lines.push(`\n## Violations (${selected.size > 0 ? `${focused.length} selected` : focused.length})`);
|
|
333
|
+
for (const v of focused.slice(0, 20)) {
|
|
334
|
+
lines.push(`- [${v.rule ?? "violation"}] ${v.source_domain} -> ${v.target_domain} @ ${v.file ?? "?"}:${v.line ?? "?"} (${v.message ?? v.target ?? ""})`);
|
|
335
|
+
}
|
|
336
|
+
} else if (b.message) {
|
|
337
|
+
lines.push(b.message);
|
|
338
|
+
}
|
|
339
|
+
return lines.join("\n");
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function sendAiAction(mode: "context" | "message", explicitPrompt?: string) {
|
|
346
|
+
const wsState = getWorkspaceState(activeWorkspace);
|
|
347
|
+
const context = buildCompactContext(currentTab, wsState);
|
|
348
|
+
if (!context) return;
|
|
349
|
+
const caps = app.getHostCapabilities();
|
|
350
|
+
|
|
351
|
+
try {
|
|
352
|
+
if (mode === "context") {
|
|
353
|
+
if (!caps?.updateModelContext) return;
|
|
354
|
+
await app.updateModelContext({ content: [{ type: "text", text: context }] });
|
|
355
|
+
const selCount = getSelectionCount(currentTab, wsState);
|
|
356
|
+
setStatus(selCount > 0 ? `Attached ${selCount} selected item(s) to chat context.` : `Attached ${currentTab} context to chat.`);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
const instruction = (explicitPrompt ?? promptDraft).trim() || DEFAULT_ASK_PROMPT[currentTab];
|
|
361
|
+
const messageText = `${instruction}\n\n${context}`;
|
|
362
|
+
if (caps?.message) {
|
|
363
|
+
await app.sendMessage({ role: "user", content: [{ type: "text", text: messageText }] });
|
|
364
|
+
if (!explicitPrompt && promptDraft.trim()) {
|
|
365
|
+
promptDraft = "";
|
|
366
|
+
const inp = document.getElementById("ai-prompt-input") as HTMLInputElement | null;
|
|
367
|
+
if (inp) inp.value = "";
|
|
368
|
+
}
|
|
369
|
+
setStatus("Sent instruction + Septum context to conversation.");
|
|
370
|
+
} else if (caps?.updateModelContext) {
|
|
371
|
+
await app.updateModelContext({ content: [{ type: "text", text: messageText }] });
|
|
372
|
+
setStatus("Host does not support direct messages; attached to model context instead.");
|
|
373
|
+
}
|
|
374
|
+
} catch (err: unknown) {
|
|
375
|
+
setStatus(err instanceof Error ? err.message : String(err));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
async function inspectDomain(domainName: string) {
|
|
380
|
+
const caps = app.getHostCapabilities();
|
|
381
|
+
if (!caps?.serverTools || !domainName) return;
|
|
382
|
+
loading = true;
|
|
383
|
+
lastError = null;
|
|
384
|
+
render();
|
|
385
|
+
try {
|
|
386
|
+
const res = await app.callServerTool({
|
|
387
|
+
name: "septum_map",
|
|
388
|
+
arguments: {
|
|
389
|
+
action: "catalog",
|
|
390
|
+
domain: domainName,
|
|
391
|
+
detail_level: "compact",
|
|
392
|
+
format: "json",
|
|
393
|
+
...(activeWorkspace ? { workspace_path: activeWorkspace } : {}),
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
ingestToolResult(res as AnyRecord, activeWorkspace);
|
|
397
|
+
} catch (err: unknown) {
|
|
398
|
+
lastError = err instanceof Error ? err.message : String(err);
|
|
399
|
+
} finally {
|
|
400
|
+
loading = false;
|
|
401
|
+
render();
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
async function refreshActiveTab(targetWorkspace = activeWorkspace) {
|
|
406
|
+
const caps = app.getHostCapabilities();
|
|
407
|
+
if (!caps?.serverTools) return;
|
|
408
|
+
if (currentTab === "slice") {
|
|
409
|
+
render();
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
loading = true;
|
|
413
|
+
lastError = null;
|
|
414
|
+
render();
|
|
415
|
+
try {
|
|
416
|
+
if (currentTab === "map") {
|
|
417
|
+
const res = await app.callServerTool({
|
|
418
|
+
name: "septum_map",
|
|
419
|
+
arguments: {
|
|
420
|
+
action: "catalog",
|
|
421
|
+
format: "json",
|
|
422
|
+
...(targetWorkspace ? { workspace_path: targetWorkspace } : {}),
|
|
423
|
+
},
|
|
424
|
+
});
|
|
425
|
+
ingestToolResult(res as AnyRecord, targetWorkspace);
|
|
426
|
+
} else if (currentTab === "boundary") {
|
|
427
|
+
const res = await app.callServerTool({
|
|
428
|
+
name: "septum_boundary",
|
|
429
|
+
arguments: {
|
|
430
|
+
scope: "all",
|
|
431
|
+
format: "json",
|
|
432
|
+
...(targetWorkspace ? { workspace_path: targetWorkspace } : {}),
|
|
433
|
+
},
|
|
434
|
+
});
|
|
435
|
+
ingestToolResult(res as AnyRecord, targetWorkspace);
|
|
436
|
+
}
|
|
437
|
+
} catch (err: unknown) {
|
|
438
|
+
lastError = err instanceof Error ? err.message : String(err);
|
|
439
|
+
} finally {
|
|
440
|
+
loading = false;
|
|
441
|
+
render();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function renderCoverageNotice(d: AnyRecord): string {
|
|
446
|
+
if (d.status === "NOT_INDEXED") {
|
|
447
|
+
return `
|
|
448
|
+
<div class="warn-box">
|
|
449
|
+
<div><strong>Workspace Not Initialized</strong> — ${esc(d.message ?? "Septum has not indexed this workspace yet.")}</div>
|
|
450
|
+
<ul>
|
|
451
|
+
<li>Run <code>septum init</code> in the workspace terminal, or</li>
|
|
452
|
+
<li>Register a domain via <code>septum_map({ action: "register", name: "core", root: "src", ingest_now: true })</code>.</li>
|
|
453
|
+
</ul>
|
|
454
|
+
<div><button type="button" class="mini-btn" id="btn-fix-coverage">Ask AI to Initialize</button></div>
|
|
455
|
+
</div>
|
|
456
|
+
`;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const health = d.health ?? {};
|
|
460
|
+
const reasons: string[] = Array.isArray(health.reasons) ? health.reasons : [];
|
|
461
|
+
const unsupported = Number(health.unsupported_files ?? 0);
|
|
462
|
+
const skipped = Number(health.skipped_files ?? 0);
|
|
463
|
+
const unresolved = Number(health.unresolved_imports ?? 0);
|
|
464
|
+
const syncNeeded = Boolean(health.sync_needed);
|
|
465
|
+
const isPartial =
|
|
466
|
+
health.coverage === "partial" ||
|
|
467
|
+
(health.index && health.index !== "complete") ||
|
|
468
|
+
syncNeeded ||
|
|
469
|
+
unsupported > 0 ||
|
|
470
|
+
skipped > 0 ||
|
|
471
|
+
unresolved > 0;
|
|
472
|
+
|
|
473
|
+
if (!isPartial) return "";
|
|
474
|
+
|
|
475
|
+
const actions: string[] = [];
|
|
476
|
+
if (syncNeeded || (health.index && health.index !== "complete")) {
|
|
477
|
+
actions.push("Run <code>septum sync</code> to refresh stale or incomplete index state.");
|
|
478
|
+
}
|
|
479
|
+
if (skipped > 0) {
|
|
480
|
+
actions.push(`${skipped} file(s) skipped — register missing directories with <code>septum_map(action="register")</code> or review <code>ignore_patterns</code>.`);
|
|
481
|
+
}
|
|
482
|
+
if (unsupported > 0) {
|
|
483
|
+
actions.push(`${unsupported} file(s) use unsupported extensions/languages and are excluded from AST slicing.`);
|
|
484
|
+
}
|
|
485
|
+
if (unresolved > 0) {
|
|
486
|
+
actions.push(`${unresolved} unresolved import(s) — verify path aliases / <code>tsconfig.json</code> or missing packages.`);
|
|
487
|
+
}
|
|
488
|
+
if (actions.length === 0) {
|
|
489
|
+
actions.push("Check <code>septum://apps</code> or run <code>septum sync</code> to inspect coverage details.");
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
return `
|
|
493
|
+
<div class="warn-box">
|
|
494
|
+
<div><strong>Partial Index Coverage</strong>${reasons.length ? ` <span class="badge">${esc(reasons.join(", "))}</span>` : ""}</div>
|
|
495
|
+
<ul>${actions.map((a) => `<li>${a}</li>`).join("")}</ul>
|
|
496
|
+
<div><button type="button" class="mini-btn" id="btn-fix-coverage">Ask AI to Resolve Gaps</button></div>
|
|
497
|
+
</div>
|
|
498
|
+
`;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function renderMap(wsState: WorkspaceViewState, canCallTools: boolean): string {
|
|
502
|
+
const d = wsState.map;
|
|
503
|
+
if (!d) {
|
|
504
|
+
return `<div class="empty">Run <code>septum_map</code> or click Refresh to load the workspace architecture.</div>`;
|
|
505
|
+
}
|
|
506
|
+
const health = d.health ?? {};
|
|
507
|
+
const domains: AnyRecord[] = d.domains ?? [];
|
|
508
|
+
const deps: AnyRecord[] = d.dependencies ?? [];
|
|
509
|
+
const entrypoints: AnyRecord[] = d.entrypoints ?? [];
|
|
510
|
+
const dd = wsState.domainDetail;
|
|
511
|
+
const ddFiles: AnyRecord[] = dd?.files ?? [];
|
|
512
|
+
|
|
513
|
+
return `
|
|
514
|
+
<div class="stats">
|
|
515
|
+
<div class="stat"><span class="label">Index</span><span class="val">${esc(health.index ?? d.status ?? "unknown")}</span></div>
|
|
516
|
+
<div class="stat"><span class="label">Coverage</span><span class="val">${esc(health.coverage ?? "unknown")}</span></div>
|
|
517
|
+
<div class="stat"><span class="label">Domains</span><span class="val">${domains.length}</span></div>
|
|
518
|
+
<div class="stat"><span class="label">Unresolved</span><span class="val">${esc(health.unresolved_imports ?? 0)}</span></div>
|
|
519
|
+
</div>
|
|
520
|
+
${renderCoverageNotice(d)}
|
|
521
|
+
${
|
|
522
|
+
dd
|
|
523
|
+
? `<div class="bar">
|
|
524
|
+
<h3>Domain Files (${ddFiles.length})</h3>
|
|
525
|
+
<button class="mini-btn" id="btn-close-domain">Back to Domains</button>
|
|
526
|
+
</div>
|
|
527
|
+
<div class="list">
|
|
528
|
+
${ddFiles
|
|
529
|
+
.slice(0, 40)
|
|
530
|
+
.map(
|
|
531
|
+
(f) => `
|
|
532
|
+
<div class="row clickable" data-file="${esc(f.path)}">
|
|
533
|
+
<code>${esc(f.path)}</code>
|
|
534
|
+
<span class="badge">${esc(f.archetype ?? "file")}</span>
|
|
535
|
+
</div>`
|
|
536
|
+
)
|
|
537
|
+
.join("")}
|
|
538
|
+
</div>`
|
|
539
|
+
: ""
|
|
540
|
+
}
|
|
541
|
+
${
|
|
542
|
+
domains.length
|
|
543
|
+
? `<h3>Domains</h3>
|
|
544
|
+
<div class="grid">
|
|
545
|
+
${domains
|
|
546
|
+
.map((dom) => {
|
|
547
|
+
const name = String(dom.name ?? "");
|
|
548
|
+
const checked = wsState.selectedDomains.has(name);
|
|
549
|
+
return `
|
|
550
|
+
<div class="card ${checked ? "selected" : ""}">
|
|
551
|
+
<div class="card-title" style="justify-content:space-between">
|
|
552
|
+
<label class="chk-wrap">
|
|
553
|
+
<input type="checkbox" class="chk sel-domain" value="${esc(name)}" ${checked ? "checked" : ""} />
|
|
554
|
+
<span>${esc(name)}</span>
|
|
555
|
+
<span class="badge">${esc(dom.file_count ?? 0)} files</span>
|
|
556
|
+
</label>
|
|
557
|
+
${canCallTools ? `<button class="mini-btn" data-inspect-domain="${esc(name)}">Files</button>` : ""}
|
|
558
|
+
</div>
|
|
559
|
+
<div class="muted">${esc(dom.root)}</div>
|
|
560
|
+
${dom.allowed_dependencies?.length ? `<div class="meta">Allow: ${esc(dom.allowed_dependencies.join(", "))}</div>` : ""}
|
|
561
|
+
${dom.forbidden_dependencies?.length ? `<div class="meta danger">Forbid: ${esc(dom.forbidden_dependencies.join(", "))}</div>` : ""}
|
|
562
|
+
</div>`;
|
|
563
|
+
})
|
|
564
|
+
.join("")}
|
|
565
|
+
</div>`
|
|
566
|
+
: ""
|
|
567
|
+
}
|
|
568
|
+
${
|
|
569
|
+
deps.length
|
|
570
|
+
? `<h3>Dependencies (${deps.length})</h3>
|
|
571
|
+
<div class="list">
|
|
572
|
+
${deps
|
|
573
|
+
.slice(0, 25)
|
|
574
|
+
.map(
|
|
575
|
+
(dep) => `
|
|
576
|
+
<div class="row">
|
|
577
|
+
<span><code>${esc(dep.from)}</code> → <code>${esc(dep.to)}</code></span>
|
|
578
|
+
<span class="badge">${esc(dep.count ?? 1)}</span>
|
|
579
|
+
</div>`
|
|
580
|
+
)
|
|
581
|
+
.join("")}
|
|
582
|
+
</div>`
|
|
583
|
+
: ""
|
|
584
|
+
}
|
|
585
|
+
${
|
|
586
|
+
entrypoints.length
|
|
587
|
+
? `<h3>Entrypoints (${entrypoints.length})</h3>
|
|
588
|
+
<div class="list">
|
|
589
|
+
${entrypoints
|
|
590
|
+
.slice(0, 20)
|
|
591
|
+
.map(
|
|
592
|
+
(ep) => `
|
|
593
|
+
<div class="row clickable" data-file="${esc(ep.file)}">
|
|
594
|
+
<span><span class="badge">${esc(ep.method)}</span> <code>${esc(ep.target)}</code></span>
|
|
595
|
+
<span class="muted">${esc(ep.file)}</span>
|
|
596
|
+
</div>`
|
|
597
|
+
)
|
|
598
|
+
.join("")}
|
|
599
|
+
</div>`
|
|
600
|
+
: ""
|
|
601
|
+
}
|
|
602
|
+
`;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function renderSlice(wsState: WorkspaceViewState): string {
|
|
606
|
+
const s = wsState.slice;
|
|
607
|
+
if (!s) {
|
|
608
|
+
return `<div class="empty">Run <code>septum_slice</code> to inspect an HTTP, GraphQL, or CLI execution chain.</div>`;
|
|
609
|
+
}
|
|
610
|
+
const ep = s.entrypoint;
|
|
611
|
+
const chain: AnyRecord[] = s.chain ?? [];
|
|
612
|
+
return `
|
|
613
|
+
<div class="stats">
|
|
614
|
+
<div class="stat"><span class="label">Status</span><span class="val">${esc(s.status ?? (s.found ? "success" : "not_found"))}</span></div>
|
|
615
|
+
<div class="stat"><span class="label">Confidence</span><span class="val">${esc(s.confidence ?? "-")}</span></div>
|
|
616
|
+
<div class="stat"><span class="label">Style</span><span class="val">${esc(s.architecture_style ?? "-")}</span></div>
|
|
617
|
+
</div>
|
|
618
|
+
${
|
|
619
|
+
ep
|
|
620
|
+
? `<div class="card clickable" data-file="${esc(ep.file)}">
|
|
621
|
+
<div class="card-title"><span class="badge">${esc(ep.method)}</span> ${esc(ep.uri)}</div>
|
|
622
|
+
<div class="muted">${esc(ep.controller)}::${esc(ep.action)} (${esc(ep.file)}:${esc(ep.line)})</div>
|
|
623
|
+
</div>`
|
|
624
|
+
: `<div class="empty">${esc(s.message ?? "No matching slice found.")}</div>`
|
|
625
|
+
}
|
|
626
|
+
${
|
|
627
|
+
chain.length
|
|
628
|
+
? `<h3>Execution Chain (${chain.length})</h3>
|
|
629
|
+
<div class="list">
|
|
630
|
+
${chain
|
|
631
|
+
.map((node, idx) => {
|
|
632
|
+
const key = sliceNodeKey(node, idx);
|
|
633
|
+
const checked = wsState.selectedSliceNodes.has(key);
|
|
634
|
+
return `
|
|
635
|
+
<div class="row ${checked ? "selected" : ""}">
|
|
636
|
+
<div class="chk-wrap">
|
|
637
|
+
<input type="checkbox" class="chk sel-slice" value="${esc(key)}" ${checked ? "checked" : ""} />
|
|
638
|
+
<div class="${node.file ? "clickable" : ""}" data-file="${esc(node.file ?? "")}">
|
|
639
|
+
<span class="badge">${esc(node.stage)}</span>
|
|
640
|
+
<strong>${esc(node.symbol)}</strong>
|
|
641
|
+
<div class="muted">${esc(node.description ?? "")}</div>
|
|
642
|
+
</div>
|
|
643
|
+
</div>
|
|
644
|
+
<span class="muted ${node.file ? "clickable" : ""}" data-file="${esc(node.file ?? "")}">${node.file ? `${esc(node.file)}:${esc(node.line ?? "")}` : esc(node.relationship?.derivation ?? "")}</span>
|
|
645
|
+
</div>`;
|
|
646
|
+
})
|
|
647
|
+
.join("")}
|
|
648
|
+
</div>`
|
|
649
|
+
: ""
|
|
650
|
+
}
|
|
651
|
+
`;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function renderBoundary(wsState: WorkspaceViewState): string {
|
|
655
|
+
const b = wsState.boundary;
|
|
656
|
+
if (!b) {
|
|
657
|
+
return `<div class="empty">Run <code>septum_boundary</code> or click Refresh to audit domain boundaries.</div>`;
|
|
658
|
+
}
|
|
659
|
+
const violations: AnyRecord[] = b.violations ?? [];
|
|
660
|
+
const statusClass = b.status === "approved" ? "ok" : b.status === "rejected" ? "danger" : "warn";
|
|
661
|
+
return `
|
|
662
|
+
<div class="stats">
|
|
663
|
+
<div class="stat"><span class="label">Verdict</span><span class="val ${statusClass}">${esc(b.status)}</span></div>
|
|
664
|
+
<div class="stat"><span class="label">Scope</span><span class="val">${esc(b.scope ?? "-")}</span></div>
|
|
665
|
+
<div class="stat"><span class="label">Violations</span><span class="val">${esc(b.total_violations ?? violations.length)}</span></div>
|
|
666
|
+
<div class="stat"><span class="label">Cycles</span><span class="val">${esc(b.circular_dependencies_count ?? 0)}</span></div>
|
|
667
|
+
</div>
|
|
668
|
+
<p class="muted">${esc(b.message ?? "")}</p>
|
|
669
|
+
${
|
|
670
|
+
violations.length
|
|
671
|
+
? `<h3>Violations (${violations.length})</h3>
|
|
672
|
+
<div class="list">
|
|
673
|
+
${violations
|
|
674
|
+
.slice(0, 25)
|
|
675
|
+
.map((v, idx) => {
|
|
676
|
+
const key = violationKey(v, idx);
|
|
677
|
+
const checked = wsState.selectedViolations.has(key);
|
|
678
|
+
return `
|
|
679
|
+
<div class="row ${checked ? "selected" : ""}">
|
|
680
|
+
<div class="chk-wrap">
|
|
681
|
+
<input type="checkbox" class="chk sel-violation" value="${esc(key)}" ${checked ? "checked" : ""} />
|
|
682
|
+
<div class="${v.file ? "clickable" : ""}" data-file="${esc(v.file ?? "")}">
|
|
683
|
+
<span class="badge danger">${esc(v.rule ?? "violation")}</span>
|
|
684
|
+
<code>${esc(v.source_domain)}</code> → <code>${esc(v.target_domain)}</code>
|
|
685
|
+
<div class="muted">${esc(v.message ?? v.target ?? "")}</div>
|
|
686
|
+
</div>
|
|
687
|
+
</div>
|
|
688
|
+
<span class="muted ${v.file ? "clickable" : ""}" data-file="${esc(v.file ?? "")}">${esc(v.file ?? "")}:${esc(v.line ?? "")}</span>
|
|
689
|
+
</div>`;
|
|
690
|
+
})
|
|
691
|
+
.join("")}
|
|
692
|
+
</div>`
|
|
693
|
+
: ""
|
|
694
|
+
}
|
|
695
|
+
`;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function renderWorkspaceBadge(): string {
|
|
699
|
+
if (knownWorkspaces.length > 1) {
|
|
700
|
+
return `<select id="workspace-select" class="scope-select" title="${esc(activeWorkspace ?? "")}">
|
|
701
|
+
${knownWorkspaces
|
|
702
|
+
.map(
|
|
703
|
+
(ws) =>
|
|
704
|
+
`<option value="${esc(ws)}" ${ws === activeWorkspace ? "selected" : ""}>${esc(shortWorkspaceLabel(ws))}</option>`
|
|
705
|
+
)
|
|
706
|
+
.join("")}
|
|
707
|
+
</select>`;
|
|
708
|
+
}
|
|
709
|
+
if (activeWorkspace) {
|
|
710
|
+
return `<span class="scope-pill" title="${esc(activeWorkspace)}">${esc(shortWorkspaceLabel(activeWorkspace))}</span>`;
|
|
711
|
+
}
|
|
712
|
+
return "";
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function renderAiBar(wsState: WorkspaceViewState, canMessage: boolean, canUpdateCtx: boolean): string {
|
|
716
|
+
if (!canMessage && !canUpdateCtx) return "";
|
|
717
|
+
const selCount = getSelectionCount(currentTab, wsState);
|
|
718
|
+
const presets = TAB_PRESETS[currentTab];
|
|
719
|
+
return `
|
|
720
|
+
<section class="ai-bar">
|
|
721
|
+
<div class="preset-row">
|
|
722
|
+
<span class="muted">${selCount > 0 ? `${selCount} selected` : `All ${currentTab}`}</span>
|
|
723
|
+
${selCount > 0 ? `<button type="button" class="mini-btn" id="btn-clear-sel">Clear</button>` : ""}
|
|
724
|
+
${presets
|
|
725
|
+
.map((p, i) => `<button type="button" class="chip" data-preset="${i}">${esc(p.label)}</button>`)
|
|
726
|
+
.join("")}
|
|
727
|
+
</div>
|
|
728
|
+
<form id="ai-prompt-form" class="prompt-form">
|
|
729
|
+
<input id="ai-prompt-input" class="prompt-input" type="text" placeholder="Instruct AI about ${esc(selCount > 0 ? `${selCount} selected item(s)` : `this ${currentTab}`)}..." value="${esc(promptDraft)}" />
|
|
730
|
+
${canUpdateCtx ? `<button type="button" class="btn" id="btn-attach">Attach Context</button>` : ""}
|
|
731
|
+
${canMessage ? `<button type="submit" class="btn primary-btn" id="btn-ask-ai">Ask AI</button>` : ""}
|
|
732
|
+
</form>
|
|
733
|
+
</section>
|
|
734
|
+
`;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function render() {
|
|
738
|
+
const root = document.getElementById("root");
|
|
739
|
+
if (!root) return;
|
|
740
|
+
const caps = app.getHostCapabilities();
|
|
741
|
+
const canCallTools = Boolean(caps?.serverTools);
|
|
742
|
+
const canUpdateCtx = Boolean(caps?.updateModelContext);
|
|
743
|
+
const canMessage = Boolean(caps?.message);
|
|
744
|
+
|
|
745
|
+
const wsState = getWorkspaceState(activeWorkspace);
|
|
746
|
+
const hasActivePayload = Boolean(wsState[currentTab]);
|
|
747
|
+
const body =
|
|
748
|
+
currentTab === "map"
|
|
749
|
+
? renderMap(wsState, canCallTools)
|
|
750
|
+
: currentTab === "slice"
|
|
751
|
+
? renderSlice(wsState)
|
|
752
|
+
: renderBoundary(wsState);
|
|
753
|
+
|
|
754
|
+
root.innerHTML = `
|
|
755
|
+
<div class="shell">
|
|
756
|
+
<header class="bar">
|
|
757
|
+
<div class="brand">
|
|
758
|
+
<div class="tabs">
|
|
759
|
+
<button class="tab ${currentTab === "map" ? "active" : ""}" data-tab="map">Architecture</button>
|
|
760
|
+
<button class="tab ${currentTab === "slice" ? "active" : ""}" data-tab="slice">Slice</button>
|
|
761
|
+
<button class="tab ${currentTab === "boundary" ? "active" : ""}" data-tab="boundary">Boundary</button>
|
|
762
|
+
</div>
|
|
763
|
+
${renderWorkspaceBadge()}
|
|
764
|
+
</div>
|
|
765
|
+
<div class="actions">
|
|
766
|
+
${canCallTools && currentTab !== "slice" ? `<button class="btn" id="btn-refresh">Refresh</button>` : ""}
|
|
767
|
+
</div>
|
|
768
|
+
</header>
|
|
769
|
+
${hasActivePayload ? renderAiBar(wsState, canMessage, canUpdateCtx) : ""}
|
|
770
|
+
<div id="status-bar" class="status-bar">${loading ? "Loading..." : esc(statusMessage)}</div>
|
|
771
|
+
${lastError ? `<div class="alert">${esc(lastError)}</div>` : ""}
|
|
772
|
+
<main>${body}</main>
|
|
773
|
+
</div>
|
|
774
|
+
`;
|
|
775
|
+
|
|
776
|
+
root.querySelectorAll<HTMLButtonElement>("[data-tab]").forEach((btn) => {
|
|
777
|
+
btn.onclick = () => {
|
|
778
|
+
const next = btn.dataset.tab as TabKind;
|
|
779
|
+
currentTab = next;
|
|
780
|
+
const curState = getWorkspaceState(activeWorkspace);
|
|
781
|
+
if ((next === "boundary" || next === "map") && !curState[next] && canCallTools) {
|
|
782
|
+
void refreshActiveTab(activeWorkspace);
|
|
783
|
+
} else {
|
|
784
|
+
render();
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
const wsSelect = document.getElementById("workspace-select") as HTMLSelectElement | null;
|
|
790
|
+
if (wsSelect) {
|
|
791
|
+
wsSelect.onchange = () => {
|
|
792
|
+
activeWorkspace = wsSelect.value;
|
|
793
|
+
const nextState = getWorkspaceState(activeWorkspace);
|
|
794
|
+
if ((currentTab === "map" || currentTab === "boundary") && !nextState[currentTab] && canCallTools) {
|
|
795
|
+
void refreshActiveTab(activeWorkspace);
|
|
796
|
+
} else {
|
|
797
|
+
render();
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
root.querySelectorAll<HTMLInputElement>(".sel-domain").forEach((chk) => {
|
|
803
|
+
chk.onchange = () => {
|
|
804
|
+
if (chk.checked) wsState.selectedDomains.add(chk.value);
|
|
805
|
+
else wsState.selectedDomains.delete(chk.value);
|
|
806
|
+
render();
|
|
807
|
+
};
|
|
808
|
+
});
|
|
809
|
+
root.querySelectorAll<HTMLInputElement>(".sel-slice").forEach((chk) => {
|
|
810
|
+
chk.onchange = () => {
|
|
811
|
+
if (chk.checked) wsState.selectedSliceNodes.add(chk.value);
|
|
812
|
+
else wsState.selectedSliceNodes.delete(chk.value);
|
|
813
|
+
render();
|
|
814
|
+
};
|
|
815
|
+
});
|
|
816
|
+
root.querySelectorAll<HTMLInputElement>(".sel-violation").forEach((chk) => {
|
|
817
|
+
chk.onchange = () => {
|
|
818
|
+
if (chk.checked) wsState.selectedViolations.add(chk.value);
|
|
819
|
+
else wsState.selectedViolations.delete(chk.value);
|
|
820
|
+
render();
|
|
821
|
+
};
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
root.querySelectorAll<HTMLButtonElement>("[data-inspect-domain]").forEach((btn) => {
|
|
825
|
+
btn.onclick = () => {
|
|
826
|
+
const dom = btn.dataset.inspectDomain;
|
|
827
|
+
if (dom) void inspectDomain(dom);
|
|
828
|
+
};
|
|
829
|
+
});
|
|
830
|
+
document.getElementById("btn-close-domain")?.addEventListener("click", () => {
|
|
831
|
+
wsState.domainDetail = null;
|
|
832
|
+
render();
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
root.querySelectorAll<HTMLElement>(".clickable[data-file]").forEach((el) => {
|
|
836
|
+
el.onclick = () => {
|
|
837
|
+
const file = el.dataset.file;
|
|
838
|
+
if (file) void openFileInPane(file);
|
|
839
|
+
};
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
const promptInput = document.getElementById("ai-prompt-input") as HTMLInputElement | null;
|
|
843
|
+
if (promptInput) {
|
|
844
|
+
promptInput.oninput = () => {
|
|
845
|
+
promptDraft = promptInput.value;
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
document.getElementById("ai-prompt-form")?.addEventListener("submit", (e) => {
|
|
849
|
+
e.preventDefault();
|
|
850
|
+
void sendAiAction("message");
|
|
851
|
+
});
|
|
852
|
+
root.querySelectorAll<HTMLButtonElement>("[data-preset]").forEach((btn) => {
|
|
853
|
+
btn.onclick = () => {
|
|
854
|
+
const idx = Number(btn.dataset.preset);
|
|
855
|
+
const preset = TAB_PRESETS[currentTab][idx];
|
|
856
|
+
if (preset) void sendAiAction("message", preset.prompt);
|
|
857
|
+
};
|
|
858
|
+
});
|
|
859
|
+
document.getElementById("btn-clear-sel")?.addEventListener("click", () => {
|
|
860
|
+
clearSelection(currentTab, wsState);
|
|
861
|
+
render();
|
|
862
|
+
});
|
|
863
|
+
document.getElementById("btn-refresh")?.addEventListener("click", () => void refreshActiveTab(activeWorkspace));
|
|
864
|
+
document.getElementById("btn-attach")?.addEventListener("click", () => void sendAiAction("context"));
|
|
865
|
+
document.getElementById("btn-fix-coverage")?.addEventListener("click", () => {
|
|
866
|
+
const prompt = wsState.map?.status === "NOT_INDEXED"
|
|
867
|
+
? "Initialize or register Septum domains for this workspace so architecture coverage becomes complete."
|
|
868
|
+
: "Inspect the partial index coverage diagnostics (skipped/unsupported files, unresolved imports, or dirty state) and guide or apply the appropriate fix.";
|
|
869
|
+
void sendAiAction("message", prompt);
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
app.ontoolinput = ({ arguments: args }: AnyRecord) => {
|
|
874
|
+
if (args && typeof args.workspace_path === "string" && args.workspace_path.trim()) {
|
|
875
|
+
pendingWorkspaceRoot = args.workspace_path.trim();
|
|
876
|
+
}
|
|
877
|
+
setStatus("Running Septum analysis...");
|
|
878
|
+
};
|
|
879
|
+
|
|
880
|
+
app.ontoolresult = (result: AnyRecord) => {
|
|
881
|
+
ingestToolResult(result);
|
|
882
|
+
};
|
|
883
|
+
|
|
884
|
+
app.onhostcontextchanged = (ctx: AnyRecord) => {
|
|
885
|
+
applyTheme(ctx);
|
|
886
|
+
};
|
|
887
|
+
|
|
888
|
+
async function boot() {
|
|
889
|
+
render();
|
|
890
|
+
try {
|
|
891
|
+
await app.connect();
|
|
892
|
+
applyTheme(app.getHostContext() as AnyRecord | undefined);
|
|
893
|
+
} catch (err) {
|
|
894
|
+
lastError = err instanceof Error ? err.message : String(err);
|
|
895
|
+
render();
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
void boot();
|