@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.
Files changed (88) hide show
  1. package/.migrations/0000_next_katie_power.sql +99 -0
  2. package/.migrations/0001_add-events-kind.sql +8 -0
  3. package/.migrations/0002_drop-session-budgets.sql +1 -0
  4. package/.migrations/0003_pink_siren.sql +8 -0
  5. package/.migrations/0004_salty_trauma.sql +1 -0
  6. package/.migrations/0005_classy_havok.sql +1 -0
  7. package/.migrations/0006_recursive_items.sql +265 -0
  8. package/.migrations/0007_unify_statuses.sql +35 -0
  9. package/.migrations/0008_core_dispatch.sql +61 -0
  10. package/.migrations/0009_webhooks.sql +17 -0
  11. package/.migrations/0010_dispatch_consumer_id.sql +1 -0
  12. package/.migrations/0011_dispatch_delivery_leases.sql +53 -0
  13. package/.migrations/0012_dispatch_fencing_audit.sql +32 -0
  14. package/.migrations/meta/0000_snapshot.json +658 -0
  15. package/.migrations/meta/0001_snapshot.json +665 -0
  16. package/.migrations/meta/0002_snapshot.json +604 -0
  17. package/.migrations/meta/0003_snapshot.json +656 -0
  18. package/.migrations/meta/0004_snapshot.json +664 -0
  19. package/.migrations/meta/0005_snapshot.json +671 -0
  20. package/.migrations/meta/0006_snapshot.json +1089 -0
  21. package/.migrations/meta/0007_unify_statuses_snapshot.json +1097 -0
  22. package/.migrations/meta/0008_snapshot.json +1382 -0
  23. package/.migrations/meta/0009_snapshot.json +1428 -0
  24. package/.migrations/meta/0010_snapshot.json +1435 -0
  25. package/.migrations/meta/0011_snapshot.json +1670 -0
  26. package/.migrations/meta/0012_snapshot.json +1900 -0
  27. package/.migrations/meta/_journal.json +97 -0
  28. package/README.md +480 -2
  29. package/bin/winch.js +4 -0
  30. package/package.json +36 -4
  31. package/plugins/README.md +304 -0
  32. package/plugins/openclaw/winch/README.md +71 -0
  33. package/plugins/openclaw/winch/dispatch.js +236 -0
  34. package/plugins/openclaw/winch/index.js +139 -0
  35. package/plugins/openclaw/winch/meta.js +35 -0
  36. package/plugins/openclaw/winch/openclaw.plugin.json +43 -0
  37. package/plugins/openclaw/winch/package.json +37 -0
  38. package/plugins/opencode/winch/dispatch.js +228 -0
  39. package/plugins/opencode/winch/hooks.js +22 -0
  40. package/plugins/opencode/winch/identity.js +34 -0
  41. package/plugins/opencode/winch/index.js +104 -0
  42. package/plugins/opencode/winch/package.json +26 -0
  43. package/src/cli.js +434 -0
  44. package/src/config.js +181 -0
  45. package/src/db.js +39 -0
  46. package/src/deps.js +70 -0
  47. package/src/dispatch-server.js +204 -0
  48. package/src/dispatch-webhook.js +221 -0
  49. package/src/dispatch.js +258 -0
  50. package/src/events-ws.js +269 -0
  51. package/src/identity.js +140 -0
  52. package/src/ids.js +18 -0
  53. package/src/mcp-http.js +208 -0
  54. package/src/mcp.js +107 -0
  55. package/src/merges.js +150 -0
  56. package/src/paths.js +15 -0
  57. package/src/ready-queue.js +77 -0
  58. package/src/release.js +96 -0
  59. package/src/reserved.js +23 -0
  60. package/src/schema.js +302 -0
  61. package/src/store/admission.js +314 -0
  62. package/src/store/artifacts.js +24 -0
  63. package/src/store/attempts.js +22 -0
  64. package/src/store/claims.js +182 -0
  65. package/src/store/core.js +225 -0
  66. package/src/store/delivery.js +137 -0
  67. package/src/store/deps.js +62 -0
  68. package/src/store/dispatch-events.js +38 -0
  69. package/src/store/epics.js +31 -0
  70. package/src/store/events.js +21 -0
  71. package/src/store/gates.js +85 -0
  72. package/src/store/index.js +135 -0
  73. package/src/store/items.js +303 -0
  74. package/src/store/stories.js +37 -0
  75. package/src/store/sweep.js +77 -0
  76. package/src/store/tasks.js +190 -0
  77. package/src/store/webhook.js +197 -0
  78. package/src/tools/accept-wake.js +30 -0
  79. package/src/tools/assign.js +75 -0
  80. package/src/tools/claim.js +88 -0
  81. package/src/tools/definitions.js +371 -0
  82. package/src/tools/delegate.js +147 -0
  83. package/src/tools/index.js +44 -0
  84. package/src/tools/plan.js +262 -0
  85. package/src/tools/read.js +103 -0
  86. package/src/tools/report.js +190 -0
  87. package/src/tools/shared.js +62 -0
  88. 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
+ }