codeninja 3.1.0 → 3.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.
Files changed (27) hide show
  1. package/ide/antigravity/.agents/personas/global-orchestrator.md +103 -84
  2. package/ide/antigravity/.agents/workflows/codeninja-api.md +98 -15
  3. package/ide/antigravity/.agents/workflows/codeninja-audit.md +69 -11
  4. package/ide/antigravity/.agents/workflows/codeninja-db-create.md +118 -5
  5. package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +81 -5
  6. package/ide/antigravity/.agents/workflows/codeninja-db-index.md +64 -5
  7. package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +100 -5
  8. package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +70 -4
  9. package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +64 -6
  10. package/ide/antigravity/.agents/workflows/codeninja-debug.md +76 -6
  11. package/ide/antigravity/.agents/workflows/codeninja-design.md +45 -12
  12. package/ide/antigravity/.agents/workflows/codeninja-explain.md +35 -6
  13. package/ide/antigravity/.agents/workflows/codeninja-init.md +329 -22
  14. package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +334 -9
  15. package/ide/antigravity/.agents/workflows/codeninja-modularize.md +214 -9
  16. package/ide/antigravity/.agents/workflows/codeninja-optimize.md +78 -7
  17. package/ide/antigravity/.agents/workflows/codeninja-refactor.md +58 -13
  18. package/ide/antigravity/.agents/workflows/codeninja-review.md +64 -6
  19. package/ide/antigravity/.agents/workflows/codeninja-sync.md +172 -12
  20. package/ide/antigravity/.agents/workflows/codeninja-test.md +51 -9
  21. package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +248 -9
  22. package/ide/cursor/.cursor/rules/01-global-orchestrator.mdc +35 -32
  23. package/ide/cursor/.cursor/rules/03-api-builder.mdc +100 -50
  24. package/ide/cursor/.cursor/rules/04-database.mdc +73 -70
  25. package/ide/cursor/.cursor/rules/05-reactjs.mdc +133 -69
  26. package/ide/vscode/.github/copilot-instructions.md +304 -190
  27. package/package.json +1 -1
@@ -1,23 +1,68 @@
1
1
  ---
2
2
  slash_command: /codeninja:refactor
3
- personas: [global-orchestrator, nodejs-backend]
4
- skills: [mcp-and-context, api-builder]
5
- description: Rename or restructure code with full context tracking
3
+ personas: [global-orchestrator, nodejs-backend, database-architect]
4
+ skills: [mcp-and-context, api-builder, database, code-intelligence]
5
+ description: Rename or restructure code with full context tracking.
6
6
  ---
7
7
 
8
8
  # /codeninja:refactor
9
9
 
10
- Delegates to: `.codeninja/commands/refactor.workflow.md`
11
-
12
10
  ## Before Running
13
11
  1. Call `context_read`
14
- 2. Ask: "What are you refactoring?" — field rename, file restructure, module rename?
12
+ 2. Call `context_check_stale`
13
+
14
+ ## Execution — Full Step-by-Step
15
+
16
+ **Step 1.** Ask: "What type of refactor?"
17
+ 1. Rename a DB column
18
+ 2. Rename a service
19
+ 3. Rename a table
20
+ 4. Rename a module
21
+ 5. Restructure files
22
+ - Store: `context.current_refactor.type`
23
+
24
+ **Step 2.** Ask: "Which service?" (if applicable — skip for DB-only refactors)
25
+
26
+ ---
15
27
 
16
- ## Execution
17
- Read and execute `refactor.workflow.md`.
18
- Show full list of affected files before making any change.
19
- ONE confirmation, then apply all changes.
20
- Update `context.change_log` with before/after record.
28
+ ### If "Rename DB column":
29
+ - Ask: "Which table?" (list from context)
30
+ - Ask: "Which column to rename?" (list current columns)
31
+ - Ask: "New column name?" (snake_case)
32
+ - Delegate to database-agent:
33
+ - Generate ALTER TABLE migration file
34
+ - Update `context.db.schema.tables[<table>].columns`
35
+ - Append to `context.db.schema.change_log`
36
+ - Delegate to nodejs-agent:
37
+ - Find all references to old column name in service files
38
+ - Update model queries
39
+ - Update swagger_doc.json
40
+
41
+ ### If "Rename service":
42
+ - Ask: "Current service name?" (list from context)
43
+ - Ask: "New service name?"
44
+ - Update `context.services` key
45
+ - Append to `context.change_log`
46
+
47
+ ### If "Rename table":
48
+ - Ask: "Which table?" (list from context)
49
+ - Ask: "New table name?" (must start with tbl_, snake_case)
50
+ - Delegate to database-agent:
51
+ - Generate ALTER migration: `RENAME TABLE <old> TO <new>`
52
+ - Update `context.db.schema.tables` key
53
+ - Append to `context.db.schema.change_log`: `{ type: "table_renamed", from: "<old>", to: "<new>" }`
54
+ - Delegate to nodejs-agent:
55
+ - Find all references to old table name in model files
56
+ - Update queries in all affected services
57
+ - Append to top-level `context.change_log`
58
+
59
+ ### If "Rename module":
60
+ - Ask: "Current module name?"
61
+ - Ask: "New module name?"
62
+ - Delegate to nodejs-agent → rename files and update route_manager
63
+
64
+ ---
21
65
 
22
- ## After Running
23
- Call `context_write` with updated service/module names if renamed.
66
+ **Confirm:** "Apply refactor? (yes/no)"
67
+ If yes → make all changes → call `context_write` call `context_clear_scratchpad` ["current_refactor"]
68
+ Show final summary.
@@ -2,11 +2,69 @@
2
2
  slash_command: /codeninja:review
3
3
  personas: [global-orchestrator, nodejs-backend]
4
4
  skills: [mcp-and-context, api-builder, code-intelligence]
5
- description: Code review severity-ranked findings with exact before/after fixes
5
+ description: Deep code review with severity-ranked findings and concrete fixes.
6
6
  ---
7
+
7
8
  # /codeninja:review
8
- Delegates to: `.codeninja/commands/review.workflow.md`
9
- Before: `context_read`, `fs_read` target, read 1–2 sibling modules.
10
- Run full checklist: Security → Architecture → Code Quality → Database.
11
- Output: [CRITICAL|WARNING|SUGGESTION] with before/after code.
12
- Offer to apply fixes. Confirm each before writing.
9
+
10
+ ## Before Running
11
+ 1. Call `context_read`
12
+ 2. Call `context_check_stale`
13
+
14
+ ## Execution — Full Step-by-Step
15
+
16
+ ### Step 1 — Identify Target
17
+ If not specified, ask: "Which file or module would you like reviewed?"
18
+
19
+ ### Step 2 — Load Context
20
+ 1. Call `fs_read` on the target file
21
+ 2. Read 1–2 similar modules from `context.services[<service>].modules` for pattern comparison
22
+ 3. Cross-reference `context.db.schema` for table/column accuracy
23
+
24
+ ### Step 3 — Run Review Checklist
25
+
26
+ #### Security (CRITICAL if failing)
27
+ - [ ] All POST/PUT/PATCH routes have validatorjs input validation
28
+ - [ ] API key middleware applied before any route logic
29
+ - [ ] JWT auth middleware present on protected routes
30
+ - [ ] No hardcoded secrets, keys, or passwords
31
+ - [ ] Parameterized queries only — no string concatenation in SQL
32
+ - [ ] Error responses don't leak stack traces or internal details
33
+
34
+ #### Architecture (WARNING if failing)
35
+ - [ ] 2-layer rule: no SQL in route.js, no res.json() in model.js
36
+ - [ ] route_manager.js registration matches route file
37
+ - [ ] swagger_doc.json has entry for this endpoint
38
+ - [ ] All user-facing strings in languages/en.js — none hardcoded in route.js
39
+
40
+ #### Code Quality (SUGGESTION if failing)
41
+ - [ ] JSDoc on every exported function
42
+ - [ ] No unused variables or dead imports
43
+ - [ ] No console.log — project logger used instead
44
+ - [ ] Async functions have try/catch blocks
45
+ - [ ] SELECT * not used — explicit column list
46
+
47
+ #### Database (WARNING if failing)
48
+ - [ ] Column names match context.db.schema exactly (snake_case)
49
+ - [ ] Foreign key columns indexed
50
+ - [ ] Transactions used where multiple writes occur together
51
+ - [ ] LIMIT clause on any query that could return unbounded rows
52
+
53
+ ### Step 4 — Output Findings
54
+
55
+ For each issue:
56
+ ```
57
+ [CRITICAL|WARNING|SUGGESTION]
58
+ File: path/to/file.js (~line N)
59
+ Issue: clear one-line description
60
+ Before: the current code
61
+ After: the corrected code
62
+ Why: one sentence explanation
63
+ ```
64
+
65
+ End with: `Review complete: X critical · Y warnings · Z suggestions`
66
+
67
+ ### Step 5 — Offer Auto-Fix
68
+ "Would you like me to apply any of these fixes?
69
+ - SUGGESTION-level: apply all at once
70
+ - WARNING/CRITICAL: one at a time, confirm each"
@@ -1,23 +1,183 @@
1
1
  ---
2
2
  slash_command: /codeninja:sync
3
3
  personas: [global-orchestrator, nodejs-backend]
4
- skills: [mcp-and-context]
5
- description: Scan the entire repo and rebuild context.json from disk
4
+ skills: [mcp-and-context, code-intelligence]
5
+ description: Scan the entire repository and rebuild context.json from what actually exists on disk.
6
6
  ---
7
7
 
8
8
  # /codeninja:sync
9
9
 
10
- Delegates to: `.codeninja/commands/sync.workflow.md`
11
-
12
10
  ## Before Running
13
- 1. Call `context_read` — load current state
11
+ 1. Call `context_read` — load current state (or detect empty)
14
12
  2. Call `service_scan` — discover all services on disk
13
+ 3. Call `context_check_stale`
14
+
15
+ ## Two Operating Modes (auto-detected — do NOT ask user)
16
+
17
+ ### Mode A — Agent-Initialized Project
18
+ Indicators: context.json exists AND `context_version > 0` AND `context.services` has entries.
19
+ → Trust context.json as baseline, scan for drift and gaps, merge new findings without overwriting.
20
+
21
+ ### Mode B — Legacy / No-Context Project
22
+ Indicators: context.json missing OR `context_version == 0` OR `context.services` is empty.
23
+ → Treat every discovery as new. Build context.json entirely from disk. No assumptions about structure.
24
+
25
+ ## Core Rules (both modes)
26
+ - ALWAYS write context.json at the end — no exceptions
27
+ - NEVER delete existing context entries — only add or update
28
+ - NEVER assume a file will be in a specific location — scan first
29
+ - Report all findings in the sync report at the end
30
+
31
+ ---
32
+
33
+ ## Execution — Full Step-by-Step
34
+
35
+ ### Phase 0 — Prepare
36
+
37
+ **Step 0a.** Check if `.codeninja/context/` exists. If not → create it.
38
+ **Step 0b.** Call `context_read`. If returns empty schema (version == 0) → set mode B, fresh schema.
39
+ **Step 0c.** Call `service_scan` — detect all service directories at repo root.
40
+ **Step 0d.** Init sync report counters: `services_synced`, `routes_discovered`, `routes_new`,
41
+ `db_tables_synced`, `db_tables_new`, `gaps_filled`, `unchanged`, `legacy_inferences`
42
+
43
+ ---
44
+
45
+ ### Phase 1 — Repository Structure Discovery
46
+
47
+ #### 1a — Find all service-like directories
48
+ Scan every directory at repository root. A directory is a candidate service if it contains ANY of:
49
+ - `package.json`
50
+ - `app.js` or `index.js`
51
+ - `src/` directory
52
+ - `composer.json` (PHP — record but do not deep-scan)
53
+
54
+ For each candidate service directory:
55
+ - Read `package.json` if present → extract name, version, dependencies
56
+ - Detect type: NodeJS vs ReactJS:
57
+ - ReactJS: has `react` in dependencies, has `src/App.jsx` or `src/App.js`
58
+ - NodeJS: has `express` in dependencies, has `app.js` with `require('express')`
59
+ - Unknown: record type as "unknown"
60
+ - Read `.env` if present (gitignored, may not exist) → extract PORT, DB_*, REDIS_*, KEY, IV, API_KEY
61
+ - Read `.env.example` if present → extract all keys defined
62
+
63
+ #### 1b — Detect service port
64
+ Priority order:
65
+ 1. PORT value from `.env`
66
+ 2. PORT value from `.env.example`
67
+ 3. `app.listen(PORT, ...)` call in `app.js` — extract default
68
+ 4. `context.services[<n>].port` if already recorded
69
+
70
+ #### 1c — Detect modules (NodeJS services)
71
+ For each NodeJS service:
72
+ - Scan `modules/` directory (may be `v1/`, `v2/`, etc.)
73
+ - Each subdirectory containing `route.js` = one module
74
+ - Read `route.js` — extract: HTTP method, route path, whether auth middleware is applied
75
+ - Record: `{ module_name, version, method, route_path, has_auth }`
76
+
77
+ #### 1d — Detect React pages (ReactJS services)
78
+ For each ReactJS service:
79
+ - Scan `src/pages/` — each subdirectory with `index.jsx` or `index.js` = one page
80
+ - Scan `src/views/` if it exists — same logic
81
+ - Detect linked backend:
82
+ - Read `src/api/apiClient.js` → extract `baseURL` → parse port → match against `context.services`
83
+ - Or read `.env` → `REACT_APP_BASE_URL` → parse port
84
+
85
+ ---
86
+
87
+ ### Phase 2 — Database Discovery
88
+
89
+ **Step 2a.** Scan for `database/` directory at repo root.
90
+ If found → read sub-directories to determine db type (postgresql, mysql, mongodb).
91
+
92
+ **Step 2b.** For each db type directory found:
93
+ - List all `.sql` files in `migrations/` sorted by numeric prefix
94
+ - Parse each setup file:
95
+ - Extract table name from `CREATE TABLE`
96
+ - Extract column names and types
97
+ - Extract CHECK constraints and COMMENT ON COLUMN
98
+ - Extract per-file CREATE INDEX statements
99
+ - Parse ALTER files: ADD COLUMN, RENAME COLUMN, DROP COLUMN, ADD CONSTRAINT
100
+ - Parse DROP files: mark table as dropped
101
+ - Parse `111-setup-database-indexes.sql`: extract CREATE INDEX, associate with tables
102
+ - Build the full schema state from all files in order
103
+
104
+ ---
105
+
106
+ ### Phase 3 — Context Assembly
107
+
108
+ #### Mode A — Merge with existing context
109
+
110
+ For each discovered service:
111
+ - If service already in `context.services` → check for drift:
112
+ - Port changed? → flag and ask user which to keep
113
+ - New modules found not in context → add them
114
+ - Modules in context not found on disk → flag as "missing on disk"
115
+ - If service NOT in context → add it as new entry
116
+
117
+ For DB schema:
118
+ - Add any tables not in context
119
+ - Add any columns not tracked
120
+ - Add any indexes not tracked
121
+ - For renames found in ALTER files → append to change_log if not already there
122
+
123
+ #### Mode B — Build from scratch
124
+
125
+ For each discovered service, build full entry:
126
+ ```json
127
+ {
128
+ "service_name": "<n>",
129
+ "type": "nodejs|reactjs",
130
+ "port": <n>,
131
+ "description": "<inferred from package.json description or service name>",
132
+ "modules": [...],
133
+ "linked_service": "<inferred from apiClient.js>",
134
+ "detected_by": "sync"
135
+ }
136
+ ```
137
+
138
+ For legacy projects that don't follow agent conventions:
139
+ - Record what IS found without imposing expected structure
140
+ - Set `legacy: true` flag on the service entry
141
+ - Note what is missing and suggest /codeninja:init to scaffold missing pieces
142
+
143
+ ---
144
+
145
+ ### Phase 4 — Drift Report and Confirmation
146
+
147
+ Before writing anything, present a drift report:
148
+
149
+ ```
150
+ SYNC REPORT
151
+ ════════════════════════════════════════════
152
+ Mode: A (agent-initialized) | B (legacy/fresh)
153
+ ────────────────────────────────────────────
154
+ Services discovered on disk: [n]
155
+ Services already in context: [n]
156
+ New services to add: [n]
157
+ Services with drift: [n]
158
+ ────────────────────────────────────────────
159
+ DB tables on disk: [n]
160
+ DB tables already in context: [n]
161
+ New tables to add: [n]
162
+ ────────────────────────────────────────────
163
+ DRIFT ITEMS (require confirmation):
164
+ ⚠ service [n]: port in context = 1001, found on disk = 1002
165
+ ⚠ module [n] in context but route.js not found on disk
166
+ ────────────────────────────────────────────
167
+ ```
168
+
169
+ For each DRIFT ITEM: ask user to confirm which value to keep — one at a time.
170
+
171
+ ---
172
+
173
+ ### Phase 5 — Write Context
174
+
175
+ **Step 5.** Call `context_write` with the fully assembled context object.
176
+ Set `last_command` = "sync"
15
177
 
16
- ## Execution
17
- Read and execute `sync.workflow.md`.
18
- Use `run_drift_check` MCP tool to compare context vs disk.
19
- Surface all detected drifts before writing anything.
20
- User approves the sync before context is updated.
178
+ **Step 6.** Show final sync summary with counts of what was added/updated.
21
179
 
22
- ## After Running
23
- Call `context_write` with fully rebuilt context.
180
+ **Step 7.** Suggest next steps based on findings:
181
+ - If new services found → "Run /codeninja:api to add API routes"
182
+ - If schema gaps found → "Run /codeninja:db:sync to rebuild DB schema"
183
+ - If legacy project → "Run /codeninja:init to scaffold missing baseline files"
@@ -1,19 +1,61 @@
1
1
  ---
2
2
  slash_command: /codeninja:test
3
3
  personas: [global-orchestrator, nodejs-backend]
4
- skills: [mcp-and-context, api-builder]
5
- description: Generate Jest + Supertest test files for a module
4
+ skills: [mcp-and-context, api-builder, code-intelligence]
5
+ description: Generate or run Jest + Supertest tests for a NodeJS module.
6
6
  ---
7
7
 
8
8
  # /codeninja:test
9
9
 
10
- Delegates to: `.codeninja/commands/test.workflow.md`
11
-
12
10
  ## Before Running
13
11
  1. Call `context_read`
14
- 2. Ask: "Which module and service?" — list from `context.services[<n>].modules`
12
+ 2. Call `context_check_stale`
13
+
14
+ ## Execution — Full Step-by-Step
15
+
16
+ **Step 1.** Ask: "Which service?" (list from `context.services`)
17
+ - Store: `context.current_test.service_name`
18
+
19
+ **Step 2.** Ask: "Which module?" (list from `context.services[<n>].modules`)
20
+ - Store: `context.current_test.module_name`
21
+
22
+ **Step 3.** Ask: "Generate new tests or run existing tests?"
23
+ - Option 1: Generate new tests
24
+ - Option 2: Run existing tests
25
+ - Store: `context.current_test.type`
26
+
27
+ **Step 4.** If `generate`:
28
+ - Read `modules/<version>/<Module>/route.js` from disk
29
+ - Read `modules/<version>/<Module>/<module>_model.js` from disk
30
+ - Read `context.api_routes` for this module
31
+ - Delegate to nodejs-agent → generate `tests/<version>/<Module>.test.js`
32
+
33
+ Generated test file covers:
34
+ - 200 happy path for each endpoint
35
+ - 400 validation failures (missing required fields, wrong types)
36
+ - 401 missing or invalid API key header
37
+ - 401 missing or invalid auth token (for protected routes)
38
+ - 404 not found (where applicable)
39
+ - 500 simulated service error (mock DB failure)
40
+
41
+ Test structure:
42
+ ```javascript
43
+ const request = require('supertest');
44
+ const app = require('../../app');
45
+
46
+ describe('<Module> — POST /<path>', () => {
47
+ it('200 — happy path', async () => { ... });
48
+ it('400 — missing required field', async () => { ... });
49
+ it('401 — invalid api-key', async () => { ... });
50
+ it('401 — invalid auth token', async () => { ... });
51
+ it('404 — record not found', async () => { ... });
52
+ });
53
+ ```
54
+
55
+ **Step 5.** If `run`:
56
+ - Execute: `npm test` inside service directory
57
+ - Parse results and display pass/fail summary
58
+
59
+ **Step 6.** Call `context_write` → update `context.services[<n>].tests`
15
60
 
16
- ## Execution
17
- Read and execute `test.workflow.md`.
18
- Generate `tests/v1/<ModuleName>.test.js`.
19
- Tests cover: happy path, each validation failure, auth failure, edge cases.
61
+ **Step 7.** Show final summary.