trekoon 0.4.1 → 0.4.3

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 (58) hide show
  1. package/.agents/skills/trekoon/SKILL.md +97 -765
  2. package/.agents/skills/trekoon/reference/execution-with-team.md +91 -141
  3. package/.agents/skills/trekoon/reference/execution.md +188 -159
  4. package/.agents/skills/trekoon/reference/harness-primitives.md +77 -0
  5. package/.agents/skills/trekoon/reference/planning.md +213 -213
  6. package/.agents/skills/trekoon/reference/status-machine.md +21 -0
  7. package/.agents/skills/trekoon/reference/sync.md +82 -0
  8. package/README.md +29 -8
  9. package/docs/ai-agents.md +65 -6
  10. package/docs/commands.md +149 -5
  11. package/docs/machine-contracts.md +123 -0
  12. package/docs/quickstart.md +55 -3
  13. package/package.json +1 -1
  14. package/src/board/assets/app.js +47 -13
  15. package/src/board/assets/components/Component.js +20 -8
  16. package/src/board/assets/components/Workspace.js +9 -3
  17. package/src/board/assets/components/helpers.js +4 -0
  18. package/src/board/assets/runtime/delegation.js +8 -0
  19. package/src/board/assets/runtime/focus-trap.js +48 -0
  20. package/src/board/assets/state/actions.js +45 -4
  21. package/src/board/assets/state/api.js +304 -17
  22. package/src/board/assets/state/store.js +82 -11
  23. package/src/board/assets/state/url.js +10 -0
  24. package/src/board/assets/state/utils.js +2 -1
  25. package/src/board/event-bus.ts +81 -0
  26. package/src/board/routes.ts +430 -40
  27. package/src/board/server.ts +86 -10
  28. package/src/board/snapshot.ts +6 -0
  29. package/src/board/wal-watcher.ts +313 -0
  30. package/src/commands/board.ts +52 -17
  31. package/src/commands/epic.ts +7 -9
  32. package/src/commands/error-utils.ts +54 -1
  33. package/src/commands/help.ts +75 -10
  34. package/src/commands/migrate.ts +153 -24
  35. package/src/commands/quickstart.ts +7 -0
  36. package/src/commands/skills.ts +17 -5
  37. package/src/commands/subtask.ts +71 -10
  38. package/src/commands/suggest.ts +6 -13
  39. package/src/commands/task.ts +137 -88
  40. package/src/domain/batch-validation.ts +329 -0
  41. package/src/domain/cascade-planner.ts +412 -0
  42. package/src/domain/dependency-rules.ts +15 -0
  43. package/src/domain/mutation-service.ts +842 -187
  44. package/src/domain/search.ts +113 -0
  45. package/src/domain/tracker-domain.ts +167 -693
  46. package/src/domain/types.ts +56 -2
  47. package/src/export/render-markdown.ts +1 -2
  48. package/src/index.ts +37 -0
  49. package/src/runtime/cli-shell.ts +44 -0
  50. package/src/runtime/daemon.ts +700 -0
  51. package/src/storage/backup.ts +166 -0
  52. package/src/storage/database.ts +268 -4
  53. package/src/storage/migrations.ts +441 -22
  54. package/src/storage/path.ts +8 -0
  55. package/src/storage/schema.ts +5 -1
  56. package/src/sync/event-writes.ts +38 -11
  57. package/src/sync/git-context.ts +226 -8
  58. package/src/sync/service.ts +679 -156
@@ -5,89 +5,43 @@ description: "Use for Trekoon-based planning and execution: creating epics, task
5
5
 
6
6
  # Trekoon Skill
7
7
 
8
- Trekoon is a local-first execution harness for tracked implementation work.
9
- Treat Trekoon as the source of truth for plans, progress, blockers, readiness,
10
- and orchestration state.
8
+ Trekoon is the source of truth for tracked implementation work: plans,
9
+ readiness, owners, blockers, progress, verification evidence, and completion.
10
+ Use this file as the router. Load references only when the current mode needs
11
+ them.
11
12
 
12
- This skill is the operating guide, not the full CLI reference. Use it to route
13
- into the right mode quickly, keep momentum, and finish work rather than
14
- stalling in analysis.
13
+ ## Mode Contracts
15
14
 
16
- ## Operating contract
15
+ - `trekoon plan <goal>`: create an execution-ready epic in Trekoon.
16
+ - `trekoon <id>`: orient on the epic/task/subtask and report current state,
17
+ blockers, and next action.
18
+ - `trekoon <id> execute`: own the epic until it is done, hard-blocked, or needs
19
+ user input. Use subagents by default for meaningful work that can run
20
+ independently when the harness exposes them.
21
+ - `trekoon <id> team execute`: same completion contract, using Claude Agent
22
+ Teams only when the user explicitly asks and the environment supports it.
17
23
 
18
- Treat these entrypoints as hard mode contracts:
24
+ Do not stop at analysis when Trekoon shows ready work. Do not invent a parallel
25
+ plan outside Trekoon.
19
26
 
20
- - `trekoon plan <goal>` → create an **execution-ready epic** in Trekoon.
21
- - `trekoon <epic-id>` → **orient** on the current state and report the next
22
- concrete action.
23
- - `trekoon <epic-id> execute` → **own the epic until it is done, hard-blocked,
24
- or requires user input**.
25
- - `trekoon <epic-id> team execute` → same execution contract, but use Agent
26
- Teams only when the environment supports it and the user explicitly wants it.
27
+ ## Load Rules
27
28
 
28
- Reading `reference/planning.md` or `reference/execution.md` is a required setup
29
- step for those modes, not the end of the workflow.
30
-
31
- ## Trigger guidance
32
-
33
- Use this skill whenever the user wants tracked planning or tracked execution in
34
- Trekoon, for example:
35
-
36
- - break a feature into epics, tasks, subtasks, or dependencies
37
- - create backlog or sprint-ready work items
38
- - check epic/task status, progress, readiness, or blockers
39
- - execute a Trekoon epic end to end with sub-agents
40
- - coordinate parallel implementation lanes from tracked work
41
-
42
- Do **not** use this skill for generic coding work that is not meant to be
43
- tracked in Trekoon.
44
-
45
- ## Command router
46
-
47
- When invoked with arguments, determine the mode first, then load only the
48
- reference needed for that mode.
49
-
50
- ## Planning preflight
51
-
52
- Before entering plan mode, harvest the context already available in the current
53
- conversation and workspace. Planning should build on prior thinking, not restart
54
- discovery from zero.
55
-
56
- Treat these as primary inputs when they exist:
57
-
58
- - brainstorm output
59
- - research notes or library findings
60
- - codebase exploration results
61
- - prior user decisions and constraints
62
- - existing Trekoon entities that should be expanded rather than replaced
63
-
64
- Compress that context into a short internal planning brief before creating the
65
- epic graph:
66
-
67
- - goal and why now
68
- - decisions already made
69
- - constraints and risks already known
70
- - affected systems/files/interfaces
71
- - verification expectations
72
- - unresolved questions that actually block planning
73
-
74
- If the remaining unknowns are real blockers, do targeted follow-up research or
75
- ask the user a narrow clarification question. Use the harness's interactive user
76
- question tool for this — `question` in OpenCode or `AskUserQuestion` in Claude
77
- Code — instead of guessing.
78
-
79
- ### 1. Route by first argument
29
+ | Situation | Load |
30
+ |---|---|
31
+ | Any Trekoon request | This file |
32
+ | Plan, break down, design tracked work | `reference/harness-primitives.md`, then `reference/planning.md` |
33
+ | Execute, implement, complete tracked work | `reference/harness-primitives.md`, then `reference/execution.md` |
34
+ | User explicitly asks for Claude team execution | `reference/harness-primitives.md`, then `reference/execution-with-team.md` |
35
+ | Sync gaps, conflicts, shared-storage questions | `reference/sync.md` |
36
+ | Status transition error or status uncertainty | `reference/status-machine.md` |
80
37
 
81
- | Command shape | Mode | Required read | Completion target |
82
- |---|---|---|---|
83
- | `trekoon plan <goal>` | Plan | `reference/planning.md` | Epic exists, graph is validated, next-wave summary is returned |
84
- | `trekoon <epic-id>` | Orient | None beyond this file unless needed | User knows current state, next ready action, and blockers |
85
- | `trekoon <epic-id> execute` | Execute | `reference/execution.md` | Epic is done, all remaining work is blocked, or user input is required |
86
- | `trekoon <epic-id> team execute` | Team execute | `reference/execution-with-team.md` | Same as execute, using Agent Teams |
38
+ `reference/harness-primitives.md` is required before planning or execution
39
+ because those modes may need local task displays, user questions, subagents,
40
+ review agents, testing tools, and Trekoon evidence recording.
87
41
 
88
- ### 2. Resolve entity IDs when present
42
+ ## Route Input
89
43
 
90
- If the first argument is not `plan`, resolve it as a Trekoon entity:
44
+ Resolve the first non-mode argument as an epic, task, or subtask:
91
45
 
92
46
  ```bash
93
47
  trekoon --toon epic show <id> 2>/dev/null || \
@@ -95,701 +49,79 @@ trekoon --toon task show <id> 2>/dev/null || \
95
49
  trekoon --toon subtask show <id> 2>/dev/null
96
50
  ```
97
51
 
98
- If none match, tell the user the ID was not found.
99
-
100
- When the entity is a **task or subtask**, resolve its parent epic ID from the
101
- entity record and scope `session`, `suggest`, and `epic progress` to that epic.
102
- If the user asked to execute a task or subtask, make forward progress on that
103
- requested entity first; continue broader epic execution only if that matches the
104
- user's intent.
52
+ If the ID is a task or subtask, resolve its parent epic and scope `session`,
53
+ `suggest`, and `epic progress` to that epic. If the user asked to execute a task
54
+ or subtask, start with that item; continue broader epic execution only when it
55
+ matches the user intent.
105
56
 
106
- ### 3. Interpret missing or extra text
107
-
108
- | User intent signal | Action |
57
+ | User signal | Mode |
109
58
  |---|---|
110
- | No text, just an ID | **Orient:** run `session --epic <epic-id>` (or show the task/subtask), summarize status, readiness, and next action |
111
- | `analyze`, `review`, `check`, `status`, `progress` | **Analyze:** run `epic progress <id>` or `task show <id> --all`, then `suggest --epic <id>`, and report findings |
112
- | `execute`, `implement`, `do`, `complete`, `start`, `run` | **Execute:** read `reference/execution.md`, choose single-agent vs orchestrated execution, and keep going until the mode contract is satisfied |
113
- | `team execute`, `execute with team` | **Team execute:** read `reference/execution-with-team.md` only when Agent Teams are available |
114
- | `plan`, `break down`, `design`, `architect` | **Plan:** read `reference/planning.md` and create or expand the epic graph |
115
-
116
- ### Examples
117
-
118
- ```text
119
- trekoon plan build a dependency-aware release workflow
120
- reads planning reference, creates a validated epic, returns epic ID + wave summary
121
-
122
- trekoon abc-123
123
- orients on epic/task/subtask abc-123, summarizes state and next action
124
-
125
- trekoon abc-123 execute
126
- reads execution reference, starts the execution loop, keeps going until done or blocked
127
-
128
- trekoon abc-123 team execute
129
- reads team execution reference, starts Agent Teams orchestration if supported
130
- ```
131
-
132
- ## Reference guides
133
-
134
- Read references lazily based on mode.
135
-
136
- > **Path note:** Script paths below are relative to this skill's folder (where this SKILL.md lives), not the current project root. Resolve them from this skill folder when invoking Bash.
137
-
138
- | Mode | Read | Use it for |
139
- |---|---|---|
140
- | Plan | `reference/planning.md` | Converting a goal into a real epic/task/subtask dependency graph with validation and handoff |
141
- | Execute | `reference/execution.md` | Running an epic end to end, choosing lanes, dispatching sub-agents, recording evidence, and closing the epic |
142
- | Team execute | `reference/execution-with-team.md` | Agent Teams coordination via TeamCreate/TaskCreate/SendMessage when the environment supports it |
143
-
144
- ## Mode completion rules
145
-
146
- These stop conditions are the core contract for the skill.
147
-
148
- - **Plan mode** is complete only when the epic has been created in Trekoon,
149
- tasks/subtasks/dependencies exist, validation passes, and the user receives
150
- the epic ID plus an execution-ready summary.
151
- - **Orient mode** is complete when the user has the current state, ready work,
152
- blockers, and the most likely next command.
153
- - **Execute mode** is complete only when one of these is true:
154
- 1. the epic is fully completed and marked `done`
155
- 2. all remaining work is blocked and blockers are recorded in Trekoon
156
- 3. a real ambiguity, approval, or external dependency requires user input
157
-
158
- ## Anti-stall rules
159
-
160
- - Do not stop after `session`, `suggest`, or `epic progress` if a clear next
161
- action exists.
162
- - Do not stop after completing one task if more ready work exists.
163
- - After each `task done`, inspect `unblocked` and `next` to decide the next
164
- move immediately.
165
- - If multiple independent tasks are ready and isolation is safe, group them by
166
- lane and delegate.
167
- - Ask the user only when the work is genuinely blocked by ambiguity, approval,
168
- or missing external access.
169
-
170
- ## Clarification tool rule
171
-
172
- When planning or execution needs user input, use the harness's user-question
173
- tool rather than burying the question inside narration:
174
-
175
- - OpenCode: `question`
176
- - Claude Code: `AskUserQuestion`
177
-
178
- Ask narrow, decision-shaping questions. Prefer one clear question with concrete
179
- options over a broad list of speculative unknowns.
180
-
181
- ## Non-negotiable defaults
182
-
183
- - Always include `--toon` on every Trekoon command.
184
- - Prefer the smallest sufficient scope.
185
- - Prefer transactional bulk commands over many single-item commands.
186
- - Prefer `--append` for progress notes, completion notes, and blocker notes.
187
- - Preview replace before `--apply`.
188
- - Prefer `--ids` over `--all` for bulk updates.
189
- - Treat Trekoon state updates as part of the workflow, not as after-the-fact
190
- bookkeeping.
191
- - Never edit `.trekoon/trekoon.db` directly.
192
- - Treat `.trekoon` as shared repo-scoped operational state in git worktrees.
193
- - Keep `.trekoon` gitignored; do not commit the SQLite DB as a recovery fix.
194
- - Never run `trekoon wipe --yes --toon` unless the user explicitly asks for it.
195
- - Create branches, commits, merges, or PRs only when the user explicitly asks
196
- and the current harness policy allows it.
197
-
198
- ## Status machine
199
-
200
- Trekoon enforces a status transition graph. Only these transitions are valid:
201
-
202
- | From | Allowed targets |
203
- |---|---|
204
- | `todo` | `in_progress`, `blocked` |
205
- | `in_progress` | `done`, `blocked` |
206
- | `blocked` | `in_progress`, `todo` |
207
- | `done` | `in_progress` |
208
-
209
- Invalid transitions (e.g. `todo → done`) return error code
210
- `status_transition_invalid`. Always transition through `in_progress` to reach
211
- `done`.
212
-
213
- **Exception:** `task done` auto-transitions through `in_progress` when the task
214
- is in `todo` or `blocked` status, so you can call `task done` from any
215
- non-done status.
216
-
217
- Recommended statuses for consistent workflows: `todo`, `in_progress`, `done`.
218
- Use `blocked` with an appended reason when work is stuck.
219
-
220
- ## Epic lifecycle
221
-
222
- The orchestrator is responsible for managing the epic's status throughout
223
- execution. Epics follow the same status machine as tasks — they must transition
224
- through `in_progress` to reach `done`.
225
-
226
- ### Start: mark epic `in_progress`
227
-
228
- Immediately after session bootstrap and before dispatching any work, transition
229
- the epic:
230
-
231
- ```bash
232
- trekoon --toon epic update <epic-id> --status in_progress
233
- ```
234
-
235
- This ensures the epic reflects actual state even if execution is interrupted.
236
-
237
- ### Finish: mark epic `done`
238
-
239
- After all tasks are verified done (see cleanup in execution references), mark
240
- the epic complete:
241
-
242
- ```bash
243
- trekoon --toon epic update <epic-id> --status done
244
- ```
245
-
246
- Since the epic is already `in_progress` from the start step, this is a single
247
- valid transition.
248
-
249
- ## Execution mode selection
250
-
251
- Choose the lightest mode that will still move the work forward.
252
-
253
- | Situation | Mode | First move |
254
- |---|---|---|
255
- | One ready task, narrow scope, or user asked to continue personally | Single-agent execution | `session --epic <epic-id>` |
256
- | Multiple ready tasks across separable subsystems or owners | Orchestrated execution | Read `reference/execution.md`, then `task ready --epic <epic-id> --limit 50` |
257
- | User explicitly asked for team execution and Agent Teams are available | Team execution | Read `reference/execution-with-team.md` |
258
-
259
- ## Delegation policy
260
-
261
- Prefer one sub-agent per execution lane, not one sub-agent per tiny task.
262
-
263
- - Spawn sub-agents when 2+ ready tasks are independent, touch different
264
- subsystems, or can be grouped into bounded lanes.
265
- - Keep each lane small enough to verify and report clearly.
266
- - Avoid delegation when the scope is tiny, the tasks are tightly coupled, or the
267
- overhead exceeds the gain.
268
- - When tasks share the same directory roots, owners, or subsystem context, group
269
- them into one lane.
270
-
271
- ## Single-agent execution loop
272
-
273
- Use this loop when one agent should continue the work directly. The primary loop
274
- is: **session → claim → work → task done → repeat**.
275
-
276
- ### 1. Orient with a single call
277
-
278
- ```bash
279
- trekoon --toon session
280
- ```
281
-
282
- If you already know which epic you are working on, scope the session:
283
-
284
- ```bash
285
- trekoon --toon session --epic <epic-id>
286
- ```
287
-
288
- `session` returns diagnostics, sync status, the next ready task with subtrees,
289
- blocker list, and readiness counts in one envelope. Use `--compact` to reduce
290
- output size when you do not need contract metadata:
291
-
292
- ```bash
293
- trekoon --toon --compact session
294
- ```
295
-
296
- **After session returns, follow this decision tree in order:**
297
-
298
- 1. **`recoveryRequired` is true?** → Stop. Run `trekoon --toon init` and
299
- re-check.
300
- 2. **`behind > 0`?** → Sync first: `trekoon --toon sync pull --from main`.
301
- This pulls tracker events (not git commits) so task states are current.
302
- 3. **`pendingConflicts > 0`?** → Resolve before claiming work:
303
- `trekoon --toon sync conflicts list`. For uniform conflicts, batch resolve:
304
- `trekoon --toon sync resolve --all --use ours` (or `--use theirs`). For
305
- mixed conflicts, inspect individually with `sync conflicts show <id>` and
306
- resolve per-conflict.
307
- 4. **Session returned a next task?** → Proceed to step 2 (claim work).
308
- 5. **No next task and unsure what to do?** → Run `trekoon --toon suggest` for
309
- priority-ranked recommendations (see step 1b below).
310
-
311
- ### 1b. Get suggestions when stuck
312
-
313
- When the session has no clear next task, or you are unsure what action to take:
314
-
315
- ```bash
316
- trekoon --toon suggest
317
- trekoon --toon suggest --epic <epic-id>
318
- ```
319
-
320
- `suggest` inspects recovery state, sync status, readiness, and epic progress,
321
- then returns up to 3 suggestions ranked by priority. Each suggestion includes a
322
- category (`recovery`, `sync`, `execution`, `planning`), a reason, and a
323
- ready-to-run command you can execute directly.
324
-
325
- Suggest respects the status machine — it will never recommend an invalid
326
- transition. Use it:
327
- - At session start when `readyCount` is 0 and you need guidance.
328
- - Mid-loop when all tasks are blocked and you need to decide what to unblock.
329
- - Before closing an epic to confirm the right next step.
330
-
331
- ### 1c. Check epic progress
332
-
333
- When you need a quick dashboard before or during work on an epic:
334
-
335
- ```bash
336
- trekoon --toon epic progress <epic-id>
337
- ```
338
-
339
- Returns done/in_progress/blocked/todo counts, ready task count, and the next
340
- candidate. Use this:
341
- - Before starting a work session to gauge how much remains.
342
- - After completing several tasks to report progress to the user.
343
- - To decide whether an epic is ready to be marked done.
344
-
345
- ### 2. Claim work explicitly
346
-
347
- Once you know which task to work on, claim it:
348
-
349
- ```bash
350
- trekoon --toon task update <task-id> --status in_progress
351
- ```
352
-
353
- Optionally assign ownership when multiple agents or people are working:
354
-
355
- ```bash
356
- trekoon --toon task update <task-id> --status in_progress --owner <name>
357
- ```
358
-
359
- Owner is for tracking who is responsible. Set it on tasks or subtasks:
360
-
361
- ```bash
362
- trekoon --toon task update <task-id> --owner alice
363
- trekoon --toon subtask update <subtask-id> --owner bob
364
- ```
365
-
366
- ### 3. Work on the task
367
-
368
- While working, append progress notes:
369
-
370
- ```bash
371
- trekoon --toon task update <task-id> --append "Started implementation"
372
- trekoon --toon task update <task-id> --append "Blocked by <reason>" --status blocked
373
- ```
374
-
375
- ### 3b. Work on subtasks explicitly when they matter
376
-
377
- Use the same status discipline for subtasks when a task depends on concrete
378
- subtask progress:
379
-
380
- ```bash
381
- trekoon --toon subtask update <subtask-id> --status in_progress
382
- trekoon --toon subtask update <subtask-id> --append "Implemented parser branch"
383
- trekoon --toon subtask update <subtask-id> --append "Verified with fixture set" --status done
384
- trekoon --toon subtask update <subtask-id> --append "Blocked by <reason>" --status blocked
385
- ```
386
-
387
- Use subtasks for real execution units, not filler. If a task has open subtasks
388
- when `task done` is called, treat the warning as a prompt to consciously decide
389
- whether the task is genuinely complete.
390
-
391
- ### 4. Finish or report a block
392
-
393
- When done, append a completion note then mark done:
394
-
395
- ```bash
396
- trekoon --toon task update <task-id> --append "Completed implementation and checks"
397
- trekoon --toon task done <task-id>
398
- ```
399
-
400
- `task done` works from any non-done status (`todo`, `in_progress`, `blocked`).
401
- It auto-transitions through `in_progress` when needed. The response includes:
402
-
403
- - **Next candidate**: the next ready task with its full tree and blockers.
404
- - **Unblocked tasks**: downstream tasks that became ready after this completion.
405
- Use this to decide what to claim next or to launch parallel work.
406
- - **Open subtask warning**: if subtasks remain incomplete (completion still
407
- proceeds, but the warning is surfaced so you can decide whether to go back).
408
-
409
- If blocked instead of done:
410
-
411
- ```bash
412
- trekoon --toon task update <task-id> --append "Blocked by <reason>" --status blocked
413
- ```
414
-
415
- ### 5. Repeat
416
-
417
- After `task done`, the returned next-task envelope is sufficient to continue
418
- the loop from step 2. A fresh `session` call is not required mid-loop unless
419
- you need updated diagnostics, sync status, or want to switch epics.
420
-
421
- Run `session` again at the start of each new conversation session.
422
-
423
- **When to use each command during the loop:**
424
-
425
- | Situation | Command |
426
- |---|---|
427
- | Start of session | `session` or `session --epic <id>` |
428
- | Unsure what to do next | `suggest` or `suggest --epic <id>` |
429
- | Quick progress check | `epic progress <epic-id>` |
430
- | Claim a task | `task update <id> --status in_progress` |
431
- | Assign ownership | `task update <id> --owner <name>` |
432
- | Log progress | `task update <id> --append "..."` |
433
- | Mark done | `task done <id>` |
434
- | Report blocker | `task update <id> --append "..." --status blocked` |
435
- | Reduce output noise | Add `--compact` to any command |
436
-
437
- ## Read policy: use the smallest sufficient read
438
-
439
- Use the narrowest command that answers the question.
440
-
441
- | Need | Preferred command |
442
- |---|---|
443
- | Session startup (diagnostics + sync + next task) | `trekoon --toon session` |
444
- | Session scoped to one epic | `trekoon --toon session --epic <epic-id>` |
445
- | Next-action suggestions | `trekoon --toon suggest` |
446
- | Epic progress dashboard | `trekoon --toon epic progress <epic-id>` |
447
- | Next task only | `trekoon --toon task next` |
448
- | A few ready options | `trekoon --toon task ready --limit 5` |
449
- | Direct blockers for one task | `trekoon --toon dep list <task-id>` |
450
- | What this item unblocks | `trekoon --toon dep reverse <task-or-subtask-id>` |
451
- | One full task payload | `trekoon --toon task show <task-id> --all` |
452
- | One full epic tree | `trekoon --toon epic show <epic-id> --all` |
453
- | Repeated text in one scope | `trekoon --toon epic|task|subtask search ...` |
454
-
455
- Avoid broad scans such as `task list --all` or `epic show --all` when
456
- `task next`, `task ready`, `dep list`, `dep reverse`, `suggest`, or `search`
457
- can answer the question more cheaply.
458
-
459
- ## Creation policy: prefer bulk planning workflows
460
-
461
- When creating multiple related records, do not loop through repeated single-item
462
- creates unless only one record is needed.
463
-
464
- ### Which command to use
465
-
466
- | Situation | Preferred command |
467
- |---|---|
468
- | New epic and full graph already known | `trekoon --toon epic create ... --task ... --subtask ... --dep ...` |
469
- | Existing epic needs linked additions | `trekoon --toon epic expand <epic-id> ...` |
470
- | Multiple sibling tasks under one epic | `trekoon --toon task create-many --epic <epic-id> --task ...` |
471
- | Multiple sibling subtasks under one task | `trekoon --toon subtask create-many <task-id> --subtask ...` |
472
- | Multiple dependency edges across existing IDs | `trekoon --toon dep add-many --dep ...` |
473
- | One record only | `epic create`, `task create`, or `subtask create` |
474
-
475
- ### Compact spec escaping rules
476
-
477
- Compact specs (pipe-delimited `--task`, `--subtask`, `--dep` values) use `\` as
478
- the escape character. Only these sequences are valid:
479
-
480
- | Sequence | Produces |
481
- |---|---|
482
- | `\|` | literal `|` (not a field separator) |
483
- | `\\` | literal `\` |
484
- | `\n` | newline |
485
- | `\r` | carriage return |
486
- | `\t` | tab |
487
-
488
- Any other `\X` combination (e.g., `\!`, `\=`, `\$`) is rejected with
489
- `Invalid escape sequence`. To avoid accidental escapes:
490
-
491
- - Do not use `!=` or similar operators in description text; rephrase instead
492
- (e.g., "null does not equal sourceBranch" instead of "null !== sourceBranch").
493
- - If a literal backslash is needed, double it: `\\`.
494
- - When using shell line continuations (`\` at end of line), ensure the next
495
- line's first character is not one that forms an invalid escape with `\`.
496
-
497
- ### Critical temp-key rule
498
-
499
- - Use plain temp keys when declaring records in compact specs, for example
500
- `task-api` or `sub-tests`.
501
- - Refer to those records later in the same invocation as `@task-api` or
502
- `@sub-tests`.
503
- - `@temp-key` references work in same-invocation graph workflows such as
504
- one-shot `epic create` and `epic expand`.
505
- - `dep add-many` does **not** resolve temp keys from earlier commands. Use real
506
- persisted IDs there.
507
-
508
- ### Compact examples
509
-
510
- #### One-shot epic creation
511
-
512
- Use this when the epic does not exist yet and you already know the tree.
513
-
514
- ```bash
515
- trekoon --toon epic create \
516
- --title "Batch command rollout" \
517
- --description "Ship linked planning in one transaction" \
518
- --task "task-api|Design API|Define compact grammar|todo" \
519
- --task "task-cli|Wire CLI|Hook parser and output|todo" \
520
- --subtask "@task-api|sub-tests|Write tests|Cover parser cases|todo" \
521
- --dep "@task-cli|@task-api"
522
- ```
523
-
524
- #### Expand an existing epic
525
-
526
- Use this when the epic already exists and the new batch needs internal links.
527
-
528
- ```bash
529
- trekoon --toon epic expand <epic-id> \
530
- --task "task-docs|Document workflow|Write operator guide|todo" \
531
- --subtask "@task-docs|sub-examples|Add examples|Show canonical flows|todo" \
532
- --dep "@sub-examples|@task-docs"
533
- ```
534
-
535
- #### Create sibling tasks or subtasks
536
-
537
- ```bash
538
- trekoon --toon task create-many --epic <epic-id> \
539
- --task "seed-api|Design API|Define grammar|todo" \
540
- --task "seed-cli|Wire CLI|Hook output|todo"
541
-
542
- trekoon --toon subtask create-many <task-id> \
543
- --subtask "seed-tests|Write tests|Cover happy path|todo" \
544
- --subtask "seed-docs|Document flow|Add notes|todo"
545
- ```
546
-
547
- #### Add dependencies after records already exist
548
-
549
- ```bash
550
- trekoon --toon dep add-many \
551
- --dep "<task-b>|<task-a>" \
552
- --dep "<subtask-c>|<task-b>"
553
- ```
554
-
555
- ## Update policy: prefer append-based progress logging
556
-
557
- Use descriptions as the durable work log. For progress updates, append instead
558
- of rewriting full descriptions.
559
-
560
- Status transitions must follow the status machine (see above). Use `in_progress`
561
- as the intermediate step to reach `done`. Direct `todo → done` is invalid via
562
- `task update`; use `task done` instead, which auto-transitions.
563
-
564
- ### Preferred patterns
565
-
566
- ```bash
567
- trekoon --toon task update <task-id> --append "Started implementation" --status in_progress
568
- trekoon --toon task update <task-id> --append "Completed implementation and checks"
569
- trekoon --toon task done <task-id>
570
- trekoon --toon task update <task-id> --append "Blocked by <reason>" --status blocked
571
- trekoon --toon task update <task-id> --owner alice
572
- ```
573
-
574
- ### Bulk update rules
575
-
576
- - Bulk update is available for `epic update`, `task update`, and
577
- `subtask update`.
578
- - Bulk mode uses `--ids <csv>` or `--all`.
579
- - Bulk mode supports only `--append` and/or `--status`.
580
- - Do not pass a positional ID in bulk mode.
581
- - `--append` and `--description` are mutually exclusive.
582
- - Prefer `--ids` for narrow, explicit updates.
583
- - Use `--all` only for clear maintenance sweeps or when the user explicitly wants
584
- a broad update.
585
-
586
- Examples:
587
-
588
- ```bash
589
- trekoon --toon task update --ids id1,id2 --append "Waiting on release" --status blocked
590
- trekoon --toon epic update --ids epic1,epic2 --append "Sprint planning refreshed" --status in_progress
591
- ```
592
-
593
- ## Search and replace policy
594
-
595
- Use scoped search before manual tree reads when you need to locate repeated
596
- paths, labels, owners, or migration targets.
597
-
598
- ### Scope choice
599
-
600
- Prefer the narrowest valid root:
601
-
602
- 1. `subtask search` or `subtask replace`
603
- 2. `task search` or `task replace`
604
- 3. `epic search` or `epic replace`
605
-
606
- Scope behavior:
607
-
608
- - `subtask` scope scans only that subtask.
609
- - `task` scope scans the task plus descendant subtasks.
610
- - `epic` scope scans the epic plus descendant tasks and subtasks.
611
-
612
- ### Safe replace workflow
613
-
614
- 1. Search first.
615
- 2. Preview replace.
616
- 3. Apply only after preview matches the intended scope.
617
-
618
- ```bash
619
- trekoon --toon epic search <epic-id> "path/to/somewhere"
620
- trekoon --toon epic replace <epic-id> --search "path/to/somewhere" --replace "path/to/new-path"
621
- trekoon --toon epic replace <epic-id> --search "path/to/somewhere" --replace "path/to/new-path" --apply
622
- ```
623
-
624
- Guardrails:
625
-
626
- - Use literal, explicit search text.
627
- - Narrow fields when useful: `--fields title`, `--fields description`, or
628
- `--fields title,description`.
629
- - Do not jump straight to `--apply`.
630
- - Prefer scoped search/replace over manually reading a whole tree and editing
631
- many records one by one.
632
-
633
- ## Setup and fallback
634
-
635
- If Trekoon is unavailable or storage diagnostics require repair:
59
+ | ID only | Orient: `session --epic <epic-id>` or show the item |
60
+ | `status`, `progress`, `analyze`, `review`, `check` | Analyze: `epic progress`, targeted show, then `suggest --epic` |
61
+ | `plan`, `break down`, `design`, `architect` | Plan |
62
+ | `execute`, `implement`, `do`, `complete`, `start`, `run` | Execute |
63
+ | `team execute`, `execute with team` | Team execute |
64
+
65
+ ## Completion Rules
66
+
67
+ - Plan mode is complete only when the epic exists, tasks/subtasks/dependencies
68
+ exist in Trekoon, the graph is validated, and the user gets the epic ID plus
69
+ first execution wave.
70
+ - Orient mode is complete when the user knows current state, blockers, ready
71
+ work, and the likely next command.
72
+ - Execute mode is complete only when the epic is marked `done`, all remaining
73
+ work is blocked with recorded reasons, or real user input is required.
74
+
75
+ ## Execution Defaults
76
+
77
+ - Start with `trekoon --toon session`; scope with `--epic <id>` when known.
78
+ - If ready work exists, keep moving. After each `task done`, inspect
79
+ `unblocked`, `warning`/`openSubtaskIds`, and `next`.
80
+ - When executing an epic, use subagents by default for any meaningful work that
81
+ can run independently. Keep small or tightly coupled tasks in the parent
82
+ agent.
83
+ - Use your context for orchestration, dependency decisions, user communication,
84
+ and final synthesis. Your job is to finish the epic, not personally perform
85
+ every implementation step.
86
+ - If a higher-priority harness rule blocks subagents without explicit user
87
+ wording, ask immediately and explain that Trekoon execution preserves the
88
+ parent context for orchestration.
89
+ - For non-trivial implementation, run relevant tests and a separate review pass
90
+ when a review agent/skill is available. Record checks and review results in
91
+ Trekoon before closing work.
92
+
93
+ ## Non-Negotiables
94
+
95
+ - Use `--toon` on every Trekoon command.
96
+ - Treat Trekoon updates as workflow state, not after-the-fact bookkeeping.
97
+ - Prefer smallest sufficient reads: `session`, `suggest`, `task ready`,
98
+ `task next`, `dep list`, `dep reverse`, targeted `show`.
99
+ - Prefer transactional/bulk commands for planning and narrow `--ids` for bulk
100
+ updates.
101
+ - Append progress, verification, and blocker notes with `--append`; do not
102
+ rewrite descriptions unless fixing the plan itself.
103
+ - Preview search/replace before `--apply`.
104
+ - Never edit `.trekoon/trekoon.db` directly. Keep `.trekoon` gitignored.
105
+ - Never run `trekoon wipe --yes --toon` unless the user explicitly asks.
106
+ - Create branches, commits, merges, pushes, or PRs only when the user explicitly
107
+ asks and the harness policy allows it.
108
+ - Use `--compact` in subagent prompts and noisy reads.
109
+
110
+ ## Status Reminder
111
+
112
+ Normal status flow is `todo -> in_progress -> done`; `blocked` requires an
113
+ appended reason. Use `task done` for task completion because it auto-transitions
114
+ from `todo` or `blocked` through `in_progress`. Load
115
+ `reference/status-machine.md` for transition errors or uncertainty.
116
+
117
+ ## Recovery
118
+
119
+ If Trekoon diagnostics show `recoveryRequired`, stop task selection and run:
636
120
 
637
121
  ```bash
638
122
  trekoon --toon init
639
123
  trekoon --toon sync status
640
- trekoon --toon quickstart
641
- trekoon --toon help sync
642
- ```
643
-
644
- Rules:
645
-
646
- - Re-bootstrap first, then re-read diagnostics.
647
- - Stop if `recoveryRequired` stays true or diagnostics report storage mismatch.
648
- - Do not continue with task selection after missing shared storage or broken
649
- bootstrap.
650
- - Do not commit `.trekoon/trekoon.db`; remove the tracked DB and keep
651
- `.trekoon` ignored instead.
652
-
653
- Use `session` as the primary entry point — it returns diagnostics, sync status,
654
- and the next ready task in one call. Use `suggest` for priority-ranked
655
- recommendations. Use `quickstart` for the canonical bootstrapping walkthrough
656
- and execution loop reference. Use `help` when you need exact flag syntax for a
657
- specific command.
658
-
659
- ## Sync reminders
660
-
661
- Same-branch sync is a no-op: `sync pull --from main` while on `main` produces
662
- zero conflicts and simply advances the cursor. `sync status` returns `behind=0`
663
- on the source branch. No action is needed.
664
-
665
- Cross-branch sync matters before merging a feature branch back:
666
-
667
- - Before merge, pull tracker events from the base branch:
668
-
669
- ```bash
670
- trekoon --toon sync pull --from main
671
- ```
672
-
673
- - If conflicts exist, inspect and resolve them explicitly:
674
-
675
- ```bash
676
- trekoon --toon sync conflicts list
677
- trekoon --toon sync conflicts show <conflict-id>
678
- trekoon --toon sync resolve <conflict-id> --use theirs --dry-run
679
- trekoon --toon sync resolve <conflict-id> --use ours
680
- ```
681
-
682
- ### Conflict resolution: ours vs theirs
683
-
684
- Conflicts are **field-level**, not whole-record. Each conflict targets one field
685
- (e.g., `status`, `title`, `description`) on one entity.
686
-
687
- - `--use ours` — keep the current entity field value in the shared DB. The
688
- entity is not written, but the conflict record is marked resolved and a
689
- resolution event is appended.
690
- - `--use theirs` — overwrite the shared DB entity field with the source-branch
691
- value. The conflict record is marked resolved and a resolution event is
692
- appended.
693
- - `--dry-run` — preview the resolution without mutating the database. Returns
694
- `oursValue`, `theirsValue`, `wouldWrite`, and `dryRun: true`. Use this before
695
- committing to a resolution.
696
-
697
- **Example:** after `sync pull --from main`, a conflict appears on epic `abc123`,
698
- field `status`:
699
- - ours (current DB): `in_progress`
700
- - theirs (source branch): `done`
701
- - `--use ours` keeps status as `in_progress`
702
- - `--use theirs` changes status to `done` in the live shared DB
703
-
704
- Always inspect conflicts with `sync conflicts show` before resolving. Choosing
705
- `theirs` without inspection can overwrite in-progress work in the shared DB.
706
-
707
- ### Understanding why conflicts happen
708
-
709
- | Scenario | Typical resolution | Why |
710
- |---|---|---|
711
- | Completed work vs stale main state | ours | Your branch has the latest progress |
712
- | Enriched descriptions vs original | ours | Your descriptions are more detailed |
713
- | Upstream updates from another agent | theirs | Accept the newer upstream state |
714
- | User-intentional reset | theirs | Respect the user's explicit action |
715
-
716
- ### Agent decision framework
717
-
718
- 1. List conflicts: `trekoon --toon sync conflicts list`
719
- 2. Group by pattern — are conflicts on the same field or direction?
720
- 3. If uniform pattern, batch resolve: `trekoon --toon sync resolve --all --use ours`
721
- 4. If mixed, narrow by entity or field, or inspect individually
722
- 5. When unsure, ask the user
723
-
724
- ### Batch resolve patterns
725
-
726
- Common scenarios:
727
-
728
- ```bash
729
- # Resolve all conflicts at once (most common after completing work)
730
- trekoon --toon sync resolve --all --use ours
731
-
732
- # Preview before resolving
733
- trekoon --toon sync resolve --all --use ours --dry-run
734
-
735
- # Narrow to status field conflicts only
736
- trekoon --toon sync resolve --all --use ours --field status
737
-
738
- # Narrow to a specific entity
739
- trekoon --toon sync resolve --all --use theirs --entity <id>
740
-
741
- # Combine filters
742
- trekoon --toon sync resolve --all --use ours --entity <id> --field description
743
124
  ```
744
125
 
745
- ## Shared-database model
746
-
747
- Trekoon uses **one live SQLite database per repository**. The file lives at
748
- `<sharedStorageRoot>/.trekoon/trekoon.db`, where `sharedStorageRoot` is the
749
- parent of `git rev-parse --git-common-dir` (i.e., the main worktree root).
750
-
751
- Key consequences:
752
-
753
- - **All linked worktrees share the same database.** A status change in one
754
- worktree is immediately visible in every other worktree.
755
- - **`git checkout` / `git switch` does not change tracker state.** The database
756
- is outside the git object store, so switching branches does not roll back or
757
- swap task data.
758
- - **Sync operates on tracker events, not on the database file itself.** Use
759
- `sync pull` to import events between branches — never copy or commit the
760
- `.db` file.
761
-
762
- Treat every write as a mutation of shared repo-wide state, not branch-scoped
763
- state.
764
-
765
- ## Worktree diagnostics and destructive scope
766
-
767
- - Inspect machine-readable storage fields when debugging worktrees:
768
- `storageMode`, `repoCommonDir`, `worktreeRoot`, `sharedStorageRoot`, and
769
- `databaseFile`.
770
- - `sharedStorageRoot` is the repo-scoped source of truth for `.trekoon` in git
771
- worktrees.
772
- - If `trekoon wipe --yes --toon` is explicitly requested, warn that it deletes
773
- shared storage for the entire repository and every linked worktree.
774
- - Wipe is destructive recovery only; it is never the right fix for a tracked DB
775
- or gitignore mistake.
776
-
777
- Trekoon stores local state in `.trekoon/trekoon.db`. In git repos and
778
- worktrees, storage resolves from the shared repository root rather than each
779
- worktree independently.
780
-
781
- ## Tool capability guidance
782
-
783
- Inspect your available tools before assuming names. Prefer capability-based
784
- selection over harness-specific tool names.
785
-
786
- - Use your harness's structured file search and file read tools instead of shell
787
- commands for code inspection whenever possible.
788
- - Use symbol-aware tools when available; fall back to content search when they
789
- are not.
790
- - Run Trekoon commands, build/lint/test flows, and explicit git operations via
791
- your shell tool.
792
- - Use `--compact` on Trekoon commands in sub-agent prompts to reduce token
793
- usage.
794
-
795
- ## User manual input:
126
+ If sync is behind or conflicts exist, resolve that before claiming work. Load
127
+ `reference/sync.md` for conflict handling.