@brainervirus/workit-cursor 8.0.0 → 8.1.0

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.
@@ -2,7 +2,7 @@
2
2
  import { createRequire } from "node:module";
3
3
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
4
4
 
5
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/task-contract.ts
5
+ // packages/workit-core/src/core/task-contract.ts
6
6
  import { createHash, randomUUID } from "node:crypto";
7
7
 
8
8
  // node_modules/zod/v4/core/util.js
@@ -7516,7 +7516,7 @@ function refine(fn, _params = {}) {
7516
7516
  function superRefine(fn, params) {
7517
7517
  return _superRefine(fn, params);
7518
7518
  }
7519
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/task-contract.ts
7519
+ // packages/workit-core/src/core/task-contract.ts
7520
7520
  var SCHEMA_VERSION = 1;
7521
7521
  var POLICY_VERSION = "1.0.0";
7522
7522
  var OPERATION_FAMILIES = [
@@ -8372,14 +8372,14 @@ function requirementId(input) {
8372
8372
  });
8373
8373
  }
8374
8374
 
8375
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/task-engine.ts
8375
+ // packages/workit-core/src/core/task-engine.ts
8376
8376
  import { realpathSync as realpathSync4 } from "node:fs";
8377
8377
 
8378
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/policy/derive.ts
8378
+ // packages/workit-core/src/core/policy/derive.ts
8379
8379
  import { existsSync } from "node:fs";
8380
8380
  import path4 from "node:path";
8381
8381
 
8382
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/git/rev.ts
8382
+ // packages/workit-core/src/git/rev.ts
8383
8383
  import { spawnSync } from "node:child_process";
8384
8384
  import { createHash as createHash2 } from "node:crypto";
8385
8385
  import fs from "node:fs";
@@ -8531,13 +8531,13 @@ function currentBranch(cwd) {
8531
8531
  return line(git(cwd, ["symbolic-ref", "--short", "-q", "HEAD"]));
8532
8532
  }
8533
8533
 
8534
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/ledger.ts
8534
+ // packages/workit-core/src/ledger.ts
8535
8535
  import { spawnSync as spawnSync3 } from "node:child_process";
8536
8536
  import { createHash as createHash4, randomBytes } from "node:crypto";
8537
8537
  import fs3 from "node:fs";
8538
8538
  import path3 from "node:path";
8539
8539
 
8540
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/store/paths.ts
8540
+ // packages/workit-core/src/store/paths.ts
8541
8541
  import { spawnSync as spawnSync2 } from "node:child_process";
8542
8542
  import { createHash as createHash3 } from "node:crypto";
8543
8543
  import fs2 from "node:fs";
@@ -8817,7 +8817,7 @@ var checkoutSlug = (root) => {
8817
8817
  return `${base}-${shortHash(canonical)}`;
8818
8818
  };
8819
8819
 
8820
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/ledger.ts
8820
+ // packages/workit-core/src/ledger.ts
8821
8821
  var LEDGER_VERSION = 1;
8822
8822
  var PASSING = new Set(["verified", "tests-verified", "type-check-only"]);
8823
8823
  var FAILING = new Set(["failed", "blocked"]);
@@ -9055,7 +9055,7 @@ var independenceReasons = (row, authors) => {
9055
9055
  reasons.push("self");
9056
9056
  return reasons;
9057
9057
  };
9058
- function effectiveOf(rows, authors) {
9058
+ function effectiveOf(rows, authors, sameCode) {
9059
9059
  let effective = null;
9060
9060
  for (const row of rows) {
9061
9061
  if (!effective) {
@@ -9066,7 +9066,7 @@ function effectiveOf(rows, authors) {
9066
9066
  const effIndependent = independenceReasons(effective, authors).length === 0;
9067
9067
  if (effIndependent && !rowIndependent)
9068
9068
  continue;
9069
- if (effIndependent && FAILING.has(String(effective.result)) && row.actor.session === effective.actor.session)
9069
+ if (effIndependent && FAILING.has(String(effective.result)) && row.actor.session === effective.actor.session && sameCode(effective, row))
9070
9070
  continue;
9071
9071
  effective = row;
9072
9072
  }
@@ -9097,16 +9097,22 @@ function checkVerdicts(cwd, branch, rows) {
9097
9097
  const head = branchHead(cwd, branch);
9098
9098
  const fallbackBase = defaultBase(cwd);
9099
9099
  const keyCache = new Map;
9100
- const keyFor = (base) => {
9101
- if (!base || !head)
9100
+ const keysAt = (base, at) => {
9101
+ if (!base || !at)
9102
9102
  return { patchId: null, diffHash: null };
9103
- let key = keyCache.get(base);
9103
+ const cacheKey = `${base}\x00${at}`;
9104
+ let key = keyCache.get(cacheKey);
9104
9105
  if (!key) {
9105
- key = { patchId: patchId(cwd, base, head), diffHash: diffHash(cwd, base, head) };
9106
- keyCache.set(base, key);
9106
+ key = { patchId: patchId(cwd, base, at), diffHash: diffHash(cwd, base, at) };
9107
+ keyCache.set(cacheKey, key);
9107
9108
  }
9108
9109
  return key;
9109
9110
  };
9111
+ const keyFor = (base) => keysAt(base, head);
9112
+ const sameCode = (failed, row) => verdictBasis(failed, {
9113
+ head: row.head,
9114
+ ...keysAt(failed.base ?? fallbackBase, row.head)
9115
+ }) !== "stale" || restackCarries(rows, branch, failed.head, row.head);
9110
9116
  const authors = authorSessions(cwd, rows, branch, { base: fallbackBase, head });
9111
9117
  const byKind = new Map;
9112
9118
  for (const row of rows)
@@ -9116,7 +9122,7 @@ function checkVerdicts(cwd, branch, rows) {
9116
9122
  }
9117
9123
  const verdicts = [];
9118
9124
  for (const [kind, list] of byKind) {
9119
- const row = effectiveOf(list, authors);
9125
+ const row = effectiveOf(list, authors, sameCode);
9120
9126
  if (!row)
9121
9127
  continue;
9122
9128
  let basis = verdictBasis(row, { head, ...keyFor(row.base ?? fallbackBase) });
@@ -9142,11 +9148,11 @@ function checkVerdicts(cwd, branch, rows) {
9142
9148
  verdicts.sort((a, b) => a.verdict.seq - b.verdict.seq);
9143
9149
  const newestCurrent = verdicts.findLast((entry) => entry.current) ?? verdicts.at(-1) ?? null;
9144
9150
  const failing = verdicts.find((entry) => entry.current && entry.independent && FAILING.has(String(entry.verdict.result)));
9145
- const newestAccepted = verdicts.findLast((entry) => entry.accepted) ?? null;
9151
+ const newestAccepted = verdicts.findLast((entry) => entry.accepted && STRONG_RESULTS.has(String(entry.verdict.result))) ?? null;
9146
9152
  const accepted = newestAccepted && !failing ? { accepted: true, verdict: newestAccepted.verdict, reasons: [] } : {
9147
9153
  accepted: false,
9148
9154
  verdict: failing?.verdict ?? null,
9149
- reasons: failing ? ["failing_verdict"] : newestCurrent?.reasons ?? ["no_verdict"]
9155
+ reasons: failing ? ["failing_verdict"] : !newestCurrent ? ["no_verdict"] : newestCurrent.reasons.length ? newestCurrent.reasons : ["type_check_only"]
9150
9156
  };
9151
9157
  const selfEntry = failing ? undefined : verdicts.findLast((entry) => entry.current && !entry.independent && STRONG_RESULTS.has(String(entry.verdict.result)));
9152
9158
  return {
@@ -9162,9 +9168,9 @@ function checkVerdicts(cwd, branch, rows) {
9162
9168
  authors: [...authors].toSorted()
9163
9169
  };
9164
9170
  }
9165
- var OBSERVED_ONLY = new Set(["check", ...PR_ROW_TYPES]);
9171
+ var OBSERVED_ONLY = new Set(["check", "merge.unverified", ...PR_ROW_TYPES]);
9166
9172
 
9167
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/policy/derive.ts
9173
+ // packages/workit-core/src/core/policy/derive.ts
9168
9174
  var RULES = {
9169
9175
  test: "check:test",
9170
9176
  self: "verdict:self",
@@ -9363,7 +9369,7 @@ function writeBlockers(task, root) {
9363
9369
  });
9364
9370
  }
9365
9371
 
9366
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/policy-resolver.ts
9372
+ // packages/workit-core/src/core/policy-resolver.ts
9367
9373
  function resolvePolicy(input) {
9368
9374
  const ids = input.constraints.map((constraint) => constraint.id);
9369
9375
  if (new Set(ids).size !== ids.length)
@@ -9419,7 +9425,7 @@ function diffPolicy(previous, next, reason, now) {
9419
9425
  return parsed.data;
9420
9426
  }
9421
9427
 
9422
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/operation-input.ts
9428
+ // packages/workit-core/src/core/operation-input.ts
9423
9429
  var str2 = (d, values) => ({
9424
9430
  type: "string",
9425
9431
  ...values ? { enum: values } : {},
@@ -9765,7 +9771,7 @@ function normalizeOperationInput(family, input, host) {
9765
9771
  return request;
9766
9772
  }
9767
9773
 
9768
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/policy/judgment.ts
9774
+ // packages/workit-core/src/core/policy/judgment.ts
9769
9775
  var isObject3 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
9770
9776
  var squash = (key) => key.toLowerCase().replace(/[_-]/g, "");
9771
9777
  var ALIASES = {
@@ -9889,11 +9895,11 @@ function normalizeJudgment(raw, previous) {
9889
9895
  return success(null, null, { judgment: parsed.data, ignored, legacy });
9890
9896
  }
9891
9897
 
9892
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/autonomy.ts
9898
+ // packages/workit-core/src/autonomy.ts
9893
9899
  import os3 from "node:os";
9894
9900
  import path7 from "node:path";
9895
9901
 
9896
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/config.ts
9902
+ // packages/workit-core/src/core/config.ts
9897
9903
  import {
9898
9904
  copyFileSync,
9899
9905
  cpSync,
@@ -9906,7 +9912,7 @@ import {
9906
9912
  import os2 from "node:os";
9907
9913
  import path5 from "node:path";
9908
9914
 
9909
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/boundary.ts
9915
+ // packages/workit-core/src/core/boundary.ts
9910
9916
  var EVENT = {
9911
9917
  initialization: "initialization",
9912
9918
  provenance: "provenance",
@@ -9927,7 +9933,7 @@ var errorDetail = (err) => {
9927
9933
  return { error_name: "unknown", error: String(err) };
9928
9934
  };
9929
9935
 
9930
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/config.ts
9936
+ // packages/workit-core/src/core/config.ts
9931
9937
  var diagnosticLogger;
9932
9938
  var PRESETS = {
9933
9939
  gitflow: {
@@ -10002,6 +10008,7 @@ var DEFAULTS = {
10002
10008
  },
10003
10009
  commitPolicy: { preset: "conventional" }
10004
10010
  };
10011
+ var unchosenBranchPolicy = new WeakSet([DEFAULTS]);
10005
10012
  var readSafe = (p) => {
10006
10013
  try {
10007
10014
  return readFileSync(p, "utf8");
@@ -10026,22 +10033,21 @@ var parseConfigResult = (raw, file) => {
10026
10033
  const locale = LOCALE_RE.test(String(input.locale ?? "")) ? input.locale : DEFAULTS.locale;
10027
10034
  const preset = Object.hasOwn(PRESETS, input.branchPolicy?.preset) ? input.branchPolicy?.preset : "gitflow";
10028
10035
  const commitPreset = COMMIT_PRESETS.includes(String(input.commitPolicy?.preset ?? "")) ? input.commitPolicy?.preset : "conventional";
10029
- return {
10030
- status: "valid",
10031
- path: file,
10032
- config: {
10033
- locale,
10034
- localeOptions: Array.isArray(input.localeOptions) ? input.localeOptions : DEFAULTS.localeOptions,
10035
- branchPolicy: mergePreset(preset, {
10036
- allowed: Array.isArray(input.branchPolicy?.allowed) ? input.branchPolicy.allowed : undefined,
10037
- protectedNames: Array.isArray(input.branchPolicy?.protected) ? input.branchPolicy.protected : undefined
10038
- }, DEFAULTS),
10039
- commitPolicy: {
10040
- preset: commitPreset,
10041
- ...typeof input.commitPolicy?.pattern === "string" ? { pattern: input.commitPolicy.pattern } : {}
10042
- }
10036
+ const config = {
10037
+ locale,
10038
+ localeOptions: Array.isArray(input.localeOptions) ? input.localeOptions : DEFAULTS.localeOptions,
10039
+ branchPolicy: mergePreset(preset, {
10040
+ allowed: Array.isArray(input.branchPolicy?.allowed) ? input.branchPolicy.allowed : undefined,
10041
+ protectedNames: Array.isArray(input.branchPolicy?.protected) ? input.branchPolicy.protected : undefined
10042
+ }, DEFAULTS),
10043
+ commitPolicy: {
10044
+ preset: commitPreset,
10045
+ ...typeof input.commitPolicy?.pattern === "string" ? { pattern: input.commitPolicy.pattern } : {}
10043
10046
  }
10044
10047
  };
10048
+ if (!Object.hasOwn(PRESETS, input.branchPolicy?.preset))
10049
+ unchosenBranchPolicy.add(config);
10050
+ return { status: "valid", path: file, config };
10045
10051
  };
10046
10052
  var readConfigTyped = (dir) => {
10047
10053
  const file = path5.join(dir ?? configDir(), "config.json");
@@ -10054,9 +10060,11 @@ var readConfig = () => {
10054
10060
  return result.config ?? DEFAULTS;
10055
10061
  };
10056
10062
  var branchGlobPattern = (glob) => new RegExp(`^${glob.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`, "i");
10057
- var resolveBranchPolicy = (config, workspace) => {
10063
+ var resolveBranchPolicy = (config, workspace, repoPreset) => {
10058
10064
  const wp = workspace?.branchPolicy ?? {};
10059
- const preset = Object.hasOwn(PRESETS, wp.preset) ? wp.preset : config.branchPolicy?.preset ?? "gitflow";
10065
+ const workspacePreset = Object.hasOwn(PRESETS, wp.preset);
10066
+ const detected = !workspacePreset && unchosenBranchPolicy.has(config) ? repoPreset?.() ?? null : null;
10067
+ const preset = workspacePreset ? wp.preset : detected ?? config.branchPolicy?.preset ?? "gitflow";
10060
10068
  const merged = mergePreset(preset, {
10061
10069
  allowed: wp.allowed,
10062
10070
  protectedNames: wp.protected
@@ -10065,9 +10073,10 @@ var resolveBranchPolicy = (config, workspace) => {
10065
10073
  return {
10066
10074
  preset,
10067
10075
  allowed,
10068
- protected: new Set(merged.protected.map((p) => p.toLowerCase())),
10076
+ protected: new Set([...merged.protected, ...detected ? PRESETS.gitflow.protected : []].map((p) => p.toLowerCase())),
10069
10077
  integration: wp.integration === "merge" ? "merge" : "pr",
10070
- defaultTargetBranch: preset === "github-flow" ? "main" : preset === "trunk-based" ? "master" : "develop"
10078
+ defaultTargetBranch: preset === "github-flow" ? "main" : preset === "trunk-based" ? "master" : "develop",
10079
+ detected: detected !== null
10071
10080
  };
10072
10081
  };
10073
10082
  var COMMIT_PRESETS = [
@@ -10089,10 +10098,77 @@ var resolveCommitPolicy = (config, workspace) => {
10089
10098
  return config.commitPolicy ?? { preset: "conventional" };
10090
10099
  };
10091
10100
 
10092
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/workspaces.ts
10101
+ // packages/workit-core/src/core/workspaces.ts
10093
10102
  import { createHash as createHash5 } from "node:crypto";
10094
10103
  import { readFileSync as readFileSync2, realpathSync } from "node:fs";
10095
10104
  import path6 from "node:path";
10105
+
10106
+ // packages/workit-core/src/core/branch-policy.ts
10107
+ import { spawnSync as spawnSync4 } from "node:child_process";
10108
+ var PREFIXES = {
10109
+ feature: "feature/*",
10110
+ bugfix: "bugfix/*",
10111
+ release: "release/*",
10112
+ hotfix: "hotfix/*"
10113
+ };
10114
+ var branchNames = (workspaceRoot) => {
10115
+ const r = spawnSync4("git", ["for-each-ref", "--format=%(refname)", "refs/heads", "refs/remotes/origin"], { cwd: workspaceRoot, encoding: "utf8" });
10116
+ if (r.status !== 0)
10117
+ return new Set;
10118
+ return new Set((r.stdout ?? "").split(`
10119
+ `).filter(Boolean).map((ref) => ref.startsWith("refs/heads/") ? ref.slice("refs/heads/".length) : ref.slice("refs/remotes/origin/".length)));
10120
+ };
10121
+ var detectBranchPolicy = (workspaceRoot) => {
10122
+ const names = branchNames(workspaceRoot);
10123
+ const develop = names.has("develop");
10124
+ const main = names.has("main");
10125
+ const master = names.has("master");
10126
+ const root = main ? "main" : master ? "master" : null;
10127
+ if (develop) {
10128
+ return {
10129
+ preset: "gitflow",
10130
+ developBranch: "develop",
10131
+ integration: "merge",
10132
+ protected: root ? [root, "develop"] : ["develop"],
10133
+ allowed: [...PRESETS.gitflow.allowed],
10134
+ prefixes: PREFIXES
10135
+ };
10136
+ }
10137
+ if (root === "main") {
10138
+ return {
10139
+ preset: "github-flow",
10140
+ developBranch: null,
10141
+ integration: "pr",
10142
+ protected: [root],
10143
+ allowed: ["*"],
10144
+ prefixes: PREFIXES
10145
+ };
10146
+ }
10147
+ if (root === "master") {
10148
+ return {
10149
+ preset: "trunk-based",
10150
+ developBranch: null,
10151
+ integration: "pr",
10152
+ protected: [root],
10153
+ allowed: ["*"],
10154
+ prefixes: PREFIXES
10155
+ };
10156
+ }
10157
+ return {
10158
+ preset: "gitflow",
10159
+ developBranch: null,
10160
+ integration: "merge",
10161
+ protected: [],
10162
+ allowed: [],
10163
+ prefixes: PREFIXES
10164
+ };
10165
+ };
10166
+ var repoBranchPreset = (workspaceRoot) => {
10167
+ const detected = detectBranchPolicy(workspaceRoot);
10168
+ return detected.developBranch || detected.allowed.length ? detected.preset : null;
10169
+ };
10170
+
10171
+ // packages/workit-core/src/core/workspaces.ts
10096
10172
  var nonBlank = string2().refine((value) => value.trim().length > 0, "must not be blank");
10097
10173
  var branchPreset = custom((value) => typeof value === "string" && Object.hasOwn(PRESETS, value), "unsupported branch preset");
10098
10174
  var commitPreset = custom((value) => typeof value === "string" && COMMIT_PRESETS.includes(value), "unsupported commit preset");
@@ -10489,7 +10565,7 @@ var resolveRuntimeWorkspacePolicy = (cwd, kind, requestedProfile) => {
10489
10565
  };
10490
10566
  };
10491
10567
 
10492
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/autonomy.ts
10568
+ // packages/workit-core/src/autonomy.ts
10493
10569
  var accountHome = () => {
10494
10570
  try {
10495
10571
  return os3.userInfo().homedir;
@@ -10624,7 +10700,7 @@ function resolveAutonomy(cwd) {
10624
10700
  var suggested = (kind) => kind === "merge" ? "verified" : "true";
10625
10701
  var grantHint = (workspace, kind) => `ask the user to run, in their own terminal: workit grant set ${workspace ?? "<workspace>"} ${kind}=${suggested(kind)}`;
10626
10702
 
10627
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/task-store.ts
10703
+ // packages/workit-core/src/core/task-store.ts
10628
10704
  import { createHash as createHash7, randomUUID as randomUUID3 } from "node:crypto";
10629
10705
  import * as fs9 from "node:fs";
10630
10706
  import path12 from "node:path";
@@ -11230,7 +11306,7 @@ function acquireFileLockSync(targetPath, options) {
11230
11306
  }
11231
11307
  }
11232
11308
  }
11233
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/package-root.ts
11309
+ // packages/workit-core/src/core/package-root.ts
11234
11310
  import { existsSync as existsSync3 } from "node:fs";
11235
11311
  import path10 from "node:path";
11236
11312
  import { fileURLToPath } from "node:url";
@@ -11244,8 +11320,8 @@ var packageRoot = () => {
11244
11320
  }
11245
11321
  };
11246
11322
 
11247
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/store-lock.ts
11248
- import { spawnSync as spawnSync4 } from "node:child_process";
11323
+ // packages/workit-core/src/core/store-lock.ts
11324
+ import { spawnSync as spawnSync5 } from "node:child_process";
11249
11325
  import fs7 from "node:fs";
11250
11326
  import { hostname } from "node:os";
11251
11327
  var metadataLockSchema = object({
@@ -11295,7 +11371,7 @@ var processStartOf = (pid) => {
11295
11371
  }
11296
11372
  if (process.platform === "darwin" || process.platform === "freebsd") {
11297
11373
  try {
11298
- const run = spawnSync4("ps", ["-o", "lstart=", "-p", String(pid)], {
11374
+ const run = spawnSync5("ps", ["-o", "lstart=", "-p", String(pid)], {
11299
11375
  encoding: "utf8",
11300
11376
  timeout: 1000
11301
11377
  });
@@ -11378,7 +11454,7 @@ var clearAbandonedReclaimGuard = (lockPath, nowMs = Date.now()) => {
11378
11454
  }
11379
11455
  };
11380
11456
 
11381
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/store/event-log.ts
11457
+ // packages/workit-core/src/store/event-log.ts
11382
11458
  import { randomUUID as randomUUID2 } from "node:crypto";
11383
11459
  import fs8 from "node:fs";
11384
11460
  import path11 from "node:path";
@@ -11538,7 +11614,7 @@ var retryTransient = (run) => {
11538
11614
  };
11539
11615
  var renameWithRetry = (from, to) => retryTransient(() => fs8.renameSync(from, to));
11540
11616
 
11541
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/store/patch.ts
11617
+ // packages/workit-core/src/store/patch.ts
11542
11618
  var isPlainObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
11543
11619
  var equal = (left, right) => {
11544
11620
  if (left === right)
@@ -11648,7 +11724,7 @@ var isPatch = (value) => Array.isArray(value) && value.every((op) => {
11648
11724
  return false;
11649
11725
  });
11650
11726
 
11651
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/store/reduce.ts
11727
+ // packages/workit-core/src/store/reduce.ts
11652
11728
  import { createHash as createHash6 } from "node:crypto";
11653
11729
  var OPENING_TYPES = new Set([
11654
11730
  "task.opened",
@@ -11779,7 +11855,7 @@ function eventType(before, after) {
11779
11855
  return "task.updated";
11780
11856
  }
11781
11857
 
11782
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/store/notes.ts
11858
+ // packages/workit-core/src/store/notes.ts
11783
11859
  var SLOT = Symbol.for("workit.migrationReporter");
11784
11860
  var reportMigration = (report) => {
11785
11861
  try {
@@ -11790,7 +11866,7 @@ var reportMigration = (report) => {
11790
11866
  };
11791
11867
  var migrationReporterInstalled = () => typeof globalThis[SLOT] === "function";
11792
11868
 
11793
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/task-store.ts
11869
+ // packages/workit-core/src/core/task-store.ts
11794
11870
  var MIGRATION_PENDING = "workit migration pending";
11795
11871
  var STORE_FORMAT = 3;
11796
11872
  var STORE_MIN_RUNTIME = "3.0.0";
@@ -13427,19 +13503,19 @@ class TaskStore {
13427
13503
  }
13428
13504
  }
13429
13505
 
13430
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/workers.ts
13506
+ // packages/workit-core/src/core/workers.ts
13431
13507
  var UNCERTAIN_WORKER_STATES = ["dispatching", "running", "cancelling", "unknown"];
13432
13508
  var isUncertainWorker = (state) => UNCERTAIN_WORKER_STATES.includes(state);
13433
13509
  var workerBlocksTransition = (transition, state) => transition === "pause" ? false : isUncertainWorker(state);
13434
13510
 
13435
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/task-evaluation.ts
13511
+ // packages/workit-core/src/core/task-evaluation.ts
13436
13512
  import { createHash as createHash8 } from "node:crypto";
13437
13513
  import * as fs11 from "node:fs";
13438
- import { spawnSync as spawnSync6 } from "node:child_process";
13514
+ import { spawnSync as spawnSync7 } from "node:child_process";
13439
13515
  import path14 from "node:path";
13440
13516
 
13441
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/check-config.ts
13442
- import { spawnSync as spawnSync5 } from "node:child_process";
13517
+ // packages/workit-core/src/check-config.ts
13518
+ import { spawnSync as spawnSync6 } from "node:child_process";
13443
13519
  import fs10 from "node:fs";
13444
13520
  import path13 from "node:path";
13445
13521
  var SCRIPT_CHECKS = ["test", "lint", "typecheck", "check"];
@@ -13483,7 +13559,7 @@ function splitCommand(command) {
13483
13559
  return argv.length ? argv : new Error("empty command");
13484
13560
  }
13485
13561
  var git3 = (cwd, args) => {
13486
- const run = spawnSync5("git", args, {
13562
+ const run = spawnSync6("git", args, {
13487
13563
  cwd,
13488
13564
  encoding: "utf8",
13489
13565
  timeout: 20000,
@@ -13643,7 +13719,7 @@ function checkCommand(args, version, onPath = workitAvailable()) {
13643
13719
  return onPath ? `workit check ${args}` : `npx -y @brainervirus/workit-cli@${version} check ${args}`;
13644
13720
  }
13645
13721
 
13646
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/task-evaluation.ts
13722
+ // packages/workit-core/src/core/task-evaluation.ts
13647
13723
  var digestBytes = (value) => createHash8("sha256").update(value).digest("hex");
13648
13724
  var inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path14.sep}`);
13649
13725
  var relative = (root, candidate) => path14.relative(root, candidate).split(path14.sep).join("/") || ".";
@@ -13688,7 +13764,7 @@ var compareCodeUnits3 = (left, right) => {
13688
13764
  return left.length - right.length;
13689
13765
  };
13690
13766
  var gitPaths = (root) => {
13691
- const result = spawnSync6("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
13767
+ const result = spawnSync7("git", ["ls-files", "-z", "--cached", "--others", "--exclude-standard"], {
13692
13768
  cwd: root,
13693
13769
  encoding: "buffer"
13694
13770
  });
@@ -13701,7 +13777,7 @@ var gitPaths = (root) => {
13701
13777
  };
13702
13778
  }
13703
13779
  const paths = result.stdout ? result.stdout.toString("utf8").split("\x00").filter(Boolean).map((item) => item.split(path14.sep).join("/")) : [];
13704
- const stagedDeleted = spawnSync6("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
13780
+ const stagedDeleted = spawnSync7("git", ["diff", "--cached", "--name-only", "--diff-filter=D", "-z"], { cwd: root, encoding: "buffer" });
13705
13781
  if (stagedDeleted.status !== 0) {
13706
13782
  const stderr = stagedDeleted.stderr?.toString("utf8") ?? "";
13707
13783
  if (!/not a git repository/i.test(stderr))
@@ -13832,7 +13908,7 @@ function captureCandidate(root, scope, environment = []) {
13832
13908
  const values = supplied.toSorted((left, right) => compareCodeUnits3(left.name, right.name)).map(({ name, value }) => ({ name, value, refs: [] }));
13833
13909
  if (values.some(({ value }) => value === null))
13834
13910
  completeness = "uncertain";
13835
- const headResult = spawnSync6("git", ["rev-parse", "HEAD"], { cwd: checkout, encoding: "utf8" });
13911
+ const headResult = spawnSync7("git", ["rev-parse", "HEAD"], { cwd: checkout, encoding: "utf8" });
13836
13912
  if (headResult.status !== 0 && !/not a git repository/i.test(headResult.stderr ?? ""))
13837
13913
  completeness = "uncertain";
13838
13914
  const head = headResult.status === 0 ? headResult.stdout.trim() : null;
@@ -14309,7 +14385,7 @@ function evaluateClosure(requestedOutcome, view) {
14309
14385
  });
14310
14386
  }
14311
14387
 
14312
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/methods.ts
14388
+ // packages/workit-core/src/core/methods.ts
14313
14389
  var METHODS = {
14314
14390
  "workit-shape": { dimensions: ["challenge", "decisions", "artifacts", "continuity"] },
14315
14391
  "workit-bdd": { dimensions: ["testing"] },
@@ -14417,7 +14493,7 @@ Skills: load the skill, never act from memory of it (slash aliases /wk-<name>).
14417
14493
  - architecture, deepen modules (user-invoked; offer it): workit-architecture
14418
14494
  `.trim();
14419
14495
 
14420
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/task-context.ts
14496
+ // packages/workit-core/src/core/task-context.ts
14421
14497
  function reconcileResume(view, observations = []) {
14422
14498
  if (observations.length > 0)
14423
14499
  return failure2("permission_denied", "worker observations require native host verification");
@@ -14532,7 +14608,7 @@ var exportDigest = (bundle) => sha256({
14532
14608
  task: bundle.task
14533
14609
  });
14534
14610
 
14535
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/task-engine.ts
14611
+ // packages/workit-core/src/core/task-engine.ts
14536
14612
  var workspaceVerification = (root) => {
14537
14613
  try {
14538
14614
  return resolveAutonomy(root).verification;
@@ -16117,7 +16193,7 @@ class WorkitCore {
16117
16193
  return this.summary(changed.data.task);
16118
16194
  }
16119
16195
  }
16120
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/hooks/descriptor.ts
16196
+ // packages/workit-core/src/hooks/descriptor.ts
16121
16197
  var support = (descriptor, axis) => {
16122
16198
  if (axis.startsWith("event:"))
16123
16199
  return descriptor.events[axis.slice("event:".length)].support;
@@ -16141,7 +16217,7 @@ var capabilitiesFor = (descriptor, observed = {}) => descriptor.capabilities.map
16141
16217
  refs: rule.refs.map((handle) => ({ kind: "host", host: descriptor.host, handle }))
16142
16218
  };
16143
16219
  });
16144
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/hooks/context.ts
16220
+ // packages/workit-core/src/hooks/context.ts
16145
16221
  import path15 from "node:path";
16146
16222
  var MIGRATION_PENDING_NOTE = "workit migration pending — run `workit task status`";
16147
16223
  var migrationPending = (result) => !result.ok && result.code === "needs_input" && (result.error ?? "").startsWith(MIGRATION_PENDING);
@@ -16289,10 +16365,10 @@ var turnContextText = (input, descriptor) => {
16289
16365
  return null;
16290
16366
  }
16291
16367
  };
16292
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/branch.ts
16368
+ // packages/workit-core/src/core/branch.ts
16293
16369
  import { createHash as createHash9 } from "node:crypto";
16294
16370
 
16295
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/release-tracks.ts
16371
+ // packages/workit-core/src/core/release-tracks.ts
16296
16372
  class ReleaseTrackError extends Error {
16297
16373
  }
16298
16374
  var KNOWN_FIELDS = new Set([
@@ -16431,7 +16507,7 @@ function workspaceReleaseTracks(cwd) {
16431
16507
  }
16432
16508
  var memo3 = new Map;
16433
16509
 
16434
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/branch.ts
16510
+ // packages/workit-core/src/core/branch.ts
16435
16511
  var withReleaseTracks = (workspaceRoot, policy) => {
16436
16512
  const read = workspaceReleaseTracks(workspaceRoot);
16437
16513
  if (read.error)
@@ -16460,7 +16536,7 @@ function effectiveWorkspacePolicy(workspaceRoot, kind, profileName) {
16460
16536
  const selected = resolveRuntimeWorkspacePolicy(workspaceRoot, kind, profileName?.trim() || process.env.WORKFLOW_PROFILE?.trim() || undefined);
16461
16537
  const config = readConfig();
16462
16538
  return kind === "branch" ? {
16463
- branchPolicy: withReleaseTracks(workspaceRoot, resolveBranchPolicy(config, selected.policy ? { branchPolicy: selected.policy } : null)),
16539
+ branchPolicy: withReleaseTracks(workspaceRoot, resolveBranchPolicy(config, selected.policy ? { branchPolicy: selected.policy } : null, () => repoBranchPreset(workspaceRoot))),
16464
16540
  provenance: { branchPolicy: selected.source }
16465
16541
  } : {
16466
16542
  commitPolicy: resolveCommitPolicy(config, selected.policy ? { commitPolicy: selected.policy } : null),
@@ -16524,7 +16600,7 @@ var validateBranchNameFor = (workspaceRoot, name) => {
16524
16600
  }
16525
16601
  };
16526
16602
 
16527
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/core/route-intent.ts
16603
+ // packages/workit-core/src/core/route-intent.ts
16528
16604
  var shellBranchTarget = (command) => {
16529
16605
  if (!command.trim() || /[\r\n;&|<>`'"$()\\*?{}~!#]/u.test(command) || command.includes("[") || command.includes("]"))
16530
16606
  return null;
@@ -16540,12 +16616,12 @@ var shellBranchPolicyViolation = (root, command) => {
16540
16616
  return target === null ? null : validateBranchNameFor(root, target);
16541
16617
  };
16542
16618
 
16543
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/hooks/policy.ts
16619
+ // packages/workit-core/src/hooks/policy.ts
16544
16620
  var shellPolicy = (cwd, command) => {
16545
16621
  const policy = shellBranchPolicyViolation(cwd, command);
16546
16622
  return policy && !policy.ok ? { kind: "deny", reason: `branch_policy_denied: ${policy.error}`, unblock: null } : { kind: "none" };
16547
16623
  };
16548
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/hooks/write-gate.ts
16624
+ // packages/workit-core/src/hooks/write-gate.ts
16549
16625
  import { realpathSync as realpathSync5 } from "node:fs";
16550
16626
  import path16 from "node:path";
16551
16627
  var NONE2 = { kind: "none" };
@@ -16657,11 +16733,11 @@ var segmentsOf = (command) => {
16657
16733
  flushSegment();
16658
16734
  return segments;
16659
16735
  };
16660
- var PREFIXES = new Set(["sudo", "command", "env", "nohup", "time", "exec", "xargs"]);
16736
+ var PREFIXES2 = new Set(["sudo", "command", "env", "nohup", "time", "exec", "xargs"]);
16661
16737
  var operands = (words) => words.filter((item) => !item.startsWith("-"));
16662
16738
  var editsOf = (input) => {
16663
16739
  let words = input;
16664
- while (words.length && (PREFIXES.has(words[0]) || /^\w+=/.test(words[0])))
16740
+ while (words.length && (PREFIXES2.has(words[0]) || /^\w+=/.test(words[0])))
16665
16741
  words = words.slice(1);
16666
16742
  const [verb, ...args] = words;
16667
16743
  const name = (verb?.split(/[\\/]/).at(-1) ?? "").toLowerCase();
@@ -16806,7 +16882,7 @@ function writeGate(cwd, paths) {
16806
16882
  return NONE2;
16807
16883
  }
16808
16884
  }
16809
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/hooks/hosts/fields.ts
16885
+ // packages/workit-core/src/hooks/hosts/fields.ts
16810
16886
  import { existsSync as existsSync6, realpathSync as realpathSync6, statSync as statSync2 } from "node:fs";
16811
16887
  import path17 from "node:path";
16812
16888
  var isRecord4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
@@ -16874,7 +16950,7 @@ var writePaths = (input) => {
16874
16950
  paths.push(match[1].trim());
16875
16951
  return [...new Set(paths)];
16876
16952
  };
16877
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/hooks/handle.ts
16953
+ // packages/workit-core/src/hooks/handle.ts
16878
16954
  var usable2 = (value) => value === "native" || value === "partial";
16879
16955
  var NONE3 = { kind: "none" };
16880
16956
  var offered = new Set;
@@ -16970,7 +17046,7 @@ var dispatchHook = (adapter, raw, env = process.env) => {
16970
17046
  };
16971
17047
  }
16972
17048
  };
16973
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/hooks/hosts/claude-code.ts
17049
+ // packages/workit-core/src/hooks/hosts/claude-code.ts
16974
17050
  var CLAUDE_CODE_DESCRIPTOR = {
16975
17051
  host: "claude_code",
16976
17052
  label: "Claude Code",
@@ -17213,7 +17289,7 @@ var claudeCodeAdapter = {
17213
17289
  render
17214
17290
  };
17215
17291
 
17216
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/hooks/hosts/codex.ts
17292
+ // packages/workit-core/src/hooks/hosts/codex.ts
17217
17293
  function detectCodexSurface(env) {
17218
17294
  return env.CODEX_INTERNAL_ORIGINATOR_OVERRIDE === "Codex Desktop" || Boolean(env.CODEX_ELECTRON_RESOURCES_PATH) ? "codex_desktop" : "codex_cli";
17219
17295
  }
@@ -17441,7 +17517,7 @@ var codexAdapter = {
17441
17517
  addendum: (input) => `<workit-codex-mutations>Codex MCP is read-only: unattested callers cannot mutate. Run workit verbs with the workit CLI on the shell (node_modules/.bin/workit, or npx -y @brainervirus/workit-cli): check, git branch|commit|push, pr, ci, stack, ledger, handoff; task-family mutations take --json${input.session.id ? ` --actor ${input.session.id}` : ""}. A verifier or reviewer records workit ledger verdict under a session the lead assigns (WORKIT_SESSION_ID=<lead>-v<n>), never the author's. Merge and release need a workspace grant (workit grant show); a question answer is not host permission.</workit-codex-mutations>`
17442
17518
  };
17443
17519
 
17444
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/hooks/hosts/cursor.ts
17520
+ // packages/workit-core/src/hooks/hosts/cursor.ts
17445
17521
  import path18 from "node:path";
17446
17522
  var undocumented2 = { support: "undocumented", native: null };
17447
17523
  var none = { support: "none", native: null };
@@ -17685,7 +17761,7 @@ var cursorAdapter = {
17685
17761
  render: render3
17686
17762
  };
17687
17763
 
17688
- // packages/workit-cursor/node_modules/@brainervirus/workit-core/src/hooks/run.ts
17764
+ // packages/workit-core/src/hooks/run.ts
17689
17765
  var HOOK_ADAPTERS = {
17690
17766
  claude_code: claudeCodeAdapter,
17691
17767
  codex_cli: codexAdapter,