@dimassetoid/septum-mcp 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +142 -2
- package/bin/septum.ts +4 -0
- package/package.json +70 -4
- package/scripts/postinstall.ts +25 -0
- package/src/cli/commands/check.ts +133 -0
- package/src/cli/commands/hook.ts +205 -0
- package/src/cli/commands/init.ts +570 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/sync.ts +39 -0
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +124 -0
- package/src/cli/scaffold/harness-config.ts +661 -0
- package/src/cli/templates/hooks.ts +110 -0
- package/src/cli/templates/rules.ts +35 -0
- package/src/cli/templates/skill.ts +55 -0
- package/src/cli/ui/prompts.ts +122 -0
- package/src/core/boundary/evaluator.ts +426 -0
- package/src/core/boundary/staged-auditor.ts +120 -0
- package/src/core/config/domain-ownership.ts +45 -0
- package/src/core/config/loader.ts +174 -0
- package/src/core/config/schema.ts +59 -0
- package/src/core/database/client.ts +60 -0
- package/src/core/database/repositories/dependency.repository.ts +733 -0
- package/src/core/database/repositories/domain.repository.ts +373 -0
- package/src/core/database/repositories/file.repository.ts +117 -0
- package/src/core/database/repositories/meta.repository.ts +33 -0
- package/src/core/database/repositories/symbol.repository.ts +647 -0
- package/src/core/database/repository.ts +358 -0
- package/src/core/database/schema.ts +123 -0
- package/src/core/discovery/navigation.ts +105 -0
- package/src/core/discovery/topology-detector.ts +863 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +590 -0
- package/src/core/parser/behavioral-analyzer.ts +123 -0
- package/src/core/parser/boundary-tracker.ts +458 -0
- package/src/core/parser/extractors/base.ts +71 -0
- package/src/core/parser/extractors/blade.ts +159 -0
- package/src/core/parser/extractors/csharp.ts +248 -0
- package/src/core/parser/extractors/django-semantic.ts +655 -0
- package/src/core/parser/extractors/elysia-semantic.ts +517 -0
- package/src/core/parser/extractors/express-semantic.ts +429 -0
- package/src/core/parser/extractors/fastapi-semantic.ts +702 -0
- package/src/core/parser/extractors/fastify-semantic.ts +759 -0
- package/src/core/parser/extractors/flask-semantic.ts +482 -0
- package/src/core/parser/extractors/frontend.ts +149 -0
- package/src/core/parser/extractors/go-semantic.ts +670 -0
- package/src/core/parser/extractors/go.ts +491 -0
- package/src/core/parser/extractors/hono-semantic.ts +546 -0
- package/src/core/parser/extractors/java.ts +227 -0
- package/src/core/parser/extractors/laravel-semantic.ts +1150 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +367 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +527 -0
- package/src/core/parser/extractors/php.ts +585 -0
- package/src/core/parser/extractors/python.ts +503 -0
- package/src/core/parser/extractors/registry.ts +99 -0
- package/src/core/parser/extractors/ruby.ts +237 -0
- package/src/core/parser/extractors/rust.ts +304 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +24 -0
- package/src/core/parser/extractors/symfony-semantic.ts +321 -0
- package/src/core/parser/extractors/typescript.ts +839 -0
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +87 -0
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +239 -0
- package/src/core/parser/schema/schema-provider-registry.ts +41 -0
- package/src/core/parser/schema/schema-provider.interface.ts +34 -0
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- package/src/core/parser/tree-sitter.ts +63 -0
- package/src/core/parser/wasm-assets.ts +25 -0
- package/src/core/parser/wasm-loader.ts +274 -0
- package/src/core/resolver/call-graph-tracer.ts +1033 -0
- package/src/core/resolver/import-resolver.ts +365 -0
- 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 +486 -0
- package/src/core/resolver/path-resolver.ts +200 -0
- 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/symbol-locator.ts +276 -0
- package/src/core/resolver/symbol-reference.ts +53 -0
- package/src/core/resolver/vertical-slice-tracer.ts +344 -0
- package/src/core/resources/ignore.ts +144 -0
- package/src/core/resources/limits.ts +14 -0
- package/src/core/resources/source-files.ts +185 -0
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +74 -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 +142 -0
- package/src/index.ts +18 -0
- package/src/mcp/schemas.ts +746 -0
- package/src/mcp/server.ts +600 -0
- package/src/mcp/tools/boundary.ts +17 -0
- package/src/mcp/tools/check-boundary.ts +382 -0
- package/src/mcp/tools/get-domain-catalog.ts +39 -0
- package/src/mcp/tools/get-symbol-impact.ts +104 -0
- package/src/mcp/tools/get-symbol.ts +399 -0
- package/src/mcp/tools/locate-symbol.ts +236 -0
- package/src/mcp/tools/map.ts +26 -0
- package/src/mcp/tools/register-domain.ts +113 -0
- package/src/mcp/tools/slice.ts +16 -0
- package/src/mcp/tools/symbol.ts +95 -0
- package/src/mcp/tools/trace-vertical-slice.ts +106 -0
- package/src/mcp/workspace-manager.ts +170 -0
- package/src/mcp/workspace-watcher.ts +202 -0
- package/src/types/index.ts +438 -0
- package/src/types/wasm.d.ts +4 -0
- package/src/utils/version-check.ts +209 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { closeSync, existsSync, lstatSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
3
|
+
import { Database } from "bun:sqlite";
|
|
4
|
+
import { SeptumConfigSchema, type ValidatedSeptumConfig } from "./schema.ts";
|
|
5
|
+
import { SeptumDatabase } from "../database/client.ts";
|
|
6
|
+
import { SeptumRepository } from "../database/repository.ts";
|
|
7
|
+
import { resolveWorkspaceRoot } from "../resolver/path-resolver.ts";
|
|
8
|
+
import type { DomainConfig } from "../../types/index.ts";
|
|
9
|
+
|
|
10
|
+
export function resolveDatabasePath(root: string, dbPath = ".septum/septum.db"): string {
|
|
11
|
+
return dbPath === ":memory:" || isAbsolute(dbPath) ? dbPath : resolve(root, dbPath);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ConfigLoader {
|
|
15
|
+
/** Read configuration without initializing or modifying workspace state. */
|
|
16
|
+
public static load(
|
|
17
|
+
dbPath?: string,
|
|
18
|
+
projectRoot?: string
|
|
19
|
+
): ValidatedSeptumConfig {
|
|
20
|
+
const root = resolveWorkspaceRoot(projectRoot);
|
|
21
|
+
const configFilePath = join(root, "septum.config.json");
|
|
22
|
+
if (existsSync(configFilePath)) {
|
|
23
|
+
const diskConfig = ConfigLoader.loadFromDisk(configFilePath);
|
|
24
|
+
if (dbPath) diskConfig.settings.db_path = dbPath;
|
|
25
|
+
return diskConfig;
|
|
26
|
+
}
|
|
27
|
+
return ConfigLoader.loadFromDatabaseOrDefaults(resolveDatabasePath(root, dbPath));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The file owns policy when present; retain unknown user fields on updates. */
|
|
31
|
+
public static writeDomain(root: string, name: string, domain: DomainConfig, expected: string): void {
|
|
32
|
+
const file = join(root, "septum.config.json");
|
|
33
|
+
const lock = `${file}.lock`;
|
|
34
|
+
const fd = openSync(lock, "wx");
|
|
35
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
36
|
+
try {
|
|
37
|
+
if (!lstatSync(file).isFile() || lstatSync(file).isSymbolicLink()) throw new Error("Policy file must be a regular file.");
|
|
38
|
+
if (readFileSync(file, "utf8") !== expected) throw new Error("Policy changed during registration; reload and retry.");
|
|
39
|
+
const raw = JSON.parse(expected);
|
|
40
|
+
const domains = { ...raw.domains };
|
|
41
|
+
const key = Object.keys(domains).find(key => key.toLowerCase() === name.toLowerCase()) ?? name;
|
|
42
|
+
domains[key] = { ...domains[key], ...domain };
|
|
43
|
+
const updated = { ...raw, domains };
|
|
44
|
+
SeptumConfigSchema.parse(updated);
|
|
45
|
+
writeFileSync(temporary, JSON.stringify(updated, null, 2) + "\n", { flag: "wx", mode: lstatSync(file).mode & 0o777 });
|
|
46
|
+
if (readFileSync(file, "utf8") !== expected) throw new Error("Policy changed during registration; reload and retry.");
|
|
47
|
+
renameSync(temporary, file);
|
|
48
|
+
} finally {
|
|
49
|
+
closeSync(fd);
|
|
50
|
+
rmSync(temporary, { force: true });
|
|
51
|
+
rmSync(lock, { force: true });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public static loadFromDisk(filePath: string): ValidatedSeptumConfig {
|
|
56
|
+
try {
|
|
57
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
58
|
+
const parsed = JSON.parse(raw);
|
|
59
|
+
const defaults = ConfigLoader.getDefaultConfig();
|
|
60
|
+
const merged = {
|
|
61
|
+
...defaults,
|
|
62
|
+
...parsed,
|
|
63
|
+
settings: {
|
|
64
|
+
...defaults.settings,
|
|
65
|
+
...(parsed.settings || {}),
|
|
66
|
+
},
|
|
67
|
+
domains: parsed.domains || {},
|
|
68
|
+
};
|
|
69
|
+
return SeptumConfigSchema.parse(merged);
|
|
70
|
+
} catch (err: any) {
|
|
71
|
+
throw new Error(`Failed to load configuration from '${filePath}': ${err.message || err}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public static syncDiskConfigToDatabase(
|
|
76
|
+
dbPath: string,
|
|
77
|
+
diskConfig: ValidatedSeptumConfig,
|
|
78
|
+
workspaceRoot?: string
|
|
79
|
+
): void {
|
|
80
|
+
if (!existsSync(dbPath)) return;
|
|
81
|
+
const septumDb = new SeptumDatabase(dbPath);
|
|
82
|
+
const repo = new SeptumRepository(septumDb.raw);
|
|
83
|
+
try {
|
|
84
|
+
repo.runInTransaction(() => {
|
|
85
|
+
repo.setMeta("settings_json", JSON.stringify(diskConfig.settings));
|
|
86
|
+
if (diskConfig.domains && Object.keys(diskConfig.domains).length > 0) {
|
|
87
|
+
const domainNames = Object.keys(diskConfig.domains);
|
|
88
|
+
for (const [name, domain] of Object.entries(diskConfig.domains)) {
|
|
89
|
+
repo.upsertDomain(name, domain, workspaceRoot);
|
|
90
|
+
}
|
|
91
|
+
repo.pruneDomainsNotIn(domainNames);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
} finally {
|
|
95
|
+
septumDb.close();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public static getDefaultConfig(): ValidatedSeptumConfig {
|
|
100
|
+
return {
|
|
101
|
+
version: "1.0",
|
|
102
|
+
settings: {
|
|
103
|
+
enforcement: "warn",
|
|
104
|
+
db_path: ".septum/septum.db",
|
|
105
|
+
ignore_patterns: [
|
|
106
|
+
"node_modules/**",
|
|
107
|
+
"vendor/**",
|
|
108
|
+
"dist/**",
|
|
109
|
+
"build/**",
|
|
110
|
+
"out/**",
|
|
111
|
+
"target/**",
|
|
112
|
+
"coverage/**",
|
|
113
|
+
".venv/**",
|
|
114
|
+
"venv/**",
|
|
115
|
+
"__pycache__/**",
|
|
116
|
+
"tests/**",
|
|
117
|
+
"scripts/**",
|
|
118
|
+
"bin/**",
|
|
119
|
+
".git/**",
|
|
120
|
+
".septum/**",
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
domains: {},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
public static loadFromRepository(repo: SeptumRepository): ValidatedSeptumConfig {
|
|
128
|
+
const config = ConfigLoader.getDefaultConfig();
|
|
129
|
+
if (repo && typeof repo.getAllDomains === "function") {
|
|
130
|
+
const rows = repo.getAllDomains();
|
|
131
|
+
for (const row of rows) {
|
|
132
|
+
config.domains[row.name] = {
|
|
133
|
+
root: row.root_path,
|
|
134
|
+
allowed_dependencies: JSON.parse(row.allowed_deps_json || "[]"),
|
|
135
|
+
forbidden_dependencies: JSON.parse(row.forbidden_deps_json || "[]"),
|
|
136
|
+
archetypes: JSON.parse(row.archetypes_json || "{}"),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (typeof repo?.getMeta === "function") {
|
|
142
|
+
const settings = repo.getMeta("settings_json");
|
|
143
|
+
if (settings) Object.assign(config.settings, JSON.parse(settings));
|
|
144
|
+
}
|
|
145
|
+
return config;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public static loadFromDatabaseOrDefaults(dbPath: string = ".septum/septum.db"): ValidatedSeptumConfig {
|
|
149
|
+
const config = ConfigLoader.getDefaultConfig();
|
|
150
|
+
config.settings.db_path = dbPath;
|
|
151
|
+
|
|
152
|
+
if (existsSync(dbPath)) {
|
|
153
|
+
try {
|
|
154
|
+
const db = new Database(dbPath, { readonly: true });
|
|
155
|
+
const tables = db
|
|
156
|
+
.query<{ name: string }, [string]>(
|
|
157
|
+
"SELECT name FROM sqlite_master WHERE type='table' AND name = ?"
|
|
158
|
+
)
|
|
159
|
+
.get("domains");
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
if (tables) Object.assign(config, ConfigLoader.loadFromRepository(new SeptumRepository(db)));
|
|
163
|
+
config.settings.db_path = dbPath;
|
|
164
|
+
} finally {
|
|
165
|
+
db.close();
|
|
166
|
+
}
|
|
167
|
+
} catch {
|
|
168
|
+
throw new Error(`Cannot load Septum configuration from '${dbPath}'.`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return config;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const DomainConfigSchema = z.object({
|
|
4
|
+
root: z.string().min(1, "root path cannot be empty"),
|
|
5
|
+
description: z.string().optional(),
|
|
6
|
+
allowed_dependencies: z.array(z.string()).default([]),
|
|
7
|
+
forbidden_dependencies: z.array(z.string()).default([]),
|
|
8
|
+
archetypes: z.record(z.string()).optional().default({}),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const SeptumConfigSchema = z.object({
|
|
12
|
+
version: z.string().default("1.0"),
|
|
13
|
+
settings: z
|
|
14
|
+
.object({
|
|
15
|
+
enforcement: z.enum(["strict", "warn"]).default("strict"),
|
|
16
|
+
db_path: z.string().default(".septum/septum.db"),
|
|
17
|
+
ignore_patterns: z
|
|
18
|
+
.array(z.string())
|
|
19
|
+
.default([
|
|
20
|
+
"node_modules/**",
|
|
21
|
+
"vendor/**",
|
|
22
|
+
"dist/**",
|
|
23
|
+
"build/**",
|
|
24
|
+
"out/**",
|
|
25
|
+
"target/**",
|
|
26
|
+
"coverage/**",
|
|
27
|
+
".venv/**",
|
|
28
|
+
"venv/**",
|
|
29
|
+
"__pycache__/**",
|
|
30
|
+
"tests/**",
|
|
31
|
+
"scripts/**",
|
|
32
|
+
"bin/**",
|
|
33
|
+
".git/**",
|
|
34
|
+
]),
|
|
35
|
+
})
|
|
36
|
+
.default({
|
|
37
|
+
enforcement: "strict",
|
|
38
|
+
db_path: ".septum/septum.db",
|
|
39
|
+
ignore_patterns: [
|
|
40
|
+
"node_modules/**",
|
|
41
|
+
"vendor/**",
|
|
42
|
+
"dist/**",
|
|
43
|
+
"build/**",
|
|
44
|
+
"out/**",
|
|
45
|
+
"target/**",
|
|
46
|
+
"coverage/**",
|
|
47
|
+
".venv/**",
|
|
48
|
+
"venv/**",
|
|
49
|
+
"__pycache__/**",
|
|
50
|
+
"tests/**",
|
|
51
|
+
"scripts/**",
|
|
52
|
+
"bin/**",
|
|
53
|
+
".git/**",
|
|
54
|
+
],
|
|
55
|
+
}),
|
|
56
|
+
domains: z.record(DomainConfigSchema).default({}),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export type ValidatedSeptumConfig = z.infer<typeof SeptumConfigSchema>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Database } from "bun:sqlite";
|
|
2
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
3
|
+
import { dirname } from "node:path";
|
|
4
|
+
import { initializeDatabaseSchema } from "./schema.ts";
|
|
5
|
+
|
|
6
|
+
export class SeptumDatabase {
|
|
7
|
+
private db: Database;
|
|
8
|
+
private dbPath: string;
|
|
9
|
+
|
|
10
|
+
constructor(dbPath: string = ".septum/septum.db") {
|
|
11
|
+
this.dbPath = dbPath;
|
|
12
|
+
const dir = dirname(dbPath);
|
|
13
|
+
if (!existsSync(dir)) {
|
|
14
|
+
mkdirSync(dir, { recursive: true });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
this.db = new Database(dbPath, { create: true });
|
|
19
|
+
this.configurePragmas();
|
|
20
|
+
this.initSchema();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
23
|
+
if (/not a database|database disk image is malformed|file is not a database|malformed database schema/i.test(message)) {
|
|
24
|
+
throw new Error(`SQLite database at '${dbPath}' appears corrupt: ${message}. Stop Septum, back up the database and any matching -wal/-shm files, then diagnose or restore the backup manually. Septum did not remove or replace the files.`);
|
|
25
|
+
}
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private configurePragmas(): void {
|
|
31
|
+
this.db.run("PRAGMA journal_mode = WAL;");
|
|
32
|
+
this.db.run("PRAGMA busy_timeout = 5000;");
|
|
33
|
+
this.db.run("PRAGMA foreign_keys = ON;");
|
|
34
|
+
this.db.run("PRAGMA synchronous = NORMAL;");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private initSchema(): void {
|
|
38
|
+
initializeDatabaseSchema(this.db);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public get raw(): Database {
|
|
42
|
+
return this.db;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public close(): void {
|
|
46
|
+
this.db.close();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public transaction<T>(fn: () => T): T {
|
|
50
|
+
return this.db.transaction(fn)();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public checkpoint(): void {
|
|
54
|
+
try {
|
|
55
|
+
this.db.run("PRAGMA wal_checkpoint(PASSIVE);");
|
|
56
|
+
} catch {
|
|
57
|
+
// Ignore if locked or busy
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|