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,111 +1,105 @@
1
1
  ---
2
2
  skill: mcp-and-context
3
- scope: always-loaded
3
+ scope: all-commands
4
+ loaded-for:
5
+ - all commands (always active)
4
6
  description: >
5
- MCP tool usage rules and context management protocol. Loaded on every
6
- session. Governs how every persona reads, writes, and protects context.json.
7
+ All MCP tools available in this project, the complete context.json schema
8
+ (including v4.0 fields), and the stale scratchpad recovery procedure.
7
9
  ---
8
10
 
9
- # Skill: MCP and Context Management
11
+ # Skill: MCP and Context
10
12
 
11
- This skill governs all interaction with the codeninja MCP server and
12
- context.json. Every persona must follow these rules without exception.
13
-
14
- ---
15
-
16
- ## Available MCP Tools
13
+ ## All MCP Tools
17
14
 
18
15
  | Tool | Purpose | When to use |
19
- |------|---------|-------------|
20
- | `context_read` | Load full project context | First thing on every activation |
21
- | `context_write` | Persist changes (deep-merge) | After every completed operation |
22
- | `context_clear_scratchpad` | Clear a current_* key | After writing context |
23
- | `context_check_stale` | Detect unresolved scratchpad | Step 0 of activation |
24
- | `service_scan` | Discover all services on disk | Step 2 of activation |
25
- | `migration_next_number` | Get next sequential migration number | Before creating any migration file |
16
+ |---|---|---|
17
+ | `context_read` | Load full context.json into memory | FIRST on every activation |
18
+ | `context_write` | Deep-merge updates into context.json | After every completed operation |
19
+ | `context_clear_scratchpad` | Clear current_* scratchpad key | After writing context post-workflow |
20
+ | `context_check_stale` | Detect unresolved scratchpad operations | Step 0 of every activation |
21
+ | `service_scan` | Discover all service directories on disk | Step 2 of activation; compare with context.services |
22
+ | `migration_next_number` | Get next sequential migration number | Before generating any migration file |
26
23
  | `fs_read` | Read a file from disk | Before modifying any existing file |
27
- | `fs_list` | List directory contents | When scanning structure |
28
- | `fs_exists` | Check if file/directory exists | Before conditional operations |
29
- | `file_insert_after` | Surgical file insertion | Appending to route_manager.js, etc. |
30
- | `file_contains` | Check if string exists in file | Before appending to avoid duplicates |
31
- | `run_drift_check` | Compare context vs disk | During @sync workflow |
32
- | `lint_file` | Lint a generated file | After generating JS/SQL files |
33
- | `npm_check_package` | Look up npm package info | When verifying dependencies |
34
- | `npm_install` | Install a package | When adding new dependencies |
35
- | `validate_redis_connection` | Test Redis connectivity | During service init |
36
- | `validate_postgres_connection` | Test DB connectivity | During service init |
37
- | `analyze_middleware_order` | Check middleware chain | During @audit |
38
- | `analyze_encryption_library` | Verify encryption setup | During @audit |
39
- | `analyze_language_keys` | Check i18n completeness | During @audit |
40
- | `analyze_dependencies` | Scan package.json | During @audit / @sync |
41
- | `analyze_env_file` | Check .env completeness | During @audit |
42
-
43
- ---
44
-
45
- ## Absolute Rules
46
-
47
- - NEVER read `context.json` directly with `fs_read` — always use `context_read`
48
- - NEVER write `context.json` directly — always use `context_write`
49
- - `context_write` deep-merges — it never overwrites the whole file
50
- - `change_log` is append-only — never delete entries
51
- - NEVER assume a stored value — always read from loaded context object
52
- - `context_version` is managed automatically — if `context_read` returns a
53
- higher version than expected, the file was modified externally — re-read before acting
54
-
55
- ---
56
-
57
- ## Context Schema Reference
24
+ | `fs_list` | List directory contents | When scanning project structure |
25
+ | `fs_exists` | Check if a file/directory exists | Before conditional operations |
26
+ | `file_insert_after` | Surgically insert content after a marker | route_manager.js, swagger_doc.json — never rewrite |
27
+ | `file_contains` | Check if file already contains a string | Before appending to avoid duplicates |
28
+ | `run_drift_check` | Compare context vs actual files on disk | During /codeninja:sync |
29
+ | `lint_file` | Lint a generated JS/TS file | After any JS/TS file generation |
30
+ | `analyze_middleware_order` | Verify middleware chain order | During /codeninja:audit |
31
+ | `analyze_encryption_library` | Verify encryption library usage | During /codeninja:audit |
32
+ | `analyze_language_keys` | Check i18n key consistency | During /codeninja:audit |
33
+ | `analyze_dependencies` | Scan package.json for issues | During /codeninja:audit |
34
+ | `analyze_env_file` | Check .env completeness | During /codeninja:audit |
35
+ | `validate_redis_connection` | Test Redis connectivity | During /codeninja:init |
36
+ | `validate_postgres_connection` | Test PostgreSQL connectivity | During /codeninja:init |
37
+
38
+ ## Context.json Schema (v4.0)
58
39
 
59
40
  ```json
60
41
  {
61
42
  "context_version": 0,
62
43
  "project_name": "",
44
+ "initialized_at": "",
45
+ "last_updated_at": "",
46
+ "last_command": "",
47
+ "repository_state": "fresh|existing",
63
48
  "project_info": {
64
49
  "summary": "",
65
50
  "detected_entities": [],
66
- "features": [],
67
- "from_doc": { "project_name": "", "domain": "", "purpose": "", "features": [], "entities": [], "tech_preferences": [] },
68
- "from_sow": { "integrations": [] },
69
- "from_figma": { "screens": [] }
51
+ "has_doc": false,
52
+ "has_sow": false,
53
+ "has_figma": false
70
54
  },
71
55
  "db": {
72
- "type": "",
73
- "name": "",
74
- "host": "",
75
- "port": 0,
76
- "user": "",
77
- "schema": {}
56
+ "type": "postgres|mysql|mongodb",
57
+ "orm": "none|prisma",
58
+ "name": "", "host": "", "port": 0, "user": "",
59
+ "schema": { "tables": {}, "change_log": [] }
60
+ },
61
+ "services": {
62
+ "<service_name>": {
63
+ "type": "nodejs|reactjs",
64
+ "language": "javascript|typescript",
65
+ "hashing_library": "bcryptjs|argon2",
66
+ "port": 0,
67
+ "client_type": "reactjs|app",
68
+ "encrypted_transport": true,
69
+ "supported_languages": ["en"],
70
+ "encryption_key": "",
71
+ "encryption_iv": "",
72
+ "api_key": "",
73
+ "modules": [],
74
+ "linked_service": "",
75
+ "linked_service_port": 0
76
+ }
78
77
  },
79
- "services": {},
80
78
  "api_routes": [],
81
- "change_log": []
79
+ "change_log": [],
80
+ "current_init": {},
81
+ "current_api": {},
82
+ "current_action": {}
82
83
  }
83
84
  ```
84
85
 
85
- ---
86
-
87
- ## Scratchpad Keys (current_* pattern)
88
-
89
- Temporary keys written during multi-step workflows:
86
+ **New v4.0 fields:**
87
+ - `db.orm` — "none" (raw driver) or "prisma" (Prisma ORM)
88
+ - `services[name].language` "javascript" or "typescript"
89
+ - `services[name].hashing_library` — "bcryptjs" or "argon2"
90
90
 
91
- | Key | Used by |
92
- |-----|---------|
93
- | `current_init` | initialize-project workflow |
94
- | `current_api` | create-api workflow |
95
- | `current_table` | db-create-table workflow |
96
- | `current_modify` | db-modify-table workflow |
97
- | `current_index` | db-add-index workflow |
98
- | `current_design` | design workflow |
91
+ ## Context Rules
99
92
 
100
- After `context_write` with final results always call `context_clear_scratchpad`
101
- for the relevant key. This prevents stale data from persisting across sessions.
102
-
103
- ---
93
+ - `context_write` deep-merges it never replaces the whole file
94
+ - `change_log` is append-only never delete or modify entries
95
+ - `context_version` auto-increments on each write
96
+ - Stale scratchpad: if `context_check_stale` returns unresolved keys, resolve them before any other operation
97
+ - After every completed workflow: call `context_write` then `context_clear_scratchpad`
104
98
 
105
99
  ## Stale Scratchpad Recovery
106
100
 
107
- When `context_check_stale` returns stale keys:
108
- 1. Show the user what was in progress
109
- 2. Ask: "Resume this operation or discard it?"
110
- 3. If resume → re-read the scratchpad and continue from where it left off
111
- 4. If discard call `context_clear_scratchpad` and start fresh
101
+ If `context_check_stale` returns stale `current_*` keys:
102
+ 1. Read the stale key contents
103
+ 2. Ask user: "There's an unfinished [operation] — continue it or discard?"
104
+ 3. If continue: resume the workflow from the summary step
105
+ 4. If discard: call `context_clear_scratchpad` for that key, then proceed
@@ -209,3 +209,39 @@ export default App;
209
209
  5. Wire form submit and button clicks to handler functions
210
210
  6. Add loading state (boolean), error state (string), success state
211
211
  7. Show loading spinner during API call, error message on failure, success feedback on completion
212
+
213
+ ---
214
+
215
+ ## Wave Generation Order (v4.0)
216
+
217
+ Wave 1 — Foundation (read `.codeninja/tasks/generate-react-package-json.task.md` etc.):
218
+ - `package.json` → task: generate-react-package-json
219
+ - `.env` + `.env.example` → task: generate-react-env
220
+ - `.gitignore` → task: generate-react-gitignore
221
+ - `README.md` → task: generate-readme
222
+ - `public/index.html` → task: generate-react-index-html
223
+ - `.htaccess` (root + public) → task: generate-react-htaccess
224
+
225
+ Wave 2 — API Layer:
226
+ - `src/api/apiClient.js` → task: generate-react-api-client
227
+ - `src/api/apiHandler.js` → task: generate-react-api-handler
228
+
229
+ Wave 3 — Application Shell:
230
+ - `src/pages/Welcome/index.jsx` → task: generate-react-welcome-page
231
+ - `src/App.jsx` → task: generate-react-app-jsx
232
+ - `src/index.jsx` → task: generate-react-index-jsx
233
+
234
+ Wave 4 — Docker:
235
+ - `Dockerfile` + `nginx.conf` → task: generate-react-dockerfile
236
+
237
+ ## .htaccess Pattern
238
+
239
+ Two files are always generated — one at service root, one in `public/`:
240
+
241
+ ```apache
242
+ RewriteEngine On
243
+ RewriteBase /
244
+ RewriteCond %{REQUEST_FILENAME} !-f
245
+ RewriteCond %{REQUEST_FILENAME} !-d
246
+ RewriteRule ^ index.html [L]
247
+ ```
@@ -1,28 +1,104 @@
1
+ This workflow runs when user invokes /codeninja:api
2
+
3
+ ---
4
+ type: workflow
5
+ name: create-api
6
+ description: >
7
+ Add a new API module (route.js + model.js) to an existing NodeJS service.
8
+ Appends to route_manager.js and patches swagger_doc.json surgically —
9
+ never rewrites existing files. Fully context-aware.
10
+ ---
11
+
12
+ # Workflow: @create-api
13
+
14
+ ## Goal
15
+ Scaffold a complete API module inside an existing NodeJS service.
16
+ Every generated file references actual DB columns from context.
17
+
18
+ ## Rules
19
+ - Ask ONE question at a time
20
+ - Never invent table or column names — read from `context.db.schema`
21
+ - Always add the new route to `context.api_routes`
22
+ - Always update `swagger_doc.json` with the new endpoint
23
+
24
+ ---
25
+
26
+ ## Step-by-Step Execution
27
+
28
+ ### Phase 0 — Existing Pattern Review
29
+ Before asking any questions, read the existing modules in
30
+ context.services[<service_name>].modules and scan 1–2 existing
31
+ route.js and _model.js files from the service.
32
+
33
+ Identify:
34
+ - Naming conventions in use (camelCase vs PascalCase for functions)
35
+ - Common validation patterns (which fields always get required rules)
36
+ - Any project-specific response patterns beyond the standard contract
37
+ - Auth pattern used across existing routes (all full? mixed?)
38
+
39
+ Surface a one-line summary: "I've reviewed [n] existing modules.
40
+ I'll follow the same structure." Then proceed to Phase 1.
41
+
42
+ ### Phase 1 — Target Service
43
+ 1. Run task: `ask-target-service`
44
+ - List available services from `context.services`
45
+ - Stores: `context.current_api.service_name`
46
+
47
+ 2. Run task: `ask-api-version`
48
+ - Default: v1
49
+ - Stores: `context.current_api.version`
50
+
51
+ ---
52
+
53
+ ### Phase 2 — Module Identity
54
+ 3. Run task: `ask-module-name`
55
+ - Example: Products, Orders, Invoice
56
+ - Stores: `context.current_api.module_name`
57
+
58
+ 4. Run task: `ask-http-method`
59
+ - Options: GET, POST, PUT, PATCH, DELETE
60
+ - Stores: `context.current_api.method`
61
+
62
+ 5. Run task: `ask-route-path`
63
+ - Example: /products, /products/:id
64
+ - Stores: `context.current_api.route_path`
65
+
66
+ 6. Run task: `ask-route-description`
67
+ - Stores: `context.current_api.description`
68
+
1
69
  ---
2
- slash_command: /codeninja:api
3
- personas: [global-orchestrator, nodejs-backend]
4
- skills: [mcp-and-context, api-builder]
5
- description: Add a new API endpoint to an existing NodeJS service using the 5-step SOP
70
+
71
+ ### Phase 3 — Database Binding
72
+ 7. Run task: `ask-primary-table`
73
+ - Show available tables from `context.db.schema.tables`
74
+ - Stores: `context.current_api.primary_table`
75
+
76
+ 8. Run task: `ask-requires-auth`
77
+ - Options: yes / no
78
+ - Stores: `context.current_api.requires_auth`
79
+
6
80
  ---
7
81
 
8
- # /codeninja:api
82
+ ### Phase 4 — Generate
83
+ 9. Confirm with user: "Generate [METHOD] [path] in [service]/modules/[version]/[Module]? (yes/no)"
9
84
 
10
- Delegates to: `.codeninja/commands/create-api.workflow.md`
85
+ > **Multi-agent:** Delegate to `nodejs-backend` via Task invocation for parallel execution.
86
+ > Read `.codeninja/tasks/generate-route.task.md` and `.codeninja/tasks/generate-model.task.md` before generating each file.
11
87
 
12
- ## Before Running
13
- 1. Call `context_check_stale`
14
- 2. Call `context_read` load `context.services` and `context.db.schema`
15
- 3. Read 1–2 existing modules in the target service to understand current patterns
88
+ 10. Delegate to `nodejs-agent`:
89
+ - Generate: `route.js` — run task: generate-route
90
+ (new filealways a full write)
91
+ - Generate: `<module>_model.js` run task: generate-model
92
+ (new file — always a full write)
93
+ - Append to: `modules/<version>/route_manager.js`
94
+ run task: generate-route-manager (Mode 2 — append only)
95
+ NEVER rewrite this file — surgical insert only
96
+ - Patch: `document/<version>/swagger_doc.json`
97
+ run task: generate-swagger (Mode 2 — patch paths object only)
98
+ NEVER rewrite this file — add new path key only
16
99
 
17
- ## Execution
18
- Read and execute `create-api.workflow.md` step by step.
19
- ONE confirmation after showing module details, then generate all files silently:
20
- - `route.js` → task: generate-route
21
- - `<module>_model.js` → task: generate-model
22
- - Append to `route_manager.js` → `file_insert_after` MCP tool (NEVER rewrite)
23
- - Patch `swagger_doc.json` → `file_insert_after` MCP tool (add new path only)
100
+ 11. Run task: `write-context`
101
+ - Append to `context.api_routes`
102
+ - Update `context.services[<service>].modules`
24
103
 
25
- ## After Running
26
- Call `context_write` — append to `context.api_routes`, update `context.services[<n>].modules`.
27
- Call `context_clear_scratchpad` for `current_api`.
28
- Show `show-final-summary` task output.
104
+ 12. Run task: `show-final-summary`
@@ -1,23 +1,119 @@
1
+ This workflow runs when user invokes /codeninja:audit
2
+
1
3
  ---
2
- slash_command: /codeninja:audit
3
- personas: [global-orchestrator, nodejs-backend]
4
- skills: [mcp-and-context, api-builder, code-intelligence]
5
- description: Security and quality review of a NodeJS service
4
+ type: workflow
5
+ name: audit
6
+ description: >
7
+ Review an existing service for code quality, security issues, naming
8
+ consistency, missing middleware, and context alignment.
6
9
  ---
7
10
 
8
- # /codeninja:audit
11
+ # Workflow: @audit
12
+
13
+ ## Goal
14
+ Produce a structured audit report for a service. Identify issues by severity.
15
+ Optionally auto-fix low-risk issues.
16
+
17
+ ## When to use @audit vs @sync drift detection
18
+
19
+ `@sync` drift detection: runs automatically with every @sync. Checks
20
+ structural markers only — middleware order, library consistency,
21
+ export patterns. Fast, read-only, always safe.
22
+
23
+ `@audit`: run manually when you want deep code quality analysis —
24
+ security checks, SQL injection patterns, response format consistency,
25
+ context alignment. Slower, comprehensive, covers logic not just structure.
26
+
27
+ Run @sync regularly. Run @audit before releasing a service or after
28
+ a major refactor.
29
+
30
+ ---
31
+
32
+ ## Step-by-Step Execution
33
+
34
+ 1. Run task: `ask-target-service`
35
+
36
+ > **Multi-agent:** Delegate to `nodejs-backend` or `database-architect` based on service type via Task invocation for parallel execution.
37
+ > Read `.codeninja/tasks/` task files relevant to the service before running checks.
38
+
39
+ 2. Delegate to relevant agent(s) based on service type.
40
+
41
+ 3. Agent checks:
42
+
43
+ ### Security Checks
44
+ - [ ] API key validation middleware applied to all routes?
45
+ - [ ] Input validation on all POST/PUT/PATCH routes?
46
+ - [ ] SQL injection prevention (parameterized queries)?
47
+ - [ ] Sensitive values only from env vars (no hardcoded keys/passwords)?
48
+ - [ ] `.env` in `.gitignore`?
49
+ - [ ] Encryption using real AES-256-CBC (not base64)?
50
+ - [ ] utilities/encryption.js is the only file importing crypto-js or cryptlib?
51
+ - [ ] res.json() is never called directly in route.js or model files?
52
+ - [ ] Validator package never imported directly in route files?
53
+ - [ ] SMTP credentials only in .env — never hardcoded in
54
+ notification.js or template.js?
55
+ - [ ] Firebase service account file in pem/ and in .gitignore?
56
+ - [ ] GLOBALS object is frozen using Object.freeze?
57
+
58
+ ### Code Quality Checks
59
+ - [ ] Controllers only call services (no DB queries in controllers)?
60
+ - [ ] Services contain business logic (no Express req/res objects)?
61
+ - [ ] Models contain only DB queries?
62
+ - [ ] Global error handler present and used?
63
+ - [ ] All routes call checkValidationRules from utilities/validator.js
64
+ before calling model functions?
65
+ - [ ] No separate _validator.js files exist per module?
66
+ - [ ] rateLimiter is the first middleware in route_manager.js?
67
+ - [ ] extractLanguage runs before validateApiKey in route_manager.js?
68
+ - [ ] decryptRequest is the last middleware in the chain?
69
+ - [ ] No route handlers defined directly in route_manager.js?
70
+ - [ ] asyncHandler wraps every middleware in route_manager.js?
71
+ - [ ] All model functions return exactly { responsecode, responsemsg,
72
+ responsedata } — no extra keys, no throws?
73
+ - [ ] No req/res objects in any model file?
74
+ - [ ] Passwords HASHED (not encrypted) using `utilities/hashing.js` before storage?
75
+ Correct: `await hashPassword(plainText)` — one-way bcrypt/argon2 hash
76
+ Wrong: `encrypt(password)` from encryption.js — reversible AES, not safe for passwords
77
+ - [ ] No direct bcrypt/argon2 imports in route.js or model files? All hashing routed through utilities/hashing.js?
78
+ - [ ] Session tokens generated only via common.generateSessionCode?
79
+ - [ ] No crypto-js or cryptlib imported directly in model files?
80
+ - [ ] No direct res.json() calls in route.js files?
9
81
 
10
- Delegates to: `.codeninja/commands/audit.workflow.md`
82
+ ### Consistency Checks
83
+ - [ ] All routes documented in `swagger_doc.json`?
84
+ - [ ] Response format consistent (success, message, data, timestamp)?
85
+ - [ ] Naming follows snake_case for DB, camelCase for JS?
86
+ - [ ] Port matches `context.services[<name>].port`?
87
+ - [ ] DB config matches `context.db`?
88
+ - [ ] All message keywords used in sendResponse calls exist in
89
+ languages/en.js?
90
+ - [ ] All language files contain the same set of keys as en.js?
91
+ - [ ] No two services share the same port in context.services?
92
+ - [ ] All encryption keys in context.services are exactly 32 characters?
93
+ - [ ] All encryption IVs in context.services are exactly 16 characters?
94
+ - [ ] No service name in context.services conflicts with a folder name
95
+ that already exists on disk for a different service?
11
96
 
12
- ## Before Running
13
- 1. Call `context_read`
14
- 2. Ask: "Which service do you want to audit?" — list from `context.services`
97
+ ### Context Alignment
98
+ - [ ] All routes present in `context.api_routes`?
99
+ - [ ] All DB tables referenced match `context.db.schema`?
100
+ - [ ] All router.use() lines in route_manager.js have a corresponding
101
+ entry in context.services[<name>].modules?
102
+ - [ ] All context.services[<name>].modules entries have a corresponding
103
+ router.use() line in route_manager.js?
104
+ - [ ] All paths in swagger_doc.json have a corresponding entry in
105
+ context.api_routes?
15
106
 
16
- ## Execution
17
- Read and execute `audit.workflow.md`.
18
- Use MCP tools: `analyze_middleware_order`, `analyze_encryption_library`,
19
- `analyze_language_keys`, `analyze_dependencies`, `analyze_env_file`.
107
+ 4. Present audit report:
108
+ ```
109
+ AUDIT REPORT <service_name>
110
+ ══════════════════════════════════════
111
+ 🔴 CRITICAL (must fix)
112
+ 🟡 WARNING (should fix)
113
+ 🟢 INFO (nice to have)
114
+ ══════════════════════════════════════
115
+ [list findings with file + line context]
116
+ ```
20
117
 
21
- ## Output
22
- Severity-ranked report: CRITICALWARNINGSUGGESTION.
23
- Offer to auto-fix SUGGESTION items. Fix WARNING/CRITICAL one at a time with confirmation.
118
+ 5. Ask: "Auto-fix critical issues? (yes/no)"
119
+ 6. If yesdelegate to relevant agent for fixes run task: `write-context`
@@ -1,11 +1,137 @@
1
+ This workflow runs when user invokes /codeninja:db:create
2
+
1
3
  ---
2
- slash_command: /codeninja:db:create
3
- personas: [global-orchestrator, database-architect]
4
- skills: [mcp-and-context, database]
5
- description: Design and generate a new table with migration file
4
+ type: workflow
5
+ name: db-create-table
6
+ command: "@db:create-table"
7
+ description: >
8
+ Design and generate a new database table following all project conventions.
9
+ Collects table purpose, name, columns one at a time, then generates the
10
+ numbered SQL file, updates create-schema.sql, and records in context.
6
11
  ---
7
- # /codeninja:db:create
8
- Delegates to: `.codeninja/commands/db-create-table.workflow.md`
9
- Before: `context_read` (load context.db fully), `context_check_stale`, `migration_next_number`.
10
- One question at a time. Never invent names — all from context.db.schema.
11
- After: `context_write` updated schema, `context_clear_scratchpad` for current_table.
12
+
13
+ # Workflow: @db:create-table
14
+
15
+ ## Goal
16
+ Generate a complete, convention-compliant SQL table file. Every generated
17
+ file must pass ALL rules defined in database-agent.md.
18
+
19
+ ## Rules
20
+ - Ask ONE question at a time — never bundle column definitions
21
+ - Always enforce tbl_ prefix and snake_case naming
22
+ - Never create a table file without updating create-schema.sql
23
+ - Always record in context.db.schema after generation
24
+
25
+ ---
26
+
27
+ ## Step-by-Step Execution
28
+
29
+ ### Phase 1 — Table Identity
30
+ 1. Run task: `ask-table-purpose`
31
+ - Stores: `context.current_db.table_purpose`
32
+ - Used by agent to suggest column names and structure
33
+
34
+ 2. Run task: `ask-table-name`
35
+ - Enforce: lowercase, snake_case, must start with `tbl_`
36
+ - Stores: `context.current_db.table_name`
37
+
38
+ 3. Run task: `ask-table-file-number`
39
+ - Agent reads existing files in `database/<db_type>/migrations/`
40
+ - Suggests next available number
41
+ - Stores: `context.current_db.file_number`
42
+
43
+ ---
44
+
45
+ ### Phase 2 — Standard Columns Decision
46
+ 4. Run task: `ask-table-needs-status`
47
+ - Ask: "Does this table need status and is_deleted columns?"
48
+ - Agent guidance: suggest YES for user/entity tables, NO for event/log tables
49
+ - Stores: `context.current_db.needs_status`
50
+
51
+ 5. Run task: `ask-table-needs-soft-delete`
52
+ - Ask: "Does this table support soft delete (is_deleted)?"
53
+ - Auto-suggest: YES if needs_status is YES
54
+ - Stores: `context.current_db.needs_soft_delete`
55
+
56
+ ---
57
+
58
+ ### Phase 3 — Column Collection (repeat until done)
59
+ 6. Run task: `ask-column-name`
60
+ - Show columns collected so far
61
+ - Ask: "Enter the next column name (or type 'done' to finish)"
62
+ - Enforce: snake_case, lowercase
63
+ - Stores: appends to `context.current_db.columns[]`
64
+
65
+ 7. Run task: `ask-column-type`
66
+ - Show suggested type based on column name pattern:
67
+ - `*_id` → BIGINT NOT NULL DEFAULT 0
68
+ - When a column name ends in `_id`:
69
+ - Cross-reference context.db.schema.tables for a table whose name
70
+ matches the prefix (e.g. user_id → tbl_users)
71
+ - If found → suggest: "This looks like a foreign key to tbl_users.
72
+ Add FK constraint? (yes/no)"
73
+ - If yes → add REFERENCES clause to the column definition
74
+ - `is_*` → BOOLEAN NOT NULL DEFAULT FALSE
75
+ - `*_at` → TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
76
+ - `status` → INTEGER NOT NULL DEFAULT 0 CHECK (status IN (0,1))
77
+ - `*_count` → BIGINT NOT NULL DEFAULT 0
78
+ - `*_price`, `*_amount` → NUMERIC(18,8) NOT NULL DEFAULT 0.00000000
79
+ - `email` → VARCHAR(132) NOT NULL DEFAULT ''
80
+ - `phone` → VARCHAR(16) NOT NULL DEFAULT ''
81
+ - `password` → TEXT NOT NULL DEFAULT ''
82
+ - `*_image`, `*_url` → VARCHAR(255) NOT NULL DEFAULT ''
83
+ - `payload`, `metadata`, `*_result` → JSON NOT NULL DEFAULT '{}'
84
+ - default → VARCHAR(255) NOT NULL DEFAULT ''
85
+ - Stores: in current column entry
86
+
87
+ 8. Run task: `ask-column-is-enum`
88
+ - Ask: "Does this column have a fixed set of allowed values? (enum-like)"
89
+ - If yes → run task: `ask-column-enum-values`
90
+ - Stores: check constraint and comment text
91
+
92
+ 9. Return to step 6 until user types 'done'
93
+
94
+ ---
95
+
96
+ ### Phase 4 — Index Decision
97
+ 10. Run task: `ask-table-indexes`
98
+ - Agent auto-suggests indexes based on collected columns:
99
+ - Every `*_id` (foreign key) column → suggest index
100
+ - `status + is_deleted` compound → suggest if both exist
101
+ - `created_at DESC` → suggest for event/log tables
102
+ - Ask user to confirm suggested indexes or add custom ones
103
+
104
+ ---
105
+
106
+ ### Phase 5 — Seed Data
107
+ 11. Run task: `ask-table-seed-data`
108
+ - Ask: "Does this table need seed/initial data?"
109
+ - Guidance: suggest YES only for reference/master data tables
110
+ - If yes → run task: `collect-seed-data`
111
+ - Stores: `context.current_db.seed_rows[]`
112
+
113
+ ---
114
+
115
+ ### Phase 6 — Summary and Generate
116
+ 12. Run task: `show-db-table-summary`
117
+ - Display complete table definition as it will be generated
118
+ - Show: table name, file number, all columns with types, indexes, seed data
119
+ - Ask: "Generate this table? (yes / no / change a value)"
120
+ - If change → re-run specific task → return to this step
121
+ - If no → abort, nothing created
122
+ - If yes → proceed
123
+
124
+ > **Multi-agent:** Delegate to `database-architect` via Task invocation for parallel execution.
125
+ > Read `.codeninja/tasks/generate-prisma-schema.task.md` and relevant task files before generating each file.
126
+
127
+ 13. Delegate to `database-agent`:
128
+ - Generate: `<repo_root>/database/<db_type>/migrations/<number>-setup-tbl-<name>.sql`
129
+ - Update: `<repo_root>/database/<db_type>/create-schema.sql`
130
+ - If any indexes belong in shared file → update: `111-setup-database-indexes.sql`
131
+
132
+ 14. Run task: `write-context`
133
+ - Append table to `context.db.schema.tables`
134
+ - Append to `context.db.schema.change_log`
135
+ - Clear `context.current_db`
136
+
137
+ 15. Run task: `show-final-summary`