@workit-dev/opencode 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.
Files changed (2) hide show
  1. package/dist/plugin.js +121 -31
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -6422,7 +6422,7 @@ var scopeSchema = object({
6422
6422
  paths: array(pathValue),
6423
6423
  exclusions: array(pathValue)
6424
6424
  }).strict();
6425
- var scopeCovers = (outer, inner) => {
6425
+ var scopeGap = (outer, inner) => {
6426
6426
  const strip = (value) => value.length > 1 ? value.replace(/\/+$/, "") : value;
6427
6427
  const normOuter = {
6428
6428
  ...outer,
@@ -6434,8 +6434,17 @@ var scopeCovers = (outer, inner) => {
6434
6434
  const excluded = (path, scope) => scope.exclusions.some((excludedPath) => excludedPath === path || path.startsWith(`${excludedPath}/`));
6435
6435
  const covers = (path) => normOuter.paths.some((base) => scopePathCovers(base, path)) && !excluded(path, normOuter);
6436
6436
  const innerExcludes = (path) => innerExclusions.some((excludedPath) => excludedPath === path || path.startsWith(`${excludedPath}/`));
6437
- return innerPaths.every(covers) && !normOuter.exclusions.some((excludedPath) => innerPaths.some((base) => (base === "." || excludedPath === base || excludedPath.startsWith(`${base}/`)) && !innerExcludes(excludedPath)));
6437
+ const uncovered = innerPaths.find((path) => !covers(path));
6438
+ if (uncovered !== undefined)
6439
+ return { path: uncovered, exclusion: null };
6440
+ for (const excludedPath of normOuter.exclusions) {
6441
+ const base = innerPaths.find((path) => (path === "." || excludedPath === path || excludedPath.startsWith(`${path}/`)) && !innerExcludes(excludedPath));
6442
+ if (base !== undefined)
6443
+ return { path: base, exclusion: excludedPath };
6444
+ }
6445
+ return null;
6438
6446
  };
6447
+ var scopeCovers = (outer, inner) => scopeGap(outer, inner) === null;
6439
6448
  var refSchema = discriminatedUnion("kind", [
6440
6449
  object({ kind: literal("file"), path: pathValue, digest: nullableDigest }).strict(),
6441
6450
  object({
@@ -6732,7 +6741,8 @@ var findingSchema = object({
6732
6741
  candidateId: nullableDigest,
6733
6742
  refs: array(refSchema),
6734
6743
  disposition: _enum(["open", "fixed", "dismissed", "deferred"]),
6735
- resolution: object({ reason: text, evidenceIds: array(id), decisionIds: array(id) }).strict().nullable()
6744
+ resolution: object({ reason: text, evidenceIds: array(id), decisionIds: array(id) }).strict().nullable(),
6745
+ leadOwned: literal(true).optional()
6736
6746
  }).strict();
6737
6747
  var assignmentSchema = object({
6738
6748
  role: _enum(["investigator", "reviewer", "implementer"]),
@@ -7631,6 +7641,9 @@ function actionKeys(family, action) {
7631
7641
  walk(defOf(option).shape, false);
7632
7642
  return out;
7633
7643
  }
7644
+ var EXAMPLE_FIELDS = {
7645
+ "finding.resolve": { disposition: "fixed", evidenceIds: ["<evidenceId>"] }
7646
+ };
7634
7647
  function exampleOperation(family, action) {
7635
7648
  const keys = actionKeys(family, action);
7636
7649
  const example = { action };
@@ -7638,7 +7651,7 @@ function exampleOperation(family, action) {
7638
7651
  example[name] = FLAT[family].fields[name]?.enum?.[0] ?? `<${name}>`;
7639
7652
  if (family === "policy" && !keys?.required.length && action !== "explain")
7640
7653
  example.riskTier = "normal";
7641
- return example;
7654
+ return { ...example, ...EXAMPLE_FIELDS[`${family}.${action}`] };
7642
7655
  }
7643
7656
  var oneOf = (values) => values.join(" | ");
7644
7657
  function invalidOperation(family, input, error) {
@@ -7653,13 +7666,18 @@ function invalidOperation(family, input, error) {
7653
7666
  const own = actionKeys(family, action);
7654
7667
  const fields = [];
7655
7668
  const sentence = [];
7669
+ const foreign = [];
7670
+ const takes = `it takes ${[...own.accepted].join(", ")}`;
7656
7671
  for (const issue of error.issues) {
7657
7672
  if (issue.code === "unrecognized_keys") {
7658
7673
  for (const key of issue.keys) {
7659
7674
  const home = actions.find((other) => other !== action && actionKeys(family, other).accepted.has(key));
7660
- const reason = home ? `${key} belongs to action: ${home}` : `${key} is not a field of ${family} ${action}; it takes ${[...own.accepted].join(", ")}`;
7675
+ const reason = home ? `${key} belongs to action: ${home}` : `${key} is not a field of ${family} ${action}; ${takes}`;
7661
7676
  fields.push({ path: key, reason });
7662
- sentence.push(reason);
7677
+ if (home)
7678
+ sentence.push(reason);
7679
+ else
7680
+ foreign.push(key);
7663
7681
  }
7664
7682
  continue;
7665
7683
  }
@@ -7672,6 +7690,8 @@ function invalidOperation(family, input, error) {
7672
7690
  fields.push({ path: issue.path.join("."), reason });
7673
7691
  sentence.push(reason);
7674
7692
  }
7693
+ if (foreign.length)
7694
+ sentence.push(`${foreign.join(", ")} ${foreign.length === 1 ? "is not a field" : "are not fields"} of ${family} ${action}; ${takes}`);
7675
7695
  const example = JSON.stringify(exampleOperation(family, action));
7676
7696
  return failure2("invalid_input", `${[...new Set(sentence)].join("; ")}. Example: ${example}`, {
7677
7697
  fields
@@ -7686,6 +7706,10 @@ function parseAdvertisedOperation(family, input, host) {
7686
7706
  return success(null, null, request);
7687
7707
  return invalidOperation(family, request, parsed.error);
7688
7708
  }
7709
+ function explainInvalidOperation(family, request) {
7710
+ const parsed = advertisedOperationSchemas[family].safeParse(request);
7711
+ return parsed.success ? null : invalidOperation(family, request, parsed.error);
7712
+ }
7689
7713
  // packages/workit-core/src/core/task-store.ts
7690
7714
  import { createHash as createHash11, randomUUID as randomUUID3 } from "node:crypto";
7691
7715
  import * as fs14 from "node:fs";
@@ -21092,6 +21116,42 @@ function diffPolicy(previous, next, reason, now) {
21092
21116
  return parsed.data;
21093
21117
  }
21094
21118
 
21119
+ // packages/workit-core/src/core/finding-evidence.ts
21120
+ var RULES3 = {
21121
+ fixed: "check or review evidence with result passed, recorded after the finding and still current on this tree",
21122
+ 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",
21123
+ deferred: "an approved limitation decision (decisionIds) that references an acceptanceAllowed requirement and covers the finding's scope"
21124
+ };
21125
+ var sameRef = (left, right) => {
21126
+ try {
21127
+ return canonicalJson(left) === canonicalJson(right);
21128
+ } catch {
21129
+ return false;
21130
+ }
21131
+ };
21132
+ var sameCandidate = (finding, evidence) => finding.candidateId === null ? (evidence.candidateId ?? null) === null : evidence.candidateId === finding.candidateId || evidence.beforeCandidateId === finding.candidateId;
21133
+ function matchingEvidence(task, finding, disposition) {
21134
+ if (disposition === "deferred")
21135
+ return [];
21136
+ return task.evidence.filter((entry) => {
21137
+ const data = entry.data;
21138
+ if (disposition === "fixed")
21139
+ return entry.recordedAt >= finding.recordedAt && data.result === "passed" && (data.kind === "check" || data.kind === "review") && (finding.data.candidateId === null || data.candidateId != null);
21140
+ 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);
21141
+ }).map((entry) => entry.id);
21142
+ }
21143
+ function acceptedEvidenceText(task, finding, disposition) {
21144
+ const accepted = `accepted for ${disposition}: ${RULES3[disposition]}`;
21145
+ if (disposition === "deferred")
21146
+ return accepted;
21147
+ const ids = matchingEvidence(task, finding, disposition);
21148
+ if (ids.length)
21149
+ return `${accepted}; evidence in this task that fits: ${ids.join(", ")}`;
21150
+ const ref = finding.data.refs[0];
21151
+ const refs = ref ? JSON.stringify([ref]) : "[]";
21152
+ 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)`;
21153
+ }
21154
+
21095
21155
  // packages/workit-core/src/core/policy/judgment.ts
21096
21156
  var isObject7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
21097
21157
  var squash = (key) => key.toLowerCase().replace(/[_-]/g, "");
@@ -21338,6 +21398,12 @@ var workspaceVerification = (root) => {
21338
21398
  return "self";
21339
21399
  }
21340
21400
  };
21401
+ var parseRequest = (family, request) => {
21402
+ const parsed = parseOperation(family, request);
21403
+ if (parsed.ok || parsed.code !== "invalid_input")
21404
+ return parsed;
21405
+ return explainInvalidOperation(family, request) ?? parsed;
21406
+ };
21341
21407
  var provenance = (context, kind = context.provenanceKind ?? "host_observed") => ({
21342
21408
  kind,
21343
21409
  host: context.caller.host,
@@ -21788,7 +21854,7 @@ class WorkitCore {
21788
21854
  return root;
21789
21855
  if ((this.context.workerId ?? null) !== null)
21790
21856
  return failure2("permission_denied", "helpers cannot control task state");
21791
- const parsed = parseOperation("state", request);
21857
+ const parsed = parseRequest("state", request);
21792
21858
  if (!parsed.ok)
21793
21859
  return parsed;
21794
21860
  const input = parsed.data;
@@ -21860,7 +21926,7 @@ class WorkitCore {
21860
21926
  const root = this.contextRootError();
21861
21927
  if (!root.ok)
21862
21928
  return root;
21863
- const parsed = parseOperation("task", request);
21929
+ const parsed = parseRequest("task", request);
21864
21930
  if (!parsed.ok)
21865
21931
  return parsed;
21866
21932
  const input = parsed.data;
@@ -21974,7 +22040,7 @@ class WorkitCore {
21974
22040
  const root = this.contextRootError();
21975
22041
  if (!root.ok)
21976
22042
  return root;
21977
- const parsed = parseOperation("policy", request);
22043
+ const parsed = parseRequest("policy", request);
21978
22044
  if (!parsed.ok)
21979
22045
  return parsed;
21980
22046
  const input = parsed.data;
@@ -22064,7 +22130,7 @@ class WorkitCore {
22064
22130
  const root = this.contextRootError();
22065
22131
  if (!root.ok)
22066
22132
  return root;
22067
- const parsed = parseOperation("evidence", request);
22133
+ const parsed = parseRequest("evidence", request);
22068
22134
  if (!parsed.ok)
22069
22135
  return parsed;
22070
22136
  const input = parsed.data;
@@ -22223,7 +22289,7 @@ class WorkitCore {
22223
22289
  const root = this.contextRootError();
22224
22290
  if (!root.ok)
22225
22291
  return root;
22226
- const parsed = parseOperation("decision", request);
22292
+ const parsed = parseRequest("decision", request);
22227
22293
  if (!parsed.ok)
22228
22294
  return parsed;
22229
22295
  const input = parsed.data;
@@ -22326,7 +22392,7 @@ class WorkitCore {
22326
22392
  const root = this.contextRootError();
22327
22393
  if (!root.ok)
22328
22394
  return root;
22329
- const parsed = parseOperation("finding", request);
22395
+ const parsed = parseRequest("finding", request);
22330
22396
  if (!parsed.ok)
22331
22397
  return parsed;
22332
22398
  const input = parsed.data;
@@ -22371,8 +22437,6 @@ class WorkitCore {
22371
22437
  return changed;
22372
22438
  return success(changed.data.revision, null, changed.data.findings.at(-1));
22373
22439
  }
22374
- if (helper?.ok)
22375
- return failure2("permission_denied", "helpers cannot resolve findings");
22376
22440
  const findingRef = resolveIdRef("finding", input.findingId, task.data.findings.map((entry) => entry.id));
22377
22441
  if (!findingRef.ok)
22378
22442
  return findingRef;
@@ -22382,10 +22446,34 @@ class WorkitCore {
22382
22446
  return failure2("not_found", "finding not found");
22383
22447
  if (!input.reason.trim())
22384
22448
  return failure2("invalid_input", "finding resolution requires a reason");
22449
+ const helperId = helper?.ok ? helper.data.id : null;
22450
+ if (helperId !== null) {
22451
+ if (finding.provenance.workerId !== helperId)
22452
+ return failure2("permission_denied", "helpers resolve only the findings they recorded; the lead resolves this one");
22453
+ if (finding.data.leadOwned)
22454
+ return failure2("permission_denied", "the lead now owns this finding (it reopened, dismissed or deferred it); report it to the lead");
22455
+ if (finding.data.disposition !== "open")
22456
+ return failure2("permission_denied", `finding is already ${finding.data.disposition}; a helper resolves only its open findings`);
22457
+ if (input.disposition !== "fixed" && input.disposition !== "dismissed")
22458
+ return failure2("permission_denied", "helpers resolve their own findings as fixed or dismissed; deferring or reopening is the lead's");
22459
+ }
22460
+ const refuse = (code, message) => {
22461
+ if (input.disposition === "open" || helperId === null && this.context.caller.host === "workit_cli")
22462
+ return failure2(code, message);
22463
+ const pool = helperId === null ? task.data : { evidence: task.data.evidence.filter((e) => e.provenance.workerId === helperId) };
22464
+ const text = acceptedEvidenceText(pool, finding, input.disposition);
22465
+ return failure2(code, `${message}; ${text}`, { guidance: text });
22466
+ };
22385
22467
  const evidence = task.data.evidence.filter((entry) => input.evidenceIds.includes(entry.id));
22386
22468
  const decisions = task.data.decisions.filter((entry) => input.decisionIds.includes(entry.id));
22387
22469
  if (evidence.length !== input.evidenceIds.length || decisions.length !== input.decisionIds.length)
22388
- return failure2("invalid_input", "finding resolution references an unknown record");
22470
+ return refuse("invalid_input", "finding resolution references an unknown record");
22471
+ if (helperId !== null) {
22472
+ if (evidence.length === 0)
22473
+ return refuse("permission_denied", "a helper's resolution requires its own evidence");
22474
+ if (evidence.some((entry) => entry.provenance.workerId !== helperId))
22475
+ return refuse("permission_denied", "a helper resolves with evidence it recorded, not another session's");
22476
+ }
22389
22477
  if (input.disposition === "fixed") {
22390
22478
  const current = captureCandidate(this.store.root, task.data.intent.data.scope, environment());
22391
22479
  if (!current.ok)
@@ -22400,10 +22488,10 @@ class WorkitCore {
22400
22488
  });
22401
22489
  });
22402
22490
  if (!verified)
22403
- return failure2("permission_denied", "fixed findings require passing verification evidence");
22491
+ return refuse("permission_denied", "fixed findings require passing verification evidence");
22404
22492
  }
22405
22493
  if (input.disposition === "dismissed" && evidence.length === 0)
22406
- return failure2("permission_denied", "dismissal requires supporting evidence");
22494
+ return refuse("permission_denied", "dismissal requires supporting evidence");
22407
22495
  if (input.disposition === "dismissed") {
22408
22496
  const relevant = evidence.every((entry) => {
22409
22497
  if (entry.data.result === "missing" || entry.data.result === "skipped")
@@ -22413,7 +22501,7 @@ class WorkitCore {
22413
22501
  return candidateMatches && (referenceMatches || entry.data.claim === finding.data.claim);
22414
22502
  });
22415
22503
  if (!relevant)
22416
- return failure2("permission_denied", "dismissal evidence is unrelated to the finding");
22504
+ return refuse("permission_denied", "dismissal evidence is unrelated to the finding");
22417
22505
  }
22418
22506
  if (input.disposition === "deferred") {
22419
22507
  const workspace = this.store.readWorkspace();
@@ -22423,14 +22511,16 @@ class WorkitCore {
22423
22511
  return failure2("not_found", "workspace not found");
22424
22512
  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)));
22425
22513
  if (!allowed)
22426
- return failure2("permission_denied", "deferred findings require an approved limitation decision that references an acceptanceAllowed requirement and covers the finding scope");
22514
+ return refuse("permission_denied", "deferred findings require an approved limitation decision");
22427
22515
  }
22428
22516
  const changed = this.store.mutateTask(task.data.id, input.expectedRevision, (current, mutation) => {
22429
22517
  const existing = current.findings.find((entry) => entry.id === input.findingId);
22430
22518
  if (!existing)
22431
22519
  return failure2("not_found", "finding not found");
22432
- const data = input.disposition === "open" ? { ...existing.data, disposition: "open", resolution: null } : {
22520
+ const owner = helperId === null && existing.provenance.workerId !== null ? { leadOwned: true } : {};
22521
+ const data = input.disposition === "open" ? { ...existing.data, ...owner, disposition: "open", resolution: null } : {
22433
22522
  ...existing.data,
22523
+ ...owner,
22434
22524
  disposition: input.disposition,
22435
22525
  resolution: {
22436
22526
  reason: input.reason,
@@ -22462,7 +22552,7 @@ class WorkitCore {
22462
22552
  const root = this.contextRootError();
22463
22553
  if (!root.ok)
22464
22554
  return root;
22465
- const parsed = parseOperation("worker", request);
22555
+ const parsed = parseRequest("worker", request);
22466
22556
  if (!parsed.ok)
22467
22557
  return parsed;
22468
22558
  const input = parsed.data;
@@ -22481,19 +22571,19 @@ class WorkitCore {
22481
22571
  return failure2("permission_denied", "helpers cannot assign workers");
22482
22572
  if (task.data.status !== "active")
22483
22573
  return failure2("invalid_transition", "paused or closed tasks cannot assign workers");
22484
- if (!scopeCovers(task.data.intent.data.scope, input.assignment.scope))
22485
- return failure2("permission_denied", "worker assignment is outside task scope", {
22574
+ const gap = scopeGap(task.data.intent.data.scope, input.assignment.scope);
22575
+ if (gap) {
22576
+ const leadScope = task.data.intent.data.scope;
22577
+ const lead = leadScope.paths.join(", ") || "(none)";
22578
+ 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`;
22579
+ const excluded = leadScope.exclusions.length ? `; lead exclusions are ${leadScope.exclusions.join(", ")}` : "";
22580
+ return failure2("permission_denied", `worker assignment is outside task scope: ${reason}`, {
22486
22581
  fields: [
22487
- {
22488
- path: "assignment.scope",
22489
- reason: `paths ${JSON.stringify(input.assignment.scope.paths)} must be contained by lead paths ${JSON.stringify(task.data.intent.data.scope.paths)}`
22490
- },
22491
- {
22492
- path: "task.intent.scope",
22493
- reason: `lead paths are ${JSON.stringify(task.data.intent.data.scope.paths)}`
22494
- }
22582
+ { path: "assignment.scope", reason },
22583
+ { path: "task.intent.scope", reason: `lead paths are ${lead}${excluded}` }
22495
22584
  ]
22496
22585
  });
22586
+ }
22497
22587
  if (input.assignment.decisionIds.some((id) => !task.data.decisions.some((entry) => entry.id === id)))
22498
22588
  return failure2("invalid_input", "worker assignment references an unknown decision");
22499
22589
  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/opencode",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "private": false,
5
5
  "description": "Workit OpenCode plugin — native tools, adaptive policy, and sixteen method skills",
6
6
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@opencode/plugin": "2.0.18",
44
- "@workit-dev/core": "^1.1.5"
44
+ "@workit-dev/core": "^1.1.6"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=24"