codeninja 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/README.md +13 -1
  2. package/agent/database-agent.md +24 -1
  3. package/agent/nodejs-agent.md +79 -0
  4. package/cli.js +27 -7
  5. package/commands/audit.workflow.md +4 -1
  6. package/commands/db-create-table.workflow.md +1 -1
  7. package/commands/initialize-project.workflow.md +21 -0
  8. package/ide/antigravity/.agents/personas/database-architect.md +431 -153
  9. package/ide/antigravity/.agents/personas/global-orchestrator.md +219 -83
  10. package/ide/antigravity/.agents/personas/nodejs-backend.md +368 -133
  11. package/ide/antigravity/.agents/personas/reactjs-frontend.md +182 -101
  12. package/ide/antigravity/.agents/skills/api-builder/SKILL.md +58 -0
  13. package/ide/antigravity/.agents/skills/code-intelligence/SKILL.md +22 -0
  14. package/ide/antigravity/.agents/skills/database/SKILL.md +32 -0
  15. package/ide/antigravity/.agents/skills/mcp-and-context/SKILL.md +76 -82
  16. package/ide/antigravity/.agents/skills/reactjs/SKILL.md +36 -0
  17. package/ide/antigravity/.agents/workflows/codeninja-api.md +97 -21
  18. package/ide/antigravity/.agents/workflows/codeninja-audit.md +112 -16
  19. package/ide/antigravity/.agents/workflows/codeninja-db-create.md +135 -9
  20. package/ide/antigravity/.agents/workflows/codeninja-db-drop.md +107 -9
  21. package/ide/antigravity/.agents/workflows/codeninja-db-index.md +100 -9
  22. package/ide/antigravity/.agents/workflows/codeninja-db-modify.md +162 -9
  23. package/ide/antigravity/.agents/workflows/codeninja-db-seed.md +102 -8
  24. package/ide/antigravity/.agents/workflows/codeninja-db-sync.md +105 -11
  25. package/ide/antigravity/.agents/workflows/codeninja-debug.md +94 -10
  26. package/ide/antigravity/.agents/workflows/codeninja-design.md +61 -14
  27. package/ide/antigravity/.agents/workflows/codeninja-explain.md +59 -9
  28. package/ide/antigravity/.agents/workflows/codeninja-init.md +518 -21
  29. package/ide/antigravity/.agents/workflows/codeninja-integrate-api.md +451 -9
  30. package/ide/antigravity/.agents/workflows/codeninja-modularize.md +332 -9
  31. package/ide/antigravity/.agents/workflows/codeninja-optimize.md +124 -11
  32. package/ide/antigravity/.agents/workflows/codeninja-refactor.md +69 -16
  33. package/ide/antigravity/.agents/workflows/codeninja-review.md +85 -10
  34. package/ide/antigravity/.agents/workflows/codeninja-sync.md +957 -16
  35. package/ide/antigravity/.agents/workflows/codeninja-test.md +40 -13
  36. package/ide/antigravity/.agents/workflows/codeninja-validate-page.md +546 -9
  37. package/ide/claude-code/.claude/CLAUDE.md +99 -0
  38. package/ide/claude-code/.claude/agents/database-agent.md +535 -0
  39. package/ide/claude-code/.claude/agents/nodejs-agent.md +493 -0
  40. package/ide/claude-code/.claude/agents/reactjs-agent.md +267 -0
  41. package/ide/claude-code/.claude/commands/codeninja-api.md +104 -0
  42. package/ide/claude-code/.claude/commands/codeninja-audit.md +119 -0
  43. package/ide/claude-code/.claude/commands/codeninja-db-create.md +138 -0
  44. package/ide/claude-code/.claude/commands/codeninja-db-drop.md +109 -0
  45. package/ide/claude-code/.claude/commands/codeninja-db-index.md +103 -0
  46. package/ide/claude-code/.claude/commands/codeninja-db-modify.md +165 -0
  47. package/ide/claude-code/.claude/commands/codeninja-db-seed.md +104 -0
  48. package/ide/claude-code/.claude/commands/codeninja-db-sync.md +106 -0
  49. package/ide/claude-code/.claude/commands/codeninja-debug.md +99 -0
  50. package/ide/claude-code/.claude/commands/codeninja-design.md +68 -0
  51. package/ide/claude-code/.claude/commands/codeninja-explain.md +61 -0
  52. package/ide/claude-code/.claude/commands/codeninja-init.md +529 -0
  53. package/ide/claude-code/.claude/commands/codeninja-integrate-api.md +453 -0
  54. package/ide/claude-code/.claude/commands/codeninja-modularize.md +334 -0
  55. package/ide/claude-code/.claude/commands/codeninja-optimize.md +129 -0
  56. package/ide/claude-code/.claude/commands/codeninja-refactor.md +76 -0
  57. package/ide/claude-code/.claude/commands/codeninja-review.md +87 -0
  58. package/ide/claude-code/.claude/commands/codeninja-sync.md +964 -0
  59. package/ide/claude-code/.claude/commands/codeninja-test.md +45 -0
  60. package/ide/claude-code/.claude/commands/codeninja-validate-page.md +548 -0
  61. package/ide/cursor/.cursor/rules/01-global-orchestrator.mdc +40 -38
  62. package/ide/cursor/.cursor/rules/02-mcp-and-context.mdc +47 -31
  63. package/ide/cursor/.cursor/rules/03-api-builder.mdc +30 -58
  64. package/ide/cursor/.cursor/rules/04-nodejs-generation.mdc +58 -0
  65. package/ide/cursor/.cursor/rules/05-database.mdc +54 -0
  66. package/ide/cursor/.cursor/rules/06-reactjs.mdc +36 -0
  67. package/ide/cursor/.cursor/rules/07-reactjs-generation.mdc +49 -0
  68. package/ide/cursor/.cursor/rules/08-code-intelligence.mdc +56 -0
  69. package/ide/cursor/.cursor/rules/09-workflow-steps.mdc +53 -0
  70. package/ide/vscode/.github/copilot-instructions.md +69 -270
  71. package/ide/vscode/.vscode/instructions/code-intelligence.instructions.md +58 -0
  72. package/ide/vscode/.vscode/instructions/database.instructions.md +55 -0
  73. package/ide/vscode/.vscode/instructions/nodejs.instructions.md +77 -0
  74. package/ide/vscode/.vscode/instructions/reactjs.instructions.md +42 -0
  75. package/package.json +2 -2
  76. package/tasks/ask-hashing-library.task.md +31 -0
  77. package/tasks/ask-language-type.task.md +26 -0
  78. package/tasks/ask-new-module-name.task.md +13 -0
  79. package/tasks/ask-new-service-name.task.md +13 -0
  80. package/tasks/ask-old-module-name.task.md +15 -0
  81. package/tasks/ask-old-service-name.task.md +13 -0
  82. package/tasks/ask-orm-type.task.md +26 -0
  83. package/tasks/collect-seed-data.task.md +19 -0
  84. package/tasks/generate-app.task.md +42 -0
  85. package/tasks/generate-common.task.md +13 -0
  86. package/tasks/generate-constants.task.md +13 -0
  87. package/tasks/generate-database.task.md +32 -0
  88. package/tasks/generate-encryption.task.md +28 -0
  89. package/tasks/generate-fast-defaults.task.md +7 -0
  90. package/tasks/generate-hashing.task.md +180 -0
  91. package/tasks/generate-headerValidator.task.md +13 -0
  92. package/tasks/generate-ioRedis.task.md +20 -0
  93. package/tasks/generate-language-en.task.md +12 -0
  94. package/tasks/generate-logging.task.md +12 -0
  95. package/tasks/generate-model.task.md +74 -6
  96. package/tasks/generate-notification.task.md +12 -0
  97. package/tasks/generate-package-json.task.md +69 -0
  98. package/tasks/generate-prisma-client.task.md +56 -0
  99. package/tasks/generate-prisma-schema.task.md +71 -0
  100. package/tasks/generate-rateLimiter.task.md +20 -0
  101. package/tasks/generate-readme.task.md +24 -0
  102. package/tasks/generate-response.task.md +27 -0
  103. package/tasks/generate-route-manager.task.md +32 -0
  104. package/tasks/generate-route.task.md +37 -0
  105. package/tasks/generate-swagger.task.md +8 -0
  106. package/tasks/generate-template.task.md +12 -0
  107. package/tasks/generate-tsconfig.task.md +38 -0
  108. package/tasks/generate-validator.task.md +31 -0
  109. package/ide/cursor/.cursor/rules/04-database.mdc +0 -87
  110. package/ide/cursor/.cursor/rules/05-reactjs.mdc +0 -83
  111. package/ide/cursor/.cursor/rules/06-code-intelligence.mdc +0 -112
@@ -1,11 +1,109 @@
1
+ This workflow runs when user invokes /codeninja:db:drop
2
+
1
3
  ---
2
- slash_command: /codeninja:db:drop
3
- personas: [global-orchestrator, database-architect]
4
- skills: [mcp-and-context, database]
5
- description: Drop a table with a DROP migration file
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.
6
11
  ---
7
- # /codeninja:db:drop
8
- Delegates to: `.codeninja/commands/db-drop-table.workflow.md`
9
- Before: `context_read`, `migration_next_number`.
10
- WARN user: "This is destructive. Confirm you want to DROP [table]?"
11
- After: `context_write` remove table from context.db.schema.
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
+
71
+ > **Multi-agent:** Delegate to `database-architect` via Task invocation for parallel execution.
72
+ > Read `.codeninja/tasks/` before generating the drop migration file.
73
+
74
+ 6. Delegate to `database-agent`:
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`
@@ -1,11 +1,102 @@
1
+ This workflow runs when user invokes /codeninja:db:index
2
+
1
3
  ---
2
- slash_command: /codeninja:db:index
3
- personas: [global-orchestrator, database-architect]
4
- skills: [mcp-and-context, database]
5
- description: Add a new index to an existing table with migration file
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.
6
11
  ---
7
- # /codeninja:db:index
8
- Delegates to: `.codeninja/commands/db-add-index.workflow.md`
9
- Before: `context_read`, `migration_next_number`.
10
- Show existing indexes from context.db.schema before suggesting new ones.
11
- After: `context_write` with updated index list.
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
+ > **Multi-agent:** Delegate to `database-architect` via Task invocation for parallel execution.
74
+ > Read `.codeninja/tasks/` before generating the index.
75
+
76
+ 8. Delegate to `database-agent`:
77
+ - If table file placement → append to `<repo_root>/database/<db_type>/migrations/<table_file>.sql`
78
+ - If shared file → append to `<repo_root>/database/<db_type>/migrations/111-setup-database-indexes.sql`
79
+
80
+ Generated SQL:
81
+ ```sql
82
+ -- Standard
83
+ CREATE INDEX <index_name> ON public.<table_name> (<col> [DESC], ...);
84
+
85
+ -- Partial
86
+ CREATE INDEX <index_name> ON public.<table_name> (<col> [DESC], ...)
87
+ WHERE <where_clause>;
88
+ ```
89
+
90
+ With standard header comment:
91
+ ```sql
92
+ --
93
+ -- Name: <index_name>; Type: INDEX; Schema: public
94
+ --
95
+ ```
96
+
97
+ 9. Run task: `write-context`
98
+ - Append index name to `context.db.schema.tables[<table>].indexes`
99
+ - Append to `context.db.schema.change_log`
100
+ - Clear `context.current_db`
101
+
102
+ 10. Run task: `show-final-summary`
@@ -1,11 +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: Add, rename, or drop a column via ALTER migration
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
- # /codeninja:db:modify
8
- Delegates to: `.codeninja/commands/db-modify-table.workflow.md`
9
- Before: `context_read`, `migration_next_number`.
10
- Show existing columns from context.db.schema before asking which to change.
11
- After: `context_write` with updated column list.
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
+ > **Multi-agent:** Delegate to `database-architect` via Task invocation for parallel execution.
135
+ > Read `.codeninja/tasks/` before generating each migration file.
136
+
137
+ 9. Delegate to `database-agent`:
138
+ - Generate: `<repo_root>/database/<db_type>/migrations/<number>-alter-tbl-<n>-<description>.sql`
139
+
140
+ Full file structure:
141
+ ```sql
142
+ -- Alter tbl_<table>: <description>
143
+ -- Migration: <number>-alter-tbl-<n>-<description>.sql
144
+ -- Generated: <ISO date>
145
+
146
+ BEGIN;
147
+
148
+ ALTER TABLE public.<table_name>
149
+ <operation>;
150
+
151
+ -- Optional: COMMENT ON COLUMN if enum/flag column
152
+ -- Optional: CREATE INDEX if new column needs one
153
+
154
+ COMMIT;
155
+ ```
156
+
157
+ - Update: `database/<db_type>/create-schema.sql`
158
+
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`
163
+
164
+ 11. Run task: `show-final-summary`
@@ -1,10 +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 or update seed data for 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
- # /codeninja:db:seed
8
- Delegates to: `.codeninja/commands/db-seed.workflow.md`
9
- Before: `context_read` — load context.db.schema for real column names.
10
- After: `context_write` to record seed file location.
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
+ > **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,12 +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 migration files and rebuild context.db.schema
6
- ---
7
- # /codeninja:db:sync
8
- Delegates to: `.codeninja/commands/db-sync.workflow.md`
9
- Before: `context_read`, `fs_list` all migration files.
10
- Compare files on disk vs context.db.schema — surface all gaps.
11
- User approves before context is updated.
12
- After: `context_write` with fully rebuilt context.db.schema.
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
+ For each discovered table (not dropped):
64
+ - Compare with existing `context.db.schema.tables[<table>]`
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
69
+
70
+ For dropped tables:
71
+ - If still in `context.db.schema.tables` → move to change_log snapshot
72
+ - Remove from active tables list
73
+
74
+ ---
75
+
76
+ ### Phase 4 — Rebuild create-schema.sql
77
+ - Re-read all file names in correct numeric order
78
+ - Rewrite `create-schema.sql` to match actual files on disk
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)
81
+
82
+ ---
83
+
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