@dimassetoid/septum-mcp 0.2.1 → 0.3.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 -28
- package/package.json +4 -4
- package/src/cli/commands/check.ts +27 -16
- package/src/cli/commands/hook.ts +38 -101
- package/src/cli/commands/init.ts +26 -9
- package/src/cli/commands/sync.ts +4 -6
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +9 -52
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +49 -14
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +39 -35
- package/src/core/boundary/evaluator.ts +67 -83
- package/src/core/boundary/staged-auditor.ts +102 -40
- package/src/core/config/domain-ownership.ts +45 -0
- package/src/core/config/loader.ts +81 -29
- package/src/core/config/schema.ts +0 -10
- package/src/core/database/repositories/dependency.repository.ts +169 -148
- package/src/core/database/repositories/domain.repository.ts +46 -3
- package/src/core/database/repositories/symbol.repository.ts +226 -87
- package/src/core/database/repository.ts +73 -18
- package/src/core/database/schema.ts +2 -33
- package/src/core/discovery/navigation.ts +105 -0
- package/src/core/discovery/topology-detector.ts +60 -2
- package/src/core/ingestion/pipeline.ts +96 -129
- 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 +7 -3
- package/src/core/parser/extractors/csharp.ts +7 -3
- package/src/core/parser/extractors/django-semantic.ts +4 -36
- package/src/core/parser/extractors/elysia-semantic.ts +3 -24
- package/src/core/parser/extractors/express-semantic.ts +3 -18
- package/src/core/parser/extractors/fastapi-semantic.ts +19 -53
- package/src/core/parser/extractors/fastify-semantic.ts +3 -18
- package/src/core/parser/extractors/flask-semantic.ts +22 -55
- package/src/core/parser/extractors/go-semantic.ts +92 -33
- package/src/core/parser/extractors/hono-semantic.ts +3 -24
- package/src/core/parser/extractors/java.ts +5 -3
- package/src/core/parser/extractors/laravel-semantic.ts +44 -16
- package/src/core/parser/extractors/mcp-cli-semantic.ts +6 -7
- package/src/core/parser/extractors/nestjs-semantic.ts +3 -19
- package/src/core/parser/extractors/php.ts +16 -0
- package/src/core/parser/extractors/python.ts +9 -4
- package/src/core/parser/extractors/registry.ts +26 -5
- package/src/core/parser/extractors/ruby.ts +8 -5
- package/src/core/parser/extractors/rust.ts +31 -13
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-semantic.ts +4 -37
- package/src/core/parser/extractors/typescript.ts +14 -1
- 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 +73 -50
- 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/resolver/call-graph-tracer.ts +337 -28
- package/src/core/resolver/import-resolver.ts +107 -179
- package/src/core/resolver/interpretation-inputs.ts +7 -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 +115 -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 +71 -0
- package/src/core/resolver/module-resolver.ts +8 -4
- package/src/core/resolver/slice-catalog.ts +79 -0
- package/src/core/resolver/slice-format.ts +9 -0
- package/src/core/resolver/symbol-impact.ts +381 -0
- package/src/core/resolver/vertical-slice-tracer.ts +93 -115
- package/src/core/resources/ignore.ts +22 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/retrieval/context-page.ts +109 -0
- package/src/core/retrieval/context.ts +320 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +262 -0
- package/src/core/telemetry/telemetry.ts +54 -9
- package/src/index.ts +0 -3
- package/src/mcp/schemas.ts +61 -420
- package/src/mcp/server.ts +116 -290
- package/src/mcp/tools/boundary.ts +2 -2
- package/src/mcp/tools/check-boundary.ts +55 -60
- package/src/mcp/tools/get-domain-catalog.ts +32 -219
- package/src/mcp/tools/get-symbol-impact.ts +45 -5
- package/src/mcp/tools/get-symbol.ts +227 -3
- package/src/mcp/tools/locate-symbol.ts +54 -14
- package/src/mcp/tools/{domain.ts → map.ts} +4 -18
- package/src/mcp/tools/register-domain.ts +41 -3
- package/src/mcp/tools/symbol.ts +23 -21
- package/src/mcp/tools/trace-vertical-slice.ts +36 -10
- package/src/mcp/workspace-manager.ts +15 -4
- package/src/mcp/workspace-watcher.ts +8 -8
- package/src/types/index.ts +35 -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/feature.ts +0 -67
- 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/register-feature.ts +0 -110
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
export type EnvironmentLayer =
|
|
2
|
-
| "edge"
|
|
3
|
-
| "gateway"
|
|
4
|
-
| "host"
|
|
5
|
-
| "runtime"
|
|
6
|
-
| "storage"
|
|
7
|
-
| "telemetry";
|
|
8
|
-
|
|
9
|
-
export type LayerResolutionStatus = "DETECTED" | "AMBIGUOUS" | "UNRESOLVED" | "VERIFIED";
|
|
10
|
-
|
|
11
|
-
export type CanonicalPlatformTag =
|
|
12
|
-
| "shared_hosting"
|
|
13
|
-
| "vps"
|
|
14
|
-
| "docker"
|
|
15
|
-
| "serverless"
|
|
16
|
-
| "kubernetes"
|
|
17
|
-
| "managed_db"
|
|
18
|
-
| "cdn_edge"
|
|
19
|
-
| "paas"
|
|
20
|
-
| "static_cdn"
|
|
21
|
-
| "unspecified";
|
|
22
|
-
|
|
23
|
-
export interface EnvironmentLayerInfo {
|
|
24
|
-
layer: EnvironmentLayer;
|
|
25
|
-
platform?: string;
|
|
26
|
-
canonical_tag?: CanonicalPlatformTag;
|
|
27
|
-
status: LayerResolutionStatus;
|
|
28
|
-
detected_from?: string[];
|
|
29
|
-
evidence?: string[];
|
|
30
|
-
constraints?: string[];
|
|
31
|
-
unresolved_inquiry?: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface TopologyNode {
|
|
35
|
-
id: string; // e.g. "edge:cloudflare", "host:api-vps", "host:worker-vps", "storage:central-db"
|
|
36
|
-
layer: EnvironmentLayer;
|
|
37
|
-
name: string; // e.g. "Cloudflare Perimeter", "API Backend VPS", "Postgres Cluster"
|
|
38
|
-
platform: string; // e.g. "Cloudflare WAF", "Hostinger VPS", "AWS RDS Postgres"
|
|
39
|
-
canonical_tag: CanonicalPlatformTag;
|
|
40
|
-
domain_or_ip?: string; // e.g. "api.example.com", "10.0.0.5"
|
|
41
|
-
role?: string; // e.g. "web_api", "queue_worker", "frontend_spa", "database_primary"
|
|
42
|
-
status: LayerResolutionStatus;
|
|
43
|
-
detected_from: string[];
|
|
44
|
-
constraints: string[];
|
|
45
|
-
connected_to?: string[]; // IDs of nodes this node interacts with
|
|
46
|
-
unresolved_inquiry?: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface CrossLayerInterplay {
|
|
50
|
-
title: string;
|
|
51
|
-
involved_layers: EnvironmentLayer[];
|
|
52
|
-
involved_node_ids?: string[];
|
|
53
|
-
risk_or_rule: string;
|
|
54
|
-
required_action: string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface EnvironmentTopology {
|
|
58
|
-
is_distributed: boolean;
|
|
59
|
-
nodes: TopologyNode[];
|
|
60
|
-
layers: Record<EnvironmentLayer, EnvironmentLayerInfo>;
|
|
61
|
-
overall_status: "RESOLVED" | "NEEDS_CLARIFICATION";
|
|
62
|
-
interplays: CrossLayerInterplay[];
|
|
63
|
-
pending_inquiries: string[];
|
|
64
|
-
architectural_summary: string;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export interface ResolveLayerInput {
|
|
68
|
-
layer: EnvironmentLayer;
|
|
69
|
-
platform: string;
|
|
70
|
-
constraints?: string[];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface ResolveNodeInput {
|
|
74
|
-
id: string;
|
|
75
|
-
layer: EnvironmentLayer;
|
|
76
|
-
name: string;
|
|
77
|
-
platform: string;
|
|
78
|
-
canonical_tag?: CanonicalPlatformTag;
|
|
79
|
-
domain_or_ip?: string;
|
|
80
|
-
role?: string;
|
|
81
|
-
constraints?: string[];
|
|
82
|
-
connected_to?: string[];
|
|
83
|
-
}
|
package/src/mcp/tools/feature.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
2
|
-
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
3
|
-
import type { FeatureToolArgs } from "../schemas.ts";
|
|
4
|
-
import { handleGetFeatureContext, handleClearFeatureContext } from "./get-feature-context.ts";
|
|
5
|
-
import { handleRegisterFeature } from "./register-feature.ts";
|
|
6
|
-
|
|
7
|
-
export type { FeatureToolArgs };
|
|
8
|
-
|
|
9
|
-
export async function handleFeatureTool(
|
|
10
|
-
repo: SeptumRepository,
|
|
11
|
-
config: ValidatedSeptumConfig,
|
|
12
|
-
args: FeatureToolArgs,
|
|
13
|
-
workspaceRoot?: string
|
|
14
|
-
) {
|
|
15
|
-
const action = args.action || "get";
|
|
16
|
-
|
|
17
|
-
switch (action) {
|
|
18
|
-
case "lock":
|
|
19
|
-
return await handleRegisterFeature(
|
|
20
|
-
repo,
|
|
21
|
-
config,
|
|
22
|
-
{
|
|
23
|
-
feature_key: args.feature_key || args.feature || "",
|
|
24
|
-
feature: args.feature || args.feature_key || "",
|
|
25
|
-
domain: args.domain || args.domain_name || "",
|
|
26
|
-
domain_name: args.domain_name || args.domain || "",
|
|
27
|
-
description: args.description,
|
|
28
|
-
allowed_touchpoints: args.allowed_touchpoints,
|
|
29
|
-
reuse_symbols: args.reuse_symbols,
|
|
30
|
-
input_contract: args.input_contract,
|
|
31
|
-
output_contract: args.output_contract,
|
|
32
|
-
workspace_path: args.workspace_path,
|
|
33
|
-
},
|
|
34
|
-
workspaceRoot || args.workspace_path || process.cwd()
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
case "release": {
|
|
38
|
-
const cleared = handleClearFeatureContext(
|
|
39
|
-
workspaceRoot || args.workspace_path || process.cwd(),
|
|
40
|
-
Boolean(args.force)
|
|
41
|
-
);
|
|
42
|
-
return {
|
|
43
|
-
content: [
|
|
44
|
-
{
|
|
45
|
-
type: "text" as const,
|
|
46
|
-
text: cleared
|
|
47
|
-
? "Active feature session successfully released."
|
|
48
|
-
: "No active feature session found to release.",
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
case "get":
|
|
55
|
-
default:
|
|
56
|
-
return handleGetFeatureContext(
|
|
57
|
-
repo,
|
|
58
|
-
config,
|
|
59
|
-
{
|
|
60
|
-
feature_key: args.feature_key || args.feature,
|
|
61
|
-
feature: args.feature || args.feature_key,
|
|
62
|
-
workspace_path: args.workspace_path,
|
|
63
|
-
},
|
|
64
|
-
workspaceRoot || args.workspace_path || process.cwd()
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
2
|
-
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
3
|
-
import { EnvironmentDetector } from "../../core/topology/environment-detector.ts";
|
|
4
|
-
import type { EnvironmentLayer } from "../../core/topology/types.ts";
|
|
5
|
-
import type { GetEnvironmentTopologyArgs } from "../schemas.ts";
|
|
6
|
-
|
|
7
|
-
export type { GetEnvironmentTopologyArgs } from "../schemas.ts";
|
|
8
|
-
|
|
9
|
-
export function handleGetEnvironmentTopology(
|
|
10
|
-
repo: SeptumRepository,
|
|
11
|
-
_config: ValidatedSeptumConfig,
|
|
12
|
-
args: GetEnvironmentTopologyArgs,
|
|
13
|
-
workspaceRoot: string
|
|
14
|
-
) {
|
|
15
|
-
// If layer resolution input is provided, persist into SQLite SSOT
|
|
16
|
-
if (args.resolve) {
|
|
17
|
-
const existing = repo.environment.getLayer(args.resolve.layer);
|
|
18
|
-
repo.environment.saveLayer({
|
|
19
|
-
layer: args.resolve.layer,
|
|
20
|
-
platform: args.resolve.platform,
|
|
21
|
-
canonical_tag: EnvironmentDetector.matchCanonicalTag(args.resolve.platform),
|
|
22
|
-
status: "VERIFIED",
|
|
23
|
-
constraints: args.resolve.constraints && args.resolve.constraints.length > 0 ? args.resolve.constraints : (existing?.constraints ?? []),
|
|
24
|
-
detected_from: ["Manual Developer Resolution via Septum"],
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// If node resolution input is provided, persist node into SQLite SSOT
|
|
29
|
-
if (args.resolveNode) {
|
|
30
|
-
repo.environment.saveNode({
|
|
31
|
-
id: args.resolveNode.id,
|
|
32
|
-
layer: args.resolveNode.layer,
|
|
33
|
-
name: args.resolveNode.name,
|
|
34
|
-
platform: args.resolveNode.platform,
|
|
35
|
-
canonical_tag: args.resolveNode.canonical_tag || EnvironmentDetector.matchCanonicalTag(args.resolveNode.platform),
|
|
36
|
-
domain_or_ip: args.resolveNode.domain_or_ip,
|
|
37
|
-
role: args.resolveNode.role,
|
|
38
|
-
status: "VERIFIED",
|
|
39
|
-
detected_from: ["Manual Developer Resolution via Septum MCP"],
|
|
40
|
-
constraints: args.resolveNode.constraints ?? [],
|
|
41
|
-
connected_to: args.resolveNode.connected_to ?? [],
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Detect current topology merging heuristics with SQLite SSOT
|
|
46
|
-
const topology = EnvironmentDetector.detect(workspaceRoot, repo, args.refresh);
|
|
47
|
-
|
|
48
|
-
// Format into high-density Markdown output
|
|
49
|
-
let output = `### 🌐 Septum Environment & Topology Plane\n\n`;
|
|
50
|
-
output += `> **Overall Status:** \`${topology.overall_status}\`\n`;
|
|
51
|
-
output += `> **Topology Mode:** \`${topology.is_distributed ? "DISTRIBUTED MULTI-NODE GRAPH" : "MONOLITHIC SINGLE-NODE"}\`\n`;
|
|
52
|
-
output += `> **Architecture:** ${topology.architectural_summary}\n\n`;
|
|
53
|
-
|
|
54
|
-
// Section 1: Distributed Nodes Graph
|
|
55
|
-
if (topology.nodes.length > 0) {
|
|
56
|
-
output += `#### 📦 Distributed Topology Nodes (${topology.nodes.length} entities):\n`;
|
|
57
|
-
output += `| Node ID | Layer | Platform / Specs | Role | Domain / Host | Connected To | Status |\n`;
|
|
58
|
-
output += `| :--- | :--- | :--- | :--- | :--- | :--- | :--- |\n`;
|
|
59
|
-
for (const node of topology.nodes) {
|
|
60
|
-
const statusBadge = node.status === "VERIFIED" ? "✅ VERIFIED" : node.status === "DETECTED" ? "🔍 DETECTED" : "⚠️ " + node.status;
|
|
61
|
-
const domain = node.domain_or_ip ? `\`${node.domain_or_ip}\`` : "-";
|
|
62
|
-
const role = node.role ? `\`${node.role}\`` : "-";
|
|
63
|
-
const connected = node.connected_to && node.connected_to.length > 0 ? node.connected_to.join(", ") : "-";
|
|
64
|
-
output += `| **\`${node.id}\`** | ${node.layer.toUpperCase()} | ${node.platform} | ${role} | ${domain} | ${connected} | ${statusBadge} |\n`;
|
|
65
|
-
}
|
|
66
|
-
output += `\n`;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Section 2: 6-Layer Summary
|
|
70
|
-
output += `#### 🗺️ 6-Layer Plane Summary:\n`;
|
|
71
|
-
output += `| Layer | Plane Domain | Platform / Setup | Status | Evidence / Files |\n`;
|
|
72
|
-
output += `| :--- | :--- | :--- | :--- | :--- |\n`;
|
|
73
|
-
|
|
74
|
-
const layerLabels: Record<EnvironmentLayer, string> = {
|
|
75
|
-
edge: "Perimeter & WAF",
|
|
76
|
-
gateway: "Ingress & Web Server",
|
|
77
|
-
host: "Deployment Platform",
|
|
78
|
-
runtime: "Application Engine",
|
|
79
|
-
storage: "Data & Cache",
|
|
80
|
-
telemetry: "Observability & Logs",
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
for (const layerKey of Object.keys(topology.layers) as EnvironmentLayer[]) {
|
|
84
|
-
const info = topology.layers[layerKey];
|
|
85
|
-
const evidence = info.detected_from && info.detected_from.length > 0 ? info.detected_from.join(", ") : "-";
|
|
86
|
-
const statusBadge = info.status === "VERIFIED" ? "✅ VERIFIED" : info.status === "DETECTED" ? "🔍 DETECTED" : "⚠️ " + info.status;
|
|
87
|
-
output += `| **${layerKey.toUpperCase()}** | ${layerLabels[layerKey]} | ${info.platform || "Not Defined"} | ${statusBadge} | ${evidence} |\n`;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Section 3: Active Constraints
|
|
91
|
-
output += `\n#### 📌 Active Architectural Constraints:\n`;
|
|
92
|
-
let hasConstraints = false;
|
|
93
|
-
for (const node of topology.nodes) {
|
|
94
|
-
if (node.constraints && node.constraints.length > 0) {
|
|
95
|
-
hasConstraints = true;
|
|
96
|
-
output += `- **\`${node.id}\` (${node.platform}):**\n`;
|
|
97
|
-
for (const c of node.constraints) {
|
|
98
|
-
output += ` • ${c}\n`;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (!hasConstraints) {
|
|
103
|
-
output += `*No specific node constraints recorded.*\n`;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Section 4: Cross-Layer & Distributed Interplays
|
|
107
|
-
if (topology.interplays.length > 0) {
|
|
108
|
-
output += `\n#### ⚡ Cross-Layer & Distributed Invariants:\n`;
|
|
109
|
-
for (const interplay of topology.interplays) {
|
|
110
|
-
const nodeTrace = interplay.involved_node_ids && interplay.involved_node_ids.length > 0 ? ` (Nodes: \`${interplay.involved_node_ids.join(", ")}\`)` : "";
|
|
111
|
-
output += `- **${interplay.title}** (Layers: \`${interplay.involved_layers.join(" ➔ ")}\`)${nodeTrace}:\n`;
|
|
112
|
-
output += ` • *Invarian:* ${interplay.risk_or_rule}\n`;
|
|
113
|
-
output += ` • *Tindakan Wajib:* ${interplay.required_action}\n`;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Section 5: Pending Inquiries
|
|
118
|
-
if (topology.pending_inquiries.length > 0) {
|
|
119
|
-
output += `\n#### ❓ Pending Architectural Inquiries (Self-Aware Inquiry Required):\n`;
|
|
120
|
-
output += `Terdapat layer atau node arsitektural yang belum terkonfirmasi. Sebelum mengeksekusi kode terkait deployment/throttling/cron/cookies, klarifikasikan hal berikut ke pengguna:\n`;
|
|
121
|
-
for (const q of topology.pending_inquiries) {
|
|
122
|
-
output += `- ${q}\n`;
|
|
123
|
-
}
|
|
124
|
-
output += `\n*Untuk mengunci jawaban pengguna ke SQLite SSOT, panggil kembali tool ini dengan argumen:*\n`;
|
|
125
|
-
output += `\`septum_domain(action: "topology", resolve: { layer: "<layer_name>", platform: "<platform_name>" })\`\n`;
|
|
126
|
-
output += `*atau untuk entitas terdistribusi:*\n`;
|
|
127
|
-
output += `\`septum_domain(action: "topology", resolve_node: { id: "<node_id>", layer: "<layer>", name: "<name>", platform: "<platform>", domain_or_ip: "<domain_or_ip>", role: "<role>" })\`\n`;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
content: [
|
|
132
|
-
{
|
|
133
|
-
type: "text" as const,
|
|
134
|
-
text: output,
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
};
|
|
138
|
-
}
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
4
|
-
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
5
|
-
import { SessionManager } from "../../core/session/session-manager.ts";
|
|
6
|
-
import type { FeatureContextResponse } from "../../types/index.ts";
|
|
7
|
-
import type { GetFeatureContextArgs } from "../schemas.ts";
|
|
8
|
-
|
|
9
|
-
export type { GetFeatureContextArgs } from "../schemas.ts";
|
|
10
|
-
|
|
11
|
-
export function handleClearFeatureContext(
|
|
12
|
-
workspaceRoot: string = process.cwd(),
|
|
13
|
-
force: boolean = false
|
|
14
|
-
): boolean {
|
|
15
|
-
return SessionManager.clearActiveSession(workspaceRoot, undefined, force);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function handleGetFeatureContext(
|
|
19
|
-
repo: SeptumRepository,
|
|
20
|
-
config: ValidatedSeptumConfig,
|
|
21
|
-
args: GetFeatureContextArgs,
|
|
22
|
-
workspaceRoot: string = process.cwd()
|
|
23
|
-
) {
|
|
24
|
-
const featureKey = (args.feature_key || args.feature || "").trim();
|
|
25
|
-
const features = { ...(config.features ?? {}) };
|
|
26
|
-
if (typeof repo?.getMeta === "function") {
|
|
27
|
-
try {
|
|
28
|
-
const metaFeaturesRaw = repo.getMeta("features_json");
|
|
29
|
-
if (metaFeaturesRaw) {
|
|
30
|
-
Object.assign(features, JSON.parse(metaFeaturesRaw));
|
|
31
|
-
}
|
|
32
|
-
} catch {}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// ZERO-ARGUMENT GRACEFUL FALLBACK: Guide the agent instead of throwing validation errors
|
|
36
|
-
if (!featureKey) {
|
|
37
|
-
const available = Object.keys(features);
|
|
38
|
-
return {
|
|
39
|
-
content: [
|
|
40
|
-
{
|
|
41
|
-
type: "text" as const,
|
|
42
|
-
text: JSON.stringify(
|
|
43
|
-
{
|
|
44
|
-
status: "prompt",
|
|
45
|
-
message: "No feature specified. Please specify 'feature_key' from the registered features below or trace routes.",
|
|
46
|
-
available_features: available.length > 0 ? available : [],
|
|
47
|
-
instructions: "Call 'septum_feature({ action: \"get\", feature_key: \"<name>\" })' or lock a feature with 'septum_feature({ action: \"lock\", feature_key: \"<name>\", domain: \"<domain>\" })'.",
|
|
48
|
-
},
|
|
49
|
-
null,
|
|
50
|
-
2
|
|
51
|
-
),
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let featureConfig = features[featureKey];
|
|
58
|
-
let isInferred = false;
|
|
59
|
-
|
|
60
|
-
if (!featureConfig) {
|
|
61
|
-
// Attempt auto-derive from vertical slices or domain symbols
|
|
62
|
-
const searchTerm = featureKey.toLowerCase();
|
|
63
|
-
const allSlices = typeof repo.getAllVerticalSlices === "function" ? repo.getAllVerticalSlices() : [];
|
|
64
|
-
const fromRepoSearch = typeof repo.findVerticalSlices === "function" ? repo.findVerticalSlices(searchTerm) : [];
|
|
65
|
-
const matchingSlices = [
|
|
66
|
-
...fromRepoSearch,
|
|
67
|
-
...allSlices.filter(
|
|
68
|
-
(s) =>
|
|
69
|
-
s.route_uri.toLowerCase().includes(searchTerm) ||
|
|
70
|
-
(s.route_name && s.route_name.toLowerCase().includes(searchTerm)) ||
|
|
71
|
-
s.controller_class.toLowerCase().includes(searchTerm) ||
|
|
72
|
-
(s.feature_key && s.feature_key.toLowerCase().includes(searchTerm))
|
|
73
|
-
),
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
const uniqueSlices = Array.from(
|
|
77
|
-
new Map(matchingSlices.map((s) => [`${s.http_method}:${s.route_uri}`, s])).values()
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
if (uniqueSlices.length > 0) {
|
|
81
|
-
isInferred = true;
|
|
82
|
-
const candidateTouchpoints = new Set<string>();
|
|
83
|
-
const candidateSymbols = new Set<string>();
|
|
84
|
-
let detectedDomain = "app";
|
|
85
|
-
|
|
86
|
-
if (config.domains && config.domains[featureKey]) {
|
|
87
|
-
detectedDomain = featureKey;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
for (const slice of uniqueSlices) {
|
|
91
|
-
if (slice.controller_file) {
|
|
92
|
-
candidateTouchpoints.add(slice.controller_file);
|
|
93
|
-
}
|
|
94
|
-
candidateSymbols.add(slice.controller_class);
|
|
95
|
-
if (slice.action_name) {
|
|
96
|
-
candidateSymbols.add(`${slice.controller_class}@${slice.action_name}`);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (slice.execution_chain_json) {
|
|
100
|
-
try {
|
|
101
|
-
const chain = JSON.parse(slice.execution_chain_json);
|
|
102
|
-
if (Array.isArray(chain)) {
|
|
103
|
-
for (const node of chain) {
|
|
104
|
-
if (node.file) candidateTouchpoints.add(node.file);
|
|
105
|
-
if (node.symbol) candidateSymbols.add(node.symbol);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
} catch {}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
featureConfig = {
|
|
113
|
-
domain: detectedDomain,
|
|
114
|
-
description: `[Auto-Derived] Feature context inferred from ${uniqueSlices.length} vertical slices matching '${featureKey}'`,
|
|
115
|
-
allowed_touchpoints: Array.from(candidateTouchpoints),
|
|
116
|
-
reuse_symbols: Array.from(candidateSymbols).slice(0, 10),
|
|
117
|
-
input_contract: {},
|
|
118
|
-
output_contract: {},
|
|
119
|
-
};
|
|
120
|
-
} else {
|
|
121
|
-
const available = Object.keys(features);
|
|
122
|
-
const availableStr = available.length > 0 ? available.join(", ") : "none";
|
|
123
|
-
return {
|
|
124
|
-
content: [
|
|
125
|
-
{
|
|
126
|
-
type: "text" as const,
|
|
127
|
-
text: JSON.stringify(
|
|
128
|
-
{
|
|
129
|
-
status: "not_found",
|
|
130
|
-
feature_key: featureKey,
|
|
131
|
-
message: `Feature '${featureKey}' not found in configuration or vertical slices. Available features: [${availableStr}].`,
|
|
132
|
-
recovery_options: [
|
|
133
|
-
`septum_feature({ action: "lock", feature_key: "${featureKey}", domain: "<domain_name>", allowed_touchpoints: ["path/to/file"] })`,
|
|
134
|
-
`septum_slice({ query: "routes/web.php" })`,
|
|
135
|
-
],
|
|
136
|
-
},
|
|
137
|
-
null,
|
|
138
|
-
2
|
|
139
|
-
),
|
|
140
|
-
},
|
|
141
|
-
],
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// MCP-14: handleGetFeatureContext is strictly read-only and does not mutate session leases
|
|
147
|
-
|
|
148
|
-
// Deterministically fetch signatures, methods, and properties for reuse_symbols from SQLite
|
|
149
|
-
const reuseSymbolsWithMeta: FeatureContextResponse["reuse_symbols"] = [];
|
|
150
|
-
const requestedSymbols = featureConfig.reuse_symbols ?? [];
|
|
151
|
-
|
|
152
|
-
for (const symName of requestedSymbols) {
|
|
153
|
-
const record = repo.findSymbolWithMembers(symName);
|
|
154
|
-
if (record) {
|
|
155
|
-
reuseSymbolsWithMeta.push({
|
|
156
|
-
name: record.symbol_name,
|
|
157
|
-
kind: record.kind,
|
|
158
|
-
signature: record.signature,
|
|
159
|
-
methods: record.methods.length > 0 ? record.methods : undefined,
|
|
160
|
-
properties: record.properties.length > 0 ? record.properties : undefined,
|
|
161
|
-
file_path: record.file_path,
|
|
162
|
-
domain: record.domain_name,
|
|
163
|
-
});
|
|
164
|
-
} else {
|
|
165
|
-
reuseSymbolsWithMeta.push({
|
|
166
|
-
name: symName,
|
|
167
|
-
kind: "unknown",
|
|
168
|
-
domain: featureConfig.domain,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const response: FeatureContextResponse = {
|
|
174
|
-
feature_key: featureKey,
|
|
175
|
-
feature: featureKey,
|
|
176
|
-
domain: featureConfig.domain,
|
|
177
|
-
description: featureConfig.description,
|
|
178
|
-
allowed_touchpoints: featureConfig.allowed_touchpoints,
|
|
179
|
-
reuse_symbols: reuseSymbolsWithMeta,
|
|
180
|
-
input_contract: (featureConfig.input_contract as Record<string, unknown>) ?? {},
|
|
181
|
-
output_contract: (featureConfig.output_contract as Record<string, unknown>) ?? {},
|
|
182
|
-
governance_directives: [
|
|
183
|
-
"DO NOT modify or edit any files outside allowed_touchpoints.",
|
|
184
|
-
"DO NOT create duplicate helpers/services; reuse the existing symbols and methods declared in reuse_symbols.",
|
|
185
|
-
"DO NOT emit or expect phantom payload fields outside input_contract and output_contract.",
|
|
186
|
-
"DO NOT import cross-domain modules without declared allowed_dependencies in Septum domain boundaries.",
|
|
187
|
-
],
|
|
188
|
-
...(isInferred ? { is_inferred: true } : {}),
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
recordFeatureAccess(featureConfig.domain, featureKey, workspaceRoot);
|
|
192
|
-
|
|
193
|
-
return {
|
|
194
|
-
content: [
|
|
195
|
-
{
|
|
196
|
-
type: "text" as const,
|
|
197
|
-
text: JSON.stringify(response, null, 2),
|
|
198
|
-
},
|
|
199
|
-
],
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function recordFeatureAccess(domain: string, feature: string, workspaceRoot: string = process.cwd()): void {
|
|
204
|
-
try {
|
|
205
|
-
const septumDir = path.resolve(workspaceRoot, ".septum");
|
|
206
|
-
if (!fs.existsSync(septumDir)) {
|
|
207
|
-
fs.mkdirSync(septumDir, { recursive: true });
|
|
208
|
-
}
|
|
209
|
-
const logPath = path.join(septumDir, "catalog_access.json");
|
|
210
|
-
let log: { domains?: Record<string, string>; features?: Record<string, string> } = {};
|
|
211
|
-
if (fs.existsSync(logPath)) {
|
|
212
|
-
try {
|
|
213
|
-
log = JSON.parse(fs.readFileSync(logPath, "utf-8"));
|
|
214
|
-
} catch {}
|
|
215
|
-
}
|
|
216
|
-
log.domains = log.domains || {};
|
|
217
|
-
log.features = log.features || {};
|
|
218
|
-
const now = new Date().toISOString();
|
|
219
|
-
log.domains[domain] = now;
|
|
220
|
-
log.features[feature] = now;
|
|
221
|
-
fs.writeFileSync(logPath, JSON.stringify(log, null, 2), "utf-8");
|
|
222
|
-
} catch {}
|
|
223
|
-
}
|
|
224
|
-
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
2
|
-
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
3
|
-
import type { SymbolKind } from "../../types/index.ts";
|
|
4
|
-
import type { GetSymbolHotspotsArgs } from "../schemas.ts";
|
|
5
|
-
|
|
6
|
-
export type { GetSymbolHotspotsArgs } from "../schemas.ts";
|
|
7
|
-
|
|
8
|
-
export function handleGetSymbolHotspots(
|
|
9
|
-
repo: SeptumRepository,
|
|
10
|
-
_config: ValidatedSeptumConfig,
|
|
11
|
-
args: GetSymbolHotspotsArgs,
|
|
12
|
-
_workspaceRoot?: string
|
|
13
|
-
) {
|
|
14
|
-
const minLines = args.min_lines ?? (args.min_nesting ? 0 : 30);
|
|
15
|
-
const minNesting = args.min_nesting ?? 1;
|
|
16
|
-
const limit = args.limit ?? 30;
|
|
17
|
-
const sortBy = args.sort_by ?? "risk_score";
|
|
18
|
-
|
|
19
|
-
const hotspots = repo.getHotspotSymbols({
|
|
20
|
-
minLines,
|
|
21
|
-
minNesting,
|
|
22
|
-
kind: args.kind as SymbolKind | undefined,
|
|
23
|
-
domain: args.domain,
|
|
24
|
-
limit,
|
|
25
|
-
sortBy,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const payload = {
|
|
29
|
-
total_found: hotspots.length,
|
|
30
|
-
threshold_min_lines: minLines,
|
|
31
|
-
threshold_min_nesting: minNesting,
|
|
32
|
-
sort_by: sortBy,
|
|
33
|
-
hotspots: hotspots.map((h) => ({
|
|
34
|
-
name: h.name,
|
|
35
|
-
kind: h.kind,
|
|
36
|
-
line_count: h.line_count,
|
|
37
|
-
nesting_depth: (h as any).nesting_depth ?? 1,
|
|
38
|
-
risk_score: (h as any).risk_score ?? h.line_count,
|
|
39
|
-
line_span: `${h.line_start}-${h.line_end}`,
|
|
40
|
-
file_path: h.file_path,
|
|
41
|
-
domain: h.domain_name,
|
|
42
|
-
signature: h.signature,
|
|
43
|
-
})),
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
content: [
|
|
48
|
-
{
|
|
49
|
-
type: "text" as const,
|
|
50
|
-
text: JSON.stringify(payload, null, 2),
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
};
|
|
54
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import type { ValidatedSeptumConfig } from "../../core/config/schema.ts";
|
|
2
|
-
import type { SeptumRepository } from "../../core/database/repository.ts";
|
|
3
|
-
import { SessionManager } from "../../core/session/session-manager.ts";
|
|
4
|
-
import type { RegisterFeatureArgs } from "../schemas.ts";
|
|
5
|
-
|
|
6
|
-
export type { RegisterFeatureArgs } from "../schemas.ts";
|
|
7
|
-
|
|
8
|
-
export async function handleRegisterFeature(
|
|
9
|
-
repo: SeptumRepository,
|
|
10
|
-
config: ValidatedSeptumConfig,
|
|
11
|
-
args: Partial<RegisterFeatureArgs>,
|
|
12
|
-
workspaceRoot: string = process.cwd()
|
|
13
|
-
) {
|
|
14
|
-
const featureKey = (args.feature_key || args.feature || "").toString().trim();
|
|
15
|
-
const domain = (args.domain || args.domain_name || "").toString().trim();
|
|
16
|
-
|
|
17
|
-
if (!featureKey || !domain) {
|
|
18
|
-
throw new Error("Missing required arguments: 'feature_key' and 'domain' are required.");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// MCP-15: Validate domain is registered in DB or config
|
|
22
|
-
const registeredDomain = repo.getDomainByName(domain);
|
|
23
|
-
const configDomain = Object.keys(config.domains || {}).find(
|
|
24
|
-
(d) => d.toLowerCase() === domain.toLowerCase()
|
|
25
|
-
);
|
|
26
|
-
if (!registeredDomain && !configDomain) {
|
|
27
|
-
throw new Error(`Domain '${domain}' is not registered. Cannot lock feature to an unknown domain.`);
|
|
28
|
-
}
|
|
29
|
-
const canonicalDomain = registeredDomain?.name || configDomain || domain;
|
|
30
|
-
|
|
31
|
-
const rawTouchpoints = args.allowed_touchpoints ?? [];
|
|
32
|
-
const allowedTouchpoints = Array.isArray(rawTouchpoints)
|
|
33
|
-
? rawTouchpoints
|
|
34
|
-
: typeof rawTouchpoints === "string"
|
|
35
|
-
? [rawTouchpoints]
|
|
36
|
-
: [];
|
|
37
|
-
|
|
38
|
-
// MCP-15: Validate supported touchpoint glob patterns (exact, /*, /**)
|
|
39
|
-
for (const tp of allowedTouchpoints) {
|
|
40
|
-
const normalized = tp.replace(/\\/g, "/");
|
|
41
|
-
if (normalized.includes("*")) {
|
|
42
|
-
if (!normalized.endsWith("/*") && !normalized.endsWith("/**") && normalized !== "*" && normalized !== "**") {
|
|
43
|
-
throw new Error(
|
|
44
|
-
`Unsupported touchpoint glob pattern '${tp}'. Septum touchpoints support exact paths, '/*', and '/**'.`
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const rawReuse = args.reuse_symbols;
|
|
51
|
-
const reuseSymbols: string[] = Array.isArray(rawReuse)
|
|
52
|
-
? rawReuse
|
|
53
|
-
: typeof rawReuse === "string"
|
|
54
|
-
? [rawReuse]
|
|
55
|
-
: [];
|
|
56
|
-
|
|
57
|
-
const featureConfig = {
|
|
58
|
-
domain: canonicalDomain,
|
|
59
|
-
description: args.description || `Feature: ${featureKey}`,
|
|
60
|
-
allowed_touchpoints: allowedTouchpoints,
|
|
61
|
-
reuse_symbols: reuseSymbols,
|
|
62
|
-
input_contract: args.input_contract || {},
|
|
63
|
-
output_contract: args.output_contract || {},
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
SessionManager.saveActiveSession(workspaceRoot, {
|
|
67
|
-
feature_key: featureKey,
|
|
68
|
-
domain: canonicalDomain,
|
|
69
|
-
touchpoints: featureConfig.allowed_touchpoints,
|
|
70
|
-
locked_at: new Date().toISOString(),
|
|
71
|
-
}, SessionManager.getOwnerId(), {
|
|
72
|
-
repo,
|
|
73
|
-
save: () => {
|
|
74
|
-
const existingRaw = repo.getMeta("features_json");
|
|
75
|
-
const featuresMap = existingRaw ? JSON.parse(existingRaw) : {};
|
|
76
|
-
featuresMap[featureKey] = featureConfig;
|
|
77
|
-
repo.setMeta("features_json", JSON.stringify(featuresMap));
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// 3. Update in-memory config only after both SQLite and session lease succeeded
|
|
82
|
-
if (!config.features) {
|
|
83
|
-
config.features = {};
|
|
84
|
-
}
|
|
85
|
-
config.features[featureKey] = featureConfig;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
content: [
|
|
91
|
-
{
|
|
92
|
-
type: "text" as const,
|
|
93
|
-
text: JSON.stringify(
|
|
94
|
-
{
|
|
95
|
-
status: "success",
|
|
96
|
-
message: `Feature '${featureKey}' successfully registered in SQLite SSOT and session lease established.`,
|
|
97
|
-
feature_key: featureKey,
|
|
98
|
-
feature: featureKey,
|
|
99
|
-
domain: canonicalDomain,
|
|
100
|
-
touchpoints: featureConfig.allowed_touchpoints,
|
|
101
|
-
reuse_symbols: featureConfig.reuse_symbols,
|
|
102
|
-
},
|
|
103
|
-
null,
|
|
104
|
-
2
|
|
105
|
-
),
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|