@igorjpimenta/winch 0.0.0-stage → 2026.11.22-beta.2
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.
- package/.migrations/0000_next_katie_power.sql +99 -0
- package/.migrations/0001_add-events-kind.sql +8 -0
- package/.migrations/0002_drop-session-budgets.sql +1 -0
- package/.migrations/0003_pink_siren.sql +8 -0
- package/.migrations/0004_salty_trauma.sql +1 -0
- package/.migrations/0005_classy_havok.sql +1 -0
- package/.migrations/0006_recursive_items.sql +265 -0
- package/.migrations/0007_unify_statuses.sql +35 -0
- package/.migrations/0008_core_dispatch.sql +61 -0
- package/.migrations/0009_webhooks.sql +17 -0
- package/.migrations/0010_dispatch_consumer_id.sql +1 -0
- package/.migrations/0011_dispatch_delivery_leases.sql +53 -0
- package/.migrations/0012_dispatch_fencing_audit.sql +32 -0
- package/.migrations/meta/0000_snapshot.json +658 -0
- package/.migrations/meta/0001_snapshot.json +665 -0
- package/.migrations/meta/0002_snapshot.json +604 -0
- package/.migrations/meta/0003_snapshot.json +656 -0
- package/.migrations/meta/0004_snapshot.json +664 -0
- package/.migrations/meta/0005_snapshot.json +671 -0
- package/.migrations/meta/0006_snapshot.json +1089 -0
- package/.migrations/meta/0007_unify_statuses_snapshot.json +1097 -0
- package/.migrations/meta/0008_snapshot.json +1382 -0
- package/.migrations/meta/0009_snapshot.json +1428 -0
- package/.migrations/meta/0010_snapshot.json +1435 -0
- package/.migrations/meta/0011_snapshot.json +1670 -0
- package/.migrations/meta/0012_snapshot.json +1900 -0
- package/.migrations/meta/_journal.json +97 -0
- package/README.md +480 -2
- package/bin/winch.js +4 -0
- package/package.json +36 -4
- package/plugins/README.md +304 -0
- package/plugins/openclaw/winch/README.md +71 -0
- package/plugins/openclaw/winch/dispatch.js +236 -0
- package/plugins/openclaw/winch/index.js +139 -0
- package/plugins/openclaw/winch/meta.js +35 -0
- package/plugins/openclaw/winch/openclaw.plugin.json +43 -0
- package/plugins/openclaw/winch/package.json +37 -0
- package/plugins/opencode/winch/dispatch.js +228 -0
- package/plugins/opencode/winch/hooks.js +22 -0
- package/plugins/opencode/winch/identity.js +34 -0
- package/plugins/opencode/winch/index.js +104 -0
- package/plugins/opencode/winch/package.json +26 -0
- package/src/cli.js +434 -0
- package/src/config.js +181 -0
- package/src/db.js +39 -0
- package/src/deps.js +70 -0
- package/src/dispatch-server.js +204 -0
- package/src/dispatch-webhook.js +221 -0
- package/src/dispatch.js +258 -0
- package/src/events-ws.js +269 -0
- package/src/identity.js +140 -0
- package/src/ids.js +18 -0
- package/src/mcp-http.js +208 -0
- package/src/mcp.js +107 -0
- package/src/merges.js +150 -0
- package/src/paths.js +15 -0
- package/src/ready-queue.js +77 -0
- package/src/release.js +96 -0
- package/src/reserved.js +23 -0
- package/src/schema.js +302 -0
- package/src/store/admission.js +314 -0
- package/src/store/artifacts.js +24 -0
- package/src/store/attempts.js +22 -0
- package/src/store/claims.js +182 -0
- package/src/store/core.js +225 -0
- package/src/store/delivery.js +137 -0
- package/src/store/deps.js +62 -0
- package/src/store/dispatch-events.js +38 -0
- package/src/store/epics.js +31 -0
- package/src/store/events.js +21 -0
- package/src/store/gates.js +85 -0
- package/src/store/index.js +135 -0
- package/src/store/items.js +303 -0
- package/src/store/stories.js +37 -0
- package/src/store/sweep.js +77 -0
- package/src/store/tasks.js +190 -0
- package/src/store/webhook.js +197 -0
- package/src/tools/accept-wake.js +30 -0
- package/src/tools/assign.js +75 -0
- package/src/tools/claim.js +88 -0
- package/src/tools/definitions.js +371 -0
- package/src/tools/delegate.js +147 -0
- package/src/tools/index.js +44 -0
- package/src/tools/plan.js +262 -0
- package/src/tools/read.js +103 -0
- package/src/tools/report.js +190 -0
- package/src/tools/shared.js +62 -0
- package/src/watcher.js +105 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "7",
|
|
3
|
+
"dialect": "sqlite",
|
|
4
|
+
"entries": [
|
|
5
|
+
{
|
|
6
|
+
"idx": 0,
|
|
7
|
+
"version": "6",
|
|
8
|
+
"when": 1792607841256,
|
|
9
|
+
"tag": "0000_next_katie_power",
|
|
10
|
+
"breakpoints": true
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"idx": 1,
|
|
14
|
+
"version": "6",
|
|
15
|
+
"when": 1792609467403,
|
|
16
|
+
"tag": "0001_add-events-kind",
|
|
17
|
+
"breakpoints": true
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"idx": 2,
|
|
21
|
+
"version": "6",
|
|
22
|
+
"when": 1792612691655,
|
|
23
|
+
"tag": "0002_drop-session-budgets",
|
|
24
|
+
"breakpoints": true
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"idx": 3,
|
|
28
|
+
"version": "6",
|
|
29
|
+
"when": 1792976641974,
|
|
30
|
+
"tag": "0003_pink_siren",
|
|
31
|
+
"breakpoints": true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"idx": 4,
|
|
35
|
+
"version": "6",
|
|
36
|
+
"when": 1793057586708,
|
|
37
|
+
"tag": "0004_salty_trauma",
|
|
38
|
+
"breakpoints": true
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"idx": 5,
|
|
42
|
+
"version": "6",
|
|
43
|
+
"when": 1793063101061,
|
|
44
|
+
"tag": "0005_classy_havok",
|
|
45
|
+
"breakpoints": true
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"idx": 6,
|
|
49
|
+
"version": "6",
|
|
50
|
+
"when": 1793063102061,
|
|
51
|
+
"tag": "0006_recursive_items",
|
|
52
|
+
"breakpoints": true
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"idx": 7,
|
|
56
|
+
"version": "6",
|
|
57
|
+
"when": 1794853886035,
|
|
58
|
+
"tag": "0007_unify_statuses",
|
|
59
|
+
"breakpoints": true
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"idx": 8,
|
|
63
|
+
"version": "6",
|
|
64
|
+
"when": 1794919676933,
|
|
65
|
+
"tag": "0008_core_dispatch",
|
|
66
|
+
"breakpoints": true
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"idx": 9,
|
|
70
|
+
"version": "6",
|
|
71
|
+
"when": 1794936798231,
|
|
72
|
+
"tag": "0009_webhooks",
|
|
73
|
+
"breakpoints": true
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"idx": 10,
|
|
77
|
+
"version": "6",
|
|
78
|
+
"when": 1795035490048,
|
|
79
|
+
"tag": "0010_dispatch_consumer_id",
|
|
80
|
+
"breakpoints": true
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"idx": 11,
|
|
84
|
+
"version": "6",
|
|
85
|
+
"when": 1795046978440,
|
|
86
|
+
"tag": "0011_dispatch_delivery_leases",
|
|
87
|
+
"breakpoints": true
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"idx": 12,
|
|
91
|
+
"version": "6",
|
|
92
|
+
"when": 1795056387292,
|
|
93
|
+
"tag": "0012_dispatch_fencing_audit",
|
|
94
|
+
"breakpoints": true
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}
|
package/README.md
CHANGED
|
@@ -1,3 +1,481 @@
|
|
|
1
|
-
#
|
|
1
|
+
# winch
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Pull-based delivery backlog for coding agents.**
|
|
4
|
+
|
|
5
|
+
Winch is a pull-based delivery backlog - epic to story to task with a dependency
|
|
6
|
+
DAG - served as an MCP server. The spec lives in the records: a planner writes
|
|
7
|
+
it once, a worker reads it, claims atomically, and reports back. `serve --ws`
|
|
8
|
+
streams every store event, so a harness wakes agents from the queue instead of
|
|
9
|
+
polling it.
|
|
10
|
+
|
|
11
|
+
Winch is harness-agnostic: the server contains no harness-specific code. The
|
|
12
|
+
adapters under `plugins/` are optional and installed per harness; the MCP
|
|
13
|
+
contract itself is the only integration surface.
|
|
14
|
+
|
|
15
|
+
- **Spec in the records** - goal, acceptance criteria, dependencies, capabilities all written once by the planner.
|
|
16
|
+
- **Atomic claim** - CAS under a lease; highest-priority ready task selected when no id is given.
|
|
17
|
+
- **Dependency DAG** - forward-only deps, cycle-checked, cancelled deps count as resolved.
|
|
18
|
+
- **Event stream** - every store insert broadcast over WebSocket; subscribers wake agents, no polling.
|
|
19
|
+
- **Human gates** - block/resume with gate types; one resume per gate, actor-checked.
|
|
20
|
+
- **Content-addressed evidence** - artifacts recorded on close, carried into downstream handoffs.
|
|
21
|
+
|
|
22
|
+
It is local-first and harness-neutral: OpenCode, OpenClaw and future harnesses
|
|
23
|
+
are adapters, not the product. A work order is self-contained - no external
|
|
24
|
+
planner task id is required. Stable releases publish since `2026.11.9`.
|
|
25
|
+
|
|
26
|
+
[Why the name?](#why-the-name)
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
Requires Node.js 22+.
|
|
31
|
+
|
|
32
|
+
npm install -g @igorjpimenta/winch
|
|
33
|
+
winch --version
|
|
34
|
+
|
|
35
|
+
The harness adapters publish on their own release lines and can use the same or
|
|
36
|
+
different winch versions than the daemon:
|
|
37
|
+
`@igorjpimenta/winch-openclaw` and `@igorjpimenta/winch-opencode`.
|
|
38
|
+
A `beta` dist-tag tracks prereleases (`YYYY.MM.DD-beta.N`); until an adapter's
|
|
39
|
+
first stable exists, its versionless install serves the newest beta.
|
|
40
|
+
|
|
41
|
+
From source instead: `npm install`, then `./bin/winch.js <command>` - or
|
|
42
|
+
`npm link` for a global `winch`.
|
|
43
|
+
|
|
44
|
+
## Quick start
|
|
45
|
+
|
|
46
|
+
Start the daemon and claim your first work order:
|
|
47
|
+
|
|
48
|
+
WINCH_HARNESS=test winch serve --mcp stdio &
|
|
49
|
+
|
|
50
|
+
Inside your harness agent:
|
|
51
|
+
|
|
52
|
+
backlog_plan { epic: { title: "my first epic" },
|
|
53
|
+
stories: [{ title: "S1", tasks: [{ title: "do the thing" }] }] }
|
|
54
|
+
backlog_claim { taskId: "<item-id>" } # identity stamped by the plugin
|
|
55
|
+
backlog_done { taskId: "<item-id>", resultSummary: "done" }
|
|
56
|
+
|
|
57
|
+
Verify from the operator side - no transcript reading:
|
|
58
|
+
|
|
59
|
+
$ winch next # task gone from the ready queue
|
|
60
|
+
$ winch serve --ws # watch the event stream light up
|
|
61
|
+
|
|
62
|
+
All MCP tools and their contracts are defined in `src/tools/` - or just list
|
|
63
|
+
them from the running server.
|
|
64
|
+
|
|
65
|
+
## How it fits together
|
|
66
|
+
|
|
67
|
+
- The **Store** is one SQLite database (`~/.winch/store.sqlite`) - the single
|
|
68
|
+
source of truth, migrations applied on open.
|
|
69
|
+
- The **MCP server** exposes the whole backlog as tools over stdio (one pipe per
|
|
70
|
+
harness) or streamable HTTP (one shared daemon). Identity is stamped at the
|
|
71
|
+
transport edge.
|
|
72
|
+
- The **Event stream** (`winch serve --ws`) is a read-only feed of backlog
|
|
73
|
+
events; its frame protocol is in [WebSocket event
|
|
74
|
+
stream](docs/websocket.md).
|
|
75
|
+
- The **Dispatch server** (`winch webhook serve`) accepts executor
|
|
76
|
+
registration and recovery, pumps `admission_queue`, and fans wakes out to
|
|
77
|
+
consumer webhooks. Tasks accept with MCP `backlog_claim`; planner wakes accept
|
|
78
|
+
with `backlog_accept_wake`.
|
|
79
|
+
- **Harness adapters** (`@igorjpimenta/winch-openclaw`, `@igorjpimenta/winch-opencode`)
|
|
80
|
+
stamp identity, checkpoint on turn end (OpenClaw), receive dispatch webhooks
|
|
81
|
+
on a plugin-local listener, and reconcile assigned `in_progress` work after a
|
|
82
|
+
restart.
|
|
83
|
+
|
|
84
|
+
harness agent --MCP (stdio | HTTP + X-Winch-Harness)--> MCP server --> SQLite store
|
|
85
|
+
|
|
|
86
|
+
admission_queue / delivery ledger
|
|
87
|
+
v
|
|
88
|
+
dispatch server --> consumer webhook --> plugin listener --> agent
|
|
89
|
+
|
|
90
|
+
## Identity
|
|
91
|
+
|
|
92
|
+
Every call is keyed `harness:agent:session`, and the harness is declared per
|
|
93
|
+
**connection**, never by the model:
|
|
94
|
+
|
|
95
|
+
| Transport | Harness declared by | Example |
|
|
96
|
+
| --- | --- | --- |
|
|
97
|
+
| stdio | `WINCH_HARNESS` env at launch | one pipe per harness |
|
|
98
|
+
| HTTP | `X-Winch-Harness` header on the session's first request | one shared daemon, all harnesses |
|
|
99
|
+
|
|
100
|
+
The agent and session halves are stamped per call as a whole pair, in **one**
|
|
101
|
+
channel: either `_meta.winch` (`{ agent, session, harness }`) or flat
|
|
102
|
+
`winch_agent` / `winch_session` arguments - halves never splice across
|
|
103
|
+
channels. Mutating calls without a full pair refuse; the adapters do this
|
|
104
|
+
stamping automatically. Full contract, per-dimension table and adapter setup:
|
|
105
|
+
[plugins/README.md](plugins/README.md).
|
|
106
|
+
|
|
107
|
+
## Dispatch
|
|
108
|
+
|
|
109
|
+
`winch webhook serve` hosts the HTTP dispatch endpoints and the wake pump;
|
|
110
|
+
`winch serve --ws` hosts only the read-only event stream. The dispatch server
|
|
111
|
+
is the single scheduler:
|
|
112
|
+
|
|
113
|
+
- It routes work-making transitions: `task.created`, `task.assigned`,
|
|
114
|
+
`task.released`, `task.restored`, `gate.resolved`, `story.created`,
|
|
115
|
+
`story.assigned`, `task.appended` (to the epic creator), and
|
|
116
|
+
`epic.completed` (to the epic creator).
|
|
117
|
+
- It writes each wake to `admission_queue`, creates a stable `dispatch_events`
|
|
118
|
+
row, one delivery row per consumer, and a per-attempt audit row. The payload
|
|
119
|
+
names one `execution: "active"` consumer and marks the rest `standby`; only
|
|
120
|
+
the active consumer starts a session. If it fails or its lease expires, the
|
|
121
|
+
dispatcher promotes a standby and bumps `leaseEpoch`.
|
|
122
|
+
- An offer reserves capacity until it is claimed, closes, or expires. Failed
|
|
123
|
+
deliveries and expired offers requeue with backoff. Planner wakes
|
|
124
|
+
(`story`/`append`/`review`) are one-shot only after `backlog_accept_wake`
|
|
125
|
+
takes the execution lease; an unaccepted wake requeues. A 4xx disables that
|
|
126
|
+
subscription; transient failures retry until the failure threshold or attempt
|
|
127
|
+
cap. A heartbeat does not erase that state.
|
|
128
|
+
- Caps are per harness (`WINCH_DISPATCH_HARNESS_MAX`) and global
|
|
129
|
+
(`WINCH_DISPATCH_GLOBAL_MAX`). The server listens on
|
|
130
|
+
`WINCH_DISPATCH_PORT` (default 38293, localhost-only unless `--host` says
|
|
131
|
+
otherwise). Status changes enqueue their wake in the same SQLite transaction
|
|
132
|
+
and ring `/dispatch/notify` on `WINCH_DISPATCH_URL`; the interval pump is
|
|
133
|
+
recovery, not routing.
|
|
134
|
+
|
|
135
|
+
Adapters register one route per `WINCH_CONSUMER_ID` (default
|
|
136
|
+
`harness:hostname`), with `WINCH_EXECUTOR_ID` as the live instance and a
|
|
137
|
+
`WINCH_WEBHOOK_BEARER` generated by `winch webhook bearer`. Registration is a
|
|
138
|
+
lease: a second live instance for the same consumer gets `409` until the
|
|
139
|
+
current lease expires. The first registration is `fresh: true`; later
|
|
140
|
+
heartbeats preserve failure state. Missing the executor or bearer disables the
|
|
141
|
+
receiver. Set `WINCH_DISPATCH_TOKEN` to authenticate registration, recovery and
|
|
142
|
+
notify; a non-loopback bind refuses without it. See
|
|
143
|
+
[Webhooks](docs/webhooks.md).
|
|
144
|
+
|
|
145
|
+
`POST /dispatch/recover` returns assigned `in_progress` work with its
|
|
146
|
+
`attemptId`, `leaseEpoch`, and `ownerInstance`, so a restarted harness resumes
|
|
147
|
+
that attempt instead of re-claiming it. The winner is recorded on the work
|
|
148
|
+
attempt; if a legacy claim has no owner, the active dispatch lease holder gets
|
|
149
|
+
it. If no active holder exists, the row is not fanned out. Standby consumers do
|
|
150
|
+
not resume the same attempt. Its first call is `backlog_update` with the
|
|
151
|
+
returned `attemptId` and `leaseEpoch`; a stale attempt or epoch gets
|
|
152
|
+
`stale_claim`. Expired leases return work to `ready` through the normal sweep.
|
|
153
|
+
|
|
154
|
+
`backlog_delegate` accepts an optional `childKey` and `visitSeq`. Retrying the
|
|
155
|
+
same pair returns the same child; a new `visitSeq` starts a new round. The
|
|
156
|
+
parent waits on every child, and `current_child_key` records the last child
|
|
157
|
+
offered. `backlog_append` wakes the epic creator, not the task assignee.
|
|
158
|
+
|
|
159
|
+
## Harnesses
|
|
160
|
+
|
|
161
|
+
An adapter attaches to an existing order; it never creates work.
|
|
162
|
+
|
|
163
|
+
**OpenClaw** - `@igorjpimenta/winch-openclaw` stamps `_meta.winch`,
|
|
164
|
+
checkpoints on turn end, resumes from the latest checkpoint, receives dispatch
|
|
165
|
+
wakes at `POST /api/winch/dispatch`, and reconciles `in_progress` attempts
|
|
166
|
+
after a restart.
|
|
167
|
+
|
|
168
|
+
openclaw plugins install npm:@igorjpimenta/winch-openclaw@latest
|
|
169
|
+
|
|
170
|
+
One daemon for all harnesses (recommended):
|
|
171
|
+
|
|
172
|
+
{
|
|
173
|
+
"mcp": {
|
|
174
|
+
"servers": {
|
|
175
|
+
"winch": {
|
|
176
|
+
"url": "http://127.0.0.1:38292/mcp",
|
|
177
|
+
"headers": {
|
|
178
|
+
"X-Winch-Harness": "openclaw",
|
|
179
|
+
"Authorization": "Bearer <WINCH_BEARER>"
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
One pipe per harness instead:
|
|
187
|
+
|
|
188
|
+
{
|
|
189
|
+
"mcp": {
|
|
190
|
+
"servers": {
|
|
191
|
+
"winch": {
|
|
192
|
+
"command": "winch",
|
|
193
|
+
"args": ["serve", "--mcp", "stdio"],
|
|
194
|
+
"env": { "WINCH_HARNESS": "openclaw" }
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
**OpenCode** - `@igorjpimenta/winch-opencode` stamps identity on every winch
|
|
201
|
+
MCP tool call. It needs the winch MCP server configured and `WINCH_AGENT` when
|
|
202
|
+
the session agent cannot be captured.
|
|
203
|
+
|
|
204
|
+
OpenCode reads config from `opencode.json(c)` (project root or `.opencode/`,
|
|
205
|
+
global at `~/.config/opencode/`). V1 configs normalize into V2, but write V2
|
|
206
|
+
canonical form for new setup:
|
|
207
|
+
|
|
208
|
+
{
|
|
209
|
+
"$schema": "https://opencode.ai/config.json",
|
|
210
|
+
"mcp": {
|
|
211
|
+
"servers": {
|
|
212
|
+
"winch": {
|
|
213
|
+
"type": "remote",
|
|
214
|
+
"url": "http://127.0.0.1:38292/mcp",
|
|
215
|
+
"headers": {
|
|
216
|
+
"X-Winch-Harness": "opencode",
|
|
217
|
+
"Authorization": "Bearer <WINCH_BEARER>"
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
"plugins": ["@igorjpimenta/winch-opencode"]
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
Or via the CLI:
|
|
226
|
+
|
|
227
|
+
opencode mcp add winch --url http://127.0.0.1:38292/mcp \
|
|
228
|
+
--header "X-Winch-Harness=opencode" \
|
|
229
|
+
--header "Authorization=Bearer <WINCH_BEARER>"
|
|
230
|
+
opencode plugin add @igorjpimenta/winch-opencode
|
|
231
|
+
|
|
232
|
+
Automatic checkpoint/resume is not part of the OpenCode adapter; the agent uses
|
|
233
|
+
the winch MCP tools directly. The plugin listens for dispatch wakes on a
|
|
234
|
+
loopback endpoint and starts a claimable session with `opencode run`.
|
|
235
|
+
|
|
236
|
+
## MCP tools
|
|
237
|
+
|
|
238
|
+
| tool | what it does |
|
|
239
|
+
| --- | --- |
|
|
240
|
+
| `backlog_plan` | create an epic with its stories and tasks in one call; the spec is written into the records |
|
|
241
|
+
| `backlog_append` | add stories to an epic and/or tasks to a story after the plan, unassigned, for the planner to route |
|
|
242
|
+
| `backlog_drop` / `backlog_restore` | disable an epic, story or task that was never claimed, and bring it back; claimed work can only be closed |
|
|
243
|
+
| `backlog_assign` | set an assignee on a task (it claims and delivers) or a story (its owner breaks it into tasks); that row is what wakes the assignee. Null/empty agents are rejected loudly |
|
|
244
|
+
| `backlog_delegate` | split work from a task to another worker (agent or human); each child becomes its own card, the parent parks in `blocked` until all children close, then returns to `ready` for the accountable. `childKey`/`visitSeq` make retries idempotent and start new rounds |
|
|
245
|
+
| `backlog_get` | read an epic, story or task by id - acceptance, results, artifacts, dependencies, readiness |
|
|
246
|
+
| `backlog_claim` | claim one task by id, or the highest-priority ready task when the id is omitted; atomic CAS under a lease |
|
|
247
|
+
| `backlog_update` | heartbeat and append progress, comment or artifact to a claimed task; pass the `leaseEpoch` for wake-owned attempts |
|
|
248
|
+
| `backlog_accept_wake` | take the single-flight execution lease for a story/append/review wake before planning |
|
|
249
|
+
| `backlog_done` | close a claimed task with a result; closing the last task closes its story, and the last story closes the epic and wakes the agent that planned it |
|
|
250
|
+
| `backlog_block` / `backlog_resume` | open a human gate (with optional `gateType` and `blockedBy` dep edge) and resolve it (`actor` optional) |
|
|
251
|
+
|
|
252
|
+
## Task lifecycle
|
|
253
|
+
|
|
254
|
+
A task starts in `backlog`. Assignment moves it to `ready`; clearing the
|
|
255
|
+
assignment returns it to `backlog`, so only an assigned task can be claimed.
|
|
256
|
+
Delegating creates one or more child tasks for the worker, parks the parent in
|
|
257
|
+
`blocked` on those dependencies, and returns the parent to `ready` when every
|
|
258
|
+
child closes. A second `backlog_delegate` on a dependency-blocked parent adds a
|
|
259
|
+
parallel child; any other block refuses.
|
|
260
|
+
`backlog_block` with `blockedBy` uses the same dependency wait; a plain block
|
|
261
|
+
still needs `backlog_resume`.
|
|
262
|
+
Assigning the reserved agent `human` stamps the reserved harness
|
|
263
|
+
`human_in_the_loop`: the pair keeps `ready`/`in_progress` semantics for human
|
|
264
|
+
work, but neither value is a caller identity, and agent dispatchers never wake
|
|
265
|
+
it. A block parks it until an operator resumes it; the last task closes its
|
|
266
|
+
story, and the last story closes the epic.
|
|
267
|
+
|
|
268
|
+
```mermaid
|
|
269
|
+
flowchart LR
|
|
270
|
+
Z[backlog] -->|assign| A[ready]
|
|
271
|
+
A -->|unassign| Z
|
|
272
|
+
A -->|claim by id or next| B[in_progress]
|
|
273
|
+
B -->|heartbeat / update| B
|
|
274
|
+
B -->|lease expires| A
|
|
275
|
+
B -->|done| C[done]
|
|
276
|
+
B -->|block| D[blocked]
|
|
277
|
+
A -->|delegate| G[child task for worker]
|
|
278
|
+
B -->|delegate| G
|
|
279
|
+
G -->|parent waits| D
|
|
280
|
+
D -->|manual resume| A
|
|
281
|
+
D -->|deps resolve| A
|
|
282
|
+
C -->|last task| E[story done]
|
|
283
|
+
E -->|last story| F[epic done]
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Claim leases, attempt caps, and gate rules: [lifecycle](docs/lifecycle.md).
|
|
287
|
+
|
|
288
|
+
## Documentation
|
|
289
|
+
|
|
290
|
+
| Goal | Start here |
|
|
291
|
+
| --- | --- |
|
|
292
|
+
| Configure ports, bearer, store, webhooks | [Configuration](docs/configuration.md) |
|
|
293
|
+
| Understand claim/lease/gate rules | [Lifecycle](docs/lifecycle.md) |
|
|
294
|
+
| Webhook subscriptions, dispatch routing, recovery and CLI | [Webhooks](docs/webhooks.md) |
|
|
295
|
+
| Event stream frame protocol and retention | [WebSocket event stream](docs/websocket.md) |
|
|
296
|
+
| Run it on a host persistently | [Docker](docs/docker.md) |
|
|
297
|
+
| Publish a release | [Releases](docs/releases.md) |
|
|
298
|
+
|
|
299
|
+
## CLI
|
|
300
|
+
|
|
301
|
+
| command | what it does |
|
|
302
|
+
| --- | --- |
|
|
303
|
+
| `serve --mcp stdio` | serve the backlog tools over MCP stdio (env-only harness) |
|
|
304
|
+
| `serve --mcp http --port N [--host H]` | serve the same tools over Streamable HTTP (shared daemon) |
|
|
305
|
+
| `watch` | one watcher tick (JSON manifest on stdout) |
|
|
306
|
+
| `resume <taskId> [--actor <name>]` | resolve a human gate: blocked to ready |
|
|
307
|
+
| `next` | list the current ready queue |
|
|
308
|
+
| `release-epic --epic <id> [--task ID] [--version V] [--base B]` | release notes + branch/PR with backlog markers |
|
|
309
|
+
| `merge-detect [--dry-run]` | apply merged/closed PR outcomes |
|
|
310
|
+
| `webhook bearer` | generate a dispatch bearer |
|
|
311
|
+
| `webhook register --topic T [--harness H] [--executor E] --url U [--id I] [--bearer B]` | register or replace a webhook subscription; a bearer is generated and printed when omitted |
|
|
312
|
+
| `webhook list [--topic T] [--harness H]` | list webhook subscriptions with bearer redacted |
|
|
313
|
+
| `webhook deliveries [--status S] [--admission ID] [--consumer ID] [--limit N]` | inspect the per-consumer delivery ledger; `--status dead` lists dead letters |
|
|
314
|
+
| `webhook revoke [--topic T] --id I` | remove a webhook subscription |
|
|
315
|
+
| `webhook test [--topic T] [--harness H] [--id I]` | POST a ping to webhook subscriptions |
|
|
316
|
+
| `serve --ws --port N [--host H]` | stream store events over WebSocket |
|
|
317
|
+
| `webhook serve [--port N] [--host H]` | serve dispatch registration, recovery and the wake pump |
|
|
318
|
+
|
|
319
|
+
## Deploy (any server)
|
|
320
|
+
|
|
321
|
+
Winch is cloud-agnostic: the portable build is the container below - plain
|
|
322
|
+
Node + a SQLite file on a volume, no cloud SDKs or provider APIs. Run it on
|
|
323
|
+
any VPS, compose host or cluster with one replica (SQLite has one writer).
|
|
324
|
+
|
|
325
|
+
docker build -t winch .
|
|
326
|
+
docker run -d --name winch --restart unless-stopped \
|
|
327
|
+
-e WINCH_BEARER="$(openssl rand -base64 32)" \
|
|
328
|
+
-v winch-data:/data -p 38292:38292 winch
|
|
329
|
+
# or: WINCH_BEARER=... docker compose up -d --build
|
|
330
|
+
|
|
331
|
+
- The container listens on `WINCH_MCP_HTTP_PORT` (default 38292); `GET /health`
|
|
332
|
+
is unauthenticated (load-balancer / `HEALTHCHECK` probe); everything else
|
|
333
|
+
needs `Authorization: Bearer <WINCH_BEARER>`.
|
|
334
|
+
- Terminate TLS in front (Caddy / Traefik / ingress); point harnesses at
|
|
335
|
+
`https://<host>/mcp` with the bearer + `X-Winch-Harness` headers - the
|
|
336
|
+
same contract as `serve --mcp http` locally. LangGraph needs no local
|
|
337
|
+
spawn: `streamablehttp_client` straight to the URL.
|
|
338
|
+
- The volume holds `WINCH_DB` (`/data/store.sqlite` in the image); back it
|
|
339
|
+
up like any stateful file. Never bake `WINCH_BEARER` into the image.
|
|
340
|
+
- `webhook serve` sweeps expired leases on `WINCH_DISPATCH_SWEEP_MS`; `watch`
|
|
341
|
+
remains the one-shot tick for hosts that do not run the dispatch service.
|
|
342
|
+
Claims still self-heal on the next tick when the DB lives elsewhere.
|
|
343
|
+
|
|
344
|
+
## Events stream
|
|
345
|
+
|
|
346
|
+
`winch serve --ws [--port N] [--host H]` (default port 38291, localhost-only
|
|
347
|
+
unless `--host` says otherwise) tails the `item_events` ledger and broadcasts every
|
|
348
|
+
new row to all connected clients as JSON text frames:
|
|
349
|
+
|
|
350
|
+
- `{"type":"welcome","payload":"v3","lastEventId":N}` on connect, then
|
|
351
|
+
`{"type":"history","events":[...]}` (newest 200), then
|
|
352
|
+
- `{"type":"event","kind":"task.completed","id":N,"at":T,"item":{id,kind,
|
|
353
|
+
title,status,assigned},"task":{id,title,story,epic,acceptance,artifacts,
|
|
354
|
+
assignee},"actor":"...","note":"..."}` per insert, in id order.
|
|
355
|
+
- Dispatch wakes are not frames on this stream and run in a separate
|
|
356
|
+
`winch webhook serve` process; see [Webhooks](docs/webhooks.md) and
|
|
357
|
+
[WebSocket event stream](docs/websocket.md).
|
|
358
|
+
|
|
359
|
+
Kinds are declared by their producer at write time and stored on the row's
|
|
360
|
+
`kind` column. Structural inference covers `task.*` and `gate.*`; producers
|
|
361
|
+
also write `story.assigned`, `deps.*`, and `release.shipped`. A shipped row
|
|
362
|
+
asserts a tag exists: merge-detect tags first and writes nothing on tag
|
|
363
|
+
failure. The emitter feeds the stored kind straight through; otherwise a row
|
|
364
|
+
maps by transition structure alone. Notes never classify anything: they are
|
|
365
|
+
free text and can change, so pre-kind rows keep exactly the meanings they
|
|
366
|
+
streamed with - an append-only log keeps its history.
|
|
367
|
+
The structural mapping lives in `src/events-ws.js`; stored producer kinds pass
|
|
368
|
+
through unchanged. History and live rows share one envelope shape.
|
|
369
|
+
|
|
370
|
+
Delivery-dynamics notes the wire will not tell you: heartbeats renew the claim
|
|
371
|
+
lease (only silence gets swept); an unmerged close dissolves its gate (late
|
|
372
|
+
approvals answer `gate_dissolved`); starvation lives in the watcher manifest
|
|
373
|
+
(`deferred` list, per-task `idleMs`), not the stream; a disputed completion is
|
|
374
|
+
a new ticket linked by dep edge with a `supersedes: ITM-x` note, never a
|
|
375
|
+
rewrite of history.
|
|
376
|
+
|
|
377
|
+
Rows carry their stored `kind` and the recursive `item` envelope; the legacy
|
|
378
|
+
`task`/`story`/`epic` blocks stay for subscribers that predate the recursive-item schema.
|
|
379
|
+
|
|
380
|
+
The server never interprets a row - a gate opening is just another event, and
|
|
381
|
+
reminders, digests and dashboards are subscriber code. Reconnect replays
|
|
382
|
+
history, so a missed frame costs a re-read, never a lost event. No auth in
|
|
383
|
+
process: keep the loopback bind, or put a bearer-checked reverse proxy in
|
|
384
|
+
front. Plain HTTP hits get 404.
|
|
385
|
+
|
|
386
|
+
## Store
|
|
387
|
+
|
|
388
|
+
DB path resolution: `WINCH_DB` -> `~/.winch/store.sqlite`. The store is
|
|
389
|
+
winch's, not the launching harness's.
|
|
390
|
+
|
|
391
|
+
Schema lives in `src/schema.js` as Drizzle tables. The schema is one recursive
|
|
392
|
+
`items` tree (`kind` = epic/story/task, `parent_id` for nesting), with
|
|
393
|
+
`item_state`, `item_tags`, `item_edges`, `attempts`, `work_sessions`,
|
|
394
|
+
`artifacts`, `item_events`, `admission_queue`, `admission_attempts`,
|
|
395
|
+
`dispatch_events`, `dispatch_deliveries`, `dispatch_delivery_attempts` and
|
|
396
|
+
`webhooks`. Item ids are opaque; `kind`
|
|
397
|
+
is the discriminator, never an id prefix. `npm run db:generate`
|
|
398
|
+
turns schema changes into SQL in `.migrations/`; `src/db.js` applies pending
|
|
399
|
+
migrations on open, and `npm run db:migrate` does the same explicitly for a
|
|
400
|
+
deploy. The files are plain SQL and may be edited before they are applied for
|
|
401
|
+
data backfills, triggers, or renames; an applied migration is a snapshot, so
|
|
402
|
+
append a new one instead of editing it.
|
|
403
|
+
|
|
404
|
+
Concurrency note: concurrent access to the sqlite file - server, watcher and
|
|
405
|
+
CLI processes at once - is safe under WAL mode, and
|
|
406
|
+
[test/unit/src/store/race.test.js](test/unit/src/store/race.test.js)
|
|
407
|
+
races 4 real OS processes with independent handles through one claim to prove
|
|
408
|
+
the CAS transaction boundary under WAL contention.
|
|
409
|
+
|
|
410
|
+
## Identity
|
|
411
|
+
|
|
412
|
+
Every claim is keyed `harness:agent:session`. The **harness is declared at
|
|
413
|
+
construction** - `winch serve --mcp stdio` will not start without
|
|
414
|
+
`WINCH_HARNESS` in the environment, because an unnamed server cannot attribute
|
|
415
|
+
anything. The agent and session of each call are stamped per call by the
|
|
416
|
+
calling harness's companion plugin (`_meta.winch`), which overwrites
|
|
417
|
+
unconditionally, so model-supplied meta cannot impersonate an agent. A call
|
|
418
|
+
whose agent or session is unstamped fails loudly instead of minting a default
|
|
419
|
+
key. Full contract, per-dimension table and harness adapter setup snippets:
|
|
420
|
+
[plugins/README.md](plugins/README.md).
|
|
421
|
+
|
|
422
|
+
## Configuration
|
|
423
|
+
|
|
424
|
+
Tuning knobs are declared the way the harness is - and none of them is
|
|
425
|
+
required. Precedence per knob: per-call `_meta.winch.config` > constructor
|
|
426
|
+
`{ config }` (`createStore`, `--config JSON|PATH` on `mcp`/`serve`/`watch`)
|
|
427
|
+
> `WINCH_*` env > code default. Every knob has a default, so a server with no
|
|
428
|
+
overrides starts with dispatch enabled. Malformed values refuse (bad key named) at startup
|
|
429
|
+
for construction config, per call for meta overlay; unknown explicit keys
|
|
430
|
+
refuse as likely typos, unknown meta keys are ignored for forward compat.
|
|
431
|
+
|
|
432
|
+
| knob | env | default |
|
|
433
|
+
|---|---|---|
|
|
434
|
+
| Claim lease | `WINCH_LEASE_SECONDS` | 1800 (30 min) |
|
|
435
|
+
| Sweeper max attempts | `WINCH_MAX_ATTEMPTS` | 3 |
|
|
436
|
+
| Gate-wait thresholds | `WINCH_GATE_WAIT_LEVELS` (`"24h,72h"`, `ms|s|m|h|d` suffixes) | 24h / 72h |
|
|
437
|
+
| WS port / history / poll | `WINCH_WS_PORT` / `WINCH_WS_HISTORY_LIMIT` / `WINCH_WS_INTERVAL_MS` | 38291 / 200 / 1000 ms |
|
|
438
|
+
| Dispatch port / poll / lease sweep | `WINCH_DISPATCH_PORT` / `WINCH_DISPATCH_INTERVAL_MS` / `WINCH_DISPATCH_SWEEP_MS` | 38293 / 1000 / 30000 ms |
|
|
439
|
+
| Dispatch caps per harness / global | `WINCH_DISPATCH_HARNESS_MAX` / `WINCH_DISPATCH_GLOBAL_MAX` | 8 / 16 |
|
|
440
|
+
| Dispatch consumer heartbeat TTL | `WINCH_DISPATCH_CONSUMER_TTL_MS` | 90000 ms |
|
|
441
|
+
| Offer TTL / backoff / attempts | `WINCH_DISPATCH_OFFER_MS` / `WINCH_DISPATCH_OFFER_BACKOFF_MS` / `WINCH_DISPATCH_OFFER_MAX_BACKOFF_MS` / `WINCH_DISPATCH_OFFER_MAX_ATTEMPTS` | 120000 / 30000 / 300000 ms / 5 |
|
|
442
|
+
| Delivery backoff / max / attempts / failure threshold / claim lease | `WINCH_DISPATCH_DELIVERY_BACKOFF_MS` / `WINCH_DISPATCH_DELIVERY_MAX_BACKOFF_MS` / `WINCH_DISPATCH_DELIVERY_MAX_ATTEMPTS` / `WINCH_DISPATCH_DELIVERY_FAILURE_THRESHOLD` / `WINCH_DISPATCH_DELIVERY_LEASE_MS` | 30000 / 300000 ms / 5 / 4 / 300000 ms |
|
|
443
|
+
| Webhook delivery timeout | `WINCH_WEBHOOK_TIMEOUT_MS` | 3000 ms |
|
|
444
|
+
| Dispatch management auth | `WINCH_DISPATCH_TOKEN` | unset (loopback) |
|
|
445
|
+
| MCP HTTP port | `WINCH_MCP_HTTP_PORT` | 38292 |
|
|
446
|
+
| DB path | `WINCH_DB` | `~/.winch/store.sqlite` |
|
|
447
|
+
| Wake routing cap | `WINCH_MAX_ACTIVE_PER_AGENT` | 2 |
|
|
448
|
+
| Scan limits (tick / candidates / blocked list) | `WINCH_SCAN_LIMIT` / `WINCH_CANDIDATES` / `WINCH_BLOCKED_LIMIT` | 50 / 5 / 20 |
|
|
449
|
+
| Dep cycle-check cap | `WINCH_DFS_NODES` | 500 nodes |
|
|
450
|
+
| Note caps (progress / result / reason / artifact) | `WINCH_NOTE_{PROGRESS,RESULT,REASON,ARTIFACT}_LIMIT` | 2000 / 4000 / 1000 / 500 |
|
|
451
|
+
| Artifacts per done | `WINCH_MAX_ARTIFACTS` | 50 |
|
|
452
|
+
|
|
453
|
+
## Troubleshooting
|
|
454
|
+
|
|
455
|
+
| Refusal message | Cause | Fix |
|
|
456
|
+
| --- | --- | --- |
|
|
457
|
+
| "refused caller identity (unresolved agent and session)" | No `_meta.winch` and no `winch_agent`/`winch_session` args | Ensure the companion plugin is installed and stamping; for OpenCode set `WINCH_AGENT` |
|
|
458
|
+
| "halves in different channels - pairs never splice" | Agent from one channel, session from another | Stamp both in the same channel (`_meta.winch` or flat args) |
|
|
459
|
+
| "refused declaration (missing: harness)" | `WINCH_HARNESS` unset on stdio, or `X-Winch-Harness` missing on HTTP | Set the env var or add the header |
|
|
460
|
+
| "refused declaration (reserved: harness)" | Harness name is `unknown`, `instance:*`, or `human_in_the_loop` | Use a real harness name |
|
|
461
|
+
| "refused caller identity" with a reserved agent | Agent is `human`, the human-assignment sentinel | Use a real agent name; `human` is a target, not a caller |
|
|
462
|
+
| "not found: ITM-..." | Item id does not exist | Check the id; tasks may have been dropped or never created |
|
|
463
|
+
| "is in_progress, not ready" | Task already claimed | Wait for completion or reassign via `backlog_assign` |
|
|
464
|
+
| "not_ready" on claim | Unmet dependency or capability mismatch | Check deps with `backlog_get`; offer matching capabilities |
|
|
465
|
+
|
|
466
|
+
## Why the name?
|
|
467
|
+
|
|
468
|
+
A winch is the machine that pulls a load up a slope - it does not push, it
|
|
469
|
+
does not carry, it pulls. Winch pulls work orders through a dependency DAG:
|
|
470
|
+
a planner loads the load at the bottom, agents pull tasks up the slope, and
|
|
471
|
+
the store records every meter of progress. The name is the mechanism.
|
|
472
|
+
|
|
473
|
+
## Development
|
|
474
|
+
|
|
475
|
+
npm install
|
|
476
|
+
npm test
|
|
477
|
+
node bin/winch.js --help
|
|
478
|
+
|
|
479
|
+
## License
|
|
480
|
+
|
|
481
|
+
MIT
|
package/bin/winch.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@igorjpimenta/winch",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2026.11.22-beta.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/igorjpimenta/winch.git"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"registry": "https://registry.npmjs.org",
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin/",
|
|
16
|
+
"src/",
|
|
17
|
+
"plugins/",
|
|
18
|
+
".migrations/",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"bin": {
|
|
22
|
+
"winch": "bin/winch.js"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "node --test",
|
|
26
|
+
"db:generate": "drizzle-kit generate",
|
|
27
|
+
"db:migrate": "drizzle-kit migrate"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
31
|
+
"better-sqlite3": "^13.0.3",
|
|
32
|
+
"drizzle-orm": "^0.45.4",
|
|
33
|
+
"zod": "^3.25 || ^4.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"drizzle-kit": "^0.31.11"
|
|
37
|
+
}
|
|
38
|
+
}
|