@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 shironim
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,143 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Septum
|
|
2
|
+
|
|
3
|
+
> **Architecture boundary guard and codebase intelligence for AI coding agents.**
|
|
4
|
+
|
|
5
|
+
[](package.json)
|
|
6
|
+
[](https://bun.sh)
|
|
7
|
+
[](https://modelcontextprotocol.io/)
|
|
8
|
+
[-003B57?logo=sqlite)](https://sqlite.org/)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
|
|
11
|
+
Septum provides architecture maps, declaration context, and boundary checks for AI coding agents before and after edits. It indexes source in a local SQLite database and evaluates configured domain dependency rules. Results describe detected relationships and analysis limits; application behavior still requires application verification.
|
|
12
|
+
|
|
13
|
+
Start with the [implemented feature documentation](docs/feature/README.md), which describes the reviewed source checkout, tool behavior and known limits. Installed binaries and running MCP processes can use a different revision.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Option 1: Standalone Binary
|
|
20
|
+
|
|
21
|
+
The standalone executable bundles its runtime. The installation scripts select a release executable for the platform:
|
|
22
|
+
|
|
23
|
+
**Linux & macOS:**
|
|
24
|
+
```bash
|
|
25
|
+
curl -fsSL https://raw.githubusercontent.com/Shironim/septum-mcp/master/install.sh | bash
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Windows (PowerShell):**
|
|
29
|
+
```powershell
|
|
30
|
+
irm https://raw.githubusercontent.com/Shironim/septum-mcp/master/install.ps1 | iex
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
> **Manual Downloads:** Precompiled 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`.
|
|
34
|
+
|
|
35
|
+
### Option 2: Via Bun
|
|
36
|
+
|
|
37
|
+
If you already use [Bun](https://bun.sh):
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
bun add -g @dimassetoid/septum-mcp
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
You can invoke the package with `bunx @dimassetoid/septum-mcp <command>`.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
### 1. Initialize a Workspace
|
|
50
|
+
|
|
51
|
+
Run `septum init` from the workspace directory you want Septum to manage:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
septum init
|
|
55
|
+
# or via bunx:
|
|
56
|
+
bunx @dimassetoid/septum-mcp init
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Initialization:
|
|
60
|
+
|
|
61
|
+
1. **Infers Project Structure:** Uses supported manifests and directory layouts to propose domains and dependency policies.
|
|
62
|
+
2. **Indexes Supported Source:** Stores extracted declarations, imports and static entrypoints in the configured database; the default is `.septum/septum.db`.
|
|
63
|
+
3. **Scaffolds Selected Agent Configurations:** Writes MCP configuration, skills and hook artifacts for supported environments:
|
|
64
|
+
- **Antigravity** (`.gemini/`)
|
|
65
|
+
- **Claude Code** (`.claude/`, `.mcp.json`, `CLAUDE.md`)
|
|
66
|
+
- **Codex** (`.codex/`)
|
|
67
|
+
- **Opencode** (`opencode/`, `opencode.json`)
|
|
68
|
+
- **.agents Standard** (`.agents/`, `AGENTS.md`)
|
|
69
|
+
|
|
70
|
+
Semantic adapters cover selected patterns in Laravel, Symfony, MCP/CLI, NestJS, Express, Fastify, Hono, Elysia, FastAPI, Django, Flask and Go. Their applicability and extraction results depend on repository syntax and configuration.
|
|
71
|
+
|
|
72
|
+
Import resolution includes supported Python manifests/lockfiles, Go workspaces/replacements, Rust Cargo/modules, Ruby literal requires/gems, Java source projects and C# namespaces/project references. See [import resolution](docs/feature/import-resolution.md) for supported cases and unresolved boundaries.
|
|
73
|
+
|
|
74
|
+
Detection and scaffolding do not certify every framework pattern or active client hook. See the [feature specifications and architecture contracts](docs/feature/README.md) for full scope and technical details.
|
|
75
|
+
|
|
76
|
+
### 2. Manual MCP Client Configuration (Optional)
|
|
77
|
+
|
|
78
|
+
If your MCP client is not configured via `septum init`, add Septum to your MCP configuration (`.mcp.json` or `claude_desktop_config.json`):
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"mcpServers": {
|
|
83
|
+
"septum": {
|
|
84
|
+
"command": "septum",
|
|
85
|
+
"args": ["serve"]
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
*(Or use `"command": "bunx", "args": ["@dimassetoid/septum-mcp", "serve"]` when invoking the package through Bun).*
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## CLI Reference
|
|
95
|
+
|
|
96
|
+
| Command | Description |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `septum init [--force]` | Scaffold agent integrations and build initial symbol catalog. `--force` regenerates Septum-managed configs while preserving existing database and user git hooks |
|
|
99
|
+
| `septum sync [--json]` | Synchronize AST and update symbol catalog into `.septum/septum.db` (full or incremental) |
|
|
100
|
+
| `septum check [--strict] [--staged] [--json]` | Verify boundary rules and detect cross-domain or circular dependency violations |
|
|
101
|
+
| `septum hook pre-write` | Reconstruct supported candidate edits from stdin and evaluate their imports; interception depends on the client and hook configuration |
|
|
102
|
+
| `septum serve` | Start stdio Model Context Protocol (MCP) server |
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## MCP Tools
|
|
107
|
+
|
|
108
|
+
All tools provide structured schemas via the Model Context Protocol:
|
|
109
|
+
|
|
110
|
+
- **Domain Map & Discovery (`septum_map`):**
|
|
111
|
+
- `action: "catalog"`: Navigation map (`navigation/v1`): domain/file import paths, static entrypoints, health and targeted next steps. `full` expands navigation; inspect signatures and source with `septum_symbol`.
|
|
112
|
+
- `action: "register"`: Register or update domain boundaries with allowed and forbidden dependencies.
|
|
113
|
+
- **Symbol Inspection & Impact Analysis (`septum_symbol`):**
|
|
114
|
+
- `action: "locate"`: Search and find symbols across the codebase.
|
|
115
|
+
- `action: "context"` (accepts `action: "inspect"` as alias): Retrieve declaration implementation and supporting declarations (deep TypeScript context retrieval within `budget_bytes`, or bounded polyglot source inspection).
|
|
116
|
+
- `action: "impact"`: Inspect static dependent/caller hints. Imports are reported separately and do not prove executed calls or a complete runtime blast radius.
|
|
117
|
+
- **Execution Flow Tracer (`septum_slice`):**
|
|
118
|
+
- Navigate static context across application layers from supported entrypoints (`query`, `controller_file`, `max_depth`). Each node shows its relationship evidence or `unknown`.
|
|
119
|
+
- **Dependency & Boundary Validator (`septum_boundary`):**
|
|
120
|
+
- Validate proposed file imports against defined architectural rules (`scope: "file"`).
|
|
121
|
+
- Check staged files in the Git index before commit (`scope: "staged"`).
|
|
122
|
+
- Audit circular dependencies and boundary violations for a specific domain (`scope: "domain"`) or the entire codebase (`scope: "all"`).
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Select context before editing
|
|
127
|
+
|
|
128
|
+
Locate a declaration, select its returned `symbol_ref` when names are ambiguous, then request context:
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{"action":"context","query":"submit","file_path":"src/submit.ts","budget_bytes":65536}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Send these arguments to `septum_symbol` with an explicit `workspace_path` when needed. Context v4 supports `.ts/.mts/.cts` and selects supporting declarations through bounded local/import bindings. Set `context_mode: "deep"` explicitly for this policy, or `context_mode: "source"` for bounded source inspection. Omission preserves legacy automatic selection; responses identify the selected mode. TSX and complete business dependency closure are outside the deep-context policy.
|
|
135
|
+
|
|
136
|
+
Read evidence scope, freshness and omissions before editing. Context inspection returns source/contracts; lookup and server freshness guards can synchronize the local index. Use impact for potential consumers and application checks for behavior. Budget, paging, source identity and recovery semantics have one owner: the [symbol context contract](docs/feature/symbol-context-contract.md). Per-action requirements are in [septum_symbol](docs/feature/septum-symbol.md).
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## License
|
|
141
|
+
|
|
142
|
+
[MIT](LICENSE) © shironim
|
|
2
143
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/bin/septum.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dimassetoid/septum-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Deterministic Bounded-Context, Structural File Catalog & Anti-Poisoning Partition for AI Agents",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "src/index.ts",
|
|
10
|
+
"bin": {
|
|
11
|
+
"septum-mcp": "./bin/septum.ts",
|
|
12
|
+
"septum": "./bin/septum.ts"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"bun": ">=1.1.0"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"start": "bun run bin/septum.ts",
|
|
19
|
+
"serve": "bun run bin/septum.ts serve",
|
|
20
|
+
"ingest": "bun run bin/septum.ts sync",
|
|
21
|
+
"sync": "bun run bin/septum.ts sync",
|
|
22
|
+
"check": "bun run bin/septum.ts check",
|
|
23
|
+
"test": "bun test",
|
|
24
|
+
"build": "bun build ./bin/septum.ts --compile --outfile dist/septum",
|
|
25
|
+
"compile:all": "bun run scripts/compile.ts",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"test:integration": "python3 tests/integration/mcp-reliability.py",
|
|
28
|
+
"postinstall": "bun run scripts/postinstall.ts || true"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@modelcontextprotocol/sdk": "^1.5.0",
|
|
32
|
+
"web-tree-sitter": "^0.24.0",
|
|
33
|
+
"yaml": "^2.7.0",
|
|
34
|
+
"zod": "^3.24.2",
|
|
35
|
+
"tree-sitter-wasms": "^0.1.13",
|
|
36
|
+
"typescript": "^5.7.3"
|
|
37
|
+
},
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/shironim/septum-mcp.git"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/shironim/septum-mcp#readme",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/shironim/septum-mcp/issues"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"mcp",
|
|
49
|
+
"model-context-protocol",
|
|
50
|
+
"bounded-context",
|
|
51
|
+
"architecture",
|
|
52
|
+
"ai-agent",
|
|
53
|
+
"tree-sitter",
|
|
54
|
+
"clean-architecture",
|
|
55
|
+
"domain-driven-design",
|
|
56
|
+
"codebase-catalog",
|
|
57
|
+
"antigravity"
|
|
58
|
+
],
|
|
59
|
+
"files": [
|
|
60
|
+
"bin",
|
|
61
|
+
"src",
|
|
62
|
+
"scripts/postinstall.ts",
|
|
63
|
+
"dist/*.js",
|
|
64
|
+
"dist/*.d.ts",
|
|
65
|
+
"README.md",
|
|
66
|
+
"LICENSE"
|
|
67
|
+
],
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/bun": "latest",
|
|
70
|
+
"@types/node": "^22.13.4"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { SEPTUM_VERSION } from "../src/version.ts";
|
|
3
|
+
|
|
4
|
+
function printBanner(): void {
|
|
5
|
+
const v = `v${SEPTUM_VERSION}`;
|
|
6
|
+
console.log(`
|
|
7
|
+
\x1b[36m╭─────────────────────────────────────────────────────────────╮\x1b[0m
|
|
8
|
+
\x1b[36m│\x1b[0m \x1b[36m│\x1b[0m
|
|
9
|
+
\x1b[36m│\x1b[0m \x1b[32m✓\x1b[0m \x1b[1mSeptum ${v}\x1b[0m successfully installed! \x1b[36m│\x1b[0m
|
|
10
|
+
\x1b[36m│\x1b[0m \x1b[36m│\x1b[0m
|
|
11
|
+
\x1b[36m│\x1b[0m \x1b[1mNext Steps:\x1b[0m \x1b[36m│\x1b[0m
|
|
12
|
+
\x1b[36m│\x1b[0m 1. Navigate to your project directory: \x1b[36m│\x1b[0m
|
|
13
|
+
\x1b[36m│\x1b[0m \x1b[36m$ cd /path/to/your-project\x1b[0m \x1b[36m│\x1b[0m
|
|
14
|
+
\x1b[36m│\x1b[0m 2. Initialize local guard & configure AI agent harness: \x1b[36m│\x1b[0m
|
|
15
|
+
\x1b[36m│\x1b[0m \x1b[36m$ septum init\x1b[0m \x1b[36m│\x1b[0m
|
|
16
|
+
\x1b[36m│\x1b[0m \x1b[36m│\x1b[0m
|
|
17
|
+
\x1b[36m╰─────────────────────────────────────────────────────────────╯\x1b[0m
|
|
18
|
+
`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
printBanner();
|
|
23
|
+
} catch {
|
|
24
|
+
// Postinstall output failure should never abort installation
|
|
25
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
|
|
2
|
+
import { ConfigLoader, resolveDatabasePath } from "../../core/config/loader.ts";
|
|
3
|
+
import { SeptumDatabase } from "../../core/database/client.ts";
|
|
4
|
+
import { SeptumRepository } from "../../core/database/repository.ts";
|
|
5
|
+
import type { BoundaryViolation } from "../../types/index.ts";
|
|
6
|
+
import { IngestionPipeline } from "../../core/ingestion/pipeline.ts";
|
|
7
|
+
import { auditStagedFiles } from "../../core/boundary/staged-auditor.ts";
|
|
8
|
+
import { resolveWorkspaceRoot } from "../../core/resolver/path-resolver.ts";
|
|
9
|
+
import { ModuleResolver } from "../../core/resolver/module-resolver.ts";
|
|
10
|
+
|
|
11
|
+
export interface CheckCommandOptions {
|
|
12
|
+
strict?: boolean;
|
|
13
|
+
staged?: boolean;
|
|
14
|
+
domain?: string;
|
|
15
|
+
json?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function handleCheckCommand(
|
|
19
|
+
optionsOrStrict?: boolean | CheckCommandOptions
|
|
20
|
+
): Promise<void> {
|
|
21
|
+
const options: CheckCommandOptions =
|
|
22
|
+
typeof optionsOrStrict === "boolean" ? { strict: optionsOrStrict } : optionsOrStrict || {};
|
|
23
|
+
|
|
24
|
+
if (!options.json) {
|
|
25
|
+
console.log(
|
|
26
|
+
options.staged
|
|
27
|
+
? "[Septum] Auditing git staged files against domain boundaries..."
|
|
28
|
+
: "[Septum] Running codebase boundary integrity check..."
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const workspaceRoot = resolveWorkspaceRoot(process.cwd());
|
|
33
|
+
const config = ConfigLoader.load(undefined, workspaceRoot);
|
|
34
|
+
if (options.strict) config.settings.enforcement = "strict";
|
|
35
|
+
const db = new SeptumDatabase(resolveDatabasePath(workspaceRoot, config.settings.db_path));
|
|
36
|
+
const repo = new SeptumRepository(db.raw);
|
|
37
|
+
const evaluator = new BoundaryEvaluator(repo, new ModuleResolver(workspaceRoot, repo));
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
let violations: BoundaryViolation[] = [];
|
|
41
|
+
|
|
42
|
+
const totalDomains = Object.keys(config.domains).length;
|
|
43
|
+
if (!options.staged && totalDomains === 0) {
|
|
44
|
+
const isStrict = options.strict || config.settings.enforcement === "strict";
|
|
45
|
+
if (options.json) {
|
|
46
|
+
console.log(JSON.stringify({
|
|
47
|
+
status: "not_indexed",
|
|
48
|
+
strict: isStrict,
|
|
49
|
+
violations: [],
|
|
50
|
+
message: "No domains registered in workspace. Run 'septum init' first to discover and register domains.",
|
|
51
|
+
}, null, 2));
|
|
52
|
+
} else {
|
|
53
|
+
console.warn("[Septum Warning] No domains registered in workspace. Run 'septum init' first to discover and register domains.");
|
|
54
|
+
}
|
|
55
|
+
if (isStrict) process.exitCode = 1;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (options.staged) {
|
|
60
|
+
const staged = await auditStagedFiles(evaluator, config, workspaceRoot, repo);
|
|
61
|
+
violations = staged.violations;
|
|
62
|
+
if (staged.resolution_issues.length && violations.length === 0) {
|
|
63
|
+
console.warn(options.json ? JSON.stringify({ status: "unknown", resolution_issues: staged.resolution_issues }) : "Staged import resolution is incomplete; approval is unknown.");
|
|
64
|
+
if (options.strict || config.settings.enforcement === "strict") process.exitCode = 1;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
await new IngestionPipeline(repo, workspaceRoot).run(config, { verifyContent: true });
|
|
69
|
+
const unsupported = JSON.parse(repo.getMeta("unsupported_files") || "[]") as string[];
|
|
70
|
+
if (unsupported.length > 0) {
|
|
71
|
+
throw new Error(`Cannot complete boundary audit: unsupported source files: ${unsupported.join(", ")}`);
|
|
72
|
+
}
|
|
73
|
+
const skipped = JSON.parse(repo.getMeta("skipped_files") || "[]") as {path: string}[];
|
|
74
|
+
if (skipped.length) throw new Error(`Cannot complete boundary audit: files exceed resource limits: ${skipped.map(file => file.path).join(", ")}`);
|
|
75
|
+
violations = evaluator.auditCodebase(config);
|
|
76
|
+
const incomplete = repo.getImportRelationships(workspaceRoot).filter(edge => edge.freshness !== "current" || edge.index_coverage !== "complete" || !["resolved","external"].includes(edge.resolution.status) || edge.resolution.coverage === "conditional");
|
|
77
|
+
if (incomplete.length && violations.length === 0) {
|
|
78
|
+
const strict = options.strict || config.settings.enforcement === "strict";
|
|
79
|
+
const payload = { status: "unknown", relationships: incomplete, message: "Import resolution is incomplete; boundary approval is unknown." };
|
|
80
|
+
console.warn(options.json ? JSON.stringify(payload) : payload.message);
|
|
81
|
+
if (strict) process.exitCode = 1;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (options.json) {
|
|
87
|
+
const isStrict = options.strict || config.settings.enforcement === "strict";
|
|
88
|
+
console.log(JSON.stringify({
|
|
89
|
+
status: violations.length === 0 ? "clean" : "violations_found",
|
|
90
|
+
strict: isStrict,
|
|
91
|
+
violations,
|
|
92
|
+
}, null, 2));
|
|
93
|
+
if (violations.length > 0 && isStrict) process.exitCode = 1;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (violations.length === 0) {
|
|
98
|
+
console.log("✓ All domain boundaries are clean. Zero cross-domain leaks detected.");
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const isStrict = options.strict || config.settings.enforcement === "strict";
|
|
103
|
+
|
|
104
|
+
if (isStrict) {
|
|
105
|
+
console.error(`\n[Septum Boundary Violation] Found ${violations.length} boundary violation(s) [STRICT MODE - BLOCKED]:\n`);
|
|
106
|
+
|
|
107
|
+
for (const v of violations) {
|
|
108
|
+
console.error(` ✕ [${v.rule.toUpperCase()}] at ${v.file}:${v.line}`);
|
|
109
|
+
console.error(` Source Domain: ${v.source_domain}`);
|
|
110
|
+
console.error(` Target Domain: ${v.target_domain}`);
|
|
111
|
+
console.error(` Import Target: ${v.imported_target}`);
|
|
112
|
+
console.error(` Message: ${v.message}\n`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
console.error("[Septum Failure] Process terminated with exit code 1 due to boundary violations in strict mode.");
|
|
116
|
+
process.exitCode = 1;
|
|
117
|
+
} else {
|
|
118
|
+
console.warn(`\n[Septum Boundary Advisory] Found ${violations.length} boundary advisory item(s) (enforcement: warn - non-blocking):\n`);
|
|
119
|
+
|
|
120
|
+
for (const v of violations) {
|
|
121
|
+
console.warn(` • [${v.rule.toUpperCase()}] at ${v.file}:${v.line}`);
|
|
122
|
+
console.warn(` Source Domain: ${v.source_domain}`);
|
|
123
|
+
console.warn(` Target Domain: ${v.target_domain}`);
|
|
124
|
+
console.warn(` Import Target: ${v.imported_target}`);
|
|
125
|
+
console.warn(` Message: ${v.message}\n`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
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");
|
|
129
|
+
}
|
|
130
|
+
} finally {
|
|
131
|
+
db.close();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
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";
|
|
4
|
+
import * as fs from "node:fs";
|
|
5
|
+
import * as path from "node:path";
|
|
6
|
+
import { BoundaryEvaluator } from "../../core/boundary/evaluator.ts";
|
|
7
|
+
import { ConfigLoader, resolveDatabasePath } from "../../core/config/loader.ts";
|
|
8
|
+
import { SeptumDatabase } from "../../core/database/client.ts";
|
|
9
|
+
import { SeptumRepository } from "../../core/database/repository.ts";
|
|
10
|
+
import { ASTParserEngine } from "../../core/parser/tree-sitter.ts";
|
|
11
|
+
import { ModuleResolver } from "../../core/resolver/module-resolver.ts";
|
|
12
|
+
|
|
13
|
+
interface ToolCallInfo {
|
|
14
|
+
name?: string;
|
|
15
|
+
args?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ToolPayload {
|
|
19
|
+
tool_name?: string;
|
|
20
|
+
toolCall?: ToolCallInfo;
|
|
21
|
+
tool_input?: {
|
|
22
|
+
TargetFile?: string;
|
|
23
|
+
file_path?: string;
|
|
24
|
+
filePath?: string;
|
|
25
|
+
path?: string;
|
|
26
|
+
Path?: string;
|
|
27
|
+
ReplacementContent?: string;
|
|
28
|
+
CodeContent?: string;
|
|
29
|
+
new_string?: string;
|
|
30
|
+
content?: string;
|
|
31
|
+
Content?: string;
|
|
32
|
+
Replacement?: string;
|
|
33
|
+
ReplacementChunks?: Array<{ ReplacementContent?: string }>;
|
|
34
|
+
};
|
|
35
|
+
arguments?: Record<string, unknown>;
|
|
36
|
+
TargetFile?: string;
|
|
37
|
+
file_path?: string;
|
|
38
|
+
filePath?: string;
|
|
39
|
+
path?: string;
|
|
40
|
+
Path?: string;
|
|
41
|
+
ReplacementContent?: string;
|
|
42
|
+
CodeContent?: string;
|
|
43
|
+
new_string?: string;
|
|
44
|
+
content?: string;
|
|
45
|
+
Content?: string;
|
|
46
|
+
Replacement?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let configuredExitCode = 1;
|
|
50
|
+
|
|
51
|
+
export async function handleHookCommand(args: string[]): Promise<void> {
|
|
52
|
+
const subHook = args[1] || "pre-write";
|
|
53
|
+
if (args.includes("--exit-code-2") || args.includes("--claude") || args.includes("--cursor")) {
|
|
54
|
+
configuredExitCode = 2;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (subHook === "pre-write") {
|
|
58
|
+
await runPreWriteHook();
|
|
59
|
+
} else {
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function blockHook(db: SeptumDatabase | null, reason: string): never {
|
|
65
|
+
if (db) {
|
|
66
|
+
try {
|
|
67
|
+
db.close();
|
|
68
|
+
} catch {
|
|
69
|
+
// ignore
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Print readable error to stderr for humans and Claude/Cursor/Codex
|
|
74
|
+
console.error(reason);
|
|
75
|
+
|
|
76
|
+
// Print JSON contract to stdout for Antigravity hook engine
|
|
77
|
+
try {
|
|
78
|
+
process.stdout.write(
|
|
79
|
+
JSON.stringify({
|
|
80
|
+
decision: "deny",
|
|
81
|
+
reason: reason.trim(),
|
|
82
|
+
}) + "\n"
|
|
83
|
+
);
|
|
84
|
+
} catch {
|
|
85
|
+
// ignore
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Exit code: 1 by default (Unix standard), or 2 if specified for Claude Code / Cursor hooks
|
|
89
|
+
process.exit(configuredExitCode);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function runPreWriteHook(): Promise<void> {
|
|
93
|
+
const callerRoot = process.cwd();
|
|
94
|
+
const workspaceRoot = path.resolve(process.env.SEPTUM_HOOK_ROOT || callerRoot);
|
|
95
|
+
const config = ConfigLoader.load(undefined, workspaceRoot);
|
|
96
|
+
const dbPath = resolveDatabasePath(workspaceRoot, config.settings.db_path);
|
|
97
|
+
if (!fs.existsSync(dbPath)) {
|
|
98
|
+
process.exit(0);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Read JSON payload from stdin
|
|
102
|
+
const stdinData = await readStdin();
|
|
103
|
+
if (!stdinData.trim()) {
|
|
104
|
+
process.exit(0);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
let payload: ToolPayload;
|
|
108
|
+
try {
|
|
109
|
+
payload = JSON.parse(stdinData);
|
|
110
|
+
} catch {
|
|
111
|
+
// Non-JSON stdin, pass through
|
|
112
|
+
process.exit(0);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let edit;
|
|
116
|
+
try {
|
|
117
|
+
edit = normalizeHookEdit(payload, target => {
|
|
118
|
+
const file = path.resolve(callerRoot, target);
|
|
119
|
+
assertPathContained(file, workspaceRoot, "Hook source");
|
|
120
|
+
return readSourceFile(file);
|
|
121
|
+
});
|
|
122
|
+
if (edit) assertPathContained(path.resolve(callerRoot, edit.target), workspaceRoot, "Hook target");
|
|
123
|
+
} catch (error) { blockHook(null, error instanceof Error ? error.message : String(error)); }
|
|
124
|
+
if (!edit) {
|
|
125
|
+
process.stdout.write(JSON.stringify({ decision: "allow", coverage: "unknown", reason: "Unsupported hook payload; no source candidate was evaluated." }) + "\n");
|
|
126
|
+
process.exit(0);
|
|
127
|
+
}
|
|
128
|
+
const targetFile = path.relative(workspaceRoot, path.resolve(callerRoot, edit.target)).replace(/\\/g, "/");
|
|
129
|
+
const content = edit.content;
|
|
130
|
+
|
|
131
|
+
const db = new SeptumDatabase(dbPath);
|
|
132
|
+
const repo = new SeptumRepository(db.raw);
|
|
133
|
+
const evaluator = new BoundaryEvaluator(repo, new ModuleResolver(workspaceRoot, repo));
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
const sourceDomain = evaluator.resolveSourceDomain(targetFile, config);
|
|
137
|
+
|
|
138
|
+
// Real-time AST Import Interception:
|
|
139
|
+
// Extract imports from proposed content and check for boundary leaks
|
|
140
|
+
if (content && sourceDomain) {
|
|
141
|
+
const astEngine = new ASTParserEngine();
|
|
142
|
+
const parsed = await astEngine.parseFile(targetFile, content);
|
|
143
|
+
if (ASTParserEngine.isSourceFile(targetFile) && (parsed.status === "unsupported" || parsed.status === "degraded")) {
|
|
144
|
+
throw new Error(`Cannot reliably check imports in '${targetFile}': parser status is ${parsed.status}.`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const proposedImports = parsed.dependencies.map((d) => d.target);
|
|
148
|
+
const boundaryViolations = evaluator.checkProposedChanges(
|
|
149
|
+
targetFile,
|
|
150
|
+
proposedImports,
|
|
151
|
+
config,
|
|
152
|
+
parsed.dependencies.map(d => d.statement)
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
if (boundaryViolations.length > 0) {
|
|
156
|
+
const v = boundaryViolations[0];
|
|
157
|
+
blockHook(
|
|
158
|
+
db,
|
|
159
|
+
`\n[SEPTUM BOUNDARY VIOLATION - Forbidden Cross-Domain Import]\n` +
|
|
160
|
+
`✕ Operation blocked: Proposed code imports forbidden domain '${v.target_domain}' from '${v.source_domain}'.\n` +
|
|
161
|
+
`▶ OFFENDING IMPORT: ${v.imported_target}\n` +
|
|
162
|
+
`▶ RULE: ${v.rule}\n` +
|
|
163
|
+
`▶ MESSAGE: ${v.message}\n` +
|
|
164
|
+
`▶ REQUIRED ACTION: Decouple this dependency. Use an authorized Interface, Event, or Shared Kernel.\n`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
db.close();
|
|
170
|
+
|
|
171
|
+
// If running in Antigravity or standard JSON IPC mode, emit allow decision
|
|
172
|
+
try {
|
|
173
|
+
process.stdout.write(JSON.stringify({ decision: "allow", coverage: edit.coverage, evaluated: sourceDomain ? "proposed_imports" : "unmapped_domain" }) + "\n");
|
|
174
|
+
} catch {
|
|
175
|
+
// ignore
|
|
176
|
+
}
|
|
177
|
+
process.exit(0);
|
|
178
|
+
} catch (err) {
|
|
179
|
+
db.close();
|
|
180
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
181
|
+
console.error(`\x1b[31m[Septum Hook Error]\x1b[0m ${message}`);
|
|
182
|
+
process.exit(configuredExitCode);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function readStdin(): Promise<string> {
|
|
187
|
+
return new Promise((resolve) => {
|
|
188
|
+
let data = "";
|
|
189
|
+
if (process.stdin.isTTY) {
|
|
190
|
+
resolve("");
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
process.stdin.setEncoding("utf-8");
|
|
195
|
+
process.stdin.on("data", (chunk) => {
|
|
196
|
+
data += chunk;
|
|
197
|
+
});
|
|
198
|
+
process.stdin.on("end", () => {
|
|
199
|
+
resolve(data);
|
|
200
|
+
});
|
|
201
|
+
process.stdin.on("error", () => {
|
|
202
|
+
resolve("");
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|