ndomo 0.1.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 (247) hide show
  1. package/.bun-version +1 -0
  2. package/.dockerignore +79 -0
  3. package/.editorconfig +18 -0
  4. package/.env.example +19 -0
  5. package/.github/CODEOWNERS +8 -0
  6. package/.github/ISSUE_TEMPLATE/bug_report.yml +62 -0
  7. package/.github/ISSUE_TEMPLATE/config.yml +2 -0
  8. package/.github/ISSUE_TEMPLATE/feature_request.yml +34 -0
  9. package/.github/dependabot.yml +36 -0
  10. package/.github/pull_request_template.md +24 -0
  11. package/.github/release.yml +30 -0
  12. package/.github/workflows/gitleaks.yml +28 -0
  13. package/.github/workflows/release-please.yml +27 -0
  14. package/.github/workflows/smoke.yml +29 -0
  15. package/.husky/commit-msg +1 -0
  16. package/CHANGELOG.md +114 -0
  17. package/Dockerfile +32 -0
  18. package/README.es.md +174 -0
  19. package/README.md +187 -0
  20. package/agents/chronicler.md +98 -0
  21. package/agents/ci-smith.md +136 -0
  22. package/agents/craftsman.md +341 -0
  23. package/agents/deploy-smith.md +138 -0
  24. package/agents/foreman.md +377 -0
  25. package/agents/go-smith.md +164 -0
  26. package/agents/guild.md +188 -0
  27. package/agents/inspector.md +83 -0
  28. package/agents/js-smith.md +127 -0
  29. package/agents/ops-scout.md +173 -0
  30. package/agents/painter.md +200 -0
  31. package/agents/python-smith.md +120 -0
  32. package/agents/ranger.md +307 -0
  33. package/agents/release-smith.md +165 -0
  34. package/agents/rust-smith.md +159 -0
  35. package/agents/sage.md +178 -0
  36. package/agents/scout.md +144 -0
  37. package/agents/scribe.md +156 -0
  38. package/agents/smith.md +201 -0
  39. package/agents/vue-smith.md +155 -0
  40. package/agents/warden.md +216 -0
  41. package/agents/zig-smith.md +156 -0
  42. package/bin/ndomo-analyses.ts +4 -0
  43. package/bin/ndomo-status.ts +4 -0
  44. package/biome.json +57 -0
  45. package/bun.lock +514 -0
  46. package/commitlint.config.js +3 -0
  47. package/config/ndomo.config.json +258 -0
  48. package/config/ndomo.schema.json +166 -0
  49. package/docs/agents.md +375 -0
  50. package/docs/bugs/plan-create-orphan-fk.md +131 -0
  51. package/docs/bugs/task_create_batch-order-index-collision.md +158 -0
  52. package/docs/configuration.md +276 -0
  53. package/docs/database.md +364 -0
  54. package/docs/features/feature-flexible-builder-v1.md +724 -0
  55. package/docs/features/feature-flexible-builder-v2.md +882 -0
  56. package/docs/features/feature-flexible-builder.md +974 -0
  57. package/docs/http-server.md +244 -0
  58. package/docs/installation.md +259 -0
  59. package/docs/integrations.md +129 -0
  60. package/docs/operations/anti-pattern-sub-agent-verify-2026-06-21.md +32 -0
  61. package/docs/operations/audit-v1.md +417 -0
  62. package/docs/operations/audit-v2.md +197 -0
  63. package/docs/operations/audit-v3.md +306 -0
  64. package/docs/operations/db-optimize-foundations.md +123 -0
  65. package/docs/operations/verify-gate-architecture.md +82 -0
  66. package/docs/workflows.md +448 -0
  67. package/opencode.json +5 -0
  68. package/package.json +65 -0
  69. package/release-please-config.json +11 -0
  70. package/scripts/dev-bust-cache.sh +164 -0
  71. package/scripts/install.sh +688 -0
  72. package/scripts/smoke-e2e.ts +704 -0
  73. package/scripts/smoke-hot.ts +417 -0
  74. package/scripts/smoke-http.sh +228 -0
  75. package/scripts/smoke-v4.ts +256 -0
  76. package/scripts/smoke-v5.ts +397 -0
  77. package/scripts/smoke.sh +9 -0
  78. package/scripts/uninstall.sh +224 -0
  79. package/skills/api-security-best-practices/SKILL.md +915 -0
  80. package/skills/bash-scripting/SKILL.md +201 -0
  81. package/skills/bun/SKILL.md +313 -0
  82. package/skills/cavecrew/SKILL.md +82 -0
  83. package/skills/caveman/SKILL.md +74 -0
  84. package/skills/caveman-review/README.md +33 -0
  85. package/skills/caveman-review/SKILL.md +55 -0
  86. package/skills/find-skills/SKILL.md +142 -0
  87. package/skills/frontend-design/LICENSE.txt +177 -0
  88. package/skills/frontend-design/SKILL.md +55 -0
  89. package/skills/golang-patterns/SKILL.md +674 -0
  90. package/skills/golang-security/SKILL.md +185 -0
  91. package/skills/golang-security/evals/evals.json +595 -0
  92. package/skills/golang-security/references/architecture.md +268 -0
  93. package/skills/golang-security/references/checklist.md +80 -0
  94. package/skills/golang-security/references/cookies.md +200 -0
  95. package/skills/golang-security/references/cryptography.md +424 -0
  96. package/skills/golang-security/references/filesystem.md +285 -0
  97. package/skills/golang-security/references/injection.md +315 -0
  98. package/skills/golang-security/references/logging.md +163 -0
  99. package/skills/golang-security/references/memory-safety.md +241 -0
  100. package/skills/golang-security/references/network.md +253 -0
  101. package/skills/golang-security/references/secrets.md +189 -0
  102. package/skills/golang-security/references/third-party.md +159 -0
  103. package/skills/golang-security/references/threat-modeling.md +189 -0
  104. package/skills/golang-testing/SKILL.md +720 -0
  105. package/skills/grill-me/SKILL.md +7 -0
  106. package/skills/javascript-testing-patterns/SKILL.md +537 -0
  107. package/skills/javascript-testing-patterns/references/advanced-testing-patterns.md +513 -0
  108. package/skills/modern-javascript-patterns/SKILL.md +43 -0
  109. package/skills/modern-javascript-patterns/references/advanced-patterns.md +487 -0
  110. package/skills/modern-javascript-patterns/references/details.md +457 -0
  111. package/skills/python-anti-patterns/SKILL.md +349 -0
  112. package/skills/python-design-patterns/SKILL.md +85 -0
  113. package/skills/python-design-patterns/references/details.md +353 -0
  114. package/skills/python-error-handling/SKILL.md +193 -0
  115. package/skills/python-error-handling/references/details.md +171 -0
  116. package/skills/python-testing-patterns/SKILL.md +278 -0
  117. package/skills/python-testing-patterns/references/advanced-patterns.md +411 -0
  118. package/skills/python-testing-patterns/references/details.md +349 -0
  119. package/skills/rust-patterns/SKILL.md +500 -0
  120. package/skills/rust-testing/SKILL.md +501 -0
  121. package/skills/security-review/SKILL.md +504 -0
  122. package/skills/security-review/cloud-infrastructure-security.md +361 -0
  123. package/skills/vue-best-practices/SKILL.md +154 -0
  124. package/skills/vue-best-practices/references/animation-class-based-technique.md +254 -0
  125. package/skills/vue-best-practices/references/animation-state-driven-technique.md +291 -0
  126. package/skills/vue-best-practices/references/component-async.md +97 -0
  127. package/skills/vue-best-practices/references/component-data-flow.md +307 -0
  128. package/skills/vue-best-practices/references/component-fallthrough-attrs.md +174 -0
  129. package/skills/vue-best-practices/references/component-keep-alive.md +137 -0
  130. package/skills/vue-best-practices/references/component-slots.md +216 -0
  131. package/skills/vue-best-practices/references/component-suspense.md +228 -0
  132. package/skills/vue-best-practices/references/component-teleport.md +108 -0
  133. package/skills/vue-best-practices/references/component-transition-group.md +128 -0
  134. package/skills/vue-best-practices/references/component-transition.md +125 -0
  135. package/skills/vue-best-practices/references/composables.md +290 -0
  136. package/skills/vue-best-practices/references/directives.md +162 -0
  137. package/skills/vue-best-practices/references/perf-avoid-component-abstraction-in-lists.md +159 -0
  138. package/skills/vue-best-practices/references/perf-v-once-v-memo-directives.md +182 -0
  139. package/skills/vue-best-practices/references/perf-virtualize-large-lists.md +187 -0
  140. package/skills/vue-best-practices/references/plugins.md +166 -0
  141. package/skills/vue-best-practices/references/reactivity.md +344 -0
  142. package/skills/vue-best-practices/references/render-functions.md +201 -0
  143. package/skills/vue-best-practices/references/sfc.md +310 -0
  144. package/skills/vue-best-practices/references/state-management.md +135 -0
  145. package/skills/vue-best-practices/references/updated-hook-performance.md +187 -0
  146. package/skills/vue-pinia-best-practices/SKILL.md +21 -0
  147. package/skills/vue-pinia-best-practices/reference/pinia-no-active-pinia-error.md +248 -0
  148. package/skills/vue-pinia-best-practices/reference/pinia-setup-store-return-all-state.md +227 -0
  149. package/skills/vue-pinia-best-practices/reference/pinia-store-destructuring-breaks-reactivity.md +193 -0
  150. package/skills/vue-pinia-best-practices/reference/state-url-for-ephemeral-filters.md +238 -0
  151. package/skills/vue-pinia-best-practices/reference/state-use-pinia-for-large-apps.md +262 -0
  152. package/skills/vue-pinia-best-practices/reference/store-method-binding-parentheses.md +191 -0
  153. package/skills/zig-0.16/SKILL.md +840 -0
  154. package/skills/zig-0.16/scripts/check-zig-version.sh +21 -0
  155. package/src/cli/analyses.ts +280 -0
  156. package/src/cli/index.ts +108 -0
  157. package/src/cli/serve.ts +192 -0
  158. package/src/cli/smoke.ts +131 -0
  159. package/src/cli/status.test.ts +204 -0
  160. package/src/cli/status.ts +263 -0
  161. package/src/cli/vacuum.test.ts +82 -0
  162. package/src/cli/vacuum.ts +96 -0
  163. package/src/config/schema.test.ts +88 -0
  164. package/src/config/schema.ts +64 -0
  165. package/src/db/analyses-migration.test.ts +210 -0
  166. package/src/db/analyses.test.ts +466 -0
  167. package/src/db/analyses.ts +375 -0
  168. package/src/db/auto-checkpoint.ts +131 -0
  169. package/src/db/client.test.ts +129 -0
  170. package/src/db/client.ts +55 -0
  171. package/src/db/fts-escape.ts +20 -0
  172. package/src/db/incidents.test.ts +201 -0
  173. package/src/db/incidents.ts +93 -0
  174. package/src/db/index.ts +86 -0
  175. package/src/db/migrations-v13.test.ts +141 -0
  176. package/src/db/migrations-v8.test.ts +301 -0
  177. package/src/db/migrations.ts +147 -0
  178. package/src/db/plan-archive.test.ts +180 -0
  179. package/src/db/plan-archive.ts +274 -0
  180. package/src/db/plan-create.test.ts +276 -0
  181. package/src/db/plan-create.ts +78 -0
  182. package/src/db/plan-files.test.ts +289 -0
  183. package/src/db/plan-update-status.ts +287 -0
  184. package/src/db/plans.test.ts +490 -0
  185. package/src/db/plans.ts +534 -0
  186. package/src/db/resolve-project-dir.test.ts +143 -0
  187. package/src/db/resolve-project-dir.ts +75 -0
  188. package/src/db/rollbacks.test.ts +150 -0
  189. package/src/db/rollbacks.ts +67 -0
  190. package/src/db/schema.ts +907 -0
  191. package/src/db/sessions.test.ts +80 -0
  192. package/src/db/sessions.ts +135 -0
  193. package/src/db/shutdown.test.ts +147 -0
  194. package/src/db/shutdown.ts +45 -0
  195. package/src/db/tasks.test.ts +921 -0
  196. package/src/db/tasks.ts +747 -0
  197. package/src/db/types.ts +619 -0
  198. package/src/http/__tests__/auth.test.ts +196 -0
  199. package/src/http/__tests__/routes.test.ts +465 -0
  200. package/src/http/__tests__/sse.test.ts +317 -0
  201. package/src/http/auth.ts +72 -0
  202. package/src/http/middleware/cors.ts +53 -0
  203. package/src/http/middleware/security-headers.ts +21 -0
  204. package/src/http/routes/events.ts +112 -0
  205. package/src/http/routes/health.ts +51 -0
  206. package/src/http/routes/plans.ts +66 -0
  207. package/src/http/routes/sessions.ts +50 -0
  208. package/src/http/routes/tasks.ts +60 -0
  209. package/src/http/server.ts +95 -0
  210. package/src/http/sse.ts +116 -0
  211. package/src/index.ts +37 -0
  212. package/src/lib.ts +65 -0
  213. package/src/mem/scoped.ts +65 -0
  214. package/src/orchestrator/background.test.ts +268 -0
  215. package/src/orchestrator/background.ts +293 -0
  216. package/src/orchestrator/memory-hook.ts +182 -0
  217. package/src/orchestrator/reconciler.ts +123 -0
  218. package/src/orchestrator/scheduler.test.ts +300 -0
  219. package/src/orchestrator/scheduler.ts +243 -0
  220. package/src/plugin.test.ts +2574 -0
  221. package/src/plugin.ts +1690 -0
  222. package/src/sdk/client.ts +66 -0
  223. package/src/worktrees/manager.ts +236 -0
  224. package/src/worktrees/state.ts +87 -0
  225. package/tests/integration/ranger-flow.test.ts +257 -0
  226. package/tools/analysis_archive.ts +28 -0
  227. package/tools/analysis_create.ts +55 -0
  228. package/tools/analysis_get.ts +33 -0
  229. package/tools/analysis_link_plan.ts +44 -0
  230. package/tools/analysis_list.ts +48 -0
  231. package/tools/analysis_search.ts +36 -0
  232. package/tools/analysis_update.ts +44 -0
  233. package/tools/plan_approve.ts +31 -0
  234. package/tools/plan_create.ts +58 -0
  235. package/tools/plan_get.ts +40 -0
  236. package/tools/plan_list.ts +37 -0
  237. package/tools/plan_search.ts +34 -0
  238. package/tools/plan_update_status.ts +71 -0
  239. package/tools/session_checkpoint.ts +31 -0
  240. package/tools/session_end.ts +26 -0
  241. package/tools/session_start.ts +43 -0
  242. package/tools/task_create_batch.ts +70 -0
  243. package/tools/task_list.ts +35 -0
  244. package/tools/task_next_for_agent.ts +30 -0
  245. package/tools/task_search.ts +34 -0
  246. package/tools/task_update_status.ts +37 -0
  247. package/tsconfig.json +31 -0
@@ -0,0 +1,448 @@
1
+ # Workflow Guide
2
+
3
+ ## Decision Tree
4
+
5
+ The first step for any user request is choosing the right agent. Use this decision tree:
6
+
7
+ ```
8
+ User envía prompt
9
+
10
+ ├─ ¿Tarea ≤2 archivos, ≤50 líneas, bien definida?
11
+ │ → craftsman (TUI) → Estado 1 (trivial, sin plan_db)
12
+
13
+ ├─ ¿Tarea 3-5 archivos, multi-stack, necesita tracking?
14
+ │ → craftsman (TUI) → Estado 2 (ad-hoc con plan_db)
15
+
16
+ ├─ ¿Tarea >5 archivos, diseño de arquitectura, o ambigua?
17
+ │ → foreman (TUI) → 4 pasos: Aclaración → Exploración → Plan → Persistir
18
+ │ → craftsman (TUI) → Estado 3 (lee plan formal)
19
+
20
+ ├─ ¿Auditoría de PR existente o tarea read-only?
21
+ │ → craftsman o scout según necesite escribir
22
+
23
+ └─ ¿Exploración read-only?
24
+ → scout (TUI)
25
+ ```
26
+
27
+ ## Foreman Workflow (Planner, 4 pasos)
28
+
29
+ Para tareas >5 archivos o diseño de arquitectura. El foreman planifica y persiste en DB; no ejecuta.
30
+
31
+ ```
32
+ User → Foreman (TUI)
33
+
34
+ Paso 1: Aclaración — identifica intención, pregunta si ambiguo
35
+ Paso 2: Exploración — memory search + scout/scribe/sage/guild
36
+ Paso 3: Plan Atómico — ≤5 steps con archivos y dependencias
37
+ Paso 4: Persistir — plan_create + task_create_batch
38
+
39
+ → User cambia a craftsman en TUI ←
40
+
41
+ craftsman: Estado 3 — task_next_for_agent → implementa → plan_update_status("completed")
42
+ ```
43
+
44
+ 1. **Aclaración** — analiza intención en 1-2 frases. Si ambigüo, `question` al usuario. Si ≤5 archivos y bien definida → sugerir `craftsman` directamente.
45
+ 2. **Exploración** — `memory({mode:"search"})` + delegar a scout/scribe/sage/guild según necesidad. NO delegar a smiths/painter/inspector/chronicler.
46
+ 3. **Plan Atómico** — desglosar en ≤5 steps. Cada step: `(Acción) → archivos esperados [paths] → dependencias`. Estimar complejidad (1-5) y riesgo (low/medium/high).
47
+ 4. **Persistir** — `plan_create` con slug/overview/approach. `task_create_batch` con steps (tasks asignadas a `craftsman`). **NO** crear `session_start` (lo hace craftsman). **NO** ejecutar tasks.
48
+
49
+ ## Craftsman Workflow (Implementer, 4 estados)
50
+
51
+ Para tareas ≤5 archivos o para ejecutar planes formales del foreman.
52
+
53
+ ### Estado 1: Trivial (≤2 archivos)
54
+ ```
55
+ craftsman (TUI) → lee archivos → implementa → verifica → reporta
56
+ ```
57
+ Sin writes a DB. Cambios directos.
58
+
59
+ ### Estado 2: Multi-archivo acotado (3-5 archivos)
60
+ ```
61
+ craftsman (TUI) → plan_create → task_create_batch → implementa por step → plan_update_status("completed")
62
+ ```
63
+ Crea su propio plan en DB para trazabilidad cross-session.
64
+
65
+ ### Estado 3: Plan formal (cualquier tamaño, plan pre-existente)
66
+ ```
67
+ craftsman (TUI) → plan_get / task_next_for_agent → implementa tasks → plan_update_status("completed")
68
+ ```
69
+ Ejecuta un plan que el foreman dejó en DB.
70
+
71
+ ### Estado 4: Fuera de dominio (>5 archivos, sin plan)
72
+ ```
73
+ [FUERA DE MI DOMINIO] → sugerir foreman → NO implementar
74
+ ```
75
+
76
+ ## Plan-Driven Workflow (ndomo DB)
77
+
78
+ Para trabajo multi-step trackeado cross-session. El foreman crea el plan en DB, craftsman lo ejecuta.
79
+
80
+ Ejemplo (foreman → craftsman):
81
+
82
+ ```bash
83
+ # === Foreman ===
84
+ # 1. Crear plan en DB
85
+ plan_create id="p1" slug="add-user-auth" title="Add user authentication" \
86
+ priority=2 overview="JWT-based auth for /api/* endpoints" \
87
+ approach="1) schema migration 2) login route 3) middleware 4) tests" \
88
+ complexity=4
89
+
90
+ # 2. Aprobar plan
91
+ plan_approve id="p1"
92
+
93
+ # 3. Crear tasks (asignadas a craftsman)
94
+ task_create_batch planId="p1" tasks='[
95
+ {"agent":"craftsman","description":"design schema migration","files":["src/db/schema.ts"],"complexity":3},
96
+ {"agent":"craftsman","description":"implement POST /login route","complexity":4,"dependencies":[0]},
97
+ {"agent":"craftsman","description":"add JWT middleware","complexity":3,"dependencies":[1]},
98
+ {"agent":"craftsman","description":"audit auth code with inspector","complexity":2,"dependencies":[1,2]}
99
+ ]'
100
+
101
+ # === User cambia a craftsman en TUI ===
102
+
103
+ # === Craftsman ===
104
+ # 4. Tomar siguiente task
105
+ task_next_for_agent({agent: "craftsman", planId: "p1"})
106
+
107
+ # 5. Para cada task:
108
+ task_update_status(id="t1", status="running")
109
+ # ... implementa ...
110
+ task_update_status(id="t1", status="done", result="...")
111
+
112
+ # 6. Todas completadas:
113
+ plan_update_status(id="p1", status="completed")
114
+ # → auto-archives a .ndomo/archives/plans/add-user-auth-2026-06-19.md
115
+
116
+ session_end(id="s1")
117
+ ```
118
+
119
+ Ver [docs/database.md](docs/database.md) para referencia completa de tools y
120
+ [agents/foreman.md](../agents/foreman.md) para el flujo detallado del foreman.
121
+
122
+ ## T3 Unified Close Flow
123
+
124
+ The `plan_update_status` tool now includes readiness checks before closing a plan.
125
+ This prevents premature closures and gives agents visibility into blockers.
126
+
127
+ ### Pre-check with dryRun
128
+
129
+ ```bash
130
+ # 1. Pre-check — see blockers without mutating
131
+ plan_update_status(id="p1", status="completed", dryRun=true)
132
+ # → { blocked: true, blockers: ["tasks_pending", "sessions_open"], warnings: [] }
133
+
134
+ # 2. Fix blockers (complete pending tasks, close sessions)
135
+ task_update_status(id="t3", status="done", result="...")
136
+ session_end(id="s1")
137
+
138
+ # 3. Re-check — should be clear now
139
+ plan_update_status(id="p1", status="completed", dryRun=true)
140
+ # → { blocked: false, blockers: [], warnings: [] }
141
+
142
+ # 4. Actually close
143
+ plan_update_status(id="p1", status="completed")
144
+ ```
145
+
146
+ ### Force close with reason
147
+
148
+ When blockers can't be resolved (e.g., abandoned work), force-close with a reason:
149
+
150
+ ```bash
151
+ plan_update_status(id="p1", status="abandoned", force=true, forceReason="scope changed, pivoting to new approach")
152
+ # → { forced: true, auditId: 42 }
153
+ ```
154
+
155
+ The force action is captured in `plan_audit` for traceability. `status_invalid` blockers
156
+ cannot be force-bypassed.
157
+
158
+ ### Blockers reference
159
+
160
+ | Blocker | Meaning |
161
+ |---|---|
162
+ | `tasks_pending` | Plan has tasks with `status='pending'` |
163
+ | `tasks_running` | Plan has tasks with `status='running'` |
164
+ | `sessions_open` | Plan has sessions without `ended_at` |
165
+ | `status_invalid` | Transition not allowed by state machine |
166
+
167
+ ## Auto-Checkpoint Behavior
168
+
169
+ The plugin automatically captures orchestrator state into session checkpoints
170
+ on configurable triggers. This provides continuity across context compactions
171
+ and agent dispatches without manual `session_checkpoint` calls.
172
+
173
+ ### Triggers
174
+
175
+ | Trigger | Fires when |
176
+ |---|---|
177
+ | `phase_transition` | `plan_update_status` succeeds (status actually changed, not dryRun) |
178
+ | `task_batch_complete` | Last pending task in a plan is marked `done` |
179
+
180
+ ### Configuration (`ndomo.json`)
181
+
182
+ ```json
183
+ {
184
+ "autoCheckpoint": {
185
+ "enabled": true,
186
+ "triggers": ["phase_transition", "task_batch_complete"],
187
+ "minIntervalMs": 30000,
188
+ "captureState": {
189
+ "completedTasks": true,
190
+ "currentPhase": true,
191
+ "blockers": true
192
+ }
193
+ }
194
+ }
195
+ ```
196
+
197
+ - `enabled` — master switch (default: `true`)
198
+ - `triggers` — which triggers are active (default: both)
199
+ - `minIntervalMs` — debounce interval in ms (default: 30000)
200
+ - `captureState` — which state fields to capture (default: all `true`)
201
+
202
+ ### Behavior
203
+
204
+ - **Non-blocking**: checkpoints are dispatched asynchronously via microtask — never blocks the tool executor.
205
+ - **Debounced**: rapid state changes produce at most one checkpoint per `minIntervalMs`.
206
+ - **Loop-safe**: an `isAutoCheckpointing` guard flag prevents re-entrant dispatch.
207
+ Since `checkpointSession` only writes to the sessions table (not plans/tasks),
208
+ loops are structurally impossible — the flag is a safety net.
209
+ - **Graceful**: errors in auto-checkpoint are swallowed (logged via `console.error`) — never break the caller.
210
+
211
+ ### Captured state
212
+
213
+ ```json
214
+ {
215
+ "trigger": "phase_transition",
216
+ "completedTasks": 5,
217
+ "currentPhase": "executing",
218
+ "blockers": ["tasks_pending"]
219
+ }
220
+ ```
221
+
222
+ ## Dependency-Aware Task Dispatch
223
+
224
+ `task_next_for_agent` now respects task dependencies. A task is only eligible
225
+ for claiming when all its dependencies (referenced by task ID) have `status='done'`.
226
+
227
+ ```bash
228
+ # Tasks: t1 (no deps), t2 (depends on t1), t3 (depends on t1)
229
+ task_next_for_agent(agent="craftsman", planId="p1")
230
+ # → claims t1 (no deps)
231
+
232
+ # After t1 is done:
233
+ task_next_for_agent(agent="craftsman", planId="p1")
234
+ # → claims t2 or t3 (both have t1 done)
235
+ ```
236
+
237
+ Use `task_dependency_resolver` to inspect a task's dependency state before claiming:
238
+
239
+ ```bash
240
+ task_dependency_resolver(taskId="t2")
241
+ # → { canStart: true, doneDeps: ["t1"], pendingDeps: [], ... }
242
+ ```
243
+
244
+ ## Deepwork
245
+
246
+ **When to use:** Multi-file refactors (> 5 files), risky architecture changes (database schema, auth flow, API contracts), phased features with inter-step dependencies, cross-stack work.
247
+
248
+ Use `deepwork <task description>` to invoke. The workflow:
249
+
250
+ 1. **Plan creation** — foreman creates `.slim/deepwork/<slug>.md` with phases, expected files, dependencies, and risk levels.
251
+ 2. **Phase breakdown** — each phase is a discrete step with clear entry/exit criteria.
252
+ 3. **Sage gates** — after each phase, `sage` reviews the result. If the gate fails, the plan is adjusted before proceeding.
253
+ 4. **Worktree isolation** — deepwork auto-creates a git worktree at `.slim/worktrees/<slug>/` for isolation.
254
+ 5. **Progress tracking** — the plan file is updated after each phase. Work can be resumed after context loss.
255
+ 6. **Completion** — after all phases pass sage gates, the foreman requests user confirmation before merging the worktree.
256
+
257
+ ## Worktrees
258
+
259
+ **When to use:** Risky changes that might break the main working tree, parallel development, experimental features, deepwork sessions.
260
+
261
+ Created by the foreman or on explicit request: "create a worktree for <task>".
262
+
263
+ ### Lifecycle
264
+
265
+ ```
266
+ Create → Work in isolation → User confirms merge → Merge → Cleanup
267
+ ```
268
+
269
+ 1. **Create** — `createWorktree(rootDir, slug, branch, agent?, description?)` creates a git worktree at `.slim/worktrees/<slug>/`.
270
+ 2. **Isolate** — specialists are dispatched inside the worktree for file isolation.
271
+ 3. **Track state** — persists state in `.slim/worktrees.json` via `loadState()` / `saveState()`.
272
+ 4. **Integrity** — `verifyIntegrity()` checks directory existence, branch validity, and git registration.
273
+ 5. **Merge** — user confirms explicitly before merging to main.
274
+ 6. **Cleanup** — `cleanup()` removes abandoned/merged worktrees older than maxAge (default 7 days).
275
+
276
+ ### Safety protocols
277
+
278
+ - `assertSafeName()` prevents shell injection in slug/branch parameters (alphanumeric, hyphens, underscores, slashes only; no leading hyphen).
279
+ - Foreman requires explicit user confirmation before merging any worktree.
280
+ - Integrity checks run on all active worktrees.
281
+
282
+ ## Reflect
283
+
284
+ **When to use:** After 3+ similar tasks, repeated friction in workflows, or on user request.
285
+
286
+ Invoke: `reflect [optional focus]`
287
+
288
+ The workflow:
289
+
290
+ 1. **Search memory** — scribe searches recent work for friction patterns and repeated errors.
291
+ 2. **Analyze** — identify the root cause of repetitive friction.
292
+ 3. **Propose fix** — suggest the smallest useful change: a new skill, command, agent, or config rule.
293
+ 4. **Implement** — with user approval, create the fix.
294
+
295
+ Not for: one-off tasks or well-understood patterns with no friction.
296
+
297
+ ## Background Dispatch
298
+
299
+ The `BackgroundDispatcher` class (`src/orchestrator/background.ts`) provides pure state tracking:
300
+
301
+ 1. **dispatch** — registers a new task (`pending` status), returns a task ID.
302
+ 2. **markRunning** — transitions to `running` with a session ID and timestamp.
303
+ 3. **getActive** — returns all pending or running tasks.
304
+ 4. **markComplete / markFailed** — transitions to terminal state with result or error.
305
+ 5. **reconcile** — collects all finished tasks for processing.
306
+ 6. **remove** — cleans up after reconciliation.
307
+
308
+ ### No write overlap rule
309
+
310
+ Two agents editing the same file simultaneously is forbidden. Before dispatching a writer, the foreman checks that no active task claims those files. This is enforced at the scheduling level — the `canRunParallel()` function checks for file conflicts and dependency chains.
311
+
312
+ ### Parallel dispatch rules
313
+
314
+ - Tasks with no explicit file list are assumed non-conflicting.
315
+ - Tasks with `parallel: false` (guild, sage debug) block the batch.
316
+ - If task A depends on task B (via `dependencies`), they cannot run in parallel.
317
+
318
+ ## Memory Integration
319
+
320
+ The foreman runs the following memory protocol on every request:
321
+
322
+ 1. **Before planning** — `memory({mode:"search", scope:"project"})` for current project context; `memory({mode:"search", scope:"all-projects"})` for cross-project knowledge.
323
+ 2. **Before storing** — compress content to caveman format using `cavemanCompress()`.
324
+ 3. **Compression rules** — drops articles, filler words, leading conjunctions, filler phrases. Preserves code blocks and URLs.
325
+ 4. **Threshold** — `shouldStoreMemory()` filters out content < 20 chars or purely code blocks.
326
+ 5. **Protected** — memory tool outputs are never pruned from context (listed in `protectedTools`).
327
+
328
+ The `memory-hook.ts` module provides `cavemanCompress()`, `prepareForMemory()`, and `shouldStoreMemory()` — all regex-based (zero LLM tokens).
329
+
330
+ ## Smoke Tests (Checklist)
331
+
332
+ Verificación manual de los flujos primarios post-refactor. No requiere DB real — validar contra código y prompts.
333
+
334
+ ### (a) Foreman flow 4 pasos
335
+
336
+ - [ ] **Aclaración:** foreman identifica intención en 1-2 frases (`agents/foreman.md:123-128`)
337
+ - [ ] **Aclaración:** si ≤5 archivos y bien definida → sugiere craftsman en lugar de planificar (`agents/foreman.md:126`)
338
+ - [ ] **Aclaración:** si >5 archivos o diseño arquitectura → continúa planificación
339
+ - [ ] **Exploración:** invoca `memory({mode:"search"})` antes de delegar (`agents/foreman.md:130-131`)
340
+ - [ ] **Exploración:** delega solo a scout/scribe/sage/guild (`agents/foreman.md:133-136`)
341
+ - [ ] **Exploración:** NO delega a smiths/painter/chronicler/inspector (`agents/foreman.md:138`)
342
+ - [ ] **Plan Atómico:** desglosa en ≤5 steps con archivos y dependencias (`agents/foreman.md:140-144`)
343
+ - [ ] **Persistir:** llama `plan_create` + `task_create_batch` con tasks para craftsman (`agents/foreman.md:147-151`)
344
+ - [ ] **Persistir:** NO crea `session_start` (lo hace craftsman al ejecutar) (`agents/foreman.md:149`)
345
+ - [ ] **Routing table:** foreman solo lista scout/scribe/sage/guild (`agents/foreman.md:45-51`)
346
+ - [ ] **Salida:** formato caveman con objetivo/exploración/plan/persistido/siguiente (`agents/foreman.md:155-164`)
347
+
348
+ ### (b) Craftsman Estado 1 (trivial, ≤2 archivos)
349
+
350
+ - [ ] Detecta ≤2 archivos sin dependencias externas (`agents/craftsman.md:58`)
351
+ - [ ] Implementa sin `plan_create` ni writes a DB (`agents/craftsman.md:67`)
352
+ - [ ] Corre validación (typecheck/tests/lint) (`agents/craftsman.md:63`)
353
+ - [ ] Reporta en formato caveman: archivos, líneas, verificación (`agents/craftsman.md:200-217`)
354
+ - [ ] NO toca `plan_db` tools (`agents/craftsman.md:67`)
355
+
356
+ ### (c) Craftsman Estado 4 (rechazo >5 archivos)
357
+
358
+ - [ ] Detecta >5 archivos o requiere diseño de arquitectura (`agents/craftsman.md:121`)
359
+ - [ ] Reporta `[FUERA DE MI DOMINIO]` con razón (`agents/craftsman.md:124`)
360
+ - [ ] Sugiere cambiar a foreman en TUI (`agents/craftsman.md:125`)
361
+ - [ ] NO implementa parcialmente — rechaza completo (`agents/craftsman.md:126`, `agents/craftsman.md:193`)
362
+ - [ ] Output format: resultado/razon/sugerencia (`agents/craftsman.md:220-224`)
363
+
364
+ ## Tools by agent
365
+
366
+ ### Craftsman
367
+
368
+ | Mode | Tools used |
369
+ |---|---|
370
+ | AD-HOC (Estado 1) | `task_update_status` (result/error only), `session_start`/`session_end` |
371
+ | PLAN (Estado 2) | `plan_create`, `task_create_batch`, `task_update_status`, `task_next_for_agent`, `task_add_artifact`, `task_review`, `plan_progress`, `plan_files_write`, `session_start`/`session_end` |
372
+ | DISPATCHED (Estado 3) | `task_next_for_agent`, `task_update_status` (with artifacts/metadataPatch), `task_add_artifact`, `task_review`, `task_peek_for_agent`, `plan_progress`, `session_start`/`session_end` |
373
+
374
+ - `task_peek_for_agent` — read-only check before claiming (no status change).
375
+ - `task_add_artifact` — register output files after implementation.
376
+ - `task_review` — inspector reviews done tasks, sets verdict.
377
+ - `plan_progress` — monitor plan progress during execution.
378
+ - `plan_files_write` — register input/modified/output files for a plan.
379
+
380
+ ### Warden
381
+
382
+ | Mode | Tools used |
383
+ |---|---|
384
+ | AD-HOC | `task_update_status`, `session_start`/`session_end` |
385
+ | PLAN | `plan_create` (metadata.category="ops"), `task_create_batch`, `task_update_status`, `task_review`, `plan_progress`, `incident_create`, `rollback_record`, `session_start`/`session_end` |
386
+ | DISPATCHED | `task_next_for_agent`, `task_update_status`, `task_review`, `plan_progress`, `incident_create`, `rollback_record` |
387
+
388
+ - `incident_create` — register an ops incident (sev1-4) when a deployment fails or issue detected.
389
+ - `rollback_record` — record a rollback execution tied to a deployment (required) + optional incident.
390
+
391
+ ### Foreman
392
+
393
+ | Mode | Tools used |
394
+ |---|---|
395
+ | Planning | `plan_create`, `task_create_batch`, `plan_get`, `plan_list`, `plan_search`, `plan_approve`, `plan_update_status`, `plan_progress`, `session_start`/`session_end` |
396
+ | Dispatch | `task_create_batch` (agent="craftsman"/"warden"), `task_next_for_agent` (check), `plan_progress` (monitor) |
397
+
398
+ - Foreman does NOT use `task_update_status` (delegates execution to craftsman/warden).
399
+ - Foreman does NOT use `task_add_artifact` or `task_review` (those are post-execution tools).
400
+
401
+ ## Warden ops workflow — incident response
402
+
403
+ The 3-call flow for incident response (warden scope):
404
+
405
+ ```
406
+ 1. Detect failure (deployment status='failed' or external alert)
407
+
408
+ 2. incident_create(title, severity, summary, triggeredByDeploymentId?)
409
+ → Returns Incident record with status='open'
410
+
411
+ 3. rollback_record(deploymentId, plan, incidentId, status='planned')
412
+ → Returns RollbackExecution record
413
+ → Optional: update status to 'executing' → 'success'/'failed' as rollback progresses
414
+ ```
415
+
416
+ ### Integration with warden workflow
417
+
418
+ This flow fits into the warden's existing incident response pattern (`agents/warden.md`):
419
+
420
+ 1. **Detect** — warden monitors deployments (via `plan_progress` or external alerts).
421
+ 2. **Triage** — `incident_create` with severity sev1-4. Status starts as `open`.
422
+ - Use `triggeredByDeploymentId` to link the incident to the failing deployment.
423
+ 3. **Rollback** — `rollback_record` with the deployment_id (required) + incident_id (optional but recommended).
424
+ - The `plan` field describes the rollback strategy (e.g. "redeploy previous release v1.2.3").
425
+ - Status transitions: `planned` → `approved` → `dry_run` → `executing` → `success`/`failed`.
426
+ 4. **Resolve** — update incident status to `mitigated` then `resolved` (via `updateIncidentStatus` DB helper).
427
+ - Optional: `postmortem` status for retrospective.
428
+
429
+ ### Example (3-call flow)
430
+
431
+ ```typescript
432
+ // 1. Detect: deployment d_abc123 failed
433
+ // 2. Create incident
434
+ incident_create({
435
+ title: "prod deployment v2.1.0 failed — auth service 500s",
436
+ severity: "sev1",
437
+ summary: "Deployment d_abc123 caused auth service to return 500 errors. ~30% of users affected.",
438
+ triggeredByDeploymentId: "d_abc123",
439
+ })
440
+
441
+ // 3. Record rollback plan
442
+ rollback_record({
443
+ deploymentId: "d_abc123",
444
+ plan: "Redeploy previous release v2.0.3. Steps: 1) mark d_abc123 as rolled_back, 2) create new deployment for v2.0.3 to prod, 3) verify auth service health.",
445
+ incidentId: "inc_xyz789",
446
+ status: "planned",
447
+ })
448
+ ```
package/opencode.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "$schema": "https://opencode.ai/config.json",
3
+ "plugin": ["ndomo"],
4
+ "default_agent": "foreman"
5
+ }
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "ndomo",
3
+ "version": "0.1.0",
4
+ "description": "OpenCode multi-agent plugin. Taller de artesanos: foreman + 3 peer primaries (craftsman, warden, ranger) + specialists (scout, scribe, painter, smith, sage, guild, inspector, chronicler) + stack-smiths + ops (ci-smith, deploy-smith, release-smith, ops-scout). Caveman-native. opencode-mem integrated. DCP peer optional.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "main": "./src/index.ts",
8
+ "exports": {
9
+ ".": "./src/index.ts",
10
+ "./plugin": "./src/plugin.ts",
11
+ "./db": "./src/db/index.ts"
12
+ },
13
+ "private": false,
14
+ "engines": {
15
+ "bun": ">=1.1.0"
16
+ },
17
+ "scripts": {
18
+ "build": "tsc --noEmit",
19
+ "dev": "bun run --watch src/index.ts",
20
+ "typecheck": "tsc --noEmit",
21
+ "lint": "biome check .",
22
+ "lint:fix": "biome check --write .",
23
+ "format": "biome format --write .",
24
+ "test": "bun test",
25
+ "test:smoke": "bash scripts/smoke.sh",
26
+ "dev:bust": "bash scripts/dev-bust-cache.sh --apply",
27
+ "dev:reset": "bash scripts/dev-bust-cache.sh --apply --kill",
28
+ "status:plans": "bun run src/cli/status.ts --plans",
29
+ "clean": "rm -rf dist .slim/worktrees",
30
+ "prepare": "husky"
31
+ },
32
+ "dependencies": {
33
+ "@opencode-ai/sdk": "1.17.7",
34
+ "elysia": "^1.4.29",
35
+ "opencode-mem": "^2.17.1"
36
+ },
37
+ "peerDependencies": {
38
+ "@opencode-ai/plugin": "^1.17.7"
39
+ },
40
+ "peerDependenciesMeta": {
41
+ "@tarquinen/opencode-dcp": {
42
+ "optional": true
43
+ }
44
+ },
45
+ "devDependencies": {
46
+ "@biomejs/biome": "2.5.0",
47
+ "@commitlint/cli": "^19.0.0",
48
+ "@commitlint/config-conventional": "^19.0.0",
49
+ "@types/bun": "latest",
50
+ "husky": "^9.0.0",
51
+ "typescript": "^6.0.0"
52
+ },
53
+ "keywords": [
54
+ "opencode",
55
+ "opencode-plugin",
56
+ "multi-agent",
57
+ "caveman",
58
+ "taller-de-artesanos"
59
+ ],
60
+ "author": "",
61
+ "repository": {
62
+ "type": "git",
63
+ "url": "https://github.com/nicosup98/ndomo-v2.git"
64
+ }
65
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "packages": {
3
+ ".": {
4
+ "release-type": "node",
5
+ "changelog-path": "CHANGELOG.md",
6
+ "bump-minor-pre-major": true,
7
+ "bump-patch-for-minor-pre-major": false,
8
+ "include-component-in-tag": false
9
+ }
10
+ }
11
+ }