@brainervirus/workit-opencode 8.16.0 → 8.16.1

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 (2) hide show
  1. package/dist/plugin.js +54 -2
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -24233,13 +24233,56 @@ var createV2Lifecycle = (deps) => {
24233
24233
  const unboundLaunch = (coordinator) => {
24234
24234
  const store = new TaskStore(root);
24235
24235
  const current = currentTaskId(store);
24236
- const base = current === null ? 'recovery_required: this branch has no Workit task yet; start it (workit_task start, or `workit task start "<objective>"`), then assign a worker on it with workit_worker before launching a native task' : "recovery_required: no assigned Workit worker is attributable to this coordinator on the current branch's task; assign one with workit_worker before launching a native task";
24236
+ const base = current === null ? 'recovery_required: this branch has no Workit task yet; start it (workit_task start, or `workit task start "<objective>"`), then assign a worker on it with workit_worker before launching a native task' : "recovery_required: no assigned Workit worker is attributable to this coordinator on the current branch's task (worker assignments are branch-scoped: they follow the task of the branch checked out when the launch happens); assign one with workit_worker on this branch's task before launching a native task";
24237
24237
  const listed = store.listTasks();
24238
24238
  if (!listed.ok)
24239
24239
  return base;
24240
24240
  const stale = listed.data.flatMap((task) => task.status === "active" && task.id !== current ? task.workers.filter((worker) => (worker.data.state === "assigned" || worker.data.state === "running") && worker.provenance.session?.kind === "host" && worker.provenance.session.handle === coordinator).map((worker) => `workit_worker {"action":"cancel","taskId":"${task.id}","workerId":"${worker.id}","reason":"stale worker from another branch"}`) : []);
24241
24241
  return stale.length > 0 ? `${base}. Workers of this coordinator are still open on other tasks; cancel any that are stale: ${stale.join("; ")}` : base;
24242
24242
  };
24243
+ const rebindStaleWorker = (coordinator, current, stale) => {
24244
+ if (stale.length !== 1)
24245
+ return false;
24246
+ const { task: from, entry } = stale[0];
24247
+ const store = new TaskStore(root);
24248
+ const target = store.readTask(current);
24249
+ if (!target.ok || target.data.status !== "active")
24250
+ return false;
24251
+ const core = new WorkitCore(store, {
24252
+ root,
24253
+ caller: { host: "opencode", actor: coordinator },
24254
+ capabilities: [],
24255
+ constraints: [],
24256
+ now
24257
+ });
24258
+ const assigned = core.worker({
24259
+ schemaVersion: 1,
24260
+ action: "assign",
24261
+ taskId: current,
24262
+ assignment: entry.data.assignment
24263
+ });
24264
+ if (!assigned.ok)
24265
+ return false;
24266
+ const cancelled = core.worker({
24267
+ schemaVersion: 1,
24268
+ action: "cancel",
24269
+ taskId: from.id,
24270
+ workerId: entry.id,
24271
+ reason: `rebound to task ${current} (worker ${assigned.data.id}) after a branch switch`
24272
+ });
24273
+ const latest = store.readTask(current);
24274
+ if (cancelled.ok && latest.ok)
24275
+ core.task({
24276
+ schemaVersion: 1,
24277
+ action: "progress",
24278
+ taskId: current,
24279
+ progress: {
24280
+ ...latest.data.progress,
24281
+ summary: `${latest.data.progress.summary} (worker ${assigned.data.id} rebound from task ${from.id} after a branch switch)`
24282
+ }
24283
+ });
24284
+ return cancelled.ok;
24285
+ };
24243
24286
  const prepareDispatch = (coordinator, callID) => {
24244
24287
  if (dispatches.has(coordinator))
24245
24288
  return "unsettled";
@@ -24253,7 +24296,16 @@ var createV2Lifecycle = (deps) => {
24253
24296
  return "unmanaged";
24254
24297
  const eligible = managed.flatMap((task) => task.workers.filter((entry) => entry.data.state === "assigned" && entry.data.session === null && entry.provenance.session?.kind === "host" && entry.provenance.session.host === "opencode" && entry.provenance.session.handle === coordinator).map((entry) => ({ task, entry })));
24255
24298
  const current = currentTaskId(store);
24256
- const next = oldest(eligible.filter((item) => item.task.id === current));
24299
+ let next = oldest(eligible.filter((item) => item.task.id === current));
24300
+ if (!next && current !== null) {
24301
+ const stale = eligible.filter((item) => item.task.id !== current);
24302
+ if (rebindStaleWorker(coordinator, current, stale)) {
24303
+ const refreshed = store.readTask(current);
24304
+ const rebound = refreshed.ok ? refreshed.data.workers.filter((entry) => entry.data.state === "assigned" && entry.data.session === null && entry.provenance.session?.kind === "host" && entry.provenance.session.handle === coordinator) : [];
24305
+ if (refreshed.ok && rebound.length > 0)
24306
+ next = oldest(rebound.map((entry) => ({ task: refreshed.data, entry })));
24307
+ }
24308
+ }
24257
24309
  if (!next)
24258
24310
  return "unbound";
24259
24311
  dispatches.set(coordinator, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brainervirus/workit-opencode",
3
- "version": "8.16.0",
3
+ "version": "8.16.1",
4
4
  "private": false,
5
5
  "description": "Workit OpenCode plugin — native tools, adaptive policy, and sixteen method skills",
6
6
  "keywords": [
@@ -39,7 +39,7 @@
39
39
  "typecheck": "tsc --noEmit"
40
40
  },
41
41
  "devDependencies": {
42
- "@brainervirus/workit-core": "^8.16.0",
42
+ "@brainervirus/workit-core": "^8.16.1",
43
43
  "@opencode/plugin": "2.0.18"
44
44
  },
45
45
  "engines": {