codeninja 3.1.0 → 4.0.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 (111) hide show
  1. package/README.md +13 -1
  2. package/agent/database-agent.md +24 -1
  3. package/agent/nodejs-agent.md +79 -0
  4. package/cli.js +27 -7
  5. package/commands/audit.workflow.md +4 -1
  6. package/commands/db-create-table.workflow.md +1 -1
  7. package/commands/initialize-project.workflow.md +21 -0
  8. package/ide/antigravity/.agents/personas/database-architect.md +431 -153
  9. package/ide/antigravity/.agents/personas/global-orchestrator.md +219 -83
  10. package/ide/antigravity/.agents/personas/nodejs-backend.md +368 -133
  11. package/ide/antigravity/.agents/personas/reactjs-frontend.md +182 -101
  12. package/ide/antigravity/.agents/skills/api-builder/SKILL.md +58 -0
  13. package/ide/antigravity/.agents/skills/code-intelligence/SKILL.md +22 -0
  14. package/ide/antigravity/.agents/skills/database/SKILL.md +32 -0
  15. package/ide/antigravity/.agents/skills/mcp-and-context/SKILL.md +76 -82
  16. package/ide/antigravity/.agents/skills/reactjs/SKILL.md +36 -0
  17. package/ide/antigravity/.agents/workflows/codeninja-api.md +97 -21
  18. package/ide/antigravity/.agents/workflows/codeninja-audit.md +112 -16
  19. package/ide/antigravity/.agents/workflows/codeninja-db-create.md +135 -9
  20. package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +107 -9
  21. package/ide/antigravity/.agents/workflows/codeninja-db-index.md +100 -9
  22. package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +162 -9
  23. package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +102 -8
  24. package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +105 -11
  25. package/ide/antigravity/.agents/workflows/codeninja-debug.md +94 -10
  26. package/ide/antigravity/.agents/workflows/codeninja-design.md +61 -14
  27. package/ide/antigravity/.agents/workflows/codeninja-explain.md +59 -9
  28. package/ide/antigravity/.agents/workflows/codeninja-init.md +518 -21
  29. package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +451 -9
  30. package/ide/antigravity/.agents/workflows/codeninja-modularize.md +332 -9
  31. package/ide/antigravity/.agents/workflows/codeninja-optimize.md +124 -11
  32. package/ide/antigravity/.agents/workflows/codeninja-refactor.md +69 -16
  33. package/ide/antigravity/.agents/workflows/codeninja-review.md +85 -10
  34. package/ide/antigravity/.agents/workflows/codeninja-sync.md +957 -16
  35. package/ide/antigravity/.agents/workflows/codeninja-test.md +40 -13
  36. package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +546 -9
  37. package/ide/claude-code/.claude/CLAUDE.md +99 -0
  38. package/ide/claude-code/.claude/agents/database-agent.md +535 -0
  39. package/ide/claude-code/.claude/agents/nodejs-agent.md +493 -0
  40. package/ide/claude-code/.claude/agents/reactjs-agent.md +267 -0
  41. package/ide/claude-code/.claude/commands/codeninja-api.md +104 -0
  42. package/ide/claude-code/.claude/commands/codeninja-audit.md +119 -0
  43. package/ide/claude-code/.claude/commands/codeninja-db-create.md +138 -0
  44. package/ide/claude-code/.claude/commands/codeninja-db-drop.md +109 -0
  45. package/ide/claude-code/.claude/commands/codeninja-db-index.md +103 -0
  46. package/ide/claude-code/.claude/commands/codeninja-db-modify.md +165 -0
  47. package/ide/claude-code/.claude/commands/codeninja-db-seed.md +104 -0
  48. package/ide/claude-code/.claude/commands/codeninja-db-sync.md +106 -0
  49. package/ide/claude-code/.claude/commands/codeninja-debug.md +99 -0
  50. package/ide/claude-code/.claude/commands/codeninja-design.md +68 -0
  51. package/ide/claude-code/.claude/commands/codeninja-explain.md +61 -0
  52. package/ide/claude-code/.claude/commands/codeninja-init.md +529 -0
  53. package/ide/claude-code/.claude/commands/codeninja-integrate-api.md +453 -0
  54. package/ide/claude-code/.claude/commands/codeninja-modularize.md +334 -0
  55. package/ide/claude-code/.claude/commands/codeninja-optimize.md +129 -0
  56. package/ide/claude-code/.claude/commands/codeninja-refactor.md +76 -0
  57. package/ide/claude-code/.claude/commands/codeninja-review.md +87 -0
  58. package/ide/claude-code/.claude/commands/codeninja-sync.md +964 -0
  59. package/ide/claude-code/.claude/commands/codeninja-test.md +45 -0
  60. package/ide/claude-code/.claude/commands/codeninja-validate-page.md +548 -0
  61. package/ide/cursor/.cursor/rules/01-global-orchestrator.mdc +40 -38
  62. package/ide/cursor/.cursor/rules/02-mcp-and-context.mdc +47 -31
  63. package/ide/cursor/.cursor/rules/03-api-builder.mdc +30 -58
  64. package/ide/cursor/.cursor/rules/04-nodejs-generation.mdc +58 -0
  65. package/ide/cursor/.cursor/rules/05-database.mdc +54 -0
  66. package/ide/cursor/.cursor/rules/06-reactjs.mdc +36 -0
  67. package/ide/cursor/.cursor/rules/07-reactjs-generation.mdc +49 -0
  68. package/ide/cursor/.cursor/rules/08-code-intelligence.mdc +56 -0
  69. package/ide/cursor/.cursor/rules/09-workflow-steps.mdc +53 -0
  70. package/ide/vscode/.github/copilot-instructions.md +69 -270
  71. package/ide/vscode/.vscode/instructions/code-intelligence.instructions.md +58 -0
  72. package/ide/vscode/.vscode/instructions/database.instructions.md +55 -0
  73. package/ide/vscode/.vscode/instructions/nodejs.instructions.md +77 -0
  74. package/ide/vscode/.vscode/instructions/reactjs.instructions.md +42 -0
  75. package/package.json +2 -2
  76. package/tasks/ask-hashing-library.task.md +31 -0
  77. package/tasks/ask-language-type.task.md +26 -0
  78. package/tasks/ask-new-module-name.task.md +13 -0
  79. package/tasks/ask-new-service-name.task.md +13 -0
  80. package/tasks/ask-old-module-name.task.md +15 -0
  81. package/tasks/ask-old-service-name.task.md +13 -0
  82. package/tasks/ask-orm-type.task.md +26 -0
  83. package/tasks/collect-seed-data.task.md +19 -0
  84. package/tasks/generate-app.task.md +42 -0
  85. package/tasks/generate-common.task.md +13 -0
  86. package/tasks/generate-constants.task.md +13 -0
  87. package/tasks/generate-database.task.md +32 -0
  88. package/tasks/generate-encryption.task.md +28 -0
  89. package/tasks/generate-fast-defaults.task.md +7 -0
  90. package/tasks/generate-hashing.task.md +180 -0
  91. package/tasks/generate-headerValidator.task.md +13 -0
  92. package/tasks/generate-ioRedis.task.md +20 -0
  93. package/tasks/generate-language-en.task.md +12 -0
  94. package/tasks/generate-logging.task.md +12 -0
  95. package/tasks/generate-model.task.md +74 -6
  96. package/tasks/generate-notification.task.md +12 -0
  97. package/tasks/generate-package-json.task.md +69 -0
  98. package/tasks/generate-prisma-client.task.md +56 -0
  99. package/tasks/generate-prisma-schema.task.md +71 -0
  100. package/tasks/generate-rateLimiter.task.md +20 -0
  101. package/tasks/generate-readme.task.md +24 -0
  102. package/tasks/generate-response.task.md +27 -0
  103. package/tasks/generate-route-manager.task.md +32 -0
  104. package/tasks/generate-route.task.md +37 -0
  105. package/tasks/generate-swagger.task.md +8 -0
  106. package/tasks/generate-template.task.md +12 -0
  107. package/tasks/generate-tsconfig.task.md +38 -0
  108. package/tasks/generate-validator.task.md +31 -0
  109. package/ide/cursor/.cursor/rules/04-database.mdc +0 -87
  110. package/ide/cursor/.cursor/rules/05-reactjs.mdc +0 -83
  111. package/ide/cursor/.cursor/rules/06-code-intelligence.mdc +0 -112
@@ -1,11 +1,334 @@
1
+ This workflow runs when user invokes /codeninja:modularize
2
+
1
3
  ---
2
- slash_command: @modularize
3
- personas: [global-orchestrator, reactjs-frontend]
4
- skills: [mcp-and-context, reactjs]
5
- description: Extract repeated layout blocks into reusable React components
4
+ type: workflow
5
+ name: modularize
6
+ description: >
7
+ Scans one or all ReactJS pages, extracts repeated layout blocks
8
+ (header, footer, sidebar, navbar, etc.) into reusable components,
9
+ and rewrites each page to import and use those components. Reuses
10
+ existing components when they already exist. Never rewrites component
11
+ logic — layout structure only.
6
12
  ---
7
- # @modularize
8
- Delegates to: `.codeninja/commands/modularize.workflow.md`
9
- Before: `context_read`. Confirm linked NodeJS service exists.
10
- Scan all pages, identify repeated layout blocks.
11
- Show user what will be extracted and confirm before changes.
13
+
14
+ # Workflow: @modularize
15
+
16
+ ## Goal
17
+ Identify repeated structural blocks across pages, create shared components
18
+ for them under `src/components/`, and update each page to use the new
19
+ components. Result: zero duplicated layout HTML across the project.
20
+
21
+ ## Rules
22
+ - Read ALL target pages fully before creating any component
23
+ - NEVER create a component that already exists under `src/components/`
24
+ — reuse it instead
25
+ - NEVER modify business logic, state, API calls, or event handlers
26
+ in any page file — layout structure only
27
+ - NEVER break existing imports or prop flows
28
+ - ONE confirmation before any file is written
29
+ - After writing files → run task: `write-context`
30
+
31
+ ---
32
+
33
+ ## Step-by-Step Execution
34
+
35
+ ---
36
+
37
+ ### Phase 1 — Target Selection
38
+
39
+ 1. Run task: `ask-react-target-service`
40
+ Stores: `context.current_action.service_name`
41
+
42
+ 2. Run task: `ask-modularize-scope`
43
+ Stores: `context.current_action.modularize_scope`
44
+ If scope == "specific" → also stores `context.current_action.page_path`
45
+
46
+ ---
47
+
48
+ ### Phase 2 — Inventory Existing Components
49
+
50
+ Before scanning pages, inventory what already exists:
51
+
52
+ 1. Scan `src/components/` in the target service.
53
+ For each subdirectory → record the component name and its file path.
54
+ Example findings:
55
+ - `src/components/Header/index.jsx` → component: Header
56
+ - `src/components/Sidebar/index.jsx` → component: Sidebar
57
+ - `src/components/layout/Navbar/index.jsx` → component: Navbar
58
+
59
+ 2. For each existing component:
60
+ - Read the file
61
+ - Identify what structural role it plays (header, footer, sidebar,
62
+ navbar, modal wrapper, card shell, breadcrumbs, etc.)
63
+ - Record: `{ name, path, role, props_accepted }`
64
+
65
+ 3. Store the full inventory as the "existing components registry" in memory.
66
+ This is the source of truth for the reuse decision in Phase 4.
67
+
68
+ ---
69
+
70
+ ### Phase 3 — Scan Target Pages
71
+
72
+ #### If scope == "all":
73
+ Scan `src/pages/` — for each subdirectory containing `index.jsx` or
74
+ `index.js`, add it to the pages list.
75
+ Also scan `src/views/` if it exists.
76
+
77
+ #### If scope == "specific":
78
+ Pages list = [ context.current_action.page_path ]
79
+
80
+ For each page in the pages list:
81
+
82
+ 1. Read the full file content.
83
+
84
+ 2. Parse the JSX structure to identify the top-level layout blocks.
85
+ A layout block is a JSX subtree that:
86
+ - Appears at the top level of the return statement (not inside
87
+ a conditional or a list map)
88
+ - Has a clear structural role in the visual layout
89
+ - Does NOT contain unique per-page business logic
90
+
91
+ 3. Classify each block using these roles (in priority order):
92
+ - **header** — contains site logo, navigation links, user avatar/menu,
93
+ search bar. Typically rendered at the very top of every page.
94
+ - **footer** — copyright text, footer links, social icons. Bottom.
95
+ - **sidebar** — vertical navigation panel, collapsible menu, drawer.
96
+ - **navbar** — horizontal navigation bar, tab bar, breadcrumbs.
97
+ - **topbar** — page title row with action buttons (e.g. "Users | + Add New")
98
+ - **page-wrapper** — the outer container div that sets max-width,
99
+ padding, or background — wraps all page content.
100
+ - **card** — a bordered/shadowed container used for data display.
101
+ Only extract as a component if it appears in 2+ pages unchanged.
102
+ - **modal-shell** — the backdrop + centered box wrapper for modals.
103
+ Only extract if used in 2+ pages unchanged.
104
+
105
+ 4. Record for each block:
106
+ - Role (from list above)
107
+ - Exact JSX tree content
108
+ - Props/variables it references from the parent page scope
109
+ - Which pages it appears in (identical or near-identical)
110
+
111
+ ---
112
+
113
+ ### Phase 4 — Decide: Create vs Reuse vs Skip
114
+
115
+ For each block found across all pages, make one of three decisions:
116
+
117
+ **REUSE** — an existing component from Phase 2 already covers this role.
118
+ Condition: an existing component has the same `role` AND its structure
119
+ matches the block (same element types, same general layout — minor
120
+ class name differences are acceptable).
121
+ Action: the page will import the existing component. No new file created.
122
+
123
+ **CREATE** — no existing component covers this role.
124
+ Condition: no match in existing components registry.
125
+ Additional condition: the block appears in at least ONE page
126
+ (for header/footer/sidebar/navbar/topbar/page-wrapper — always create
127
+ even if seen on only one page, because they are foundational layout).
128
+ For card/modal-shell → only create if seen on 2+ pages unchanged.
129
+ Action: a new component will be created.
130
+
131
+ **SKIP** — the block is too unique to extract.
132
+ Condition: the block contains page-specific state, API calls, or
133
+ dynamic content that cannot be expressed as simple props.
134
+ Example: a sidebar that renders a different menu depending on user role
135
+ and reads from a page-specific hook → SKIP.
136
+ Action: leave the block inline in the page. Note it in the report.
137
+
138
+ ---
139
+
140
+ ### Phase 5 — Build Component Plan
141
+
142
+ For each block decided as CREATE, determine:
143
+
144
+ 1. **Component name** — PascalCase of the role.
145
+ Examples: Header, Footer, Sidebar, Navbar, PageTopbar, PageWrapper,
146
+ DataCard, ModalShell.
147
+ If a more specific name is obvious from the content
148
+ (e.g. the sidebar contains "Admin Menu") → use AdminSidebar.
149
+
150
+ 2. **File path** — `src/components/<ComponentName>/index.jsx`
151
+ and `src/components/<ComponentName>/<ComponentName>.module.css`
152
+
153
+ 3. **Props** — anything the block references from the parent scope
154
+ that varies between pages must become a prop.
155
+ Examples:
156
+ - Page title → `title` prop
157
+ - Active nav item → `activeItem` prop
158
+ - User display name in header → `userName` prop
159
+ Common static content (logo, copyright text, link list) → hardcoded
160
+ inside the component, not a prop.
161
+
162
+ 4. **CSS extraction** — any inline styles or style classes that belong
163
+ only to this block are moved to the component's `.module.css` file.
164
+ Classes shared with the rest of the page remain in the page's own
165
+ `.module.css`. Do not break existing page styles.
166
+
167
+ ---
168
+
169
+ ### Phase 6 — Show Plan and Confirm
170
+
171
+ Display the modularization plan:
172
+
173
+ ```
174
+ ┌──────────────────────────────────────────────────────┐
175
+ │ MODULARIZATION PLAN │
176
+ ├──────────────────────────────────────────────────────┤
177
+ │ Service : [service_name] │
178
+ │ Pages scanned: [n] │
179
+ ├──────────────────────────────────────────────────────┤
180
+ │ COMPONENTS TO CREATE │
181
+ │ → src/components/Header/index.jsx │
182
+ │ Props: userName, activeItem │
183
+ │ Used by: Login, Dashboard, Profile (3 pages) │
184
+ │ │
185
+ │ → src/components/Footer/index.jsx │
186
+ │ Props: none │
187
+ │ Used by: all 3 pages │
188
+ ├──────────────────────────────────────────────────────┤
189
+ │ COMPONENTS TO REUSE (already exist) │
190
+ │ → src/components/Sidebar/index.jsx [existing] │
191
+ │ Will be imported into: Dashboard, Profile │
192
+ ├──────────────────────────────────────────────────────┤
193
+ │ BLOCKS SKIPPED (too page-specific to extract) │
194
+ │ → Dashboard hero banner — contains dynamic API data │
195
+ ├──────────────────────────────────────────────────────┤
196
+ │ PAGES TO UPDATE │
197
+ │ → src/pages/Login/index.jsx │
198
+ │ → src/pages/Dashboard/index.jsx │
199
+ │ → src/pages/Profile/index.jsx │
200
+ └──────────────────────────────────────────────────────┘
201
+ ```
202
+
203
+ Ask exactly this question:
204
+ "Proceed with this modularization plan? (yes / no / adjust)"
205
+
206
+ - If yes → proceed to Phase 7 immediately
207
+ - If no → abort. Nothing is created.
208
+ - If adjust → ask: "What would you like to change?"
209
+ Allow the user to exclude a component, rename one, or change a
210
+ prop assignment. Apply the adjustment and re-display the plan.
211
+
212
+ ---
213
+
214
+ ### Phase 7 — Generate Components
215
+
216
+ For each component in the CREATE list:
217
+
218
+ #### Generate `src/components/<ComponentName>/index.jsx`
219
+
220
+ Structure:
221
+ - JSDoc block above the component:
222
+ ```
223
+ /**
224
+ * [Role] component shared across all pages.
225
+ *
226
+ * @param {Object} props
227
+ * @param {string} [props.<propName>] - [description] ← one line per prop
228
+ * @returns {JSX.Element}
229
+ */
230
+ ```
231
+ - Import React at the top
232
+ - Import CSS module: `import styles from './<ComponentName>.module.css'`
233
+ - Functional component with props destructured in the signature
234
+ - JSX extracted verbatim from the source page, with parent-scope
235
+ variable references replaced by the corresponding prop name
236
+ - Default export
237
+
238
+ #### Generate `src/components/<ComponentName>/<ComponentName>.module.css`
239
+
240
+ - Move all CSS classes that belong exclusively to this component's
241
+ block from the source page's `.module.css`
242
+ - If no specific classes are used → generate an empty file with a
243
+ comment: `/* Styles for <ComponentName> */`
244
+
245
+ ---
246
+
247
+ ### Phase 8 — Update Pages
248
+
249
+ For each page in the pages list that references at least one component
250
+ (created or reused):
251
+
252
+ Read the current page file. Apply these surgical edits:
253
+
254
+ 1. **Add imports** at the top of the file, after existing imports:
255
+ ```jsx
256
+ import Header from '../../components/Header';
257
+ import Footer from '../../components/Footer';
258
+ ```
259
+ Use the correct relative path from the page file's location to
260
+ `src/components/`. Always use `../../components/` from the standard
261
+ `src/pages/<PageName>/` depth.
262
+
263
+ 2. **Replace the extracted JSX block** with the component tag.
264
+ Pass any required props using the values that were previously
265
+ inline in the page.
266
+ Example:
267
+ Before: `<header className={styles.header}><nav>...</nav></header>`
268
+ After: `<Header activeItem="dashboard" userName={user.name} />`
269
+
270
+ 3. **Remove orphaned imports** — if the original block used an import
271
+ that is no longer referenced in the page after extraction
272
+ (e.g. a logo image import that moved into the Header component) →
273
+ remove it from the page's import list.
274
+
275
+ 4. **Clean up orphaned CSS classes** — if classes were moved to the
276
+ component's CSS module, remove them from the page's `.module.css`.
277
+
278
+ Never modify:
279
+ - Business logic functions (state, useEffect, API calls)
280
+ - The page's own JSX content outside the extracted blocks
281
+ - Event handlers, form logic, any non-layout code
282
+
283
+ > **Multi-agent:** Delegate to `reactjs-frontend` via Task invocation for parallel execution.
284
+ > Read `.codeninja/tasks/` before generating each component and updating pages.
285
+
286
+ ---
287
+
288
+ ### Phase 9 — Write Context and Report
289
+
290
+ Run task: `write-context` with:
291
+ - Append to `context.services[<service_name>].components`:
292
+ For each new component created:
293
+ `{ name, path, role, props, used_by: [page_names], created_by: "modularize" }`
294
+ - Set `last_command` = "modularize"
295
+ - Append to top-level `change_log`:
296
+ `{ timestamp, command: "modularize", action: "Created [n] components, updated [n] pages", affected_files: [...] }`
297
+ - After write-context → call MCP tool `context_clear_scratchpad` with keys: ["current_action"]
298
+
299
+ Display the modularization report:
300
+
301
+ ```
302
+ @modularize Complete
303
+ ─────────────────────────────────────────
304
+ Components created : [n]
305
+ Components reused : [n]
306
+ Pages updated : [n]
307
+ Blocks skipped : [n]
308
+ ─────────────────────────────────────────
309
+ Created:
310
+ ✓ src/components/Header/index.jsx
311
+ ✓ src/components/Header/Header.module.css
312
+ ✓ src/components/Footer/index.jsx
313
+ ✓ src/components/Footer/Footer.module.css
314
+
315
+ Updated:
316
+ ✓ src/pages/Login/index.jsx
317
+ ✓ src/pages/Dashboard/index.jsx
318
+ ✓ src/pages/Profile/index.jsx
319
+ ─────────────────────────────────────────
320
+ ```
321
+
322
+ Run task: `show-final-summary`
323
+
324
+ ---
325
+
326
+ ## What This Workflow Does NOT Do
327
+
328
+ - Does not create page-level components (forms, tables, charts) —
329
+ only layout/structural shell components
330
+ - Does not add routing — components are not registered in App.jsx
331
+ - Does not touch any backend files
332
+ - Does not modify apiHandler.js or apiClient.js
333
+ - Does not add state management (Redux, Context API)
334
+ - Does not install any new npm packages
@@ -1,13 +1,126 @@
1
+ This workflow runs when user invokes /codeninja:optimize
2
+
1
3
  ---
2
- slash_command: /codeninja:optimize
3
- personas: [global-orchestrator, nodejs-backend, database-architect]
4
- skills: [mcp-and-context, api-builder, database, code-intelligence]
5
- description: Find and fix performance bottlenecks with concrete impact estimates
4
+ type: workflow
5
+ name: optimize
6
+ description: >
7
+ Analyse and improve performance of a route, query, or service using real
8
+ project context — actual table sizes, existing indexes, query patterns, and
9
+ middleware overhead. Produces ranked recommendations with concrete code.
6
10
  ---
7
- # /codeninja:optimize
8
- Delegates to: `.codeninja/commands/optimize.workflow.md`
9
- Before: `context_read` for `context.db.schema` and `context.services`.
10
- Ask: slow endpoint / heavy query / startup / describe it.
11
- Cross-reference existing indexes. Generate migration via `migration_next_number`.
12
- Output: [HIGH|MED|LOW] ranked. Confirm before applying.
13
- `context_write` after index additions.
11
+
12
+ # Workflow: @optimize / /codeninja:optimize
13
+
14
+ ## Goal
15
+ Find real performance bottlenecks using actual project data. Every
16
+ recommendation includes a concrete fix and an estimated impact.
17
+ No generic advice — only changes grounded in this codebase.
18
+
19
+ ## Rules
20
+ - Check context.db.schema for existing indexes before recommending new ones
21
+ - Reference real table names and column names from context
22
+ - Estimate impact where possible (e.g., "seq scan → index scan on 2M rows")
23
+ - Rank by impact: HIGH → MED → LOW
24
+
25
+ ---
26
+
27
+ ## Step-by-Step Execution
28
+
29
+ ### Step 1 — Identify Target
30
+ If not specified, ask:
31
+ "What would you like to optimise?
32
+ (a) A slow API endpoint — paste the route path
33
+ (b) A heavy SQL query — paste the query or file path
34
+ (c) Overall service startup / memory usage
35
+ (d) Something else — describe it"
36
+
37
+ ### Step 2 — Load Context
38
+ 1. Call `context_read` — load `context.db.schema`, `context.services`
39
+ 2. Call `fs_read` on the relevant files (route.js, _model.js)
40
+ 3. For DB queries: list existing indexes from `context.db.schema.<table>.indexes`
41
+
42
+ ### Step 3A — Database Query Analysis
43
+
44
+ For each query in the target:
45
+
46
+ **Check 1 — Missing Indexes**
47
+ Compare WHERE / JOIN / ORDER BY columns against existing indexes.
48
+ ```
49
+ Table: tbl_scores
50
+ Query: WHERE week_id = $1 ORDER BY score DESC
51
+ Indexes on tbl_scores: [id, user_id] ← week_id NOT indexed
52
+ Fix: CREATE INDEX CONCURRENTLY idx_scores_week_id_score
53
+ ON tbl_scores(week_id, score DESC);
54
+ Impact: HIGH — seq scan on every leaderboard call → index scan
55
+ ```
56
+
57
+ **Check 2 — SELECT * Anti-Pattern**
58
+ ```
59
+ Before: SELECT * FROM tbl_users WHERE user_id = $1
60
+ After: SELECT id, user_id, display_name, status FROM tbl_users WHERE user_id = $1
61
+ Why: Eliminates unused column transfer; avoids fetching large text/jsonb columns
62
+ ```
63
+
64
+ **Check 3 — N+1 Query Pattern**
65
+ Flag any loop that calls a DB function per iteration.
66
+ Suggest: single query with IN clause or JOIN.
67
+
68
+ **Check 4 — Window Function Choice**
69
+ ```
70
+ RANK() → gaps after ties (positions: 1, 2, 2, 4) ← usually wrong for leaderboards
71
+ DENSE_RANK() → no gaps (positions: 1, 2, 2, 3) ← correct for leaderboards
72
+ ROW_NUMBER() → unique position per row (1, 2, 3, 4) ← correct for pagination
73
+ ```
74
+
75
+ **Check 5 — Duplicate Row Prevention**
76
+ ```
77
+ -- Symptom: same user appears multiple times in results
78
+ -- Fix: dedup using MIN(id) GROUP BY user_id before joining
79
+ SELECT MIN(id) as id, user_id FROM tbl_users GROUP BY user_id
80
+ ```
81
+
82
+ **Check 6 — Functional Index Trap**
83
+ ```
84
+ -- BAD: DATE(created_at) = '2026-04-13' prevents index use
85
+ -- GOOD: created_at >= '2026-04-13' AND created_at < '2026-04-14'
86
+ ```
87
+
88
+ **Check 7 — work_mem for Sort Operations**
89
+ If EXPLAIN shows "Sort Method: external merge Disk:", recommend:
90
+ ```sql
91
+ SET work_mem = '64MB'; -- session-level, before the heavy query
92
+ ```
93
+
94
+ ### Step 3B — API Route Analysis
95
+
96
+ Check middleware chain for overhead:
97
+ - Is heavy middleware applied to lightweight routes?
98
+ - Any synchronous blocking in the request path?
99
+ - Repeated DB lookups that could be cached in Redis?
100
+
101
+ Check response size:
102
+ - Is pagination applied to list endpoints?
103
+ - Any large JSON blobs being serialized unnecessarily?
104
+
105
+ ### Step 4 — Output Recommendations
106
+
107
+ ```
108
+ [HIGH | MED | LOW] — Impact label
109
+
110
+ Target: describe what's being optimised
111
+ Root cause: why it's slow right now
112
+ Fix:
113
+ [exact SQL or code change]
114
+ Estimated gain: concrete estimate
115
+ Side effects: anything the developer should know
116
+ ```
117
+
118
+ List all recommendations, highest impact first.
119
+
120
+ ### Step 5 — Offer to Apply
121
+ "I've found [N] optimisations. Want me to apply them?
122
+ I'll implement each one and show you the change before writing."
123
+
124
+ For index changes: generate `NNN_add_index_<name>.sql` migration file.
125
+ For code changes: edit the relevant model or route file surgically.
126
+ Always call `context_write` after applying index additions to update schema.
@@ -1,23 +1,76 @@
1
+ This workflow runs when user invokes /codeninja:refactor
2
+
3
+ ---
4
+ type: workflow
5
+ name: refactor
6
+ description: >
7
+ Rename, restructure, or improve existing code. Always records changes in
8
+ context.change_log so all agents remain aware of the history.
1
9
  ---
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
10
+
11
+ # Workflow: @refactor
12
+
13
+ ## Goal
14
+ Make a controlled change to existing code with full traceability in context.
15
+
16
+ ## Rules
17
+ - Every rename is recorded in `context.change_log`
18
+ - DB column renames generate a migration file
19
+ - Never delete the old name from change_log
20
+
6
21
  ---
7
22
 
8
- # /codeninja:refactor
23
+ ## Step-by-Step Execution
24
+
25
+ 1. Run task: `ask-refactor-type`
26
+ - Options: rename DB column, rename service, rename module, restructure files
27
+ - Stores: `context.current_refactor.type`
28
+
29
+ 2. Run task: `ask-target-service` (if applicable)
30
+
31
+ 3. Based on refactor type:
32
+
33
+ ### rename DB column
34
+ - Run task: `ask-table-name`
35
+ - Run task: `ask-old-column-name`
36
+ - Run task: `ask-new-column-name`
37
+ - Delegate to `database-agent`:
38
+ - Generate ALTER TABLE migration
39
+ - Update `context.db.schema.tables[<table>].columns`
40
+ - Append to `context.db.schema.change_log`
41
+ - Delegate to `nodejs-agent`:
42
+ - Find all references to old column name in service files
43
+ - Update model queries
44
+ - Update swagger_doc.json
45
+
46
+ ### rename service
47
+ - Run task: `ask-old-service-name`
48
+ - Run task: `ask-new-service-name`
49
+ - Update `context.services` key
50
+ - Append to `context.change_log`
51
+
52
+ ### rename table
53
+ - Run task: `ask-table-name`
54
+ - Run task: `ask-new-table-name`
55
+ - Delegate to `database-agent`:
56
+ - Generate ALTER migration: `RENAME TABLE <old> TO <new>`
57
+ - Update `context.db.schema.tables` key
58
+ - Append to `context.db.schema.change_log`:
59
+ `{ type: "table_renamed", from: "<old>", to: "<new>", migration_file: "..." }`
60
+ - Delegate to `nodejs-agent`:
61
+ - Find all references to old table name in model files
62
+ - Update queries in all affected services
63
+ - Append to top-level `context.change_log`
9
64
 
10
- Delegates to: `.codeninja/commands/refactor.workflow.md`
65
+ ### rename module
66
+ - Run task: `ask-old-module-name`
67
+ - Run task: `ask-new-module-name`
68
+ - Delegate to `nodejs-agent` → rename files and update route_manager
11
69
 
12
- ## Before Running
13
- 1. Call `context_read`
14
- 2. Ask: "What are you refactoring?" — field rename, file restructure, module rename?
70
+ 4. Confirm: "Apply refactor? (yes/no)"
15
71
 
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.
72
+ > **Multi-agent:** Delegate to `database-architect` (DB refactors) or `nodejs-backend` (service/module refactors) via Task invocation for parallel execution.
73
+ > Read `.codeninja/tasks/` before applying each change.
21
74
 
22
- ## After Running
23
- Call `context_write` with updated service/module names if renamed.
75
+ 5. If yes → make changes → run task: `write-context`
76
+ 6. Run task: `show-final-summary`
@@ -1,12 +1,87 @@
1
+ This workflow runs when user invokes /codeninja:review
2
+
1
3
  ---
2
- slash_command: /codeninja:review
3
- personas: [global-orchestrator, nodejs-backend]
4
- skills: [mcp-and-context, api-builder, code-intelligence]
5
- description: Code review severity-ranked findings with exact before/after fixes
4
+ type: workflow
5
+ name: review
6
+ description: >
7
+ Deep code review of any file or module security, architecture, naming
8
+ conventions, and alignment with project patterns. Outputs severity-ranked
9
+ findings with exact fixes.
6
10
  ---
7
- # /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.
11
+
12
+ # Workflow: @review / /codeninja:review
13
+
14
+ ## Goal
15
+ Produce a structured code review that finds real issues using actual project
16
+ context not generic best practices. Every finding references the real file
17
+ and line, and every fix is concrete code, not advice.
18
+
19
+ ## Rules
20
+ - Read the actual file before reviewing it
21
+ - Cross-reference `context.db.schema` for table/column accuracy
22
+ - Compare against 1–2 existing modules to check pattern consistency
23
+ - Never flag something as an issue if it's the established pattern in this project
24
+
25
+ ---
26
+
27
+ ## Step-by-Step Execution
28
+
29
+ ### Step 1 — Identify Target
30
+ If not specified, ask: "Which file or module would you like me to review?"
31
+
32
+ ### Step 2 — Load Context
33
+ 1. Call `context_read`
34
+ 2. Call `fs_read` on the target file
35
+ 3. Read 1–2 similar modules from `context.services[<service>].modules` for comparison
36
+
37
+ ### Step 3 — Run Review Checklist
38
+
39
+ #### Security (flag as CRITICAL if failing)
40
+ - [ ] All POST/PUT/PATCH routes have validatorjs input validation
41
+ - [ ] API key middleware applied before any route logic
42
+ - [ ] JWT auth middleware present on protected routes
43
+ - [ ] No hardcoded secrets, keys, or passwords
44
+ - [ ] Parameterized queries only — no string concatenation in SQL
45
+ - [ ] Error responses don't leak stack traces or internal details
46
+
47
+ #### Architecture (flag as WARNING if failing)
48
+ - [ ] 2-layer rule: no SQL in route.js, no res.json() in model.js
49
+ - [ ] route_manager.js registration matches route file
50
+ - [ ] swagger_doc.json has entry for this endpoint
51
+ - [ ] All user-facing strings in languages/en.js — none hardcoded in route.js
52
+
53
+ #### Code Quality (flag as SUGGESTION if failing)
54
+ - [ ] JSDoc on every exported function
55
+ - [ ] No unused variables or dead imports
56
+ - [ ] No console.log — project logger used instead
57
+ - [ ] Async functions have try/catch blocks
58
+ - [ ] SELECT * not used — explicit column list
59
+
60
+ #### Database (flag as WARNING if failing)
61
+ - [ ] Column names match context.db.schema exactly (snake_case)
62
+ - [ ] Foreign key columns indexed
63
+ - [ ] Transactions used where multiple writes occur together
64
+ - [ ] LIMIT clause on any query that could return unbounded rows
65
+
66
+ ### Step 4 — Output Findings
67
+
68
+ For each issue:
69
+ ```
70
+ [CRITICAL|WARNING|SUGGESTION]
71
+ File: path/to/file.js (~line N)
72
+ Issue: clear one-line description
73
+ Before: the current code
74
+ After: the corrected code
75
+ Why: one sentence explanation
76
+ ```
77
+
78
+ End with summary line:
79
+ ```
80
+ Review complete: X critical · Y warnings · Z suggestions
81
+ ```
82
+
83
+ ### Step 5 — Offer Auto-Fix
84
+ "Would you like me to apply any of these fixes? I'll confirm each change before writing."
85
+
86
+ For SUGGESTION-level items: offer to apply all at once.
87
+ For WARNING/CRITICAL items: apply one at a time, confirm each.