@workit-dev/opencode 2.27.13 → 2.29.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.
Files changed (2) hide show
  1. package/dist/plugin.js +67 -25
  2. package/package.json +2 -2
package/dist/plugin.js CHANGED
@@ -8712,7 +8712,8 @@ var workspaceBranchPolicySchema = strictObject({
8712
8712
  })),
8713
8713
  allowed: optional(array(nonBlank)),
8714
8714
  protected: optional(array(nonBlank)),
8715
- integration: optional(_enum(["pr", "merge"]))
8715
+ integration: optional(_enum(["pr", "merge"])),
8716
+ releaseTagPrefix: optional(string2())
8716
8717
  });
8717
8718
  var workspaceCommitPolicySchema = strictObject({
8718
8719
  preset: commitPreset,
@@ -8802,7 +8803,7 @@ var workspaceConfigSchema = looseObject({
8802
8803
  })),
8803
8804
  models: optional(looseObject({ roles: modelRoles })),
8804
8805
  resources: optional(unknown()),
8805
- remotes: optional(array(nonBlank.check(refine((pattern) => remotePattern(pattern) !== null, "is not a remote URL (https://host/owner/repo, git@host:owner/repo, a path, or owner/*)")))),
8806
+ remotes: optional(array(nonBlank.check(refine((pattern) => isRemotePattern(pattern), "is not a remote URL (https://host/owner/repo, git@host:owner/repo, a path, or owner/*)")))),
8806
8807
  externalRepos: optional(array(nonBlank.check(_regex(/^[\w-]+(?:\/\w[\w.-]*)*\/(?:\w[\w.-]*|\*)$/u, "is owner/name, group/project or owner/* on the checkout's forge host, without the host")))),
8807
8808
  additiveRiskPaths: optional(array(nonBlank)),
8808
8809
  autonomy: optional(looseObject(Object.fromEntries(["push", "pr", "merge", "release", "rerun"].map((kind) => [
@@ -8829,7 +8830,9 @@ var workspaceConfigSchema = looseObject({
8829
8830
  defaultProfile: optional(nonBlank),
8830
8831
  profiles: optional(record(nonBlank, workspaceProfileSchema)),
8831
8832
  releaseTracks: optional(record(nonBlank, releaseTrackSchema)),
8832
- releasePackages: optional(unknown())
8833
+ releasePackages: optional(unknown()),
8834
+ releaseTagPrefix: optional(string2()),
8835
+ trunkCi: optional(unknown())
8833
8836
  }).check(superRefine((workspace, context) => {
8834
8837
  if (workspace.defaultProfile !== undefined && !Object.hasOwn(workspace.profiles ?? {}, workspace.defaultProfile)) {
8835
8838
  context.addIssue({
@@ -9170,6 +9173,7 @@ var canonicalGlob = (glob) => {
9170
9173
  return real + (prefix.endsWith("/") ? "/" : "") + rest;
9171
9174
  };
9172
9175
  var globSpecificity = (glob) => glob.replaceAll("\\", "/").split("/").filter((segment) => segment.length > 0 && !/[*?[\]{]/.test(segment)).length;
9176
+ var workspaceMatches = (cwd, entries) => matchingEntries(cwd, entries);
9173
9177
  var selectWorkspaceMatch = (matches, cwd, workspaceName) => {
9174
9178
  if (workspaceName !== undefined) {
9175
9179
  const named = matches.filter((entry) => entry.name === workspaceName);
@@ -9191,15 +9195,32 @@ var selectWorkspaceMatch = (matches, cwd, workspaceName) => {
9191
9195
  }
9192
9196
  return mostSpecific[0];
9193
9197
  };
9194
- var resolveWorkspaceFromEntries = (cwd, entries, workspaceName) => {
9195
- const matches = matchingEntries(cwd, entries);
9196
- return selectWorkspaceMatch(matches, cwd, workspaceName) ?? null;
9197
- };
9198
- var resolveWorkspaceFrom = (cwd, dir, workspaceName) => {
9198
+ var HOSTLESS_REMOTE = /^[\w-]+\/\*$/u;
9199
+ var expandRemotePattern = (entry, pattern) => {
9200
+ if (!HOSTLESS_REMOTE.test(pattern.trim()))
9201
+ return pattern;
9202
+ const vcs = entry.vcs ?? {};
9203
+ const host = typeof vcs.host === "string" && vcs.host.trim().replace(/^https?:\/\/|\/.*$/giu, "") || `${vcs.provider === "gitlab" ? "gitlab" : "github"}.com`;
9204
+ return `https://${host}/${pattern.trim()}`;
9205
+ };
9206
+ var isRemotePattern = (pattern) => !!remotePattern(expandRemotePattern({}, pattern));
9207
+ var remoteClaimOf = (entry, key, exact = false) => (Array.isArray(entry.remotes) ? entry.remotes : []).find((pattern) => typeof pattern === "string" && !(exact && pattern.trim().endsWith("/*")) && remoteMatches(expandRemotePattern(entry, pattern), key));
9208
+ var resolveWorkspaceFromEntries = (cwd, entries, workspaceName, remotes) => {
9209
+ const globbed = matchingEntries(cwd, entries);
9210
+ const listed = !remotes || globbed.length || !entries.some((entry) => entry.remotes) ? [] : checkoutRemotes(cwd);
9211
+ const origin = listed instanceof Error ? [] : listed.filter((item) => item.name === "origin");
9212
+ const hits = entries.filter((entry) => origin.length && origin.every((item) => remoteClaimOf(entry, item.key)));
9213
+ const exact = hits.filter((entry) => origin.every((item) => remoteClaimOf(entry, item.key, true)));
9214
+ const ranked = exact.length ? exact : hits;
9215
+ if (workspaceName === undefined && ranked.length > 1)
9216
+ return null;
9217
+ return selectWorkspaceMatch(hits.length ? workspaceName ? hits : ranked : globbed, cwd, workspaceName) ?? null;
9218
+ };
9219
+ var resolveWorkspaceFrom = (cwd, dir, workspaceName, remotes) => {
9199
9220
  const result = readWorkspacesResult(dir);
9200
9221
  if (result.status === "malformed" || result.status === "invalid")
9201
9222
  throw new WorkspaceConfigError(result.error);
9202
- return resolveWorkspaceFromEntries(cwd, result.entries, workspaceName);
9223
+ return resolveWorkspaceFromEntries(cwd, result.entries, workspaceName, remotes);
9203
9224
  };
9204
9225
  var runtimeWorkspacePolicySchema = (kind) => {
9205
9226
  const key = kind === "branch" ? "branchPolicy" : kind === "commit" ? "commitPolicy" : "vcs";
@@ -9249,10 +9270,12 @@ var matchRuntimeWorkspace = (cwd, dir = configDir2()) => {
9249
9270
  if (!glob.ok)
9250
9271
  throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
9251
9272
  }
9252
- const matches = matchingEntries(cwd, entries ?? []);
9253
9273
  const workspaceName = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
9254
- const selected = selectWorkspaceMatch(matches, cwd, workspaceName);
9255
- return selected ? { file, selected, matches } : null;
9274
+ const selected = resolveWorkspaceFromEntries(cwd, entries ?? [], workspaceName, true);
9275
+ if (!selected)
9276
+ return null;
9277
+ const matches = matchingEntries(cwd, entries ?? []);
9278
+ return { file, selected, matches: matches.length ? matches : [selected] };
9256
9279
  };
9257
9280
  var resolveRuntimeReleaseTracks = (cwd) => {
9258
9281
  const matched = matchRuntimeWorkspace(cwd);
@@ -19278,6 +19301,7 @@ function ytrackReadiness(run, host) {
19278
19301
  }
19279
19302
 
19280
19303
  // packages/workit-core/src/autonomy.ts
19304
+ var resolveWorkspaceFrom2 = (cwd, dir, name) => resolveWorkspaceFrom(cwd, dir, name, true);
19281
19305
  var accountHomeDir = () => {
19282
19306
  const home = grantsHome.resolve();
19283
19307
  return home === null ? null : configDir({ HOME: home });
@@ -19310,11 +19334,11 @@ var accountUnread = () => {
19310
19334
  };
19311
19335
  var entriesIn = (dir) => dir === null ? [] : loadWorkspacesFrom(dir);
19312
19336
  var fileSource = (dir = accountDir()) => ({
19313
- resolve: (cwd, name) => dir === null ? null : resolveWorkspaceFrom(cwd, dir, name),
19337
+ resolve: (cwd, name) => dir === null ? null : resolveWorkspaceFrom2(cwd, dir, name),
19314
19338
  entries: () => entriesIn(dir)
19315
19339
  });
19316
19340
  var sealedSource = (entries) => ({
19317
- resolve: (cwd, name) => resolveWorkspaceFromEntries(cwd, entries, name),
19341
+ resolve: (cwd, name) => resolveWorkspaceFromEntries(cwd, entries, name, true),
19318
19342
  entries: () => entries
19319
19343
  });
19320
19344
  var sealOf = () => {
@@ -19340,8 +19364,8 @@ var youTrackWritesPolicy = (cwd) => {
19340
19364
  return ASK;
19341
19365
  const auto = (entry) => youtrackOf(entry)?.writes === "auto";
19342
19366
  const name = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
19343
- const named = resolveWorkspaceFrom(cwd, dir, name);
19344
- const folder = name ? resolveWorkspaceFrom(cwd, dir) : named;
19367
+ const named = resolveWorkspaceFrom2(cwd, dir, name);
19368
+ const folder = name ? resolveWorkspaceFrom2(cwd, dir) : named;
19345
19369
  if (!auto(named) || !auto(folder))
19346
19370
  return ASK;
19347
19371
  const [a, b] = [autoHostsOf(named), autoHostsOf(folder)];
@@ -19596,7 +19620,8 @@ function resolveWith(source, cwd, world, target) {
19596
19620
  const above = checkoutsAbove(cwd);
19597
19621
  for (const where of above instanceof Error ? [above] : above)
19598
19622
  autonomy = capAt(source, autonomy, where, where instanceof Error ? "git" : `checkout ${where}`, "a worktree or submodule never exceeds it", true);
19599
- return capAtRemotes(source, autonomy, cwd, target);
19623
+ const own = real && workspaceMatches(cwd, source.entries()).length === 0 ? real : undefined;
19624
+ return capAtRemotes(source, autonomy, cwd, target, own);
19600
19625
  }
19601
19626
  var needsAccount = (autonomy) => autonomy.configured.length > 0 && !autonomy.accountConfigured;
19602
19627
  function stricter(current, sealed, note, unblock) {
@@ -19635,17 +19660,31 @@ function stricter(current, sealed, note, unblock) {
19635
19660
  note: current.note ? `${current.note}; ${note}` : note
19636
19661
  };
19637
19662
  }
19638
- function capAtRemotes(source, autonomy, cwd, target) {
19663
+ function capAtRemotes(source, autonomy, cwd, target, own) {
19639
19664
  const claiming = source.entries().filter((entry) => entry.remotes?.length);
19640
19665
  if (claiming.length === 0)
19641
19666
  return autonomy;
19642
19667
  const remotes = target === undefined ? checkoutRemotes(cwd) : typeof target === "function" ? target() : target;
19643
19668
  if (remotes instanceof Error)
19644
19669
  return capAt(source, autonomy, remotes, target === undefined ? "git" : "target", "a target that cannot be resolved never raises grants");
19670
+ const listed = Array.isArray(remotes) ? remotes : remotes.remotes;
19671
+ const capped = own ? capAtOwnClaim(source, autonomy, cwd, own, target && listed) : autonomy;
19672
+ return capAtClaims(source, capped, listed, claiming);
19673
+ }
19674
+ function capAtOwnClaim(source, autonomy, cwd, own, judged) {
19675
+ const push = judged ? { remotes: judged } : pushTarget(cwd, pushRemoteName(cwd) ?? "");
19676
+ if (push instanceof Error)
19677
+ return capAt(source, autonomy, push, "push target", "a target that cannot be resolved never raises grants");
19678
+ const unclaimed = push.remotes.filter((remote) => !remoteClaimOf(own, remote.key));
19679
+ if (unclaimed.length === 0 && push.remotes.length > 0)
19680
+ return autonomy;
19681
+ return stricter(autonomy, autonomyOf(null), `${unclaimed.map((remote) => `remote ${remote.name} ${remote.url}`).join(", ") || "no target"}: not in workspace ${own.name}'s remotes, which matched this checkout by its origin; grants capped at the defaults`, `ask the user to add that repository to workspace ${own.name}'s remotes, in their own terminal: workit workspace set ${own.name} remotes=<patterns>`);
19682
+ }
19683
+ function capAtClaims(source, autonomy, listed, claiming) {
19645
19684
  let capped = autonomy;
19646
- for (const remote of Array.isArray(remotes) ? remotes : remotes.remotes)
19685
+ for (const remote of listed)
19647
19686
  for (const entry of claiming) {
19648
- const pattern = entry.remotes.find((item) => remoteMatches(item, remote.key));
19687
+ const pattern = remoteClaimOf(entry, remote.key);
19649
19688
  if (pattern)
19650
19689
  capped = capAt(source, capped, { entry }, `remote ${remote.name} ${remote.url} (workspace ${entry.name} claims ${pattern})`, "a checkout never exceeds the workspace that owns its remote");
19651
19690
  }
@@ -19673,7 +19712,7 @@ function claimsIn(target, entries) {
19673
19712
  return target;
19674
19713
  const claiming = entries.filter((entry) => entry.remotes?.length);
19675
19714
  return target.remotes.flatMap((remote) => claiming.flatMap((entry) => {
19676
- const pattern = entry.remotes.find((item) => remoteMatches(item, remote.key));
19715
+ const pattern = remoteClaimOf(entry, remote.key);
19677
19716
  return pattern ? [{ url: remote.url, workspace: entry.name, pattern }] : [];
19678
19717
  }));
19679
19718
  }
@@ -25735,7 +25774,8 @@ var pushTargetIsStable = (cwd, remote) => {
25735
25774
  if (result.status !== 0 && result.status !== 1)
25736
25775
  return false;
25737
25776
  const prefixes = (result.stdout ?? "").split(/\r?\n/u).map((line) => line.trim().slice(line.trim().indexOf(" ") + 1)).filter(Boolean);
25738
- return !prefixes.some((prefix) => target.startsWith(prefix));
25777
+ const raw = remote.trim();
25778
+ return !prefixes.some((prefix) => target.startsWith(prefix) || raw.startsWith(prefix));
25739
25779
  };
25740
25780
 
25741
25781
  // packages/workit-core/src/core/tracker-issues.ts
@@ -32549,7 +32589,8 @@ function pushPreflight(cwd, options = {}) {
32549
32589
  const branch = options.branch ?? currentBranch(cwd);
32550
32590
  if (!branch)
32551
32591
  return failure3("invalid_input", "HEAD is detached; push a branch");
32552
- if (isProtectedTarget(cwd, branch))
32592
+ const protectedBranch = isProtectedTarget(cwd, branch);
32593
+ if (protectedBranch && !options.initial)
32553
32594
  return failure3("blocked", `protected_branch: ${branch} is protected by the workspace branch policy; workit git push never pushes to it`, releaseBranch(cwd, branch) ? `workit git push --release ${branch} # finishing a release or hotfix; needs the release grant` : "workit git branch <feature/name> # push a feature branch and open a PR");
32554
32595
  const sha = resolveRef(cwd, `refs/heads/${branch}`);
32555
32596
  if (!sha)
@@ -32562,7 +32603,7 @@ function pushPreflight(cwd, options = {}) {
32562
32603
  return failure3("blocked", `remote "${remote}" has no single push URL`, `git remote get-url --push --all ${remote} # keep exactly one push URL`);
32563
32604
  const parsed = parseRemoteUrl(raw);
32564
32605
  const local = parsed?.protocol === "file";
32565
- if (!local && !pushTargetIsStable(cwd, raw))
32606
+ if ((!local || protectedBranch) && !pushTargetIsStable(cwd, raw))
32566
32607
  return failure3("blocked", `push_target_rewritten: the push URL of "${remote}" is rewritten by a url.*.insteadOf rule, so the destination is not the one checked`, "git config --get-regexp '^url\\.' # remove the rewrite for this remote");
32567
32608
  return success2({
32568
32609
  branch,
@@ -32570,7 +32611,8 @@ function pushPreflight(cwd, options = {}) {
32570
32611
  remote,
32571
32612
  url: redactRemote(raw),
32572
32613
  rawUrl: raw,
32573
- local
32614
+ local,
32615
+ ...protectedBranch ? { initial: true } : {}
32574
32616
  });
32575
32617
  }
32576
32618
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/opencode",
3
- "version": "2.27.13",
3
+ "version": "2.29.0",
4
4
  "private": false,
5
5
  "description": "Workit OpenCode plugin — native tools, adaptive policy, and sixteen method skills",
6
6
  "keywords": [
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "devDependencies": {
43
43
  "@opencode/plugin": "2.3.2",
44
- "@workit-dev/core": "^2.27.13"
44
+ "@workit-dev/core": "^2.29.0"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=24"