@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,371 @@
|
|
|
1
|
+
// definitions.js — the MCP tool surface: names, descriptions, JSON schemas.
|
|
2
|
+
// Behaviour lives one file per family; this file is the contract a harness reads.
|
|
3
|
+
|
|
4
|
+
export const TOOL_DEFS = [
|
|
5
|
+
{
|
|
6
|
+
name: "backlog_claim",
|
|
7
|
+
description:
|
|
8
|
+
"Atomically claim work for THIS agent (identity resolved from request meta / environment). With `taskId`, claims that one task: " +
|
|
9
|
+
"it must be ready AND currently claimable (deps done, caps intersect) — otherwise refused as not_claimed / not_ready, never queued. " +
|
|
10
|
+
"Without `taskId`, claims the highest-priority ready task for this agent and silently tries the next candidate on a race. " +
|
|
11
|
+
"Same CAS semantics under a per-identity lease either way; a targeted race gives back `raced`, never a partial claim.",
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: "object",
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
properties: {
|
|
16
|
+
taskId: { type: "string", description: "Task item id (opaque). Omit to claim the highest-priority ready task." },
|
|
17
|
+
capabilities: {
|
|
18
|
+
type: "array",
|
|
19
|
+
items: { type: "string" },
|
|
20
|
+
description: "Capability tags this agent offers; filters tasks whose required caps intersect.",
|
|
21
|
+
},
|
|
22
|
+
dryRun: {
|
|
23
|
+
type: "boolean",
|
|
24
|
+
description: "Report the task (or the next candidate) without claiming it.",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "backlog_assign",
|
|
31
|
+
description:
|
|
32
|
+
"Set (or clear) the assignee of a task or a story; that row is what wakes the assignee. " +
|
|
33
|
+
"Assigning moves a backlog item to ready; clearing it returns the item to backlog. " +
|
|
34
|
+
"A task assignee claims and delivers it. A story assignee breaks it down first: it reads the story and appends the tasks with " +
|
|
35
|
+
"`backlog_append`, unassigned, so the planner can route them — use story assignment when the breakdown is not known at plan time. " +
|
|
36
|
+
"Refuses to reassign a task already in progress by someone else. Passing `agent: null` or \"\" clears it. " +
|
|
37
|
+
"The reserved agent `human` assigns human work with the reserved harness `human_in_the_loop`. " +
|
|
38
|
+
"Optional `capabilities` replaces the item's capability tags.",
|
|
39
|
+
inputSchema: {
|
|
40
|
+
type: "object",
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
properties: {
|
|
43
|
+
id: { type: "string", description: "Item id (opaque) for a task or a story." },
|
|
44
|
+
taskId: { type: "string", description: "Deprecated alias for `id` when assigning a task." },
|
|
45
|
+
agent: { type: ["string", "null"], description: "Target agent id, or null/\"\" to unassign." },
|
|
46
|
+
capabilities: {
|
|
47
|
+
type: "array",
|
|
48
|
+
items: { type: "string" },
|
|
49
|
+
description: "Capability tags the item requires; replaces existing tags.",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "backlog_delegate",
|
|
56
|
+
description:
|
|
57
|
+
"Hand part of a task to another worker without changing the parent's accountable assignee. Creates a child task under the parent, " +
|
|
58
|
+
"assigns it to `agent`, adds it to the parent's dependency wait, and parks the parent in `blocked`. Additional children may be " +
|
|
59
|
+
"delegated while the parent is dependency-blocked; it returns to `ready` when every child closes. Use `agent: \"human\"` for " +
|
|
60
|
+
"human work; the child carries the reserved human pair.",
|
|
61
|
+
inputSchema: {
|
|
62
|
+
type: "object",
|
|
63
|
+
additionalProperties: false,
|
|
64
|
+
required: ["taskId", "agent", "title"],
|
|
65
|
+
properties: {
|
|
66
|
+
taskId: { type: "string", description: "Parent task item id (opaque). The caller must be its accountable assignee or it must be unassigned." },
|
|
67
|
+
agent: { type: "string", description: "Worker agent that claims and delivers the child. Use `human` for human work." },
|
|
68
|
+
title: { type: "string", description: "Child task title." },
|
|
69
|
+
childKey: { type: "string", description: "Stable fan-out lane name, e.g. docs. Same parent + key + visitSeq returns the existing child." },
|
|
70
|
+
visitSeq: { type: "integer", minimum: 0, description: "Fan-out round for this childKey; default 0. A review re-run uses 1." },
|
|
71
|
+
description: { type: "string", description: "Child task description." },
|
|
72
|
+
acceptance: { type: "string", description: "What done means for the child. Defaults to the parent acceptance." },
|
|
73
|
+
capabilities: {
|
|
74
|
+
type: "array",
|
|
75
|
+
items: { type: "string" },
|
|
76
|
+
description: "Capability tags the child requires. Defaults to the parent tags.",
|
|
77
|
+
},
|
|
78
|
+
executionKind: {
|
|
79
|
+
type: "string",
|
|
80
|
+
enum: ["pipeclaw", "subagent", "cli", "gate", "manual"],
|
|
81
|
+
description: "How the child is executed; default manual.",
|
|
82
|
+
},
|
|
83
|
+
executionArgs: { type: "object", description: "Execution arguments for the child." },
|
|
84
|
+
reason: { type: "string", description: "Why the work is delegated; recorded on the parent wait." },
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: "backlog_plan",
|
|
90
|
+
description:
|
|
91
|
+
"Create a whole plan in one call: an epic, its stories, and their tasks, wired with dependencies. This is how a planner " +
|
|
92
|
+
"protocols a demand — the spec goes INTO the records (task description, story acceptance, capability tags), because a " +
|
|
93
|
+
"worker receives only a task id and reads the record itself. Tasks land `backlog`; assigning one moves it to `ready`. Use " +
|
|
94
|
+
"`backlog_assign`. `dependsOn` references other tasks in the same plan by key (default `s<story>t<task>`, zero-based) " +
|
|
95
|
+
"and may only point backward, so the plan is acyclic by construction. All-or-nothing: an invalid key rolls back the plan.",
|
|
96
|
+
inputSchema: {
|
|
97
|
+
type: "object",
|
|
98
|
+
additionalProperties: false,
|
|
99
|
+
required: ["epic", "stories"],
|
|
100
|
+
properties: {
|
|
101
|
+
epic: {
|
|
102
|
+
type: "object",
|
|
103
|
+
description: "The epic this plan creates.",
|
|
104
|
+
additionalProperties: false,
|
|
105
|
+
required: ["title"],
|
|
106
|
+
properties: {
|
|
107
|
+
title: { type: "string" },
|
|
108
|
+
description: { type: "string", description: "Why this epic exists and any shared constraint." },
|
|
109
|
+
acceptance: { type: "string", description: "What done means for the epic." },
|
|
110
|
+
priority: { type: "integer", description: "0-100, default 50." },
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
stories: {
|
|
114
|
+
type: "array",
|
|
115
|
+
minItems: 1,
|
|
116
|
+
description: "Stories to create under the epic, each with its tasks.",
|
|
117
|
+
items: {
|
|
118
|
+
type: "object",
|
|
119
|
+
additionalProperties: false,
|
|
120
|
+
required: ["title", "tasks"],
|
|
121
|
+
properties: {
|
|
122
|
+
title: { type: "string" },
|
|
123
|
+
description: { type: "string" },
|
|
124
|
+
acceptance: { type: "string", description: "Verifiable acceptance criteria; every worker on this story sees it." },
|
|
125
|
+
priority: { type: "integer" },
|
|
126
|
+
capabilities: { type: "array", items: { type: "string" }, description: "Default capability tags for the story's tasks." },
|
|
127
|
+
tasks: {
|
|
128
|
+
type: "array",
|
|
129
|
+
minItems: 1,
|
|
130
|
+
items: {
|
|
131
|
+
type: "object",
|
|
132
|
+
additionalProperties: false,
|
|
133
|
+
required: ["title"],
|
|
134
|
+
properties: {
|
|
135
|
+
title: { type: "string" },
|
|
136
|
+
description: { type: "string", description: "Everything the worker needs: what to build, where, and the constraints. There is no other brief." },
|
|
137
|
+
key: { type: "string", description: "Referenced by dependsOn; defaults to s<story>t<task> (zero-based)." },
|
|
138
|
+
executionKind: { type: "string", enum: ["pipeclaw", "subagent", "cli", "gate", "manual"] },
|
|
139
|
+
executionArgs: { type: "object", description: "Structured args the worker's harness understands." },
|
|
140
|
+
capabilities: { type: "array", items: { type: "string" }, description: "Capability tags the work truly needs." },
|
|
141
|
+
dependsOn: { type: "array", items: { type: "string" }, description: "Keys of earlier tasks in this plan that must finish first." },
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "backlog_append",
|
|
153
|
+
description:
|
|
154
|
+
"Append to an existing plan: add stories to an epic, and/or tasks to a story, after work has started. Use it for a gap a worker " +
|
|
155
|
+
"found, a follow-up from review, or a story split discovered late. Both kinds are written with the same self-sufficient record a " +
|
|
156
|
+
"planned item carries; tasks land `backlog` unless `assigned` is given (then `ready`), and a `task.appended` row is written so a dispatcher can " +
|
|
157
|
+
"route them. `dependsOn` accepts a key from this call or an existing item id. All-or-nothing.",
|
|
158
|
+
inputSchema: {
|
|
159
|
+
type: "object",
|
|
160
|
+
additionalProperties: false,
|
|
161
|
+
properties: {
|
|
162
|
+
epicId: { type: "string", description: "Epic item id (opaque)." },
|
|
163
|
+
storyId: { type: "string", description: "Story item id (opaque)." },
|
|
164
|
+
stories: {
|
|
165
|
+
type: "array",
|
|
166
|
+
description: "Stories to append to epicId.",
|
|
167
|
+
items: {
|
|
168
|
+
type: "object",
|
|
169
|
+
additionalProperties: false,
|
|
170
|
+
required: ["title", "tasks"],
|
|
171
|
+
properties: {
|
|
172
|
+
title: { type: "string" },
|
|
173
|
+
description: { type: "string" },
|
|
174
|
+
acceptance: { type: "string", description: "Verifiable criteria; every worker on the story reads them." },
|
|
175
|
+
priority: { type: "integer" },
|
|
176
|
+
capabilities: { type: "array", items: { type: "string" } },
|
|
177
|
+
tasks: {
|
|
178
|
+
type: "array",
|
|
179
|
+
minItems: 1,
|
|
180
|
+
items: {
|
|
181
|
+
type: "object",
|
|
182
|
+
additionalProperties: false,
|
|
183
|
+
required: ["title"],
|
|
184
|
+
properties: {
|
|
185
|
+
title: { type: "string" },
|
|
186
|
+
description: { type: "string" },
|
|
187
|
+
key: { type: "string", description: "Referenced by dependsOn within this call; defaults to s<story>t<task>." },
|
|
188
|
+
executionKind: { type: "string", enum: ["pipeclaw", "subagent", "cli", "gate", "manual"] },
|
|
189
|
+
executionArgs: { type: "object" },
|
|
190
|
+
capabilities: { type: "array", items: { type: "string" } },
|
|
191
|
+
assigned: { type: "string", description: "Leave empty so the planner routes it." },
|
|
192
|
+
dependsOn: { type: "array", items: { type: "string" } },
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
tasks: {
|
|
200
|
+
type: "array",
|
|
201
|
+
description: "Tasks to append to storyId.",
|
|
202
|
+
minItems: 1,
|
|
203
|
+
items: {
|
|
204
|
+
type: "object",
|
|
205
|
+
additionalProperties: false,
|
|
206
|
+
required: ["title"],
|
|
207
|
+
properties: {
|
|
208
|
+
title: { type: "string" },
|
|
209
|
+
description: { type: "string", description: "What to build, where, how to verify, what is out of scope." },
|
|
210
|
+
key: { type: "string", description: "Referenced by dependsOn within this call; defaults to a<index>." },
|
|
211
|
+
executionKind: { type: "string", enum: ["pipeclaw", "subagent", "cli", "gate", "manual"] },
|
|
212
|
+
executionArgs: { type: "object" },
|
|
213
|
+
capabilities: { type: "array", items: { type: "string" } },
|
|
214
|
+
assigned: { type: "string", description: "Leave empty so the planner routes it." },
|
|
215
|
+
dependsOn: { type: "array", items: { type: "string" } },
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: "backlog_drop",
|
|
224
|
+
description:
|
|
225
|
+
"Disable an epic, story or task that was never claimed — a plan correction, a duplicate, or a story that no longer applies. " +
|
|
226
|
+
"Nothing is deleted: the item and everything under it move to `cancelled`, dependencies are left in place (a cancelled dependency " +
|
|
227
|
+
"counts as resolved), and each task leaves a `task.dropped` row. Refused if anything under it has been claimed (claimed_at set, " +
|
|
228
|
+
"or any status other than backlog/ready): closing real work is `backlog_done`'s job. `backlog_restore` undoes this.",
|
|
229
|
+
inputSchema: {
|
|
230
|
+
type: "object",
|
|
231
|
+
additionalProperties: false,
|
|
232
|
+
required: ["id"],
|
|
233
|
+
properties: {
|
|
234
|
+
id: { type: "string", description: "Item id (opaque): epic, story or task." },
|
|
235
|
+
reason: { type: "string", description: "Why it is being dropped; recorded on each audit row." },
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: "backlog_restore",
|
|
241
|
+
description:
|
|
242
|
+
"Undo `backlog_drop`: return a dropped epic, story or task, and everything dropped with it, to the queue (epic ready, " +
|
|
243
|
+
"story ready, task ready), writing a `task.restored` row for each. Dependencies were never removed, so ordering comes back intact.",
|
|
244
|
+
inputSchema: {
|
|
245
|
+
type: "object",
|
|
246
|
+
additionalProperties: false,
|
|
247
|
+
required: ["id"],
|
|
248
|
+
properties: { id: { type: "string", description: "Item id (opaque): epic, story or task." } },
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: "backlog_get",
|
|
253
|
+
description:
|
|
254
|
+
"Read the backlog at any level with one call: pass an epic item id for the whole tree (stories, acceptance, every task, results, " +
|
|
255
|
+
"artifacts, counts), a story item id for the story with its tasks and parent epic, or a task item id for the task with its story " +
|
|
256
|
+
"acceptance, epic, artifacts, dependencies and readiness. Read-only; never claims.",
|
|
257
|
+
inputSchema: {
|
|
258
|
+
type: "object",
|
|
259
|
+
additionalProperties: false,
|
|
260
|
+
required: ["id"],
|
|
261
|
+
properties: {
|
|
262
|
+
id: { type: "string", description: "Item id (opaque): epic, story or task." },
|
|
263
|
+
capabilities: {
|
|
264
|
+
type: "array",
|
|
265
|
+
items: { type: "string" },
|
|
266
|
+
description: "For a task read: capability tags this agent offers, used only to report readiness.",
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
name: "backlog_accept_wake",
|
|
273
|
+
description:
|
|
274
|
+
"Acquire the execution lease for a story/append/review wake. Call this once before doing planner work. " +
|
|
275
|
+
"The dispatcher marks one consumer active; this CAS makes it the only session allowed to act.",
|
|
276
|
+
inputSchema: {
|
|
277
|
+
type: "object",
|
|
278
|
+
additionalProperties: false,
|
|
279
|
+
required: ["admissionId", "attemptNo", "leaseEpoch"],
|
|
280
|
+
properties: {
|
|
281
|
+
admissionId: { type: "string", description: "Admission id from the wake payload." },
|
|
282
|
+
attemptNo: { type: "integer", description: "Attempt number from the wake payload." },
|
|
283
|
+
leaseEpoch: { type: "integer", description: "Lease epoch from the wake payload; stale epochs are rejected." },
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
name: "backlog_update",
|
|
289
|
+
description:
|
|
290
|
+
"Report liveness and progress on a task you have claimed. `heartbeat: true` refreshes last_heartbeat " +
|
|
291
|
+
"(the sweeper reclaims tasks whose lease expires without heartbeats). `progressSummary`/`comment` append " +
|
|
292
|
+
"an audit event. Only the assigned agent may update.",
|
|
293
|
+
inputSchema: {
|
|
294
|
+
type: "object",
|
|
295
|
+
additionalProperties: false,
|
|
296
|
+
required: ["taskId"],
|
|
297
|
+
properties: {
|
|
298
|
+
taskId: { type: "string", description: "Task item id (opaque)." },
|
|
299
|
+
attemptId: { type: "string", description: "Attempt id from recovery or claim; fences a stale session out of a newer attempt." },
|
|
300
|
+
leaseEpoch: { type: "integer", description: "Execution lease epoch from claim or recovery; required for wake-owned attempts." },
|
|
301
|
+
heartbeat: { type: "boolean", description: "Refresh liveness (default true)." },
|
|
302
|
+
progressSummary: { type: "string", description: "One-line progress note for the audit trail." },
|
|
303
|
+
comment: { type: "string", description: "Freeform note appended as an audit event." },
|
|
304
|
+
addArtifact: { type: "string", description: "Artifact path/URL produced so far; recorded as an audit event and carried into downstream handoffs." },
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
name: "backlog_done",
|
|
310
|
+
description:
|
|
311
|
+
"Close a task you have claimed: status → done, result summary recorded, audit event appended. " +
|
|
312
|
+
"Only the assigned agent may complete it. The next dependent task becomes claimable.",
|
|
313
|
+
inputSchema: {
|
|
314
|
+
type: "object",
|
|
315
|
+
additionalProperties: false,
|
|
316
|
+
required: ["taskId", "resultSummary"],
|
|
317
|
+
properties: {
|
|
318
|
+
taskId: { type: "string", description: "Task item id (opaque)." },
|
|
319
|
+
attemptId: { type: "string", description: "Attempt id from recovery or claim; fences a stale session out of a newer attempt." },
|
|
320
|
+
leaseEpoch: { type: "integer", description: "Execution lease epoch from claim or recovery; required for wake-owned attempts." },
|
|
321
|
+
resultSummary: { type: "string", description: "One-paragraph outcome (success or failure)." },
|
|
322
|
+
artifacts: { type: "array", items: { type: "string" }, description: "Paths/URLs of produced artifacts (diff, doc, PR)." },
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
name: "backlog_block",
|
|
328
|
+
description:
|
|
329
|
+
"Mark a task you have claimed as blocked with a reason; optionally declare what it is blocked by " +
|
|
330
|
+
"(`blockedBy: {kind, id}`) which adds a dependency edge (cycle-checked). Blocked tasks leave the " +
|
|
331
|
+
"ready queue until an operator unblocks them. Only the assigned agent may block.",
|
|
332
|
+
inputSchema: {
|
|
333
|
+
type: "object",
|
|
334
|
+
additionalProperties: false,
|
|
335
|
+
required: ["taskId", "reason"],
|
|
336
|
+
properties: {
|
|
337
|
+
taskId: { type: "string", description: "Task item id (opaque)." },
|
|
338
|
+
attemptId: { type: "string", description: "Attempt id from recovery or claim; fences a stale session out of a newer attempt." },
|
|
339
|
+
leaseEpoch: { type: "integer", description: "Execution lease epoch from claim or recovery; required for wake-owned attempts." },
|
|
340
|
+
reason: { type: "string", description: "Why the task cannot proceed." },
|
|
341
|
+
gateType: { type: "string", description: "Human gate being opened (roadmap|architecture|release|custom) — stamps gate_type; resume clears it." },
|
|
342
|
+
blockedBy: {
|
|
343
|
+
type: "object",
|
|
344
|
+
additionalProperties: false,
|
|
345
|
+
required: ["kind", "id"],
|
|
346
|
+
properties: {
|
|
347
|
+
kind: { type: "string", enum: ["epic", "story", "task"] },
|
|
348
|
+
id: { type: "string" },
|
|
349
|
+
},
|
|
350
|
+
description: "Item this task now depends on (edge added, cycle-checked).",
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
name: "backlog_resume",
|
|
357
|
+
description:
|
|
358
|
+
"Operator resolution of a human gate: blocked → ready with claim fields and gate metadata cleared, " +
|
|
359
|
+
"so the task re-enters the queue for a fresh claim. One resume per gate — a second call is rejected " +
|
|
360
|
+
"as not_resumable.",
|
|
361
|
+
inputSchema: {
|
|
362
|
+
type: "object",
|
|
363
|
+
additionalProperties: false,
|
|
364
|
+
required: ["taskId"],
|
|
365
|
+
properties: {
|
|
366
|
+
taskId: { type: "string", description: "Task item id (opaque)." },
|
|
367
|
+
actor: { type: "string", description: "Must equal the caller's agent when given; anyone else's name is rejected as actor_mismatch. Defaults to the caller." },
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
];
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// delegate.js — hand work to another worker without changing the parent's
|
|
2
|
+
// accountable assignee. The child is the worker's item; the parent stays with
|
|
3
|
+
// the accountable and waits on the child.
|
|
4
|
+
import { addDep } from "../deps.js";
|
|
5
|
+
import { HUMAN_AGENT, HUMAN_HARNESS } from "../reserved.js";
|
|
6
|
+
import { clampNote, err, ok } from "./shared.js";
|
|
7
|
+
|
|
8
|
+
export function createDelegateTools({ store, logger }) {
|
|
9
|
+
return {
|
|
10
|
+
async backlog_delegate(args, identity, cfg) {
|
|
11
|
+
const parentId = args?.taskId ?? args?.id;
|
|
12
|
+
if (!parentId) return err("backlog_delegate: taskId is required", "rejected");
|
|
13
|
+
const parent = store.task.get(parentId);
|
|
14
|
+
if (!parent) return err(`backlog_delegate: task not found: ${parentId}`, "not_found");
|
|
15
|
+
|
|
16
|
+
const worker = args?.agent;
|
|
17
|
+
if (worker === null || worker === "" || worker === undefined) {
|
|
18
|
+
return err("backlog_delegate: agent is required", "rejected", { taskId: parent.id });
|
|
19
|
+
}
|
|
20
|
+
const childKey = args?.childKey == null || args.childKey === "" ? null : String(args.childKey);
|
|
21
|
+
const visitSeq = args?.visitSeq == null ? 0 : Number(args.visitSeq);
|
|
22
|
+
if (!Number.isInteger(visitSeq) || visitSeq < 0) {
|
|
23
|
+
return err("backlog_delegate: visitSeq must be a non-negative integer", "rejected", { taskId: parent.id });
|
|
24
|
+
}
|
|
25
|
+
if (parent.assignee_agent && parent.assignee_agent !== identity.agent) {
|
|
26
|
+
return err(
|
|
27
|
+
`${parent.id} is assigned to ${parent.assignee_agent}, not ${identity.agent}; only the accountable can delegate it.`,
|
|
28
|
+
"not_assignee",
|
|
29
|
+
{ taskId: parent.id, assigned: parent.assignee_agent }
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const actor = `${identity.harness}:${identity.agent}`;
|
|
34
|
+
const depWait = parent.status === "blocked" && parent.state_json?.wait?.kind === "deps";
|
|
35
|
+
|
|
36
|
+
// A retry of the same (parent, childKey, visitSeq) is a lookup, not a
|
|
37
|
+
// second delegation. Do it before the blocked check: the first attempt
|
|
38
|
+
// parked the parent.
|
|
39
|
+
if (childKey) {
|
|
40
|
+
const existing = store.item.byChild(parent.id, childKey, visitSeq);
|
|
41
|
+
if (existing) {
|
|
42
|
+
addDep(store, parent.id, existing.id);
|
|
43
|
+
if (!["blocked", "done", "cancelled", "review"].includes(parent.status) &&
|
|
44
|
+
existing.status !== "done" && existing.status !== "cancelled") {
|
|
45
|
+
store.task.blockOnDeps({
|
|
46
|
+
id: parent.id,
|
|
47
|
+
note: `delegated ${existing.id} to ${existing.assignee_agent ?? worker}`,
|
|
48
|
+
childId: existing.id,
|
|
49
|
+
actor,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const freshParent = store.task.get(parent.id);
|
|
53
|
+
return ok(
|
|
54
|
+
JSON.stringify({
|
|
55
|
+
ok: true,
|
|
56
|
+
reused: true,
|
|
57
|
+
parent: { id: freshParent.id, status: freshParent.status, assigned: freshParent.assignee_agent },
|
|
58
|
+
child: { id: existing.id, status: existing.status, assigned: existing.assignee_agent, childKey, visitSeq },
|
|
59
|
+
}),
|
|
60
|
+
{ status: "ok", taskId: parent.id, childId: existing.id, agent: identity.agent, reused: true }
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (parent.status === "done" || parent.status === "cancelled") {
|
|
66
|
+
return err(`${parent.id} is ${parent.status}; only live tasks can delegate.`, "rejected", { taskId: parent.id });
|
|
67
|
+
}
|
|
68
|
+
if (parent.status === "blocked" && !depWait) {
|
|
69
|
+
return err(`${parent.id} is already blocked; resolve or close its current wait before delegating again.`, "rejected", { taskId: parent.id });
|
|
70
|
+
}
|
|
71
|
+
if (parent.status === "review") {
|
|
72
|
+
return err(`${parent.id} is in review; accept or return it before delegating.`, "rejected", { taskId: parent.id });
|
|
73
|
+
}
|
|
74
|
+
if (!args?.title) return err("backlog_delegate: title is required", "rejected", { taskId: parent.id });
|
|
75
|
+
|
|
76
|
+
if (!parent.assignee_agent) {
|
|
77
|
+
store.task.assign({ id: parent.id, agentId: identity.agent, harness: identity.harness, actor });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let parentSession = null;
|
|
81
|
+
if (identity.session) {
|
|
82
|
+
parentSession = store.session.ensure({
|
|
83
|
+
harness: identity.harness,
|
|
84
|
+
agentId: identity.agent,
|
|
85
|
+
externalSessionId: identity.session,
|
|
86
|
+
itemId: parent.id,
|
|
87
|
+
kind: "claim",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let child;
|
|
92
|
+
try {
|
|
93
|
+
child = store.task.create({
|
|
94
|
+
storyId: parent.id,
|
|
95
|
+
title: args.title,
|
|
96
|
+
description: args.description ?? null,
|
|
97
|
+
acceptance: args.acceptance ?? parent.acceptance ?? null,
|
|
98
|
+
status: "backlog",
|
|
99
|
+
executionKind: args.executionKind ?? "manual",
|
|
100
|
+
executionArgs: args.executionArgs,
|
|
101
|
+
capabilities: args.capabilities ?? parent.capabilities,
|
|
102
|
+
assigned: worker,
|
|
103
|
+
assigneeHarness: worker === HUMAN_AGENT ? HUMAN_HARNESS : identity.harness,
|
|
104
|
+
childKey,
|
|
105
|
+
visitSeq,
|
|
106
|
+
state: parentSession ? { fanout: { parentSessionId: parentSession.id } } : undefined,
|
|
107
|
+
});
|
|
108
|
+
} catch (e) {
|
|
109
|
+
return err(`backlog_delegate failed: ${e?.message}`, "error", { taskId: parent.id });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const edge = addDep(store, parent.id, child.id);
|
|
113
|
+
if (!edge.ok) {
|
|
114
|
+
try { store.item.drop(child.id, { reason: "delegate failed", actor }); } catch { /* best effort */ }
|
|
115
|
+
return err(`backlog_delegate: dependency rejected: ${edge.code}`, "error", { taskId: parent.id });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
const reason = args?.reason == null ? null : clampNote(args.reason, cfg.noteReasonLimit);
|
|
120
|
+
const note = reason
|
|
121
|
+
? `delegated ${child.id} to ${worker}: ${reason}`
|
|
122
|
+
: `delegated ${child.id} to ${worker}`;
|
|
123
|
+
if (depWait) {
|
|
124
|
+
store.event.append({
|
|
125
|
+
itemId: parent.id, fromStatus: "blocked", toStatus: "blocked", kind: "deps.waiting",
|
|
126
|
+
actor, note: `waiting on ${child.id}`,
|
|
127
|
+
});
|
|
128
|
+
} else {
|
|
129
|
+
store.task.blockOnDeps({ id: parent.id, note, childId: child.id, actor });
|
|
130
|
+
}
|
|
131
|
+
logger?.info?.(`backlog: ${actor} delegated ${parent.id} -> ${child.id} (${worker})`);
|
|
132
|
+
const fresh = store.task.get(parent.id);
|
|
133
|
+
return ok(
|
|
134
|
+
JSON.stringify({
|
|
135
|
+
ok: true,
|
|
136
|
+
parent: { id: fresh.id, status: fresh.status, assigned: fresh.assignee_agent },
|
|
137
|
+
child: { id: child.id, status: child.status, assigned: child.assignee_agent, childKey, visitSeq },
|
|
138
|
+
}),
|
|
139
|
+
{ status: "ok", taskId: parent.id, childId: child.id, agent: identity.agent }
|
|
140
|
+
);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
try { store.item.drop(child.id, { reason: "delegate failed", actor }); } catch { /* best effort */ }
|
|
143
|
+
return err(`backlog_delegate failed: ${e?.message}`, "error", { taskId: parent.id });
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// index.js — assembles the tool surface. Identity is never a tool param: the
|
|
2
|
+
// caller comes from the resolved identity, so no agent can act as another.
|
|
3
|
+
//
|
|
4
|
+
// Claim semantics are the store's CAS (`status='ready' AND assignee_harness=? AND
|
|
5
|
+
// assignee_agent=?`): a race loser gets `claim === null` and moves on. There is
|
|
6
|
+
// no blocking wait inside a tool call.
|
|
7
|
+
|
|
8
|
+
import { assertCleanTriple } from "../identity.js";
|
|
9
|
+
import { resolveRequestConfig } from "../config.js";
|
|
10
|
+
import { TOOL_DEFS } from "./definitions.js";
|
|
11
|
+
import { err } from "./shared.js";
|
|
12
|
+
import { createClaimTools } from "./claim.js";
|
|
13
|
+
import { createAcceptWakeTools } from "./accept-wake.js";
|
|
14
|
+
import { createAssignTools } from "./assign.js";
|
|
15
|
+
import { createDelegateTools } from "./delegate.js";
|
|
16
|
+
import { createPlanTools } from "./plan.js";
|
|
17
|
+
import { createReadTools } from "./read.js";
|
|
18
|
+
import { createReportTools } from "./report.js";
|
|
19
|
+
|
|
20
|
+
export { TOOL_DEFS } from "./definitions.js";
|
|
21
|
+
export { collectStoryArtifacts, renderReceiverPrompt } from "./shared.js";
|
|
22
|
+
|
|
23
|
+
export function createToolHandlers(store, logger) {
|
|
24
|
+
const baseConfig = store.config;
|
|
25
|
+
const handlers = {
|
|
26
|
+
...createClaimTools({ store, logger }),
|
|
27
|
+
...createAcceptWakeTools({ store, logger }),
|
|
28
|
+
...createAssignTools({ store, logger }),
|
|
29
|
+
...createDelegateTools({ store, logger }),
|
|
30
|
+
...createPlanTools({ store, logger }),
|
|
31
|
+
...createReadTools({ store, logger }),
|
|
32
|
+
...createReportTools({ store, logger }),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
async function handle(name, args, identity, meta = null) {
|
|
36
|
+
assertCleanTriple(identity, `caller identity for ${name}`);
|
|
37
|
+
const cfg = resolveRequestConfig(baseConfig, meta);
|
|
38
|
+
const fn = handlers[name];
|
|
39
|
+
if (!fn) return err(`unknown tool: ${name}`, "unknown_tool");
|
|
40
|
+
return fn(args, identity, cfg);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { TOOL_DEFS, handle };
|
|
44
|
+
}
|