@brainervirus/workit-opencode 8.27.0 → 8.28.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 +126 -7
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -7106,8 +7106,9 @@ function flatOperationJsonSchema(family, options = {}) {
7106
7106
  };
7107
7107
  const properties = { action: { type: "string", enum: actions } };
7108
7108
  const readField = (name) => name === "taskId" || (family === "task" ? READ_TASK_FIELDS.has(name) : family === "policy");
7109
+ const taken = (name) => family === "policy" || actions.some((action) => actionKeys(family, action)?.accepted.has(name));
7109
7110
  for (const [name, field] of Object.entries({ ...COMMON, ...spec.fields }))
7110
- if (options.readOnly ? readField(name) : !(family === "state" && name === "expectedRevision"))
7111
+ if (options.readOnly ? readField(name) : taken(name))
7111
7112
  properties[name] = property(field);
7112
7113
  return {
7113
7114
  $schema: "https://json-schema.org/draft/2020-12/schema",
@@ -7349,6 +7350,98 @@ function normalizeOperationInput(family, input, host) {
7349
7350
  request[key] = strings(request[key]);
7350
7351
  return request;
7351
7352
  }
7353
+ var defOf = (node) => node._zod.def;
7354
+ var unwrap = (node) => {
7355
+ let inner = node;
7356
+ while (["optional", "nullable"].includes(defOf(inner).type) && defOf(inner).innerType)
7357
+ inner = defOf(inner).innerType;
7358
+ return inner;
7359
+ };
7360
+ var FLAT_NAME = {
7361
+ authorityRefs: "refs",
7362
+ contentRefs: "refs",
7363
+ statedChoice: "choice",
7364
+ reviewContext: "reviewSession"
7365
+ };
7366
+ var NOT_FLAT = new Set(["schemaVersion", "action", "workspaceId"]);
7367
+ function actionKeys(family, action) {
7368
+ const options = advertisedOperationSchemas[family].options;
7369
+ const option = options.find((item) => {
7370
+ const literal = defOf(item).shape?.action;
7371
+ return literal._zod.def.values.includes(action);
7372
+ });
7373
+ if (!option)
7374
+ return null;
7375
+ const out = { accepted: new Set, required: [] };
7376
+ const walk = (shape, nested) => {
7377
+ for (const [key, node] of Object.entries(shape)) {
7378
+ if (NOT_FLAT.has(key) || nested && key === "taskId")
7379
+ continue;
7380
+ const inner = unwrap(node);
7381
+ const type = defOf(inner).type;
7382
+ const needed = !["optional", "nullable"].includes(defOf(node).type);
7383
+ if (key === "scope")
7384
+ for (const name of ["scope", "paths", "exclusions"])
7385
+ out.accepted.add(name);
7386
+ else if (type === "object" && key !== "bundle" && !(key in FLAT_NAME)) {
7387
+ out.accepted.add(key);
7388
+ walk(defOf(inner).shape, true);
7389
+ } else {
7390
+ const name = FLAT_NAME[key] ?? key;
7391
+ out.accepted.add(name);
7392
+ if (needed && type !== "array" && type !== "record" && !out.required.includes(name))
7393
+ out.required.push(name);
7394
+ }
7395
+ }
7396
+ };
7397
+ walk(defOf(option).shape, false);
7398
+ return out;
7399
+ }
7400
+ function exampleOperation(family, action) {
7401
+ const keys = actionKeys(family, action);
7402
+ const example = { action };
7403
+ for (const name of keys?.required ?? [])
7404
+ example[name] = FLAT[family].fields[name]?.enum?.[0] ?? `<${name}>`;
7405
+ if (family === "policy" && !keys?.required.length && action !== "explain")
7406
+ example.riskTier = "normal";
7407
+ return example;
7408
+ }
7409
+ var oneOf = (values) => values.join(" | ");
7410
+ function invalidOperation(family, input, error) {
7411
+ const request = isObject2(input) ? input : {};
7412
+ const action = typeof request.action === "string" ? request.action : "";
7413
+ const actions = OPERATION_ACTIONS[family];
7414
+ if (!actions.includes(action))
7415
+ return failure2("invalid_input", `${family}: action must be one of ${oneOf(actions)}`, {
7416
+ fields: [{ path: "action", reason: `got ${JSON.stringify(request.action ?? null)}` }]
7417
+ });
7418
+ const own = actionKeys(family, action);
7419
+ const fields = [];
7420
+ const sentence = [];
7421
+ for (const issue of error.issues) {
7422
+ if (issue.code === "unrecognized_keys") {
7423
+ for (const key of issue.keys) {
7424
+ const home = actions.find((other) => other !== action && actionKeys(family, other).accepted.has(key));
7425
+ const reason = home ? `${key} belongs to action: ${home}` : `${key} is not a field of ${family} ${action}; it takes ${[...own.accepted].join(", ")}`;
7426
+ fields.push({ path: key, reason });
7427
+ sentence.push(reason);
7428
+ }
7429
+ continue;
7430
+ }
7431
+ const last = String(issue.path.at(-1) ?? "");
7432
+ const name = Object.entries(FLAT_NAME).find(([contract]) => contract === last)?.[1] ?? last;
7433
+ const missing = issue.code === "invalid_type" && /received undefined/.test(issue.message);
7434
+ const absent = own.required.filter((key) => !(key in request));
7435
+ const needs = missing && issue.path.length === 1 && absent.length ? absent.join(", ") : name;
7436
+ const reason = missing ? `${family} ${action} requires ${needs}` : `${name}: ${issue.message}`;
7437
+ fields.push({ path: issue.path.join("."), reason });
7438
+ sentence.push(reason);
7439
+ }
7440
+ const example = JSON.stringify(exampleOperation(family, action));
7441
+ return failure2("invalid_input", `${[...new Set(sentence)].join("; ")}. Example: ${example}`, {
7442
+ fields
7443
+ });
7444
+ }
7352
7445
  function parseAdvertisedOperation(family, input, host) {
7353
7446
  const request = normalizeOperationInput(family, input, host);
7354
7447
  if (isObject2(request) && request.schemaVersion !== SCHEMA_VERSION)
@@ -7356,12 +7449,7 @@ function parseAdvertisedOperation(family, input, host) {
7356
7449
  const parsed = advertisedOperationSchemas[family].safeParse(request);
7357
7450
  if (parsed.success)
7358
7451
  return success(null, null, request);
7359
- return failure2("invalid_input", "operation input is invalid", {
7360
- fields: parsed.error.issues.map((issue) => ({
7361
- path: issue.code === "unrecognized_keys" ? issue.keys.join(".") : issue.path.join("."),
7362
- reason: issue.message
7363
- }))
7364
- });
7452
+ return invalidOperation(family, request, parsed.error);
7365
7453
  }
7366
7454
  // packages/workit-core/src/core/task-store.ts
7367
7455
  import { createHash as createHash9, randomUUID as randomUUID3 } from "node:crypto";
@@ -10074,11 +10162,16 @@ var branchPolicySnapshotFor = (workspaceRoot) => {
10074
10162
  fingerprint
10075
10163
  };
10076
10164
  };
10165
+ var rethrowRuntimeBug = (error) => {
10166
+ if (error instanceof TypeError || error instanceof ReferenceError)
10167
+ throw error;
10168
+ };
10077
10169
  var validateBranchNameFor = (workspaceRoot, name) => {
10078
10170
  try {
10079
10171
  const resolved = branchPolicySnapshotFor(workspaceRoot);
10080
10172
  return validateBranchNamePolicy(name, resolved.namePolicy, resolved.source);
10081
10173
  } catch (error) {
10174
+ rethrowRuntimeBug(error);
10082
10175
  const correction = "repair or select a valid workspace policy before creating a branch";
10083
10176
  return {
10084
10177
  ok: false,
@@ -23766,6 +23859,32 @@ var standingSinceStart = (input) => {
23766
23859
  return null;
23767
23860
  }
23768
23861
  };
23862
+ // packages/workit-core/src/core/role-models.ts
23863
+ var MODEL_ROLES = [
23864
+ "decider",
23865
+ "implementer",
23866
+ "verifier",
23867
+ "reviewer",
23868
+ "explore",
23869
+ "babysit"
23870
+ ];
23871
+ var MODEL_TIERS = ["mundane", "standard", "hard"];
23872
+ var HOST_KEYS = new Set([
23873
+ "claude_code",
23874
+ "opencode",
23875
+ "codex",
23876
+ "codex_cli",
23877
+ "codex_desktop",
23878
+ "cursor",
23879
+ "pi",
23880
+ "default"
23881
+ ]);
23882
+ var ROLE_SELECTORS = MODEL_ROLES.flatMap((role) => role === "implementer" ? MODEL_TIERS.map((tier) => ({ role, tier })) : [{ role }]);
23883
+
23884
+ // packages/workit-core/src/hooks/agent-model.ts
23885
+ var MODELS = new Set(["sonnet", "opus", "haiku", "fable"]);
23886
+ var EFFORTS = new Set(["low", "medium", "high", "xhigh", "max"]);
23887
+
23769
23888
  // packages/workit-core/src/hooks/cwd-normalize.ts
23770
23889
  var DIR = String.raw`[A-Za-z0-9_./@%+:,=-]+|'[^'$${"`"}\\\n]*'|"[^"$${"`"}\\!\n]*"`;
23771
23890
  var COMPOUND = new RegExp(String.raw`^\s*cd\s+(${DIR})\s*&&\s*(workit(?:\s[\s\S]*)?)$`, "u");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brainervirus/workit-opencode",
3
- "version": "8.27.0",
3
+ "version": "8.28.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.27.0",
42
+ "@brainervirus/workit-core": "^8.28.1",
43
43
  "@opencode/plugin": "2.0.18"
44
44
  },
45
45
  "engines": {