septum 0.1.0 → 0.1.2

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.
Files changed (65) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +100 -100
  3. package/bin/septum.ts +4 -4
  4. package/package.json +63 -62
  5. package/src/cli/commands/check.ts +161 -161
  6. package/src/cli/commands/hook.ts +188 -188
  7. package/src/cli/commands/ingest.ts +29 -29
  8. package/src/cli/commands/init.ts +211 -211
  9. package/src/cli/commands/locate.ts +61 -61
  10. package/src/cli/commands/query.ts +64 -64
  11. package/src/cli/commands/serve.ts +5 -5
  12. package/src/cli/commands/slice.ts +90 -90
  13. package/src/cli/commands/sync.ts +31 -31
  14. package/src/cli/index.ts +199 -178
  15. package/src/cli/templates/hooks.ts +75 -75
  16. package/src/cli/templates/rules.ts +38 -38
  17. package/src/cli/templates/skill.ts +66 -66
  18. package/src/core/boundary/evaluator.ts +210 -210
  19. package/src/core/config/loader.ts +84 -84
  20. package/src/core/config/schema.ts +39 -39
  21. package/src/core/database/client.ts +44 -132
  22. package/src/core/database/repositories/dependency.repository.ts +279 -279
  23. package/src/core/database/repositories/domain.repository.ts +198 -198
  24. package/src/core/database/repositories/file.repository.ts +99 -99
  25. package/src/core/database/repositories/meta.repository.ts +33 -33
  26. package/src/core/database/repositories/symbol.repository.ts +424 -424
  27. package/src/core/database/repository.ts +242 -242
  28. package/src/core/database/schema.ts +120 -0
  29. package/src/core/discovery/topology-detector.ts +418 -418
  30. package/src/core/ingestion/hasher.ts +5 -5
  31. package/src/core/ingestion/pipeline.ts +438 -438
  32. package/src/core/parser/boundary-tracker.ts +128 -128
  33. package/src/core/parser/extractors/base.ts +60 -60
  34. package/src/core/parser/extractors/frontend.ts +194 -194
  35. package/src/core/parser/extractors/go.ts +176 -176
  36. package/src/core/parser/extractors/laravel-semantic.ts +426 -426
  37. package/src/core/parser/extractors/mcp-cli-semantic.ts +199 -199
  38. package/src/core/parser/extractors/nestjs-semantic.ts +119 -119
  39. package/src/core/parser/extractors/php.ts +149 -149
  40. package/src/core/parser/extractors/python.ts +226 -226
  41. package/src/core/parser/extractors/registry.ts +49 -49
  42. package/src/core/parser/extractors/semantic-extractor.interface.ts +21 -21
  43. package/src/core/parser/extractors/typescript.ts +177 -177
  44. package/src/core/parser/tree-sitter.ts +39 -39
  45. package/src/core/resolver/call-graph-tracer.ts +668 -668
  46. package/src/core/resolver/module-resolver.ts +342 -323
  47. package/src/core/resolver/symbol-locator.ts +543 -405
  48. package/src/core/resolver/vertical-slice-tracer.ts +237 -236
  49. package/src/core/session/session-manager.ts +56 -56
  50. package/src/core/telemetry/telemetry.ts +86 -86
  51. package/src/index.ts +18 -18
  52. package/src/mcp/schemas.ts +68 -68
  53. package/src/mcp/server.ts +612 -602
  54. package/src/mcp/tools/check-boundary.ts +102 -102
  55. package/src/mcp/tools/get-domain-catalog.ts +91 -91
  56. package/src/mcp/tools/get-feature-context.ts +116 -116
  57. package/src/mcp/tools/get-symbol-hotspots.ts +49 -49
  58. package/src/mcp/tools/get-symbol-impact.ts +26 -26
  59. package/src/mcp/tools/get-symbol.ts +63 -63
  60. package/src/mcp/tools/locate-symbol.ts +74 -74
  61. package/src/mcp/tools/register-domain.ts +64 -64
  62. package/src/mcp/tools/trace-vertical-slice.ts +102 -102
  63. package/src/types/index.ts +296 -296
  64. package/src/version.ts +3 -0
  65. package/src/core/database/schema.sql +0 -92
@@ -1,84 +1,84 @@
1
- import { existsSync } from "node:fs";
2
- import { Database } from "bun:sqlite";
3
- import type { ValidatedSeptumConfig } from "./schema.ts";
4
- import { TopologyDetector } from "../discovery/topology-detector.ts";
5
- import { SeptumDatabase } from "../database/client.ts";
6
- import { SeptumRepository } from "../database/repository.ts";
7
-
8
- export class ConfigLoader {
9
- /**
10
- * Loads configuration with SQLite as the Single Source of Truth (SSOT).
11
- * Automatically executes Zero-Config TopologyDetector if the database has no domains.
12
- */
13
- public static load(dbPath: string = ".septum/septum.db"): ValidatedSeptumConfig {
14
- // 1. If database exists and has registered domains, load directly from SQLite SSOT
15
- if (existsSync(dbPath)) {
16
- const dbConfig = ConfigLoader.loadFromDatabaseOrDefaults(dbPath);
17
- if (Object.keys(dbConfig.domains).length > 0) {
18
- return dbConfig;
19
- }
20
- }
21
-
22
- // 2. Zero-Config Auto-Discovery: Discover project topology and persist to SQLite
23
- const septumDb = new SeptumDatabase(dbPath);
24
- const repo = new SeptumRepository(septumDb.raw);
25
- TopologyDetector.discoverAndPersist(repo, process.cwd());
26
- septumDb.close();
27
-
28
- return ConfigLoader.loadFromDatabaseOrDefaults(dbPath);
29
- }
30
-
31
- public static getDefaultConfig(): ValidatedSeptumConfig {
32
- return {
33
- version: "1.0",
34
- settings: {
35
- enforcement: "warn",
36
- db_path: ".septum/septum.db",
37
- ignore_patterns: [
38
- "node_modules/**",
39
- "vendor/**",
40
- "dist/**",
41
- "build/**",
42
- "tests/**",
43
- ".git/**",
44
- ".septum/**",
45
- ],
46
- },
47
- domains: {},
48
- features: {},
49
- };
50
- }
51
-
52
- public static loadFromDatabaseOrDefaults(dbPath: string = ".septum/septum.db"): ValidatedSeptumConfig {
53
- const config = ConfigLoader.getDefaultConfig();
54
- config.settings.db_path = dbPath;
55
-
56
- if (existsSync(dbPath)) {
57
- try {
58
- const db = new Database(dbPath, { readonly: true });
59
- const tables = db
60
- .query<{ name: string }, [string]>(
61
- "SELECT name FROM sqlite_master WHERE type='table' AND name = ?"
62
- )
63
- .get("domains");
64
-
65
- if (tables) {
66
- const rows = db.query<any, []>("SELECT * FROM domains").all();
67
- for (const r of rows) {
68
- config.domains[r.name] = {
69
- root: r.root_path,
70
- allowed_dependencies: JSON.parse(r.allowed_deps_json || "[]"),
71
- forbidden_dependencies: JSON.parse(r.forbidden_deps_json || "[]"),
72
- archetypes: JSON.parse(r.archetypes_json || "{}"),
73
- };
74
- }
75
- }
76
- db.close();
77
- } catch {
78
- // Fallback gracefully to default config
79
- }
80
- }
81
-
82
- return config;
83
- }
84
- }
1
+ import { existsSync } from "node:fs";
2
+ import { Database } from "bun:sqlite";
3
+ import type { ValidatedSeptumConfig } from "./schema.ts";
4
+ import { TopologyDetector } from "../discovery/topology-detector.ts";
5
+ import { SeptumDatabase } from "../database/client.ts";
6
+ import { SeptumRepository } from "../database/repository.ts";
7
+
8
+ export class ConfigLoader {
9
+ /**
10
+ * Loads configuration with SQLite as the Single Source of Truth (SSOT).
11
+ * Automatically executes Zero-Config TopologyDetector if the database has no domains.
12
+ */
13
+ public static load(dbPath: string = ".septum/septum.db"): ValidatedSeptumConfig {
14
+ // 1. If database exists and has registered domains, load directly from SQLite SSOT
15
+ if (existsSync(dbPath)) {
16
+ const dbConfig = ConfigLoader.loadFromDatabaseOrDefaults(dbPath);
17
+ if (Object.keys(dbConfig.domains).length > 0) {
18
+ return dbConfig;
19
+ }
20
+ }
21
+
22
+ // 2. Zero-Config Auto-Discovery: Discover project topology and persist to SQLite
23
+ const septumDb = new SeptumDatabase(dbPath);
24
+ const repo = new SeptumRepository(septumDb.raw);
25
+ TopologyDetector.discoverAndPersist(repo, process.cwd());
26
+ septumDb.close();
27
+
28
+ return ConfigLoader.loadFromDatabaseOrDefaults(dbPath);
29
+ }
30
+
31
+ public static getDefaultConfig(): ValidatedSeptumConfig {
32
+ return {
33
+ version: "1.0",
34
+ settings: {
35
+ enforcement: "warn",
36
+ db_path: ".septum/septum.db",
37
+ ignore_patterns: [
38
+ "node_modules/**",
39
+ "vendor/**",
40
+ "dist/**",
41
+ "build/**",
42
+ "tests/**",
43
+ ".git/**",
44
+ ".septum/**",
45
+ ],
46
+ },
47
+ domains: {},
48
+ features: {},
49
+ };
50
+ }
51
+
52
+ public static loadFromDatabaseOrDefaults(dbPath: string = ".septum/septum.db"): ValidatedSeptumConfig {
53
+ const config = ConfigLoader.getDefaultConfig();
54
+ config.settings.db_path = dbPath;
55
+
56
+ if (existsSync(dbPath)) {
57
+ try {
58
+ const db = new Database(dbPath, { readonly: true });
59
+ const tables = db
60
+ .query<{ name: string }, [string]>(
61
+ "SELECT name FROM sqlite_master WHERE type='table' AND name = ?"
62
+ )
63
+ .get("domains");
64
+
65
+ if (tables) {
66
+ const rows = db.query<any, []>("SELECT * FROM domains").all();
67
+ for (const r of rows) {
68
+ config.domains[r.name] = {
69
+ root: r.root_path,
70
+ allowed_dependencies: JSON.parse(r.allowed_deps_json || "[]"),
71
+ forbidden_dependencies: JSON.parse(r.forbidden_deps_json || "[]"),
72
+ archetypes: JSON.parse(r.archetypes_json || "{}"),
73
+ };
74
+ }
75
+ }
76
+ db.close();
77
+ } catch {
78
+ // Fallback gracefully to default config
79
+ }
80
+ }
81
+
82
+ return config;
83
+ }
84
+ }
@@ -1,39 +1,39 @@
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 FeatureConfigSchema = z.object({
12
- domain: z.string().min(1, "domain reference is required"),
13
- description: z.string().optional(),
14
- allowed_touchpoints: z.array(z.string()).min(1, "allowed_touchpoints must contain at least one file/path"),
15
- reuse_symbols: z.array(z.string()).optional().default([]),
16
- input_contract: z.record(z.unknown()).optional().default({}),
17
- output_contract: z.record(z.unknown()).optional().default({}),
18
- });
19
-
20
- export const SeptumConfigSchema = z.object({
21
- version: z.string().default("1.0"),
22
- settings: z
23
- .object({
24
- enforcement: z.enum(["strict", "warn"]).default("strict"),
25
- db_path: z.string().default(".septum/septum.db"),
26
- ignore_patterns: z
27
- .array(z.string())
28
- .default(["node_modules/**", "vendor/**", "dist/**", "build/**", "tests/**", ".git/**"]),
29
- })
30
- .default({
31
- enforcement: "strict",
32
- db_path: ".septum/septum.db",
33
- ignore_patterns: ["node_modules/**", "vendor/**", "dist/**", "build/**", "tests/**", ".git/**"],
34
- }),
35
- domains: z.record(DomainConfigSchema).default({}),
36
- features: z.record(FeatureConfigSchema).optional().default({}),
37
- });
38
-
39
- export type ValidatedSeptumConfig = z.infer<typeof SeptumConfigSchema>;
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 FeatureConfigSchema = z.object({
12
+ domain: z.string().min(1, "domain reference is required"),
13
+ description: z.string().optional(),
14
+ allowed_touchpoints: z.array(z.string()).min(1, "allowed_touchpoints must contain at least one file/path"),
15
+ reuse_symbols: z.array(z.string()).optional().default([]),
16
+ input_contract: z.record(z.unknown()).optional().default({}),
17
+ output_contract: z.record(z.unknown()).optional().default({}),
18
+ });
19
+
20
+ export const SeptumConfigSchema = z.object({
21
+ version: z.string().default("1.0"),
22
+ settings: z
23
+ .object({
24
+ enforcement: z.enum(["strict", "warn"]).default("strict"),
25
+ db_path: z.string().default(".septum/septum.db"),
26
+ ignore_patterns: z
27
+ .array(z.string())
28
+ .default(["node_modules/**", "vendor/**", "dist/**", "build/**", "tests/**", ".git/**"]),
29
+ })
30
+ .default({
31
+ enforcement: "strict",
32
+ db_path: ".septum/septum.db",
33
+ ignore_patterns: ["node_modules/**", "vendor/**", "dist/**", "build/**", "tests/**", ".git/**"],
34
+ }),
35
+ domains: z.record(DomainConfigSchema).default({}),
36
+ features: z.record(FeatureConfigSchema).optional().default({}),
37
+ });
38
+
39
+ export type ValidatedSeptumConfig = z.infer<typeof SeptumConfigSchema>;
@@ -1,132 +1,44 @@
1
- import { Database } from "bun:sqlite";
2
- import { existsSync, mkdirSync, readFileSync } from "node:fs";
3
- import { dirname, join } from "node:path";
4
-
5
- export class SeptumDatabase {
6
- private db: Database;
7
- private dbPath: string;
8
-
9
- constructor(dbPath: string = ".septum/septum.db") {
10
- this.dbPath = dbPath;
11
- const dir = dirname(dbPath);
12
- if (!existsSync(dir)) {
13
- mkdirSync(dir, { recursive: true });
14
- }
15
-
16
- this.db = new Database(dbPath, { create: true });
17
- this.configurePragmas();
18
- this.initSchema();
19
- }
20
-
21
- private configurePragmas(): void {
22
- this.db.run("PRAGMA journal_mode = WAL;");
23
- this.db.run("PRAGMA foreign_keys = ON;");
24
- this.db.run("PRAGMA synchronous = NORMAL;");
25
- }
26
-
27
- private initSchema(): void {
28
- const schemaFile = join(import.meta.dir, "schema.sql");
29
- if (existsSync(schemaFile)) {
30
- const sql = readFileSync(schemaFile, "utf-8");
31
- this.db.run(sql);
32
- } else {
33
- // Fallback inline schema if schema.sql is not found in compiled bundle
34
- this.db.run(`
35
- CREATE TABLE IF NOT EXISTS domains (
36
- id INTEGER PRIMARY KEY AUTOINCREMENT,
37
- name TEXT NOT NULL UNIQUE,
38
- root_path TEXT NOT NULL,
39
- allowed_deps_json TEXT NOT NULL DEFAULT '[]',
40
- forbidden_deps_json TEXT NOT NULL DEFAULT '[]',
41
- archetypes_json TEXT NOT NULL DEFAULT '{}',
42
- created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
43
- updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
44
- );
45
- CREATE TABLE IF NOT EXISTS files (
46
- id INTEGER PRIMARY KEY AUTOINCREMENT,
47
- domain_id INTEGER NOT NULL,
48
- path TEXT NOT NULL UNIQUE,
49
- archetype TEXT NOT NULL DEFAULT 'unknown',
50
- content_hash TEXT NOT NULL,
51
- line_count INTEGER NOT NULL DEFAULT 0,
52
- last_scanned_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
53
- FOREIGN KEY (domain_id) REFERENCES domains(id) ON DELETE CASCADE
54
- );
55
- CREATE TABLE IF NOT EXISTS symbols (
56
- id INTEGER PRIMARY KEY AUTOINCREMENT,
57
- file_id INTEGER NOT NULL,
58
- name TEXT NOT NULL,
59
- kind TEXT NOT NULL,
60
- signature TEXT NOT NULL,
61
- visibility TEXT NOT NULL DEFAULT 'public',
62
- line_start INTEGER NOT NULL DEFAULT 0,
63
- line_end INTEGER NOT NULL DEFAULT 0,
64
- FOREIGN KEY (file_id) REFERENCES files(id) ON DELETE CASCADE
65
- );
66
- CREATE TABLE IF NOT EXISTS dependencies (
67
- id INTEGER PRIMARY KEY AUTOINCREMENT,
68
- source_file_id INTEGER NOT NULL,
69
- target_symbol_or_path TEXT NOT NULL,
70
- import_statement TEXT NOT NULL,
71
- line_number INTEGER NOT NULL DEFAULT 0,
72
- is_external BOOLEAN NOT NULL DEFAULT 0,
73
- FOREIGN KEY (source_file_id) REFERENCES files(id) ON DELETE CASCADE
74
- );
75
- CREATE TABLE IF NOT EXISTS vertical_slices (
76
- id INTEGER PRIMARY KEY AUTOINCREMENT,
77
- domain_id INTEGER,
78
- feature_key TEXT,
79
- http_method TEXT NOT NULL,
80
- route_uri TEXT NOT NULL,
81
- route_name TEXT,
82
- controller_class TEXT NOT NULL,
83
- action_name TEXT NOT NULL,
84
- controller_file TEXT,
85
- controller_line INTEGER DEFAULT 0,
86
- architecture_style TEXT NOT NULL DEFAULT 'clean',
87
- entry_kind TEXT NOT NULL DEFAULT 'http_route',
88
- execution_chain_json TEXT NOT NULL,
89
- created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
90
- FOREIGN KEY (domain_id) REFERENCES domains(id) ON DELETE CASCADE
91
- );
92
- CREATE INDEX IF NOT EXISTS idx_slices_route_uri ON vertical_slices(route_uri);
93
- CREATE INDEX IF NOT EXISTS idx_slices_route_name ON vertical_slices(route_name);
94
- CREATE INDEX IF NOT EXISTS idx_slices_controller ON vertical_slices(controller_class, action_name);
95
- CREATE TABLE IF NOT EXISTS repo_meta (
96
- key TEXT PRIMARY KEY,
97
- value TEXT NOT NULL,
98
- updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
99
- );
100
- `);
101
- }
102
- this.migrateSchema();
103
- }
104
-
105
- private migrateSchema(): void {
106
- try {
107
- const tableInfo = this.db.query<{ name: string }, []>("PRAGMA table_info(vertical_slices)").all();
108
- const existingCols = new Set(tableInfo.map((c) => c.name));
109
-
110
- if (tableInfo.length > 0) {
111
- if (existingCols.has("form_request_class") || !existingCols.has("execution_chain_json")) {
112
- this.db.run("DROP TABLE IF EXISTS vertical_slices;");
113
- this.initSchema();
114
- }
115
- }
116
- } catch (_) {
117
- // Ignore migration errors
118
- }
119
- }
120
-
121
- public get raw(): Database {
122
- return this.db;
123
- }
124
-
125
- public close(): void {
126
- this.db.close();
127
- }
128
-
129
- public transaction<T>(fn: () => T): T {
130
- return this.db.transaction(fn)();
131
- }
132
- }
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
+ this.db = new Database(dbPath, { create: true });
18
+ this.configurePragmas();
19
+ this.initSchema();
20
+ }
21
+
22
+ private configurePragmas(): void {
23
+ this.db.run("PRAGMA journal_mode = WAL;");
24
+ this.db.run("PRAGMA busy_timeout = 5000;");
25
+ this.db.run("PRAGMA foreign_keys = ON;");
26
+ this.db.run("PRAGMA synchronous = NORMAL;");
27
+ }
28
+
29
+ private initSchema(): void {
30
+ initializeDatabaseSchema(this.db);
31
+ }
32
+
33
+ public get raw(): Database {
34
+ return this.db;
35
+ }
36
+
37
+ public close(): void {
38
+ this.db.close();
39
+ }
40
+
41
+ public transaction<T>(fn: () => T): T {
42
+ return this.db.transaction(fn)();
43
+ }
44
+ }