codeninja 3.1.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.
- package/ide/antigravity/.agents/personas/global-orchestrator.md +103 -84
- package/ide/antigravity/.agents/workflows/codeninja-api.md +98 -15
- package/ide/antigravity/.agents/workflows/codeninja-audit.md +69 -11
- package/ide/antigravity/.agents/workflows/codeninja-db-create.md +118 -5
- package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +81 -5
- package/ide/antigravity/.agents/workflows/codeninja-db-index.md +64 -5
- package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +100 -5
- package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +70 -4
- package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +64 -6
- package/ide/antigravity/.agents/workflows/codeninja-debug.md +76 -6
- package/ide/antigravity/.agents/workflows/codeninja-design.md +45 -12
- package/ide/antigravity/.agents/workflows/codeninja-explain.md +35 -6
- package/ide/antigravity/.agents/workflows/codeninja-init.md +329 -22
- package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +334 -9
- package/ide/antigravity/.agents/workflows/codeninja-modularize.md +214 -9
- package/ide/antigravity/.agents/workflows/codeninja-optimize.md +78 -7
- package/ide/antigravity/.agents/workflows/codeninja-refactor.md +58 -13
- package/ide/antigravity/.agents/workflows/codeninja-review.md +64 -6
- package/ide/antigravity/.agents/workflows/codeninja-sync.md +172 -12
- package/ide/antigravity/.agents/workflows/codeninja-test.md +51 -9
- package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +248 -9
- package/ide/cursor/.cursor/rules/01-global-orchestrator.mdc +35 -32
- package/ide/cursor/.cursor/rules/03-api-builder.mdc +100 -50
- package/ide/cursor/.cursor/rules/04-database.mdc +73 -70
- package/ide/cursor/.cursor/rules/05-reactjs.mdc +133 -69
- package/ide/vscode/.github/copilot-instructions.md +304 -190
- package/package.json +1 -1
|
@@ -2,10 +2,86 @@
|
|
|
2
2
|
slash_command: /codeninja:db:drop
|
|
3
3
|
personas: [global-orchestrator, database-architect]
|
|
4
4
|
skills: [mcp-and-context, database]
|
|
5
|
-
description:
|
|
5
|
+
description: Generate a DROP TABLE migration. Never deletes the original setup file.
|
|
6
6
|
---
|
|
7
|
+
|
|
7
8
|
# /codeninja:db:drop
|
|
8
|
-
|
|
9
|
-
Before
|
|
10
|
-
|
|
11
|
-
|
|
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 to drop?" (list from `context.db.schema.tables`)
|
|
19
|
+
- Store: `context.current_db.table_name`
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
### Phase 2 — Impact Analysis
|
|
24
|
+
|
|
25
|
+
**Step 2.** Agent scans context:
|
|
26
|
+
- Check `context.api_routes` for routes referencing this table as `primary_table`
|
|
27
|
+
- Check `context.services` for modules using this table
|
|
28
|
+
- Check `context.db.schema.tables` for FK columns pointing to this table
|
|
29
|
+
|
|
30
|
+
**Step 3.** If references found, display warning:
|
|
31
|
+
```
|
|
32
|
+
⚠ WARNING: This table is referenced by:
|
|
33
|
+
- [service]/modules/[Module] (primary_table)
|
|
34
|
+
- tbl_<other_table>.<col> → <this_table> (FK dependency)
|
|
35
|
+
|
|
36
|
+
Dropping this table will break these references.
|
|
37
|
+
Make sure to update or remove dependent code first.
|
|
38
|
+
```
|
|
39
|
+
Ask: "Do you still want to proceed? (yes / no)"
|
|
40
|
+
If no → abort.
|
|
41
|
+
|
|
42
|
+
**Step 4.** Final confirmation:
|
|
43
|
+
Ask: "Type the table name to confirm the drop."
|
|
44
|
+
Must match exactly — if wrong → abort.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
### Phase 3 — File Numbering
|
|
49
|
+
|
|
50
|
+
**Step 5.** Ask: "Migration file number?" (suggest next available)
|
|
51
|
+
- Store: `context.current_db.file_number`
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### Phase 4 — Generate
|
|
56
|
+
|
|
57
|
+
**Step 6.** Delegate to database-agent:
|
|
58
|
+
Generate: `<repo_root>/database/<db_type>/migrations/<number>-drop-tbl-<n>.sql`
|
|
59
|
+
|
|
60
|
+
```sql
|
|
61
|
+
-- Drop tbl_<table_name>
|
|
62
|
+
-- Migration: <number>-drop-tbl-<n>.sql
|
|
63
|
+
-- Generated: <ISO date>
|
|
64
|
+
-- WARNING: This migration is irreversible in production.
|
|
65
|
+
-- Original table definition: <original_setup_file>
|
|
66
|
+
|
|
67
|
+
BEGIN;
|
|
68
|
+
|
|
69
|
+
DROP TABLE IF EXISTS public.<table_name> CASCADE;
|
|
70
|
+
|
|
71
|
+
COMMIT;
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Update `create-schema.sql`:
|
|
75
|
+
- Keep the original `\i <setup_file>` entry
|
|
76
|
+
- Add the drop file entry AFTER it (never remove original)
|
|
77
|
+
|
|
78
|
+
**Step 7.** Call `context_write`:
|
|
79
|
+
- Snapshot full column list before removing from active tables
|
|
80
|
+
- Append to `context.db.schema.change_log`:
|
|
81
|
+
`{ type: "table_dropped", table: "<n>", snapshot: { full column list }, file: "<path>" }`
|
|
82
|
+
- Remove table from `context.db.schema.tables`
|
|
83
|
+
- Clear `context.current_db`
|
|
84
|
+
|
|
85
|
+
**Step 8.** Call `context_clear_scratchpad` with keys: ["current_db"]
|
|
86
|
+
|
|
87
|
+
**Step 9.** Show final summary.
|
|
@@ -2,10 +2,69 @@
|
|
|
2
2
|
slash_command: /codeninja:db:index
|
|
3
3
|
personas: [global-orchestrator, database-architect]
|
|
4
4
|
skills: [mcp-and-context, database]
|
|
5
|
-
description: Add a new index to an existing table
|
|
5
|
+
description: Add a new index to an existing table.
|
|
6
6
|
---
|
|
7
|
+
|
|
7
8
|
# /codeninja:db:index
|
|
8
|
-
|
|
9
|
-
Before
|
|
10
|
-
|
|
11
|
-
|
|
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 Table
|
|
17
|
+
|
|
18
|
+
**Step 1.** Ask: "Which table?" (list from `context.db.schema.tables`)
|
|
19
|
+
- Store: `context.current_db.table_name`
|
|
20
|
+
|
|
21
|
+
### Phase 2 — Index Columns
|
|
22
|
+
|
|
23
|
+
**Step 2.** Ask: "Which column(s) for this index?"
|
|
24
|
+
- List available columns from `context.db.schema.tables[<table>].columns`
|
|
25
|
+
- Allow one or multiple (compound index)
|
|
26
|
+
- Store: `context.current_db.index_columns[]`
|
|
27
|
+
|
|
28
|
+
**Step 3.** Ask: "Should any column be sorted DESC?" (common: `created_at DESC`, `time DESC`)
|
|
29
|
+
- If yes → ask which column(s)
|
|
30
|
+
- Store: `context.current_db.index_desc_columns[]`
|
|
31
|
+
|
|
32
|
+
**Step 4.** Ask: "Standard or partial index?"
|
|
33
|
+
- Standard: covers all rows
|
|
34
|
+
- Partial: only rows matching a WHERE condition — if partial, ask for WHERE clause
|
|
35
|
+
- Store: `context.current_db.index_where_clause`
|
|
36
|
+
|
|
37
|
+
### Phase 3 — File Placement
|
|
38
|
+
|
|
39
|
+
**Step 5.** Ask: "Where should this index be defined?"
|
|
40
|
+
1. In the table's own setup file (for new/just-created tables)
|
|
41
|
+
2. In `111-setup-database-indexes.sql` (for existing tables — auto-suggested)
|
|
42
|
+
- Store: `context.current_db.index_file`
|
|
43
|
+
|
|
44
|
+
### Phase 4 — Generate
|
|
45
|
+
|
|
46
|
+
**Step 6.** Agent auto-generates index name:
|
|
47
|
+
- In table file: `idx_<table_without_tbl_prefix>_<columns_joined>`
|
|
48
|
+
- In shared file: `idx_tbl_<table_without_tbl_prefix>_<columns_joined>`
|
|
49
|
+
- Show: "Index will be named: <name> — OK? (yes / rename)"
|
|
50
|
+
|
|
51
|
+
**Step 7.** Confirm: "Generate this index? (yes / no)"
|
|
52
|
+
|
|
53
|
+
**Step 8.** Delegate to database-agent:
|
|
54
|
+
```sql
|
|
55
|
+
--
|
|
56
|
+
-- Name: <index_name>; Type: INDEX; Schema: public
|
|
57
|
+
--
|
|
58
|
+
CREATE INDEX <index_name> ON public.<table_name> (<col> [DESC], ...)
|
|
59
|
+
[WHERE <where_clause>];
|
|
60
|
+
```
|
|
61
|
+
Append to correct file (table setup file OR `111-setup-database-indexes.sql`).
|
|
62
|
+
|
|
63
|
+
**Step 9.** Call `context_write`:
|
|
64
|
+
- Append index to `context.db.schema.tables[<table>].indexes`
|
|
65
|
+
- Append to `context.db.schema.change_log`
|
|
66
|
+
- Clear `context.current_db`
|
|
67
|
+
|
|
68
|
+
**Step 10.** Call `context_clear_scratchpad` with keys: ["current_db"]
|
|
69
|
+
|
|
70
|
+
**Step 11.** Show final summary.
|
|
@@ -2,10 +2,105 @@
|
|
|
2
2
|
slash_command: /codeninja:db:modify
|
|
3
3
|
personas: [global-orchestrator, database-architect]
|
|
4
4
|
skills: [mcp-and-context, database]
|
|
5
|
-
description:
|
|
5
|
+
description: Modify an existing table via a numbered ALTER migration file.
|
|
6
6
|
---
|
|
7
|
+
|
|
7
8
|
# /codeninja:db:modify
|
|
8
|
-
|
|
9
|
-
Before
|
|
10
|
-
|
|
11
|
-
|
|
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.
|
|
@@ -2,9 +2,75 @@
|
|
|
2
2
|
slash_command: /codeninja:db:seed
|
|
3
3
|
personas: [global-orchestrator, database-architect]
|
|
4
4
|
skills: [mcp-and-context, database]
|
|
5
|
-
description: Add
|
|
5
|
+
description: Add seed/initial data to a table.
|
|
6
6
|
---
|
|
7
|
+
|
|
7
8
|
# /codeninja:db:seed
|
|
8
|
-
|
|
9
|
-
Before
|
|
10
|
-
|
|
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.
|
|
@@ -2,11 +2,69 @@
|
|
|
2
2
|
slash_command: /codeninja:db:sync
|
|
3
3
|
personas: [global-orchestrator, database-architect]
|
|
4
4
|
skills: [mcp-and-context, database]
|
|
5
|
-
description: Scan migration files and rebuild context.db.schema
|
|
5
|
+
description: Scan all migration files and rebuild context.db.schema from actual file contents.
|
|
6
6
|
---
|
|
7
|
+
|
|
7
8
|
# /codeninja:db:sync
|
|
8
|
-
|
|
9
|
-
Before
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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.
|
|
@@ -2,11 +2,81 @@
|
|
|
2
2
|
slash_command: /codeninja:debug
|
|
3
3
|
personas: [global-orchestrator, nodejs-backend]
|
|
4
4
|
skills: [mcp-and-context, api-builder, code-intelligence]
|
|
5
|
-
description: Diagnose and fix
|
|
5
|
+
description: Diagnose and fix bugs using full project context and code path tracing.
|
|
6
6
|
---
|
|
7
|
+
|
|
7
8
|
# /codeninja:debug
|
|
8
|
-
|
|
9
|
-
Before
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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)
|
|
@@ -1,21 +1,54 @@
|
|
|
1
1
|
---
|
|
2
2
|
slash_command: /codeninja:design
|
|
3
|
-
personas: [global-orchestrator, nodejs-backend
|
|
4
|
-
skills: [mcp-and-context, api-builder
|
|
5
|
-
description: Plan a feature, API contract, or
|
|
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
6
|
---
|
|
7
7
|
|
|
8
8
|
# /codeninja:design
|
|
9
9
|
|
|
10
|
-
Delegates to: `.codeninja/commands/design.workflow.md`
|
|
11
|
-
|
|
12
10
|
## Before Running
|
|
13
|
-
1. Call `context_read`
|
|
14
|
-
2.
|
|
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
|
|
15
50
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Produce a written plan before any code is generated. User approves plan before execution begins.
|
|
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"]
|
|
19
53
|
|
|
20
|
-
|
|
21
|
-
Call `context_write` with design notes stored in `context.current_design`.
|
|
54
|
+
**Step 8.** Show final summary.
|
|
@@ -1,11 +1,40 @@
|
|
|
1
1
|
---
|
|
2
2
|
slash_command: /codeninja:explain
|
|
3
|
-
personas: [global-orchestrator
|
|
3
|
+
personas: [global-orchestrator]
|
|
4
4
|
skills: [mcp-and-context, code-intelligence]
|
|
5
|
-
description: Explain any file, function, pattern, or concept
|
|
5
|
+
description: Explain any file, function, pattern, or concept using full project context.
|
|
6
6
|
---
|
|
7
|
+
|
|
7
8
|
# /codeninja:explain
|
|
8
|
-
|
|
9
|
-
Before
|
|
10
|
-
|
|
11
|
-
|
|
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?"
|