codeninja 2.0.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 (46) hide show
  1. package/README.md +122 -251
  2. package/agent/global-agent.md +8 -0
  3. package/cli.js +248 -223
  4. package/commands/debug.workflow.md +94 -0
  5. package/commands/explain.workflow.md +59 -0
  6. package/commands/optimize.workflow.md +124 -0
  7. package/commands/review.workflow.md +85 -0
  8. package/ide/antigravity/.agents/personas/database-architect.md +249 -0
  9. package/ide/antigravity/.agents/personas/global-orchestrator.md +144 -0
  10. package/ide/antigravity/.agents/personas/nodejs-backend.md +250 -0
  11. package/ide/antigravity/.agents/personas/reactjs-frontend.md +179 -0
  12. package/ide/antigravity/.agents/skills/api-builder/SKILL.md +179 -0
  13. package/ide/antigravity/.agents/skills/code-intelligence/SKILL.md +184 -0
  14. package/ide/antigravity/.agents/skills/database/SKILL.md +165 -0
  15. package/ide/antigravity/.agents/skills/mcp-and-context/SKILL.md +111 -0
  16. package/ide/antigravity/.agents/skills/reactjs/SKILL.md +211 -0
  17. package/ide/antigravity/.agents/workflows/codeninja-api.md +111 -0
  18. package/ide/antigravity/.agents/workflows/codeninja-audit.md +81 -0
  19. package/ide/antigravity/.agents/workflows/codeninja-db-create.md +124 -0
  20. package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +87 -0
  21. package/ide/antigravity/.agents/workflows/codeninja-db-index.md +70 -0
  22. package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +106 -0
  23. package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +76 -0
  24. package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +70 -0
  25. package/ide/antigravity/.agents/workflows/codeninja-debug.md +82 -0
  26. package/ide/antigravity/.agents/workflows/codeninja-design.md +54 -0
  27. package/ide/antigravity/.agents/workflows/codeninja-explain.md +40 -0
  28. package/ide/antigravity/.agents/workflows/codeninja-init.md +336 -0
  29. package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +336 -0
  30. package/ide/antigravity/.agents/workflows/codeninja-modularize.md +216 -0
  31. package/ide/antigravity/.agents/workflows/codeninja-optimize.md +84 -0
  32. package/ide/antigravity/.agents/workflows/codeninja-refactor.md +68 -0
  33. package/ide/antigravity/.agents/workflows/codeninja-review.md +70 -0
  34. package/ide/antigravity/.agents/workflows/codeninja-sync.md +183 -0
  35. package/ide/antigravity/.agents/workflows/codeninja-test.md +61 -0
  36. package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +250 -0
  37. package/ide/cursor/.cursor/mcp.json +8 -0
  38. package/ide/cursor/.cursor/rules/01-global-orchestrator.mdc +63 -0
  39. package/ide/cursor/.cursor/rules/02-mcp-and-context.mdc +38 -0
  40. package/ide/cursor/.cursor/rules/03-api-builder.mdc +124 -0
  41. package/ide/cursor/.cursor/rules/04-database.mdc +90 -0
  42. package/ide/cursor/.cursor/rules/05-reactjs.mdc +147 -0
  43. package/ide/cursor/.cursor/rules/06-code-intelligence.mdc +112 -0
  44. package/ide/vscode/.github/copilot-instructions.md +399 -0
  45. package/ide/vscode/.vscode/mcp.json +9 -0
  46. package/package.json +24 -23
@@ -0,0 +1,106 @@
1
+ ---
2
+ slash_command: /codeninja:db:modify
3
+ personas: [global-orchestrator, database-architect]
4
+ skills: [mcp-and-context, database]
5
+ description: Modify an existing table via a numbered ALTER migration file.
6
+ ---
7
+
8
+ # /codeninja:db:modify
9
+
10
+ ## Before Running
11
+ 1. Call `context_read` — load `context.db.schema` fully
12
+ 2. Call `context_check_stale`
13
+ 3. Call `migration_next_number` to get next sequential number
14
+
15
+ ## Execution — Full Step-by-Step
16
+
17
+ ### Phase 1 — Target
18
+
19
+ **Step 1.** Ask: "Which table?" (list from `context.db.schema.tables`)
20
+ - Store: `context.current_db.table_name`
21
+
22
+ **Step 2.** Ask: "What operation?"
23
+ 1. Add a new column
24
+ 2. Rename a column
25
+ 3. Drop a column
26
+ 4. Change a column type
27
+ 5. Add a CHECK constraint to an existing column
28
+ 6. Add a new index → route to /codeninja:db:index instead
29
+ - Store: `context.current_db.modify_operation`
30
+
31
+ ---
32
+
33
+ ### Phase 2 — Operation Details
34
+
35
+ #### If "Add a new column":
36
+ - Ask: "New column name?" (snake_case, lowercase)
37
+ - Ask: "Column type?" (show type suggestions from naming patterns — same as db:create)
38
+ - Ask: "Is this an enum column?" — if yes, collect allowed values
39
+ - Ask: "Add column after which existing column?" (list current columns from context)
40
+ - SQL generated: `ALTER TABLE public.<table> ADD COLUMN <col> <type> NOT NULL DEFAULT <default>;`
41
+
42
+ #### If "Rename a column":
43
+ - Ask: "Which column to rename?" (list current columns from context)
44
+ - Ask: "New column name?" (snake_case)
45
+ - SQL generated: `ALTER TABLE public.<table> RENAME COLUMN <old> TO <new>;`
46
+
47
+ #### If "Drop a column":
48
+ - Ask: "Which column to drop?" (list current columns)
49
+ - WARN: "This will generate a DROP COLUMN migration. This is irreversible in production.
50
+ Make sure you have removed all code references first."
51
+ - Ask: "Confirm dropping column '<col>'? (yes/no)"
52
+ - SQL generated: `ALTER TABLE public.<table> DROP COLUMN IF EXISTS <col>;`
53
+
54
+ #### If "Change a column type":
55
+ - Ask: "Which column?" (list current columns)
56
+ - Ask: "New type?" (warn about potential data loss for narrower types)
57
+ - SQL generated: `ALTER TABLE public.<table> ALTER COLUMN <col> TYPE <new_type> USING <col>::<new_type>;`
58
+
59
+ #### If "Add CHECK constraint":
60
+ - Ask: "Which column?" (list current columns)
61
+ - Ask: "Allowed values?" (comma-separated)
62
+ - SQL generated: `ALTER TABLE public.<table> ADD CONSTRAINT chk_<table>_<col> CHECK (<col> IN (<values>));`
63
+ Plus: `COMMENT ON COLUMN public.<table>.<col> IS '<enum explanation>';`
64
+
65
+ ---
66
+
67
+ ### Phase 3 — File Numbering
68
+
69
+ **Step 7.** Ask: "Migration file number?" (agent suggests next available)
70
+ - Store: `context.current_db.file_number`
71
+
72
+ ---
73
+
74
+ ### Phase 4 — Confirm and Generate
75
+
76
+ **Step 8.** Show the exact SQL that will be generated. Ask: "Generate? (yes / no)"
77
+
78
+ **Step 9.** Delegate to database-agent:
79
+ Generate: `<repo_root>/database/<db_type>/migrations/<number>-alter-tbl-<n>-<description>.sql`
80
+
81
+ Full file structure:
82
+ ```sql
83
+ -- Alter tbl_<table>: <description>
84
+ -- Migration: <number>-alter-tbl-<n>-<description>.sql
85
+ -- Generated: <ISO date>
86
+
87
+ BEGIN;
88
+
89
+ ALTER TABLE public.<table_name>
90
+ <operation>;
91
+
92
+ -- COMMENT ON COLUMN if enum/flag column
93
+ -- CREATE INDEX if new column needs one
94
+
95
+ COMMIT;
96
+ ```
97
+ Update: `database/<db_type>/create-schema.sql`
98
+
99
+ **Step 10.** Call `context_write`:
100
+ - Update `context.db.schema.tables[<table>].columns`
101
+ - Append to `context.db.schema.change_log`
102
+ - Clear `context.current_db`
103
+
104
+ **Step 11.** Call `context_clear_scratchpad` with keys: ["current_db"]
105
+
106
+ **Step 12.** Show final summary.
@@ -0,0 +1,76 @@
1
+ ---
2
+ slash_command: /codeninja:db:seed
3
+ personas: [global-orchestrator, database-architect]
4
+ skills: [mcp-and-context, database]
5
+ description: Add seed/initial data to a table.
6
+ ---
7
+
8
+ # /codeninja:db:seed
9
+
10
+ ## Before Running
11
+ 1. Call `context_read` — load `context.db.schema`
12
+ 2. Call `context_check_stale`
13
+
14
+ ## Execution — Full Step-by-Step
15
+
16
+ ### Phase 1 — Target
17
+
18
+ **Step 1.** Ask: "Which table?" (list from `context.db.schema.tables`)
19
+ - Store: `context.current_db.table_name`
20
+
21
+ ### Phase 2 — Seed File Type
22
+
23
+ **Step 2.** Determine seed target:
24
+ - Reference tables (seed goes IN setup file): lookup tables, master/config tables
25
+ - All other tables: standalone seed file in seeds/
26
+
27
+ Ask: "Where should this seed data go?"
28
+ 1. Append to the table's setup file (for reference/master data)
29
+ 2. Create standalone seed file in seeds/ (for dev/test data)
30
+ - Store: `context.current_db.seed_target`
31
+
32
+ ### Phase 3 — Data Collection
33
+
34
+ **Step 3.** Show column list from context (excluding `id` and `created_at` — auto-generated).
35
+
36
+ **Step 4.** Ask: "How many rows do you want to seed?"
37
+ - Store: `context.current_db.seed_count`
38
+
39
+ **Step 5.** For each row (repeat seed_count times):
40
+ - Ask value for each column one at a time
41
+ - If column is `password` → warn: "Enter the encrypted/hashed value only. Never store plaintext."
42
+ - If column has CHECK constraint → show allowed values
43
+ - If column has DEFAULT → offer to use default (press Enter to skip)
44
+ - Append to: `context.current_db.seed_rows[]`
45
+
46
+ ### Phase 4 — Generate
47
+
48
+ **Step 6.** Show full INSERT preview. Ask: "Generate this seed data? (yes / no)"
49
+
50
+ **Step 7.** Delegate to database-agent:
51
+
52
+ If appending to setup file → append after the GRANT line:
53
+ ```sql
54
+ INSERT INTO public.<table_name> (<col1>, <col2>, ...) VALUES
55
+ (<val1a>, <val2a>, ...),
56
+ (<val1b>, <val2b>, ...);
57
+ ```
58
+
59
+ If standalone seed file → generate `database/<db_type>/seeds/<table_name>_seed.sql`:
60
+ ```sql
61
+ -- Seed data for <table_name>
62
+ -- Environment: development
63
+ -- Generated: <ISO date>
64
+
65
+ INSERT INTO public.<table_name> (<col1>, <col2>, ...) VALUES
66
+ (<val1a>, <val2a>, ...),
67
+ (<val1b>, <val2b>, ...);
68
+ ```
69
+
70
+ **Step 8.** Call `context_write`:
71
+ - Append to `context.db.schema.change_log`: `{ type: "seed_added", table: "<n>", rows: <count> }`
72
+ - Clear `context.current_db`
73
+
74
+ **Step 9.** Call `context_clear_scratchpad` with keys: ["current_db"]
75
+
76
+ **Step 10.** Show final summary.
@@ -0,0 +1,70 @@
1
+ ---
2
+ slash_command: /codeninja:db:sync
3
+ personas: [global-orchestrator, database-architect]
4
+ skills: [mcp-and-context, database]
5
+ description: Scan all migration files and rebuild context.db.schema from actual file contents.
6
+ ---
7
+
8
+ # /codeninja:db:sync
9
+
10
+ ## Before Running
11
+ 1. Call `context_read`
12
+ 2. Call `context_check_stale`
13
+
14
+ ## Execution — Full Step-by-Step
15
+
16
+ ### Phase 1 — Locate Files
17
+
18
+ **Step 1.** Read `context.db.type` → find `<repo_root>/database/<db_type>/migrations/`
19
+ **Step 2.** List all `.sql` files, sort by numeric prefix (1, 2, 3… 111)
20
+ **Step 3.** Categorize:
21
+ - setup files: `*-setup-tbl-*.sql`
22
+ - alter files: `*-alter-tbl-*.sql`
23
+ - drop files: `*-drop-tbl-*.sql`
24
+ - index file: `111-setup-database-indexes.sql`
25
+
26
+ ### Phase 2 — Parse Each File
27
+
28
+ For each setup file (in order):
29
+ - Extract table name from CREATE TABLE
30
+ - Extract all column names and types
31
+ - Extract CHECK constraints and COMMENT ON COLUMN lines (enum descriptions)
32
+ - Extract per-file CREATE INDEX lines
33
+ - Note if table has `status`, `is_deleted`, `created_at`
34
+
35
+ For each alter file (in order after its setup file):
36
+ - ADD COLUMN → add to that table's columns
37
+ - RENAME COLUMN → update name, record in change_log
38
+ - DROP COLUMN → remove from columns
39
+ - ADD CONSTRAINT → update column constraint info
40
+
41
+ For each drop file: mark table as dropped.
42
+
43
+ For the index file: parse all CREATE INDEX, associate each with its table.
44
+
45
+ ### Phase 3 — Rebuild Context
46
+
47
+ For each discovered table (not dropped):
48
+ - Compare with existing `context.db.schema.tables[<table>]`
49
+ - Add tables not already in context
50
+ - Add columns not already tracked
51
+ - Add indexes not already tracked
52
+ - For renames in ALTER files → append to change_log if not already there
53
+
54
+ For dropped tables:
55
+ - If still in `context.db.schema.tables` → move to change_log snapshot, remove from active tables
56
+
57
+ ### Phase 4 — Rebuild create-schema.sql
58
+
59
+ - Re-read all filenames in correct numeric order
60
+ - Rewrite `create-schema.sql` to match actual files on disk
61
+ - Report: any `\i` entries in create-schema.sql missing from disk (stale)
62
+ - Report: any files on disk not in create-schema.sql (missing)
63
+
64
+ ### Phase 5 — Finalize
65
+
66
+ **Step 5.** Show sync report: tables synced, columns added, indexes added, stale entries, missing files.
67
+
68
+ **Step 6.** Call `context_write` with rebuilt `context.db.schema`.
69
+
70
+ **Step 7.** Show final summary.
@@ -0,0 +1,82 @@
1
+ ---
2
+ slash_command: /codeninja:debug
3
+ personas: [global-orchestrator, nodejs-backend]
4
+ skills: [mcp-and-context, api-builder, code-intelligence]
5
+ description: Diagnose and fix bugs using full project context and code path tracing.
6
+ ---
7
+
8
+ # /codeninja:debug
9
+
10
+ ## Before Running
11
+ 1. Call `context_read` — load services, DB schema, project config
12
+ 2. Call `context_check_stale`
13
+
14
+ ## Execution — Full Step-by-Step
15
+
16
+ ### Step 1 — Gather Error Information (ask one at a time if not provided)
17
+ 1. "Paste the full error message and stack trace."
18
+ 2. "Which endpoint or operation triggered it? (e.g., POST /v1/scores/submit)"
19
+ 3. "What did you expect vs what actually happened?"
20
+ 4. "What changed recently before this error appeared?"
21
+
22
+ ### Step 2 — Load Context
23
+ 1. Call `fs_read` on the relevant `route.js`
24
+ 2. Call `fs_read` on the relevant `_model.js`
25
+ 3. Call `fs_exists` on the migration file for any table mentioned in the error
26
+
27
+ ### Step 3 — Trace the Failure Path
28
+
29
+ Walk the request lifecycle in order — mark the exact step where failure occurs:
30
+ ```
31
+ Request received
32
+ → Language middleware (extracts Accept-Language)
33
+ → API key middleware (validates api-key header)
34
+ → Auth middleware (validates JWT if protected)
35
+ → Validation (validatorjs schema)
36
+ → Route handler (calls model)
37
+ → Model function (executes query)
38
+ → Database (pg pool / mysql2 / mongoose)
39
+ → Response formatter
40
+ ```
41
+
42
+ ### Step 4 — Check Common Root Causes
43
+
44
+ | Symptom | Check |
45
+ |---|---|
46
+ | `column does not exist` | context.db.schema vs actual column names in model.js |
47
+ | `undefined is not a function` | wrong import path or missing export in model |
48
+ | `Cannot read property of undefined` | missing null check after DB query returns 0 rows |
49
+ | `401 Unauthorized` | middleware order — apiKey middleware applied? header name correct? |
50
+ | `500 Internal Server Error` | missing try/catch around async DB call |
51
+ | `Wrong number of rows` | missing dedup, RANK vs DENSE_RANK, missing WHERE clause |
52
+ | `Migration not applied` | table exists in code but not in DB — run migration |
53
+ | Stale context data | context.db.schema out of date — suggest /codeninja:db:sync |
54
+
55
+ ### Step 5 — Produce Fix
56
+
57
+ ```
58
+ Root cause: [one sentence — be precise]
59
+
60
+ Fix:
61
+ File: path/to/file.js
62
+
63
+ Before:
64
+ [the buggy code]
65
+
66
+ After:
67
+ [the corrected code]
68
+
69
+ Why this fixes it: [one sentence]
70
+ ```
71
+
72
+ If multiple files need changes, show each in order.
73
+
74
+ ### Step 6 — Verify Plan
75
+
76
+ "Before I apply this fix, confirm: does this match what you're seeing?
77
+ Once confirmed, I'll make the changes."
78
+
79
+ ### Step 7 — Prevent Recurrence
80
+
81
+ After fixing: suggest one guard that prevents this class of bug in the future.
82
+ (e.g., a missing index, an added null check helper, a context convention)
@@ -0,0 +1,54 @@
1
+ ---
2
+ slash_command: /codeninja:design
3
+ personas: [global-orchestrator, nodejs-backend, database-architect]
4
+ skills: [mcp-and-context, api-builder, database]
5
+ description: Plan a feature, API contract, or database change before writing any code.
6
+ ---
7
+
8
+ # /codeninja:design
9
+
10
+ ## Before Running
11
+ 1. Call `context_read`
12
+ 2. Call `context_check_stale`
13
+
14
+ ## Execution — Full Step-by-Step
15
+
16
+ ### Phase 1 — Scope
17
+
18
+ **Step 1.** Ask: "What are you designing?"
19
+ - Options: new feature / new API endpoint / database change / full module
20
+ - Store: `context.current_design.type`
21
+
22
+ **Step 2.** Ask: "Feature or module name?"
23
+ - Store: `context.current_design.feature_name`
24
+
25
+ **Step 3.** Ask: "What should this feature do?" (free text)
26
+ - Store: `context.current_design.description`
27
+
28
+ ### Phase 2 — Database Design (if applicable)
29
+
30
+ **Step 4.** If design involves data storage:
31
+ - Delegate to database-agent
32
+ - Design table structure, column types, indexes, relationships
33
+ - Present schema proposal for feedback
34
+ - Allow changes one at a time
35
+
36
+ ### Phase 3 — API Design (if applicable)
37
+
38
+ **Step 5.** If design involves API endpoints:
39
+ - Delegate to nodejs-agent
40
+ - Propose: method, path, request body, response shape, auth requirement
41
+ - Present for feedback
42
+
43
+ ### Phase 4 — Output
44
+
45
+ **Step 6.** Generate `.codeninja/agent/designs/<feature_name>.design.md`:
46
+ - Feature summary
47
+ - DB schema proposal (tables, columns, indexes, relationships)
48
+ - API contracts (method, path, request, response shape)
49
+ - Open questions / decisions needed
50
+
51
+ **Step 7.** Ask: "Save this design and mark planned routes/schema in context? (yes/no)"
52
+ If yes → call `context_write` with operation "design", then `context_clear_scratchpad` ["current_design"]
53
+
54
+ **Step 8.** Show final summary.
@@ -0,0 +1,40 @@
1
+ ---
2
+ slash_command: /codeninja:explain
3
+ personas: [global-orchestrator]
4
+ skills: [mcp-and-context, code-intelligence]
5
+ description: Explain any file, function, pattern, or concept using full project context.
6
+ ---
7
+
8
+ # /codeninja:explain
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: "What would you like me to explain?
18
+ (e.g., a file path, a function name, a pattern like 'the auth middleware',
19
+ or a concept like 'why we use DENSE_RANK')"
20
+
21
+ ### Step 2 — Load Context
22
+ 1. Call `fs_read` on the target file (if a file was specified)
23
+ 2. Read 1 related file to understand how the target fits in the system
24
+ 3. Reference `context.db.schema` for any table/column mentions
25
+ 4. Reference `context.services` for service names and ports
26
+
27
+ ### Step 3 — Explain
28
+
29
+ Structure every explanation as:
30
+
31
+ **What it is** (1–2 sentences — plain English)
32
+
33
+ **How it works** (step-by-step walkthrough of the key logic)
34
+
35
+ **Why this way** (the architectural decision behind it)
36
+
37
+ **Where it connects** (related files and functions in this project — use real names)
38
+
39
+ ### Step 4 — Offer Follow-up
40
+ End with: "Want me to explain any part in more detail, or show how to modify it?"