@dimassetoid/septum-mcp 0.3.0 → 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 +38 -55
- package/package.json +7 -5
- package/src/cli/commands/check.ts +14 -10
- package/src/cli/commands/hook.ts +41 -6
- package/src/cli/commands/init.ts +10 -1
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +32 -4
- package/src/cli/index.ts +7 -0
- package/src/cli/templates/hooks.ts +3 -14
- package/src/cli/templates/skill.ts +17 -10
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +251 -114
- package/src/core/boundary/staged-auditor.ts +147 -55
- package/src/core/config/domain-ownership.ts +6 -4
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +1 -25
- package/src/core/config/schema.ts +24 -36
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +334 -572
- package/src/core/database/repositories/domain.repository.ts +2 -1
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -398
- package/src/core/database/repository.ts +68 -9
- package/src/core/database/schema.ts +26 -0
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +222 -58
- package/src/core/discovery/topology-detector.ts +93 -168
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +287 -88
- package/src/core/parser/extractors/base.ts +11 -3
- package/src/core/parser/extractors/csharp.ts +2 -2
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +397 -481
- package/src/core/parser/extractors/elysia-semantic.ts +172 -475
- package/src/core/parser/extractors/express-semantic.ts +195 -383
- package/src/core/parser/extractors/fastapi-semantic.ts +178 -361
- package/src/core/parser/extractors/fastify-semantic.ts +216 -717
- package/src/core/parser/extractors/flask-semantic.ts +89 -352
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +205 -562
- 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 -509
- package/src/core/parser/extractors/java.ts +2 -2
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +143 -335
- 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 +82 -333
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -494
- 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 +1 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +5 -9
- package/src/core/parser/extractors/registry.ts +2 -0
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +2 -2
- package/src/core/parser/extractors/rust.ts +4 -4
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +72 -226
- 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 +23 -216
- package/src/core/parser/language-capabilities.ts +1 -1
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +4 -1
- 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 +169 -414
- 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 +60 -7
- package/src/core/resolver/interpretation-inputs.ts +60 -2
- package/src/core/resolver/languages/python.ts +31 -13
- package/src/core/resolver/languages/shared.ts +4 -1
- package/src/core/resolver/module-resolver.ts +10 -3
- 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 +21 -6
- package/src/core/resolver/slice-format.ts +13 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +104 -8
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +31 -230
- package/src/core/resources/ignore.ts +0 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +11 -4
- package/src/core/retrieval/context.ts +363 -226
- package/src/{mcp/tools/get-symbol.ts → core/retrieval/source-context.ts} +145 -96
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +3 -3
- package/src/core/retrieval/typescript-references.ts +38 -7
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +192 -49
- 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 -746
- package/src/mcp/server.ts +269 -429
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +68 -3
- package/src/mcp/tools/map.ts +104 -4
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +469 -17
- 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 +88 -15
- package/src/mcp/workspace-watcher.ts +30 -11
- package/src/types/index.ts +12 -0
- package/src/mcp/tools/check-boundary.ts +0 -382
- package/src/mcp/tools/get-domain-catalog.ts +0 -39
- package/src/mcp/tools/get-symbol-impact.ts +0 -104
- package/src/mcp/tools/locate-symbol.ts +0 -236
- package/src/mcp/tools/register-domain.ts +0 -113
- package/src/mcp/tools/trace-vertical-slice.ts +0 -106
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
-
import { isAbsolute, join } from "node:path";
|
|
3
|
-
import { isIgnoredDirectory } from "../../core/resources/ignore.ts";
|
|
4
|
-
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
5
|
-
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
6
|
-
import type { IngestionPipeline } from "../../core/ingestion/pipeline.ts";
|
|
7
|
-
import {
|
|
8
|
-
SymbolLocator,
|
|
9
|
-
type SymbolLocationResult,
|
|
10
|
-
} from "../../core/resolver/symbol-locator.ts";
|
|
11
|
-
import type { LocateSymbolArgs } from "../schemas.ts";
|
|
12
|
-
import { symbolWorkspace, withSymbolEvidence } from "../../core/retrieval/symbol-evidence.ts";
|
|
13
|
-
|
|
14
|
-
export type { LocateSymbolArgs } from "../schemas.ts";
|
|
15
|
-
|
|
16
|
-
export async function handleLocateSymbol(
|
|
17
|
-
repo: SeptumRepository,
|
|
18
|
-
config: ValidatedSeptumConfig,
|
|
19
|
-
args: Partial<LocateSymbolArgs>,
|
|
20
|
-
pipeline?: IngestionPipeline,
|
|
21
|
-
workspaceRoot?: string
|
|
22
|
-
) {
|
|
23
|
-
const query = (args.query || args.symbol || args.symbol_ref?.name || "").toString().trim();
|
|
24
|
-
const root = symbolWorkspace(repo, workspaceRoot || args.workspace_path);
|
|
25
|
-
const diagnostics: string[] = [];
|
|
26
|
-
const limit = args.limit ?? 10;
|
|
27
|
-
|
|
28
|
-
if (!query) {
|
|
29
|
-
if (args.file_path) {
|
|
30
|
-
const normalizedPath = args.file_path.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
31
|
-
const file = repo.getFileByPath(normalizedPath);
|
|
32
|
-
const allSymbols = file ? repo.getSymbolsByFileId(file.id) : [];
|
|
33
|
-
const sliced = allSymbols.slice(0, limit).map((s) => ({
|
|
34
|
-
name: s.name,
|
|
35
|
-
file_path: normalizedPath,
|
|
36
|
-
kind: s.kind,
|
|
37
|
-
signature: s.signature,
|
|
38
|
-
start_line: s.line_start,
|
|
39
|
-
end_line: s.line_end,
|
|
40
|
-
}));
|
|
41
|
-
const filePayload = {
|
|
42
|
-
status: sliced.length > 0 ? "success" : "not_found",
|
|
43
|
-
found: sliced.length > 0,
|
|
44
|
-
query: null,
|
|
45
|
-
file_path: normalizedPath,
|
|
46
|
-
candidates: sliced,
|
|
47
|
-
total_candidates: allSymbols.length,
|
|
48
|
-
omitted_candidates: Math.max(0, allSymbols.length - sliced.length),
|
|
49
|
-
summary: sliced.length > 0
|
|
50
|
-
? `[FOUND] Listed ${sliced.length} of ${allSymbols.length} declarations in ${normalizedPath}.`
|
|
51
|
-
: `[NOT FOUND] No indexed declarations found in '${normalizedPath}'.`,
|
|
52
|
-
};
|
|
53
|
-
return withSymbolEvidence(repo, root, { operation: "locate", requested: args.symbol_ref, diagnostics }, () => ({
|
|
54
|
-
content: [{ type: "text" as const, text: JSON.stringify(filePayload, null, 2) }],
|
|
55
|
-
metadata: filePayload,
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
throw new Error(
|
|
59
|
-
"Missing required argument: 'query' (e.g. 'OrderController::calculateTotal' or error log snippet)"
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// 1. Guarded Lazy Ingestion on Empty Catalog / Cold Start
|
|
64
|
-
if (repo.countFiles() === 0 && pipeline) {
|
|
65
|
-
try {
|
|
66
|
-
await pipeline.run(config);
|
|
67
|
-
} catch {
|
|
68
|
-
diagnostics.push("initial_index_refresh_failed");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (repo.countFiles() === 0) {
|
|
72
|
-
const diagnostic = {
|
|
73
|
-
status: "NOT_INDEXED",
|
|
74
|
-
found: false,
|
|
75
|
-
query,
|
|
76
|
-
message: `Workspace '${root}' belum terindeks dalam Septum catalog.`,
|
|
77
|
-
suggested_action: {
|
|
78
|
-
tool: "septum_map",
|
|
79
|
-
params: { action: "register", name: "core", root: "src", ingest_now: true },
|
|
80
|
-
},
|
|
81
|
-
agent_guidance:
|
|
82
|
-
"Panggil tool 'septum_map(action: \"register\", name: \"core\", root: \"src\", ingest_now: true)' untuk mendaftarkan dan mengindeks codebase ini, atau jalankan 'septum init' di terminal workspace.",
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return withSymbolEvidence(repo, root, { operation: "locate", requested: args.symbol_ref, diagnostics }, () => ({
|
|
86
|
-
content: [
|
|
87
|
-
{
|
|
88
|
-
type: "text",
|
|
89
|
-
text: JSON.stringify(diagnostic, null, 2),
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
metadata: diagnostic,
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const locator = new SymbolLocator(repo);
|
|
98
|
-
let result: SymbolLocationResult = locator.locate(query, args.domain, { filePath: args.file_path, reference: args.symbol_ref });
|
|
99
|
-
|
|
100
|
-
// 2. JIT Delta Sync: Check if located file has changed on disk since last ingest
|
|
101
|
-
if (result.found && result.file_path && pipeline) {
|
|
102
|
-
const fullPath = isAbsolute(result.file_path)
|
|
103
|
-
? result.file_path
|
|
104
|
-
: join(root, result.file_path);
|
|
105
|
-
try {
|
|
106
|
-
const reindexed = await pipeline.ingestFile(fullPath, config);
|
|
107
|
-
if (reindexed) {
|
|
108
|
-
result = locator.locate(query, args.domain, { filePath: args.file_path, reference: args.symbol_ref });
|
|
109
|
-
}
|
|
110
|
-
} catch {
|
|
111
|
-
diagnostics.push("target_index_refresh_failed");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// 3. Fallback on Cache Miss: Search for candidate source files matching the query terms
|
|
116
|
-
if (!result.found && pipeline) {
|
|
117
|
-
try {
|
|
118
|
-
const cleanTerm = query.replace(/[^a-zA-Z0-9_]/g, " ").trim().split(/\s+/)[0] || "";
|
|
119
|
-
if (cleanTerm.length >= 3) {
|
|
120
|
-
const candidateFiles = findCandidateFiles(root, cleanTerm);
|
|
121
|
-
let anyReindexed = false;
|
|
122
|
-
for (const candidate of candidateFiles) {
|
|
123
|
-
const reindexed = await pipeline.ingestFile(candidate, config);
|
|
124
|
-
if (reindexed) anyReindexed = true;
|
|
125
|
-
}
|
|
126
|
-
if (anyReindexed) {
|
|
127
|
-
result = locator.locate(query, args.domain, { filePath: args.file_path, reference: args.symbol_ref });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
} catch {
|
|
131
|
-
diagnostics.push("candidate_refresh_failed");
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const exactLineCount = result.exact_symbol
|
|
136
|
-
? result.exact_symbol.line_end - result.exact_symbol.line_start + 1
|
|
137
|
-
: 0;
|
|
138
|
-
const complexitySmell =
|
|
139
|
-
exactLineCount > 300
|
|
140
|
-
? {
|
|
141
|
-
is_high_complexity: true,
|
|
142
|
-
threshold: 300,
|
|
143
|
-
total_lines: exactLineCount,
|
|
144
|
-
warning: `Symbol '${result.exact_symbol?.name}' spans ${exactLineCount} lines (exceeds 300-line threshold). Candidate for decomposition/refactoring.`,
|
|
145
|
-
}
|
|
146
|
-
: undefined;
|
|
147
|
-
|
|
148
|
-
const suggestions = (result.suggestions || []).slice(0, limit);
|
|
149
|
-
let summary = result.status === "ambiguous"
|
|
150
|
-
? `[AMBIGUOUS] Multiple declarations match '${query}'; select a candidate with symbol_ref or file_path.`
|
|
151
|
-
: result.status === "stale_reference"
|
|
152
|
-
? `[STALE REFERENCE] Locate '${query}' again before using its indexed coordinates.`
|
|
153
|
-
: result.found
|
|
154
|
-
? `[FOUND] ${result.exact_symbol?.name || query} in ${result.file_path} (lines ${result.exact_symbol?.line_start}-${result.exact_symbol?.line_end})`
|
|
155
|
-
: `[NOT FOUND] Symbol '${query}' not found. ${suggestions.length > 0 ? `Top suggestions: ${suggestions.map((s) => s.name).slice(0, 3).join(", ")}` : "No close suggestions."}`;
|
|
156
|
-
|
|
157
|
-
if (complexitySmell) {
|
|
158
|
-
summary += ` | ⚠️ High-Complexity Smell: spans ${exactLineCount} lines (> 300L)`;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const allCandidates = result.candidates || [];
|
|
162
|
-
const boundedCandidates = allCandidates.slice(0, limit);
|
|
163
|
-
const payload = {
|
|
164
|
-
status: result.status ?? (result.found ? "success" : "not_found"),
|
|
165
|
-
candidates: result.candidates ? boundedCandidates : undefined,
|
|
166
|
-
...(allCandidates.length > boundedCandidates.length
|
|
167
|
-
? { total_candidates: allCandidates.length, omitted_candidates: allCandidates.length - boundedCandidates.length }
|
|
168
|
-
: {}),
|
|
169
|
-
symbol_ref: result.symbol_ref,
|
|
170
|
-
visibility_semantics: "legacy_normalized",
|
|
171
|
-
found: result.found,
|
|
172
|
-
query,
|
|
173
|
-
file_path: result.file_path || null,
|
|
174
|
-
container_name: result.container_name || null,
|
|
175
|
-
exact_symbol: result.exact_symbol
|
|
176
|
-
? {
|
|
177
|
-
...result.exact_symbol,
|
|
178
|
-
total_lines: exactLineCount,
|
|
179
|
-
}
|
|
180
|
-
: null,
|
|
181
|
-
complexity_smell: complexitySmell,
|
|
182
|
-
sibling_methods: result.sibling_methods || [],
|
|
183
|
-
suggestions,
|
|
184
|
-
summary,
|
|
185
|
-
message: result.message || summary,
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
return withSymbolEvidence(repo, root, { operation: "locate", requested: args.symbol_ref, diagnostics }, () => ({
|
|
189
|
-
content: [
|
|
190
|
-
{
|
|
191
|
-
type: "text" as const,
|
|
192
|
-
text: JSON.stringify(payload, null, 2),
|
|
193
|
-
},
|
|
194
|
-
],
|
|
195
|
-
metadata: payload,
|
|
196
|
-
}));
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Searches for potential candidate files whose names resemble parts of the query term.
|
|
201
|
-
*/
|
|
202
|
-
function findCandidateFiles(root: string, term: string): string[] {
|
|
203
|
-
const matched: string[] = [];
|
|
204
|
-
const lowerTerm = term.toLowerCase().replace(/_/g, "");
|
|
205
|
-
const searchDirs = ["src", "app", "lib"].map((d) => join(root, d)).filter((d) => existsSync(d));
|
|
206
|
-
|
|
207
|
-
function scan(dir: string, depth: number = 0) {
|
|
208
|
-
if (depth > 4) return;
|
|
209
|
-
try {
|
|
210
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
211
|
-
for (const e of entries) {
|
|
212
|
-
if (isIgnoredDirectory(e.name)) continue;
|
|
213
|
-
const full = join(dir, e.name);
|
|
214
|
-
if (e.isDirectory()) {
|
|
215
|
-
scan(full, depth + 1);
|
|
216
|
-
} else if (e.isFile() && /\.(ts|tsx|js|jsx|php|py|go)$/i.test(e.name)) {
|
|
217
|
-
const lowerName = e.name.toLowerCase().replace(/[-_.]/g, "");
|
|
218
|
-
if (lowerName.includes(lowerTerm) || lowerTerm.includes(lowerName.replace(/\.[^.]+$/, ""))) {
|
|
219
|
-
matched.push(full);
|
|
220
|
-
if (matched.length >= 5) return;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
} catch {
|
|
225
|
-
// Ignore
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
for (const sDir of searchDirs) {
|
|
230
|
-
scan(sDir);
|
|
231
|
-
if (matched.length >= 5) break;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return matched;
|
|
235
|
-
}
|
|
236
|
-
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
2
|
-
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
3
|
-
import { IngestionPipeline, type IngestionMetrics } from "../../core/ingestion/pipeline.ts";
|
|
4
|
-
import { assertPathContained } from "../../core/resolver/path-resolver.ts";
|
|
5
|
-
import { assertUniqueDomainRoots, domainNameKey, domainRootIdentity } from "../../core/config/domain-ownership.ts";
|
|
6
|
-
import type { RegisterDomainArgs } from "../schemas.ts";
|
|
7
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { ConfigLoader } from "../../core/config/loader.ts";
|
|
10
|
-
import { SeptumConfigSchema } from "../../core/config/schema.ts";
|
|
11
|
-
|
|
12
|
-
export type { RegisterDomainArgs } from "../schemas.ts";
|
|
13
|
-
|
|
14
|
-
export async function handleRegisterDomain(
|
|
15
|
-
repo: SeptumRepository,
|
|
16
|
-
config: ValidatedSeptumConfig,
|
|
17
|
-
args: Partial<RegisterDomainArgs>,
|
|
18
|
-
workspaceRoot: string = process.cwd(),
|
|
19
|
-
signal?: AbortSignal
|
|
20
|
-
) {
|
|
21
|
-
signal?.throwIfAborted();
|
|
22
|
-
const domainName = (args.domain || args.name || "").trim();
|
|
23
|
-
if (!domainName || !args.root) {
|
|
24
|
-
throw new Error("Missing required arguments: 'domain' (or 'name') and 'root' are required.");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// SV-02: Enforce workspace containment (reject traversal/absolute/symlink escape)
|
|
28
|
-
assertPathContained(args.root, workspaceRoot, "Domain root");
|
|
29
|
-
signal?.throwIfAborted();
|
|
30
|
-
|
|
31
|
-
const domainConfig = {
|
|
32
|
-
root: args.root,
|
|
33
|
-
description: args.description || `Domain: ${domainName}`,
|
|
34
|
-
allowed_dependencies: args.allowed_dependencies,
|
|
35
|
-
forbidden_dependencies: args.forbidden_dependencies,
|
|
36
|
-
archetypes: args.archetypes,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const proposed = domainRootIdentity(args.root, workspaceRoot);
|
|
40
|
-
const claims = Object.fromEntries(Object.entries(config.domains).filter(([name, claim]) =>
|
|
41
|
-
domainNameKey(name) !== domainNameKey(domainName) && domainRootIdentity(claim.root, workspaceRoot) === proposed));
|
|
42
|
-
assertUniqueDomainRoots({ ...claims, [domainName]: domainConfig }, workspaceRoot);
|
|
43
|
-
|
|
44
|
-
const policyFile = join(workspaceRoot, "septum.config.json");
|
|
45
|
-
const policySource = existsSync(policyFile) ? readFileSync(policyFile, "utf8") : undefined;
|
|
46
|
-
if (policySource !== undefined) {
|
|
47
|
-
const policy = SeptumConfigSchema.parse(JSON.parse(policySource));
|
|
48
|
-
const existing = Object.entries(policy.domains).find(([name]) => domainNameKey(name) === domainNameKey(domainName))?.[1];
|
|
49
|
-
domainConfig.allowed_dependencies ??= existing?.allowed_dependencies ?? [];
|
|
50
|
-
domainConfig.forbidden_dependencies ??= existing?.forbidden_dependencies ?? [];
|
|
51
|
-
domainConfig.archetypes ??= existing?.archetypes ?? {};
|
|
52
|
-
domainConfig.description = args.description ?? existing?.description ?? domainConfig.description;
|
|
53
|
-
const claims = Object.fromEntries(Object.entries(policy.domains).filter(([name, claim]) =>
|
|
54
|
-
domainNameKey(name) !== domainNameKey(domainName) && domainRootIdentity(claim.root, workspaceRoot) === proposed));
|
|
55
|
-
assertUniqueDomainRoots({ ...claims, [domainName]: domainConfig }, workspaceRoot);
|
|
56
|
-
}
|
|
57
|
-
const domainId = repo.runInTransaction(() => {
|
|
58
|
-
const id = repo.domains.upsertDomain(domainName, domainConfig, workspaceRoot);
|
|
59
|
-
const stored = repo.domains.getDomainByName(domainName)!;
|
|
60
|
-
if (policySource !== undefined) ConfigLoader.writeDomain(workspaceRoot, stored.name, {
|
|
61
|
-
...domainConfig,
|
|
62
|
-
allowed_dependencies: JSON.parse(stored.allowed_deps_json),
|
|
63
|
-
forbidden_dependencies: JSON.parse(stored.forbidden_deps_json),
|
|
64
|
-
archetypes: JSON.parse(stored.archetypes_json),
|
|
65
|
-
}, policySource);
|
|
66
|
-
return id;
|
|
67
|
-
}, true);
|
|
68
|
-
const stored = repo.domains.getDomainByName(domainName);
|
|
69
|
-
const canonicalName = stored?.name || domainName;
|
|
70
|
-
const finalConfig = {
|
|
71
|
-
root: stored?.root_path || domainConfig.root,
|
|
72
|
-
description: domainConfig.description,
|
|
73
|
-
allowed_dependencies: stored ? JSON.parse(stored.allowed_deps_json || "[]") : (domainConfig.allowed_dependencies || []),
|
|
74
|
-
forbidden_dependencies: stored ? JSON.parse(stored.forbidden_deps_json || "[]") : (domainConfig.forbidden_dependencies || []),
|
|
75
|
-
archetypes: stored ? JSON.parse(stored.archetypes_json || "{}") : (domainConfig.archetypes || {}),
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
config.domains[canonicalName] = finalConfig;
|
|
79
|
-
|
|
80
|
-
let ingestionMetrics: IngestionMetrics | null = null;
|
|
81
|
-
if (args.ingest_now) {
|
|
82
|
-
const pipeline = new IngestionPipeline(repo, workspaceRoot);
|
|
83
|
-
ingestionMetrics = await pipeline.run(config, { signal });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
content: [
|
|
88
|
-
{
|
|
89
|
-
type: "text" as const,
|
|
90
|
-
text: JSON.stringify(
|
|
91
|
-
{
|
|
92
|
-
status: "success",
|
|
93
|
-
policy_owner: policySource === undefined ? "database" : "file",
|
|
94
|
-
message: `Domain '${canonicalName}' successfully registered in ${policySource === undefined ? "SQLite" : "septum.config.json"}.${
|
|
95
|
-
args.ingest_now ? " Initial ingestion completed." : ""
|
|
96
|
-
}`,
|
|
97
|
-
domain_id: domainId,
|
|
98
|
-
domain: canonicalName,
|
|
99
|
-
name: canonicalName,
|
|
100
|
-
config: finalConfig,
|
|
101
|
-
...(repo.getMeta("sync_error_code") === "DOMAIN_ROOT_CONFLICT" ? {
|
|
102
|
-
index_status: { sync_state: "error", code: "DOMAIN_ROOT_CONFLICT" },
|
|
103
|
-
next: ["Resolve any remaining duplicate roots, then sync before using indexed facts. Registration success only records this policy change."],
|
|
104
|
-
} : {}),
|
|
105
|
-
...(ingestionMetrics ? { ingestion_metrics: ingestionMetrics } : {}),
|
|
106
|
-
},
|
|
107
|
-
null,
|
|
108
|
-
2
|
|
109
|
-
),
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
};
|
|
113
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
2
|
-
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
3
|
-
import { VerticalSliceTracer } from "../../core/resolver/vertical-slice-tracer.ts";
|
|
4
|
-
import type { VerticalSliceTraceResponse } from "../../types/index.ts";
|
|
5
|
-
import type { TraceVerticalSliceArgs } from "../schemas.ts";
|
|
6
|
-
import { formatSliceNode, SLICE_RELATIONSHIP_LIMITS } from "../../core/resolver/slice-format.ts";
|
|
7
|
-
|
|
8
|
-
export type { TraceVerticalSliceArgs } from "../schemas.ts";
|
|
9
|
-
|
|
10
|
-
export function handleTraceVerticalSlice(
|
|
11
|
-
repo: SeptumRepository,
|
|
12
|
-
config: ValidatedSeptumConfig,
|
|
13
|
-
args: Partial<TraceVerticalSliceArgs> & { route?: string },
|
|
14
|
-
workspaceRoot?: string,
|
|
15
|
-
signal?: AbortSignal
|
|
16
|
-
) {
|
|
17
|
-
const query = (
|
|
18
|
-
args.query ||
|
|
19
|
-
args.symbol ||
|
|
20
|
-
args.route ||
|
|
21
|
-
""
|
|
22
|
-
).toString().trim();
|
|
23
|
-
|
|
24
|
-
if (!query) {
|
|
25
|
-
throw new Error(
|
|
26
|
-
"Missing required argument: 'query' (e.g. 'POST /orders/{id}/status', 'OrderController@updateStatus', or task intent 'Ubah status order di dashboard')"
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const root =
|
|
31
|
-
workspaceRoot ||
|
|
32
|
-
args.workspace_path ||
|
|
33
|
-
((config.settings as Record<string, unknown>)?.workspace_root as string) ||
|
|
34
|
-
process.cwd();
|
|
35
|
-
const maxDepth = Math.min(Math.max(Math.trunc(Number(args.max_depth ?? 5)), 1), 8);
|
|
36
|
-
const tracer = new VerticalSliceTracer(repo, root, config.settings.ignore_patterns, false);
|
|
37
|
-
return tracer.traceAsync(query, maxDepth, signal, args.controller_file).then((result: VerticalSliceTraceResponse) => {
|
|
38
|
-
const chain = result.chain || result.slice || [];
|
|
39
|
-
|
|
40
|
-
let summary = "";
|
|
41
|
-
if (result.found && chain.length > 0) {
|
|
42
|
-
summary = chain.map(formatSliceNode).join("\n");
|
|
43
|
-
} else if (result.found && result.entrypoint) {
|
|
44
|
-
summary = `[ENTRYPOINT] ${result.entrypoint.method} ${result.entrypoint.uri}; catalog handler ${result.entrypoint.controller}@${result.entrypoint.action} [unknown; unknown]`;
|
|
45
|
-
} else if (result.diagnostics?.length) {
|
|
46
|
-
summary = ` [UNKNOWN] ${result.message || `No matching slice in the available static catalog for '${query}'.`}`.trim();
|
|
47
|
-
} else {
|
|
48
|
-
summary = `[NOT FOUND] No matching slice in the available static catalog for '${query}'; this does not prove the route is absent at runtime.`;
|
|
49
|
-
}
|
|
50
|
-
if (result.diagnostics?.includes("ambiguous_target")) {
|
|
51
|
-
summary = `[AMBIGUOUS] ${result.message}`;
|
|
52
|
-
} else if (result.diagnostics?.length && result.found) {
|
|
53
|
-
summary = `[UNKNOWN: ${result.diagnostics.join(", ")}]\n${summary}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const nextHints = result.next ?? [
|
|
57
|
-
result.found && result.entrypoint?.action && result.entrypoint?.file
|
|
58
|
-
? `Use septum_symbol(action='context', query='${result.entrypoint.action}', file_path='${result.entrypoint.file}') to inspect handler source/contracts; read the selected mode, freshness and omissions.`
|
|
59
|
-
: result.found
|
|
60
|
-
? "Inspect the selected implementation and unresolved relationships before planning edits."
|
|
61
|
-
: "Refine the query or synchronize the workspace; no match does not prove runtime absence.",
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
const payload = {
|
|
65
|
-
status: result.diagnostics?.includes("ambiguous_target") ? "ambiguous" : result.diagnostics?.length ? "unknown" : result.found ? "success" : "not_found",
|
|
66
|
-
coverage: result.coverage,
|
|
67
|
-
diagnostics: result.diagnostics,
|
|
68
|
-
next: nextHints,
|
|
69
|
-
controller_file_filter: args.controller_file ?? null,
|
|
70
|
-
query,
|
|
71
|
-
found: result.found,
|
|
72
|
-
confidence: result.confidence,
|
|
73
|
-
confidence_scope: "query_to_catalog_target_only",
|
|
74
|
-
relationship_limits: SLICE_RELATIONSHIP_LIMITS,
|
|
75
|
-
execution_order: "not_established",
|
|
76
|
-
branch_scope: "Static relationships can span mutually exclusive handler actions; this is not one executed branch.",
|
|
77
|
-
is_exact_match: result.is_exact_match,
|
|
78
|
-
architecture_style: result.architecture_style,
|
|
79
|
-
max_depth_applied: result.max_depth_applied ?? maxDepth,
|
|
80
|
-
entrypoint: result.entrypoint || null,
|
|
81
|
-
chain,
|
|
82
|
-
alternatives: result.alternatives || [],
|
|
83
|
-
candidate_count: result.candidate_count,
|
|
84
|
-
alternatives_omitted: result.alternatives_omitted,
|
|
85
|
-
summary,
|
|
86
|
-
message: result.message || summary,
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
content: [
|
|
91
|
-
{
|
|
92
|
-
type: "text" as const,
|
|
93
|
-
text: JSON.stringify(payload),
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
metadata: {
|
|
97
|
-
status: payload.status,
|
|
98
|
-
found: payload.found,
|
|
99
|
-
confidence: payload.confidence,
|
|
100
|
-
query: payload.query,
|
|
101
|
-
chain_length: payload.chain.length,
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|