codeninja 2.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 (140) hide show
  1. package/.gitattributes +11 -0
  2. package/README.md +293 -0
  3. package/agent/database-agent.md +504 -0
  4. package/agent/designs/README.md +10 -0
  5. package/agent/global-agent.md +236 -0
  6. package/agent/nodejs-agent.md +406 -0
  7. package/agent/reactjs-agent.md +260 -0
  8. package/cli.js +352 -0
  9. package/commands/audit.workflow.md +111 -0
  10. package/commands/create-api.workflow.md +99 -0
  11. package/commands/db-add-index.workflow.md +97 -0
  12. package/commands/db-create-table.workflow.md +132 -0
  13. package/commands/db-drop-table.workflow.md +103 -0
  14. package/commands/db-modify-table.workflow.md +159 -0
  15. package/commands/db-seed.workflow.md +99 -0
  16. package/commands/db-sync.workflow.md +100 -0
  17. package/commands/design.workflow.md +66 -0
  18. package/commands/initialize-project.workflow.md +500 -0
  19. package/commands/integrate-api.workflow.md +448 -0
  20. package/commands/modularize.workflow.md +329 -0
  21. package/commands/refactor.workflow.md +70 -0
  22. package/commands/sync.workflow.md +962 -0
  23. package/commands/test.workflow.md +40 -0
  24. package/commands/validate-page.workflow.md +543 -0
  25. package/mcp-server.js +842 -0
  26. package/package.json +24 -0
  27. package/tasks/README.md +283 -0
  28. package/tasks/add-health-route.task.md +103 -0
  29. package/tasks/ask-api-integration-scope.task.md +34 -0
  30. package/tasks/ask-api-key.task.md +23 -0
  31. package/tasks/ask-api-version.task.md +28 -0
  32. package/tasks/ask-client-type.task.md +24 -0
  33. package/tasks/ask-column-enum-values.task.md +51 -0
  34. package/tasks/ask-column-is-enum.task.md +39 -0
  35. package/tasks/ask-column-name.task.md +39 -0
  36. package/tasks/ask-column-position.task.md +39 -0
  37. package/tasks/ask-column-type.task.md +59 -0
  38. package/tasks/ask-database-config.task.md +66 -0
  39. package/tasks/ask-database-host.task.md +16 -0
  40. package/tasks/ask-database-name.task.md +18 -0
  41. package/tasks/ask-database-port.task.md +23 -0
  42. package/tasks/ask-database-type.task.md +30 -0
  43. package/tasks/ask-database-user.task.md +14 -0
  44. package/tasks/ask-design-description.task.md +16 -0
  45. package/tasks/ask-design-target.task.md +24 -0
  46. package/tasks/ask-encrypted-transport.task.md +25 -0
  47. package/tasks/ask-encryption-iv.task.md +23 -0
  48. package/tasks/ask-encryption-key.task.md +23 -0
  49. package/tasks/ask-feature-name.task.md +20 -0
  50. package/tasks/ask-http-method.task.md +21 -0
  51. package/tasks/ask-index-columns.task.md +46 -0
  52. package/tasks/ask-index-file-placement.task.md +33 -0
  53. package/tasks/ask-index-sort-order.task.md +37 -0
  54. package/tasks/ask-index-type.task.md +42 -0
  55. package/tasks/ask-init-mode.task.md +28 -0
  56. package/tasks/ask-linked-service.task.md +57 -0
  57. package/tasks/ask-modify-operation.task.md +36 -0
  58. package/tasks/ask-modularize-scope.task.md +31 -0
  59. package/tasks/ask-module-name.task.md +30 -0
  60. package/tasks/ask-new-column-name.task.md +21 -0
  61. package/tasks/ask-new-table-name.task.md +22 -0
  62. package/tasks/ask-old-column-name.task.md +22 -0
  63. package/tasks/ask-package-author.task.md +16 -0
  64. package/tasks/ask-package-name.task.md +23 -0
  65. package/tasks/ask-page-path.task.md +40 -0
  66. package/tasks/ask-primary-table.task.md +30 -0
  67. package/tasks/ask-project-figma.task.md +71 -0
  68. package/tasks/ask-project-info-doc.task.md +57 -0
  69. package/tasks/ask-project-scope-of-work.task.md +57 -0
  70. package/tasks/ask-project-type.task.md +24 -0
  71. package/tasks/ask-react-target-service.task.md +32 -0
  72. package/tasks/ask-redis-config.task.md +42 -0
  73. package/tasks/ask-redis-host.task.md +16 -0
  74. package/tasks/ask-redis-port.task.md +18 -0
  75. package/tasks/ask-refactor-type.task.md +26 -0
  76. package/tasks/ask-requires-auth.task.md +22 -0
  77. package/tasks/ask-response-mode.task.md +38 -0
  78. package/tasks/ask-route-description.task.md +20 -0
  79. package/tasks/ask-route-path.task.md +29 -0
  80. package/tasks/ask-seed-row-values.task.md +42 -0
  81. package/tasks/ask-seed-rows-count.task.md +22 -0
  82. package/tasks/ask-service-description.task.md +16 -0
  83. package/tasks/ask-service-name.task.md +27 -0
  84. package/tasks/ask-service-port.task.md +24 -0
  85. package/tasks/ask-supported-languages.task.md +40 -0
  86. package/tasks/ask-table-file-number.task.md +36 -0
  87. package/tasks/ask-table-indexes.task.md +47 -0
  88. package/tasks/ask-table-name.task.md +32 -0
  89. package/tasks/ask-table-needs-soft-delete.task.md +29 -0
  90. package/tasks/ask-table-needs-status.task.md +30 -0
  91. package/tasks/ask-table-purpose.task.md +28 -0
  92. package/tasks/ask-table-seed-data.task.md +44 -0
  93. package/tasks/ask-target-service.task.md +32 -0
  94. package/tasks/ask-test-type.task.md +20 -0
  95. package/tasks/ask-validation-library.task.md +38 -0
  96. package/tasks/detect-repository-state.task.md +92 -0
  97. package/tasks/generate-app.task.md +146 -0
  98. package/tasks/generate-common.task.md +330 -0
  99. package/tasks/generate-constants.task.md +123 -0
  100. package/tasks/generate-database.task.md +168 -0
  101. package/tasks/generate-docker-compose.task.md +298 -0
  102. package/tasks/generate-dockerfile.task.md +126 -0
  103. package/tasks/generate-dockerignore.task.md +123 -0
  104. package/tasks/generate-enc-dec-html.task.md +127 -0
  105. package/tasks/generate-enc-dec-php.task.md +145 -0
  106. package/tasks/generate-encryption.task.md +159 -0
  107. package/tasks/generate-fast-defaults.task.md +68 -0
  108. package/tasks/generate-gitignore.task.md +79 -0
  109. package/tasks/generate-headerValidator.task.md +377 -0
  110. package/tasks/generate-ide-configs.task.md +114 -0
  111. package/tasks/generate-ioRedis.task.md +120 -0
  112. package/tasks/generate-language-en.task.md +155 -0
  113. package/tasks/generate-logging.task.md +257 -0
  114. package/tasks/generate-model.task.md +180 -0
  115. package/tasks/generate-notification.task.md +251 -0
  116. package/tasks/generate-package-json.task.md +114 -0
  117. package/tasks/generate-rateLimiter.task.md +125 -0
  118. package/tasks/generate-react-api-client.task.md +169 -0
  119. package/tasks/generate-react-api-handler.task.md +102 -0
  120. package/tasks/generate-react-app-jsx.task.md +56 -0
  121. package/tasks/generate-react-dockerfile.task.md +175 -0
  122. package/tasks/generate-react-env.task.md +58 -0
  123. package/tasks/generate-react-gitignore.task.md +49 -0
  124. package/tasks/generate-react-htaccess.task.md +54 -0
  125. package/tasks/generate-react-index-html.task.md +53 -0
  126. package/tasks/generate-react-index-jsx.task.md +51 -0
  127. package/tasks/generate-react-package-json.task.md +77 -0
  128. package/tasks/generate-react-welcome-page.task.md +71 -0
  129. package/tasks/generate-readme.task.md +160 -0
  130. package/tasks/generate-response.task.md +202 -0
  131. package/tasks/generate-route-manager.task.md +173 -0
  132. package/tasks/generate-route.task.md +203 -0
  133. package/tasks/generate-swagger.task.md +290 -0
  134. package/tasks/generate-tbl-user-deviceinfo.task.md +75 -0
  135. package/tasks/generate-template.task.md +129 -0
  136. package/tasks/generate-validator.task.md +122 -0
  137. package/tasks/show-db-table-summary.task.md +66 -0
  138. package/tasks/show-final-summary.task.md +108 -0
  139. package/tasks/show-init-summary.task.md +257 -0
  140. package/tasks/write-context.task.md +314 -0
@@ -0,0 +1,99 @@
1
+ ---
2
+ type: workflow
3
+ name: db-seed
4
+ command: "@db:seed"
5
+ description: >
6
+ Add or update seed data for a table. For reference/master data tables,
7
+ seed goes inside the table setup file. For all others, a standalone seed
8
+ file is generated in the seeds/ folder.
9
+ ---
10
+
11
+ # Workflow: @db:seed
12
+
13
+ ## Goal
14
+ Generate properly formatted INSERT seed data for a table. Determine whether
15
+ seed belongs in the table file or a standalone seed file.
16
+
17
+ ## Rules
18
+ - Passwords in seed data must be pre-encrypted — agent must ask for encrypted value
19
+ - Never generate plaintext passwords in any file
20
+ - Multi-row INSERT format always (single INSERT with multiple value tuples)
21
+ - Seed file naming: `<repo_root>/database/<db_type>/seeds/<table_name>_seed.sql`
22
+
23
+ ---
24
+
25
+ ## Step-by-Step Execution
26
+
27
+ ### Phase 1 — Target
28
+ 1. Run task: `ask-table-name`
29
+ - List tables from `context.db.schema.tables`
30
+ - Stores: `context.current_db.table_name`
31
+
32
+ ---
33
+
34
+ ### Phase 2 — Seed File Type
35
+ 2. Agent checks if table is a reference/master table:
36
+ - Reference tables (seed goes IN setup file): tbl_country, tbl_app_content,
37
+ tbl_strategy_modules, tbl_admin, any lookup table
38
+ - All others: standalone seed file in seeds/
39
+
40
+ Ask: "Where should this seed data go?"
41
+ Options:
42
+ 1. Append to the table's setup file (for reference/master data)
43
+ 2. Create a standalone seed file in seeds/ (for dev/test data)
44
+
45
+ Stores: `context.current_db.seed_target`
46
+
47
+ ---
48
+
49
+ ### Phase 3 — Data Collection
50
+ 3. Show column list for the table from context.
51
+
52
+ 4. Run task: `ask-seed-rows-count`
53
+ - Ask: "How many rows do you want to seed?"
54
+ - Stores: `context.current_db.seed_count`
55
+
56
+ 5. For each row (repeat seed_count times):
57
+ Run task: `ask-seed-row-values`
58
+ - For each column (excluding `id` and `created_at` — auto-generated):
59
+ - Ask the value one column at a time
60
+ - If column is `password` → warn: "Enter the encrypted/hashed value only. Never store plaintext."
61
+ - If column has CHECK constraint → show allowed values
62
+ - If column has DEFAULT → offer to use default (user can press enter to skip)
63
+ - Stores: appends to `context.current_db.seed_rows[]`
64
+
65
+ ---
66
+
67
+ ### Phase 4 — Generate
68
+ 6. Show full INSERT preview to user
69
+ - Ask: "Generate this seed data? (yes / no)"
70
+
71
+ 7. Delegate to `database-agent`:
72
+
73
+ If appending to setup file:
74
+ - Read existing setup file
75
+ - Append after the GRANT line:
76
+ ```sql
77
+ INSERT INTO public.<table_name> (<col1>, <col2>, ...) VALUES
78
+ (<val1a>, <val2a>, ...),
79
+ (<val1b>, <val2b>, ...);
80
+ ```
81
+
82
+ If standalone seed file:
83
+ - Generate: `database/<db_type>/seeds/<table_name>_seed.sql`
84
+ ```sql
85
+ -- Seed data for <table_name>
86
+ -- Environment: development
87
+ -- Generated: <ISO date>
88
+
89
+ INSERT INTO public.<table_name> (<col1>, <col2>, ...) VALUES
90
+ (<val1a>, <val2a>, ...),
91
+ (<val1b>, <val2b>, ...);
92
+ ```
93
+
94
+ 8. Run task: `write-context`
95
+ - Append to `context.db.schema.change_log`:
96
+ `{ "type": "seed_added", "table": "<n>", "rows": <count> }`
97
+ - Clear `context.current_db`
98
+
99
+ 9. Run task: `show-final-summary`
@@ -0,0 +1,100 @@
1
+ ---
2
+ type: workflow
3
+ name: db-sync
4
+ command: "@db:sync"
5
+ description: >
6
+ Scan all migration files in the database folder and rebuild context.db.schema
7
+ from actual file contents. Safe to run at any time. Never destructive —
8
+ only adds or updates, never removes existing context entries.
9
+ ---
10
+
11
+ # Workflow: @db:sync
12
+
13
+ ## Goal
14
+ Make context.db.schema an accurate reflection of what is actually on disk.
15
+ Parse every migration file in order and reconstruct the full schema state.
16
+
17
+ ---
18
+
19
+ ## Step-by-Step Execution
20
+
21
+ ### Phase 1 — Locate Files
22
+ 1. Read `context.db.type` to find the correct folder:
23
+ `<repo_root>/database/<db_type>/migrations/`
24
+ The database folder is always at repository root, never inside
25
+ a service folder.
26
+ 2. List all `.sql` files in that folder
27
+ 3. Sort them in numeric order by filename prefix (1, 2, 3... 111)
28
+ 4. Separate into categories:
29
+ - setup files: `*-setup-tbl-*.sql`
30
+ - alter files: `*-alter-tbl-*.sql`
31
+ - drop files: `*-drop-tbl-*.sql`
32
+ - index file: `111-setup-database-indexes.sql`
33
+
34
+ ---
35
+
36
+ ### Phase 2 — Parse Each File
37
+ For each setup file (in order):
38
+ - Extract table name from CREATE TABLE statement
39
+ - Extract all column names and types
40
+ - Extract CHECK constraints (enum values)
41
+ - Extract COMMENT ON COLUMN lines (enum descriptions)
42
+ - Extract per-file CREATE INDEX lines
43
+ - Note if table has `status`, `is_deleted`, `created_at`
44
+
45
+ For each alter file (in order after its setup file):
46
+ - Parse ADD COLUMN → add to that table's columns
47
+ - Parse RENAME COLUMN → update column name, record in change_log
48
+ - Parse DROP COLUMN → remove from columns
49
+ - Parse ADD CONSTRAINT → update column's constraint info
50
+
51
+ For each drop file:
52
+ - Mark that table as dropped in the scan result
53
+
54
+ For the index file:
55
+ - Parse all CREATE INDEX statements
56
+ - Associate each index with its table
57
+
58
+ ---
59
+
60
+ ### Phase 3 — Rebuild Context
61
+ For each discovered table (not dropped):
62
+ - Compare with existing `context.db.schema.tables[<table>]`
63
+ - Add any tables not already in context
64
+ - Add any columns not already tracked
65
+ - Add any indexes not already tracked
66
+ - For renames found in ALTER files → append to change_log if not already there
67
+
68
+ For dropped tables:
69
+ - If still in `context.db.schema.tables` → move to change_log snapshot
70
+ - Remove from active tables list
71
+
72
+ ---
73
+
74
+ ### Phase 4 — Rebuild create-schema.sql
75
+ - Re-read all file names in correct numeric order
76
+ - Rewrite `create-schema.sql` to match actual files on disk
77
+ - Report any \i entries that are in create-schema.sql but missing from disk (stale)
78
+ - Report any files on disk not in create-schema.sql (missing)
79
+
80
+ ---
81
+
82
+ ### Phase 5 — Write and Report
83
+ 1. Run task: `write-context` with all schema deltas
84
+ 2. Display sync report:
85
+ ```
86
+ @db:sync complete
87
+ ─────────────────────────────────────────
88
+ Migration files scanned : [n]
89
+ Tables discovered : [n] ([x] new)
90
+ Columns synced : [n] ([x] new)
91
+ Indexes synced : [n] ([x] new)
92
+ Renames detected : [n]
93
+ Dropped tables : [n]
94
+ create-schema.sql : updated
95
+ Context gaps filled : [n]
96
+ ─────────────────────────────────────────
97
+ ```
98
+ 3. If any conflicts found (e.g. column exists in context with different type than file):
99
+ - List each conflict
100
+ - Ask user which to keep (file or context) — one at a time
@@ -0,0 +1,66 @@
1
+ ---
2
+ type: workflow
3
+ name: design
4
+ description: >
5
+ Plan a feature, API contract, or database change before writing any code.
6
+ Produces a design document and optionally updates context with the planned
7
+ schema or routes for other agents to reference.
8
+ ---
9
+
10
+ # Workflow: @design
11
+
12
+ ## Goal
13
+ Think before coding. Produce a structured design plan that becomes the
14
+ contract for `@create-api`, `@initialize-project`, or manual implementation.
15
+
16
+ ## Rules
17
+ - No files are generated unless user explicitly confirms
18
+ - Design output is stored in `.codeninja/agent/designs/<feature_name>.design.md`
19
+ - Approved designs update context with planned routes and schema
20
+
21
+ ---
22
+
23
+ ## Step-by-Step Execution
24
+
25
+ ### Phase 1 — Scope
26
+ 1. Run task: `ask-design-target`
27
+ - Options: new feature, new API endpoint, database change, full module
28
+ - Stores: `context.current_design.type`
29
+
30
+ 2. Run task: `ask-feature-name`
31
+ - Stores: `context.current_design.feature_name`
32
+
33
+ 3. Run task: `ask-design-description`
34
+ - Free text: what should this feature do?
35
+ - Stores: `context.current_design.description`
36
+
37
+ ---
38
+
39
+ ### Phase 2 — Database Design (if applicable)
40
+ 4. If design involves data storage:
41
+ - Delegate to `database-agent`
42
+ - Design table structure, column types, indexes, relationships
43
+ - Present schema proposal to user for feedback
44
+ - Allow user to request changes (one change at a time)
45
+
46
+ ---
47
+
48
+ ### Phase 3 — API Design (if applicable)
49
+ 5. If design involves API endpoints:
50
+ - Delegate to `nodejs-agent`
51
+ - Propose: method, path, request body, response shape, auth requirement
52
+ - Present to user for feedback
53
+
54
+ ---
55
+
56
+ ### Phase 4 — Output
57
+ 6. Generate `.codeninja/agent/designs/<feature_name>.design.md` containing:
58
+ - Feature summary
59
+ - DB schema proposal (tables, columns)
60
+ - API contracts (method, path, request, response)
61
+ - Open questions / decisions needed
62
+
63
+ 7. Ask: "Save this design and mark planned routes/schema in context? (yes/no)"
64
+ 8. If yes → run task: `write-context` with operation = "design"
65
+ Then call: context_clear_scratchpad with keys: ["current_design"]
66
+ 9. Run task: `show-final-summary`