secufusion-mcp 2.1.6 → 2.2.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 CHANGED
@@ -24,7 +24,6 @@
24
24
  | `get_pattern_from_task` | **Phase 1** — Cross-Task Intelligence | Extracts reusable decisions, file patterns, and test scenarios from a completed task |
25
25
  | `manage_branch_state` | Legacy — Branch State | Backward-compatible branch-scoped JSON state tracker (for tasks before `manage_task`) |
26
26
  | `log_rejected_pattern` | **Phase 3** — Course Correction | Records bad patterns to `.rejected-patterns.json` so they are never repeated |
27
- | `run_pre_pr_checks_with_reviewer_agent` | **Phase 4** — PR Handoff | **NEW** — Unified 3-tier PR gate. Runs mechanical checks, AI file reviews, and context-aware task evaluation in a single pass. |
28
27
  | `get_secufusion_rules` | **Setup** | Returns the `AGENTS.md` rules for AI clients that don't natively support MCP Resources |
29
28
  | `classify_task` | **Phase 0.5** — Task Classification | **NEW** — Deep multi-pass analysis engine. Classifies any task as `BACKEND_ONLY`, `FRONTEND_ONLY`, etc. based on root cause. |
30
29
  | `prime_session` | **Phase 0** — Session Start | **NEW** — Hyper-efficient session startup. Combines Phase 00 (spec) and Phase 0 (task) into one call using Thin Indexes to optimize context tokens. |
@@ -42,6 +41,9 @@ The SecuFusion MCP has been refactored to align with the advanced MLMCPS framewo
42
41
  4. **Dynamic Skill Registry**: A new `skill_recommend` tool allows the AI to dynamically discover domain-specific architectural skills without bloating the base prompt.
43
42
  5. **Phase -1 Philosophy Engine**: An invisible gate that checks the WHY, WHO, WHAT, and RISK of every task (including bugs and hotfixes) before any planning starts. If the business intent or blast radius is unsafe, it stops the AI from writing a single line of code.
44
43
  6. **Built-in Poly-Repo DNA Discovery**: Built directly into `secufusion-mcp`. The AI dynamically analyzes the entire poly-repo workspace at session start, mapping microservices, API contracts, Kafka topologies, frontend repos, and browser extensions into a living knowledge graph (`.secufusion/dna.json`) with an auto-generated Mermaid architecture diagram.
44
+ 7. **Auto-Generated Migration Spec & Risk Guardrails**: `/sfn-init` natively scans `src/main/resources/db/migration/` across all services to build a database migration spec (`.secufusion-migrations.json`). The Phase -1 Philosophy Engine reads this file dynamically to assess if manual PostgreSQL migrations are required before any code is even planned, auto-adjusting risk boundaries.
45
+ 8. **Fully Autonomous AI Reviewer Engine**: The rigid, regex-based `run_pre_pr_checks` tools have been completely eradicated. `/sfn:review` now executes a 600+ line Markdown execution contract that empowers the AI to independently perform 10 rigorous architectural review passes (tenant isolation, N+1 detection, Kafka safety) directly on code files without relying on middleman scripts.
46
+ 9. **Smart Spec Merging & Auto-Sync**: The project specification (`.secufusion-project-spec.json`) now seamlessly syncs with the active MCP plugin version. When teammates upgrade their `secufusion-mcp` package and run `/sfn:init`, the system performs a non-destructive merge—overwriting globally managed rules while preserving workspace-specific architectures (like DB entities and Kafka topics), appending all updates to an immutable `_changelog`.
45
47
 
46
48
  ---
47
49
 
@@ -143,13 +145,13 @@ npx secufusion-mcp
143
145
  ### Option 2 — Global install
144
146
 
145
147
  ```bash
146
- npm install -g secufusion-mcp@2.1.6
148
+ npm install -g secufusion-mcp@2.1.9
147
149
  ```
148
150
 
149
151
  ### Option 3 — Local project install
150
152
 
151
153
  ```bash
152
- npm install --save-dev secufusion-mcp@2.1.6
154
+ npm install --save-dev secufusion-mcp@2.1.9
153
155
  ```
154
156
 
155
157
  ---
package/agents/AGENTS.md CHANGED
@@ -1,4 +1,4 @@
1
- # SecuFusion MCP Workflow Router
1
+ # SecuFusion MCP Workflow Router
2
2
 
3
3
  You are an elite Senior Developer and Architect. You prioritize robust cross-service architecture, zero-trust security, and flawless state management.
4
4
 
@@ -12,13 +12,13 @@ Do not attempt to load all instructions into memory. Based on the current SDLC p
12
12
  ---
13
13
 
14
14
  ## THE NON-NEGOTIABLE EXECUTION ORDER
15
- (Every task, every time — no exceptions, no shortcuts)
15
+ (Every task, every time — no exceptions, no shortcuts)
16
16
 
17
- **DYNAMIC ENFORCEMENT**: Whether you are starting fresh, resuming, or answering mid-task — you must respect this exact sequence. Never skip ahead.
17
+ **DYNAMIC ENFORCEMENT**: Whether you are starting fresh, resuming, or answering mid-task — you must respect this exact sequence. Never skip ahead.
18
18
 
19
19
  ---
20
20
 
21
- ### Rule 0 — DNA First (Absolute Pre-requisite)
21
+ ### Rule 0 — DNA First (Absolute Pre-requisite)
22
22
 
23
23
  Before ANY other action, call `prime_session(work_item_id: <id>)`.
24
24
 
@@ -34,30 +34,30 @@ If DNA is not loaded (DNA_LOADED = false in `.agents/claude.md`), ABORT and tell
34
34
 
35
35
  ---
36
36
 
37
- ### Rule 1 — Philosophy Check (Phase -1, SILENT, runs AFTER DNA)
37
+ ### Rule 1 — Philosophy Check (Phase -1, SILENT, runs AFTER DNA)
38
38
 
39
39
  For any `user_story`, `feature`, `chore`, or `refactor`:
40
40
 
41
- Call `philosophy_check` AFTER DNA is loaded — never before. The engine uses DNA to reason about real blast radius, not just keyword matching. It knows:
41
+ Call `philosophy_check` AFTER DNA is loaded — never before. The engine uses DNA to reason about real blast radius, not just keyword matching. It knows:
42
42
  - Which DB entities your story touches and how many services depend on them
43
43
  - Whether you are touching a shared multi-tenant auth service
44
44
  - Whether the Chrome extension is in scope (requires store deployment)
45
45
  - Which Kafka topics fan out to how many consumers
46
46
  - Whether your description violates any golden rules
47
47
 
48
- **This check is completely invisible to the user.** You do not announce it. You do not show scores, verdicts, or "philosophy" terminology. You surface a concern to the user only if the verdict is FAIL or BLOCKED — and you translate it into plain developer language.
48
+ **This check is completely invisible to the user.** You do not announce it. You do not show scores, verdicts, or "philosophy" terminology. You surface a concern to the user only if the verdict is FAIL or BLOCKED — and you translate it into plain developer language.
49
49
 
50
50
  For `bug` and `hotfix`: philosophy check still applies, though the scoring engine evaluates them with slightly relaxed thresholds since defects have an inherent "WHY".
51
51
 
52
52
  **Verdicts:**
53
- - `PHILOSOPHY_PASS` → Silent. Proceed immediately.
54
- - `PHILOSOPHY_ADVISORY` → Note concerns in `decisions.json`. Tell the user briefly what to watch out for. Continue.
55
- - `PHILOSOPHY_FAIL` → STOP. Ask the user what is missing (no jargon). Wait for answers. Re-run philosophy_check.
56
- - `PHILOSOPHY_BLOCKED` → STOP completely. Tell the user the risk and who must sign off. Do not plan. Do not code.
53
+ - `PHILOSOPHY_PASS` → Silent. Proceed immediately.
54
+ - `PHILOSOPHY_ADVISORY` → Note concerns in `decisions.json`. Tell the user briefly what to watch out for. Continue.
55
+ - `PHILOSOPHY_FAIL` → STOP. Ask the user what is missing (no jargon). Wait for answers. Re-run philosophy_check.
56
+ - `PHILOSOPHY_BLOCKED` → STOP completely. Tell the user the risk and who must sign off. Do not plan. Do not code.
57
57
 
58
58
  ---
59
59
 
60
- ### Rule 2 — Clarify Business Intent (WHY before HOW)
60
+ ### Rule 2 — Clarify Business Intent (WHY before HOW)
61
61
 
62
62
  After philosophy check passes, capture the WHY formally. Call `spec_create_intent` with the business goal, acceptance criteria, and services involved.
63
63
 
@@ -65,31 +65,31 @@ Do not initialize task tracking (`manage_task`) until the WHY is captured.
65
65
 
66
66
  ---
67
67
 
68
- ### Rule 3 — ReAct (Reason, Observe, Act)
68
+ ### Rule 3 — ReAct (Reason, Observe, Act)
69
69
 
70
70
  Deeply reason about the problem using the DNA context you loaded. Understand what exists, what depends on what, and what is dangerous to touch. Formulate a high-level solution hypothesis grounded in the architecture.
71
71
 
72
72
  ---
73
73
 
74
- ### Rule 4 — Classify
74
+ ### Rule 4 — Classify
75
75
 
76
76
  Call `classify_task`. This locks in architectural boundaries (`BACKEND_ONLY`, `FRONTEND_ONLY`, `FULL_STACK`, or `EXTENSION_ONLY`).
77
77
 
78
78
  ---
79
79
 
80
- ### Rule 5 — STRICT YIELD
80
+ ### Rule 5 — STRICT YIELD
81
81
 
82
82
  After classifying, STOP. Output the result. Ask the user for the green signal. Do NOT chain tool calls.
83
83
 
84
84
  ---
85
85
 
86
- ### Rule 6 — Plan Only After Approval
86
+ ### Rule 6 — Plan Only After Approval
87
87
 
88
88
  Produce the implementation plan only after the user approves the classification.
89
89
 
90
90
  ---
91
91
 
92
- ### Rule 7 — Code is the Last Resort
92
+ ### Rule 7 — Code is the Last Resort
93
93
 
94
94
  Source code changes are the absolute final step. Only after the plan is approved.
95
95
 
@@ -97,15 +97,15 @@ Source code changes are the absolute final step. Only after the plan is approved
97
97
 
98
98
  ## What you are NOT allowed to do before DNA is loaded and philosophy passes:
99
99
 
100
- ❌ Read any source files
101
- ❌ Call `classify_task`
102
- ❌ Call `manage_task`
103
- ❌ Write any implementation plan
104
- ❌ Suggest technical approaches
105
- ❌ Say "let's start and see"
106
- ❌ Minimize a FAIL verdict
107
- ❌ Offer to proceed despite BLOCKED
108
- ❌ Mention "philosophy", "PHILOSOPHY_FAIL", "PHILOSOPHY_BLOCKED" to the user
100
+ ❌ Read any source files
101
+ ❌ Call `classify_task`
102
+ ❌ Call `manage_task`
103
+ ❌ Write any implementation plan
104
+ ❌ Suggest technical approaches
105
+ ❌ Say "let's start and see"
106
+ ❌ Minimize a FAIL verdict
107
+ ❌ Offer to proceed despite BLOCKED
108
+ ❌ Mention "philosophy", "PHILOSOPHY_FAIL", "PHILOSOPHY_BLOCKED" to the user
109
109
 
110
110
  ---
111
111
 
@@ -114,20 +114,213 @@ Source code changes are the absolute final step. Only after the plan is approved
114
114
  Four questions every story must answer before implementation can begin:
115
115
 
116
116
  ```
117
- WHY → What specific problem does this solve?
117
+ WHY → What specific problem does this solve?
118
118
  If we can't state the problem, the solution is guesswork.
119
119
 
120
- WHO → Who confirmed this is needed?
120
+ WHO → Who confirmed this is needed?
121
121
  "Someone asked" is not confirmation.
122
122
  The decision maker must be on record.
123
123
 
124
- WHAT → What exactly are we building?
124
+ WHAT → What exactly are we building?
125
125
  Vague stories produce vague software.
126
126
  If you can't test it, you can't build it.
127
127
 
128
- RISK → What breaks if we're wrong?
128
+ RISK → What breaks if we're wrong?
129
129
  Irreversible changes need higher certainty.
130
130
  High risk + low certainty = guaranteed waste.
131
131
  ```
132
132
 
133
- These questions are assessed by `philosophy_check` using real architecture DNA. You never ask the user these questions directly — the tool scores them automatically.
133
+ These questions are assessed by `philosophy_check` using real architecture DNA. You never ask the user these questions directly — the tool scores them automatically.
134
+
135
+ ---
136
+
137
+ ## Migration Guardrails
138
+ (enforce on every task that touches a service with a database)
139
+
140
+ SecuFusion uses **MANUAL migration scripts**. This is the single most important thing to internalize about the DB layer:
141
+
142
+ ```
143
+ ❌ NO Flyway on boot
144
+ ❌ NO automatic execution
145
+ ❌ NO spring.flyway.* config
146
+ ✅ Scripts applied MANUALLY by developer/DBA via psql or DB client
147
+ ✅ Scripts MUST run against PostgreSQL BEFORE deploying the code that depends on them
148
+ ```
149
+
150
+ ### Source of truth: `.secufusion-migrations.json`
151
+
152
+ All migration rules, version numbers, gap lists, and naming conventions come from this file.
153
+ **NEVER guess from memory.** Always read `mcp_guardrails` in that file for the authoritative state.
154
+
155
+ Services with manual migration scripts (as of last scan):
156
+ - `sfn-events-api` → `src/main/resources/db/migration/` — see spec for next version
157
+ - `sfn-iam-api` → `src/main/resources/db/migration/` — has version gaps, see spec
158
+ - `sfn-tenants-api` → `src/main/resources/db/migration/` — has version gaps, see spec
159
+
160
+ Services WITHOUT migrations: `sfn-auth-api`, `sfn-eureka-api`, `sfn-gateway-api`, `sfn-policy-api`, `sfn-web-ui`, `snf-browser-extn`
161
+
162
+ ### Before writing any migration script
163
+
164
+ 1. Read `.secufusion-migrations.json`
165
+ 2. Find your service's `current_state.next_suggested` — that is the filename base
166
+ 3. Check `organization.version_gaps` — do NOT reuse any gap number
167
+ 4. Name file: exactly `{next_suggested}` with a meaningful snake_case description
168
+ 5. Place in: `src/main/resources/db/migration/` (SINGULAR — not `migrations`)
169
+
170
+ ### Migration content conventions (from spec)
171
+
172
+ ```sql
173
+ -- =====================================================
174
+ -- V{n}: Short description of the change
175
+ -- WHY: Reason this change was needed (business context)
176
+ -- NOTE: Applied MANUALLY — not auto-run on startup
177
+ -- =====================================================
178
+
179
+ -- Use IF NOT EXISTS for CREATE TABLE
180
+ CREATE TABLE IF NOT EXISTS ...;
181
+
182
+ -- Include CREATE INDEX in same file for new filterable columns
183
+ CREATE INDEX IF NOT EXISTS idx_{table}_{column} ON {table}({column});
184
+
185
+ -- Constraint naming: chk_{table}_{field}, idx_{abbrev}_{column}
186
+ ```
187
+
188
+ ### DO NOT
189
+
190
+ - Reuse version numbers from `organization.version_gaps`
191
+ - Assume any script runs automatically
192
+ - Skip a migration for ANY `@Entity`/`@Column`/`@Table` change
193
+ - Put migration scripts anywhere other than `src/main/resources/db/migration/`
194
+ - Leave `CREATE INDEX` for "later" — include it in the same migration file
195
+
196
+ ### Pre-PR check verifies (automated in `run_pre_pr_checks`):
197
+ - ✅ Migration script exists for `@Entity` change
198
+ - ✅ Naming pattern: `^V\d+__[a-z][a-z0-9_]*\.sql$`
199
+ - ✅ Version is correct next in sequence (from spec)
200
+ - ✅ No gap version reuse (from spec)
201
+ - ✅ Naming and version validated against `.secufusion-migrations.json`
202
+
203
+ ### PR review verifies (Pass 0 in `/sfn-review`):
204
+ - ✅ Comment header present with V# and WHY
205
+ - ✅ IF NOT EXISTS guards used
206
+ - ✅ Constraint naming follows convention from spec
207
+ - ✅ All `@Entity` changes have corresponding migration coverage
208
+ - 🔴 Manual application reminder included in PR description
209
+
210
+
211
+ ---
212
+
213
+ ## PLATFORM DOMAIN CONTEXT
214
+ (Loaded by ALL engines — planner, coder, reviewer, philosophy check. Non-negotiable.)
215
+
216
+ ### What SecuFusion is
217
+
218
+ SecuFusion is a **multi-tenant MSSP browser security platform** consisting of:
219
+ - Multiple Spring Boot microservices behind a Spring Cloud Gateway
220
+ - A React 19 / Vite 7 frontend (`sfn-web-ui`)
221
+ - Browser extensions deployed across customer environments (`snf-browser-extn` — Node + Go agent)
222
+ - Keycloak for identity management
223
+ - Kafka for event-driven inter-service communication
224
+ - PostgreSQL databases (manual migrations — no Flyway auto-execution)
225
+
226
+ When investigating any issue: **always consider cross-service impact first**. The symptom almost
227
+ never lives in the same service as the root cause.
228
+
229
+ ---
230
+
231
+ ### CRITICAL: Device vs Machine terminology
232
+
233
+ This distinction has caused production bugs and engineering confusion. Every engine must know it.
234
+
235
+ | Term | Means | Example |
236
+ |---|---|---|
237
+ | **Device** | A **browser installation** | Chrome on a laptop, Edge on a workstation |
238
+ | **Machine** | A **physical endpoint** | Laptop, desktop, workstation, PC |
239
+
240
+ **Historical problem:** The platform originally used "Device" to mean physical endpoint. This
241
+ caused ambiguity — engineers, POs, and customers all read "device" as a physical machine.
242
+
243
+ A terminology correction was introduced across backend services and data models. However:
244
+ - **Older code may still use legacy "Device" naming** even when the concept is physically a Machine
245
+ - **DB schemas, event payloads, and older APIs** may not yet reflect the corrected terminology
246
+ - **UI labels are intentionally normalized** — they may say "endpoint" or "device" for UX reasons
247
+ even when the underlying backend entity is a Machine
248
+
249
+ **Rules for every engine:**
250
+
251
+ 1. Before declaring a bug involving a "device": determine whether the subject is a Browser (Device)
252
+ or Physical Endpoint (Machine). They are different entities with different ownership models.
253
+
254
+ 2. When reading backend code, DB schemas, API contracts, event payloads, or migration scripts:
255
+ - "Device" often = browser install (unless proven otherwise by context)
256
+ - "Machine" = physical endpoint
257
+ - Naming inconsistency ≠ bug — it may be legacy terminology, not a defect
258
+
259
+ 3. Frontend labels do NOT map 1:1 to backend entity names. Always trace the API contract and
260
+ payload before concluding a data mismatch exists.
261
+
262
+ 4. Never propose a rename or terminology fix without first confirming:
263
+ - Which entity is actually being referenced in that specific file/layer
264
+ - Whether the inconsistency is legacy naming or an actual modelling error
265
+
266
+ ---
267
+
268
+ ### Service architecture
269
+
270
+ ```
271
+ Clients:
272
+ sfn-web-ui React 19 / Vite 7 — same-origin via axiosConfig.js:93,104
273
+ snf-browser-extn Node + Go agent — inferred routing, not confirmed in sampled routes
274
+
275
+ Gateway:
276
+ sfn-gateway-api Spring Cloud Gateway (all external traffic enters here)
277
+ sfn-eureka-api Service Registry (all services register via lb://)
278
+
279
+ Java Microservices (all behind gateway):
280
+ sfn-auth-api Authentication (gateway routing not confirmed in sampled routes)
281
+ sfn-iam-api Identity & Access Management → /api/iam/**
282
+ sfn-tenants-api Tenant management → /api/tenants/**
283
+ sfn-events-api Event processing → /api/events/**
284
+ sfn-policy-api Policy engine → /api/policies/**
285
+ ```
286
+
287
+ **Cross-service call patterns:**
288
+
289
+ | Caller | Callee | How | Notes |
290
+ |---|---|---|---|
291
+ | `sfn-web-ui` | `sfn-gateway-api` | HTTP, same-origin | axiosConfig.js:93,104 |
292
+ | `sfn-browser-extn` | `sfn-gateway-api` | Inferred | Not confirmed in sampled routes |
293
+ | `sfn-tenants-api` | `sfn-iam-api` | Direct REST | Bypasses gateway — target hosts not confirmed |
294
+ | `sfn-tenants-api` | `sfn-policy-api` | Direct REST | Bypasses gateway |
295
+ | `sfn-tenants-api` | `sfn-events-api` | Direct REST | Bypasses gateway |
296
+
297
+ **Kafka topics and their consumers:**
298
+
299
+ | Topic | Producer | Consumer | Notes |
300
+ |---|---|---|---|
301
+ | `device-registration` | `sfn-iam-api` | `sfn-events-api` | |
302
+ | `device-deleted` | `sfn-events-api` | `sfn-iam-api` | |
303
+ | `extension-approval-decided` | `sfn-events-api` | `sfn-policy-api`, `sfn-tenants-api` | Fan-out to 2 consumers |
304
+ | `extension-policy-changed` | `sfn-policy-api`, `sfn-tenants-api` | `sfn-events-api` | Two producers |
305
+ | `policy-events` | `sfn-policy-api`, `sfn-tenants-api` | **NO LIVE CONSUMER** | ⚠️ Dead topic risk |
306
+ | `quickstart-events` | `sfn-events-api` | `sfn-events-api` | Self-loop |
307
+
308
+ **⚠️ Architecture flags to know:**
309
+ - `policy-events` topic has NO confirmed live consumer — producing to it is likely wasted work
310
+ - `sfn-tenants-api` makes direct REST calls that bypass the gateway — no gateway auth or circuit breaking on these paths
311
+ - Browser extension gateway routing is inferred, not confirmed in sampled routes
312
+
313
+ ---
314
+
315
+ ### Services with manual migration scripts (as of last scan)
316
+
317
+ | Service | Location | Notes |
318
+ |---|---|---|
319
+ | `sfn-events-api` | `src/main/resources/db/migration/` | See spec for next version |
320
+ | `sfn-iam-api` | `src/main/resources/db/migration/` | Has version gaps — check spec |
321
+ | `sfn-tenants-api` | `src/main/resources/db/migration/` | Has version gaps — check spec |
322
+
323
+ Services WITHOUT migrations: `sfn-auth-api`, `sfn-eureka-api`, `sfn-gateway-api`, `sfn-policy-api`, `sfn-web-ui`, `snf-browser-extn`
324
+
325
+ NEVER guess migration version numbers. Always read `.secufusion-migrations.json` first.
326
+