@selesai/code 0.3.10 → 0.5.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 (80) hide show
  1. package/dist/core/agent-session-auto-handoff.test.d.ts +2 -0
  2. package/dist/core/agent-session-auto-handoff.test.d.ts.map +1 -0
  3. package/dist/core/agent-session-auto-handoff.test.js +161 -0
  4. package/dist/core/agent-session-auto-handoff.test.js.map +1 -0
  5. package/dist/core/agent-session.d.ts +4 -0
  6. package/dist/core/agent-session.d.ts.map +1 -1
  7. package/dist/core/agent-session.js +43 -0
  8. package/dist/core/agent-session.js.map +1 -1
  9. package/dist/core/settings-manager-auto-handoff.test.d.ts +2 -0
  10. package/dist/core/settings-manager-auto-handoff.test.d.ts.map +1 -0
  11. package/dist/core/settings-manager-auto-handoff.test.js +29 -0
  12. package/dist/core/settings-manager-auto-handoff.test.js.map +1 -0
  13. package/dist/core/settings-manager.d.ts +9 -0
  14. package/dist/core/settings-manager.d.ts.map +1 -1
  15. package/dist/core/settings-manager.js +22 -0
  16. package/dist/core/settings-manager.js.map +1 -1
  17. package/dist/defaults/models.json +2 -3
  18. package/dist/extensions/caveman/index.js +16 -1
  19. package/dist/extensions/caveman/test/extension.test.js +7 -4
  20. package/dist/extensions/caveman/test/helpers.test.js +12 -1
  21. package/dist/extensions/context-compaction-reminder.test.ts +82 -0
  22. package/dist/extensions/context-compaction-reminder.ts +28 -0
  23. package/dist/extensions/handoff-new.test.ts +2 -13
  24. package/dist/extensions/handoff-new.ts +16 -25
  25. package/dist/extensions/package.json +1 -0
  26. package/dist/extensions/pi-powerline-footer/index.ts +43 -2
  27. package/dist/extensions/pi-powerline-footer/session-usage.ts +44 -0
  28. package/dist/extensions/pi-powerline-footer/tests/session-usage.test.ts +47 -0
  29. package/dist/extensions/pi-subagents/README.md +1 -1
  30. package/dist/extensions/pi-subagents/agents/architect.md +9 -29
  31. package/dist/extensions/pi-subagents/agents/builder.md +17 -106
  32. package/dist/extensions/pi-subagents/agents/commentator.md +20 -117
  33. package/dist/extensions/pi-subagents/agents/explorer.md +14 -35
  34. package/dist/extensions/pi-subagents/agents/recapper.md +20 -12
  35. package/dist/extensions/pi-subagents/agents/researcher.md +11 -34
  36. package/dist/extensions/pi-subagents/src/agents/agents.ts +46 -0
  37. package/dist/extensions/pi-subagents/src/extension/index.ts +2 -1
  38. package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +2 -0
  39. package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +24 -0
  40. package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +25 -1
  41. package/dist/extensions/question/constants.ts +0 -7
  42. package/dist/extensions/question/index.ts +11 -108
  43. package/dist/extensions/question/schemas.ts +1 -26
  44. package/dist/extensions/question/shortcuts.ts +5 -14
  45. package/dist/extensions/question/tests/question-list.test.ts +8 -0
  46. package/dist/extensions/question/tests/ui-protocol.test.ts +1 -7
  47. package/dist/extensions/question/tui-adapter.ts +3 -20
  48. package/dist/extensions/question/types.ts +0 -6
  49. package/dist/extensions/question/ui-protocol.ts +2 -17
  50. package/dist/extensions/workflow/adapter.ts +395 -275
  51. package/dist/extensions/workflow/extension.ts +2 -1
  52. package/dist/extensions/workflow/modes/prototype.ts +17 -19
  53. package/dist/extensions/workflow/modes/quick.ts +17 -19
  54. package/dist/extensions/workflow/modes/task.ts +82 -0
  55. package/dist/extensions/workflow/run-state.ts +124 -0
  56. package/dist/extensions/workflow/state-machine.ts +7 -8
  57. package/dist/extensions/workflow/task-validators.ts +69 -0
  58. package/dist/index.d.ts +1 -1
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js.map +1 -1
  61. package/dist/modes/interactive/components/settings-selector.d.ts +4 -0
  62. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  63. package/dist/modes/interactive/components/settings-selector.js +20 -0
  64. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  65. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  66. package/dist/modes/interactive/interactive-mode.js +8 -0
  67. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  68. package/dist/modes/rpc/rpc-client.d.ts +8 -0
  69. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  70. package/dist/modes/rpc/rpc-client.js +12 -0
  71. package/dist/modes/rpc/rpc-client.js.map +1 -1
  72. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  73. package/dist/modes/rpc/rpc-mode.js +14 -0
  74. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  75. package/dist/modes/rpc/rpc-types.d.ts +20 -0
  76. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  77. package/dist/modes/rpc/rpc-types.js.map +1 -1
  78. package/dist/skills/workflow-creation/SKILL.md +72 -0
  79. package/docs/workflows.md +46 -7
  80. package/package.json +1 -1
package/docs/workflows.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Workflows
2
2
 
3
- Selesai ships a workflow engine under `src/extensions/workflow/`. It powers the built-in `prototype` and `quick` workflows and is designed so you can add a new workflow mode as a thin config file — no engine changes.
3
+ Selesai ships a workflow engine under `src/extensions/workflow/`. It powers the built-in `prototype`, `quick`, and `task` workflows and is designed so you can add a new workflow mode as a thin config file — no engine changes.
4
4
 
5
5
  ## How it fits together
6
6
 
@@ -8,15 +8,18 @@ Selesai ships a workflow engine under `src/extensions/workflow/`. It powers the
8
8
  src/extensions/workflow/
9
9
  package.json pi package manifest; loads ./extension.ts as the single entry
10
10
  state-machine.ts pure phase state machine (no fs, no pi API)
11
- adapter.ts pi wiring: tools, commands, events, fs, agent continuation
11
+ adapter.ts pi wiring: tools, commands, events, fs, durable-state lifecycle
12
+ run-state.ts versioned atomic workflow.json load/save/discovery
12
13
  extension.ts single pi extension that mounts every workflow mode
13
14
  modes/
14
15
  prototype.ts mode config + registration object (exported as `prototypeMode`)
15
16
  quick.ts mode config + registration object (exported as `quickMode`)
17
+ task.ts mode config + registration object (exported as `taskMode`)
16
18
  ```
17
19
 
18
20
  - **`state-machine.ts`** is the deep module. It owns the phase graph, artifact gating, skip rules, the terminal close gate, and the reentrancy guard. It imports nothing external — no `node:fs`, no pi API, no `pi-tui`, no `typebox`. Every method returns a `WorkflowEffect` (a discriminated union in domain vocabulary) that the adapter pattern-matches on.
19
- - **`adapter.ts`** is the thin glue. One state-machine method per call site (`start` tool, `end` tool, `tool_result` auto-advance, `/<command>`) plus one `applyEffect` switch. It owns all pi/fs wiring and the git-based `reuse` skip predicate. There is no `next` tool — phase advance is automatic once the phase artifact lands, and terminal close is via the `end` tool.
21
+ - **`adapter.ts`** is the thin glue. It owns Pi/fs wiring, durable state, explicit resume, loop review persistence, and the git-based `reuse` skip predicate. Parent-written artifacts advance durable phase state. `prototype` and `quick` stop at user-controlled boundaries; `task` queues its build loop as soon as its plan is ready.
22
+ - **`workflow.json`** in each artifact directory is the canonical, versioned run record. It is atomically replaced after state changes; session custom entries are only pointers for UI/history and never reconstruct an active run.
20
23
  - **`extension.ts`** imports each mode's registration object and calls `createWorkflowExtension(config, options)(pi)` for each, so one extension load resolves a single shared writer tool + one start/end tool pair per mode.
21
24
  - **A mode file** is pure data: the phase list, the per-phase artifact filenames, the per-phase prompt generators, the terminal close artifacts, and identity strings (tool names, command name, status key, entry type). Prompts are functions that receive `{ artifactDir, userPrompt }` and return a string. Each mode exports a `WorkflowModeRegistration` object (e.g. `prototypeMode`, `quickMode`); it does not call `createWorkflowExtension` itself.
22
25
 
@@ -90,10 +93,12 @@ export const rigorousMode: WorkflowModeRegistration = {
90
93
  "Run the rigorous workflow (grill → spec → research → plan → reuse → handoff → loop → audit → sign-off)",
91
94
  toolNames: {
92
95
  start: "start_rigorous_workflow",
96
+ resume: "resume_rigorous_workflow",
93
97
  end: "end_rigorous_workflow",
94
98
  },
95
99
  toolLabels: {
96
100
  start: "Start Rigorous Workflow",
101
+ resume: "Resume Rigorous Workflow",
97
102
  end: "End Rigorous Workflow",
98
103
  },
99
104
  };
@@ -111,7 +116,21 @@ import { rigorousMode } from "./modes/rigorous.ts";
111
116
  const MODES = [prototypeMode, quickMode, rigorousMode] as const;
112
117
  ```
113
118
 
114
- That's it. The loader picks it up at boot (`package.json` loads only `./extension.ts`); the two tools (`start_rigorous_workflow`, `end_rigorous_workflow`) and the `/rigorous` command are registered automatically. There is no `next` tool — phases auto-advance as artifacts land and the `end` tool closes the terminal phase.
119
+ That's it. The loader picks it up at boot (`package.json` loads only `./extension.ts`); start/resume/end tools and the `/rigorous` command are registered automatically. There is no `next` tool — phases auto-advance as artifacts land and only the `end` tool completes the terminal phase.
120
+
121
+ ## Built-in modes
122
+
123
+ ### `task` — rapid plan + build/review loop
124
+
125
+ The simplest workflow: an architect subagent produces a validated `plan.md`, then a builder↔commentator review loop runs (max 3 blocking rounds). A clean review makes the workflow terminal-ready; `end_task_workflow` completes it.
126
+
127
+ Lifecycle: `plan → loop (build ↔ review) → terminal-ready → end_task_workflow`
128
+
129
+ - `/workflow-task <goal>` — start a new run
130
+ - `/workflow-task resume` — list and resume active runs
131
+ - `/workflow-task help` — show the lifecycle
132
+ - Its ready plan automatically queues the builder↔review loop
133
+ - No grilling, research, reuse, or handoff phases
115
134
 
116
135
  ## Config reference
117
136
 
@@ -124,8 +143,9 @@ That's it. The loader picks it up at boot (`package.json` loads only `./extensio
124
143
  | `closeArtifacts` | `string[]` | Files that must exist before `end()` succeeds. Config-owned, no built-in default. |
125
144
  | `skipRules?` | `{ phase, shouldSkip }[]` | Optional per-phase skip rules. `shouldSkip` is a boolean predicate; when true the engine skips to the next phase. Omit to use the adapter's default (skip `reuse` on empty projects). |
126
145
  | `statusKey` | `string` | Footer status key. |
127
- | `entryType` | `string` | Persisted entry custom-type, used for session resume. |
146
+ | `entryType` | `string` | Session-history custom-type. It stores a pointer only; `workflow.json` is canonical. |
128
147
  | `footerLabel` | `string` | Label shown in the footer (`● label · step/total phase`). |
148
+ | `continueAfterArtifact?` | `boolean` | Queue the next phase prompt after the parent writes a valid artifact. `task` enables this for plan → build. |
129
149
 
130
150
  ### Adapter options
131
151
 
@@ -133,12 +153,31 @@ The second argument to `createWorkflowExtension`:
133
153
 
134
154
  | Field | Description |
135
155
  |---|---|
136
- | `toolNames` | `{ start, end }` — the two registered tool names. There is no `next` tool; phases auto-advance as artifacts land. |
156
+ | `toolNames` | `{ start, resume, end }` — registered tool names. Artifacts advance phase state; the user explicitly continues the attached run. |
137
157
  | `toolLabels` | Human-readable labels for the tools. |
138
158
  | `commandName` | The `/<command>` name users type to kick off the workflow. |
139
159
  | `commandDescription` | Description shown in the command list. |
140
160
 
141
- ## How transitions work
161
+ ## Durable runs and explicit resume
162
+
163
+ Each started workflow receives a UUID artifact directory under `.selesai/artifacts/` and an adjacent `workflow.json`. It stores the mode, phase, armed state, loop round/review path, and timestamps. Writes use a temporary sibling file plus rename, so a crash cannot partially overwrite the canonical record.
164
+
165
+ Runs are **never** auto-resumed on session start. At most one run can be attached to a Pi instance, but older active runs remain resumable:
166
+
167
+ - `resume_workflow({ run: "<id-or-path>" })` / `resume_quick_workflow(...)` / `resume_task_workflow(...)`
168
+ - `/workflow-prototype resume <id-or-artifact-dir-or-workflow.json>` / `/workflow-quick resume ...` / `/workflow-task resume ...`
169
+ - `/workflow-prototype resume`, `/workflow-quick resume`, or `/workflow-task resume` lists active runs (and offers a UI picker when available).
170
+ - `/workflow-prototype help`, `/workflow-quick help`, or `/workflow-task help` shows the start, resume, continue, and explicit-completion lifecycle.
171
+
172
+ Resume validates the selected file is under the artifacts base, belongs to that mode, is active, and matches its containing directory. It reconciles the current expected artifact once before emitting the current prompt, covering a crash after `write_workflow_artifact` writes the file but before the phase-state write. Artifact writes do not inject the next phase prompt or launch the next subagent; they terminate the parent turn and wait for the user to continue. A mode can opt out of that pause after a parent artifact write; `task` does so after `plan.md` so the build loop starts immediately. Corrupt records are skipped during discovery.
173
+
174
+ A valid terminal artifact makes a workflow **terminal-ready**; it does not complete the run. Call the mode-specific `end_*_workflow` tool to write `status: "completed"`, append the done entry, and terminate. This is the only completion path.
175
+
176
+ ## Artifact ownership
177
+
178
+ Workflow artifacts have one writer: the parent session's `write_workflow_artifact` tool. Every workflow child call uses `output: false` and returns inline. In artifact phases (`plan`, `reuse`, `handoff`, and `audit`), the parent inspects that result, validates any required marker, and immediately passes it to `write_workflow_artifact`. Child output paths and fallback persistence are deliberately disabled; a child result alone cannot create an artifact or advance a phase.
179
+
180
+ The implement/review loop is the explicit exception to parent persistence, not inline return: the engine persists `loop-review-<round>.md` and `loop-complete.md` from commentator results so it can manage review rounds. Builders only change workspace code.
142
181
 
143
182
  Every state-machine method returns a `WorkflowEffect` — a discriminated union the adapter switches on:
144
183
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selesai/code",
3
- "version": "0.3.10",
3
+ "version": "0.5.0",
4
4
  "description": "Selesai coding agent",
5
5
  "type": "module",
6
6
  "piConfig": {