@workit-dev/pi 1.1.5 → 1.1.6

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
@@ -6174,7 +6174,8 @@ var findingSchema = object({
6174
6174
  candidateId: nullableDigest,
6175
6175
  refs: array(refSchema),
6176
6176
  disposition: _enum(["open", "fixed", "dismissed", "deferred"]),
6177
- resolution: object({ reason: text, evidenceIds: array(id), decisionIds: array(id) }).strict().nullable()
6177
+ resolution: object({ reason: text, evidenceIds: array(id), decisionIds: array(id) }).strict().nullable(),
6178
+ leadOwned: literal(true).optional()
6178
6179
  }).strict();
6179
6180
  var assignmentSchema = object({
6180
6181
  role: _enum(["investigator", "reviewer", "implementer"]),
package/dist/workit.js CHANGED
@@ -6243,7 +6243,7 @@ var scopeSchema = object({
6243
6243
  paths: array(pathValue),
6244
6244
  exclusions: array(pathValue)
6245
6245
  }).strict();
6246
- var scopeCovers = (outer, inner) => {
6246
+ var scopeGap = (outer, inner) => {
6247
6247
  const strip = (value) => value.length > 1 ? value.replace(/\/+$/, "") : value;
6248
6248
  const normOuter = {
6249
6249
  ...outer,
@@ -6255,8 +6255,17 @@ var scopeCovers = (outer, inner) => {
6255
6255
  const excluded = (path, scope) => scope.exclusions.some((excludedPath) => excludedPath === path || path.startsWith(`${excludedPath}/`));
6256
6256
  const covers = (path) => normOuter.paths.some((base) => scopePathCovers(base, path)) && !excluded(path, normOuter);
6257
6257
  const innerExcludes = (path) => innerExclusions.some((excludedPath) => excludedPath === path || path.startsWith(`${excludedPath}/`));
6258
- return innerPaths.every(covers) && !normOuter.exclusions.some((excludedPath) => innerPaths.some((base) => (base === "." || excludedPath === base || excludedPath.startsWith(`${base}/`)) && !innerExcludes(excludedPath)));
6258
+ const uncovered = innerPaths.find((path) => !covers(path));
6259
+ if (uncovered !== undefined)
6260
+ return { path: uncovered, exclusion: null };
6261
+ for (const excludedPath of normOuter.exclusions) {
6262
+ const base = innerPaths.find((path) => (path === "." || excludedPath === path || excludedPath.startsWith(`${path}/`)) && !innerExcludes(excludedPath));
6263
+ if (base !== undefined)
6264
+ return { path: base, exclusion: excludedPath };
6265
+ }
6266
+ return null;
6259
6267
  };
6268
+ var scopeCovers = (outer, inner) => scopeGap(outer, inner) === null;
6260
6269
  var refSchema = discriminatedUnion("kind", [
6261
6270
  object({ kind: literal("file"), path: pathValue, digest: nullableDigest }).strict(),
6262
6271
  object({
@@ -6553,7 +6562,8 @@ var findingSchema = object({
6553
6562
  candidateId: nullableDigest,
6554
6563
  refs: array(refSchema),
6555
6564
  disposition: _enum(["open", "fixed", "dismissed", "deferred"]),
6556
- resolution: object({ reason: text, evidenceIds: array(id), decisionIds: array(id) }).strict().nullable()
6565
+ resolution: object({ reason: text, evidenceIds: array(id), decisionIds: array(id) }).strict().nullable(),
6566
+ leadOwned: literal(true).optional()
6557
6567
  }).strict();
6558
6568
  var assignmentSchema = object({
6559
6569
  role: _enum(["investigator", "reviewer", "implementer"]),
@@ -7452,6 +7462,9 @@ function actionKeys(family, action) {
7452
7462
  walk(defOf(option).shape, false);
7453
7463
  return out;
7454
7464
  }
7465
+ var EXAMPLE_FIELDS = {
7466
+ "finding.resolve": { disposition: "fixed", evidenceIds: ["<evidenceId>"] }
7467
+ };
7455
7468
  function exampleOperation(family, action) {
7456
7469
  const keys = actionKeys(family, action);
7457
7470
  const example = { action };
@@ -7459,7 +7472,7 @@ function exampleOperation(family, action) {
7459
7472
  example[name] = FLAT[family].fields[name]?.enum?.[0] ?? `<${name}>`;
7460
7473
  if (family === "policy" && !keys?.required.length && action !== "explain")
7461
7474
  example.riskTier = "normal";
7462
- return example;
7475
+ return { ...example, ...EXAMPLE_FIELDS[`${family}.${action}`] };
7463
7476
  }
7464
7477
  var oneOf = (values) => values.join(" | ");
7465
7478
  function invalidOperation(family, input, error) {
@@ -7474,13 +7487,18 @@ function invalidOperation(family, input, error) {
7474
7487
  const own = actionKeys(family, action);
7475
7488
  const fields = [];
7476
7489
  const sentence = [];
7490
+ const foreign = [];
7491
+ const takes = `it takes ${[...own.accepted].join(", ")}`;
7477
7492
  for (const issue of error.issues) {
7478
7493
  if (issue.code === "unrecognized_keys") {
7479
7494
  for (const key of issue.keys) {
7480
7495
  const home = actions.find((other) => other !== action && actionKeys(family, other).accepted.has(key));
7481
- const reason = home ? `${key} belongs to action: ${home}` : `${key} is not a field of ${family} ${action}; it takes ${[...own.accepted].join(", ")}`;
7496
+ const reason = home ? `${key} belongs to action: ${home}` : `${key} is not a field of ${family} ${action}; ${takes}`;
7482
7497
  fields.push({ path: key, reason });
7483
- sentence.push(reason);
7498
+ if (home)
7499
+ sentence.push(reason);
7500
+ else
7501
+ foreign.push(key);
7484
7502
  }
7485
7503
  continue;
7486
7504
  }
@@ -7493,6 +7511,8 @@ function invalidOperation(family, input, error) {
7493
7511
  fields.push({ path: issue.path.join("."), reason });
7494
7512
  sentence.push(reason);
7495
7513
  }
7514
+ if (foreign.length)
7515
+ sentence.push(`${foreign.join(", ")} ${foreign.length === 1 ? "is not a field" : "are not fields"} of ${family} ${action}; ${takes}`);
7496
7516
  const example = JSON.stringify(exampleOperation(family, action));
7497
7517
  return failure2("invalid_input", `${[...new Set(sentence)].join("; ")}. Example: ${example}`, {
7498
7518
  fields
@@ -7507,6 +7527,10 @@ function parseAdvertisedOperation(family, input, host) {
7507
7527
  return success(null, null, request);
7508
7528
  return invalidOperation(family, request, parsed.error);
7509
7529
  }
7530
+ function explainInvalidOperation(family, request) {
7531
+ const parsed = advertisedOperationSchemas[family].safeParse(request);
7532
+ return parsed.success ? null : invalidOperation(family, request, parsed.error);
7533
+ }
7510
7534
  // packages/workit-core/src/core/task-store.ts
7511
7535
  import { createHash as createHash9, randomUUID as randomUUID3 } from "node:crypto";
7512
7536
  import * as fs12 from "node:fs";
@@ -20909,6 +20933,42 @@ function diffPolicy(previous, next, reason, now) {
20909
20933
  return parsed.data;
20910
20934
  }
20911
20935
 
20936
+ // packages/workit-core/src/core/finding-evidence.ts
20937
+ var RULES3 = {
20938
+ fixed: "check or review evidence with result passed, recorded after the finding and still current on this tree",
20939
+ dismissed: "evidence (check, review, investigation or artifact) with result passed or failed, on the finding's candidate, that shares a ref with the finding or repeats its claim",
20940
+ deferred: "an approved limitation decision (decisionIds) that references an acceptanceAllowed requirement and covers the finding's scope"
20941
+ };
20942
+ var sameRef = (left, right) => {
20943
+ try {
20944
+ return canonicalJson(left) === canonicalJson(right);
20945
+ } catch {
20946
+ return false;
20947
+ }
20948
+ };
20949
+ var sameCandidate = (finding, evidence) => finding.candidateId === null ? (evidence.candidateId ?? null) === null : evidence.candidateId === finding.candidateId || evidence.beforeCandidateId === finding.candidateId;
20950
+ function matchingEvidence(task, finding, disposition) {
20951
+ if (disposition === "deferred")
20952
+ return [];
20953
+ return task.evidence.filter((entry) => {
20954
+ const data = entry.data;
20955
+ if (disposition === "fixed")
20956
+ return entry.recordedAt >= finding.recordedAt && data.result === "passed" && (data.kind === "check" || data.kind === "review") && (finding.data.candidateId === null || data.candidateId != null);
20957
+ return (data.result === "passed" || data.result === "failed") && sameCandidate(finding.data, data) && (finding.data.refs.some((left) => data.refs.some((right) => sameRef(left, right))) || data.claim === finding.data.claim);
20958
+ }).map((entry) => entry.id);
20959
+ }
20960
+ function acceptedEvidenceText(task, finding, disposition) {
20961
+ const accepted = `accepted for ${disposition}: ${RULES3[disposition]}`;
20962
+ if (disposition === "deferred")
20963
+ return accepted;
20964
+ const ids = matchingEvidence(task, finding, disposition);
20965
+ if (ids.length)
20966
+ return `${accepted}; evidence in this task that fits: ${ids.join(", ")}`;
20967
+ const ref = finding.data.refs[0];
20968
+ const refs = ref ? JSON.stringify([ref]) : "[]";
20969
+ return `${accepted}; none recorded in this task yet: workit evidence record --payload '{"kind":"${disposition === "fixed" ? "check" : "review"}","claim":${JSON.stringify(finding.data.claim)},"result":"passed","refs":${refs},…}' (or workit check <name> for a check)`;
20970
+ }
20971
+
20912
20972
  // packages/workit-core/src/core/policy/judgment.ts
20913
20973
  var isObject7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
20914
20974
  var squash = (key) => key.toLowerCase().replace(/[_-]/g, "");
@@ -21155,6 +21215,12 @@ var workspaceVerification = (root) => {
21155
21215
  return "self";
21156
21216
  }
21157
21217
  };
21218
+ var parseRequest = (family, request) => {
21219
+ const parsed = parseOperation(family, request);
21220
+ if (parsed.ok || parsed.code !== "invalid_input")
21221
+ return parsed;
21222
+ return explainInvalidOperation(family, request) ?? parsed;
21223
+ };
21158
21224
  var provenance = (context, kind = context.provenanceKind ?? "host_observed") => ({
21159
21225
  kind,
21160
21226
  host: context.caller.host,
@@ -21605,7 +21671,7 @@ class WorkitCore {
21605
21671
  return root;
21606
21672
  if ((this.context.workerId ?? null) !== null)
21607
21673
  return failure2("permission_denied", "helpers cannot control task state");
21608
- const parsed = parseOperation("state", request);
21674
+ const parsed = parseRequest("state", request);
21609
21675
  if (!parsed.ok)
21610
21676
  return parsed;
21611
21677
  const input = parsed.data;
@@ -21677,7 +21743,7 @@ class WorkitCore {
21677
21743
  const root = this.contextRootError();
21678
21744
  if (!root.ok)
21679
21745
  return root;
21680
- const parsed = parseOperation("task", request);
21746
+ const parsed = parseRequest("task", request);
21681
21747
  if (!parsed.ok)
21682
21748
  return parsed;
21683
21749
  const input = parsed.data;
@@ -21791,7 +21857,7 @@ class WorkitCore {
21791
21857
  const root = this.contextRootError();
21792
21858
  if (!root.ok)
21793
21859
  return root;
21794
- const parsed = parseOperation("policy", request);
21860
+ const parsed = parseRequest("policy", request);
21795
21861
  if (!parsed.ok)
21796
21862
  return parsed;
21797
21863
  const input = parsed.data;
@@ -21881,7 +21947,7 @@ class WorkitCore {
21881
21947
  const root = this.contextRootError();
21882
21948
  if (!root.ok)
21883
21949
  return root;
21884
- const parsed = parseOperation("evidence", request);
21950
+ const parsed = parseRequest("evidence", request);
21885
21951
  if (!parsed.ok)
21886
21952
  return parsed;
21887
21953
  const input = parsed.data;
@@ -22040,7 +22106,7 @@ class WorkitCore {
22040
22106
  const root = this.contextRootError();
22041
22107
  if (!root.ok)
22042
22108
  return root;
22043
- const parsed = parseOperation("decision", request);
22109
+ const parsed = parseRequest("decision", request);
22044
22110
  if (!parsed.ok)
22045
22111
  return parsed;
22046
22112
  const input = parsed.data;
@@ -22143,7 +22209,7 @@ class WorkitCore {
22143
22209
  const root = this.contextRootError();
22144
22210
  if (!root.ok)
22145
22211
  return root;
22146
- const parsed = parseOperation("finding", request);
22212
+ const parsed = parseRequest("finding", request);
22147
22213
  if (!parsed.ok)
22148
22214
  return parsed;
22149
22215
  const input = parsed.data;
@@ -22188,8 +22254,6 @@ class WorkitCore {
22188
22254
  return changed;
22189
22255
  return success(changed.data.revision, null, changed.data.findings.at(-1));
22190
22256
  }
22191
- if (helper?.ok)
22192
- return failure2("permission_denied", "helpers cannot resolve findings");
22193
22257
  const findingRef = resolveIdRef("finding", input.findingId, task.data.findings.map((entry) => entry.id));
22194
22258
  if (!findingRef.ok)
22195
22259
  return findingRef;
@@ -22199,10 +22263,34 @@ class WorkitCore {
22199
22263
  return failure2("not_found", "finding not found");
22200
22264
  if (!input.reason.trim())
22201
22265
  return failure2("invalid_input", "finding resolution requires a reason");
22266
+ const helperId = helper?.ok ? helper.data.id : null;
22267
+ if (helperId !== null) {
22268
+ if (finding.provenance.workerId !== helperId)
22269
+ return failure2("permission_denied", "helpers resolve only the findings they recorded; the lead resolves this one");
22270
+ if (finding.data.leadOwned)
22271
+ return failure2("permission_denied", "the lead now owns this finding (it reopened, dismissed or deferred it); report it to the lead");
22272
+ if (finding.data.disposition !== "open")
22273
+ return failure2("permission_denied", `finding is already ${finding.data.disposition}; a helper resolves only its open findings`);
22274
+ if (input.disposition !== "fixed" && input.disposition !== "dismissed")
22275
+ return failure2("permission_denied", "helpers resolve their own findings as fixed or dismissed; deferring or reopening is the lead's");
22276
+ }
22277
+ const refuse = (code, message) => {
22278
+ if (input.disposition === "open" || helperId === null && this.context.caller.host === "workit_cli")
22279
+ return failure2(code, message);
22280
+ const pool = helperId === null ? task.data : { evidence: task.data.evidence.filter((e) => e.provenance.workerId === helperId) };
22281
+ const text = acceptedEvidenceText(pool, finding, input.disposition);
22282
+ return failure2(code, `${message}; ${text}`, { guidance: text });
22283
+ };
22202
22284
  const evidence = task.data.evidence.filter((entry) => input.evidenceIds.includes(entry.id));
22203
22285
  const decisions = task.data.decisions.filter((entry) => input.decisionIds.includes(entry.id));
22204
22286
  if (evidence.length !== input.evidenceIds.length || decisions.length !== input.decisionIds.length)
22205
- return failure2("invalid_input", "finding resolution references an unknown record");
22287
+ return refuse("invalid_input", "finding resolution references an unknown record");
22288
+ if (helperId !== null) {
22289
+ if (evidence.length === 0)
22290
+ return refuse("permission_denied", "a helper's resolution requires its own evidence");
22291
+ if (evidence.some((entry) => entry.provenance.workerId !== helperId))
22292
+ return refuse("permission_denied", "a helper resolves with evidence it recorded, not another session's");
22293
+ }
22206
22294
  if (input.disposition === "fixed") {
22207
22295
  const current = captureCandidate(this.store.root, task.data.intent.data.scope, environment());
22208
22296
  if (!current.ok)
@@ -22217,10 +22305,10 @@ class WorkitCore {
22217
22305
  });
22218
22306
  });
22219
22307
  if (!verified)
22220
- return failure2("permission_denied", "fixed findings require passing verification evidence");
22308
+ return refuse("permission_denied", "fixed findings require passing verification evidence");
22221
22309
  }
22222
22310
  if (input.disposition === "dismissed" && evidence.length === 0)
22223
- return failure2("permission_denied", "dismissal requires supporting evidence");
22311
+ return refuse("permission_denied", "dismissal requires supporting evidence");
22224
22312
  if (input.disposition === "dismissed") {
22225
22313
  const relevant = evidence.every((entry) => {
22226
22314
  if (entry.data.result === "missing" || entry.data.result === "skipped")
@@ -22230,7 +22318,7 @@ class WorkitCore {
22230
22318
  return candidateMatches && (referenceMatches || entry.data.claim === finding.data.claim);
22231
22319
  });
22232
22320
  if (!relevant)
22233
- return failure2("permission_denied", "dismissal evidence is unrelated to the finding");
22321
+ return refuse("permission_denied", "dismissal evidence is unrelated to the finding");
22234
22322
  }
22235
22323
  if (input.disposition === "deferred") {
22236
22324
  const workspace = this.store.readWorkspace();
@@ -22240,14 +22328,16 @@ class WorkitCore {
22240
22328
  return failure2("not_found", "workspace not found");
22241
22329
  const allowed = decisions.some((entry) => entry.provenance.kind !== "imported" && entry.data.purpose === "limitation" && entry.data.response === "approved" && entry.data.revoked === null && verifyDecisionContentAtRoot(this.store.root, entry.data.binding).ok && entry.data.binding.taskId === task.data.id && entry.data.binding.workspaceId === workspace.data.id && scopeCovers(entry.data.binding.scope, finding.data.scope) && entry.data.requirementIds.some((id) => task.data.policy?.requirements.some((requirement) => requirement.id === id && requirement.acceptanceAllowed)));
22242
22330
  if (!allowed)
22243
- return failure2("permission_denied", "deferred findings require an approved limitation decision that references an acceptanceAllowed requirement and covers the finding scope");
22331
+ return refuse("permission_denied", "deferred findings require an approved limitation decision");
22244
22332
  }
22245
22333
  const changed = this.store.mutateTask(task.data.id, input.expectedRevision, (current, mutation) => {
22246
22334
  const existing = current.findings.find((entry) => entry.id === input.findingId);
22247
22335
  if (!existing)
22248
22336
  return failure2("not_found", "finding not found");
22249
- const data = input.disposition === "open" ? { ...existing.data, disposition: "open", resolution: null } : {
22337
+ const owner = helperId === null && existing.provenance.workerId !== null ? { leadOwned: true } : {};
22338
+ const data = input.disposition === "open" ? { ...existing.data, ...owner, disposition: "open", resolution: null } : {
22250
22339
  ...existing.data,
22340
+ ...owner,
22251
22341
  disposition: input.disposition,
22252
22342
  resolution: {
22253
22343
  reason: input.reason,
@@ -22279,7 +22369,7 @@ class WorkitCore {
22279
22369
  const root = this.contextRootError();
22280
22370
  if (!root.ok)
22281
22371
  return root;
22282
- const parsed = parseOperation("worker", request);
22372
+ const parsed = parseRequest("worker", request);
22283
22373
  if (!parsed.ok)
22284
22374
  return parsed;
22285
22375
  const input = parsed.data;
@@ -22298,19 +22388,19 @@ class WorkitCore {
22298
22388
  return failure2("permission_denied", "helpers cannot assign workers");
22299
22389
  if (task.data.status !== "active")
22300
22390
  return failure2("invalid_transition", "paused or closed tasks cannot assign workers");
22301
- if (!scopeCovers(task.data.intent.data.scope, input.assignment.scope))
22302
- return failure2("permission_denied", "worker assignment is outside task scope", {
22391
+ const gap = scopeGap(task.data.intent.data.scope, input.assignment.scope);
22392
+ if (gap) {
22393
+ const leadScope = task.data.intent.data.scope;
22394
+ const lead = leadScope.paths.join(", ") || "(none)";
22395
+ const reason = gap.exclusion === null ? `${gap.path} is not inside lead paths ${lead}` : `${gap.path} reaches lead exclusion ${gap.exclusion}; add ${gap.exclusion} to the worker exclusions`;
22396
+ const excluded = leadScope.exclusions.length ? `; lead exclusions are ${leadScope.exclusions.join(", ")}` : "";
22397
+ return failure2("permission_denied", `worker assignment is outside task scope: ${reason}`, {
22303
22398
  fields: [
22304
- {
22305
- path: "assignment.scope",
22306
- reason: `paths ${JSON.stringify(input.assignment.scope.paths)} must be contained by lead paths ${JSON.stringify(task.data.intent.data.scope.paths)}`
22307
- },
22308
- {
22309
- path: "task.intent.scope",
22310
- reason: `lead paths are ${JSON.stringify(task.data.intent.data.scope.paths)}`
22311
- }
22399
+ { path: "assignment.scope", reason },
22400
+ { path: "task.intent.scope", reason: `lead paths are ${lead}${excluded}` }
22312
22401
  ]
22313
22402
  });
22403
+ }
22314
22404
  if (input.assignment.decisionIds.some((id) => !task.data.decisions.some((entry) => entry.id === id)))
22315
22405
  return failure2("invalid_input", "worker assignment references an unknown decision");
22316
22406
  if (input.assignment.requirementIds.some((id) => !task.data.policy?.requirements.some((requirement) => requirement.id === id)))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/pi",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",