@brainervirus/workit-pi 8.0.1 → 8.1.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.
package/dist/worker.js CHANGED
@@ -8413,6 +8413,7 @@ var DEFAULTS = {
8413
8413
  },
8414
8414
  commitPolicy: { preset: "conventional" }
8415
8415
  };
8416
+ var unchosenBranchPolicy = new WeakSet([DEFAULTS]);
8416
8417
  var COMMIT_PRESETS = [
8417
8418
  "conventional",
8418
8419
  "gitmoji",
@@ -8541,6 +8542,7 @@ var workspacesFileSchema = object({ workspaces: array(workspaceConfigSchema).opt
8541
8542
  names.add(workspace.name);
8542
8543
  }
8543
8544
  });
8545
+ var mainCheckouts = new Map;
8544
8546
  var runtimeWorkspaceIndexSchema = object({
8545
8547
  workspaces: array(object({ name: nonBlank, glob: nonBlank }).passthrough()).optional()
8546
8548
  }).passthrough();
package/dist/workit.js CHANGED
@@ -3,7 +3,7 @@ import { randomUUID as randomUUID5 } from "node:crypto";
3
3
  import { fileURLToPath as fileURLToPath2 } from "node:url";
4
4
 
5
5
  // packages/workit-core/src/core.ts
6
- import { spawnSync as spawnSync12 } from "node:child_process";
6
+ import { spawnSync as spawnSync14 } from "node:child_process";
7
7
  import { existsSync as existsSync7, realpathSync as realpathSync5 } from "node:fs";
8
8
  import path19 from "node:path";
9
9
 
@@ -13927,73 +13927,8 @@ var exportDigest = (bundle) => sha256({
13927
13927
  // packages/workit-core/src/core/branch.ts
13928
13928
  import { createHash as createHash10 } from "node:crypto";
13929
13929
 
13930
- // packages/workit-core/src/core/git.ts
13931
- import { execFileSync } from "node:child_process";
13932
- var run = (cwd, args) => {
13933
- try {
13934
- const stdout = execFileSync("git", args, {
13935
- cwd,
13936
- encoding: "utf8",
13937
- stdio: ["pipe", "pipe", "pipe"]
13938
- });
13939
- return { stdout: stdout.trimEnd(), stderr: "", exitCode: 0 };
13940
- } catch (error) {
13941
- const e = error;
13942
- return {
13943
- stdout: (e.stdout ?? "").trimEnd(),
13944
- stderr: (e.stderr ?? "").trimEnd(),
13945
- exitCode: e.status ?? 1
13946
- };
13947
- }
13948
- };
13949
- var gitContext = (workspaceRoot, paths = []) => {
13950
- const cwd = workspaceRoot;
13951
- let failure;
13952
- const runHere = (args) => {
13953
- const result = run(cwd, args);
13954
- if (!failure && result.exitCode !== 0) {
13955
- failure = { stderr: result.stderr, exitCode: result.exitCode };
13956
- }
13957
- return result.stdout;
13958
- };
13959
- const branch = runHere(["rev-parse", "--abbrev-ref", "HEAD"]) || "unknown";
13960
- const status_short = runHere(["status", "--porcelain"]);
13961
- const staged = [];
13962
- const unstaged = [];
13963
- const untracked = [];
13964
- for (const line of status_short.split(`
13965
- `).filter(Boolean)) {
13966
- const code = line.slice(0, 2);
13967
- const file = line.slice(3);
13968
- if (code === "??") {
13969
- untracked.push(file);
13970
- } else {
13971
- if (code[0] !== " " && code[0] !== "?")
13972
- staged.push(file);
13973
- if (code[1] !== " " && code[1] !== "?")
13974
- unstaged.push(file);
13975
- }
13976
- }
13977
- const pathArgs = paths.length ? ["--", ...paths] : [];
13978
- const diff_stat = runHere(["diff", "--stat", ...pathArgs]);
13979
- const cached_stat = runHere(["diff", "--cached", "--stat", ...pathArgs]);
13980
- const stagedSet = new Set(staged);
13981
- const unstagedSet = new Set(unstaged);
13982
- const partial_staged = [...stagedSet].filter((f) => unstagedSet.has(f));
13983
- return {
13984
- workspace_root: cwd,
13985
- branch,
13986
- status_short,
13987
- staged,
13988
- unstaged,
13989
- untracked,
13990
- diff_stat: [diff_stat, cached_stat].filter(Boolean).join(`
13991
- `),
13992
- partial_staged: partial_staged.length > 0,
13993
- partial_staged_files: partial_staged,
13994
- ...failure ? { stderr: failure.stderr, exitCode: failure.exitCode } : {}
13995
- };
13996
- };
13930
+ // packages/workit-core/src/core/branch-policy.ts
13931
+ import { spawnSync as spawnSync7 } from "node:child_process";
13997
13932
 
13998
13933
  // packages/workit-core/src/core/config.ts
13999
13934
  import {
@@ -14104,6 +14039,7 @@ var DEFAULTS = {
14104
14039
  },
14105
14040
  commitPolicy: { preset: "conventional" }
14106
14041
  };
14042
+ var unchosenBranchPolicy = new WeakSet([DEFAULTS]);
14107
14043
  var readSafe = (p) => {
14108
14044
  try {
14109
14045
  return readFileSync3(p, "utf8");
@@ -14128,22 +14064,21 @@ var parseConfigResult = (raw, file) => {
14128
14064
  const locale = LOCALE_RE.test(String(input.locale ?? "")) ? input.locale : DEFAULTS.locale;
14129
14065
  const preset = Object.hasOwn(PRESETS, input.branchPolicy?.preset) ? input.branchPolicy?.preset : "gitflow";
14130
14066
  const commitPreset = COMMIT_PRESETS.includes(String(input.commitPolicy?.preset ?? "")) ? input.commitPolicy?.preset : "conventional";
14131
- return {
14132
- status: "valid",
14133
- path: file,
14134
- config: {
14135
- locale,
14136
- localeOptions: Array.isArray(input.localeOptions) ? input.localeOptions : DEFAULTS.localeOptions,
14137
- branchPolicy: mergePreset(preset, {
14138
- allowed: Array.isArray(input.branchPolicy?.allowed) ? input.branchPolicy.allowed : undefined,
14139
- protectedNames: Array.isArray(input.branchPolicy?.protected) ? input.branchPolicy.protected : undefined
14140
- }, DEFAULTS),
14141
- commitPolicy: {
14142
- preset: commitPreset,
14143
- ...typeof input.commitPolicy?.pattern === "string" ? { pattern: input.commitPolicy.pattern } : {}
14144
- }
14067
+ const config = {
14068
+ locale,
14069
+ localeOptions: Array.isArray(input.localeOptions) ? input.localeOptions : DEFAULTS.localeOptions,
14070
+ branchPolicy: mergePreset(preset, {
14071
+ allowed: Array.isArray(input.branchPolicy?.allowed) ? input.branchPolicy.allowed : undefined,
14072
+ protectedNames: Array.isArray(input.branchPolicy?.protected) ? input.branchPolicy.protected : undefined
14073
+ }, DEFAULTS),
14074
+ commitPolicy: {
14075
+ preset: commitPreset,
14076
+ ...typeof input.commitPolicy?.pattern === "string" ? { pattern: input.commitPolicy.pattern } : {}
14145
14077
  }
14146
14078
  };
14079
+ if (!Object.hasOwn(PRESETS, input.branchPolicy?.preset))
14080
+ unchosenBranchPolicy.add(config);
14081
+ return { status: "valid", path: file, config };
14147
14082
  };
14148
14083
  var readConfigTyped = (dir) => {
14149
14084
  const file = path12.join(dir ?? configDir(), "config.json");
@@ -14157,9 +14092,11 @@ var readConfig = () => {
14157
14092
  };
14158
14093
  var vcsConfigPath = () => process.env.WORKFLOW_VCS_CONFIG ?? path12.join(configDir(), "vcs.json");
14159
14094
  var branchGlobPattern = (glob) => new RegExp(`^${glob.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`, "i");
14160
- var resolveBranchPolicy = (config, workspace) => {
14095
+ var resolveBranchPolicy = (config, workspace, repoPreset) => {
14161
14096
  const wp = workspace?.branchPolicy ?? {};
14162
- const preset = Object.hasOwn(PRESETS, wp.preset) ? wp.preset : config.branchPolicy?.preset ?? "gitflow";
14097
+ const workspacePreset = Object.hasOwn(PRESETS, wp.preset);
14098
+ const detected = !workspacePreset && unchosenBranchPolicy.has(config) ? repoPreset?.() ?? null : null;
14099
+ const preset = workspacePreset ? wp.preset : detected ?? config.branchPolicy?.preset ?? "gitflow";
14163
14100
  const merged = mergePreset(preset, {
14164
14101
  allowed: wp.allowed,
14165
14102
  protectedNames: wp.protected
@@ -14168,9 +14105,10 @@ var resolveBranchPolicy = (config, workspace) => {
14168
14105
  return {
14169
14106
  preset,
14170
14107
  allowed,
14171
- protected: new Set(merged.protected.map((p) => p.toLowerCase())),
14108
+ protected: new Set([...merged.protected, ...detected ? PRESETS.gitflow.protected : []].map((p) => p.toLowerCase())),
14172
14109
  integration: wp.integration === "merge" ? "merge" : "pr",
14173
- defaultTargetBranch: preset === "github-flow" ? "main" : preset === "trunk-based" ? "master" : "develop"
14110
+ defaultTargetBranch: preset === "github-flow" ? "main" : preset === "trunk-based" ? "master" : "develop",
14111
+ detected: detected !== null
14174
14112
  };
14175
14113
  };
14176
14114
  var COMMIT_PRESETS = [
@@ -14192,7 +14130,140 @@ var resolveCommitPolicy = (config, workspace) => {
14192
14130
  return config.commitPolicy ?? { preset: "conventional" };
14193
14131
  };
14194
14132
 
14133
+ // packages/workit-core/src/core/branch-policy.ts
14134
+ var PREFIXES = {
14135
+ feature: "feature/*",
14136
+ bugfix: "bugfix/*",
14137
+ release: "release/*",
14138
+ hotfix: "hotfix/*"
14139
+ };
14140
+ var branchNames = (workspaceRoot) => {
14141
+ const r = spawnSync7("git", ["for-each-ref", "--format=%(refname)", "refs/heads", "refs/remotes/origin"], { cwd: workspaceRoot, encoding: "utf8" });
14142
+ if (r.status !== 0)
14143
+ return new Set;
14144
+ return new Set((r.stdout ?? "").split(`
14145
+ `).filter(Boolean).map((ref) => ref.startsWith("refs/heads/") ? ref.slice("refs/heads/".length) : ref.slice("refs/remotes/origin/".length)));
14146
+ };
14147
+ var detectBranchPolicy = (workspaceRoot) => {
14148
+ const names = branchNames(workspaceRoot);
14149
+ const develop = names.has("develop");
14150
+ const main = names.has("main");
14151
+ const master = names.has("master");
14152
+ const root = main ? "main" : master ? "master" : null;
14153
+ if (develop) {
14154
+ return {
14155
+ preset: "gitflow",
14156
+ developBranch: "develop",
14157
+ integration: "merge",
14158
+ protected: root ? [root, "develop"] : ["develop"],
14159
+ allowed: [...PRESETS.gitflow.allowed],
14160
+ prefixes: PREFIXES
14161
+ };
14162
+ }
14163
+ if (root === "main") {
14164
+ return {
14165
+ preset: "github-flow",
14166
+ developBranch: null,
14167
+ integration: "pr",
14168
+ protected: [root],
14169
+ allowed: ["*"],
14170
+ prefixes: PREFIXES
14171
+ };
14172
+ }
14173
+ if (root === "master") {
14174
+ return {
14175
+ preset: "trunk-based",
14176
+ developBranch: null,
14177
+ integration: "pr",
14178
+ protected: [root],
14179
+ allowed: ["*"],
14180
+ prefixes: PREFIXES
14181
+ };
14182
+ }
14183
+ return {
14184
+ preset: "gitflow",
14185
+ developBranch: null,
14186
+ integration: "merge",
14187
+ protected: [],
14188
+ allowed: [],
14189
+ prefixes: PREFIXES
14190
+ };
14191
+ };
14192
+ var repoBranchPreset = (workspaceRoot) => {
14193
+ const detected = detectBranchPolicy(workspaceRoot);
14194
+ return detected.developBranch || detected.allowed.length ? detected.preset : null;
14195
+ };
14196
+
14197
+ // packages/workit-core/src/core/git.ts
14198
+ import { execFileSync } from "node:child_process";
14199
+ var run = (cwd, args) => {
14200
+ try {
14201
+ const stdout = execFileSync("git", args, {
14202
+ cwd,
14203
+ encoding: "utf8",
14204
+ stdio: ["pipe", "pipe", "pipe"]
14205
+ });
14206
+ return { stdout: stdout.trimEnd(), stderr: "", exitCode: 0 };
14207
+ } catch (error) {
14208
+ const e = error;
14209
+ return {
14210
+ stdout: (e.stdout ?? "").trimEnd(),
14211
+ stderr: (e.stderr ?? "").trimEnd(),
14212
+ exitCode: e.status ?? 1
14213
+ };
14214
+ }
14215
+ };
14216
+ var gitContext = (workspaceRoot, paths = []) => {
14217
+ const cwd = workspaceRoot;
14218
+ let failure;
14219
+ const runHere = (args) => {
14220
+ const result = run(cwd, args);
14221
+ if (!failure && result.exitCode !== 0) {
14222
+ failure = { stderr: result.stderr, exitCode: result.exitCode };
14223
+ }
14224
+ return result.stdout;
14225
+ };
14226
+ const branch = runHere(["rev-parse", "--abbrev-ref", "HEAD"]) || "unknown";
14227
+ const status_short = runHere(["status", "--porcelain"]);
14228
+ const staged = [];
14229
+ const unstaged = [];
14230
+ const untracked = [];
14231
+ for (const line of status_short.split(`
14232
+ `).filter(Boolean)) {
14233
+ const code = line.slice(0, 2);
14234
+ const file = line.slice(3);
14235
+ if (code === "??") {
14236
+ untracked.push(file);
14237
+ } else {
14238
+ if (code[0] !== " " && code[0] !== "?")
14239
+ staged.push(file);
14240
+ if (code[1] !== " " && code[1] !== "?")
14241
+ unstaged.push(file);
14242
+ }
14243
+ }
14244
+ const pathArgs = paths.length ? ["--", ...paths] : [];
14245
+ const diff_stat = runHere(["diff", "--stat", ...pathArgs]);
14246
+ const cached_stat = runHere(["diff", "--cached", "--stat", ...pathArgs]);
14247
+ const stagedSet = new Set(staged);
14248
+ const unstagedSet = new Set(unstaged);
14249
+ const partial_staged = [...stagedSet].filter((f) => unstagedSet.has(f));
14250
+ return {
14251
+ workspace_root: cwd,
14252
+ branch,
14253
+ status_short,
14254
+ staged,
14255
+ unstaged,
14256
+ untracked,
14257
+ diff_stat: [diff_stat, cached_stat].filter(Boolean).join(`
14258
+ `),
14259
+ partial_staged: partial_staged.length > 0,
14260
+ partial_staged_files: partial_staged,
14261
+ ...failure ? { stderr: failure.stderr, exitCode: failure.exitCode } : {}
14262
+ };
14263
+ };
14264
+
14195
14265
  // packages/workit-core/src/core/workspaces.ts
14266
+ import { spawnSync as spawnSync8 } from "node:child_process";
14196
14267
  import { createHash as createHash8 } from "node:crypto";
14197
14268
  import { readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
14198
14269
  import path13 from "node:path";
@@ -14437,6 +14508,53 @@ var validateWorkspaceGlob = (glob) => {
14437
14508
  }
14438
14509
  return { ok: true };
14439
14510
  };
14511
+
14512
+ class WorkspaceConfigError extends Error {
14513
+ name = "WorkspaceConfigError";
14514
+ }
14515
+ var mainCheckouts = new Map;
14516
+ var mainCheckoutOf = (cwd) => {
14517
+ const cached = mainCheckouts.get(cwd);
14518
+ if (cached !== undefined)
14519
+ return cached;
14520
+ const env = { ...process.env };
14521
+ for (const name of ["GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR", "GIT_INDEX_FILE"])
14522
+ delete env[name];
14523
+ const git = (args) => {
14524
+ const run = spawnSync8("git", args, {
14525
+ cwd,
14526
+ env,
14527
+ encoding: "utf8",
14528
+ timeout: 5000,
14529
+ windowsHide: true
14530
+ });
14531
+ return run.status === 0 ? run.stdout : null;
14532
+ };
14533
+ let main = null;
14534
+ const dirs = git(["rev-parse", "--path-format=absolute", "--git-dir", "--git-common-dir"]);
14535
+ const [gitDir, common] = (dirs ?? "").trim().split(/\r?\n/u);
14536
+ if (gitDir && common && path13.resolve(gitDir) !== path13.resolve(common)) {
14537
+ const listed = /^worktree (.+)$/mu.exec(git(["worktree", "list", "--porcelain"]) ?? "")?.[1];
14538
+ main = listed?.trim() || (path13.basename(common) === ".git" ? path13.dirname(common) : common);
14539
+ }
14540
+ mainCheckouts.set(cwd, main);
14541
+ return main;
14542
+ };
14543
+ var matchingEntries = (cwd, entries) => {
14544
+ const match = (where) => {
14545
+ const targets = [where, realpathOf(where)].map((value) => value.replaceAll("\\", "/"));
14546
+ return entries.filter((entry) => {
14547
+ const glob = entry.glob.replaceAll("\\", "/");
14548
+ const canonical = canonicalGlob(glob);
14549
+ return targets.some((target) => matchWorkspace(glob, target) || canonical !== glob && matchWorkspace(canonical, target));
14550
+ });
14551
+ };
14552
+ const direct = match(cwd);
14553
+ if (direct.length)
14554
+ return direct;
14555
+ const main = mainCheckoutOf(cwd);
14556
+ return main ? match(main) : direct;
14557
+ };
14440
14558
  var realpathOf = (p) => {
14441
14559
  const real = realpathSync3.native ?? realpathSync3;
14442
14560
  try {
@@ -14461,43 +14579,29 @@ var selectWorkspaceMatch = (matches, cwd, workspaceName) => {
14461
14579
  if (named.length === 1)
14462
14580
  return named[0];
14463
14581
  if (named.length > 1)
14464
- throw new Error(`ambiguous workspace ${JSON.stringify(workspaceName)} for ${cwd}`);
14582
+ throw new WorkspaceConfigError(`ambiguous workspace ${JSON.stringify(workspaceName)} for ${cwd}`);
14465
14583
  if (matches.length > 0) {
14466
- throw new Error(`workspace ${JSON.stringify(workspaceName)} does not match ${cwd}; matching choices: ${matches.map((entry) => entry.name).join(", ")}`);
14584
+ throw new WorkspaceConfigError(`workspace ${JSON.stringify(workspaceName)} does not match ${cwd}; matching choices: ${matches.map((entry) => entry.name).join(", ")}`);
14467
14585
  }
14468
- throw new Error(`workspace ${JSON.stringify(workspaceName)} does not match ${cwd}`);
14586
+ throw new WorkspaceConfigError(`workspace ${JSON.stringify(workspaceName)} does not match ${cwd}`);
14469
14587
  }
14470
14588
  if (matches.length < 2)
14471
14589
  return matches[0];
14472
14590
  const highestSpecificity = Math.max(...matches.map((entry) => globSpecificity(entry.glob)));
14473
14591
  const mostSpecific = matches.filter((entry) => globSpecificity(entry.glob) === highestSpecificity);
14474
14592
  if (mostSpecific.length > 1) {
14475
- throw new Error(`ambiguous workspace for ${cwd}; choose one of: ${mostSpecific.map((entry) => entry.name).join(", ")}`);
14593
+ throw new WorkspaceConfigError(`ambiguous workspace for ${cwd}; choose one of: ${mostSpecific.map((entry) => entry.name).join(", ")}`);
14476
14594
  }
14477
14595
  return mostSpecific[0];
14478
14596
  };
14479
14597
  var resolveWorkspaceFromEntries = (cwd, entries, workspaceName) => {
14480
- const targets = [cwd, realpathOf(cwd)].map((p) => p.replaceAll("\\", "/"));
14481
- const matches = [];
14482
- for (const ws of entries) {
14483
- const glob = ws.glob.replaceAll("\\", "/");
14484
- const canonical = canonicalGlob(glob);
14485
- let matched = false;
14486
- for (const target of targets) {
14487
- if (matchWorkspace(glob, target) || canonical !== glob && matchWorkspace(canonical, target)) {
14488
- matched = true;
14489
- break;
14490
- }
14491
- }
14492
- if (matched)
14493
- matches.push(ws);
14494
- }
14598
+ const matches = matchingEntries(cwd, entries);
14495
14599
  return selectWorkspaceMatch(matches, cwd, workspaceName) ?? null;
14496
14600
  };
14497
14601
  var resolveWorkspaceFrom = (cwd, dir, workspaceName) => {
14498
14602
  const result = readWorkspacesResult(dir);
14499
14603
  if (result.status === "malformed" || result.status === "invalid")
14500
- throw new Error(result.error);
14604
+ throw new WorkspaceConfigError(result.error);
14501
14605
  return resolveWorkspaceFromEntries(cwd, result.entries, workspaceName);
14502
14606
  };
14503
14607
  var runtimeWorkspacePolicySchema = (kind) => {
@@ -14529,31 +14633,26 @@ var matchRuntimeWorkspace = (cwd) => {
14529
14633
  } catch (error) {
14530
14634
  if (error.code === "ENOENT")
14531
14635
  return null;
14532
- throw new Error(`${file} could not be read: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
14636
+ throw new WorkspaceConfigError(`${file} could not be read: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
14533
14637
  }
14534
14638
  let parsed;
14535
14639
  try {
14536
14640
  parsed = JSON.parse(raw);
14537
14641
  } catch {
14538
- throw new Error(`${file} is not valid JSON`);
14642
+ throw new WorkspaceConfigError(`${file} is not valid JSON`);
14539
14643
  }
14540
14644
  const validated = runtimeWorkspaceIndexSchema.safeParse(parsed);
14541
14645
  if (!validated.success) {
14542
14646
  const detail = validated.error.issues.map((issue) => `${issue.path.map(String).join(".") || "workspaces"}: ${issue.message}`).join("; ");
14543
- throw new Error(`${file} has invalid workspace matching data: ${detail}`);
14647
+ throw new WorkspaceConfigError(`${file} has invalid workspace matching data: ${detail}`);
14544
14648
  }
14545
14649
  const entries = validated.data.workspaces;
14546
14650
  for (const entry of entries ?? []) {
14547
14651
  const glob = validateWorkspaceGlob(entry.glob);
14548
14652
  if (!glob.ok)
14549
- throw new Error(`${file} workspace ${entry.name}: ${glob.error}`);
14653
+ throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
14550
14654
  }
14551
- const targets = [cwd, realpathOf(cwd)].map((value) => value.replaceAll("\\", "/"));
14552
- const matches = (entries ?? []).filter((entry) => {
14553
- const glob = entry.glob.replaceAll("\\", "/");
14554
- const canonical = canonicalGlob(glob);
14555
- return targets.some((target) => matchWorkspace(glob, target) || canonical !== glob && matchWorkspace(canonical, target));
14556
- });
14655
+ const matches = matchingEntries(cwd, entries ?? []);
14557
14656
  const workspaceName = process.env.WORKFLOW_WORKSPACE_NAME?.trim() || undefined;
14558
14657
  const selected = selectWorkspaceMatch(matches, cwd, workspaceName);
14559
14658
  return selected ? { file, selected } : null;
@@ -14570,7 +14669,7 @@ var resolveRuntimeWorkspaceCandidate = (cwd, kind) => {
14570
14669
  const policy = runtimeWorkspacePolicySchema(kind).safeParse(selected);
14571
14670
  if (!policy.success) {
14572
14671
  const detail = policy.error.issues.map((issue) => `${issue.path.map(String).join(".") || "workspace"}: ${issue.message}`).join("; ");
14573
- throw new Error(`${file} has invalid ${kind} policy configuration: ${detail}`);
14672
+ throw new WorkspaceConfigError(`${file} has invalid ${kind} policy configuration: ${detail}`);
14574
14673
  }
14575
14674
  return policy.data;
14576
14675
  };
@@ -14581,10 +14680,10 @@ var resolveRuntimeWorkspacePolicy = (cwd, kind, requestedProfile) => {
14581
14680
  const key = kind === "branch" ? "branchPolicy" : "commitPolicy";
14582
14681
  const profileName = requestedProfile?.trim() || candidate.defaultProfile;
14583
14682
  if (candidate.defaultProfile && !Object.hasOwn(candidate.profiles ?? {}, candidate.defaultProfile))
14584
- throw new Error(`workspace ${JSON.stringify(candidate.name)} has no profile ${JSON.stringify(candidate.defaultProfile)}`);
14683
+ throw new WorkspaceConfigError(`workspace ${JSON.stringify(candidate.name)} has no profile ${JSON.stringify(candidate.defaultProfile)}`);
14585
14684
  const profile = profileName ? candidate.profiles?.[profileName] : undefined;
14586
14685
  if (profileName && !profile)
14587
- throw new Error(`workspace ${JSON.stringify(candidate.name)} has no profile ${JSON.stringify(profileName)}`);
14686
+ throw new WorkspaceConfigError(`workspace ${JSON.stringify(candidate.name)} has no profile ${JSON.stringify(profileName)}`);
14588
14687
  const profilePolicy = profile?.[key];
14589
14688
  const workspacePolicy = candidate[key];
14590
14689
  return {
@@ -14597,18 +14696,18 @@ function workspaceDefaultTarget(cwd, globalDefault) {
14597
14696
  const wp = ws?.branchPolicy ?? {};
14598
14697
  const hasWorkspacePolicy = typeof wp.preset === "string" && Object.hasOwn(PRESETS, wp.preset);
14599
14698
  const selected = resolveRuntimeWorkspacePolicy(cwd, "branch", process.env.WORKFLOW_PROFILE?.trim() || undefined);
14600
- const policyDefault = resolveBranchPolicy(readConfig(), selected.policy ? { branchPolicy: selected.policy } : null).defaultTargetBranch;
14699
+ const policyDefault = resolveBranchPolicy(readConfig(), selected.policy ? { branchPolicy: selected.policy } : null, () => repoBranchPreset(cwd)).defaultTargetBranch;
14601
14700
  return String(ws?.vcs?.defaultTargetBranch ?? (hasWorkspacePolicy ? policyDefault : globalDefault ?? policyDefault) ?? "develop");
14602
14701
  }
14603
14702
 
14604
14703
  // packages/workit-core/src/core/vcs-config.ts
14605
14704
  import fs12 from "node:fs";
14606
14705
  import path14 from "node:path";
14607
- import { spawnSync as spawnSync8 } from "node:child_process";
14706
+ import { spawnSync as spawnSync10 } from "node:child_process";
14608
14707
 
14609
14708
  // packages/workit-core/src/core/release-tracks.ts
14610
14709
  import { createHash as createHash9 } from "node:crypto";
14611
- import { spawnSync as spawnSync7 } from "node:child_process";
14710
+ import { spawnSync as spawnSync9 } from "node:child_process";
14612
14711
  class ReleaseTrackError extends Error {
14613
14712
  }
14614
14713
  var KNOWN_FIELDS = new Set([
@@ -14893,7 +14992,7 @@ function resolveReleaseTrack(input) {
14893
14992
  return fallback(`${branch} has the same or unrelated fork points with ${[...new Set(newest.map((fork) => `${fork.ref} (${fork.track.name === IMPLICIT ? "workspace default" : fork.track.name})`))].join(" and ")}`);
14894
14993
  }
14895
14994
  var git4 = (cwd, args) => {
14896
- const run = spawnSync7("git", args, {
14995
+ const run = spawnSync9("git", args, {
14897
14996
  cwd,
14898
14997
  encoding: "utf8",
14899
14998
  timeout: 20000,
@@ -15008,7 +15107,7 @@ function resolveTrackFor(cwd, options) {
15008
15107
  var workspacesPath = () => path14.join(configDir(), "workspaces.json");
15009
15108
  var vcsCwd = (cwd) => cwd ?? process.env.WORKFLOW_WORKSPACE_ROOT ?? process.cwd();
15010
15109
  var remoteProvider = (cwd) => {
15011
- const r = spawnSync8("git", ["remote", "get-url", "origin"], { cwd, encoding: "utf8" });
15110
+ const r = spawnSync10("git", ["remote", "get-url", "origin"], { cwd, encoding: "utf8" });
15012
15111
  if (r.status !== 0)
15013
15112
  return null;
15014
15113
  const url = (r.stdout ?? "").trim();
@@ -15045,7 +15144,7 @@ var remoteEndpoint = (remote) => {
15045
15144
  var configuredSshEndpoint = (host) => {
15046
15145
  if (host.startsWith("-"))
15047
15146
  return null;
15048
- const resolved = spawnSync8("ssh", ["-G", host], {
15147
+ const resolved = spawnSync10("ssh", ["-G", host], {
15049
15148
  encoding: "utf8",
15050
15149
  timeout: 5000,
15051
15150
  maxBuffer: 1024 * 1024,
@@ -15218,7 +15317,7 @@ function mergedPrStyle(limit = 6, cwd) {
15218
15317
  `).filter((l) => l.startsWith("## ")).map((l) => l.trim()),
15219
15318
  descriptionPreview: desc.slice(0, 600)
15220
15319
  });
15221
- const remoteResult = spawnSync8("git", ["remote", "get-url", "--push", "--all", "origin"], {
15320
+ const remoteResult = spawnSync10("git", ["remote", "get-url", "--push", "--all", "origin"], {
15222
15321
  cwd,
15223
15322
  encoding: "utf8"
15224
15323
  });
@@ -15234,7 +15333,7 @@ function mergedPrStyle(limit = 6, cwd) {
15234
15333
  if (!hostingApiHostMatches(remote, host))
15235
15334
  return { ok: false, error: "PR style target does not match the provider host" };
15236
15335
  if (provider === "gitlab") {
15237
- const run = (args) => spawnSync8("glab", ["api", ...args], {
15336
+ const run = (args) => spawnSync10("glab", ["api", ...args], {
15238
15337
  cwd,
15239
15338
  encoding: "utf8",
15240
15339
  env
@@ -15254,7 +15353,7 @@ function mergedPrStyle(limit = 6, cwd) {
15254
15353
  });
15255
15354
  }
15256
15355
  } else if (provider === "github") {
15257
- const r = spawnSync8("gh", [
15356
+ const r = spawnSync10("gh", [
15258
15357
  "pr",
15259
15358
  "list",
15260
15359
  "--repo",
@@ -15315,7 +15414,7 @@ function effectiveWorkspacePolicy(workspaceRoot, kind, profileName) {
15315
15414
  const selected = resolveRuntimeWorkspacePolicy(workspaceRoot, kind, profileName?.trim() || process.env.WORKFLOW_PROFILE?.trim() || undefined);
15316
15415
  const config = readConfig();
15317
15416
  return kind === "branch" ? {
15318
- branchPolicy: withReleaseTracks(workspaceRoot, resolveBranchPolicy(config, selected.policy ? { branchPolicy: selected.policy } : null)),
15417
+ branchPolicy: withReleaseTracks(workspaceRoot, resolveBranchPolicy(config, selected.policy ? { branchPolicy: selected.policy } : null, () => repoBranchPreset(workspaceRoot))),
15319
15418
  provenance: { branchPolicy: selected.source }
15320
15419
  } : {
15321
15420
  commitPolicy: resolveCommitPolicy(config, selected.policy ? { commitPolicy: selected.policy } : null),
@@ -17300,7 +17399,7 @@ class WorkitCore {
17300
17399
  }
17301
17400
  }
17302
17401
  // packages/workit-core/src/core/repo-context.ts
17303
- import { spawnSync as spawnSync9 } from "node:child_process";
17402
+ import { spawnSync as spawnSync11 } from "node:child_process";
17304
17403
  import { existsSync as existsSync6, readFileSync as readFileSync5, readdirSync as readdirSync4 } from "node:fs";
17305
17404
  import path16 from "node:path";
17306
17405
  var isSafeContextRange = (value) => value.length <= 4096 && (() => {
@@ -17329,7 +17428,7 @@ var invalidRange = (cwd) => ({
17329
17428
  cwd
17330
17429
  });
17331
17430
  var runGit = (cwd, args) => {
17332
- const result = spawnSync9("git", args, { cwd, encoding: "utf8" });
17431
+ const result = spawnSync11("git", args, { cwd, encoding: "utf8" });
17333
17432
  return {
17334
17433
  stdout: (result.stdout ?? "").trimEnd(),
17335
17434
  stderr: (result.stderr ?? "").trimEnd(),
@@ -17770,12 +17869,12 @@ function releaseNotesContext(root, rangeOrTag) {
17770
17869
  }
17771
17870
 
17772
17871
  // packages/workit-core/src/core/tracker-issues.ts
17773
- import { spawnSync as spawnSync11 } from "node:child_process";
17872
+ import { spawnSync as spawnSync13 } from "node:child_process";
17774
17873
 
17775
17874
  // packages/workit-core/src/core/pr-create.ts
17776
17875
  import fs13 from "node:fs";
17777
17876
  import path17 from "node:path";
17778
- import { spawnSync as spawnSync10 } from "node:child_process";
17877
+ import { spawnSync as spawnSync12 } from "node:child_process";
17779
17878
  // packages/workit-core/src/forge/pr-body.ts
17780
17879
  function parseGhIssue(value) {
17781
17880
  const m = /issues\/(\d+)/.exec(value);
@@ -17800,7 +17899,7 @@ function whichOnPath(tool) {
17800
17899
  }
17801
17900
  var hostingCliAvailable = (provider) => whichOnPath(provider === "gitlab" ? "glab" : "gh") !== null;
17802
17901
  var pushRemote = (cwd) => {
17803
- const result = spawnSync10("git", ["remote", "get-url", "--push", "--all", "origin"], {
17902
+ const result = spawnSync12("git", ["remote", "get-url", "--push", "--all", "origin"], {
17804
17903
  cwd,
17805
17904
  encoding: "utf8"
17806
17905
  });
@@ -17831,7 +17930,7 @@ var defaultCli = (bin, available) => {
17831
17930
  if (!available)
17832
17931
  return null;
17833
17932
  return (args, root) => {
17834
- const out = spawnSync11(bin, args, {
17933
+ const out = spawnSync13(bin, args, {
17835
17934
  cwd: root,
17836
17935
  encoding: "utf8",
17837
17936
  env: { ...process.env, PATH: process.env.PATH ?? "" }
@@ -18364,7 +18463,7 @@ function resolveInside(root, candidate) {
18364
18463
  }
18365
18464
  function run2(root, executable, args, env = {}) {
18366
18465
  const cwd = realpathSync5(root);
18367
- const result = spawnSync12(executable, args, {
18466
+ const result = spawnSync14(executable, args, {
18368
18467
  cwd,
18369
18468
  encoding: "utf8",
18370
18469
  env: { ...process.env, ...env }
@@ -18665,11 +18764,11 @@ var segmentsOf = (command) => {
18665
18764
  flushSegment();
18666
18765
  return segments;
18667
18766
  };
18668
- var PREFIXES = new Set(["sudo", "command", "env", "nohup", "time", "exec", "xargs"]);
18767
+ var PREFIXES2 = new Set(["sudo", "command", "env", "nohup", "time", "exec", "xargs"]);
18669
18768
  var operands = (words) => words.filter((item) => !item.startsWith("-"));
18670
18769
  var editsOf = (input) => {
18671
18770
  let words = input;
18672
- while (words.length && (PREFIXES.has(words[0]) || /^\w+=/.test(words[0])))
18771
+ while (words.length && (PREFIXES2.has(words[0]) || /^\w+=/.test(words[0])))
18673
18772
  words = words.slice(1);
18674
18773
  const [verb, ...args] = words;
18675
18774
  const name = (verb?.split(/[\\/]/).at(-1) ?? "").toLowerCase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brainervirus/workit-pi",
3
- "version": "8.0.1",
3
+ "version": "8.1.1",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",