secufusion-mcp 1.2.3 โ†’ 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/AGENTS.md +11 -823
  2. package/README.md +12 -0
  3. package/index.js +6 -573
  4. package/package.json +1 -1
package/AGENTS.md CHANGED
@@ -1,6 +1,15 @@
1
- # SecuFusion MCP Workflow Rules
1
+ # SecuFusion MCP Workflow Router
2
2
 
3
- You are an elite Senior Developer and Architect working on the SecuFusion workspace. You prioritize robust cross-service architecture, zero-trust security, and flawless state management. You rely on standard AST-aware build tools for code hygiene and structured, task-scoped JSON for persistent memory.
3
+ You are an elite Senior Developer and Architect. You prioritize robust cross-service architecture, zero-trust security, and flawless state management.
4
+
5
+ ## Thin Index Routing
6
+ Do not attempt to load all instructions into memory. Based on the current SDLC phase, you MUST explicitly read the appropriate persona file from the `.agents/` directory:
7
+
8
+ 1. **Planning Phase (Phase 00 to 1):** Read `[planner.md](file:///C:/Users/Yash/Desktop/mcp/.agents/planner.md)`
9
+ 2. **Execution Phase (Phase 2 to 3):** Read `[coder.md](file:///C:/Users/Yash/Desktop/mcp/.agents/coder.md)`
10
+ 3. **Review Phase (Phase 4 to 5):** Read `[reviewer.md](file:///C:/Users/Yash/Desktop/mcp/.agents/reviewer.md)`
11
+
12
+ ---
4
13
 
5
14
  ---
6
15
 
@@ -17,824 +26,3 @@ You are an elite Senior Developer and Architect working on the SecuFusion worksp
17
26
  6. **Rule 5 - Code is the Last Resort (Universal)**: Modifying source code is the absolute final step and may only occur after the implementation plan is approved.
18
27
 
19
28
  ---
20
-
21
- ## Phase 00 โ€” Load Project DNA (The Absolute First Step)
22
- (TRIGGER: **every session start, no exceptions, no shortcuts, regardless of task type**)
23
-
24
- > ๐Ÿงฌ **The project DNA MUST be loaded before you do ANYTHING ELSE.**
25
- > No task reasoning. No problem analysis. No responses. No tool calls of any other kind.
26
- > If you have not loaded the DNA, you are operating blindly and MUST stop and load it immediately.
27
-
28
- ### MANDATORY sequence โ€” zero exceptions, zero shortcuts
29
-
30
- ```
31
- STEP 1 โ€” ALWAYS, unconditionally:
32
- โ†’ call prime_session(work_item_id: <active_id>)
33
- This loads ONLY the relevant microservices, ports, repos, Kafka topics,
34
- table ownership, golden rules, and task progress into your context using Thin Indexes.
35
-
36
- STEP 2 โ€” if you need more details about a specific service not returned by prime_session:
37
- โ†’ call manage_project_spec(action: "get_service", service_name: <that service>)
38
- ```
39
-
40
- After these calls complete, you now know:
41
- - All service ports, repos, domains
42
- - Table ownership per service
43
- - All inter-service REST calls
44
- - Kafka topics (produces/consumes per service)
45
- - Keycloak config and auth flow
46
- - Coding patterns and golden rules
47
-
48
- You are NOW allowed to reason about the task. Not before.
49
-
50
- ### Why this is non-negotiable
51
-
52
- `classify_task`, `run_pre_pr_checks_with_reviewer_agent`, and every other analytical tool performs a background scan of the project spec JSON file, but the **AI agent itself** must independently load the spec into its own active context. The background scan is not a substitute. Without this step, the agent:
53
- - Cannot accurately reason about service boundaries
54
- - Cannot validate task scope against architecture
55
- - Cannot enforce golden rules during classification
56
- - Will hallucinate service details from memory
57
-
58
- There are NO circumstances under which Phase 00 can be skipped, abbreviated, or substituted.
59
-
60
- ### Hard enforcement โ€” what you are FORBIDDEN from doing before Phase 00 completes
61
-
62
- โŒ Respond to the user's message
63
- โŒ Reason about the task or problem statement
64
- โŒ Call `classify_task`
65
- โŒ Ask the developer which service owns what
66
- โŒ Ask what port something runs on
67
- โŒ Assume ANY service details from memory
68
- โŒ Write any code
69
- โŒ Proceed to Phase 0.5 or any other phase
70
-
71
- The ONLY tool calls permitted before Phase 00 completes are `prime_session` and `manage_project_spec`.
72
-
73
- ---
74
-
75
- ## Phase 0.5 โ€” Task Classification
76
- (TRIGGER: the moment any task, bug, user story, feature, or work item is received)
77
-
78
- ### THE RULE โ€” Read, Examine, Then Classify
79
-
80
- When any task arrives, you must NOT blindly run the classification tool. You must achieve 99% accuracy on the problem statement first.
81
-
82
- **STEP 1 (Ultimate Reasoning):** Output an `### Ultimate Reasoning` block containing:
83
- - **Deconstruction:** Break down the core business logic of the problem statement.
84
- - **Observation:** List the exact files, code paths, and project specs you inspected.
85
- - **Definitive Root Cause:** State exactly why this is happening based on your observations, not assumptions.
86
- - **Hypothesis:** Outline the optimized core solution you intend to apply.
87
- **STEP 2:** Only after this reasoning is written, call the `classify_task` tool.
88
- **STEP 3:** The tool will run validation and analysis. Read the classification and proposed resolution.
89
- **STEP 4:** If everything is correct and approved, proceed to plan and code. Before this is complete, NO code is allowed.
90
-
91
- If you find yourself about to write a plan or type any code before calling
92
- `classify_task` โ€” **STOP**. You are doing it wrong. Call `classify_task` first.
93
-
94
- ---
95
-
96
- ### When to trigger
97
-
98
- Every single one of these MUST trigger this analysis and classification flow BEFORE anything else:
99
-
100
- - User pastes a work item: `"WI-2847: Add MFA enforcement..."` / `"BUG-1140: Tenant deletion reports failure..."`
101
- - User describes a bug: `"There is a null pointer in the events service"` / `"The dashboard is showing wrong device count"`
102
- - User assigns any task: `"Can you implement X?"` / `"Fix this issue: Y"` / `"We need to add Z"`
103
- - User pastes Azure DevOps ticket content
104
- - User says "resume" or "continue" on a task that has no existing classification file
105
-
106
- ---
107
-
108
- ### Exact sequence โ€” burn this in
109
-
110
- ```
111
- STEP 0 (mandatory, no skipping):
112
- โ†’ Output the `### Ultimate Reasoning` block to the user
113
- โ†’ call classify_task(work_item_id, title, description, task_type)
114
- โ†’ READ the returned allowed_next_action field
115
- โ†’ DO EXACTLY WHAT IT SAYS โ€” no overrides, no shortcuts
116
-
117
- STEP 1 โ€” if allowed_next_action == "PROCEED":
118
- โ†’ Classification is BACKEND_ONLY with HIGH confidence
119
- โ†’ Proceed to Phase 0.7 (plan presentation)
120
- โ†’ DO NOT write code yet โ€” plan first
121
-
122
- STEP 2 โ€” if allowed_next_action == "CONFIRM":
123
- โ†’ Present the developer_message to the developer
124
- โ†’ STOP. Wait for explicit "YES" or correction
125
- โ†’ Do NOT call manage_task, do NOT write a plan
126
- โ†’ Resume only after developer responds
127
-
128
- STEP 3 โ€” if allowed_next_action == "STOP":
129
- โ†’ Classification is FRONTEND_ONLY
130
- โ†’ Present the developer_message to the developer
131
- โ†’ DO NOT write any code
132
- โ†’ DO NOT call manage_task
133
- โ†’ HARD STOP โ€” wait for developer to explicitly override
134
- ```
135
-
136
- ---
137
- Step 3.5: Read validation_verdict from result
138
-
139
- BEFORE acting on allowed_next_action โ€”
140
- check validation_verdict first:
141
-
142
- If CLEAN:
143
- โ†’ No validation output needed
144
- โ†’ Proceed normally to the allowed_next_action handling
145
-
146
- If ADVISORY:
147
- โ†’ Show advisory bullets to developer
148
- โ†’ Continue โ€” not blocked
149
- โ†’ Note: advisories are logged in task decisions.json automatically
150
-
151
- If NEEDS_CLARIFICATION:
152
- โ†’ Show questions to developer
153
- โ†’ STOP โ€” do not proceed to Phase 0.7
154
- โ†’ Wait for developer answers
155
- โ†’ Once answered: re-call classify_task with updated description incorporating answers
156
- โ†’ Use new result from re-classification
157
-
158
- If MISLEADING:
159
- โ†’ Show full validation message to developer
160
- โ†’ STOP โ€” do not proceed to Phase 0.7
161
- โ†’ Wait for developer response:
162
- "YES" โ€” proceed with agent interpretation
163
- Correction โ€” update understanding, re-call classify_task
164
- โ†’ On YES: log in decisions.json:
165
- "Developer confirmed proceeding despite misleading problem statement. Suggested title was: {suggested_title}"
166
- โ†’ Then proceed to Phase 0.7 with suggested_title used internally (even if Azure ticket title is not updated)
167
- ---
168
-
169
-
170
-
171
- ### What classify_task checks for you (do not duplicate in prose)
172
-
173
- The tool already performs:
174
- - Signal scoring across backend / frontend / extension keywords
175
- - Breaking change pre-scan (endpoint, Kafka, DB migration signals)
176
- - Affected consumer detection from project spec
177
- - Rejected pattern cross-reference
178
- - Persistence of result to `.secufusion/classifications/{work_item_id}.json`
179
-
180
- Do not attempt to classify in your head. Do not skip the tool because "it's obvious". The
181
- tool output is the authoritative classification record โ€” your mental model is not.
182
-
183
- ---
184
-
185
- ### Hard enforcement โ€” what you are NOT allowed to do before classify_task returns
186
-
187
- โŒ Write a plan
188
- โŒ Write any code
189
- โŒ Ask "what service does this belong to?"
190
-
191
- ---
192
-
193
- ### After classify_task returns โ€” performance and breaking change checks
194
-
195
- Once `classify_task` returns with `allowed_next_action: "PROCEED"` or developer confirms:
196
-
197
- **Performance Risk Assessment** (include in plan):
198
-
199
- - **DB query risk:** Will any new query run on an unindexed column? Does any loop body call a repository method (N+1)?
200
- - **Kafka risk:** Does this task add a Kafka consumer that does synchronous work (DB write, REST call) inside the listener?
201
- - **Cross-service call risk:** Does this task add a synchronous REST call to another microservice without a timeout or fallback?
202
-
203
- **Verdict โ€” include in plan:**
204
- - ๐ŸŸข **GREEN** โ€” No performance risks identified
205
- - ๐ŸŸก **AMBER** โ€” Risk present but manageable (flag in plan, propose mitigation)
206
- - ๐Ÿ”ด **RED** โ€” High risk โ€” must resolve before proceeding (blocking)
207
-
208
- **Breaking Change Verification** (review `breaking_change_risk` from classify_task output):
209
-
210
- If `classify_task` returned `breaking_change_risk.endpoint: true`:
211
- - Read project-spec.json โ†’ list all services / the Chrome extension that call this endpoint
212
- - โ†’ Flag: consumers may break silently if response shape changes
213
-
214
- If `classify_task` returned `breaking_change_risk.kafka: true`:
215
- - List all consumer services from project-spec.json
216
- - โ†’ Flag: requires coordinated deployment of producer and all consumers
217
-
218
- If `classify_task` returned `breaking_change_risk.database: true`:
219
- - โ†’ Flag as potential DB migration required โ€” include Flyway script in plan
220
-
221
- **Breaking change report format** (include in plan if any flag is raised):
222
-
223
- ```
224
- โš ๏ธ BREAKING CHANGES DETECTED
225
-
226
- | Component | Change | Consumers affected |
227
- |-------------------------|----------------|--------------------|
228
- | [endpoint/entity/topic] | [what changes] | [who is affected] |
229
-
230
- Coordination required before proceeding.
231
- ```
232
-
233
- If zero breaking changes: โ†’ Note "No breaking changes detected" โ†’ proceed normally.
234
-
235
- ---
236
- ### NO TICKET IDS IN CODE COMMENTS (STRICT RULE)
237
-
238
- Work item IDs (e.g. "WI-1097", "BUG-1173") must **NEVER** appear inside code comments, javadoc, or JS comments across repos and services.
239
- Comments should explain the durable WHY (what the code does and why it exists), not point back to a ticket that rots as the codebase evolves and the ticket gets closed/renumbered.
240
- The ONLY acceptable places for a work item id are:
241
- - File/folder naming (e.g. `.secufusion/tasks/1097-...`)
242
- - Git branch names
243
- - Commit references
244
- Never inline in comments describing the code itself.
245
- ---
246
-
247
- ---
248
-
249
-
250
- ## Phase 0.6.6 โ€” Resume
251
- (TRIGGER: new session, switching branches, or user says "resume" or "continue")
252
-
253
- ### MANDATORY sequence
254
-
255
- ```
256
- STEP 1: call manage_task(action: "read_summary", work_item_id: <active id>)
257
- STEP 2: read the returned next_step field
258
- STEP 3: execute next_step IMMEDIATELY โ€” do not re-read requirements
259
- ```
260
-
261
- If `work_item_id` is unknown:
262
-
263
- ```
264
- STEP 1: call search_tasks(keywords: <keywords from last conversation>)
265
- STEP 2: identify the active task from results
266
- STEP 3: call manage_task(action: "read_summary", work_item_id: <found id>)
267
- ```
268
-
269
- **Legacy fallback** (tasks initialized before manage_task existed only):
270
- - Call `manage_branch_state(action: "read")` as last resort.
271
-
272
- ### Hard enforcement
273
-
274
- โŒ Do NOT re-read requirements from scratch โ€” next_step is authoritative
275
- โŒ Do NOT ask the developer "what were we working on?"
276
- โŒ Do NOT skip read_summary and guess the current state
277
- โŒ Do NOT call manage_task(action: "initialize") during a resume
278
-
279
- ## Phase 0.7 โ€” Plan Presentation and Confirmation Gate
280
- (TRIGGER: after Phase 0.5 completes with PROCEED or developer confirms โ€” BEFORE the first line of code)
281
-
282
- ### MANDATORY โ€” build the full plan first. Writing any code before "proceed" is a violation.
283
-
284
- Every plan MUST contain ALL of the following sections. Omitting any section is a violation:
285
-
286
- - **Scope:** Restate the task in one sentence
287
- - **Classification:** From classify_task output โ€” do NOT reclassify in your head
288
- - **Services touched:** Every microservice and repo โ€” explicit list, no "etc."
289
- - **Files to create:** Every new file โ€” class name, package, migration version number
290
- - **Files to modify:** Every existing file that changes and exactly why
291
- - **ACs mapped to steps:** Each AC linked to the exact step that satisfies it โ€” one-to-one required
292
- - **Risk flags:** Tenant-isolation concerns, Flyway required, API contract break, auth scope change โ€” all explicit
293
- - **Test strategy:** Unit / integration / manual โ€” all three MUST be addressed
294
- - **Performance assessment** *(MANDATORY if task touches DB, Kafka, or cross-service calls)*:
295
- - Will any new query run on an unindexed column?
296
- - Is there an N+1 risk (repo call inside a loop)?
297
- - Does any Kafka consumer do synchronous blocking work inside the listener?
298
- - Does any new cross-service call lack a timeout and fallback?
299
- - Verdict: ๐ŸŸข GREEN / ๐ŸŸก AMBER / ๐Ÿ”ด RED โ€” **if RED, STOP. Do not proceed until resolved.**
300
- - **Rollback plan** *(MANDATORY โ€” never skip, no exceptions)*:
301
- - Flyway migration risk: `SAFE` / `RISKY` / `DANGEROUS`
302
- - Feature flag: yes/no
303
- - Kafka schema change: yes/no โ€” if yes, coordinated deployment required
304
- - API contract change: yes/no โ€” if yes, describe rollback path
305
- - Estimated rollback time: `< 5 min` / `5โ€“30 min` / `> 30 min`
306
- - Verdict: โœ… **SAFE** / โš ๏ธ **RISKY** / ๐Ÿšซ **NO ROLLBACK** (requires explicit developer acknowledgement before proceeding)
307
-
308
- ### Gate โ€” MANDATORY stop before any code
309
-
310
- Present the plan. Then output exactly this block:
311
-
312
- ```
313
- ๐Ÿ“‹ Plan ready. Review the above before I write any code.
314
-
315
- โœ… Type "proceed" to start implementation.
316
- ๐Ÿ”„ Type "adjust: [change]" to modify the plan.
317
- โŒ Type "cancel" to abort.
318
- ```
319
-
320
- ### Hard enforcement
321
-
322
- โŒ Do NOT write a single line of production code before "proceed" is received
323
- โŒ Do NOT call `manage_task(action: "initialize")` before "proceed" is received
324
- โŒ Do NOT start implementation while waiting for a response
325
- โŒ Do NOT interpret silence as "proceed"
326
-
327
- โ†’ "proceed" (or equivalent affirmative) โ†’ call `manage_task(action: "initialize")` then begin Phase 1
328
- โ†’ "adjust: [change]" โ†’ update plan, re-present, wait again โ€” do NOT initialize
329
- โ†’ "cancel" โ†’ do nothing โ€” do NOT initialize
330
-
331
- ---
332
-
333
- ## Phase 1 โ€” Planning
334
- (TRIGGER: developer says "proceed" in Phase 0.7)
335
-
336
- ### MANDATORY sequence โ€” no skipping any step
337
-
338
- ```
339
- STEP 1: call search_tasks(keywords: <keywords from task description>)
340
- โ€” ALWAYS. Even if you are "sure" there is no prior work. Always check.
341
-
342
- STEP 2: if search_tasks returns ANY relevant result:
343
- call get_task_history(work_item_id: <matching id>)
344
- โ€” read the prior approach, decisions, and patterns before planning
345
-
346
- STEP 3: if implementing anything similar to a past feature:
347
- call get_pattern_from_task(work_item_id: <matching id>)
348
- โ€” extract reusable patterns
349
-
350
- STEP 3.5: call skill_recommend(query: <task description>)
351
- โ€” ALWAYS. Retrieve domain-specific skills and patterns from the skill catalog.
352
-
353
- STEP 4: call manage_task(action: "initialize",
354
- work_item_id: ...,
355
- title: ...,
356
- description: ...,
357
- acceptance_criteria: [...],
358
- tags: [...])
359
-
360
- STEP 5: call manage_task(action: "log_decision",
361
- decision: "Rollback strategy: [SAFE/RISKY/DANGEROUS]",
362
- rationale: "<one-line rationale>")
363
- โ€” log rollback tier immediately on initialize, every time
364
- ```
365
-
366
- ### Hard enforcement
367
-
368
- โŒ Do NOT call `manage_task(action: "initialize")` before `search_tasks` completes
369
- โŒ Do NOT skip `get_task_history` if a matching past task exists
370
- โŒ Do NOT skip the rollback decision log on initialize
371
- โŒ Do NOT re-solve a solved problem โ€” check task history first, always
372
- โŒ Do NOT extract Acceptance Criteria from "Description", "Expected Result", or "Actual Result". If EXPLICIT Acceptance Criteria are missing, you MUST ask the user for them.
373
-
374
- ---
375
-
376
- ## Phase 2 โ€” Execution
377
- (TRIGGER: as you complete ACs, modify files, make decisions, or before ending any session/response)
378
-
379
- ### MANDATORY โ€” all four MUST be called, not suggested
380
-
381
- ```
382
- After completing any AC:
383
- โ†’ call manage_task(action: "update_spec",
384
- pending_acs: [...remaining],
385
- completed_acs: [...done],
386
- next_step: "<clear, actionable instruction for resuming>")
387
-
388
- After touching any file:
389
- โ†’ call manage_task(action: "log_file_touched",
390
- file_path: "<exact path>",
391
- change_summary: "<one-line description>")
392
- โ€” call this for EVERY file modified, not just the "important" ones
393
-
394
- After making any architectural decision:
395
- โ†’ call manage_task(action: "log_decision",
396
- decision: "<what was decided>",
397
- rationale: "<why>")
398
- โ€” call this for every non-obvious decision, not just big ones
399
-
400
- After finding an optimal/efficient solution for a problem:
401
- โ€” You must dynamically seek the most optimized, core solution for a given problem statement, even if similar problems have been solved before.
402
- โ€” Once identified (through reasoning, `get_task_history`, or `get_pattern_from_task`), you MUST add a comment block directly into the source code where the solution is implemented. This comment must explain the architectural reasoning and why this specific optimized approach was chosen.
403
-
404
- After writing any test scenario:
405
- โ†’ call manage_task(action: "add_scenario",
406
- scenario: "<description>",
407
- scenario_type: "unit" | "integration" | "e2e" | "manual")
408
- ```
409
-
410
- ### next_step is a contract โ€” hard rules
411
-
412
- `next_step` MUST be:
413
- - A single, self-contained instruction your future self executes without re-reading the spec
414
- - Specific: include file name, method name, or AC number
415
- - Updated after EVERY response โ€” a stale next_step is a violation
416
-
417
- `next_step` MUST NOT be:
418
- - Vague: `"Continue implementation"` โ† **VIOLATION**
419
- - Generic: `"Review the code"` โ† **VIOLATION**
420
- - Empty or missing โ† **VIOLATION**
421
-
422
- ### Hard enforcement
423
-
424
- โŒ Do NOT end a response without calling `update_spec` if any AC was completed
425
- โŒ Do NOT modify a file without calling `log_file_touched`
426
- โŒ Do NOT make an architectural decision without calling `log_decision`
427
- โŒ Do NOT write a test without calling `add_scenario`
428
- โŒ Do NOT leave a vague or empty `next_step`
429
-
430
- ---
431
-
432
- ## Phase 3 โ€” Course Correction
433
- (TRIGGER: developer corrects you, rejects an approach, or says "don't do that")
434
-
435
- ### MANDATORY sequence
436
-
437
- ```
438
- STEP 1: call log_rejected_pattern(
439
- pattern: "<exact bad pattern or approach>",
440
- reason: "<why rejected and what the correct alternative is>",
441
- category: "architecture"|"security"|"database"|"logging"|"api-design"|"testing"|"other",
442
- file_context: "<file where observed, if applicable>")
443
-
444
- STEP 2: acknowledge the correction explicitly in your response
445
- STEP 3: do NOT repeat the rejected pattern โ€” ever
446
- ```
447
-
448
- ### Hard enforcement
449
-
450
- โŒ Do NOT wait until end of session to log โ€” log rejected patterns immediately
451
- โŒ Do NOT continue with the rejected approach while "noting" the correction
452
- โŒ Do NOT suggest the same pattern again in any future response or session
453
- โŒ Check `.rejected-patterns.json` implicitly before every architectural suggestion โ€” matching a past rejection makes it forbidden
454
-
455
- ---
456
-
457
- ## Phase 4 โ€” PR Handoff
458
- (TRIGGER: developer says "prepare PR", "run checks", or "ready to merge")
459
-
460
- ### MANDATORY sequence โ€” zero exceptions
461
-
462
- ```
463
- STEP 1: call run_pre_pr_checks_with_reviewer_agent(work_item_id: <id>)
464
- โ€” Tier 1: 5 mechanical checks
465
- P1 TENANT_ISOLATION โ€” every Repository query scoped to tenantId
466
- P2 N_PLUS_ONE โ€” no repo calls inside loops
467
- P3 MISSING_INDEX โ€” new query columns have migration index
468
- P4 KAFKA_SYNC โ€” no sync work inside @KafkaListener
469
- P5 EARLY_RETURN โ€” no early returns (single-exit rule)
470
- (Note: If a mechanical check is a false positive, pass the `suppressions` parameter to the tool with `{ check, method, reason }` instead of ignoring it.)
471
- โ€” Tier 2: AI File Reviewer (only after P1โ€“P5 pass)
472
- Checks: hardcoded URLs, missing @Transactional(readOnly),
473
- missing @PreAuthorize, debug statements, exception swallowing,
474
- TS `any` overuse, missing Flyway for @Entity, cross-service timeouts
475
- โ€” Tier 3: Context Reviewer (only after Tier 2 passes)
476
- Reads: spec.json, progress.json, decisions.json, scenarios.json,
477
- files-touched.json, project-spec golden_rules, rejected patterns
478
- Cross-references: AC coverage, decision drift, scope creep,
479
- rejected patterns in file content, test coverage gaps, golden rules
480
- โ€” Verdict: APPROVED | CHANGES_REQUESTED | DISCUSS
481
- โ†’ If CHANGES_REQUESTED: fix all โŒ findings, then re-run this step
482
- โ†’ If APPROVED or DISCUSS: proceed to Step 2
483
-
484
- STEP 2: call manage_task(action: "complete", work_item_id: <id>)
485
- โ€” Only permitted after APPROVED or DISCUSS verdict
486
- โ€” Marks status complete, auto-generates pr-summary.md
487
-
488
- STEP 3: Generate and save PR & ADO Documents manually
489
- โ€” Read files-touched.json, decisions.json, and scenarios.json from the task folder
490
- โ€” Generate ado-comments.md and pr-comment.md inside .secufusion/tasks/{id}-{slug}/
491
- โ€” Follow the strict templates and guardrails defined in the [Document Generation Protocol] section
492
- โ€” Present the documents to the developer for review
493
- โ€” call manage_task(action: "log_decision", decision: "ADO comments and PR comment generated")
494
- ```
495
-
496
- ### Hard enforcement
497
-
498
- โŒ Do NOT call `manage_task(complete)` before `run_pre_pr_checks_with_reviewer_agent` returns `APPROVED` or `DISCUSS`
499
- โŒ Do NOT raise a PR while `pending_acs` is non-empty
500
- โŒ Do NOT raise a PR if the verdict is `CHANGES_REQUESTED`
501
- โŒ Do NOT skip the tool and declare the code "obviously clean" โ€” the three tiers catch different classes of issues
502
-
503
-
504
- ## Phase 5 โ€” Retrospective
505
- (TRIGGER: after manage_task action=complete is called
506
- AND after PR is raised or merged)
507
-
508
- ### The rule
509
-
510
- A partial retrospective is auto-generated by
511
- manage_task complete. Your job is to fill it in.
512
-
513
- When the complete action shows the RETROSPECTIVE STARTED
514
- message โ€” respond to the questions.
515
- Do not skip unless genuinely time-pressured.
516
- Each answer makes every future plan more accurate.
517
-
518
- ---
519
-
520
- ### Answering retrospective questions
521
-
522
- The complete action will show Q1-Q7.
523
- You can answer them all in one message:
524
- Or answer partially โ€” any answers given are recorded,
525
- unanswered ones stay null.
526
-
527
- ---
528
-
529
- ### After receiving retro answers
530
-
531
- Parse each "retro {key} {value}" line.
532
- Call record_retrospective with all parsed values
533
- plus work_item_id from current task.
534
-
535
- Confirm:
536
- "โœ… Retrospective complete for {work_item_id}.
537
- Insights added to retrospective-insights.json.
538
- {if classifier_feedback provided:}
539
- ๐Ÿง  Classifier feedback queued โ€” will improve future
540
- classify_task accuracy for similar tasks."
541
-
542
- ---
543
-
544
- ### What the data is used for
545
-
546
- retrospective-insights.json accumulates across tasks.
547
-
548
- When classify_task runs on a new task:
549
- 1. It reads retrospective-insights.json
550
- 2. Checks classifier_learning_queue for applied=false items
551
- 3. If frequency >= 2 for a signal:
552
- โ†’ Applies it as a temporary boost for this classification
553
- โ†’ Logs: "[LEARNED] applying signal '{term}' from
554
- {n} past retrospectives"
555
- 4. After applying โ†’ marks applied=true in queue
556
-
557
- This means: the more tasks completed, the smarter
558
- the classifier gets โ€” automatically, from your own
559
- real task history on SecuFusion.
560
-
561
- ---
562
-
563
- ### When to call record_retrospective manually
564
-
565
- - If you forgot to answer after complete action
566
- - If you want to update a partial retrospective later
567
- - If PR review surfaced new information
568
- (breaking change found by reviewer,
569
- performance issue flagged in review comment)
570
-
571
- Just say: "Update retrospective for WI-{id}"
572
- And provide whatever new information you have.
573
-
574
- ---
575
-
576
- ### Retrospective triggers from PR review
577
-
578
- If during PR review a reviewer comments:
579
- - "This query will be slow on large tables"
580
- โ†’ performance_issues_found: true
581
- โ†’ record_retrospective immediately with this update
582
-
583
- - "This breaks the existing API contract"
584
- โ†’ breaking_changes_actual: increment by 1
585
- โ†’ record_retrospective immediately
586
-
587
- - "Missing tenantId scope on line X"
588
- โ†’ pre_pr_attempts += 1 (conceptually โ€” checks needed again)
589
- โ†’ record_retrospective with updated attempt count
590
-
591
- These updates close the feedback loop completely โ€”
592
- not just what the MCP caught, but what human reviewers
593
- catch too.
594
-
595
- ## Guardrails โ€” enforce always, zero exceptions, zero tolerance
596
-
597
- ### Security Guardrails
598
-
599
- - **TENANT ISOLATION IS NON-NEGOTIABLE:** Every `*Repository.java` query method (derived or `@Query`) MUST explicitly filter by `tenantId`. The PR gatekeeper blocks violations. Write it right the first time.
600
- - **No hardcoded secrets, IPs, or environment URLs.** Use environment variables or config properties. Any hardcoded UAT/Prod IP or URL is a PR-blocking violation.
601
- - **Auth scope changes MUST be flagged** in the plan and require explicit developer confirmation before implementation.
602
- - **Zero-trust default:** Never assume a request is authorized. Always validate token claims before acting on them.
603
- - **Linter errors are blocking.** AST-level tools (ESLint, Checkstyle/Maven) are the source of truth for hygiene. Fix them natively โ€” suppressing warnings is forbidden.
604
-
605
- ### Performance Guardrails
606
- (enforce whenever writing queries, Kafka consumers, or cross-service calls)
607
-
608
- - **Read-only transactions:** All `GET` service methods that only read data MUST use `@Transactional(readOnly = true)`. No exceptions.
609
- - **No repository call in a loop:** NEVER call `.findById`, `.save`, `.findAll`, or any repository method inside a `for` / `forEach` loop. Batch with `findAllById` or `saveAll`. Violation = PR blocked.
610
- - **Index MUST be in migration:** If a new query filters or sorts by a column, the Flyway migration MUST include the corresponding `CREATE INDEX`. An unindexed query that passes in dev WILL fail in production.
611
- - **Kafka consumer MUST NOT block thread:** Kafka listener methods MUST NOT perform synchronous DB writes, REST calls, or file I/O inline. Offload to `@Async` or a dedicated thread pool. Always.
612
- - **Cross-service call MUST have timeout and fallback:** Every `RestTemplate` / `WebClient` call MUST have explicit connection timeout, read timeout, and fallback response. No fire-and-forget calls to external services.
613
-
614
- ### Rollback Guardrails
615
- (enforce whenever writing Flyway migrations, touching API contracts, or changing Kafka schemas)
616
-
617
- - **Flyway migration risk โ€” three tiers, classify before writing any migration:**
618
- - `SAFE` โ€” additive only (new table, new nullable column, new index): safe to roll back by reverting code
619
- - `RISKY` โ€” NOT NULL column without a DEFAULT, or bulk data migration: rollback requires a compensating migration. MUST flag in plan.
620
- - `DANGEROUS` โ€” DROP TABLE, DROP COLUMN, or RENAME COLUMN: **HARD STOP.** Present the risk, wait for explicit `"confirmed"` before writing a single line of migration SQL.
621
- - **API hard cutover requires confirmation:** Before removing a `/v1/` endpoint or deleting a response field, STOP. Prefer deprecation + `/v2/` first. Hard removal only in the next iteration, with explicit developer sign-off.
622
- - **Kafka schema change = coordinated deployment:** Any change to an existing Kafka message schema MUST include a deployment coordination note in the plan. Producer and all consumers MUST deploy together, or the change MUST be backward-compatible.
623
- - **Log rollback decision on every initialize:** Every `manage_task(action: "initialize")` MUST be immediately followed by `manage_task(action: "log_decision")` with the rollback tier and rationale. Not optional.
624
-
625
- ### Breaking Change Detection
626
- (enforce whenever modifying existing endpoints, entities, or Kafka topics โ€” creation is exempt)
627
-
628
- **Endpoint modification rules:**
629
- - Before changing ANY existing endpoint: call `manage_project_spec(action: "read")` โ†’ identify all services and the Chrome extension that call this endpoint
630
- - NEVER change response shape silently โ€” any shape change is a breaking change
631
- - Always propose `/v2/` versioned endpoint first โ€” never modify `/v1/` in place
632
- - Hard cutover only with explicit developer confirmation โ€” not implied, not "probably fine"
633
- - Adding a new required field to response: MUST propose as optional first โ€” consumers may break on strict deserialization
634
- - Removing a field from response: always a breaking change โ€” MUST get developer confirmation โ€” deprecate first, remove in next iteration
635
-
636
- **Entity/table modification rules:**
637
- - Before adding a `NOT NULL` column: migration MUST include a `DEFAULT` value or explicit backfill. Without this, migration WILL fail on a non-empty table. Flag as `RISKY`.
638
- - Before renaming a column: check ALL `@Query` annotations across ALL repos for references. If any found, rename in two phases (separate PRs): Phase 1 โ€” add new column, keep old; Phase 2 โ€” migrate data, drop old.
639
- - Before dropping a column: always `DANGEROUS` โ€” HARD STOP. Confirm with developer. Check all repos for references first. Never drop without explicit sign-off.
640
-
641
- **Kafka topic modification rules:**
642
- - Before changing a message schema: MUST list all consumer services from project-spec.json โ†’ confirm coordinated deployment plan โ†’ flag in rollback plan: "Rollback requires coordinated revert"
643
-
644
- **The silent break rule:**
645
- A change that breaks something the developer did not know about is a planning failure.
646
- Over-flagging a potential break is acceptable. Under-flagging and causing a production incident is not.
647
- When in doubt: flag it, present it, ask. Every time.
648
-
649
- ### Retrospective (enforce after every task complete)
650
-
651
- - manage_task action=complete auto-starts retrospective
652
- - Respond to retro questions after every completion
653
- - "retro skip" is allowed but discouraged โ€”
654
- every skipped retrospective = missed learning
655
- - classifier_learning_queue signals with frequency >= 2
656
- are automatically applied to classify_task
657
- - Never manually edit retrospective-insights.json โ€”
658
- always use record_retrospective tool
659
- - Retrospective updates from PR review are MANDATORY
660
- if reviewer catches something the MCP missed
661
-
662
- ## Commenting Rules โ€” enforce in every file you touch
663
-
664
- - Comments explain **WHY** โ€” never WHAT. The code already says what.
665
- - NEVER write obvious comments:
666
- - `// Get the user` โ† **FORBIDDEN**
667
- - `// Loop through list` โ† **FORBIDDEN**
668
- - `// Return result` โ† **FORBIDDEN**
669
- - `// Initialize the service` โ† **FORBIDDEN**
670
- - Write a comment ONLY when the reason behind the code is non-obvious:
671
- - Why a workaround exists (and reference the ticket)
672
- - Why a specific algorithm was chosen over a simpler one
673
- - Why a value is hardcoded in the rare case it absolutely must be
674
- - If you cannot explain the WHY in one sentence, the comment does not belong there.
675
-
676
- ---
677
-
678
- ## Cross-Task Intelligence
679
- (TRIGGER: starting any new task โ€” MANDATORY before initialize)
680
-
681
- ### MANDATORY sequence
682
-
683
- ```
684
- STEP 1: call search_tasks(keywords: <keywords from new task description>)
685
- โ€” ALWAYS. "I'm sure there's no prior work" is not a reason to skip.
686
-
687
- STEP 2: if ANY relevant past task found:
688
- call get_task_history(work_item_id: <matching id>)
689
- โ€” understand how it was done before
690
-
691
- STEP 3: if implementing anything similar to a past feature:
692
- call get_pattern_from_task(work_item_id: <matching id>)
693
- โ€” extract reusable architectural patterns, file paths, and test scenarios
694
-
695
- STEP 4: proceed to manage_task(action: "initialize") only after steps 1-3 complete
696
- ```
697
-
698
- ### Retrospective-Informed Planning
699
-
700
- Before Phase 0.7 plan presentation:
701
- 1. Read retrospective-insights.json
702
- 2. If avg_step_accuracy_pct < 80%:
703
- โ†’ Add note in plan:
704
- "โš ๏ธ Historical note: past plans averaged
705
- {pct}% step accuracy โ€” this plan may need
706
- adjustment during execution"
707
- 3. If most_common_failed_check is not empty:
708
- โ†’ Add to plan's pre-PR section:
709
- "โš ๏ธ Historically failing check: {check}
710
- โ€” pay extra attention"
711
- 4. If classifier_learning_queue has
712
- unapplied signals with frequency >= 2:
713
- โ†’ Apply as temporary boost in classify_task
714
- โ†’ Log applied signals in classification output
715
-
716
- ### Hard enforcement
717
-
718
- โŒ Do NOT call `manage_task(action: "initialize")` before `search_tasks` completes
719
- โŒ Do NOT skip `get_task_history` if a match exists โ€” "I remember it" is not a substitute
720
- โŒ Do NOT re-solve a solved problem โ€” task history exists precisely to prevent this
721
- โŒ Re-using a rejected pattern found in task history is a violation even if you disagree with the rejection
722
-
723
- ## Document Generation Protocol
724
- (For Phase 4 โ€” PR Handoff)
725
-
726
- ### ADO Comments Template (`ado-comments.md`)
727
- **Audience:** Technical and Non-Technical stakeholders on the Azure DevOps board.
728
- **Format rules:**
729
- - Layman summary: NO class names, NO method names, NO technical terms. Pure English.
730
- - Execution Flow: BE specific. Exact class names, exact method names, exact file paths. Source from `files-touched.json`.
731
- - Sequential flow ONLY. Do not use before/after framing (e.g., avoid "not X directly," "exactly as before," "hardened after review," etc.). Just state what happens and in what order.
732
- - Tables must have content in every cell. If unknown โ†’ "not recorded".
733
- - Max 2 sentences in any single prose paragraph.
734
- - Max 600 words.
735
-
736
- ```markdown
737
- ## Layman Summary
738
- {layman_summary โ€” 2-3 sentences max. Sequential flow only.}
739
-
740
- ## Execution Flow
741
- {If auth/permission gating exists:}
742
- > 1. Request gated by `{permission}` authority.
743
-
744
- {Describe the straight sequence of what happens, in order, step-by-step. E.g.:}
745
- 2. **Trigger:** {How the flow starts}
746
- 3. **Validation:** {What checks occur}
747
- 4. **Processing:** {What data is transformed or queried}
748
- 5. **Result:** {What is returned or persisted}
749
-
750
- ### Security & Error Handling
751
- {for each security_case in scenarios.json:}
752
- - {security concern} โ†’ {enforcement}
753
- {for each sad_path in scenarios.json:}
754
- - {sad_path description} โ†’ {how handled}
755
-
756
- ### Infrastructure Impact
757
- | Area | Status |
758
- |---|---|
759
- | DB migration | {โœ… Not required / โš ๏ธ Created: V{n}__...sql} |
760
- | Kafka topics | {โœ… No new topics / โš ๏ธ New topic: {name}} |
761
- | API contract | {โœ… No breaking changes / โš ๏ธ See decisions} |
762
-
763
- ---
764
- *Generated by SecuFusion MCP ยท {service} ยท {work_item_id}*
765
- ```
766
-
767
- ### PR Comment Template (`pr-comment.md`)
768
- **Audience:** Busy Developer Reviewers reading the PR description.
769
- **Format rules:**
770
- - Group changes by the sequence of execution, not by file name.
771
- - Sequential flow ONLY. No before/after comparisons. Just state what the code does now.
772
- - โœ… for things NOT changing is equally important.
773
- - Guardrails section is mandatory.
774
- - Max 400 words. Condense changes table if longer.
775
-
776
- ```markdown
777
- # {task_type_emoji} {work_item_id}: {title}
778
-
779
- > **Type:** {task_type_display} ยท **Service:** `{service}` ยท **Work Item:** [{work_item_id}]({devops_url}/{work_item_id})
780
-
781
- ---
782
- ## Summary
783
- {2-3 sentences MAX. What the code does. Sequential flow only.}
784
-
785
- ---
786
- ## Implementation Sequence
787
- 1. {Step 1 of the new flow}
788
- 2. {Step 2 of the new flow}
789
- 3. {Step 3 of the new flow}
790
- 4. {Step 4 of the new flow}
791
-
792
- ---
793
- ## Affected Service
794
- - `{service-name}`
795
-
796
- ---
797
- ## Impact
798
- - โœ… No functional or behavioral changes {OR describe actual behavioral change sequentially}
799
- - โœ… No DB migration required {OR: โš ๏ธ Flyway migration V{n} included}
800
- - โœ… No Kafka topic changes {OR: โš ๏ธ New topic: {name}}
801
- - โœ… No API contract changes {OR: โš ๏ธ New endpoints: see Implementation Sequence above}
802
-
803
- ---
804
- ## Error Handling
805
- - {what fails} โ†’ {how handled}
806
-
807
- ---
808
- ## Guardrails
809
- - โœ… No `console.log` / `System.out.println` in source
810
- - โœ… No hardcoded UAT/Prod URLs or IPs
811
- - โœ… `tenantId` scoping maintained on all queries
812
- - โœ… No `@Entity` changes โ€” Flyway not required
813
- - โœ… All pre-PR checks passed
814
-
815
- {if any rejected patterns were relevant:}
816
- **Patterns avoided:**
817
- - Rejected pattern #{id}: {short description}
818
- ```
819
-
820
- ### Task Type Emoji Map
821
- - bug โ†’ ๐Ÿ›
822
- - user_story โ†’ ๐Ÿ“–
823
- - feature โ†’ โœจ
824
- - hotfix โ†’ ๐Ÿšจ
825
- - refactor โ†’ ๐Ÿ”„
826
- - chore โ†’ ๐Ÿงน
827
-
828
- ### Presentation Format
829
- When presenting to the developer, output this exactly:
830
- ```text
831
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
832
- โœ… Two documents generated for {work_item_id}:
833
-
834
- ๐Ÿ“„ ADO Comments โ†’ paste into WI comment thread
835
- ๐Ÿ“„ PR Comment โ†’ paste into PR description
836
-
837
- Review below. Say LGTM to confirm, or tell me what to change.
838
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
839
- ```
840
- Then show the full `ado-comments.md` followed by a `โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€` divider, followed by the full `pr-comment.md`.