codeninja 3.2.0 → 4.0.1

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 +15 -4
  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 +202 -85
  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 +76 -83
  18. package/ide/antigravity/.agents/workflows/codeninja-audit.md +82 -44
  19. package/ide/antigravity/.agents/workflows/codeninja-db-create.md +107 -94
  20. package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +89 -67
  21. package/ide/antigravity/.agents/workflows/codeninja-db-index.md +86 -54
  22. package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +126 -68
  23. package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +87 -59
  24. package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +77 -41
  25. package/ide/antigravity/.agents/workflows/codeninja-debug.md +35 -21
  26. package/ide/antigravity/.agents/workflows/codeninja-design.md +49 -35
  27. package/ide/antigravity/.agents/workflows/codeninja-explain.md +41 -20
  28. package/ide/antigravity/.agents/workflows/codeninja-init.md +479 -289
  29. package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +253 -136
  30. package/ide/antigravity/.agents/workflows/codeninja-modularize.md +250 -132
  31. package/ide/antigravity/.agents/workflows/codeninja-optimize.md +71 -29
  32. package/ide/antigravity/.agents/workflows/codeninja-refactor.md +50 -42
  33. package/ide/antigravity/.agents/workflows/codeninja-review.md +38 -21
  34. package/ide/antigravity/.agents/workflows/codeninja-sync.md +922 -141
  35. package/ide/antigravity/.agents/workflows/codeninja-test.md +34 -49
  36. package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +449 -151
  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 +12 -13
  62. package/ide/cursor/.cursor/rules/02-mcp-and-context.mdc +47 -31
  63. package/ide/cursor/.cursor/rules/03-api-builder.mdc +32 -110
  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 +67 -382
  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 -90
  110. package/ide/cursor/.cursor/rules/05-reactjs.mdc +0 -147
  111. package/ide/cursor/.cursor/rules/06-code-intelligence.mdc +0 -112
@@ -1,106 +1,164 @@
1
+ This workflow runs when user invokes /codeninja:db:modify
2
+
1
3
  ---
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.
4
+ type: workflow
5
+ name: db-modify-table
6
+ command: "@db:modify-table"
7
+ description: >
8
+ Modify an existing table via a numbered ALTER migration file. Supports
9
+ adding columns, renaming columns, dropping columns, changing types,
10
+ and adding check constraints. Always generates a migration file and
11
+ updates context.
6
12
  ---
7
13
 
8
- # /codeninja:db:modify
14
+ # Workflow: @db:modify-table
9
15
 
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
16
+ ## Goal
17
+ Generate a properly numbered ALTER TABLE migration file that modifies an
18
+ existing table. Record the change in context.db.schema.change_log so all
19
+ agents have the updated schema.
14
20
 
15
- ## Execution — Full Step-by-Step
21
+ ## Rules
22
+ - ALWAYS generate an ALTER file — never edit the original table setup file
23
+ - ALTER files are numbered sequentially after the last existing file
24
+ - Every change is recorded in context.db.schema.change_log
25
+ - create-schema.sql is updated after every ALTER file generated
16
26
 
17
- ### Phase 1 — Target
27
+ ---
18
28
 
19
- **Step 1.** Ask: "Which table?" (list from `context.db.schema.tables`)
20
- - Store: `context.current_db.table_name`
29
+ ## Step-by-Step Execution
21
30
 
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`
31
+ ### Phase 1 Target
32
+ 1. Run task: `ask-table-name`
33
+ - List tables from `context.db.schema.tables`
34
+ - Stores: `context.current_db.table_name`
35
+
36
+ 2. Run task: `ask-modify-operation`
37
+ - Ask: "What do you want to do?"
38
+ - Options:
39
+ 1. Add a new column
40
+ 2. Rename a column
41
+ 3. Drop a column
42
+ 4. Change a column type
43
+ 5. Add a CHECK constraint to an existing column
44
+ 6. Add a new index
45
+ - Stores: `context.current_db.modify_operation`
46
+
47
+ 2b. If `context.current_db.modify_operation == "add_index"`:
48
+ → Immediately route to `@db:add-index` workflow.
49
+ → End this workflow (no further steps needed).
30
50
 
31
51
  ---
32
52
 
33
- ### Phase 2 — Operation Details
53
+ ### Phase 2 — Operation-Specific Collection
34
54
 
35
55
  #### 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>;`
56
+ 3. Run task: `ask-column-name`
57
+ 4. Run task: `ask-column-type`
58
+ 5. Run task: `ask-column-is-enum`
59
+ 6. Run task: `ask-column-position`
60
+ - Ask: "Add column after which existing column?"
61
+ - List current columns from context
62
+ - Stores: `context.current_db.after_column`
63
+
64
+ Generated SQL pattern:
65
+ ```sql
66
+ ALTER TABLE public.<table_name>
67
+ ADD COLUMN <col_name> <type> NOT NULL DEFAULT <default>;
68
+ ```
41
69
 
42
70
  #### 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>;`
71
+ 3. Run task: `ask-old-column-name`
72
+ - List current columns from context
73
+ 4. Run task: `ask-new-column-name`
74
+ - Enforce: snake_case, lowercase
75
+
76
+ Generated SQL pattern:
77
+ ```sql
78
+ ALTER TABLE public.<table_name>
79
+ RENAME COLUMN <old_name> TO <new_name>;
80
+ ```
46
81
 
47
82
  #### 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>;`
83
+ 3. Run task: `ask-old-column-name`
84
+ - List current columns from context
85
+ - WARN: "This will generate a DROP COLUMN migration. This is irreversible
86
+ in production. Make sure you have removed all code references first."
87
+ - Ask: "Confirm dropping column '<col>'? (yes/no)"
88
+
89
+ Generated SQL pattern:
90
+ ```sql
91
+ ALTER TABLE public.<table_name>
92
+ DROP COLUMN IF EXISTS <col_name>;
93
+ ```
53
94
 
54
95
  #### 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>;`
96
+ 3. Run task: `ask-old-column-name`
97
+ 4. Run task: `ask-column-type` (new type)
98
+ - WARN agent about potential data loss if changing to narrower type
99
+
100
+ Generated SQL pattern:
101
+ ```sql
102
+ ALTER TABLE public.<table_name>
103
+ ALTER COLUMN <col_name> TYPE <new_type> USING <col_name>::<new_type>;
104
+ ```
105
+
106
+ #### If "Add a CHECK constraint":
107
+ 3. Run task: `ask-old-column-name`
108
+ 4. Run task: `ask-column-enum-values`
109
+
110
+ Generated SQL pattern:
111
+ ```sql
112
+ ALTER TABLE public.<table_name>
113
+ ADD CONSTRAINT chk_<table>_<col> CHECK (<col_name> IN (<values>));
114
+ COMMENT ON COLUMN public.<table_name>.<col_name> IS '<enum explanation>';
115
+ ```
58
116
 
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>';`
117
+ #### If "Add a new index":
118
+ Route to `@db:add-index` workflow instead.
64
119
 
65
120
  ---
66
121
 
67
122
  ### Phase 3 — File Numbering
68
-
69
- **Step 7.** Ask: "Migration file number?" (agent suggests next available)
70
- - Store: `context.current_db.file_number`
123
+ 7. Run task: `ask-table-file-number`
124
+ - Suggest: next available number after all existing files
125
+ - Stores: `context.current_db.file_number`
71
126
 
72
127
  ---
73
128
 
74
129
  ### Phase 4 — Confirm and Generate
130
+ 8. Show summary of the ALTER operation
131
+ - Display the exact SQL that will be generated
132
+ - Ask: "Generate this migration? (yes / no)"
75
133
 
76
- **Step 8.** Show the exact SQL that will be generated. Ask: "Generate? (yes / no)"
134
+ > **Multi-agent:** Delegate to `database-architect` via Task invocation for parallel execution.
135
+ > Read `.codeninja/tasks/` before generating each migration file.
77
136
 
78
- **Step 9.** Delegate to database-agent:
79
- Generate: `<repo_root>/database/<db_type>/migrations/<number>-alter-tbl-<n>-<description>.sql`
137
+ 9. Delegate to `database-agent`:
138
+ - Generate: `<repo_root>/database/<db_type>/migrations/<number>-alter-tbl-<n>-<description>.sql`
80
139
 
81
- Full file structure:
82
- ```sql
83
- -- Alter tbl_<table>: <description>
84
- -- Migration: <number>-alter-tbl-<n>-<description>.sql
85
- -- Generated: <ISO date>
140
+ Full file structure:
141
+ ```sql
142
+ -- Alter tbl_<table>: <description>
143
+ -- Migration: <number>-alter-tbl-<n>-<description>.sql
144
+ -- Generated: <ISO date>
86
145
 
87
- BEGIN;
146
+ BEGIN;
88
147
 
89
- ALTER TABLE public.<table_name>
90
- <operation>;
148
+ ALTER TABLE public.<table_name>
149
+ <operation>;
91
150
 
92
- -- COMMENT ON COLUMN if enum/flag column
93
- -- CREATE INDEX if new column needs one
151
+ -- Optional: COMMENT ON COLUMN if enum/flag column
152
+ -- Optional: CREATE INDEX if new column needs one
94
153
 
95
- COMMIT;
96
- ```
97
- Update: `database/<db_type>/create-schema.sql`
154
+ COMMIT;
155
+ ```
98
156
 
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`
157
+ - Update: `database/<db_type>/create-schema.sql`
103
158
 
104
- **Step 11.** Call `context_clear_scratchpad` with keys: ["current_db"]
159
+ 10. Run task: `write-context`
160
+ - Update `context.db.schema.tables[<table>].columns`
161
+ - Append to `context.db.schema.change_log`
162
+ - Clear `context.current_db`
105
163
 
106
- **Step 12.** Show final summary.
164
+ 11. Run task: `show-final-summary`
@@ -1,76 +1,104 @@
1
+ This workflow runs when user invokes /codeninja:db:seed
2
+
1
3
  ---
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.
4
+ type: workflow
5
+ name: db-seed
6
+ command: "@db:seed"
7
+ description: >
8
+ Add or update seed data for a table. For reference/master data tables,
9
+ seed goes inside the table setup file. For all others, a standalone seed
10
+ file is generated in the seeds/ folder.
6
11
  ---
7
12
 
8
- # /codeninja:db:seed
13
+ # Workflow: @db:seed
14
+
15
+ ## Goal
16
+ Generate properly formatted INSERT seed data for a table. Determine whether
17
+ seed belongs in the table file or a standalone seed file.
9
18
 
10
- ## Before Running
11
- 1. Call `context_read`load `context.db.schema`
12
- 2. Call `context_check_stale`
19
+ ## Rules
20
+ - Passwords in seed data must be pre-encrypted agent must ask for encrypted value
21
+ - Never generate plaintext passwords in any file
22
+ - Multi-row INSERT format always (single INSERT with multiple value tuples)
23
+ - Seed file naming: `<repo_root>/database/<db_type>/seeds/<table_name>_seed.sql`
13
24
 
14
- ## Execution — Full Step-by-Step
25
+ ---
26
+
27
+ ## Step-by-Step Execution
15
28
 
16
29
  ### Phase 1 — Target
30
+ 1. Run task: `ask-table-name`
31
+ - List tables from `context.db.schema.tables`
32
+ - Stores: `context.current_db.table_name`
17
33
 
18
- **Step 1.** Ask: "Which table?" (list from `context.db.schema.tables`)
19
- - Store: `context.current_db.table_name`
34
+ ---
20
35
 
21
36
  ### Phase 2 — Seed File Type
37
+ 2. Agent checks if table is a reference/master table:
38
+ - Reference tables (seed goes IN setup file): tbl_country, tbl_app_content,
39
+ tbl_strategy_modules, tbl_admin, any lookup table
40
+ - All others: standalone seed file in seeds/
22
41
 
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/
42
+ Ask: "Where should this seed data go?"
43
+ Options:
44
+ 1. Append to the table's setup file (for reference/master data)
45
+ 2. Create a standalone seed file in seeds/ (for dev/test data)
26
46
 
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`
47
+ Stores: `context.current_db.seed_target`
31
48
 
32
- ### Phase 3 — Data Collection
33
-
34
- **Step 3.** Show column list from context (excluding `id` and `created_at` — auto-generated).
49
+ ---
35
50
 
36
- **Step 4.** Ask: "How many rows do you want to seed?"
37
- - Store: `context.current_db.seed_count`
51
+ ### Phase 3 Data Collection
52
+ 3. Show column list for the table from context.
53
+
54
+ 4. Run task: `ask-seed-rows-count`
55
+ - Ask: "How many rows do you want to seed?"
56
+ - Stores: `context.current_db.seed_count`
57
+
58
+ 5. For each row (repeat seed_count times):
59
+ Run task: `ask-seed-row-values`
60
+ - For each column (excluding `id` and `created_at` — auto-generated):
61
+ - Ask the value one column at a time
62
+ - If column is `password` → warn: "Enter the encrypted/hashed value only. Never store plaintext."
63
+ - If column has CHECK constraint → show allowed values
64
+ - If column has DEFAULT → offer to use default (user can press enter to skip)
65
+ - Stores: appends to `context.current_db.seed_rows[]`
38
66
 
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[]`
67
+ ---
45
68
 
46
69
  ### 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.
70
+ 6. Show full INSERT preview to user
71
+ - Ask: "Generate this seed data? (yes / no)"
72
+
73
+ > **Multi-agent:** Delegate to `database-architect` via Task invocation for parallel execution.
74
+ > Read `.codeninja/tasks/collect-seed-data.task.md` before generating seed data.
75
+
76
+ 7. Delegate to `database-agent`:
77
+
78
+ If appending to setup file:
79
+ - Read existing setup file
80
+ - Append after the GRANT line:
81
+ ```sql
82
+ INSERT INTO public.<table_name> (<col1>, <col2>, ...) VALUES
83
+ (<val1a>, <val2a>, ...),
84
+ (<val1b>, <val2b>, ...);
85
+ ```
86
+
87
+ If standalone seed file:
88
+ - Generate: `database/<db_type>/seeds/<table_name>_seed.sql`
89
+ ```sql
90
+ -- Seed data for <table_name>
91
+ -- Environment: development
92
+ -- Generated: <ISO date>
93
+
94
+ INSERT INTO public.<table_name> (<col1>, <col2>, ...) VALUES
95
+ (<val1a>, <val2a>, ...),
96
+ (<val1b>, <val2b>, ...);
97
+ ```
98
+
99
+ 8. Run task: `write-context`
100
+ - Append to `context.db.schema.change_log`:
101
+ `{ "type": "seed_added", "table": "<n>", "rows": <count> }`
102
+ - Clear `context.current_db`
103
+
104
+ 9. Run task: `show-final-summary`
@@ -1,70 +1,106 @@
1
+ This workflow runs when user invokes /codeninja:db:sync
2
+
1
3
  ---
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.
4
+ type: workflow
5
+ name: db-sync
6
+ command: "@db:sync"
7
+ description: >
8
+ Scan all migration files in the database folder and rebuild context.db.schema
9
+ from actual file contents. Safe to run at any time. Never destructive —
10
+ only adds or updates, never removes existing context entries.
6
11
  ---
7
12
 
8
- # /codeninja:db:sync
13
+ # Workflow: @db:sync
14
+
15
+ ## Goal
16
+ Make context.db.schema an accurate reflection of what is actually on disk.
17
+ Parse every migration file in order and reconstruct the full schema state.
9
18
 
10
- ## Before Running
11
- 1. Call `context_read`
12
- 2. Call `context_check_stale`
19
+ ---
13
20
 
14
- ## Execution — Full Step-by-Step
21
+ ## Step-by-Step Execution
15
22
 
16
23
  ### Phase 1 — Locate Files
24
+ 1. Read `context.db.type` to find the correct folder:
25
+ `<repo_root>/database/<db_type>/migrations/`
26
+ The database folder is always at repository root, never inside
27
+ a service folder.
28
+ 2. List all `.sql` files in that folder
29
+ 3. Sort them in numeric order by filename prefix (1, 2, 3... 111)
30
+ 4. Separate into categories:
31
+ - setup files: `*-setup-tbl-*.sql`
32
+ - alter files: `*-alter-tbl-*.sql`
33
+ - drop files: `*-drop-tbl-*.sql`
34
+ - index file: `111-setup-database-indexes.sql`
17
35
 
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`
36
+ ---
25
37
 
26
38
  ### Phase 2 — Parse Each File
27
-
28
39
  For each setup file (in order):
29
- - Extract table name from CREATE TABLE
40
+ - Extract table name from CREATE TABLE statement
30
41
  - Extract all column names and types
31
- - Extract CHECK constraints and COMMENT ON COLUMN lines (enum descriptions)
42
+ - Extract CHECK constraints (enum values)
43
+ - Extract COMMENT ON COLUMN lines (enum descriptions)
32
44
  - Extract per-file CREATE INDEX lines
33
45
  - Note if table has `status`, `is_deleted`, `created_at`
34
46
 
35
47
  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
48
+ - Parse ADD COLUMN → add to that table's columns
49
+ - Parse RENAME COLUMN → update column name, record in change_log
50
+ - Parse DROP COLUMN → remove from columns
51
+ - Parse ADD CONSTRAINT → update column's constraint info
40
52
 
41
- For each drop file: mark table as dropped.
53
+ For each drop file:
54
+ - Mark that table as dropped in the scan result
42
55
 
43
- For the index file: parse all CREATE INDEX, associate each with its table.
56
+ For the index file:
57
+ - Parse all CREATE INDEX statements
58
+ - Associate each index with its table
44
59
 
45
- ### Phase 3 — Rebuild Context
60
+ ---
46
61
 
62
+ ### Phase 3 — Rebuild Context
47
63
  For each discovered table (not dropped):
48
64
  - 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
65
+ - Add any tables not already in context
66
+ - Add any columns not already tracked
67
+ - Add any indexes not already tracked
68
+ - For renames found in ALTER files → append to change_log if not already there
53
69
 
54
70
  For dropped tables:
55
- - If still in `context.db.schema.tables` → move to change_log snapshot, remove from active tables
71
+ - If still in `context.db.schema.tables` → move to change_log snapshot
72
+ - Remove from active tables list
56
73
 
57
- ### Phase 4 — Rebuild create-schema.sql
74
+ ---
58
75
 
59
- - Re-read all filenames in correct numeric order
76
+ ### Phase 4 Rebuild create-schema.sql
77
+ - Re-read all file names in correct numeric order
60
78
  - 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)
79
+ - Report any \i entries that are in create-schema.sql but missing from disk (stale)
80
+ - Report any files on disk not in create-schema.sql (missing)
63
81
 
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`.
82
+ ---
69
83
 
70
- **Step 7.** Show final summary.
84
+ ### Phase 5 Write and Report
85
+
86
+ > **Multi-agent:** Delegate to `database-architect` via Task invocation for parallel execution.
87
+ > Read `.codeninja/tasks/` before generating any schema updates.
88
+
89
+ 1. Run task: `write-context` with all schema deltas
90
+ 2. Display sync report:
91
+ ```
92
+ @db:sync complete
93
+ ─────────────────────────────────────────
94
+ Migration files scanned : [n]
95
+ Tables discovered : [n] ([x] new)
96
+ Columns synced : [n] ([x] new)
97
+ Indexes synced : [n] ([x] new)
98
+ Renames detected : [n]
99
+ Dropped tables : [n]
100
+ create-schema.sql : updated
101
+ Context gaps filled : [n]
102
+ ─────────────────────────────────────────
103
+ ```
104
+ 3. If any conflicts found (e.g. column exists in context with different type than file):
105
+ - List each conflict
106
+ - Ask user which to keep (file or context) — one at a time
@@ -1,44 +1,60 @@
1
+ This workflow runs when user invokes /codeninja:debug
2
+
1
3
  ---
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.
4
+ type: workflow
5
+ name: debug
6
+ description: >
7
+ Diagnose and fix bugs using full project context DB schema, middleware
8
+ chain, service config, and established patterns. Traces the exact failure
9
+ path and produces a concrete fix.
6
10
  ---
7
11
 
8
- # /codeninja:debug
12
+ # Workflow: @debug / /codeninja:debug
9
13
 
10
- ## Before Running
11
- 1. Call `context_read` load services, DB schema, project config
12
- 2. Call `context_check_stale`
14
+ ## Goal
15
+ Find the root cause of a bug and produce a concrete fix using actual project
16
+ context. Never guess — trace the real code path.
17
+
18
+ ## Rules
19
+ - Trace the full request path before concluding anything
20
+ - Cross-reference context.db.schema before assuming a DB mismatch
21
+ - Check middleware chain order before assuming an auth issue
22
+ - One question at a time when gathering information
23
+
24
+ ---
13
25
 
14
- ## Execution — Full Step-by-Step
26
+ ## Step-by-Step Execution
15
27
 
16
- ### Step 1 — Gather Error Information (ask one at a time if not provided)
28
+ ### Step 1 — Gather Error Information
29
+ Ask (one at a time if not already provided):
17
30
  1. "Paste the full error message and stack trace."
18
31
  2. "Which endpoint or operation triggered it? (e.g., POST /v1/scores/submit)"
19
- 3. "What did you expect vs what actually happened?"
32
+ 3. "What did you expect to happen vs what actually happened?"
20
33
  4. "What changed recently before this error appeared?"
21
34
 
22
35
  ### 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
36
+ 1. Call `context_read` load services, DB schema, project config
37
+ 2. Call `fs_read` on the relevant route.js
38
+ 3. Call `fs_read` on the relevant _model.js
39
+ 4. Call `fs_exists` on the migration file for any table mentioned in the error
26
40
 
27
41
  ### Step 3 — Trace the Failure Path
28
42
 
29
- Walk the request lifecycle in order — mark the exact step where failure occurs:
43
+ Walk the request lifecycle in order:
30
44
  ```
31
45
  Request received
32
46
  → Language middleware (extracts Accept-Language)
33
47
  → API key middleware (validates api-key header)
34
- → Auth middleware (validates JWT if protected)
48
+ → Auth middleware (validates JWT, if protected)
35
49
  → Validation (validatorjs schema)
36
50
  → Route handler (calls model)
37
51
  → Model function (executes query)
38
- → Database (pg pool / mysql2 / mongoose)
52
+ → Database (pg pool)
39
53
  → Response formatter
40
54
  ```
41
55
 
56
+ Mark the exact step where the error occurs.
57
+
42
58
  ### Step 4 — Check Common Root Causes
43
59
 
44
60
  | Symptom | Check |
@@ -48,7 +64,7 @@ Request received
48
64
  | `Cannot read property of undefined` | missing null check after DB query returns 0 rows |
49
65
  | `401 Unauthorized` | middleware order — apiKey middleware applied? header name correct? |
50
66
  | `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 |
67
+ | `Wrong number of rows` | missing dedup query, RANK vs DENSE_RANK, missing WHERE clause |
52
68
  | `Migration not applied` | table exists in code but not in DB — run migration |
53
69
  | Stale context data | context.db.schema out of date — suggest /codeninja:db:sync |
54
70
 
@@ -69,14 +85,12 @@ After:
69
85
  Why this fixes it: [one sentence]
70
86
  ```
71
87
 
72
- If multiple files need changes, show each in order.
88
+ If multiple files need changes, show each one in order.
73
89
 
74
90
  ### Step 6 — Verify Plan
75
-
76
91
  "Before I apply this fix, confirm: does this match what you're seeing?
77
92
  Once confirmed, I'll make the changes."
78
93
 
79
94
  ### Step 7 — Prevent Recurrence
80
-
81
95
  After fixing: suggest one guard that prevents this class of bug in the future.
82
96
  (e.g., a missing index, an added null check helper, a context convention)