@workit-dev/mcp 1.1.5 → 1.1.7

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/index.js +121 -31
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -15084,7 +15084,7 @@ var scopeSchema = object({
15084
15084
  paths: array(pathValue),
15085
15085
  exclusions: array(pathValue)
15086
15086
  }).strict();
15087
- var scopeCovers = (outer, inner) => {
15087
+ var scopeGap = (outer, inner) => {
15088
15088
  const strip = (value) => value.length > 1 ? value.replace(/\/+$/, "") : value;
15089
15089
  const normOuter = {
15090
15090
  ...outer,
@@ -15096,8 +15096,17 @@ var scopeCovers = (outer, inner) => {
15096
15096
  const excluded = (path, scope) => scope.exclusions.some((excludedPath) => excludedPath === path || path.startsWith(`${excludedPath}/`));
15097
15097
  const covers = (path) => normOuter.paths.some((base) => scopePathCovers(base, path)) && !excluded(path, normOuter);
15098
15098
  const innerExcludes = (path) => innerExclusions.some((excludedPath) => excludedPath === path || path.startsWith(`${excludedPath}/`));
15099
- return innerPaths.every(covers) && !normOuter.exclusions.some((excludedPath) => innerPaths.some((base) => (base === "." || excludedPath === base || excludedPath.startsWith(`${base}/`)) && !innerExcludes(excludedPath)));
15099
+ const uncovered = innerPaths.find((path) => !covers(path));
15100
+ if (uncovered !== undefined)
15101
+ return { path: uncovered, exclusion: null };
15102
+ for (const excludedPath of normOuter.exclusions) {
15103
+ const base = innerPaths.find((path) => (path === "." || excludedPath === path || excludedPath.startsWith(`${path}/`)) && !innerExcludes(excludedPath));
15104
+ if (base !== undefined)
15105
+ return { path: base, exclusion: excludedPath };
15106
+ }
15107
+ return null;
15100
15108
  };
15109
+ var scopeCovers = (outer, inner) => scopeGap(outer, inner) === null;
15101
15110
  var refSchema = discriminatedUnion("kind", [
15102
15111
  object({ kind: literal("file"), path: pathValue, digest: nullableDigest }).strict(),
15103
15112
  object({
@@ -15394,7 +15403,8 @@ var findingSchema = object({
15394
15403
  candidateId: nullableDigest,
15395
15404
  refs: array(refSchema),
15396
15405
  disposition: _enum(["open", "fixed", "dismissed", "deferred"]),
15397
- resolution: object({ reason: text, evidenceIds: array(id), decisionIds: array(id) }).strict().nullable()
15406
+ resolution: object({ reason: text, evidenceIds: array(id), decisionIds: array(id) }).strict().nullable(),
15407
+ leadOwned: literal(true).optional()
15398
15408
  }).strict();
15399
15409
  var assignmentSchema = object({
15400
15410
  role: _enum(["investigator", "reviewer", "implementer"]),
@@ -16293,6 +16303,9 @@ function actionKeys(family, action) {
16293
16303
  walk(defOf(option).shape, false);
16294
16304
  return out;
16295
16305
  }
16306
+ var EXAMPLE_FIELDS = {
16307
+ "finding.resolve": { disposition: "fixed", evidenceIds: ["<evidenceId>"] }
16308
+ };
16296
16309
  function exampleOperation(family, action) {
16297
16310
  const keys = actionKeys(family, action);
16298
16311
  const example = { action };
@@ -16300,7 +16313,7 @@ function exampleOperation(family, action) {
16300
16313
  example[name] = FLAT[family].fields[name]?.enum?.[0] ?? `<${name}>`;
16301
16314
  if (family === "policy" && !keys?.required.length && action !== "explain")
16302
16315
  example.riskTier = "normal";
16303
- return example;
16316
+ return { ...example, ...EXAMPLE_FIELDS[`${family}.${action}`] };
16304
16317
  }
16305
16318
  var oneOf = (values) => values.join(" | ");
16306
16319
  function invalidOperation(family, input, error) {
@@ -16315,13 +16328,18 @@ function invalidOperation(family, input, error) {
16315
16328
  const own = actionKeys(family, action);
16316
16329
  const fields = [];
16317
16330
  const sentence = [];
16331
+ const foreign = [];
16332
+ const takes = `it takes ${[...own.accepted].join(", ")}`;
16318
16333
  for (const issue of error.issues) {
16319
16334
  if (issue.code === "unrecognized_keys") {
16320
16335
  for (const key of issue.keys) {
16321
16336
  const home = actions.find((other) => other !== action && actionKeys(family, other).accepted.has(key));
16322
- const reason = home ? `${key} belongs to action: ${home}` : `${key} is not a field of ${family} ${action}; it takes ${[...own.accepted].join(", ")}`;
16337
+ const reason = home ? `${key} belongs to action: ${home}` : `${key} is not a field of ${family} ${action}; ${takes}`;
16323
16338
  fields.push({ path: key, reason });
16324
- sentence.push(reason);
16339
+ if (home)
16340
+ sentence.push(reason);
16341
+ else
16342
+ foreign.push(key);
16325
16343
  }
16326
16344
  continue;
16327
16345
  }
@@ -16334,6 +16352,8 @@ function invalidOperation(family, input, error) {
16334
16352
  fields.push({ path: issue.path.join("."), reason });
16335
16353
  sentence.push(reason);
16336
16354
  }
16355
+ if (foreign.length)
16356
+ sentence.push(`${foreign.join(", ")} ${foreign.length === 1 ? "is not a field" : "are not fields"} of ${family} ${action}; ${takes}`);
16337
16357
  const example = JSON.stringify(exampleOperation(family, action));
16338
16358
  return failure2("invalid_input", `${[...new Set(sentence)].join("; ")}. Example: ${example}`, {
16339
16359
  fields
@@ -16348,6 +16368,10 @@ function parseAdvertisedOperation(family, input, host) {
16348
16368
  return success(null, null, request);
16349
16369
  return invalidOperation(family, request, parsed.error);
16350
16370
  }
16371
+ function explainInvalidOperation(family, request) {
16372
+ const parsed = advertisedOperationSchemas[family].safeParse(request);
16373
+ return parsed.success ? null : invalidOperation(family, request, parsed.error);
16374
+ }
16351
16375
  // packages/workit-core/src/core/task-store.ts
16352
16376
  import { createHash as createHash8, randomUUID as randomUUID3 } from "node:crypto";
16353
16377
  import * as fs12 from "node:fs";
@@ -26468,6 +26492,42 @@ function diffPolicy(previous, next, reason, now) {
26468
26492
  return parsed.data;
26469
26493
  }
26470
26494
 
26495
+ // packages/workit-core/src/core/finding-evidence.ts
26496
+ var RULES3 = {
26497
+ fixed: "check or review evidence with result passed, recorded after the finding and still current on this tree",
26498
+ 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",
26499
+ deferred: "an approved limitation decision (decisionIds) that references an acceptanceAllowed requirement and covers the finding's scope"
26500
+ };
26501
+ var sameRef = (left, right) => {
26502
+ try {
26503
+ return canonicalJson(left) === canonicalJson(right);
26504
+ } catch {
26505
+ return false;
26506
+ }
26507
+ };
26508
+ var sameCandidate = (finding, evidence) => finding.candidateId === null ? (evidence.candidateId ?? null) === null : evidence.candidateId === finding.candidateId || evidence.beforeCandidateId === finding.candidateId;
26509
+ function matchingEvidence(task, finding, disposition) {
26510
+ if (disposition === "deferred")
26511
+ return [];
26512
+ return task.evidence.filter((entry) => {
26513
+ const data = entry.data;
26514
+ if (disposition === "fixed")
26515
+ return entry.recordedAt >= finding.recordedAt && data.result === "passed" && (data.kind === "check" || data.kind === "review") && (finding.data.candidateId === null || data.candidateId != null);
26516
+ 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);
26517
+ }).map((entry) => entry.id);
26518
+ }
26519
+ function acceptedEvidenceText(task, finding, disposition) {
26520
+ const accepted = `accepted for ${disposition}: ${RULES3[disposition]}`;
26521
+ if (disposition === "deferred")
26522
+ return accepted;
26523
+ const ids = matchingEvidence(task, finding, disposition);
26524
+ if (ids.length)
26525
+ return `${accepted}; evidence in this task that fits: ${ids.join(", ")}`;
26526
+ const ref = finding.data.refs[0];
26527
+ const refs = ref ? JSON.stringify([ref]) : "[]";
26528
+ 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)`;
26529
+ }
26530
+
26471
26531
  // packages/workit-core/src/core/policy/judgment.ts
26472
26532
  var isObject6 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
26473
26533
  var squash = (key) => key.toLowerCase().replace(/[_-]/g, "");
@@ -26714,6 +26774,12 @@ var workspaceVerification = (root) => {
26714
26774
  return "self";
26715
26775
  }
26716
26776
  };
26777
+ var parseRequest = (family, request) => {
26778
+ const parsed = parseOperation(family, request);
26779
+ if (parsed.ok || parsed.code !== "invalid_input")
26780
+ return parsed;
26781
+ return explainInvalidOperation(family, request) ?? parsed;
26782
+ };
26717
26783
  var provenance = (context, kind = context.provenanceKind ?? "host_observed") => ({
26718
26784
  kind,
26719
26785
  host: context.caller.host,
@@ -27164,7 +27230,7 @@ class WorkitCore {
27164
27230
  return root;
27165
27231
  if ((this.context.workerId ?? null) !== null)
27166
27232
  return failure2("permission_denied", "helpers cannot control task state");
27167
- const parsed = parseOperation("state", request);
27233
+ const parsed = parseRequest("state", request);
27168
27234
  if (!parsed.ok)
27169
27235
  return parsed;
27170
27236
  const input = parsed.data;
@@ -27236,7 +27302,7 @@ class WorkitCore {
27236
27302
  const root = this.contextRootError();
27237
27303
  if (!root.ok)
27238
27304
  return root;
27239
- const parsed = parseOperation("task", request);
27305
+ const parsed = parseRequest("task", request);
27240
27306
  if (!parsed.ok)
27241
27307
  return parsed;
27242
27308
  const input = parsed.data;
@@ -27350,7 +27416,7 @@ class WorkitCore {
27350
27416
  const root = this.contextRootError();
27351
27417
  if (!root.ok)
27352
27418
  return root;
27353
- const parsed = parseOperation("policy", request);
27419
+ const parsed = parseRequest("policy", request);
27354
27420
  if (!parsed.ok)
27355
27421
  return parsed;
27356
27422
  const input = parsed.data;
@@ -27440,7 +27506,7 @@ class WorkitCore {
27440
27506
  const root = this.contextRootError();
27441
27507
  if (!root.ok)
27442
27508
  return root;
27443
- const parsed = parseOperation("evidence", request);
27509
+ const parsed = parseRequest("evidence", request);
27444
27510
  if (!parsed.ok)
27445
27511
  return parsed;
27446
27512
  const input = parsed.data;
@@ -27599,7 +27665,7 @@ class WorkitCore {
27599
27665
  const root = this.contextRootError();
27600
27666
  if (!root.ok)
27601
27667
  return root;
27602
- const parsed = parseOperation("decision", request);
27668
+ const parsed = parseRequest("decision", request);
27603
27669
  if (!parsed.ok)
27604
27670
  return parsed;
27605
27671
  const input = parsed.data;
@@ -27702,7 +27768,7 @@ class WorkitCore {
27702
27768
  const root = this.contextRootError();
27703
27769
  if (!root.ok)
27704
27770
  return root;
27705
- const parsed = parseOperation("finding", request);
27771
+ const parsed = parseRequest("finding", request);
27706
27772
  if (!parsed.ok)
27707
27773
  return parsed;
27708
27774
  const input = parsed.data;
@@ -27747,8 +27813,6 @@ class WorkitCore {
27747
27813
  return changed;
27748
27814
  return success(changed.data.revision, null, changed.data.findings.at(-1));
27749
27815
  }
27750
- if (helper?.ok)
27751
- return failure2("permission_denied", "helpers cannot resolve findings");
27752
27816
  const findingRef = resolveIdRef("finding", input.findingId, task.data.findings.map((entry) => entry.id));
27753
27817
  if (!findingRef.ok)
27754
27818
  return findingRef;
@@ -27758,10 +27822,34 @@ class WorkitCore {
27758
27822
  return failure2("not_found", "finding not found");
27759
27823
  if (!input.reason.trim())
27760
27824
  return failure2("invalid_input", "finding resolution requires a reason");
27825
+ const helperId = helper?.ok ? helper.data.id : null;
27826
+ if (helperId !== null) {
27827
+ if (finding.provenance.workerId !== helperId)
27828
+ return failure2("permission_denied", "helpers resolve only the findings they recorded; the lead resolves this one");
27829
+ if (finding.data.leadOwned)
27830
+ return failure2("permission_denied", "the lead now owns this finding (it reopened, dismissed or deferred it); report it to the lead");
27831
+ if (finding.data.disposition !== "open")
27832
+ return failure2("permission_denied", `finding is already ${finding.data.disposition}; a helper resolves only its open findings`);
27833
+ if (input.disposition !== "fixed" && input.disposition !== "dismissed")
27834
+ return failure2("permission_denied", "helpers resolve their own findings as fixed or dismissed; deferring or reopening is the lead's");
27835
+ }
27836
+ const refuse = (code, message) => {
27837
+ if (input.disposition === "open" || helperId === null && this.context.caller.host === "workit_cli")
27838
+ return failure2(code, message);
27839
+ const pool = helperId === null ? task.data : { evidence: task.data.evidence.filter((e) => e.provenance.workerId === helperId) };
27840
+ const text = acceptedEvidenceText(pool, finding, input.disposition);
27841
+ return failure2(code, `${message}; ${text}`, { guidance: text });
27842
+ };
27761
27843
  const evidence = task.data.evidence.filter((entry) => input.evidenceIds.includes(entry.id));
27762
27844
  const decisions = task.data.decisions.filter((entry) => input.decisionIds.includes(entry.id));
27763
27845
  if (evidence.length !== input.evidenceIds.length || decisions.length !== input.decisionIds.length)
27764
- return failure2("invalid_input", "finding resolution references an unknown record");
27846
+ return refuse("invalid_input", "finding resolution references an unknown record");
27847
+ if (helperId !== null) {
27848
+ if (evidence.length === 0)
27849
+ return refuse("permission_denied", "a helper's resolution requires its own evidence");
27850
+ if (evidence.some((entry) => entry.provenance.workerId !== helperId))
27851
+ return refuse("permission_denied", "a helper resolves with evidence it recorded, not another session's");
27852
+ }
27765
27853
  if (input.disposition === "fixed") {
27766
27854
  const current = captureCandidate(this.store.root, task.data.intent.data.scope, environment());
27767
27855
  if (!current.ok)
@@ -27776,10 +27864,10 @@ class WorkitCore {
27776
27864
  });
27777
27865
  });
27778
27866
  if (!verified)
27779
- return failure2("permission_denied", "fixed findings require passing verification evidence");
27867
+ return refuse("permission_denied", "fixed findings require passing verification evidence");
27780
27868
  }
27781
27869
  if (input.disposition === "dismissed" && evidence.length === 0)
27782
- return failure2("permission_denied", "dismissal requires supporting evidence");
27870
+ return refuse("permission_denied", "dismissal requires supporting evidence");
27783
27871
  if (input.disposition === "dismissed") {
27784
27872
  const relevant = evidence.every((entry) => {
27785
27873
  if (entry.data.result === "missing" || entry.data.result === "skipped")
@@ -27789,7 +27877,7 @@ class WorkitCore {
27789
27877
  return candidateMatches && (referenceMatches || entry.data.claim === finding.data.claim);
27790
27878
  });
27791
27879
  if (!relevant)
27792
- return failure2("permission_denied", "dismissal evidence is unrelated to the finding");
27880
+ return refuse("permission_denied", "dismissal evidence is unrelated to the finding");
27793
27881
  }
27794
27882
  if (input.disposition === "deferred") {
27795
27883
  const workspace = this.store.readWorkspace();
@@ -27799,14 +27887,16 @@ class WorkitCore {
27799
27887
  return failure2("not_found", "workspace not found");
27800
27888
  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)));
27801
27889
  if (!allowed)
27802
- return failure2("permission_denied", "deferred findings require an approved limitation decision that references an acceptanceAllowed requirement and covers the finding scope");
27890
+ return refuse("permission_denied", "deferred findings require an approved limitation decision");
27803
27891
  }
27804
27892
  const changed = this.store.mutateTask(task.data.id, input.expectedRevision, (current, mutation) => {
27805
27893
  const existing = current.findings.find((entry) => entry.id === input.findingId);
27806
27894
  if (!existing)
27807
27895
  return failure2("not_found", "finding not found");
27808
- const data = input.disposition === "open" ? { ...existing.data, disposition: "open", resolution: null } : {
27896
+ const owner = helperId === null && existing.provenance.workerId !== null ? { leadOwned: true } : {};
27897
+ const data = input.disposition === "open" ? { ...existing.data, ...owner, disposition: "open", resolution: null } : {
27809
27898
  ...existing.data,
27899
+ ...owner,
27810
27900
  disposition: input.disposition,
27811
27901
  resolution: {
27812
27902
  reason: input.reason,
@@ -27838,7 +27928,7 @@ class WorkitCore {
27838
27928
  const root = this.contextRootError();
27839
27929
  if (!root.ok)
27840
27930
  return root;
27841
- const parsed = parseOperation("worker", request);
27931
+ const parsed = parseRequest("worker", request);
27842
27932
  if (!parsed.ok)
27843
27933
  return parsed;
27844
27934
  const input = parsed.data;
@@ -27857,19 +27947,19 @@ class WorkitCore {
27857
27947
  return failure2("permission_denied", "helpers cannot assign workers");
27858
27948
  if (task.data.status !== "active")
27859
27949
  return failure2("invalid_transition", "paused or closed tasks cannot assign workers");
27860
- if (!scopeCovers(task.data.intent.data.scope, input.assignment.scope))
27861
- return failure2("permission_denied", "worker assignment is outside task scope", {
27950
+ const gap = scopeGap(task.data.intent.data.scope, input.assignment.scope);
27951
+ if (gap) {
27952
+ const leadScope = task.data.intent.data.scope;
27953
+ const lead = leadScope.paths.join(", ") || "(none)";
27954
+ 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`;
27955
+ const excluded = leadScope.exclusions.length ? `; lead exclusions are ${leadScope.exclusions.join(", ")}` : "";
27956
+ return failure2("permission_denied", `worker assignment is outside task scope: ${reason}`, {
27862
27957
  fields: [
27863
- {
27864
- path: "assignment.scope",
27865
- reason: `paths ${JSON.stringify(input.assignment.scope.paths)} must be contained by lead paths ${JSON.stringify(task.data.intent.data.scope.paths)}`
27866
- },
27867
- {
27868
- path: "task.intent.scope",
27869
- reason: `lead paths are ${JSON.stringify(task.data.intent.data.scope.paths)}`
27870
- }
27958
+ { path: "assignment.scope", reason },
27959
+ { path: "task.intent.scope", reason: `lead paths are ${lead}${excluded}` }
27871
27960
  ]
27872
27961
  });
27962
+ }
27873
27963
  if (input.assignment.decisionIds.some((id) => !task.data.decisions.some((entry) => entry.id === id)))
27874
27964
  return failure2("invalid_input", "worker assignment references an unknown decision");
27875
27965
  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/mcp",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "private": false,
5
5
  "description": "Workit shared MCP transport for the eight task and policy operation families",
6
6
  "keywords": [
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@modelcontextprotocol/sdk": "1.32.0",
47
- "@workit-dev/core": "^1.1.5",
47
+ "@workit-dev/core": "^1.1.7",
48
48
  "zod": "4.6.5"
49
49
  },
50
50
  "engines": {