codeninja 3.2.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.
- package/README.md +13 -1
- package/agent/database-agent.md +24 -1
- package/agent/nodejs-agent.md +79 -0
- package/cli.js +27 -7
- package/commands/audit.workflow.md +4 -1
- package/commands/db-create-table.workflow.md +1 -1
- package/commands/initialize-project.workflow.md +21 -0
- package/ide/antigravity/.agents/personas/database-architect.md +431 -153
- package/ide/antigravity/.agents/personas/global-orchestrator.md +202 -85
- package/ide/antigravity/.agents/personas/nodejs-backend.md +368 -133
- package/ide/antigravity/.agents/personas/reactjs-frontend.md +182 -101
- package/ide/antigravity/.agents/skills/api-builder/SKILL.md +58 -0
- package/ide/antigravity/.agents/skills/code-intelligence/SKILL.md +22 -0
- package/ide/antigravity/.agents/skills/database/SKILL.md +32 -0
- package/ide/antigravity/.agents/skills/mcp-and-context/SKILL.md +76 -82
- package/ide/antigravity/.agents/skills/reactjs/SKILL.md +36 -0
- package/ide/antigravity/.agents/workflows/codeninja-api.md +76 -83
- package/ide/antigravity/.agents/workflows/codeninja-audit.md +82 -44
- package/ide/antigravity/.agents/workflows/codeninja-db-create.md +107 -94
- package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +89 -67
- package/ide/antigravity/.agents/workflows/codeninja-db-index.md +86 -54
- package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +126 -68
- package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +87 -59
- package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +77 -41
- package/ide/antigravity/.agents/workflows/codeninja-debug.md +35 -21
- package/ide/antigravity/.agents/workflows/codeninja-design.md +49 -35
- package/ide/antigravity/.agents/workflows/codeninja-explain.md +41 -20
- package/ide/antigravity/.agents/workflows/codeninja-init.md +479 -289
- package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +253 -136
- package/ide/antigravity/.agents/workflows/codeninja-modularize.md +250 -132
- package/ide/antigravity/.agents/workflows/codeninja-optimize.md +71 -29
- package/ide/antigravity/.agents/workflows/codeninja-refactor.md +50 -42
- package/ide/antigravity/.agents/workflows/codeninja-review.md +38 -21
- package/ide/antigravity/.agents/workflows/codeninja-sync.md +922 -141
- package/ide/antigravity/.agents/workflows/codeninja-test.md +34 -49
- package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +449 -151
- package/ide/claude-code/.claude/CLAUDE.md +99 -0
- package/ide/claude-code/.claude/agents/database-agent.md +535 -0
- package/ide/claude-code/.claude/agents/nodejs-agent.md +493 -0
- package/ide/claude-code/.claude/agents/reactjs-agent.md +267 -0
- package/ide/claude-code/.claude/commands/codeninja-api.md +104 -0
- package/ide/claude-code/.claude/commands/codeninja-audit.md +119 -0
- package/ide/claude-code/.claude/commands/codeninja-db-create.md +138 -0
- package/ide/claude-code/.claude/commands/codeninja-db-drop.md +109 -0
- package/ide/claude-code/.claude/commands/codeninja-db-index.md +103 -0
- package/ide/claude-code/.claude/commands/codeninja-db-modify.md +165 -0
- package/ide/claude-code/.claude/commands/codeninja-db-seed.md +104 -0
- package/ide/claude-code/.claude/commands/codeninja-db-sync.md +106 -0
- package/ide/claude-code/.claude/commands/codeninja-debug.md +99 -0
- package/ide/claude-code/.claude/commands/codeninja-design.md +68 -0
- package/ide/claude-code/.claude/commands/codeninja-explain.md +61 -0
- package/ide/claude-code/.claude/commands/codeninja-init.md +529 -0
- package/ide/claude-code/.claude/commands/codeninja-integrate-api.md +453 -0
- package/ide/claude-code/.claude/commands/codeninja-modularize.md +334 -0
- package/ide/claude-code/.claude/commands/codeninja-optimize.md +129 -0
- package/ide/claude-code/.claude/commands/codeninja-refactor.md +76 -0
- package/ide/claude-code/.claude/commands/codeninja-review.md +87 -0
- package/ide/claude-code/.claude/commands/codeninja-sync.md +964 -0
- package/ide/claude-code/.claude/commands/codeninja-test.md +45 -0
- package/ide/claude-code/.claude/commands/codeninja-validate-page.md +548 -0
- package/ide/cursor/.cursor/rules/01-global-orchestrator.mdc +12 -13
- package/ide/cursor/.cursor/rules/02-mcp-and-context.mdc +47 -31
- package/ide/cursor/.cursor/rules/03-api-builder.mdc +32 -110
- package/ide/cursor/.cursor/rules/04-nodejs-generation.mdc +58 -0
- package/ide/cursor/.cursor/rules/05-database.mdc +54 -0
- package/ide/cursor/.cursor/rules/06-reactjs.mdc +36 -0
- package/ide/cursor/.cursor/rules/07-reactjs-generation.mdc +49 -0
- package/ide/cursor/.cursor/rules/08-code-intelligence.mdc +56 -0
- package/ide/cursor/.cursor/rules/09-workflow-steps.mdc +53 -0
- package/ide/vscode/.github/copilot-instructions.md +67 -382
- package/ide/vscode/.vscode/instructions/code-intelligence.instructions.md +58 -0
- package/ide/vscode/.vscode/instructions/database.instructions.md +55 -0
- package/ide/vscode/.vscode/instructions/nodejs.instructions.md +77 -0
- package/ide/vscode/.vscode/instructions/reactjs.instructions.md +42 -0
- package/package.json +2 -2
- package/tasks/ask-hashing-library.task.md +31 -0
- package/tasks/ask-language-type.task.md +26 -0
- package/tasks/ask-new-module-name.task.md +13 -0
- package/tasks/ask-new-service-name.task.md +13 -0
- package/tasks/ask-old-module-name.task.md +15 -0
- package/tasks/ask-old-service-name.task.md +13 -0
- package/tasks/ask-orm-type.task.md +26 -0
- package/tasks/collect-seed-data.task.md +19 -0
- package/tasks/generate-app.task.md +42 -0
- package/tasks/generate-common.task.md +13 -0
- package/tasks/generate-constants.task.md +13 -0
- package/tasks/generate-database.task.md +32 -0
- package/tasks/generate-encryption.task.md +28 -0
- package/tasks/generate-fast-defaults.task.md +7 -0
- package/tasks/generate-hashing.task.md +180 -0
- package/tasks/generate-headerValidator.task.md +13 -0
- package/tasks/generate-ioRedis.task.md +20 -0
- package/tasks/generate-language-en.task.md +12 -0
- package/tasks/generate-logging.task.md +12 -0
- package/tasks/generate-model.task.md +74 -6
- package/tasks/generate-notification.task.md +12 -0
- package/tasks/generate-package-json.task.md +69 -0
- package/tasks/generate-prisma-client.task.md +56 -0
- package/tasks/generate-prisma-schema.task.md +71 -0
- package/tasks/generate-rateLimiter.task.md +20 -0
- package/tasks/generate-readme.task.md +24 -0
- package/tasks/generate-response.task.md +27 -0
- package/tasks/generate-route-manager.task.md +32 -0
- package/tasks/generate-route.task.md +37 -0
- package/tasks/generate-swagger.task.md +8 -0
- package/tasks/generate-template.task.md +12 -0
- package/tasks/generate-tsconfig.task.md +38 -0
- package/tasks/generate-validator.task.md +31 -0
- package/ide/cursor/.cursor/rules/04-database.mdc +0 -90
- package/ide/cursor/.cursor/rules/05-reactjs.mdc +0 -147
- package/ide/cursor/.cursor/rules/06-code-intelligence.mdc +0 -112
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
This command runs when user types /codeninja:db-drop
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
type: workflow
|
|
5
|
+
name: db-drop-table
|
|
6
|
+
command: "@db:drop-table"
|
|
7
|
+
description: >
|
|
8
|
+
Generate a DROP TABLE migration file for an existing table. Removes the
|
|
9
|
+
table from context, updates create-schema.sql, and records the drop in
|
|
10
|
+
change_log. Never deletes the original setup file — history is preserved.
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Workflow: @db:drop-table
|
|
14
|
+
|
|
15
|
+
## Goal
|
|
16
|
+
Safely generate a DROP TABLE migration. The original setup file is preserved
|
|
17
|
+
for history. The schema runner will execute the drop when run.
|
|
18
|
+
|
|
19
|
+
## Rules
|
|
20
|
+
- NEVER delete the original <number>-setup-tbl-<n>.sql file
|
|
21
|
+
- ALWAYS generate a new numbered drop migration file
|
|
22
|
+
- ALWAYS warn the user about irreversibility
|
|
23
|
+
- Records in change_log with full before-state for rollback reference
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Step-by-Step Execution
|
|
28
|
+
|
|
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`
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
### Phase 2 — Impact Analysis
|
|
37
|
+
2. Agent scans `context`:
|
|
38
|
+
- Check `context.api_routes` for any routes that reference this table as `primary_table`
|
|
39
|
+
- Check `context.services` for any modules using this table
|
|
40
|
+
- Check `context.db.schema.tables` for any other tables with FK columns pointing here
|
|
41
|
+
|
|
42
|
+
3. If references found:
|
|
43
|
+
- Display warning:
|
|
44
|
+
```
|
|
45
|
+
⚠ WARNING: This table is referenced by:
|
|
46
|
+
- [service]/modules/[Module] (primary_table)
|
|
47
|
+
- tbl_<other_table>.user_id → tbl_users (FK dependency)
|
|
48
|
+
|
|
49
|
+
Dropping this table will break these references.
|
|
50
|
+
Make sure to update or remove dependent code first.
|
|
51
|
+
```
|
|
52
|
+
- Ask: "Do you still want to proceed? (yes / no)"
|
|
53
|
+
- If no → abort
|
|
54
|
+
|
|
55
|
+
4. Final confirmation:
|
|
56
|
+
- Ask exactly: "Type the table name to confirm the drop."
|
|
57
|
+
- Must match exactly — if wrong → abort
|
|
58
|
+
- Stores: confirmation
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### Phase 3 — File Numbering
|
|
63
|
+
5. Run task: `ask-table-file-number`
|
|
64
|
+
- Suggest: next available number
|
|
65
|
+
- Stores: `context.current_db.file_number`
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### Phase 4 — Generate
|
|
70
|
+
6. Delegate to `database-agent`:
|
|
71
|
+
|
|
72
|
+
> **Claude Code sub-agent:** Spawn sub-agent: Task(database-agent)
|
|
73
|
+
> The spawned agent reads `.codeninja/tasks/generate-*.task.md` for generation standards.
|
|
74
|
+
|
|
75
|
+
- Generate: `<repo_root>/database/<db_type>/migrations/<number>-drop-tbl-<n>.sql`
|
|
76
|
+
|
|
77
|
+
File contents:
|
|
78
|
+
```sql
|
|
79
|
+
-- Drop tbl_<table_name>
|
|
80
|
+
-- Migration: <number>-drop-tbl-<n>.sql
|
|
81
|
+
-- Generated: <ISO date>
|
|
82
|
+
-- WARNING: This migration is irreversible in production.
|
|
83
|
+
-- Original table definition: <original_setup_file>
|
|
84
|
+
|
|
85
|
+
BEGIN;
|
|
86
|
+
|
|
87
|
+
DROP TABLE IF EXISTS public.<table_name> CASCADE;
|
|
88
|
+
|
|
89
|
+
COMMIT;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- Update: `database/<db_type>/create-schema.sql`
|
|
93
|
+
- Keep the original `\i <setup_file>` entry
|
|
94
|
+
- Add the drop file entry AFTER it
|
|
95
|
+
|
|
96
|
+
7. Run task: `write-context`
|
|
97
|
+
- Move table from `context.db.schema.tables` → save columns snapshot
|
|
98
|
+
- Append to `context.db.schema.change_log`:
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"type": "table_dropped",
|
|
102
|
+
"table": "<table_name>",
|
|
103
|
+
"snapshot": { "<full column list saved here>" },
|
|
104
|
+
"file": "<drop_file_path>"
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
- Clear `context.current_db`
|
|
108
|
+
|
|
109
|
+
8. Run task: `show-final-summary`
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
This command runs when user types /codeninja:db-index
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
type: workflow
|
|
5
|
+
name: db-add-index
|
|
6
|
+
command: "@db:add-index"
|
|
7
|
+
description: >
|
|
8
|
+
Add a new index to an existing table. Determines whether the index belongs
|
|
9
|
+
in the table's own file (new tables) or in 111-setup-database-indexes.sql
|
|
10
|
+
(shared/cross-service indexes). Updates context and create-schema.sql.
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Workflow: @db:add-index
|
|
14
|
+
|
|
15
|
+
## Goal
|
|
16
|
+
Generate a properly named CREATE INDEX statement and place it in the correct
|
|
17
|
+
file. Follow all index naming conventions from database-agent.md.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Step-by-Step Execution
|
|
22
|
+
|
|
23
|
+
### Phase 1 — Target Table
|
|
24
|
+
1. Run task: `ask-table-name`
|
|
25
|
+
- List tables from `context.db.schema.tables`
|
|
26
|
+
- Stores: `context.current_db.table_name`
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
### Phase 2 — Index Columns
|
|
31
|
+
2. Run task: `ask-index-columns`
|
|
32
|
+
- Ask: "Which column(s) should this index cover?"
|
|
33
|
+
- List available columns from `context.db.schema.tables[<table>].columns`
|
|
34
|
+
- Allow selecting one or multiple columns (compound index)
|
|
35
|
+
- Stores: `context.current_db.index_columns[]`
|
|
36
|
+
|
|
37
|
+
3. Run task: `ask-index-sort-order`
|
|
38
|
+
- Ask: "Should any column in this index be sorted descending?"
|
|
39
|
+
- Common case: `created_at DESC`, `time DESC`
|
|
40
|
+
- If yes → ask which column(s) should be DESC
|
|
41
|
+
- Stores: `context.current_db.index_desc_columns[]`
|
|
42
|
+
|
|
43
|
+
4. Run task: `ask-index-type`
|
|
44
|
+
- Ask: "Is this a standard index or a partial index?"
|
|
45
|
+
- Options:
|
|
46
|
+
1. Standard index (covers all rows)
|
|
47
|
+
2. Partial index (only indexes rows matching a condition)
|
|
48
|
+
- If partial → ask: "Enter the WHERE condition."
|
|
49
|
+
Example: `WHERE is_deleted = FALSE`
|
|
50
|
+
- Stores: `context.current_db.index_where_clause`
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
### Phase 3 — File Placement
|
|
55
|
+
5. Run task: `ask-index-file-placement`
|
|
56
|
+
- Ask: "Where should this index be defined?"
|
|
57
|
+
- Options:
|
|
58
|
+
1. In the table's own setup file (for new/just-created tables)
|
|
59
|
+
2. In 111-setup-database-indexes.sql (for existing tables, shared use)
|
|
60
|
+
- Auto-suggest option 2 if table already has a setup file in migrations
|
|
61
|
+
- Stores: `context.current_db.index_file`
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
### Phase 4 — Generate
|
|
66
|
+
6. Agent auto-generates the index name following convention:
|
|
67
|
+
- In table file: `idx_<table_without_tbl_prefix>_<columns_joined>`
|
|
68
|
+
- In shared file: `idx_tbl_<table_without_tbl_prefix>_<columns_joined>`
|
|
69
|
+
- Show name to user: "Index will be named: <n> — OK? (yes / rename)"
|
|
70
|
+
|
|
71
|
+
7. Confirm: "Generate this index? (yes / no)"
|
|
72
|
+
|
|
73
|
+
8. Delegate to `database-agent`:
|
|
74
|
+
|
|
75
|
+
> **Claude Code sub-agent:** Spawn sub-agent: Task(database-agent)
|
|
76
|
+
> The spawned agent reads `.codeninja/tasks/generate-*.task.md` for generation standards.
|
|
77
|
+
|
|
78
|
+
- If table file placement → append to `<repo_root>/database/<db_type>/migrations/<table_file>.sql`
|
|
79
|
+
- If shared file → append to `<repo_root>/database/<db_type>/migrations/111-setup-database-indexes.sql`
|
|
80
|
+
|
|
81
|
+
Generated SQL:
|
|
82
|
+
```sql
|
|
83
|
+
-- Standard
|
|
84
|
+
CREATE INDEX <index_name> ON public.<table_name> (<col> [DESC], ...);
|
|
85
|
+
|
|
86
|
+
-- Partial
|
|
87
|
+
CREATE INDEX <index_name> ON public.<table_name> (<col> [DESC], ...)
|
|
88
|
+
WHERE <where_clause>;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
With standard header comment:
|
|
92
|
+
```sql
|
|
93
|
+
--
|
|
94
|
+
-- Name: <index_name>; Type: INDEX; Schema: public
|
|
95
|
+
--
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
9. Run task: `write-context`
|
|
99
|
+
- Append index name to `context.db.schema.tables[<table>].indexes`
|
|
100
|
+
- Append to `context.db.schema.change_log`
|
|
101
|
+
- Clear `context.current_db`
|
|
102
|
+
|
|
103
|
+
10. Run task: `show-final-summary`
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
This command runs when user types /codeninja:db-modify
|
|
2
|
+
|
|
3
|
+
---
|
|
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.
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
# Workflow: @db:modify-table
|
|
15
|
+
|
|
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.
|
|
20
|
+
|
|
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
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Step-by-Step Execution
|
|
30
|
+
|
|
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).
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
### Phase 2 — Operation-Specific Collection
|
|
54
|
+
|
|
55
|
+
#### If "Add a new column":
|
|
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
|
+
```
|
|
69
|
+
|
|
70
|
+
#### If "Rename a column":
|
|
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
|
+
```
|
|
81
|
+
|
|
82
|
+
#### If "Drop a column":
|
|
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
|
+
```
|
|
94
|
+
|
|
95
|
+
#### If "Change a column 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
|
+
```
|
|
116
|
+
|
|
117
|
+
#### If "Add a new index":
|
|
118
|
+
→ Route to `@db:add-index` workflow instead.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
### Phase 3 — File Numbering
|
|
123
|
+
7. Run task: `ask-table-file-number`
|
|
124
|
+
- Suggest: next available number after all existing files
|
|
125
|
+
- Stores: `context.current_db.file_number`
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
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)"
|
|
133
|
+
|
|
134
|
+
9. Delegate to `database-agent`:
|
|
135
|
+
|
|
136
|
+
> **Claude Code sub-agent:** Spawn sub-agent: Task(database-agent)
|
|
137
|
+
> The spawned agent reads `.codeninja/tasks/generate-*.task.md` for generation standards.
|
|
138
|
+
|
|
139
|
+
- Generate: `<repo_root>/database/<db_type>/migrations/<number>-alter-tbl-<n>-<description>.sql`
|
|
140
|
+
|
|
141
|
+
Full file structure:
|
|
142
|
+
```sql
|
|
143
|
+
-- Alter tbl_<table>: <description>
|
|
144
|
+
-- Migration: <number>-alter-tbl-<n>-<description>.sql
|
|
145
|
+
-- Generated: <ISO date>
|
|
146
|
+
|
|
147
|
+
BEGIN;
|
|
148
|
+
|
|
149
|
+
ALTER TABLE public.<table_name>
|
|
150
|
+
<operation>;
|
|
151
|
+
|
|
152
|
+
-- Optional: COMMENT ON COLUMN if enum/flag column
|
|
153
|
+
-- Optional: CREATE INDEX if new column needs one
|
|
154
|
+
|
|
155
|
+
COMMIT;
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
- Update: `database/<db_type>/create-schema.sql`
|
|
159
|
+
|
|
160
|
+
10. Run task: `write-context`
|
|
161
|
+
- Update `context.db.schema.tables[<table>].columns`
|
|
162
|
+
- Append to `context.db.schema.change_log`
|
|
163
|
+
- Clear `context.current_db`
|
|
164
|
+
|
|
165
|
+
11. Run task: `show-final-summary`
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
This command runs when user types /codeninja:db-seed
|
|
2
|
+
|
|
3
|
+
---
|
|
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.
|
|
11
|
+
---
|
|
12
|
+
|
|
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.
|
|
18
|
+
|
|
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`
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Step-by-Step Execution
|
|
28
|
+
|
|
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`
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
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/
|
|
41
|
+
|
|
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)
|
|
46
|
+
|
|
47
|
+
Stores: `context.current_db.seed_target`
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
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[]`
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### Phase 4 — Generate
|
|
70
|
+
6. Show full INSERT preview to user
|
|
71
|
+
- Ask: "Generate this seed data? (yes / no)"
|
|
72
|
+
|
|
73
|
+
7. Delegate to `database-agent`:
|
|
74
|
+
|
|
75
|
+
> **Claude Code sub-agent:** Spawn sub-agent: Task(database-agent)
|
|
76
|
+
> The spawned agent reads `.codeninja/tasks/generate-*.task.md` for generation standards.
|
|
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`
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
This command runs when user types /codeninja:db-sync
|
|
2
|
+
|
|
3
|
+
---
|
|
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.
|
|
11
|
+
---
|
|
12
|
+
|
|
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.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Step-by-Step Execution
|
|
22
|
+
|
|
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`
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
### Phase 2 — Parse Each File
|
|
39
|
+
For each setup file (in order):
|
|
40
|
+
- Extract table name from CREATE TABLE statement
|
|
41
|
+
- Extract all column names and types
|
|
42
|
+
- Extract CHECK constraints (enum values)
|
|
43
|
+
- Extract COMMENT ON COLUMN lines (enum descriptions)
|
|
44
|
+
- Extract per-file CREATE INDEX lines
|
|
45
|
+
- Note if table has `status`, `is_deleted`, `created_at`
|
|
46
|
+
|
|
47
|
+
For each alter file (in order after its setup file):
|
|
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
|
|
52
|
+
|
|
53
|
+
For each drop file:
|
|
54
|
+
- Mark that table as dropped in the scan result
|
|
55
|
+
|
|
56
|
+
For the index file:
|
|
57
|
+
- Parse all CREATE INDEX statements
|
|
58
|
+
- Associate each index with its table
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### Phase 3 — Rebuild Context
|
|
63
|
+
|
|
64
|
+
> **Claude Code sub-agent:** Spawn sub-agent: Task(database-agent)
|
|
65
|
+
> The spawned agent reads `.codeninja/tasks/generate-*.task.md` for generation standards.
|
|
66
|
+
|
|
67
|
+
For each discovered table (not dropped):
|
|
68
|
+
- Compare with existing `context.db.schema.tables[<table>]`
|
|
69
|
+
- Add any tables not already in context
|
|
70
|
+
- Add any columns not already tracked
|
|
71
|
+
- Add any indexes not already tracked
|
|
72
|
+
- For renames found in ALTER files → append to change_log if not already there
|
|
73
|
+
|
|
74
|
+
For dropped tables:
|
|
75
|
+
- If still in `context.db.schema.tables` → move to change_log snapshot
|
|
76
|
+
- Remove from active tables list
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
### Phase 4 — Rebuild create-schema.sql
|
|
81
|
+
- Re-read all file names in correct numeric order
|
|
82
|
+
- Rewrite `create-schema.sql` to match actual files on disk
|
|
83
|
+
- Report any \i entries that are in create-schema.sql but missing from disk (stale)
|
|
84
|
+
- Report any files on disk not in create-schema.sql (missing)
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
### Phase 5 — Write and Report
|
|
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
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
This command runs when user types /codeninja:debug
|
|
2
|
+
|
|
3
|
+
---
|
|
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.
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Workflow: @debug / /codeninja:debug
|
|
13
|
+
|
|
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
|
+
---
|
|
25
|
+
|
|
26
|
+
## Step-by-Step Execution
|
|
27
|
+
|
|
28
|
+
### Step 1 — Gather Error Information
|
|
29
|
+
Ask (one at a time if not already provided):
|
|
30
|
+
1. "Paste the full error message and stack trace."
|
|
31
|
+
2. "Which endpoint or operation triggered it? (e.g., POST /v1/scores/submit)"
|
|
32
|
+
3. "What did you expect to happen vs what actually happened?"
|
|
33
|
+
4. "What changed recently before this error appeared?"
|
|
34
|
+
|
|
35
|
+
### Step 2 — Load Context
|
|
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
|
|
40
|
+
|
|
41
|
+
### Step 3 — Trace the Failure Path
|
|
42
|
+
|
|
43
|
+
Walk the request lifecycle in order:
|
|
44
|
+
```
|
|
45
|
+
Request received
|
|
46
|
+
→ Language middleware (extracts Accept-Language)
|
|
47
|
+
→ API key middleware (validates api-key header)
|
|
48
|
+
→ Auth middleware (validates JWT, if protected)
|
|
49
|
+
→ Validation (validatorjs schema)
|
|
50
|
+
→ Route handler (calls model)
|
|
51
|
+
→ Model function (executes query)
|
|
52
|
+
→ Database (pg pool)
|
|
53
|
+
→ Response formatter
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Mark the exact step where the error occurs.
|
|
57
|
+
|
|
58
|
+
### Step 4 — Check Common Root Causes
|
|
59
|
+
|
|
60
|
+
| Symptom | Check |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `column does not exist` | context.db.schema vs actual column names in model.js |
|
|
63
|
+
| `undefined is not a function` | wrong import path or missing export in model |
|
|
64
|
+
| `Cannot read property of undefined` | missing null check after DB query returns 0 rows |
|
|
65
|
+
| `401 Unauthorized` | middleware order — apiKey middleware applied? header name correct? |
|
|
66
|
+
| `500 Internal Server Error` | missing try/catch around async DB call |
|
|
67
|
+
| `Wrong number of rows` | missing dedup query, RANK vs DENSE_RANK, missing WHERE clause |
|
|
68
|
+
| `Migration not applied` | table exists in code but not in DB — run migration |
|
|
69
|
+
| Stale context data | context.db.schema out of date — suggest /codeninja:db:sync |
|
|
70
|
+
|
|
71
|
+
### Step 5 — Produce Fix
|
|
72
|
+
|
|
73
|
+
> **Claude Code sub-agent:** No spawning — analysis only.
|
|
74
|
+
> The spawned agent reads `.codeninja/tasks/generate-*.task.md` for generation standards.
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
Root cause: [one sentence — be precise]
|
|
78
|
+
|
|
79
|
+
Fix:
|
|
80
|
+
File: path/to/file.js
|
|
81
|
+
|
|
82
|
+
Before:
|
|
83
|
+
[the buggy code]
|
|
84
|
+
|
|
85
|
+
After:
|
|
86
|
+
[the corrected code]
|
|
87
|
+
|
|
88
|
+
Why this fixes it: [one sentence]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
If multiple files need changes, show each one in order.
|
|
92
|
+
|
|
93
|
+
### Step 6 — Verify Plan
|
|
94
|
+
"Before I apply this fix, confirm: does this match what you're seeing?
|
|
95
|
+
Once confirmed, I'll make the changes."
|
|
96
|
+
|
|
97
|
+
### Step 7 — Prevent Recurrence
|
|
98
|
+
After fixing: suggest one guard that prevents this class of bug in the future.
|
|
99
|
+
(e.g., a missing index, an added null check helper, a context convention)
|