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,314 @@
1
+ ---
2
+ type: task
3
+ name: write-context
4
+ ---
5
+
6
+ # File: .codeninja/context/context.json
7
+
8
+ ## Purpose
9
+ Persists all in-memory context accumulated during the current workflow
10
+ to disk. This file is the project's single source of truth — it must
11
+ be written after every command that changes project state. If this
12
+ file does not exist yet, create it. If it exists, merge the new values
13
+ into it without removing existing entries.
14
+
15
+ ---
16
+
17
+ ## CRITICAL — How to Write This File
18
+
19
+ Call MCP tool `context_write` with two parameters:
20
+ - `updates` — the object containing all changes for this operation,
21
+ as defined in the Write Rules section below
22
+ - `operation` — the command name e.g. "initialize-project",
23
+ "create-api", "db:create-table"
24
+
25
+ The MCP tool handles everything automatically:
26
+ reading the existing file, deep-merging updates, incrementing
27
+ context_version, setting timestamps, and writing the file.
28
+
29
+ After context_write succeeds, call MCP tool `context_clear_scratchpad`
30
+ with the relevant current_* key for this operation.
31
+ Example: after @initialize-project → clear ["current_init"]
32
+ Example: after @create-api → clear ["current_api"]
33
+
34
+ Do NOT write context.json any other way.
35
+ Do NOT output context.json as a code block.
36
+ Do NOT attempt to merge or write manually.
37
+
38
+ ---
39
+
40
+ ## Rules
41
+ - NEVER delete existing entries — only add or update
42
+ - NEVER clear `change_log` or `db.schema.change_log` — append only
43
+ - NEVER leave `current_*` keys populated after a workflow completes —
44
+ always clear the relevant one
45
+ - ALWAYS read the existing file first before writing — never blindly
46
+ overwrite with only the new data
47
+ - ALWAYS increment `context_version` by 1 on every write
48
+ - ALWAYS set `last_command_at` = ISO now on every write
49
+
50
+ ---
51
+
52
+ ## Stale Scratchpad Recovery
53
+
54
+ After loading context.json in step 1 above, check all `current_*`
55
+ keys in the loaded object.
56
+
57
+ If any `current_*` key is non-empty AND `last_command_at` is more
58
+ than 10 minutes ago → the previous workflow likely failed mid-run.
59
+
60
+ Inform the user:
61
+ "⚠ Found incomplete workflow state from a previous session:
62
+ current_[type] has data from [last_command_at].
63
+ This may be from an interrupted [last_command] operation.
64
+
65
+ Options:
66
+ 1. Clear it — discard the incomplete state and start fresh
67
+ 2. Inspect it — show me what was in progress"
68
+
69
+ If user selects Clear → set the non-empty `current_*` key to `{}`
70
+ and run write-context to persist the cleanup.
71
+ If user selects Inspect → display the `current_*` key contents
72
+ and let the user decide what to do.
73
+
74
+ Never silently discard stale scratchpad data.
75
+ Never silently proceed with stale scratchpad data.
76
+ Always surface it and let the user decide.
77
+
78
+ ---
79
+
80
+ ## Change Log Separation Rule
81
+
82
+ - `context.change_log` (top-level): records COMMAND-level events only.
83
+ Who ran what command, when, and which files were affected.
84
+ Example: "initialize-project created auth service"
85
+
86
+ - `context.db.schema.change_log`: records SCHEMA-level events only.
87
+ Column renames, table drops, index additions — the structural history
88
+ that agents need to reconstruct the DB state.
89
+ Example: "column_renamed from user_name to full_name in tbl_users"
90
+
91
+ Never write the same event to both. DB operations append to
92
+ db.schema.change_log only. The top-level change_log gets one summary
93
+ entry per command run.
94
+
95
+ ---
96
+
97
+ ## Write Rules Per Operation
98
+
99
+ ### After @initialize-project
100
+ - Set `project_name` = `current_init.service_name`
101
+ (top-level key — set on first init, kept as-is on subsequent services)
102
+ - Set `initialized_at` = ISO now if not already set
103
+ (only set on the very first @initialize-project run)
104
+ - Set `last_command` = `"initialize-project"`
105
+ - Set `services.<service_name>` with values from `current_init`
106
+ according to project type:
107
+
108
+ **If `type == "nodejs"`** — store:
109
+ `type, port, description, package_name, author,`
110
+ `client_type, encrypted_transport, supported_languages, init_mode,`
111
+ `encryption_key, encryption_iv, api_key,`
112
+ `initialized_at = ISO now`
113
+
114
+ **If `type == "reactjs"`** — store:
115
+ `type, port, description, package_name, author,`
116
+ `linked_service, linked_service_port, init_mode,`
117
+ `initialized_at = ISO now`
118
+ Do NOT store `encryption_key`, `encryption_iv`, or `api_key` on the
119
+ reactjs service entry — those live only on the linked nodejs service.
120
+ - Append to top-level `change_log`:
121
+ `{ timestamp, command: "initialize-project", action: "Service <name> initialized", affected_files: [] }`
122
+ - Set `current_init` = `{}`
123
+ - Set `last_updated_at` = ISO now
124
+ - Increment `context_version` by 1
125
+ - Set `last_command_at` = ISO now
126
+
127
+ ### After @create-api
128
+ - Append route to `services.<name>.modules.<Module>.routes`
129
+ - Append to `api_routes`
130
+ - Append to `change_log`: "Route [METHOD] [path] added to [service]"
131
+ - Set `current_api` = `{}`
132
+ - Set `last_updated_at` = ISO now
133
+ - Increment `context_version` by 1
134
+ - Set `last_command_at` = ISO now
135
+
136
+ ### After @db:create-table
137
+ - Append table to `db.schema.tables[<table_name>]` with full column list
138
+ - Append to `db.schema.change_log`: `{ type: "table_created", table, file }`
139
+ - Append to top-level `change_log`
140
+ - Set `current_db` = `{}`
141
+ - Set `last_updated_at` = ISO now
142
+ - Increment `context_version` by 1
143
+ - Set `last_command_at` = ISO now
144
+
145
+ ### After @db:modify-table (add column)
146
+ - Append new column to `db.schema.tables[<table>].columns`
147
+ - Append to `db.schema.change_log`: `{ type: "column_added", ... }`
148
+ - Set `current_db` = `{}`
149
+ - Set `last_updated_at` = ISO now
150
+ - Increment `context_version` by 1
151
+ - Set `last_command_at` = ISO now
152
+
153
+ ### After @db:modify-table (rename column)
154
+ - Update column name in `db.schema.tables[<table>].columns`
155
+ - Append to `db.schema.change_log`: `{ type: "column_renamed", from, to }`
156
+ - Set `current_db` = `{}`
157
+ - Set `last_updated_at` = ISO now
158
+ - Increment `context_version` by 1
159
+ - Set `last_command_at` = ISO now
160
+
161
+ ### After @db:modify-table (drop column)
162
+ - Remove column from `db.schema.tables[<table>].columns`
163
+ - Append to `db.schema.change_log`: `{ type: "column_dropped", snapshot: <col_def> }`
164
+ - Set `current_db` = `{}`
165
+ - Set `last_updated_at` = ISO now
166
+ - Increment `context_version` by 1
167
+ - Set `last_command_at` = ISO now
168
+
169
+ ### After @db:add-index
170
+ - Append index name to `db.schema.tables[<table>].indexes`
171
+ - Append to `db.schema.change_log`: `{ type: "index_added", ... }`
172
+ - Set `current_db` = `{}`
173
+ - Set `last_updated_at` = ISO now
174
+ - Increment `context_version` by 1
175
+ - Set `last_command_at` = ISO now
176
+
177
+ ### After @db:drop-table
178
+ - Save full table snapshot to change_log entry before removing
179
+ - Remove table from `db.schema.tables`
180
+ - Append to `db.schema.change_log`: `{ type: "table_dropped", snapshot: {...} }`
181
+ - Set `current_db` = `{}`
182
+ - Set `last_updated_at` = ISO now
183
+ - Increment `context_version` by 1
184
+ - Set `last_command_at` = ISO now
185
+
186
+ ### After @db:seed
187
+ - Append to `db.schema.change_log`: `{ type: "seed_added", table, rows: n }`
188
+ - Set `current_db` = `{}`
189
+ - Set `last_updated_at` = ISO now
190
+ - Increment `context_version` by 1
191
+ - Set `last_command_at` = ISO now
192
+
193
+ ### After @sync / @db:sync
194
+ - Merge all discovered data — never overwrite existing entries
195
+ - Append gap-fill entries to relevant change_log arrays
196
+ - Set `last_updated_at` = ISO now
197
+ - Increment `context_version` by 1
198
+ - Set `last_command_at` = ISO now
199
+
200
+ ### After @refactor
201
+ - Update the renamed key in its location
202
+ - Append to top-level `change_log` with before/after values
203
+ - For column renames: also append to `db.schema.change_log`
204
+ - Set `current_refactor` = `{}`
205
+ - Set `last_updated_at` = ISO now
206
+ - Increment `context_version` by 1
207
+ - Set `last_command_at` = ISO now
208
+
209
+ ### After @design (approved)
210
+ - Append to `designs` array with `status: "planned"`
211
+ - Set `current_design` = `{}`
212
+ - Set `last_updated_at` = ISO now
213
+ - Increment `context_version` by 1
214
+ - Set `last_command_at` = ISO now
215
+
216
+ ### After @integrate-api / @modularize / @validate-page
217
+ - Set `current_action` = `{}`
218
+
219
+ ### After @test
220
+ - Append to `context.services[<n>].tests`: `{ module, type, file, timestamp }`
221
+ - Set `current_test` = `{}`
222
+ - Set `last_updated_at` = ISO now
223
+ - Increment `context_version` by 1
224
+ - Set `last_command_at` = ISO now
225
+
226
+ ---
227
+
228
+ ## current_* Namespace Rules
229
+ - The `current_*` keys are scratchpad only — in-progress workflow state
230
+ - ALWAYS clear the relevant `current_*` key after a workflow completes
231
+ - NEVER read stale `current_*` data from a previous workflow run
232
+ - If a workflow is aborted mid-way, clear its `current_*` key and
233
+ run write-context to persist the cleanup before exiting
234
+ - If a `current_*` key is non-empty at activation time and
235
+ `last_command_at` is more than 10 minutes old → follow the
236
+ Stale Scratchpad Recovery procedure above
237
+
238
+ ---
239
+
240
+ ## Empty Schema (use when context.json does not exist yet)
241
+ ```json
242
+ {
243
+ "context_version": 0,
244
+ "project_name": "",
245
+ "initialized_at": "",
246
+ "last_updated_at": "",
247
+ "last_command": "",
248
+ "last_command_at": "",
249
+ "repository_state": "",
250
+ "has_context_file": false,
251
+ "detected_services": [],
252
+ "detected_db": false,
253
+ "project_info": {
254
+ "has_doc": false,
255
+ "doc_url": "",
256
+ "doc_source": "",
257
+ "doc_content": "",
258
+ "has_sow": false,
259
+ "sow_url": "",
260
+ "sow_source": "",
261
+ "sow_content": "",
262
+ "has_figma": false,
263
+ "figma_url": "",
264
+ "figma_accessible": false,
265
+ "figma_screens": "",
266
+ "summary": "",
267
+ "detected_entities": [],
268
+ "from_doc": {
269
+ "project_name": "",
270
+ "domain": "",
271
+ "purpose": "",
272
+ "features": [],
273
+ "entities": [],
274
+ "tech_preferences": []
275
+ },
276
+ "from_sow": {
277
+ "phases": [],
278
+ "deliverables": [],
279
+ "apis_expected": [],
280
+ "tables_expected": [],
281
+ "integrations": [],
282
+ "constraints": [],
283
+ "timeline": ""
284
+ },
285
+ "from_figma": {
286
+ "screens": [],
287
+ "components_hinted": [],
288
+ "color_theme": ""
289
+ }
290
+ },
291
+ "db": {
292
+ "type": "",
293
+ "name": "",
294
+ "host": "",
295
+ "port": 0,
296
+ "user": "",
297
+ "schema": {
298
+ "tables": {},
299
+ "change_log": []
300
+ }
301
+ },
302
+ "services": {},
303
+ "api_routes": [],
304
+ "designs": [],
305
+ "change_log": [],
306
+ "current_init": {},
307
+ "current_api": {},
308
+ "current_action": {},
309
+ "current_refactor": {},
310
+ "current_design": {},
311
+ "current_test": {},
312
+ "current_db": {}
313
+ }
314
+ ```