@r-33/opencode 0.5.0 → 0.5.1-rc.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.
package/README.md CHANGED
@@ -98,6 +98,10 @@ folder never changes who this one bills for. Keys are short-lived and rotate
98
98
  automatically; nothing secret is ever written to your project, logs, or
99
99
  terminal.
100
100
 
101
+ Outside a Git repository a folder has no budget of its own: `/connect`
102
+ offers your personal key, and that one choice covers every such folder on
103
+ this machine.
104
+
101
105
  ## Session cost
102
106
 
103
107
  The cost OpenCode shows for a session on a route_33 model is an estimate
@@ -131,7 +135,6 @@ wizard.
131
135
  | ------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------- |
132
136
  | No route_33 models after start | `/connect` → Route 33 — the silent sign-in expired; sign in once and they return |
133
137
  | "This Route 33 build has no OAuth client id" | Update the plugin to a released build, or set `ROUTE33_CLIENT_ID` and restart |
134
- | "To assign a Route 33 budget, open a Git repository." | Open a Git repository (or `git init`) in the folder, then connect again |
135
138
  | Sign-in link never appears / SSH-only machine | Sign-in needs a browser on the same machine — there is no device-flow fallback |
136
139
  | "Route 33 — key not created" (OpenCode v2) | The dialog gives Route 33's reason, such as a cap above your allowance — change the answer and confirm again |
137
140
  | "Choosing individual models needs a fresh Route 33 sign-in." | A personal budget lists its models only for a sign-in that carries the `models:read` permission; the next browser sign-in adds it |
@@ -90,6 +90,12 @@ var parseManagementSubject = (credential) => {
90
90
  return subject;
91
91
  };
92
92
 
93
+ // src/cli/read-env-client-id/read-env-client-id.ts
94
+ var readEnvClientId = (env = process.env) => {
95
+ const value = env["ROUTE33_CLIENT_ID"]?.trim();
96
+ return value === "" ? void 0 : value;
97
+ };
98
+
93
99
  // src/attribution/read-legacy-key/read-legacy-key.ts
94
100
  import * as path from "node:path";
95
101
  var LEGACY_KEY_RELATIVE_PATH = path.join(".opencode", "route33.key");
@@ -1646,12 +1652,6 @@ var createLiveProductionSmokePlan = (options) => {
1646
1652
  };
1647
1653
  };
1648
1654
 
1649
- // src/cli/read-env-client-id/read-env-client-id.ts
1650
- var readEnvClientId = (env = process.env) => {
1651
- const value = env["ROUTE33_CLIENT_ID"]?.trim();
1652
- return value === "" ? void 0 : value;
1653
- };
1654
-
1655
1655
  // src/cli/production-smoke/production-smoke.ts
1656
1656
  var productionSmokeClientId = readEnvClientId() ?? DEFAULT_ROUTE33_CLIENT_ID;
1657
1657
  var ProductionSmoke = class {
package/dist/index.js CHANGED
@@ -1746,14 +1746,14 @@ var DEFAULT_GATEWAY_KEY_TTL_MS = 15 * 60 * 1e3;
1746
1746
  // src/key-lease/file-secret-store/file-secret-store.ts
1747
1747
  import { randomUUID as randomUUID2 } from "node:crypto";
1748
1748
  import * as fs13 from "node:fs/promises";
1749
- import * as path12 from "node:path";
1749
+ import * as path13 from "node:path";
1750
1750
 
1751
1751
  // src/attribution/clear-attribution/clear-attribution.ts
1752
1752
  import * as fs8 from "node:fs";
1753
1753
 
1754
1754
  // src/attribution/resolve-attribution-file/resolve-attribution-file.ts
1755
1755
  import * as fs7 from "node:fs";
1756
- import * as path8 from "node:path";
1756
+ import * as path9 from "node:path";
1757
1757
 
1758
1758
  // src/attribution/detect-worktree-root/detect-worktree-root.ts
1759
1759
  import * as fs6 from "node:fs";
@@ -1776,18 +1776,33 @@ var detectWorktreeRoot = (startDirectory) => {
1776
1776
  }
1777
1777
  };
1778
1778
 
1779
+ // src/attribution/global-attribution-file/global-attribution-file.ts
1780
+ import * as path8 from "node:path";
1781
+ var globalAttributionFile = () => path8.join(resolveV1SecretStoreDirectory(), "route33.attribution.json");
1782
+
1779
1783
  // src/attribution/resolve-attribution-file/resolve-attribution-file.ts
1784
+ var STATE_FILE = "route33.attribution.json";
1780
1785
  var resolveAttributionFile = (options) => {
1781
1786
  const worktreeRoot = detectWorktreeRoot(options.directory);
1782
1787
  if (worktreeRoot !== void 0) {
1783
- return path8.join(worktreeRoot, ".opencode", "route33.attribution.json");
1788
+ return path9.join(worktreeRoot, ".opencode", STATE_FILE);
1789
+ }
1790
+ switch (options.outsideWorktree) {
1791
+ case "use-directory":
1792
+ return path9.join(
1793
+ fs7.realpathSync(options.directory),
1794
+ ".opencode",
1795
+ STATE_FILE
1796
+ );
1797
+ case "use-global":
1798
+ return globalAttributionFile();
1799
+ case "return-undefined":
1800
+ return void 0;
1801
+ default: {
1802
+ const unexpected = options.outsideWorktree;
1803
+ throw new TypeError(`Unexpected policy: ${String(unexpected)}`);
1804
+ }
1784
1805
  }
1785
- const fallbackRoots = {
1786
- "return-undefined": void 0,
1787
- "use-directory": fs7.realpathSync(options.directory)
1788
- };
1789
- const fallbackRoot = fallbackRoots[options.outsideWorktree];
1790
- return fallbackRoot === void 0 ? void 0 : path8.join(fallbackRoot, ".opencode", "route33.attribution.json");
1791
1806
  };
1792
1807
 
1793
1808
  // src/attribution/clear-attribution/clear-attribution.ts
@@ -1800,16 +1815,22 @@ var clearAttribution = (options) => {
1800
1815
  return true;
1801
1816
  };
1802
1817
 
1818
+ // src/attribution/is-global-attribution/is-global-attribution.ts
1819
+ var isGlobalAttribution = (options) => options.outsideWorktree === "use-global" && detectWorktreeRoot(options.directory) === void 0;
1820
+
1821
+ // src/attribution/is-global-choice/is-global-choice.ts
1822
+ var isGlobalChoice = (attribution) => attribution.kind === "personal" && attribution.boundKeyId === void 0;
1823
+
1803
1824
  // src/attribution/read-legacy-key/read-legacy-key.ts
1804
1825
  import * as fs9 from "node:fs";
1805
- import * as path9 from "node:path";
1806
- var LEGACY_KEY_RELATIVE_PATH = path9.join(".opencode", "route33.key");
1826
+ import * as path10 from "node:path";
1827
+ var LEGACY_KEY_RELATIVE_PATH = path10.join(".opencode", "route33.key");
1807
1828
  var readLegacyKey = (worktree) => {
1808
1829
  if (worktree.trim() === "") return void 0;
1809
1830
  let raw;
1810
1831
  try {
1811
1832
  raw = fs9.readFileSync(
1812
- path9.join(worktree, LEGACY_KEY_RELATIVE_PATH),
1833
+ path10.join(worktree, LEGACY_KEY_RELATIVE_PATH),
1813
1834
  "utf8"
1814
1835
  );
1815
1836
  } catch {
@@ -1881,7 +1902,8 @@ var readAttribution = (options) => {
1881
1902
  }
1882
1903
  try {
1883
1904
  const parsed = JSON.parse(fs10.readFileSync(file, "utf8"));
1884
- return parseAttribution(parsed);
1905
+ const attribution = parseAttribution(parsed);
1906
+ return isGlobalAttribution(options) && !isGlobalChoice(attribution) ? void 0 : attribution;
1885
1907
  } catch {
1886
1908
  return void 0;
1887
1909
  }
@@ -1889,11 +1911,11 @@ var readAttribution = (options) => {
1889
1911
 
1890
1912
  // src/attribution/remove-legacy-key/remove-legacy-key.ts
1891
1913
  import * as fs11 from "node:fs";
1892
- import * as path10 from "node:path";
1893
- var LEGACY_KEY_RELATIVE_PATH2 = path10.join(".opencode", "route33.key");
1914
+ import * as path11 from "node:path";
1915
+ var LEGACY_KEY_RELATIVE_PATH2 = path11.join(".opencode", "route33.key");
1894
1916
  var removeLegacyKey = (worktree) => {
1895
1917
  try {
1896
- fs11.rmSync(path10.join(worktree, LEGACY_KEY_RELATIVE_PATH2), { force: true });
1918
+ fs11.rmSync(path11.join(worktree, LEGACY_KEY_RELATIVE_PATH2), { force: true });
1897
1919
  return true;
1898
1920
  } catch {
1899
1921
  return false;
@@ -1903,13 +1925,16 @@ var removeLegacyKey = (worktree) => {
1903
1925
  // src/attribution/write-attribution/write-attribution.ts
1904
1926
  import { randomUUID } from "node:crypto";
1905
1927
  import * as fs12 from "node:fs";
1906
- import * as path11 from "node:path";
1928
+ import * as path12 from "node:path";
1907
1929
  var writeAttribution = (options, attribution) => {
1908
1930
  const file = resolveAttributionFile(options);
1909
1931
  if (file === void 0) {
1910
1932
  return false;
1911
1933
  }
1912
- fs12.mkdirSync(path11.dirname(file), { recursive: true });
1934
+ if (isGlobalAttribution(options) && !isGlobalChoice(attribution)) {
1935
+ return false;
1936
+ }
1937
+ fs12.mkdirSync(path12.dirname(file), { recursive: true });
1913
1938
  const temporaryFile = `${file}.${String(process.pid)}.${randomUUID()}.tmp`;
1914
1939
  try {
1915
1940
  fs12.writeFileSync(temporaryFile, `${JSON.stringify(attribution)}
@@ -2039,7 +2064,7 @@ var FileSecretStore = class {
2039
2064
  throw new TypeError("File secret store scope is not portable");
2040
2065
  }
2041
2066
  this.#directory = options.directory;
2042
- this.#file = path12.join(options.directory, `lease-${options.scopeId}.json`);
2067
+ this.#file = path13.join(options.directory, `lease-${options.scopeId}.json`);
2043
2068
  }
2044
2069
  /** Reads and parses the scoped gateway credential.
2045
2070
  * @returns The persisted credential, when present.
@@ -2092,7 +2117,7 @@ var FileSecretStore = class {
2092
2117
  async stage(key, lease) {
2093
2118
  await fs13.mkdir(this.#directory, { mode: 448, recursive: true });
2094
2119
  await fs13.chmod(this.#directory, 448);
2095
- const temporary = path12.join(this.#directory, `.lease-${randomUUID2()}.tmp`);
2120
+ const temporary = path13.join(this.#directory, `.lease-${randomUUID2()}.tmp`);
2096
2121
  try {
2097
2122
  const record = lease === void 0 ? key.value : { key: key.value, lease };
2098
2123
  await fs13.writeFile(temporary, `${JSON.stringify(record)}
@@ -2894,6 +2919,7 @@ var WorkspaceKeyBinding = class {
2894
2919
  * @returns Secret-free options; local options do not need destructive consent.
2895
2920
  */
2896
2921
  async candidates(choice) {
2922
+ if (detectWorktreeRoot(this.deps.state.directory) === void 0) return [];
2897
2923
  const listing = this.#listings.get(choice.orgId) ?? this.listKeys(choice.orgId);
2898
2924
  this.#listings.set(choice.orgId, listing);
2899
2925
  const rows = await listing;
@@ -2941,6 +2967,8 @@ var WorkspaceKeyBinding = class {
2941
2967
  * @returns The attribution to commit after saving the secret.
2942
2968
  */
2943
2969
  async bind(choice, id, confirmed) {
2970
+ if (detectWorktreeRoot(this.deps.state.directory) === void 0)
2971
+ throw new GatewayCredentialError("Key binding requires a worktree.");
2944
2972
  const row = await this.deps.client.get(this.deps.token, id, choice.orgId);
2945
2973
  if (row.id !== id || !this.matches(row, choice))
2946
2974
  throw new GatewayCredentialError(
@@ -3085,6 +3113,22 @@ var createAttributionPrompt = (projects, options = {}) => {
3085
3113
  var PERSONAL_SELECTION_SUFFIX = ":personal";
3086
3114
  var isPersonalSelection = (selection) => selection === "personal" || selection.endsWith(PERSONAL_SELECTION_SUFFIX);
3087
3115
 
3116
+ // src/ux/attribution-plan/attribution-plan.ts
3117
+ var GLOBAL_ATTRIBUTION_NOTICE = "This folder is not a Git repository, so it cannot have its own budget. Choose the personal key for all such folders on this machine.";
3118
+ var attributionPlan = (input) => {
3119
+ const options = {
3120
+ orgs: input.orgs,
3121
+ personalKeyActive: input.personalKeyActive
3122
+ };
3123
+ return input.global ? {
3124
+ ...createAttributionPrompt([], options),
3125
+ notice: GLOBAL_ATTRIBUTION_NOTICE
3126
+ } : createAttributionPrompt(
3127
+ input.orgs.flatMap(({ projects }) => projects),
3128
+ options
3129
+ );
3130
+ };
3131
+
3088
3132
  // src/ux/attribution-prompt-error/attribution-prompt-error.ts
3089
3133
  var MESSAGES = {
3090
3134
  ATTRIBUTION_BACK: "Left budget selection without changing attribution.",
@@ -3549,7 +3593,7 @@ var Route33Runtime = class {
3549
3593
  async resolveWorkspaceCredential(directory) {
3550
3594
  const attribution = readAttribution({
3551
3595
  directory,
3552
- outsideWorktree: "return-undefined"
3596
+ outsideWorktree: this.#options.state.outsideWorktree
3553
3597
  });
3554
3598
  if (attribution === void 0) {
3555
3599
  const installation = this.#installation({ kind: "personal" });
@@ -3713,7 +3757,7 @@ var Route33Runtime = class {
3713
3757
  async workspaceKeyAllowance(directory) {
3714
3758
  const attribution = readAttribution({
3715
3759
  directory,
3716
- outsideWorktree: "return-undefined"
3760
+ outsideWorktree: this.#options.state.outsideWorktree
3717
3761
  });
3718
3762
  if (attribution === void 0) {
3719
3763
  return void 0;
@@ -3899,6 +3943,7 @@ var createRoute33Plugin = (options = {}) => {
3899
3943
  ...options.config
3900
3944
  };
3901
3945
  const runtimeOptions = options.runtime;
3946
+ const outsideWorktree = options.outsideWorktree ?? "return-undefined";
3902
3947
  const installation = runtimeOptions === void 0 ? void 0 : runtimeOptions.installation ?? createLeaseInstallationFactory({
3903
3948
  listScopes: () => FileSecretStore.scopes(
3904
3949
  resolveV1SecretStoreDirectory({
@@ -3917,10 +3962,7 @@ var createRoute33Plugin = (options = {}) => {
3917
3962
  ...runtimeOptions,
3918
3963
  auth: { ...runtimeOptions.auth, clientId: clientId2 },
3919
3964
  installation,
3920
- state: {
3921
- directory: input.worktree,
3922
- outsideWorktree: "return-undefined"
3923
- }
3965
+ state: { directory: input.worktree, outsideWorktree }
3924
3966
  });
3925
3967
  if (runtime2 !== void 0) {
3926
3968
  options.bindRuntime?.(runtime2);
@@ -3958,7 +4000,7 @@ var createRoute33Plugin = (options = {}) => {
3958
4000
  return false;
3959
4001
  }
3960
4002
  },
3961
- outsideWorktree: "return-undefined"
4003
+ outsideWorktree
3962
4004
  });
3963
4005
  }
3964
4006
  return Promise.resolve({
@@ -4895,6 +4937,7 @@ export {
4895
4937
  DEFAULT_GATEWAY_KEY_RENEWAL_RATIO,
4896
4938
  DEFAULT_GATEWAY_KEY_TTL_MS,
4897
4939
  FileSecretStore,
4940
+ GLOBAL_ATTRIBUTION_NOTICE,
4898
4941
  GatewayApiKey,
4899
4942
  HostStorageSecretStore,
4900
4943
  KeyLeaseError,
@@ -4907,6 +4950,7 @@ export {
4907
4950
  Route33Plugin,
4908
4951
  Route33Runtime,
4909
4952
  TRUSTED_PARTY_COPY,
4953
+ attributionPlan,
4910
4954
  changeAttribution,
4911
4955
  clearAttribution,
4912
4956
  contractFixtures,
@@ -4918,7 +4962,10 @@ export {
4918
4962
  detectWorktreeRoot,
4919
4963
  drainPages,
4920
4964
  fixtureToWire,
4965
+ globalAttributionFile,
4921
4966
  inspectSession,
4967
+ isGlobalAttribution,
4968
+ isGlobalChoice,
4922
4969
  isPersonalSelection,
4923
4970
  leaseForAttribution,
4924
4971
  mintKey,
@@ -4001,25 +4001,56 @@ var init_detect_worktree_root2 = __esm({
4001
4001
  }
4002
4002
  });
4003
4003
 
4004
+ // src/attribution/global-attribution-file/global-attribution-file.ts
4005
+ import * as path8 from "node:path";
4006
+ var globalAttributionFile;
4007
+ var init_global_attribution_file = __esm({
4008
+ "src/attribution/global-attribution-file/global-attribution-file.ts"() {
4009
+ "use strict";
4010
+ init_cli();
4011
+ globalAttributionFile = () => path8.join(resolveV1SecretStoreDirectory(), "route33.attribution.json");
4012
+ }
4013
+ });
4014
+
4015
+ // src/attribution/global-attribution-file/index.ts
4016
+ var init_global_attribution_file2 = __esm({
4017
+ "src/attribution/global-attribution-file/index.ts"() {
4018
+ "use strict";
4019
+ init_global_attribution_file();
4020
+ }
4021
+ });
4022
+
4004
4023
  // src/attribution/resolve-attribution-file/resolve-attribution-file.ts
4005
4024
  import * as fs7 from "node:fs";
4006
- import * as path8 from "node:path";
4007
- var resolveAttributionFile;
4025
+ import * as path9 from "node:path";
4026
+ var STATE_FILE, resolveAttributionFile;
4008
4027
  var init_resolve_attribution_file = __esm({
4009
4028
  "src/attribution/resolve-attribution-file/resolve-attribution-file.ts"() {
4010
4029
  "use strict";
4011
4030
  init_detect_worktree_root2();
4031
+ init_global_attribution_file2();
4032
+ STATE_FILE = "route33.attribution.json";
4012
4033
  resolveAttributionFile = (options) => {
4013
4034
  const worktreeRoot = detectWorktreeRoot(options.directory);
4014
4035
  if (worktreeRoot !== void 0) {
4015
- return path8.join(worktreeRoot, ".opencode", "route33.attribution.json");
4036
+ return path9.join(worktreeRoot, ".opencode", STATE_FILE);
4037
+ }
4038
+ switch (options.outsideWorktree) {
4039
+ case "use-directory":
4040
+ return path9.join(
4041
+ fs7.realpathSync(options.directory),
4042
+ ".opencode",
4043
+ STATE_FILE
4044
+ );
4045
+ case "use-global":
4046
+ return globalAttributionFile();
4047
+ case "return-undefined":
4048
+ return void 0;
4049
+ default: {
4050
+ const unexpected = options.outsideWorktree;
4051
+ throw new TypeError(`Unexpected policy: ${String(unexpected)}`);
4052
+ }
4016
4053
  }
4017
- const fallbackRoots = {
4018
- "return-undefined": void 0,
4019
- "use-directory": fs7.realpathSync(options.directory)
4020
- };
4021
- const fallbackRoot = fallbackRoots[options.outsideWorktree];
4022
- return fallbackRoot === void 0 ? void 0 : path8.join(fallbackRoot, ".opencode", "route33.attribution.json");
4023
4054
  };
4024
4055
  }
4025
4056
  });
@@ -4058,20 +4089,55 @@ var init_clear_attribution2 = __esm({
4058
4089
  }
4059
4090
  });
4060
4091
 
4092
+ // src/attribution/is-global-attribution/is-global-attribution.ts
4093
+ var isGlobalAttribution;
4094
+ var init_is_global_attribution = __esm({
4095
+ "src/attribution/is-global-attribution/is-global-attribution.ts"() {
4096
+ "use strict";
4097
+ init_detect_worktree_root2();
4098
+ isGlobalAttribution = (options) => options.outsideWorktree === "use-global" && detectWorktreeRoot(options.directory) === void 0;
4099
+ }
4100
+ });
4101
+
4102
+ // src/attribution/is-global-attribution/index.ts
4103
+ var init_is_global_attribution2 = __esm({
4104
+ "src/attribution/is-global-attribution/index.ts"() {
4105
+ "use strict";
4106
+ init_is_global_attribution();
4107
+ }
4108
+ });
4109
+
4110
+ // src/attribution/is-global-choice/is-global-choice.ts
4111
+ var isGlobalChoice;
4112
+ var init_is_global_choice = __esm({
4113
+ "src/attribution/is-global-choice/is-global-choice.ts"() {
4114
+ "use strict";
4115
+ isGlobalChoice = (attribution) => attribution.kind === "personal" && attribution.boundKeyId === void 0;
4116
+ }
4117
+ });
4118
+
4119
+ // src/attribution/is-global-choice/index.ts
4120
+ var init_is_global_choice2 = __esm({
4121
+ "src/attribution/is-global-choice/index.ts"() {
4122
+ "use strict";
4123
+ init_is_global_choice();
4124
+ }
4125
+ });
4126
+
4061
4127
  // src/attribution/read-legacy-key/read-legacy-key.ts
4062
4128
  import * as fs9 from "node:fs";
4063
- import * as path9 from "node:path";
4129
+ import * as path10 from "node:path";
4064
4130
  var LEGACY_KEY_RELATIVE_PATH, readLegacyKey;
4065
4131
  var init_read_legacy_key = __esm({
4066
4132
  "src/attribution/read-legacy-key/read-legacy-key.ts"() {
4067
4133
  "use strict";
4068
- LEGACY_KEY_RELATIVE_PATH = path9.join(".opencode", "route33.key");
4134
+ LEGACY_KEY_RELATIVE_PATH = path10.join(".opencode", "route33.key");
4069
4135
  readLegacyKey = (worktree) => {
4070
4136
  if (worktree.trim() === "") return void 0;
4071
4137
  let raw;
4072
4138
  try {
4073
4139
  raw = fs9.readFileSync(
4074
- path9.join(worktree, LEGACY_KEY_RELATIVE_PATH),
4140
+ path10.join(worktree, LEGACY_KEY_RELATIVE_PATH),
4075
4141
  "utf8"
4076
4142
  );
4077
4143
  } catch {
@@ -4182,6 +4248,8 @@ var readAttribution;
4182
4248
  var init_read_attribution = __esm({
4183
4249
  "src/attribution/read-attribution/read-attribution.ts"() {
4184
4250
  "use strict";
4251
+ init_is_global_attribution2();
4252
+ init_is_global_choice2();
4185
4253
  init_parse_attribution2();
4186
4254
  init_resolve_attribution_file2();
4187
4255
  readAttribution = (options) => {
@@ -4191,7 +4259,8 @@ var init_read_attribution = __esm({
4191
4259
  }
4192
4260
  try {
4193
4261
  const parsed = JSON.parse(fs10.readFileSync(file, "utf8"));
4194
- return parseAttribution(parsed);
4262
+ const attribution = parseAttribution(parsed);
4263
+ return isGlobalAttribution(options) && !isGlobalChoice(attribution) ? void 0 : attribution;
4195
4264
  } catch {
4196
4265
  return void 0;
4197
4266
  }
@@ -4209,15 +4278,15 @@ var init_read_attribution2 = __esm({
4209
4278
 
4210
4279
  // src/attribution/remove-legacy-key/remove-legacy-key.ts
4211
4280
  import * as fs11 from "node:fs";
4212
- import * as path10 from "node:path";
4281
+ import * as path11 from "node:path";
4213
4282
  var LEGACY_KEY_RELATIVE_PATH2, removeLegacyKey;
4214
4283
  var init_remove_legacy_key = __esm({
4215
4284
  "src/attribution/remove-legacy-key/remove-legacy-key.ts"() {
4216
4285
  "use strict";
4217
- LEGACY_KEY_RELATIVE_PATH2 = path10.join(".opencode", "route33.key");
4286
+ LEGACY_KEY_RELATIVE_PATH2 = path11.join(".opencode", "route33.key");
4218
4287
  removeLegacyKey = (worktree) => {
4219
4288
  try {
4220
- fs11.rmSync(path10.join(worktree, LEGACY_KEY_RELATIVE_PATH2), { force: true });
4289
+ fs11.rmSync(path11.join(worktree, LEGACY_KEY_RELATIVE_PATH2), { force: true });
4221
4290
  return true;
4222
4291
  } catch {
4223
4292
  return false;
@@ -4237,18 +4306,23 @@ var init_remove_legacy_key2 = __esm({
4237
4306
  // src/attribution/write-attribution/write-attribution.ts
4238
4307
  import { randomUUID } from "node:crypto";
4239
4308
  import * as fs12 from "node:fs";
4240
- import * as path11 from "node:path";
4309
+ import * as path12 from "node:path";
4241
4310
  var writeAttribution;
4242
4311
  var init_write_attribution = __esm({
4243
4312
  "src/attribution/write-attribution/write-attribution.ts"() {
4244
4313
  "use strict";
4314
+ init_is_global_attribution2();
4315
+ init_is_global_choice2();
4245
4316
  init_resolve_attribution_file2();
4246
4317
  writeAttribution = (options, attribution) => {
4247
4318
  const file = resolveAttributionFile(options);
4248
4319
  if (file === void 0) {
4249
4320
  return false;
4250
4321
  }
4251
- fs12.mkdirSync(path11.dirname(file), { recursive: true });
4322
+ if (isGlobalAttribution(options) && !isGlobalChoice(attribution)) {
4323
+ return false;
4324
+ }
4325
+ fs12.mkdirSync(path12.dirname(file), { recursive: true });
4252
4326
  const temporaryFile = `${file}.${String(process.pid)}.${randomUUID()}.tmp`;
4253
4327
  try {
4254
4328
  fs12.writeFileSync(temporaryFile, `${JSON.stringify(attribution)}
@@ -4277,6 +4351,9 @@ var init_attribution = __esm({
4277
4351
  "use strict";
4278
4352
  init_clear_attribution2();
4279
4353
  init_detect_worktree_root2();
4354
+ init_global_attribution_file2();
4355
+ init_is_global_attribution2();
4356
+ init_is_global_choice2();
4280
4357
  init_read_legacy_key2();
4281
4358
  init_parse_attribution2();
4282
4359
  init_read_attribution2();
@@ -4396,7 +4473,7 @@ var init_lease_state2 = __esm({
4396
4473
  // src/key-lease/file-secret-store/file-secret-store.ts
4397
4474
  import { randomUUID as randomUUID2 } from "node:crypto";
4398
4475
  import * as fs13 from "node:fs/promises";
4399
- import * as path12 from "node:path";
4476
+ import * as path13 from "node:path";
4400
4477
  var FileSecretStore;
4401
4478
  var init_file_secret_store = __esm({
4402
4479
  "src/key-lease/file-secret-store/file-secret-store.ts"() {
@@ -4430,7 +4507,7 @@ var init_file_secret_store = __esm({
4430
4507
  throw new TypeError("File secret store scope is not portable");
4431
4508
  }
4432
4509
  this.#directory = options.directory;
4433
- this.#file = path12.join(options.directory, `lease-${options.scopeId}.json`);
4510
+ this.#file = path13.join(options.directory, `lease-${options.scopeId}.json`);
4434
4511
  }
4435
4512
  /** Reads and parses the scoped gateway credential.
4436
4513
  * @returns The persisted credential, when present.
@@ -4483,7 +4560,7 @@ var init_file_secret_store = __esm({
4483
4560
  async stage(key, lease) {
4484
4561
  await fs13.mkdir(this.#directory, { mode: 448, recursive: true });
4485
4562
  await fs13.chmod(this.#directory, 448);
4486
- const temporary = path12.join(this.#directory, `.lease-${randomUUID2()}.tmp`);
4563
+ const temporary = path13.join(this.#directory, `.lease-${randomUUID2()}.tmp`);
4487
4564
  try {
4488
4565
  const record = lease === void 0 ? key.value : { key: key.value, lease };
4489
4566
  await fs13.writeFile(temporary, `${JSON.stringify(record)}
@@ -5731,6 +5808,7 @@ var init_workspace_key_binding = __esm({
5731
5808
  * @returns Secret-free options; local options do not need destructive consent.
5732
5809
  */
5733
5810
  async candidates(choice) {
5811
+ if (detectWorktreeRoot(this.deps.state.directory) === void 0) return [];
5734
5812
  const listing = this.#listings.get(choice.orgId) ?? this.listKeys(choice.orgId);
5735
5813
  this.#listings.set(choice.orgId, listing);
5736
5814
  const rows = await listing;
@@ -5778,6 +5856,8 @@ var init_workspace_key_binding = __esm({
5778
5856
  * @returns The attribution to commit after saving the secret.
5779
5857
  */
5780
5858
  async bind(choice, id, confirmed) {
5859
+ if (detectWorktreeRoot(this.deps.state.directory) === void 0)
5860
+ throw new GatewayCredentialError("Key binding requires a worktree.");
5781
5861
  const row = await this.deps.client.get(this.deps.token, id, choice.orgId);
5782
5862
  if (row.id !== id || !this.matches(row, choice))
5783
5863
  throw new GatewayCredentialError(
@@ -5965,12 +6045,9 @@ var init_attribution_prompt = __esm({
5965
6045
  });
5966
6046
 
5967
6047
  // src/ux/attribution-prompt/is-personal-selection/is-personal-selection.ts
5968
- var PERSONAL_SELECTION_SUFFIX, isPersonalSelection;
5969
6048
  var init_is_personal_selection = __esm({
5970
6049
  "src/ux/attribution-prompt/is-personal-selection/is-personal-selection.ts"() {
5971
6050
  "use strict";
5972
- PERSONAL_SELECTION_SUFFIX = ":personal";
5973
- isPersonalSelection = (selection) => selection === "personal" || selection.endsWith(PERSONAL_SELECTION_SUFFIX);
5974
6051
  }
5975
6052
  });
5976
6053
 
@@ -5992,6 +6069,22 @@ var init_attribution_prompt2 = __esm({
5992
6069
  }
5993
6070
  });
5994
6071
 
6072
+ // src/ux/attribution-plan/attribution-plan.ts
6073
+ var init_attribution_plan = __esm({
6074
+ "src/ux/attribution-plan/attribution-plan.ts"() {
6075
+ "use strict";
6076
+ init_attribution_prompt2();
6077
+ }
6078
+ });
6079
+
6080
+ // src/ux/attribution-plan/index.ts
6081
+ var init_attribution_plan2 = __esm({
6082
+ "src/ux/attribution-plan/index.ts"() {
6083
+ "use strict";
6084
+ init_attribution_plan();
6085
+ }
6086
+ });
6087
+
5995
6088
  // src/ux/attribution-prompt-error/attribution-prompt-error.ts
5996
6089
  var MESSAGES, AttributionPromptError;
5997
6090
  var init_attribution_prompt_error = __esm({
@@ -6109,6 +6202,7 @@ var init_callback_page_copy2 = __esm({
6109
6202
  var init_ux = __esm({
6110
6203
  "src/ux/index.ts"() {
6111
6204
  "use strict";
6205
+ init_attribution_plan2();
6112
6206
  init_attribution_prompt2();
6113
6207
  init_attribution_prompt_error2();
6114
6208
  init_prompt_flow2();
@@ -6606,7 +6700,7 @@ var init_route33_runtime = __esm({
6606
6700
  async resolveWorkspaceCredential(directory) {
6607
6701
  const attribution = readAttribution({
6608
6702
  directory,
6609
- outsideWorktree: "return-undefined"
6703
+ outsideWorktree: this.#options.state.outsideWorktree
6610
6704
  });
6611
6705
  if (attribution === void 0) {
6612
6706
  const installation = this.#installation({ kind: "personal" });
@@ -6770,7 +6864,7 @@ var init_route33_runtime = __esm({
6770
6864
  async workspaceKeyAllowance(directory) {
6771
6865
  const attribution = readAttribution({
6772
6866
  directory,
6773
- outsideWorktree: "return-undefined"
6867
+ outsideWorktree: this.#options.state.outsideWorktree
6774
6868
  });
6775
6869
  if (attribution === void 0) {
6776
6870
  return void 0;
@@ -7016,6 +7110,7 @@ var init_create_route33_plugin = __esm({
7016
7110
  ...options.config
7017
7111
  };
7018
7112
  const runtimeOptions = options.runtime;
7113
+ const outsideWorktree = options.outsideWorktree ?? "return-undefined";
7019
7114
  const installation = runtimeOptions === void 0 ? void 0 : runtimeOptions.installation ?? createLeaseInstallationFactory({
7020
7115
  listScopes: () => FileSecretStore.scopes(
7021
7116
  resolveV1SecretStoreDirectory({
@@ -7034,10 +7129,7 @@ var init_create_route33_plugin = __esm({
7034
7129
  ...runtimeOptions,
7035
7130
  auth: { ...runtimeOptions.auth, clientId },
7036
7131
  installation,
7037
- state: {
7038
- directory: input.worktree,
7039
- outsideWorktree: "return-undefined"
7040
- }
7132
+ state: { directory: input.worktree, outsideWorktree }
7041
7133
  });
7042
7134
  if (runtime !== void 0) {
7043
7135
  options.bindRuntime?.(runtime);
@@ -7075,7 +7167,7 @@ var init_create_route33_plugin = __esm({
7075
7167
  return false;
7076
7168
  }
7077
7169
  },
7078
- outsideWorktree: "return-undefined"
7170
+ outsideWorktree
7079
7171
  });
7080
7172
  }
7081
7173
  return Promise.resolve({
@@ -8427,7 +8519,7 @@ var v2SetupDirectory = (context) => {
8427
8519
  if (location === void 0) return void 0;
8428
8520
  const attributed = readAttribution({
8429
8521
  directory: location.directory,
8430
- outsideWorktree: "return-undefined"
8522
+ outsideWorktree: "use-global"
8431
8523
  }) !== void 0;
8432
8524
  return attributed ? void 0 : location.directory;
8433
8525
  };
@@ -8504,7 +8596,6 @@ var createV1ConnectWizard = (composeOptions = productionOptions) => (api) => {
8504
8596
 
8505
8597
  // src/tui-entry/v2-tui/v2-tui.ts
8506
8598
  init_attribution();
8507
- init_ux();
8508
8599
 
8509
8600
  // src/tui-entry/show-r33-menu/show-r33-menu.ts
8510
8601
  init_attribution();
@@ -8619,7 +8710,6 @@ var showCompletion = (dialog, options, selection, extras) => {
8619
8710
  // src/v2-entry/connect-copy/connect-copy.ts
8620
8711
  var CONNECT_COPY = {
8621
8712
  failFastClientId: "This Route 33 build has no OAuth client ID; reinstall it from the opencode-dist ref.",
8622
- failFastWorktree: "To assign a Route 33 budget, open a Git repository.",
8623
8713
  selectionInvalid: "That Route 33 option is no longer available; open /r33 and choose Attribute.",
8624
8714
  signedInNextStep: "Signed in to Route 33; open /r33 and choose Attribute to assign a budget.",
8625
8715
  budgetSelected: "Budget selected but not assigned; open /r33 and choose Attribute to finish setup."
@@ -9090,6 +9180,12 @@ var v2BudgetPicker = async (deps) => {
9090
9180
  const orgField = deps.formFields.find(
9091
9181
  (field) => field.key === ORGANISATION_FIELD_KEY
9092
9182
  );
9183
+ if (attributionField.description !== void 0) {
9184
+ await deps.dialog.alert({
9185
+ message: attributionField.description,
9186
+ title: V2_CONNECT_COPY.busyTitle
9187
+ });
9188
+ }
9093
9189
  for (; ; ) {
9094
9190
  const round = await runBudgetRound({
9095
9191
  budgetOptions: attributionField.options ?? [],
@@ -9295,7 +9391,7 @@ var v2Autoconnect = async (context, options = {}) => {
9295
9391
  if (directory === void 0) return;
9296
9392
  const unattributed = () => readAttribution({
9297
9393
  directory,
9298
- outsideWorktree: "return-undefined"
9394
+ outsideWorktree: "use-global"
9299
9395
  }) === void 0;
9300
9396
  const dialog = context.ui.dialog;
9301
9397
  if (dialog !== void 0) {
@@ -9372,7 +9468,7 @@ var showR33Menu = async (context, deps) => {
9372
9468
  if (location === void 0 || readEnvDirectApiKey() !== void 0) return;
9373
9469
  if (readAttribution({
9374
9470
  directory: location.directory,
9375
- outsideWorktree: "return-undefined"
9471
+ outsideWorktree: "use-global"
9376
9472
  }) === void 0) {
9377
9473
  await v2Autoconnect(context, { directory: location.directory });
9378
9474
  } else {
@@ -9446,7 +9542,6 @@ var v2BootMatrix = async ({
9446
9542
  probe,
9447
9543
  assumedAlive = false,
9448
9544
  attributed,
9449
- globalFallback,
9450
9545
  wizard
9451
9546
  }) => {
9452
9547
  if (!assumedAlive && await probe() === "dead") {
@@ -9455,9 +9550,6 @@ var v2BootMatrix = async ({
9455
9550
  if (attributed()) {
9456
9551
  return { kind: "silent" };
9457
9552
  }
9458
- if (globalFallback !== void 0 && await globalFallback()) {
9459
- return { kind: "silent" };
9460
- }
9461
9553
  await wizard();
9462
9554
  return { kind: "wizard-settled" };
9463
9555
  };
@@ -9737,7 +9829,7 @@ var composeV2TuiRuntime = (context) => {
9737
9829
  }),
9738
9830
  state: {
9739
9831
  directory: location?.directory ?? "",
9740
- outsideWorktree: "return-undefined"
9832
+ outsideWorktree: "use-global"
9741
9833
  }
9742
9834
  });
9743
9835
  };
@@ -9890,10 +9982,9 @@ var createV2Tui = () => ({
9890
9982
  const location = context.location ?? context.data?.location.default();
9891
9983
  const directory = location?.directory ?? "";
9892
9984
  const wizard = v2WizardControl();
9893
- let globalPersonalKey = false;
9894
9985
  const attributed = () => directory === "" ? false : readAttribution({
9895
9986
  directory,
9896
- outsideWorktree: "return-undefined"
9987
+ outsideWorktree: "use-global"
9897
9988
  }) !== void 0;
9898
9989
  const storedRoute33Token = () => {
9899
9990
  const box = context.storage?.store("route33_auth", {
@@ -9920,26 +10011,11 @@ var createV2Tui = () => ({
9920
10011
  readStoredToken: storedRoute33Token
9921
10012
  });
9922
10013
  };
9923
- const globalFallback = async () => {
9924
- if (detectWorktreeRoot(directory) !== void 0) return false;
9925
- const form = await v2AttributionForm(context).catch(() => void 0);
9926
- for (const option of form?.options ?? []) {
9927
- if (isPersonalSelection(option.value) && option.label.includes(PERSONAL_KEY_ACTIVE_MARKER)) {
9928
- return true;
9929
- }
9930
- }
9931
- return false;
9932
- };
9933
10014
  const automatic = (host) => v2Autoconnect(host, { superseded: wizard.superseded });
9934
10015
  const boot = async (options) => {
9935
10016
  await v2BootMatrix({
9936
10017
  assumedAlive: options?.assumedAlive === true,
9937
10018
  attributed,
9938
- globalFallback: async () => {
9939
- const silent = await globalFallback();
9940
- globalPersonalKey = silent;
9941
- return silent;
9942
- },
9943
10019
  probe: sessionProbe,
9944
10020
  wizard: () => withAttributionPicker({ ...context, location }, automatic)
9945
10021
  });
@@ -9954,7 +10030,7 @@ var createV2Tui = () => ({
9954
10030
  }
9955
10031
  },
9956
10032
  mode: context.keymap?.mode,
9957
- pending: () => v2SetupDirectory({ location: { directory } }) !== void 0 && !globalPersonalKey,
10033
+ pending: () => v2SetupDirectory({ location: { directory } }) !== void 0,
9958
10034
  run: boot
9959
10035
  });
9960
10036
  void lock.start().catch(() => void 0);
@@ -1746,14 +1746,14 @@ var DEFAULT_GATEWAY_KEY_TTL_MS = 15 * 60 * 1e3;
1746
1746
  // src/key-lease/file-secret-store/file-secret-store.ts
1747
1747
  import { randomUUID as randomUUID2 } from "node:crypto";
1748
1748
  import * as fs11 from "node:fs/promises";
1749
- import * as path12 from "node:path";
1749
+ import * as path13 from "node:path";
1750
1750
 
1751
1751
  // src/attribution/clear-attribution/clear-attribution.ts
1752
1752
  import * as fs8 from "node:fs";
1753
1753
 
1754
1754
  // src/attribution/resolve-attribution-file/resolve-attribution-file.ts
1755
1755
  import * as fs7 from "node:fs";
1756
- import * as path8 from "node:path";
1756
+ import * as path9 from "node:path";
1757
1757
 
1758
1758
  // src/attribution/detect-worktree-root/detect-worktree-root.ts
1759
1759
  import * as fs6 from "node:fs";
@@ -1776,18 +1776,33 @@ var detectWorktreeRoot = (startDirectory) => {
1776
1776
  }
1777
1777
  };
1778
1778
 
1779
+ // src/attribution/global-attribution-file/global-attribution-file.ts
1780
+ import * as path8 from "node:path";
1781
+ var globalAttributionFile = () => path8.join(resolveV1SecretStoreDirectory(), "route33.attribution.json");
1782
+
1779
1783
  // src/attribution/resolve-attribution-file/resolve-attribution-file.ts
1784
+ var STATE_FILE = "route33.attribution.json";
1780
1785
  var resolveAttributionFile = (options) => {
1781
1786
  const worktreeRoot = detectWorktreeRoot(options.directory);
1782
1787
  if (worktreeRoot !== void 0) {
1783
- return path8.join(worktreeRoot, ".opencode", "route33.attribution.json");
1788
+ return path9.join(worktreeRoot, ".opencode", STATE_FILE);
1789
+ }
1790
+ switch (options.outsideWorktree) {
1791
+ case "use-directory":
1792
+ return path9.join(
1793
+ fs7.realpathSync(options.directory),
1794
+ ".opencode",
1795
+ STATE_FILE
1796
+ );
1797
+ case "use-global":
1798
+ return globalAttributionFile();
1799
+ case "return-undefined":
1800
+ return void 0;
1801
+ default: {
1802
+ const unexpected = options.outsideWorktree;
1803
+ throw new TypeError(`Unexpected policy: ${String(unexpected)}`);
1804
+ }
1784
1805
  }
1785
- const fallbackRoots = {
1786
- "return-undefined": void 0,
1787
- "use-directory": fs7.realpathSync(options.directory)
1788
- };
1789
- const fallbackRoot = fallbackRoots[options.outsideWorktree];
1790
- return fallbackRoot === void 0 ? void 0 : path8.join(fallbackRoot, ".opencode", "route33.attribution.json");
1791
1806
  };
1792
1807
 
1793
1808
  // src/attribution/clear-attribution/clear-attribution.ts
@@ -1800,9 +1815,15 @@ var clearAttribution = (options) => {
1800
1815
  return true;
1801
1816
  };
1802
1817
 
1818
+ // src/attribution/is-global-attribution/is-global-attribution.ts
1819
+ var isGlobalAttribution = (options) => options.outsideWorktree === "use-global" && detectWorktreeRoot(options.directory) === void 0;
1820
+
1821
+ // src/attribution/is-global-choice/is-global-choice.ts
1822
+ var isGlobalChoice = (attribution) => attribution.kind === "personal" && attribution.boundKeyId === void 0;
1823
+
1803
1824
  // src/attribution/read-legacy-key/read-legacy-key.ts
1804
- import * as path9 from "node:path";
1805
- var LEGACY_KEY_RELATIVE_PATH = path9.join(".opencode", "route33.key");
1825
+ import * as path10 from "node:path";
1826
+ var LEGACY_KEY_RELATIVE_PATH = path10.join(".opencode", "route33.key");
1806
1827
 
1807
1828
  // src/attribution/parse-attribution/read-org-id/read-org-id.ts
1808
1829
  var readOrgId = (value) => {
@@ -1855,26 +1876,30 @@ var readAttribution = (options) => {
1855
1876
  }
1856
1877
  try {
1857
1878
  const parsed = JSON.parse(fs9.readFileSync(file, "utf8"));
1858
- return parseAttribution(parsed);
1879
+ const attribution = parseAttribution(parsed);
1880
+ return isGlobalAttribution(options) && !isGlobalChoice(attribution) ? void 0 : attribution;
1859
1881
  } catch {
1860
1882
  return void 0;
1861
1883
  }
1862
1884
  };
1863
1885
 
1864
1886
  // src/attribution/remove-legacy-key/remove-legacy-key.ts
1865
- import * as path10 from "node:path";
1866
- var LEGACY_KEY_RELATIVE_PATH2 = path10.join(".opencode", "route33.key");
1887
+ import * as path11 from "node:path";
1888
+ var LEGACY_KEY_RELATIVE_PATH2 = path11.join(".opencode", "route33.key");
1867
1889
 
1868
1890
  // src/attribution/write-attribution/write-attribution.ts
1869
1891
  import { randomUUID } from "node:crypto";
1870
1892
  import * as fs10 from "node:fs";
1871
- import * as path11 from "node:path";
1893
+ import * as path12 from "node:path";
1872
1894
  var writeAttribution = (options, attribution) => {
1873
1895
  const file = resolveAttributionFile(options);
1874
1896
  if (file === void 0) {
1875
1897
  return false;
1876
1898
  }
1877
- fs10.mkdirSync(path11.dirname(file), { recursive: true });
1899
+ if (isGlobalAttribution(options) && !isGlobalChoice(attribution)) {
1900
+ return false;
1901
+ }
1902
+ fs10.mkdirSync(path12.dirname(file), { recursive: true });
1878
1903
  const temporaryFile = `${file}.${String(process.pid)}.${randomUUID()}.tmp`;
1879
1904
  try {
1880
1905
  fs10.writeFileSync(temporaryFile, `${JSON.stringify(attribution)}
@@ -2004,7 +2029,7 @@ var FileSecretStore = class {
2004
2029
  throw new TypeError("File secret store scope is not portable");
2005
2030
  }
2006
2031
  this.#directory = options.directory;
2007
- this.#file = path12.join(options.directory, `lease-${options.scopeId}.json`);
2032
+ this.#file = path13.join(options.directory, `lease-${options.scopeId}.json`);
2008
2033
  }
2009
2034
  /** Reads and parses the scoped gateway credential.
2010
2035
  * @returns The persisted credential, when present.
@@ -2057,7 +2082,7 @@ var FileSecretStore = class {
2057
2082
  async stage(key, lease) {
2058
2083
  await fs11.mkdir(this.#directory, { mode: 448, recursive: true });
2059
2084
  await fs11.chmod(this.#directory, 448);
2060
- const temporary = path12.join(this.#directory, `.lease-${randomUUID2()}.tmp`);
2085
+ const temporary = path13.join(this.#directory, `.lease-${randomUUID2()}.tmp`);
2061
2086
  try {
2062
2087
  const record = lease === void 0 ? key.value : { key: key.value, lease };
2063
2088
  await fs11.writeFile(temporary, `${JSON.stringify(record)}
@@ -2859,6 +2884,7 @@ var WorkspaceKeyBinding = class {
2859
2884
  * @returns Secret-free options; local options do not need destructive consent.
2860
2885
  */
2861
2886
  async candidates(choice) {
2887
+ if (detectWorktreeRoot(this.deps.state.directory) === void 0) return [];
2862
2888
  const listing = this.#listings.get(choice.orgId) ?? this.listKeys(choice.orgId);
2863
2889
  this.#listings.set(choice.orgId, listing);
2864
2890
  const rows = await listing;
@@ -2906,6 +2932,8 @@ var WorkspaceKeyBinding = class {
2906
2932
  * @returns The attribution to commit after saving the secret.
2907
2933
  */
2908
2934
  async bind(choice, id, confirmed) {
2935
+ if (detectWorktreeRoot(this.deps.state.directory) === void 0)
2936
+ throw new GatewayCredentialError("Key binding requires a worktree.");
2909
2937
  const row = await this.deps.client.get(this.deps.token, id, choice.orgId);
2910
2938
  if (row.id !== id || !this.matches(row, choice))
2911
2939
  throw new GatewayCredentialError(
@@ -3046,6 +3074,22 @@ var createAttributionPrompt = (projects, options = {}) => {
3046
3074
  };
3047
3075
  };
3048
3076
 
3077
+ // src/ux/attribution-plan/attribution-plan.ts
3078
+ var GLOBAL_ATTRIBUTION_NOTICE = "This folder is not a Git repository, so it cannot have its own budget. Choose the personal key for all such folders on this machine.";
3079
+ var attributionPlan = (input) => {
3080
+ const options = {
3081
+ orgs: input.orgs,
3082
+ personalKeyActive: input.personalKeyActive
3083
+ };
3084
+ return input.global ? {
3085
+ ...createAttributionPrompt([], options),
3086
+ notice: GLOBAL_ATTRIBUTION_NOTICE
3087
+ } : createAttributionPrompt(
3088
+ input.orgs.flatMap(({ projects }) => projects),
3089
+ options
3090
+ );
3091
+ };
3092
+
3049
3093
  // src/ux/attribution-prompt-error/attribution-prompt-error.ts
3050
3094
  var MESSAGES = {
3051
3095
  ATTRIBUTION_BACK: "Left budget selection without changing attribution.",
@@ -3510,7 +3554,7 @@ var Route33Runtime = class {
3510
3554
  async resolveWorkspaceCredential(directory) {
3511
3555
  const attribution = readAttribution({
3512
3556
  directory,
3513
- outsideWorktree: "return-undefined"
3557
+ outsideWorktree: this.#options.state.outsideWorktree
3514
3558
  });
3515
3559
  if (attribution === void 0) {
3516
3560
  const installation = this.#installation({ kind: "personal" });
@@ -3674,7 +3718,7 @@ var Route33Runtime = class {
3674
3718
  async workspaceKeyAllowance(directory) {
3675
3719
  const attribution = readAttribution({
3676
3720
  directory,
3677
- outsideWorktree: "return-undefined"
3721
+ outsideWorktree: this.#options.state.outsideWorktree
3678
3722
  });
3679
3723
  if (attribution === void 0) {
3680
3724
  return void 0;
@@ -3860,6 +3904,7 @@ var createRoute33Plugin = (options = {}) => {
3860
3904
  ...options.config
3861
3905
  };
3862
3906
  const runtimeOptions = options.runtime;
3907
+ const outsideWorktree = options.outsideWorktree ?? "return-undefined";
3863
3908
  const installation = runtimeOptions === void 0 ? void 0 : runtimeOptions.installation ?? createLeaseInstallationFactory({
3864
3909
  listScopes: () => FileSecretStore.scopes(
3865
3910
  resolveV1SecretStoreDirectory({
@@ -3878,10 +3923,7 @@ var createRoute33Plugin = (options = {}) => {
3878
3923
  ...runtimeOptions,
3879
3924
  auth: { ...runtimeOptions.auth, clientId: clientId2 },
3880
3925
  installation,
3881
- state: {
3882
- directory: input.worktree,
3883
- outsideWorktree: "return-undefined"
3884
- }
3926
+ state: { directory: input.worktree, outsideWorktree }
3885
3927
  });
3886
3928
  if (runtime2 !== void 0) {
3887
3929
  options.bindRuntime?.(runtime2);
@@ -3919,7 +3961,7 @@ var createRoute33Plugin = (options = {}) => {
3919
3961
  return false;
3920
3962
  }
3921
3963
  },
3922
- outsideWorktree: "return-undefined"
3964
+ outsideWorktree
3923
3965
  });
3924
3966
  }
3925
3967
  return Promise.resolve({
@@ -5009,7 +5051,6 @@ var parseBudgetAnswer = (answer, maximum) => {
5009
5051
  // src/v2-entry/connect-copy/connect-copy.ts
5010
5052
  var CONNECT_COPY = {
5011
5053
  failFastClientId: "This Route 33 build has no OAuth client ID; reinstall it from the opencode-dist ref.",
5012
- failFastWorktree: "To assign a Route 33 budget, open a Git repository.",
5013
5054
  selectionInvalid: "That Route 33 option is no longer available; open /r33 and choose Attribute.",
5014
5055
  signedInNextStep: "Signed in to Route 33; open /r33 and choose Attribute to assign a budget.",
5015
5056
  budgetSelected: "Budget selected but not assigned; open /r33 and choose Attribute to finish setup."
@@ -5080,13 +5121,13 @@ var applyWizardAnswer = async (deps, answer) => {
5080
5121
 
5081
5122
  // src/v2-entry/connect-authorize/connect-authorize.ts
5082
5123
  var createConnectAuthorize = (deps) => async (answer = {}) => {
5083
- if (deps.clientId === "") {
5084
- throw new GatewayCredentialError(CONNECT_COPY.failFastClientId);
5085
- }
5086
- if (detectWorktreeRoot(deps.directory) === void 0) {
5087
- throw new GatewayCredentialError(CONNECT_COPY.failFastWorktree);
5088
- }
5124
+ const refuseUnusableBuild = () => {
5125
+ if (deps.clientId === "") {
5126
+ throw new GatewayCredentialError(CONNECT_COPY.failFastClientId);
5127
+ }
5128
+ };
5089
5129
  const callback = (async () => {
5130
+ refuseUnusableBuild();
5090
5131
  const emptyAnswer = Object.keys(answer).length === 0;
5091
5132
  if (emptyAnswer) {
5092
5133
  const runtime2 = deps.getRuntime();
@@ -5128,6 +5169,20 @@ var createConnectAuthorize = (deps) => async (answer = {}) => {
5128
5169
  };
5129
5170
  };
5130
5171
 
5172
+ // src/v2-entry/connect-form/budget-question-copy/budget-question-copy.ts
5173
+ var budgetQuestionCopy = (plan) => plan.notice === void 0 ? {
5174
+ attribution: {
5175
+ title: "Which budget covers Route 33 usage in this folder?"
5176
+ },
5177
+ organisation: "Which Route 33 organisation covers this folder?"
5178
+ } : {
5179
+ attribution: {
5180
+ description: plan.notice,
5181
+ title: "Which personal key covers folders outside Git?"
5182
+ },
5183
+ organisation: "Which Route 33 organisation covers folders outside Git?"
5184
+ };
5185
+
5131
5186
  // src/v2-entry/connect-form/connect-form.ts
5132
5187
  var ATTRIBUTION_FIELD_KEY2 = "attribution";
5133
5188
  var ORGANISATION_FIELD_KEY = "organisation";
@@ -5141,7 +5196,6 @@ var ALLOWED_MODELS_FIELD_KEY = "allowed_models";
5141
5196
  var ALLOWED_MODELS_TITLE = "Which models may this key use?";
5142
5197
  var ALL_MODELS_VALUE = "all";
5143
5198
  var ALL_MODELS_LABEL = "All models (inherit)";
5144
- var ORGANISATION_FIELD_TITLE = "Which Route 33 organisation covers this folder?";
5145
5199
  var EXPIRY_OPTIONS = [
5146
5200
  { label: "30 days", value: "30" },
5147
5201
  { label: "90 days", value: "90" },
@@ -5151,13 +5205,15 @@ var EXPIRY_OPTIONS = [
5151
5205
  var buildConnectForm = (plan, key) => {
5152
5206
  const maximum = key?.maximum;
5153
5207
  const orgs = plan.orgs ?? [];
5208
+ const copy = budgetQuestionCopy(plan);
5154
5209
  const organisationField = {
5155
5210
  key: ORGANISATION_FIELD_KEY,
5156
5211
  options: orgs.map(({ id, name }) => ({ label: name, value: id })),
5157
- title: ORGANISATION_FIELD_TITLE,
5212
+ title: copy.organisation,
5158
5213
  type: "string"
5159
5214
  };
5160
5215
  const attributionField = {
5216
+ ...copy.attribution,
5161
5217
  key: ATTRIBUTION_FIELD_KEY2,
5162
5218
  options: plan.options.map((option) => ({
5163
5219
  label: option.label,
@@ -5167,7 +5223,6 @@ var buildConnectForm = (plan, key) => {
5167
5223
  // an answer — a required field makes the host reject bare connects
5168
5224
  // (400 Missing required form field) and kills the probe. The wizard
5169
5225
  // still sends the attribution on its answer pass.
5170
- title: "Which budget covers Route 33 usage in this folder?",
5171
5226
  type: "string"
5172
5227
  };
5173
5228
  const budgetFields = orgs.length > 1 ? [organisationField, attributionField] : [attributionField];
@@ -5349,7 +5404,7 @@ var sessionModelUsage = (sessions) => {
5349
5404
  var gateDirectory = async (deps, sessionID) => {
5350
5405
  const session = await deps.session.get({ sessionID });
5351
5406
  const directory = session?.location.directory ?? deps.fallbackDirectory;
5352
- return { directory, outsideWorktree: "return-undefined" };
5407
+ return { directory, outsideWorktree: "use-global" };
5353
5408
  };
5354
5409
 
5355
5410
  // src/v2-entry/gate-fallback/gate-fallback.ts
@@ -5698,8 +5753,9 @@ var createRoute33V2Plugin = (options = {}) => {
5698
5753
  const stash = createAuthorizationUrlStash2();
5699
5754
  const state = {
5700
5755
  directory: context.location.directory,
5701
- outsideWorktree: "return-undefined"
5756
+ outsideWorktree: "use-global"
5702
5757
  };
5758
+ const global = isGlobalAttribution(state);
5703
5759
  const installation = createLeaseInstallationFactory({
5704
5760
  listScopes: () => HostStorageSecretStore.scopes(context.storage),
5705
5761
  createSecretStore: (scopeId) => new HostStorageSecretStore({
@@ -5732,6 +5788,7 @@ var createRoute33V2Plugin = (options = {}) => {
5732
5788
  runtime2 = instance;
5733
5789
  },
5734
5790
  clientId: clientId2,
5791
+ outsideWorktree: state.outsideWorktree,
5735
5792
  runtime: runtimeInput
5736
5793
  })({ worktree: context.location.directory });
5737
5794
  const resolveCredential = () => resolveHostCredential({
@@ -5762,16 +5819,13 @@ var createRoute33V2Plugin = (options = {}) => {
5762
5819
  await context.integration.reload();
5763
5820
  return;
5764
5821
  }
5765
- plan = createAttributionPrompt(
5766
- mintableOrgs.flatMap(({ projects }) => projects),
5767
- { personalKeyActive, orgs: mintableOrgs }
5768
- );
5822
+ const orgs = mintableOrgs;
5823
+ plan = attributionPlan({ global, orgs, personalKeyActive });
5769
5824
  connectFields = buildConnectForm(plan);
5770
5825
  await context.integration.reload();
5771
5826
  };
5772
5827
  const authorize = createConnectAuthorize({
5773
5828
  clientId: clientId2,
5774
- directory: context.location.directory,
5775
5829
  getPlan: () => plan,
5776
5830
  getRuntime: () => runtime2,
5777
5831
  mintWorkspaceKey: (attribution, extras, save) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r-33/opencode",
3
- "version": "0.5.0",
3
+ "version": "0.5.1-rc.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",