@brainervirus/workit-pi 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.
package/dist/worker.js CHANGED
@@ -7546,6 +7546,8 @@ var text = string2().check((ctx) => {
7546
7546
  ctx.issues.push({ code: "custom", input: ctx.value, message: "invalid Unicode", path: [] });
7547
7547
  });
7548
7548
  var id = text.regex(uuidPattern, "expected lowercase UUID");
7549
+ var idRefPattern = /^[0-9a-f][0-9a-f-]{7,35}$/;
7550
+ var idRef = text.regex(idRefPattern, "expected a UUID or an id prefix of 8+ characters");
7549
7551
  var digest = text.regex(digestPattern, "expected lowercase SHA-256 digest");
7550
7552
  var revision = text.regex(uuidPattern, "expected UUID revision");
7551
7553
  var validUtc = (value) => {
@@ -7825,7 +7827,7 @@ var workerReportSchema = object({
7825
7827
  outcome: _enum(["completed", "failed", "cancelled"]),
7826
7828
  summary: text,
7827
7829
  evidenceIds: array(id),
7828
- findingIds: array(id)
7830
+ findingIds: array(idRef)
7829
7831
  }).strict();
7830
7832
  var workerSchema = object({
7831
7833
  assignment: assignmentSchema,
@@ -8018,7 +8020,7 @@ var findingOperations = {
8018
8020
  action: literal("resolve"),
8019
8021
  ...taskId,
8020
8022
  expectedRevision: revision.optional(),
8021
- findingId: id,
8023
+ findingId: idRef,
8022
8024
  disposition: _enum(["open", "fixed", "dismissed", "deferred"]),
8023
8025
  reason: text,
8024
8026
  evidenceIds: array(id),
@@ -8059,7 +8061,7 @@ var workerOperations = {
8059
8061
  ...taskId,
8060
8062
  expectedRevision: revision.optional(),
8061
8063
  expectedWorkspaceRevision: revision.optional(),
8062
- workerId: id,
8064
+ workerId: idRef,
8063
8065
  report: workerReportSchema
8064
8066
  }),
8065
8067
  cancel: operation({
@@ -8067,7 +8069,7 @@ var workerOperations = {
8067
8069
  ...taskId,
8068
8070
  ...revisions,
8069
8071
  expectedWorkspaceRevision: revision.optional(),
8070
- workerId: id,
8072
+ workerId: idRef,
8071
8073
  reason: text
8072
8074
  })
8073
8075
  };
package/dist/workit.js CHANGED
@@ -7771,6 +7771,8 @@ var text = string2().check((ctx) => {
7771
7771
  ctx.issues.push({ code: "custom", input: ctx.value, message: "invalid Unicode", path: [] });
7772
7772
  });
7773
7773
  var id = text.regex(uuidPattern, "expected lowercase UUID");
7774
+ var idRefPattern = /^[0-9a-f][0-9a-f-]{7,35}$/;
7775
+ var idRef = text.regex(idRefPattern, "expected a UUID or an id prefix of 8+ characters");
7774
7776
  var digest = text.regex(digestPattern, "expected lowercase SHA-256 digest");
7775
7777
  var revision = text.regex(uuidPattern, "expected UUID revision");
7776
7778
  var validUtc = (value) => {
@@ -8148,7 +8150,7 @@ var workerReportSchema = object({
8148
8150
  outcome: _enum(["completed", "failed", "cancelled"]),
8149
8151
  summary: text,
8150
8152
  evidenceIds: array(id),
8151
- findingIds: array(id)
8153
+ findingIds: array(idRef)
8152
8154
  }).strict();
8153
8155
  var workerSchema = object({
8154
8156
  assignment: assignmentSchema,
@@ -8394,7 +8396,7 @@ var findingOperations = {
8394
8396
  action: literal("resolve"),
8395
8397
  ...taskId,
8396
8398
  expectedRevision: revision.optional(),
8397
- findingId: id,
8399
+ findingId: idRef,
8398
8400
  disposition: _enum(["open", "fixed", "dismissed", "deferred"]),
8399
8401
  reason: text,
8400
8402
  evidenceIds: array(id),
@@ -8435,7 +8437,7 @@ var workerOperations = {
8435
8437
  ...taskId,
8436
8438
  expectedRevision: revision.optional(),
8437
8439
  expectedWorkspaceRevision: revision.optional(),
8438
- workerId: id,
8440
+ workerId: idRef,
8439
8441
  report: workerReportSchema
8440
8442
  }),
8441
8443
  cancel: operation({
@@ -8443,7 +8445,7 @@ var workerOperations = {
8443
8445
  ...taskId,
8444
8446
  ...revisions,
8445
8447
  expectedWorkspaceRevision: revision.optional(),
8446
- workerId: id,
8448
+ workerId: idRef,
8447
8449
  reason: text
8448
8450
  })
8449
8451
  };
@@ -8493,6 +8495,16 @@ var success = (revisionValue, workspaceRevisionValue, data) => ({
8493
8495
  data
8494
8496
  });
8495
8497
  var failure2 = (code, error, details = {}) => ({ ok: false, schemaVersion: 1, code, error, details });
8498
+ function resolveIdRef(kind, ref, ids) {
8499
+ if (ids.includes(ref))
8500
+ return success(null, null, ref);
8501
+ const matches = ids.filter((candidate) => candidate.startsWith(ref));
8502
+ if (matches.length === 1)
8503
+ return success(null, null, matches[0]);
8504
+ if (matches.length === 0)
8505
+ return failure2("not_found", `${kind} not found`);
8506
+ return failure2("invalid_input", `${kind} prefix ${ref} is ambiguous; candidates: ${matches.join(", ")}`);
8507
+ }
8496
8508
  function parseOperation(family, input) {
8497
8509
  if (typeof input === "object" && input !== null && "schemaVersion" in input && input.schemaVersion !== SCHEMA_VERSION)
8498
8510
  return failure2("unsupported_version", "unsupported schema version", { operation: family });
@@ -11036,20 +11048,26 @@ class TaskStore {
11036
11048
  return success(null, null, { key: key.data, bound: bound.data });
11037
11049
  }
11038
11050
  taskForWorker(workerId) {
11039
- if (typeof workerId !== "string" || !validId(workerId))
11051
+ if (typeof workerId !== "string" || !idRefPattern.test(workerId))
11040
11052
  return failure2("invalid_input", "needs a worker id: `workit worker cancel|report <workerId>`");
11041
11053
  const listed = this.listTaskIndex();
11042
11054
  if (!listed.ok)
11043
11055
  return listed;
11056
+ const owners = new Map;
11044
11057
  for (const entry of listed.data) {
11045
11058
  if (entry.status === "closed")
11046
11059
  continue;
11047
11060
  const loaded = this.load(entry.id);
11048
11061
  if (!loaded.ok)
11049
11062
  return loaded;
11050
- if (loaded.data?.record.workers.some((worker) => worker.id === workerId))
11051
- return success(null, null, entry.id);
11063
+ for (const worker of loaded.data?.record.workers ?? [])
11064
+ owners.set(worker.id, entry.id);
11052
11065
  }
11066
+ const resolved = resolveIdRef("worker", workerId, [...owners.keys()]);
11067
+ if (resolved.ok)
11068
+ return success(null, null, owners.get(resolved.data) ?? null);
11069
+ if (resolved.code !== "not_found")
11070
+ return resolved;
11053
11071
  return success(null, null, null);
11054
11072
  }
11055
11073
  originTaskEntry() {
@@ -18998,6 +19016,8 @@ var TASK_SCOPED_ACTIONS = new Set([
18998
19016
  "worker.cancel",
18999
19017
  "state.export"
19000
19018
  ]);
19019
+ var ONLY_OWN_REPORT = "workers can submit only their own report";
19020
+ var NO_HELPER_CONTROL = "helpers cannot cancel or control workers";
19001
19021
  var WORKER_ADDRESSED_ACTIONS = new Set(["worker.cancel", "worker.report"]);
19002
19022
  var workerCommand = (taskId, request) => {
19003
19023
  const { action, workerId, reason, report } = request;
@@ -19895,6 +19915,10 @@ class WorkitCore {
19895
19915
  }
19896
19916
  if (helper?.ok)
19897
19917
  return failure2("permission_denied", "helpers cannot resolve findings");
19918
+ const findingRef = resolveIdRef("finding", input.findingId, task.data.findings.map((entry) => entry.id));
19919
+ if (!findingRef.ok)
19920
+ return findingRef;
19921
+ input.findingId = findingRef.data;
19898
19922
  const finding = task.data.findings.find((entry) => entry.id === input.findingId);
19899
19923
  if (!finding)
19900
19924
  return failure2("not_found", "finding not found");
@@ -20046,15 +20070,31 @@ class WorkitCore {
20046
20070
  return changed;
20047
20071
  return success(changed.data.task.revision, changed.data.workspace.revision, changed.data.task.workers.at(-1));
20048
20072
  }
20073
+ const workerRef = resolveIdRef("worker", input.workerId, helperId === null ? task.data.workers.map((candidate) => candidate.id) : [helperId]);
20074
+ if (!workerRef.ok)
20075
+ return helperId === null ? workerRef : failure2("permission_denied", input.action === "report" ? ONLY_OWN_REPORT : NO_HELPER_CONTROL);
20076
+ input.workerId = workerRef.data;
20049
20077
  const entry = task.data.workers.find((candidate) => candidate.id === input.workerId);
20050
20078
  if (!entry)
20051
20079
  return failure2("not_found", "worker not found");
20052
20080
  if (input.action === "report") {
20053
20081
  if (helperId === null || helperId !== input.workerId)
20054
- return failure2("permission_denied", "workers can submit only their own report");
20082
+ return failure2("permission_denied", ONLY_OWN_REPORT);
20055
20083
  const helper = this.helperEntry(task.data, true, true);
20056
20084
  if (!helper.ok)
20057
20085
  return helper;
20086
+ const ownFindings = task.data.findings.filter((candidate) => candidate.provenance.workerId === helperId).map((candidate) => candidate.id);
20087
+ const reported = [];
20088
+ for (const findingRef of input.report.findingIds) {
20089
+ const found = resolveIdRef("finding", findingRef, ownFindings);
20090
+ if (found.ok)
20091
+ reported.push(found.data);
20092
+ else if (found.code === "not_found")
20093
+ reported.push(findingRef);
20094
+ else
20095
+ return found;
20096
+ }
20097
+ input.report.findingIds = reported;
20058
20098
  const evidence = task.data.evidence.filter((candidate) => input.report.evidenceIds.includes(candidate.id));
20059
20099
  const findings = task.data.findings.filter((candidate) => input.report.findingIds.includes(candidate.id));
20060
20100
  if (evidence.length !== input.report.evidenceIds.length || findings.length !== input.report.findingIds.length)
@@ -20082,7 +20122,7 @@ class WorkitCore {
20082
20122
  return updated ? success(changed.data.task.revision, changed.data.workspace.revision, updated) : failure2("recovery_required", "worker disappeared during report");
20083
20123
  }
20084
20124
  if (helperId !== null)
20085
- return failure2("permission_denied", "helpers cannot cancel or control workers");
20125
+ return failure2("permission_denied", NO_HELPER_CONTROL);
20086
20126
  if (task.data.status === "closed")
20087
20127
  return failure2("invalid_transition", "closed task cannot cancel workers");
20088
20128
  if (entry.data.state === "stopped") {
@@ -23779,7 +23819,10 @@ var readAssignment = (ctx, request) => {
23779
23819
  return failure2("permission_denied", "worker assignment is not bound to this workspace");
23780
23820
  if (task.data.status !== "active")
23781
23821
  return failure2("invalid_transition", "paused or closed tasks cannot supervise workers");
23782
- const worker = task.data.workers.find((candidate) => candidate.id === request.workerId);
23822
+ const workerId = resolveIdRef("worker", request.workerId, task.data.workers.map((candidate) => candidate.id));
23823
+ if (!workerId.ok)
23824
+ return workerId;
23825
+ const worker = task.data.workers.find((candidate) => candidate.id === workerId.data);
23783
23826
  if (!worker)
23784
23827
  return failure2("not_found", "worker assignment not found");
23785
23828
  return success(null, workspace.data.revision, {
@@ -23926,7 +23969,7 @@ function extension(pi) {
23926
23969
  if (!validated.ok)
23927
23970
  return validated;
23928
23971
  const { store, task, workspace, worker } = validated.data;
23929
- const current = [...workers.values()].find((handle) => handle.workerId === request.workerId);
23972
+ const current = [...workers.values()].find((handle) => handle.workerId === worker.id);
23930
23973
  if (request.action === "cancel") {
23931
23974
  if (!current)
23932
23975
  return failure2("recovery_required", "worker process is not live in this session");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brainervirus/workit-pi",
3
- "version": "8.14.0",
3
+ "version": "8.14.1",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",