@dimassetoid/septum-mcp 0.2.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -45
- package/package.json +8 -6
- package/src/cli/commands/check.ts +41 -26
- package/src/cli/commands/hook.ts +77 -105
- package/src/cli/commands/init.ts +35 -9
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +35 -9
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +15 -51
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +51 -27
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +46 -35
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +299 -178
- package/src/core/boundary/staged-auditor.ts +188 -34
- package/src/core/config/domain-ownership.ts +47 -0
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +82 -54
- package/src/core/config/schema.ts +24 -46
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +326 -543
- package/src/core/database/repositories/domain.repository.ts +48 -4
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -259
- package/src/core/database/repository.ts +138 -24
- package/src/core/database/schema.ts +28 -33
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +269 -0
- package/src/core/discovery/topology-detector.ts +153 -170
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +378 -212
- package/src/core/parser/behavioral-analyzer.ts +26 -22
- package/src/core/parser/boundary-tracker.ts +15 -0
- package/src/core/parser/extractors/base.ts +16 -4
- package/src/core/parser/extractors/csharp.ts +9 -5
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +400 -516
- package/src/core/parser/extractors/elysia-semantic.ts +172 -496
- package/src/core/parser/extractors/express-semantic.ts +195 -398
- package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
- package/src/core/parser/extractors/fastify-semantic.ts +216 -732
- package/src/core/parser/extractors/flask-semantic.ts +92 -388
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +210 -508
- package/src/core/parser/extractors/go.ts +6 -3
- package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
- package/src/core/parser/extractors/hono-semantic.ts +132 -530
- package/src/core/parser/extractors/java.ts +7 -5
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +169 -333
- package/src/core/parser/extractors/manifest-helpers.ts +64 -0
- package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +84 -336
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
- package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
- package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
- package/src/core/parser/extractors/php.ts +17 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +9 -8
- package/src/core/parser/extractors/registry.ts +28 -5
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +10 -7
- package/src/core/parser/extractors/rust.ts +35 -17
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +75 -262
- package/src/core/parser/extractors/typescript-bindings.ts +333 -0
- package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
- package/src/core/parser/extractors/typescript-fallback.ts +207 -0
- package/src/core/parser/extractors/typescript-route-context.ts +58 -0
- package/src/core/parser/extractors/typescript.ts +36 -216
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +23 -7
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
- package/src/core/parser/schema/schema-provider-registry.ts +1 -3
- package/src/core/parser/schema/schema-provider.interface.ts +2 -1
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- package/src/core/parser/wasm-loader.ts +6 -2
- package/src/core/resolver/ast-method-tracer.ts +230 -0
- package/src/core/resolver/call-graph-helpers.ts +72 -0
- package/src/core/resolver/call-graph-tracer.ts +375 -311
- package/src/core/resolver/dependency-analysis.ts +593 -0
- package/src/core/resolver/import-candidates.ts +120 -0
- package/src/core/resolver/import-evidence.ts +88 -0
- package/src/core/resolver/import-resolver.ts +162 -181
- package/src/core/resolver/interpretation-inputs.ts +65 -0
- package/src/core/resolver/languages/go.ts +103 -0
- package/src/core/resolver/languages/managed.ts +200 -0
- package/src/core/resolver/languages/python.ts +133 -0
- package/src/core/resolver/languages/ruby.ts +40 -0
- package/src/core/resolver/languages/rust.ts +127 -0
- package/src/core/resolver/languages/shared.ts +74 -0
- package/src/core/resolver/module-resolver.ts +18 -7
- package/src/core/resolver/path-resolver.ts +6 -3
- package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
- package/src/core/resolver/slice-catalog.ts +94 -0
- package/src/core/resolver/slice-format.ts +22 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +477 -0
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +57 -278
- package/src/core/resources/ignore.ts +21 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +116 -0
- package/src/core/retrieval/context.ts +457 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/source-context.ts +448 -0
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +293 -0
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +225 -37
- package/src/index.ts +0 -3
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +253 -0
- package/src/mcp/schemas/boundary.ts +145 -0
- package/src/mcp/schemas/map.ts +250 -0
- package/src/mcp/schemas/shared.ts +52 -0
- package/src/mcp/schemas/slice.ts +60 -0
- package/src/mcp/schemas/symbol.ts +268 -0
- package/src/mcp/schemas.ts +5 -1105
- package/src/mcp/server.ts +263 -597
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +69 -4
- package/src/mcp/tools/map.ts +126 -0
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +480 -26
- package/src/mcp/ui/app-client.ts +899 -0
- package/src/mcp/ui/app.html +478 -0
- package/src/mcp/workflow-playbooks.ts +181 -0
- package/src/mcp/workspace-boundary.ts +50 -0
- package/src/mcp/workspace-manager.ts +102 -18
- package/src/mcp/workspace-watcher.ts +38 -19
- package/src/types/index.ts +47 -53
- package/src/cli/commands/topology.ts +0 -161
- package/src/core/database/repositories/environment.repository.ts +0 -207
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
- package/src/core/session/session-manager.ts +0 -107
- package/src/core/topology/environment-detector.ts +0 -973
- package/src/core/topology/types.ts +0 -83
- package/src/mcp/tools/check-boundary.ts +0 -387
- package/src/mcp/tools/domain.ts +0 -40
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-domain-catalog.ts +0 -226
- package/src/mcp/tools/get-environment-topology.ts +0 -138
- package/src/mcp/tools/get-feature-context.ts +0 -224
- package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
- package/src/mcp/tools/get-symbol-impact.ts +0 -64
- package/src/mcp/tools/get-symbol.ts +0 -175
- package/src/mcp/tools/locate-symbol.ts +0 -196
- package/src/mcp/tools/register-domain.ts +0 -75
- package/src/mcp/tools/register-feature.ts +0 -110
- package/src/mcp/tools/trace-vertical-slice.ts +0 -80
package/README.md
CHANGED
|
@@ -1,22 +1,39 @@
|
|
|
1
1
|
# Septum
|
|
2
2
|
|
|
3
|
-
> **
|
|
3
|
+
> **Local codebase intelligence and architecture boundary guard for AI coding agents.**
|
|
4
4
|
|
|
5
|
-
[](package.json)
|
|
6
6
|
[](https://bun.sh)
|
|
7
7
|
[](https://modelcontextprotocol.io/)
|
|
8
8
|
[-003B57?logo=sqlite)](https://sqlite.org/)
|
|
9
9
|
[](LICENSE)
|
|
10
10
|
|
|
11
|
-
Septum
|
|
11
|
+
Septum is a local static-analysis MCP server and CLI that keeps AI coding agents oriented and within architectural boundaries. Instead of reading entire files or guessing module rules, agents query a local SQLite AST index (`.septum/septum.db`) for compact domain maps, budget-bounded symbol context, static flow slices, and deterministic import/boundary checks before and after edits.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## What It Does
|
|
16
|
+
|
|
17
|
+
- **Domain Map & Discovery (`septum_map`):** Provides a compact navigation catalog of domains, file import relationships, static entrypoints, and index health—and lets you register or update allowed/forbidden domain dependencies.
|
|
18
|
+
- **Bounded Symbol Context & Impact (`septum_symbol`):** Locates declarations across the codebase, retrieves bounded implementation context (deep TypeScript reference context within `budget_bytes`, or bounded polyglot source inspection), and reports static dependents and caller hints.
|
|
19
|
+
- **Static Flow Tracing (`septum_slice`):** Traces static relationship chains from supported application entrypoints (`query`, `controller_file`, `max_depth`) across layers, showing relationship evidence or `unknown` for each node.
|
|
20
|
+
- **Architecture Boundary Guard (`septum_boundary`):** Validates proposed file imports against domain rules before writing (`scope: "file"`), checks staged Git changes before commit (`scope: "staged"`), and audits circular or cross-domain violations (`scope: "domain"`, `scope: "all"`).
|
|
21
|
+
|
|
22
|
+
### Language Support & Analysis Scope
|
|
23
|
+
|
|
24
|
+
- **AST & Declarations (`web-tree-sitter` + TypeScript compiler fallback):** Partial declaration extraction for TypeScript, JavaScript, PHP, Python, Go, Rust, Java, C#, Ruby, Blade, and embedded scripts in Vue, Astro, and Svelte. TypeScript and TSX files automatically fall back to the TypeScript compiler parser when `tree-sitter-wasms` hits syntax recovery on newer syntax. Deep context (`context_mode: "deep"`) targets `.ts`, `.tsx`, `.mts`, and `.cts` files.
|
|
25
|
+
- **Entrypoint Adapters:** Selected patterns in Laravel, Symfony, MCP/CLI, NestJS, Express, Fastify, Hono, Elysia, Next.js App Router, FastAPI, Django, Flask, and Go.
|
|
26
|
+
- **Import Resolution:** Supported patterns across JS/TS, PHP, Python manifests/lockfiles, Go workspaces/replacements, Rust Cargo/modules, Ruby literal requires/gems, Java source projects, and C# namespaces/project references.
|
|
27
|
+
|
|
28
|
+
> **Static Analysis Scope:** Septum evaluates source files and dependency policies statically—it does not execute the target application or establish complete runtime call graphs. Application behavior still requires application tests. See [implemented features](docs/feature/README.md) and [import resolution](docs/feature/import-resolution.md) for full tool contracts and known limits.
|
|
12
29
|
|
|
13
30
|
---
|
|
14
31
|
|
|
15
32
|
## Installation
|
|
16
33
|
|
|
17
|
-
### Option 1: Standalone Binary
|
|
34
|
+
### Option 1: Standalone Binary
|
|
18
35
|
|
|
19
|
-
|
|
36
|
+
Precompiled executables bundle the runtime:
|
|
20
37
|
|
|
21
38
|
**Linux & macOS:**
|
|
22
39
|
```bash
|
|
@@ -28,7 +45,7 @@ curl -fsSL https://raw.githubusercontent.com/Shironim/septum-mcp/master/install.
|
|
|
28
45
|
irm https://raw.githubusercontent.com/Shironim/septum-mcp/master/install.ps1 | iex
|
|
29
46
|
```
|
|
30
47
|
|
|
31
|
-
> **Manual Downloads:**
|
|
48
|
+
> **Manual Downloads:** Binaries are also available on [GitHub Releases](https://github.com/Shironim/septum-mcp/releases) for `linux-x64`, `linux-arm64`, `darwin-x64`, `darwin-arm64`, and `windows-x64.exe`.
|
|
32
49
|
|
|
33
50
|
### Option 2: Via Bun
|
|
34
51
|
|
|
@@ -38,26 +55,27 @@ If you already use [Bun](https://bun.sh):
|
|
|
38
55
|
bun add -g @dimassetoid/septum-mcp
|
|
39
56
|
```
|
|
40
57
|
|
|
41
|
-
|
|
58
|
+
You can also invoke it directly with `bunx @dimassetoid/septum-mcp <command>`.
|
|
42
59
|
|
|
43
60
|
---
|
|
44
61
|
|
|
45
62
|
## Quick Start
|
|
46
63
|
|
|
47
|
-
### 1. Initialize
|
|
64
|
+
### 1. Initialize a Workspace
|
|
48
65
|
|
|
49
|
-
Run `septum init`
|
|
66
|
+
Run `septum init` in your project root:
|
|
50
67
|
|
|
51
68
|
```bash
|
|
52
69
|
septum init
|
|
53
|
-
# or
|
|
54
|
-
bunx septum init
|
|
70
|
+
# or via bunx:
|
|
71
|
+
bunx @dimassetoid/septum-mcp init
|
|
55
72
|
```
|
|
56
73
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
74
|
+
Initialization performs three steps:
|
|
75
|
+
|
|
76
|
+
1. **Infers Project Structure:** Uses supported manifests and directory layouts to propose domain boundaries and dependency policies.
|
|
77
|
+
2. **Indexes Supported Source:** Extracts declarations, imports, and static entrypoints into `.septum/septum.db`.
|
|
78
|
+
3. **Scaffolds Agent Integrations:** Writes MCP configs, skills, and hook artifacts for supported clients:
|
|
61
79
|
- **Antigravity** (`.gemini/`)
|
|
62
80
|
- **Claude Code** (`.claude/`, `.mcp.json`, `CLAUDE.md`)
|
|
63
81
|
- **Codex** (`.codex/`)
|
|
@@ -66,7 +84,7 @@ Septum automatically:
|
|
|
66
84
|
|
|
67
85
|
### 2. Manual MCP Client Configuration (Optional)
|
|
68
86
|
|
|
69
|
-
If your MCP client is not configured via `septum init`, add Septum to
|
|
87
|
+
If your MCP client is not configured via `septum init`, add Septum to `.mcp.json` or `claude_desktop_config.json`:
|
|
70
88
|
|
|
71
89
|
```json
|
|
72
90
|
{
|
|
@@ -78,7 +96,7 @@ If your MCP client is not configured via `septum init`, add Septum to your MCP c
|
|
|
78
96
|
}
|
|
79
97
|
}
|
|
80
98
|
```
|
|
81
|
-
*(Or use `"command": "bunx", "args": ["septum", "serve"]`
|
|
99
|
+
*(Or use `"command": "bunx", "args": ["@dimassetoid/septum-mcp", "serve"]` when invoking through Bun.)*
|
|
82
100
|
|
|
83
101
|
---
|
|
84
102
|
|
|
@@ -86,40 +104,23 @@ If your MCP client is not configured via `septum init`, add Septum to your MCP c
|
|
|
86
104
|
|
|
87
105
|
| Command | Description |
|
|
88
106
|
|---|---|
|
|
89
|
-
| `septum init [--force]` |
|
|
90
|
-
| `septum sync [--json]` | Synchronize AST and update symbol catalog
|
|
91
|
-
| `septum check [--strict] [--staged] [--
|
|
92
|
-
| `septum
|
|
93
|
-
| `septum hook pre-write` |
|
|
94
|
-
| `septum
|
|
95
|
-
| `septum serve` | Start stdio Model Context Protocol (MCP) server |
|
|
107
|
+
| `septum init [--force]` | Scaffold agent integrations and build the initial symbol catalog. `--force` regenerates Septum-managed configs while preserving the existing database and user git hooks |
|
|
108
|
+
| `septum sync [--json]` | Synchronize AST and update the symbol catalog in `.septum/septum.db` (full or incremental) |
|
|
109
|
+
| `septum check [--strict] [--staged] [--json]` | Verify boundary rules and detect cross-domain or circular dependency violations |
|
|
110
|
+
| `septum stats [workspace] [--json]` | Summarize recent MCP tool calls, error rates, and latency/size percentiles from `.septum/septum.log` |
|
|
111
|
+
| `septum hook pre-write` | Reconstruct supported candidate edits from stdin and evaluate their imports (interception depends on client hook configuration) |
|
|
112
|
+
| `septum serve` | Start the stdio Model Context Protocol (MCP) server |
|
|
96
113
|
|
|
97
114
|
---
|
|
98
115
|
|
|
99
|
-
##
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
-
|
|
104
|
-
- `action: "catalog"`: High-level architecture map and module dependencies (`detail_level: "compact" | "full"`).
|
|
105
|
-
- `action: "register"`: Register or update domain boundaries with allowed and forbidden dependencies.
|
|
106
|
-
- `action: "topology"`: Inspect deployment environment and infrastructure services.
|
|
107
|
-
- **Symbol Inspection & Impact Analysis (`septum_symbol`):**
|
|
108
|
-
- `action: "locate"`: Search and find symbols across the codebase.
|
|
109
|
-
- `action: "inspect"`: Inspect symbol declarations, signatures, and source snippets.
|
|
110
|
-
- `action: "impact"`: Analyze call graphs, dependents, and refactoring blast radius.
|
|
111
|
-
- `action: "hotspots"`: Identify complex functions based on line count and nesting depth.
|
|
112
|
-
- **Execution Flow Tracer (`septum_slice`):**
|
|
113
|
-
- Trace call chains across application layers (*Route ➔ Controller ➔ Service ➔ Repository ➔ Entity*) from HTTP endpoints, queue jobs, CLI commands, or event handlers.
|
|
114
|
-
- **Dependency & Boundary Validator (`septum_boundary`):**
|
|
115
|
-
- Validate proposed file imports against defined architectural rules (`scope: "file"`).
|
|
116
|
-
- Check staged files (`scope: "staged"`), specific domains (`scope: "domain"`), or the whole codebase (`scope: "all"`) for circular dependencies and boundary violations.
|
|
117
|
-
- **Feature Scope Management (`septum_feature`):**
|
|
118
|
-
- Restrict agent editing scope to designated touchpoint files during feature work to prevent unintended changes.
|
|
116
|
+
## Documentation
|
|
117
|
+
|
|
118
|
+
- [Implemented Features & Limits](docs/feature/README.md) — Tool behaviors, language coverage, and verification scope
|
|
119
|
+
- [Symbol Context Contract](docs/feature/symbol-context-contract.md) — Deep context selection, byte budgets, and pagination
|
|
120
|
+
- [Import Resolution](docs/feature/import-resolution.md) — Supported static targets and unresolved boundaries
|
|
119
121
|
|
|
120
122
|
---
|
|
121
123
|
|
|
122
124
|
## License
|
|
123
125
|
|
|
124
126
|
[MIT](LICENSE) © shironim
|
|
125
|
-
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dimassetoid/septum-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Deterministic Bounded-Context, Structural File Catalog & Anti-Poisoning Partition for AI Agents",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -21,18 +21,21 @@
|
|
|
21
21
|
"sync": "bun run bin/septum.ts sync",
|
|
22
22
|
"check": "bun run bin/septum.ts check",
|
|
23
23
|
"test": "bun test",
|
|
24
|
-
"build": "bun
|
|
24
|
+
"build:ui": "bun run scripts/build-mcp-app.ts",
|
|
25
|
+
"build": "bun run build:ui && bun build ./bin/septum.ts --compile --outfile dist/septum",
|
|
25
26
|
"compile:all": "bun run scripts/compile.ts",
|
|
26
27
|
"typecheck": "tsc --noEmit",
|
|
27
28
|
"test:integration": "python3 tests/integration/mcp-reliability.py",
|
|
28
29
|
"postinstall": "bun run scripts/postinstall.ts || true"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
32
|
+
"@modelcontextprotocol/ext-apps": "^2.0.4",
|
|
31
33
|
"@modelcontextprotocol/sdk": "^1.5.0",
|
|
34
|
+
"tree-sitter-wasms": "^0.1.13",
|
|
35
|
+
"typescript": "^5.7.3",
|
|
32
36
|
"web-tree-sitter": "^0.24.0",
|
|
33
37
|
"yaml": "^2.7.0",
|
|
34
|
-
"zod": "^3.24.2"
|
|
35
|
-
"tree-sitter-wasms": "^0.1.13"
|
|
38
|
+
"zod": "^3.24.2"
|
|
36
39
|
},
|
|
37
40
|
"license": "MIT",
|
|
38
41
|
"repository": {
|
|
@@ -66,7 +69,6 @@
|
|
|
66
69
|
],
|
|
67
70
|
"devDependencies": {
|
|
68
71
|
"@types/bun": "latest",
|
|
69
|
-
"@types/node": "^22.13.4"
|
|
70
|
-
"typescript": "^5.7.3"
|
|
72
|
+
"@types/node": "^22.13.4"
|
|
71
73
|
}
|
|
72
74
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { evaluateBoundary } from "../../core/boundary/audit.ts";
|
|
1
2
|
import { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
|
|
2
|
-
import { ConfigLoader } from "../../core/config/loader.ts";
|
|
3
|
+
import { ConfigLoader, resolveDatabasePath } from "../../core/config/loader.ts";
|
|
3
4
|
import { SeptumDatabase } from "../../core/database/client.ts";
|
|
4
5
|
import { SeptumRepository } from "../../core/database/repository.ts";
|
|
5
6
|
import type { BoundaryViolation } from "../../types/index.ts";
|
|
@@ -7,12 +8,11 @@ import { IngestionPipeline } from "../../core/ingestion/pipeline.ts";
|
|
|
7
8
|
import { auditStagedFiles } from "../../core/boundary/staged-auditor.ts";
|
|
8
9
|
import { resolveWorkspaceRoot } from "../../core/resolver/path-resolver.ts";
|
|
9
10
|
import { ModuleResolver } from "../../core/resolver/module-resolver.ts";
|
|
10
|
-
import { join, isAbsolute } from "node:path";
|
|
11
11
|
|
|
12
12
|
export interface CheckCommandOptions {
|
|
13
13
|
strict?: boolean;
|
|
14
14
|
staged?: boolean;
|
|
15
|
-
|
|
15
|
+
domain?: string;
|
|
16
16
|
json?: boolean;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -33,7 +33,7 @@ export async function handleCheckCommand(
|
|
|
33
33
|
const workspaceRoot = resolveWorkspaceRoot(process.cwd());
|
|
34
34
|
const config = ConfigLoader.load(undefined, workspaceRoot);
|
|
35
35
|
if (options.strict) config.settings.enforcement = "strict";
|
|
36
|
-
const db = new SeptumDatabase(
|
|
36
|
+
const db = new SeptumDatabase(resolveDatabasePath(workspaceRoot, config.settings.db_path));
|
|
37
37
|
const repo = new SeptumRepository(db.raw);
|
|
38
38
|
const evaluator = new BoundaryEvaluator(repo, new ModuleResolver(workspaceRoot, repo));
|
|
39
39
|
|
|
@@ -58,7 +58,7 @@ export async function handleCheckCommand(
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
if (options.staged) {
|
|
61
|
-
const staged = await auditStagedFiles(evaluator, config, workspaceRoot,
|
|
61
|
+
const staged = await auditStagedFiles(evaluator, config, workspaceRoot, repo);
|
|
62
62
|
violations = staged.violations;
|
|
63
63
|
if (staged.resolution_issues.length && violations.length === 0) {
|
|
64
64
|
console.warn(options.json ? JSON.stringify({ status: "unknown", resolution_issues: staged.resolution_issues }) : "Staged import resolution is incomplete; approval is unknown.");
|
|
@@ -67,18 +67,21 @@ export async function handleCheckCommand(
|
|
|
67
67
|
}
|
|
68
68
|
} else {
|
|
69
69
|
await new IngestionPipeline(repo, workspaceRoot).run(config, { verifyContent: true });
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
throw new Error(`Cannot complete boundary audit: unsupported source files: ${
|
|
70
|
+
const { payload } = await evaluateBoundary(evaluator, config, { scope: "all" }, repo, workspaceRoot);
|
|
71
|
+
if ("unsupported_files" in payload) {
|
|
72
|
+
throw new Error(`Cannot complete boundary audit: unsupported source files: ${payload.unsupported_files.join(", ")}`);
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (
|
|
74
|
+
if ("skipped_files" in payload) {
|
|
75
|
+
throw new Error(`Cannot complete boundary audit: files exceed resource limits: ${payload.skipped_files.map(file => file.path).join(", ")}`);
|
|
76
|
+
}
|
|
77
|
+
violations = "violations" in payload ? payload.violations : [];
|
|
78
|
+
if (payload.status === "unknown") {
|
|
79
79
|
const strict = options.strict || config.settings.enforcement === "strict";
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
console.warn(options.json ? JSON.stringify({
|
|
81
|
+
status: payload.status,
|
|
82
|
+
...("relationships" in payload && { relationships: payload.relationships }),
|
|
83
|
+
message: payload.message,
|
|
84
|
+
}) : payload.message);
|
|
82
85
|
if (strict) process.exitCode = 1;
|
|
83
86
|
return;
|
|
84
87
|
}
|
|
@@ -100,21 +103,33 @@ export async function handleCheckCommand(
|
|
|
100
103
|
return;
|
|
101
104
|
}
|
|
102
105
|
|
|
103
|
-
|
|
106
|
+
const isStrict = options.strict || config.settings.enforcement === "strict";
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
console.error(
|
|
107
|
-
console.error(` Source Domain: ${v.source_domain}`);
|
|
108
|
-
console.error(` Target Domain: ${v.target_domain}`);
|
|
109
|
-
console.error(` Import Target: ${v.imported_target}`);
|
|
110
|
-
console.error(` Message: ${v.message}\n`);
|
|
111
|
-
}
|
|
108
|
+
if (isStrict) {
|
|
109
|
+
console.error(`\n[Septum Boundary Violation] Found ${violations.length} boundary violation(s) [STRICT MODE - BLOCKED]:\n`);
|
|
112
110
|
|
|
111
|
+
for (const v of violations) {
|
|
112
|
+
console.error(` ✕ [${v.rule.toUpperCase()}] at ${v.file}:${v.line}`);
|
|
113
|
+
console.error(` Source Domain: ${v.source_domain}`);
|
|
114
|
+
console.error(` Target Domain: ${v.target_domain}`);
|
|
115
|
+
console.error(` Import Target: ${v.imported_target}`);
|
|
116
|
+
console.error(` Message: ${v.message}\n`);
|
|
117
|
+
}
|
|
113
118
|
|
|
114
|
-
|
|
115
|
-
if (isStrict) {
|
|
116
|
-
console.error("[Septum Failure] Process terminated with exit code 1 due to boundary violations.");
|
|
119
|
+
console.error("[Septum Failure] Process terminated with exit code 1 due to boundary violations in strict mode.");
|
|
117
120
|
process.exitCode = 1;
|
|
121
|
+
} else {
|
|
122
|
+
console.warn(`\n[Septum Boundary Advisory] Found ${violations.length} boundary advisory item(s) (enforcement: warn - non-blocking):\n`);
|
|
123
|
+
|
|
124
|
+
for (const v of violations) {
|
|
125
|
+
console.warn(` • [${v.rule.toUpperCase()}] at ${v.file}:${v.line}`);
|
|
126
|
+
console.warn(` Source Domain: ${v.source_domain}`);
|
|
127
|
+
console.warn(` Target Domain: ${v.target_domain}`);
|
|
128
|
+
console.warn(` Import Target: ${v.imported_target}`);
|
|
129
|
+
console.warn(` Message: ${v.message}\n`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
console.warn("[Septum Advisory Notice] Staged changes allowed (exit code 0). To block commits on boundary violations, configure 'enforcement: \"strict\"' in septum settings or pass '--strict'.\n");
|
|
118
133
|
}
|
|
119
134
|
} finally {
|
|
120
135
|
db.close();
|
package/src/cli/commands/hook.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { normalizeHookEdit } from "../hook-payload.ts";
|
|
2
|
+
import { assertPathContained } from "../../core/resolver/path-resolver.ts";
|
|
3
|
+
import { readSourceFile } from "../../core/resources/source-files.ts";
|
|
1
4
|
import * as fs from "node:fs";
|
|
2
5
|
import * as path from "node:path";
|
|
3
6
|
import { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
|
|
4
|
-
import { ConfigLoader } from "../../core/config/loader.ts";
|
|
7
|
+
import { ConfigLoader, resolveDatabasePath } from "../../core/config/loader.ts";
|
|
5
8
|
import { SeptumDatabase } from "../../core/database/client.ts";
|
|
6
9
|
import { SeptumRepository } from "../../core/database/repository.ts";
|
|
7
10
|
import { ASTParserEngine } from "../../core/parser/tree-sitter.ts";
|
|
8
|
-
import {
|
|
11
|
+
import { ModuleResolver } from "../../core/resolver/module-resolver.ts";
|
|
12
|
+
import { SeptumTelemetry } from "../../core/telemetry/telemetry.ts";
|
|
9
13
|
|
|
10
14
|
interface ToolCallInfo {
|
|
11
15
|
name?: string;
|
|
@@ -20,20 +24,27 @@ export interface ToolPayload {
|
|
|
20
24
|
file_path?: string;
|
|
21
25
|
filePath?: string;
|
|
22
26
|
path?: string;
|
|
27
|
+
Path?: string;
|
|
23
28
|
ReplacementContent?: string;
|
|
24
29
|
CodeContent?: string;
|
|
25
30
|
new_string?: string;
|
|
26
31
|
content?: string;
|
|
32
|
+
Content?: string;
|
|
33
|
+
Replacement?: string;
|
|
27
34
|
ReplacementChunks?: Array<{ ReplacementContent?: string }>;
|
|
28
|
-
feature_key?: string;
|
|
29
35
|
};
|
|
30
36
|
arguments?: Record<string, unknown>;
|
|
31
37
|
TargetFile?: string;
|
|
32
38
|
file_path?: string;
|
|
33
39
|
filePath?: string;
|
|
34
40
|
path?: string;
|
|
41
|
+
Path?: string;
|
|
35
42
|
ReplacementContent?: string;
|
|
36
43
|
CodeContent?: string;
|
|
44
|
+
new_string?: string;
|
|
45
|
+
content?: string;
|
|
46
|
+
Content?: string;
|
|
47
|
+
Replacement?: string;
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
let configuredExitCode = 1;
|
|
@@ -80,9 +91,15 @@ function blockHook(db: SeptumDatabase | null, reason: string): never {
|
|
|
80
91
|
}
|
|
81
92
|
|
|
82
93
|
async function runPreWriteHook(): Promise<void> {
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
94
|
+
const callerRoot = process.cwd();
|
|
95
|
+
const workspaceRoot = path.resolve(process.env.SEPTUM_HOOK_ROOT || callerRoot);
|
|
96
|
+
const configFilePath = path.join(workspaceRoot, "septum.config.json");
|
|
97
|
+
const hasDiskConfig = fs.existsSync(configFilePath);
|
|
98
|
+
const config = hasDiskConfig
|
|
99
|
+
? ConfigLoader.loadFromDisk(configFilePath)
|
|
100
|
+
: ConfigLoader.load(undefined, workspaceRoot);
|
|
101
|
+
const dbPath = resolveDatabasePath(workspaceRoot, config.settings.db_path);
|
|
102
|
+
if (!hasDiskConfig && !fs.existsSync(dbPath)) {
|
|
86
103
|
process.exit(0);
|
|
87
104
|
}
|
|
88
105
|
|
|
@@ -100,107 +117,33 @@ async function runPreWriteHook(): Promise<void> {
|
|
|
100
117
|
process.exit(0);
|
|
101
118
|
}
|
|
102
119
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
payload
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
: "";
|
|
114
|
-
const content: string =
|
|
115
|
-
toolInput.ReplacementContent ||
|
|
116
|
-
toolInput.CodeContent ||
|
|
117
|
-
toolInput.new_string ||
|
|
118
|
-
toolInput.content ||
|
|
119
|
-
chunkContent ||
|
|
120
|
-
"";
|
|
121
|
-
|
|
122
|
-
if (!targetFile) {
|
|
120
|
+
let edit;
|
|
121
|
+
try {
|
|
122
|
+
edit = normalizeHookEdit(payload, target => {
|
|
123
|
+
const file = path.resolve(callerRoot, target);
|
|
124
|
+
assertPathContained(file, workspaceRoot, "Hook source");
|
|
125
|
+
return readSourceFile(file);
|
|
126
|
+
});
|
|
127
|
+
if (edit) assertPathContained(path.resolve(callerRoot, edit.target), workspaceRoot, "Hook target");
|
|
128
|
+
} catch (error) { blockHook(null, error instanceof Error ? error.message : String(error)); }
|
|
129
|
+
if (!edit) {
|
|
130
|
+
process.stdout.write(JSON.stringify({ decision: "allow", coverage: "unknown", reason: "Unsupported hook payload; no source candidate was evaluated." }) + "\n");
|
|
123
131
|
process.exit(0);
|
|
124
132
|
}
|
|
133
|
+
const targetFile = path.relative(workspaceRoot, path.resolve(callerRoot, edit.target)).replace(/\\/g, "/");
|
|
134
|
+
const content = edit.content;
|
|
125
135
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
const
|
|
136
|
+
// Zero-SQLite fast path: when septum.config.json owns policy, evaluate proposed imports
|
|
137
|
+
// in-memory without opening SQLite on every edit.
|
|
138
|
+
const db = hasDiskConfig ? null : new SeptumDatabase(dbPath);
|
|
139
|
+
const repo = db ? new SeptumRepository(db.raw) : undefined;
|
|
140
|
+
const evaluator = new BoundaryEvaluator(repo, new ModuleResolver(workspaceRoot, repo));
|
|
130
141
|
|
|
131
142
|
try {
|
|
132
143
|
const sourceDomain = evaluator.resolveSourceDomain(targetFile, config);
|
|
133
144
|
|
|
134
|
-
//
|
|
135
|
-
if (sourceDomain) {
|
|
136
|
-
// -------------------------------------------------------------
|
|
137
|
-
// GATE 3: Mandatory Catalog Consultation
|
|
138
|
-
// Verify that the AI has consulted the domain catalog before writing
|
|
139
|
-
// -------------------------------------------------------------
|
|
140
|
-
const accessLogPath = path.resolve(process.cwd(), ".septum/catalog_access.json");
|
|
141
|
-
let hasConsulted = false;
|
|
142
|
-
|
|
143
|
-
if (fs.existsSync(accessLogPath)) {
|
|
144
|
-
try {
|
|
145
|
-
const rawAccess = JSON.parse(fs.readFileSync(accessLogPath, "utf-8"));
|
|
146
|
-
const domainsMap: Record<string, string> = rawAccess.domains || {};
|
|
147
|
-
const lowerSource = sourceDomain.toLowerCase();
|
|
148
|
-
const domainAccessedAt =
|
|
149
|
-
domainsMap[sourceDomain] ||
|
|
150
|
-
domainsMap[lowerSource] ||
|
|
151
|
-
Object.entries(domainsMap).find(([k]) => k.toLowerCase() === lowerSource)?.[1];
|
|
152
|
-
if (domainAccessedAt) {
|
|
153
|
-
hasConsulted = true;
|
|
154
|
-
}
|
|
155
|
-
} catch {
|
|
156
|
-
// ignore parse error
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (!hasConsulted) {
|
|
161
|
-
blockHook(
|
|
162
|
-
db,
|
|
163
|
-
`\n[SEPTUM GATE 3 VIOLATION - Mandatory Consultation Required]\n` +
|
|
164
|
-
`✕ Operation blocked: You are attempting to write to domain '${sourceDomain}' (${targetFile}) ` +
|
|
165
|
-
`without inspecting its authoritative symbol & file-connection catalog first.\n` +
|
|
166
|
-
`▶ REQUIRED ACTION: Call tool 'septum_domain({ action: "catalog", domain: "${sourceDomain}", detail_level: "compact" })' ` +
|
|
167
|
-
`or 'septum_feature({ action: "get" })' before writing code.\n`
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// -------------------------------------------------------------
|
|
173
|
-
// GATE 1: Hard Touchpoint Lock (if features are defined)
|
|
174
|
-
// -------------------------------------------------------------
|
|
175
|
-
const session = SessionManager.getActiveSession(process.cwd());
|
|
176
|
-
const requestedFeatureKey = toolInput.feature_key || process.env.SEPTUM_ACTIVE_FEATURE;
|
|
177
|
-
if (session && requestedFeatureKey && requestedFeatureKey !== session.feature_key) {
|
|
178
|
-
throw new Error(`Requested feature '${requestedFeatureKey}' does not own the active scope '${session.feature_key}'.`);
|
|
179
|
-
}
|
|
180
|
-
const activeFeatureKey = session?.feature_key || requestedFeatureKey;
|
|
181
|
-
|
|
182
|
-
if (activeFeatureKey) {
|
|
183
|
-
const touchpointViolations = evaluator.checkFeatureTouchpoints(
|
|
184
|
-
activeFeatureKey,
|
|
185
|
-
targetFile,
|
|
186
|
-
config
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
if (touchpointViolations.length > 0) {
|
|
190
|
-
blockHook(
|
|
191
|
-
db,
|
|
192
|
-
`\n[SEPTUM GATE 1 VIOLATION - Scope Touchpoint Lock]\n` +
|
|
193
|
-
`✕ Operation blocked: File '${targetFile}' is outside the declared allowed_touchpoints for feature '${activeFeatureKey}'.\n` +
|
|
194
|
-
`▶ REASON: ${touchpointViolations[0].message}\n` +
|
|
195
|
-
`▶ REQUIRED ACTION: Only modify files declared in allowed_touchpoints for this feature.\n`
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// -------------------------------------------------------------
|
|
201
|
-
// GATE 2: Real-time AST Import Interception
|
|
145
|
+
// Real-time AST Import Interception:
|
|
202
146
|
// Extract imports from proposed content and check for boundary leaks
|
|
203
|
-
// -------------------------------------------------------------
|
|
204
147
|
if (content && sourceDomain) {
|
|
205
148
|
const astEngine = new ASTParserEngine();
|
|
206
149
|
const parsed = await astEngine.parseFile(targetFile, content);
|
|
@@ -212,14 +155,29 @@ async function runPreWriteHook(): Promise<void> {
|
|
|
212
155
|
const boundaryViolations = evaluator.checkProposedChanges(
|
|
213
156
|
targetFile,
|
|
214
157
|
proposedImports,
|
|
215
|
-
config
|
|
158
|
+
config,
|
|
159
|
+
parsed.dependencies.map(d => d.statement)
|
|
216
160
|
);
|
|
217
161
|
|
|
218
162
|
if (boundaryViolations.length > 0) {
|
|
219
163
|
const v = boundaryViolations[0];
|
|
164
|
+
SeptumTelemetry.recordSystemEvent({
|
|
165
|
+
level: "WARN",
|
|
166
|
+
component: "hook",
|
|
167
|
+
event: "hook_decision",
|
|
168
|
+
fields: {
|
|
169
|
+
decision: "deny",
|
|
170
|
+
rule: v.rule,
|
|
171
|
+
source_domain: v.source_domain,
|
|
172
|
+
target_domain: v.target_domain,
|
|
173
|
+
zero_sqlite: hasDiskConfig,
|
|
174
|
+
},
|
|
175
|
+
workspaceRoot,
|
|
176
|
+
emitStderr: false,
|
|
177
|
+
});
|
|
220
178
|
blockHook(
|
|
221
179
|
db,
|
|
222
|
-
`\n[SEPTUM
|
|
180
|
+
`\n[SEPTUM BOUNDARY VIOLATION - Forbidden Cross-Domain Import]\n` +
|
|
223
181
|
`✕ Operation blocked: Proposed code imports forbidden domain '${v.target_domain}' from '${v.source_domain}'.\n` +
|
|
224
182
|
`▶ OFFENDING IMPORT: ${v.imported_target}\n` +
|
|
225
183
|
`▶ RULE: ${v.rule}\n` +
|
|
@@ -229,20 +187,34 @@ async function runPreWriteHook(): Promise<void> {
|
|
|
229
187
|
}
|
|
230
188
|
}
|
|
231
189
|
|
|
232
|
-
db
|
|
190
|
+
db?.close();
|
|
191
|
+
|
|
192
|
+
SeptumTelemetry.recordSystemEvent({
|
|
193
|
+
level: "INFO",
|
|
194
|
+
component: "hook",
|
|
195
|
+
event: "hook_decision",
|
|
196
|
+
fields: {
|
|
197
|
+
decision: "allow",
|
|
198
|
+
coverage: edit.coverage,
|
|
199
|
+
evaluated: sourceDomain ? "proposed_imports" : "unmapped_domain",
|
|
200
|
+
zero_sqlite: hasDiskConfig,
|
|
201
|
+
},
|
|
202
|
+
workspaceRoot,
|
|
203
|
+
emitStderr: false,
|
|
204
|
+
});
|
|
233
205
|
|
|
234
206
|
// If running in Antigravity or standard JSON IPC mode, emit allow decision
|
|
235
207
|
try {
|
|
236
|
-
process.stdout.write(JSON.stringify({ decision: "allow" }) + "\n");
|
|
208
|
+
process.stdout.write(JSON.stringify({ decision: "allow", coverage: edit.coverage, evaluated: sourceDomain ? "proposed_imports" : "unmapped_domain" }) + "\n");
|
|
237
209
|
} catch {
|
|
238
210
|
// ignore
|
|
239
211
|
}
|
|
240
212
|
process.exit(0);
|
|
241
213
|
} catch (err) {
|
|
242
|
-
db
|
|
214
|
+
db?.close();
|
|
243
215
|
const message = err instanceof Error ? err.message : String(err);
|
|
244
216
|
console.error(`\x1b[31m[Septum Hook Error]\x1b[0m ${message}`);
|
|
245
|
-
process.exit(
|
|
217
|
+
process.exit(configuredExitCode);
|
|
246
218
|
}
|
|
247
219
|
}
|
|
248
220
|
|