@brainervirus/workit-opencode 8.14.0 → 8.14.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 +49 -9
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -7772,6 +7772,8 @@ var text = string2().check((ctx) => {
7772
7772
  ctx.issues.push({ code: "custom", input: ctx.value, message: "invalid Unicode", path: [] });
7773
7773
  });
7774
7774
  var id = text.regex(uuidPattern, "expected lowercase UUID");
7775
+ var idRefPattern = /^[0-9a-f][0-9a-f-]{7,35}$/;
7776
+ var idRef = text.regex(idRefPattern, "expected a UUID or an id prefix of 8+ characters");
7775
7777
  var digest = text.regex(digestPattern, "expected lowercase SHA-256 digest");
7776
7778
  var revision = text.regex(uuidPattern, "expected UUID revision");
7777
7779
  var validUtc = (value) => {
@@ -8149,7 +8151,7 @@ var workerReportSchema = object({
8149
8151
  outcome: _enum(["completed", "failed", "cancelled"]),
8150
8152
  summary: text,
8151
8153
  evidenceIds: array(id),
8152
- findingIds: array(id)
8154
+ findingIds: array(idRef)
8153
8155
  }).strict();
8154
8156
  var workerSchema = object({
8155
8157
  assignment: assignmentSchema,
@@ -8395,7 +8397,7 @@ var findingOperations = {
8395
8397
  action: literal("resolve"),
8396
8398
  ...taskId,
8397
8399
  expectedRevision: revision.optional(),
8398
- findingId: id,
8400
+ findingId: idRef,
8399
8401
  disposition: _enum(["open", "fixed", "dismissed", "deferred"]),
8400
8402
  reason: text,
8401
8403
  evidenceIds: array(id),
@@ -8436,7 +8438,7 @@ var workerOperations = {
8436
8438
  ...taskId,
8437
8439
  expectedRevision: revision.optional(),
8438
8440
  expectedWorkspaceRevision: revision.optional(),
8439
- workerId: id,
8441
+ workerId: idRef,
8440
8442
  report: workerReportSchema
8441
8443
  }),
8442
8444
  cancel: operation({
@@ -8444,7 +8446,7 @@ var workerOperations = {
8444
8446
  ...taskId,
8445
8447
  ...revisions,
8446
8448
  expectedWorkspaceRevision: revision.optional(),
8447
- workerId: id,
8449
+ workerId: idRef,
8448
8450
  reason: text
8449
8451
  })
8450
8452
  };
@@ -8494,6 +8496,16 @@ var success = (revisionValue, workspaceRevisionValue, data) => ({
8494
8496
  data
8495
8497
  });
8496
8498
  var failure2 = (code, error, details = {}) => ({ ok: false, schemaVersion: 1, code, error, details });
8499
+ function resolveIdRef(kind, ref, ids) {
8500
+ if (ids.includes(ref))
8501
+ return success(null, null, ref);
8502
+ const matches = ids.filter((candidate) => candidate.startsWith(ref));
8503
+ if (matches.length === 1)
8504
+ return success(null, null, matches[0]);
8505
+ if (matches.length === 0)
8506
+ return failure2("not_found", `${kind} not found`);
8507
+ return failure2("invalid_input", `${kind} prefix ${ref} is ambiguous; candidates: ${matches.join(", ")}`);
8508
+ }
8497
8509
  function parseOperation(family, input) {
8498
8510
  if (typeof input === "object" && input !== null && "schemaVersion" in input && input.schemaVersion !== SCHEMA_VERSION)
8499
8511
  return failure2("unsupported_version", "unsupported schema version", { operation: family });
@@ -11003,20 +11015,26 @@ class TaskStore {
11003
11015
  return success(null, null, { key: key.data, bound: bound.data });
11004
11016
  }
11005
11017
  taskForWorker(workerId) {
11006
- if (typeof workerId !== "string" || !validId(workerId))
11018
+ if (typeof workerId !== "string" || !idRefPattern.test(workerId))
11007
11019
  return failure2("invalid_input", "needs a worker id: `workit worker cancel|report <workerId>`");
11008
11020
  const listed = this.listTaskIndex();
11009
11021
  if (!listed.ok)
11010
11022
  return listed;
11023
+ const owners = new Map;
11011
11024
  for (const entry of listed.data) {
11012
11025
  if (entry.status === "closed")
11013
11026
  continue;
11014
11027
  const loaded = this.load(entry.id);
11015
11028
  if (!loaded.ok)
11016
11029
  return loaded;
11017
- if (loaded.data?.record.workers.some((worker) => worker.id === workerId))
11018
- return success(null, null, entry.id);
11030
+ for (const worker of loaded.data?.record.workers ?? [])
11031
+ owners.set(worker.id, entry.id);
11019
11032
  }
11033
+ const resolved = resolveIdRef("worker", workerId, [...owners.keys()]);
11034
+ if (resolved.ok)
11035
+ return success(null, null, owners.get(resolved.data) ?? null);
11036
+ if (resolved.code !== "not_found")
11037
+ return resolved;
11020
11038
  return success(null, null, null);
11021
11039
  }
11022
11040
  originTaskEntry() {
@@ -18966,6 +18984,8 @@ var TASK_SCOPED_ACTIONS = new Set([
18966
18984
  "worker.cancel",
18967
18985
  "state.export"
18968
18986
  ]);
18987
+ var ONLY_OWN_REPORT = "workers can submit only their own report";
18988
+ var NO_HELPER_CONTROL = "helpers cannot cancel or control workers";
18969
18989
  var WORKER_ADDRESSED_ACTIONS = new Set(["worker.cancel", "worker.report"]);
18970
18990
  var workerCommand = (taskId, request) => {
18971
18991
  const { action, workerId, reason, report } = request;
@@ -19863,6 +19883,10 @@ class WorkitCore {
19863
19883
  }
19864
19884
  if (helper?.ok)
19865
19885
  return failure2("permission_denied", "helpers cannot resolve findings");
19886
+ const findingRef = resolveIdRef("finding", input.findingId, task.data.findings.map((entry) => entry.id));
19887
+ if (!findingRef.ok)
19888
+ return findingRef;
19889
+ input.findingId = findingRef.data;
19866
19890
  const finding = task.data.findings.find((entry) => entry.id === input.findingId);
19867
19891
  if (!finding)
19868
19892
  return failure2("not_found", "finding not found");
@@ -20014,15 +20038,31 @@ class WorkitCore {
20014
20038
  return changed;
20015
20039
  return success(changed.data.task.revision, changed.data.workspace.revision, changed.data.task.workers.at(-1));
20016
20040
  }
20041
+ const workerRef = resolveIdRef("worker", input.workerId, helperId === null ? task.data.workers.map((candidate) => candidate.id) : [helperId]);
20042
+ if (!workerRef.ok)
20043
+ return helperId === null ? workerRef : failure2("permission_denied", input.action === "report" ? ONLY_OWN_REPORT : NO_HELPER_CONTROL);
20044
+ input.workerId = workerRef.data;
20017
20045
  const entry = task.data.workers.find((candidate) => candidate.id === input.workerId);
20018
20046
  if (!entry)
20019
20047
  return failure2("not_found", "worker not found");
20020
20048
  if (input.action === "report") {
20021
20049
  if (helperId === null || helperId !== input.workerId)
20022
- return failure2("permission_denied", "workers can submit only their own report");
20050
+ return failure2("permission_denied", ONLY_OWN_REPORT);
20023
20051
  const helper = this.helperEntry(task.data, true, true);
20024
20052
  if (!helper.ok)
20025
20053
  return helper;
20054
+ const ownFindings = task.data.findings.filter((candidate) => candidate.provenance.workerId === helperId).map((candidate) => candidate.id);
20055
+ const reported = [];
20056
+ for (const findingRef of input.report.findingIds) {
20057
+ const found = resolveIdRef("finding", findingRef, ownFindings);
20058
+ if (found.ok)
20059
+ reported.push(found.data);
20060
+ else if (found.code === "not_found")
20061
+ reported.push(findingRef);
20062
+ else
20063
+ return found;
20064
+ }
20065
+ input.report.findingIds = reported;
20026
20066
  const evidence = task.data.evidence.filter((candidate) => input.report.evidenceIds.includes(candidate.id));
20027
20067
  const findings = task.data.findings.filter((candidate) => input.report.findingIds.includes(candidate.id));
20028
20068
  if (evidence.length !== input.report.evidenceIds.length || findings.length !== input.report.findingIds.length)
@@ -20050,7 +20090,7 @@ class WorkitCore {
20050
20090
  return updated ? success(changed.data.task.revision, changed.data.workspace.revision, updated) : failure2("recovery_required", "worker disappeared during report");
20051
20091
  }
20052
20092
  if (helperId !== null)
20053
- return failure2("permission_denied", "helpers cannot cancel or control workers");
20093
+ return failure2("permission_denied", NO_HELPER_CONTROL);
20054
20094
  if (task.data.status === "closed")
20055
20095
  return failure2("invalid_transition", "closed task cannot cancel workers");
20056
20096
  if (entry.data.state === "stopped") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brainervirus/workit-opencode",
3
- "version": "8.14.0",
3
+ "version": "8.14.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.14.0",
42
+ "@brainervirus/workit-core": "^8.14.1",
43
43
  "@opencode/plugin": "2.0.18"
44
44
  },
45
45
  "engines": {