@igorjpimenta/winch 0.0.0-stage → 2026.11.22-beta.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.
- 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 +198 -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
package/src/watcher.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// watcher.js — one delivery-watcher tick: sweep expired leases, compute the
|
|
3
|
+
// claimable set, emit a wake manifest for the cron that drives it.
|
|
4
|
+
//
|
|
5
|
+
// Claimable-ness is a stored predicate (ready-queue SQL over deps/status
|
|
6
|
+
// columns), so a missed or delayed wake costs only latency — the next tick
|
|
7
|
+
// recomputes the same set. That loss-tolerance is the point: this script must
|
|
8
|
+
// never be load-bearing for correctness, only for promptness.
|
|
9
|
+
//
|
|
10
|
+
// Exit code is always 0, including on an empty tick — silence is the calling
|
|
11
|
+
// cron message's decision, not the script's.
|
|
12
|
+
|
|
13
|
+
import { pathToFileURL } from "node:url";
|
|
14
|
+
import { HUMAN_AGENT } from "./reserved.js";
|
|
15
|
+
import { createStore } from "./store/index.js";
|
|
16
|
+
import { readyTasks } from "./ready-queue.js";
|
|
17
|
+
|
|
18
|
+
// An agent this busy should finish before it hears about more work. Keeps the
|
|
19
|
+
// wake queue from stacking claims on an already-loaded assignee; the deferred
|
|
20
|
+
// list is the starvation signal.
|
|
21
|
+
export const MAX_ACTIVE_PER_AGENT = 2;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @returns {{ts:number, swept:string[], resolved:string[], waits:object[], routed:object[], human:object[], deferred:object[], unrouted:object[], blocked:object[], gates:object[]}}
|
|
25
|
+
* swept — lease-expired tasks the sweep requeued or escalated this tick
|
|
26
|
+
* resolved — dependency-wait tasks returned to ready this tick
|
|
27
|
+
* waits — gate-waiting rows written this tick (24h/72h age thresholds, one per gate per level)
|
|
28
|
+
* routed — claimable AND assigned AND assignee under the active cap: the cron wakes `assigned`
|
|
29
|
+
* human — claimable human work: ready for a person, never woken through an agent harness
|
|
30
|
+
* deferred — claimable AND assigned BUT assignee at MAX_ACTIVE: never woken (starvation metric)
|
|
31
|
+
* unrouted — always empty while ready requires an assignment; kept for manifest compatibility
|
|
32
|
+
*/
|
|
33
|
+
export function tick(store, { config: override = null } = {}) {
|
|
34
|
+
const cfg = override ?? store.config;
|
|
35
|
+
const nowTs = Date.now();
|
|
36
|
+
const swept = store.task.sweepExpired({});
|
|
37
|
+
const resolved = store.task.resumeDependencyWaits({ at: nowTs });
|
|
38
|
+
const waits = store.task.recordGateWaits({ now: nowTs });
|
|
39
|
+
const claimable = readyTasks(store, { limit: cfg.scanLimit }).map((r) => ({
|
|
40
|
+
taskId: r.task.id,
|
|
41
|
+
title: r.task.title,
|
|
42
|
+
executionKind: r.task.execution_kind,
|
|
43
|
+
executionArgs: r.task.execution_args,
|
|
44
|
+
assigned: r.task.assignee_agent,
|
|
45
|
+
assignedHarness: r.task.assignee_harness,
|
|
46
|
+
capabilities: r.task.capabilities,
|
|
47
|
+
storyId: r.story.id,
|
|
48
|
+
epicId: r.epic.id,
|
|
49
|
+
}));
|
|
50
|
+
const blocked = store.item
|
|
51
|
+
.list({ kind: "task", status: "blocked" })
|
|
52
|
+
.slice(0, cfg.blockedLimit)
|
|
53
|
+
.map((t) => ({ id: t.id, title: t.title, assigned: t.assignee_agent, gate_type: t.gate_type, blocked_at: t.blocked_at }));
|
|
54
|
+
// Gated tasks are separated from plain blocks for visibility. Who should
|
|
55
|
+
// be told about them is a subscriber decision — the events WebSocket
|
|
56
|
+
// streams every row, and clients track their own seen state.
|
|
57
|
+
const gates = store.item
|
|
58
|
+
.list({ kind: "task", status: "blocked" })
|
|
59
|
+
.filter((t) => t.gate_type)
|
|
60
|
+
.sort((a, b) => (a.blocked_at ?? 0) - (b.blocked_at ?? 0))
|
|
61
|
+
.map((t) => ({ id: t.id, title: t.title, gate_type: t.gate_type, blocked_at: t.blocked_at, assigned: t.assignee_agent }));
|
|
62
|
+
const active = new Map();
|
|
63
|
+
for (const t of store.item.list({ kind: "task", status: "in_progress" })) {
|
|
64
|
+
if (!t.assignee_agent) continue;
|
|
65
|
+
active.set(t.assignee_agent, (active.get(t.assignee_agent) ?? 0) + 1);
|
|
66
|
+
}
|
|
67
|
+
const human = claimable.filter((c) => c.assigned === HUMAN_AGENT);
|
|
68
|
+
const routed = claimable.filter(
|
|
69
|
+
(c) => c.assigned && c.assigned !== HUMAN_AGENT && (active.get(c.assigned) ?? 0) < cfg.maxActivePerAgent
|
|
70
|
+
);
|
|
71
|
+
const deferred = claimable
|
|
72
|
+
.filter((c) => c.assigned && c.assigned !== HUMAN_AGENT && (active.get(c.assigned) ?? 0) >= cfg.maxActivePerAgent)
|
|
73
|
+
.map((c) => ({ ...c, activeCount: active.get(c.assigned) }));
|
|
74
|
+
const unrouted = claimable
|
|
75
|
+
.filter((c) => !c.assigned)
|
|
76
|
+
// Waiting-age gauge: the wire streams transitions, never waiting, so the
|
|
77
|
+
// manifest carries how long each unrouted task has sat idle instead.
|
|
78
|
+
.map((c) => {
|
|
79
|
+
const row = store.task.get(c.taskId);
|
|
80
|
+
return { ...c, idleMs: row ? nowTs - (row.updated_at ?? nowTs) : 0 };
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
ts: nowTs,
|
|
85
|
+
swept: swept.map((t) => t.id),
|
|
86
|
+
resolved,
|
|
87
|
+
waits,
|
|
88
|
+
routed,
|
|
89
|
+
human,
|
|
90
|
+
deferred,
|
|
91
|
+
unrouted,
|
|
92
|
+
blocked,
|
|
93
|
+
gates,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const invokedDirectly = process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;
|
|
98
|
+
if (invokedDirectly) {
|
|
99
|
+
const store = createStore();
|
|
100
|
+
try {
|
|
101
|
+
console.log(JSON.stringify(tick(store)));
|
|
102
|
+
} finally {
|
|
103
|
+
store.close();
|
|
104
|
+
}
|
|
105
|
+
}
|