@r-33/opencode 0.4.7-rc.24 → 0.4.7-rc.26

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/index.js CHANGED
@@ -2588,7 +2588,7 @@ var createLeaseInstallationFactory = (options) => {
2588
2588
  return existing;
2589
2589
  }
2590
2590
  const installation = {
2591
- keyName: `route33:lease:${scopeId}`,
2591
+ keyName: `route33_lease_${scopeId}`,
2592
2592
  secretStore: options.createSecretStore(scopeId),
2593
2593
  ...options.createStateStore === void 0 ? {} : { stateStore: options.createStateStore(scopeId) },
2594
2594
  state: LeaseState.restore(void 0)
@@ -2906,11 +2906,14 @@ var Route33Runtime = class {
2906
2906
  * member-visible project listing, organisation names stitched from the
2907
2907
  * login's own memberships. Orgs the login merely administers carry no
2908
2908
  * budget row and drop out — the picker never offers a project whose
2909
- * keys the login cannot create.
2909
+ * keys the login cannot create. A `allowBrowser: false` policy makes
2910
+ * the call non-blocking: a dead session rejects instead of opening a
2911
+ * browser, so the picker's form registration never stalls a boot.
2912
+ * @param policy - Whether a dead session may open a browser login.
2910
2913
  * @returns Mintable projects with organisation context for the picker.
2911
2914
  */
2912
- async listMintableProjects() {
2913
- const credential = await this.#session.credential();
2915
+ async listMintableProjects(policy = {}) {
2916
+ const credential = await this.#session.credential(policy);
2914
2917
  const subject = this.#subject(credential);
2915
2918
  const client = this.#client();
2916
2919
  const [budgets, memberships] = await Promise.all([
@@ -13,70 +13,6 @@ var __export = (target, all) => {
13
13
  __defProp(target, name, { get: all[name], enumerable: true });
14
14
  };
15
15
 
16
- // src/cli/e2e-bin/is-executable/is-executable.ts
17
- var init_is_executable = __esm({
18
- "src/cli/e2e-bin/is-executable/is-executable.ts"() {
19
- "use strict";
20
- }
21
- });
22
-
23
- // src/cli/e2e-bin/is-executable/index.ts
24
- var init_is_executable2 = __esm({
25
- "src/cli/e2e-bin/is-executable/index.ts"() {
26
- "use strict";
27
- init_is_executable();
28
- }
29
- });
30
-
31
- // src/cli/e2e-bin/e2e-bin.ts
32
- var init_e2e_bin = __esm({
33
- "src/cli/e2e-bin/e2e-bin.ts"() {
34
- "use strict";
35
- init_is_executable2();
36
- }
37
- });
38
-
39
- // src/cli/e2e-bin/find-host-binary/find-host-binary.ts
40
- var init_find_host_binary = __esm({
41
- "src/cli/e2e-bin/find-host-binary/find-host-binary.ts"() {
42
- "use strict";
43
- init_e2e_bin();
44
- }
45
- });
46
-
47
- // src/cli/e2e-bin/find-host-binary/index.ts
48
- var init_find_host_binary2 = __esm({
49
- "src/cli/e2e-bin/find-host-binary/index.ts"() {
50
- "use strict";
51
- init_find_host_binary();
52
- }
53
- });
54
-
55
- // src/cli/e2e-bin/parent-host-env/parent-host-env.ts
56
- var init_parent_host_env = __esm({
57
- "src/cli/e2e-bin/parent-host-env/parent-host-env.ts"() {
58
- "use strict";
59
- }
60
- });
61
-
62
- // src/cli/e2e-bin/parent-host-env/index.ts
63
- var init_parent_host_env2 = __esm({
64
- "src/cli/e2e-bin/parent-host-env/index.ts"() {
65
- "use strict";
66
- init_parent_host_env();
67
- }
68
- });
69
-
70
- // src/cli/e2e-bin/index.ts
71
- var init_e2e_bin2 = __esm({
72
- "src/cli/e2e-bin/index.ts"() {
73
- "use strict";
74
- init_e2e_bin();
75
- init_find_host_binary2();
76
- init_parent_host_env2();
77
- }
78
- });
79
-
80
16
  // src/cli/read-env-base-url/read-env-base-url.ts
81
17
  var readEnvBaseUrl;
82
18
  var init_read_env_base_url = __esm({
@@ -523,21 +459,6 @@ var init_read_env_strict2 = __esm({
523
459
  }
524
460
  });
525
461
 
526
- // src/cli/read-e2e-dev-env/read-e2e-dev-env.ts
527
- var init_read_e2e_dev_env = __esm({
528
- "src/cli/read-e2e-dev-env/read-e2e-dev-env.ts"() {
529
- "use strict";
530
- }
531
- });
532
-
533
- // src/cli/read-e2e-dev-env/index.ts
534
- var init_read_e2e_dev_env2 = __esm({
535
- "src/cli/read-e2e-dev-env/index.ts"() {
536
- "use strict";
537
- init_read_e2e_dev_env();
538
- }
539
- });
540
-
541
462
  // src/cli/resolve-v1-secret-store-directory/resolve-v1-secret-store-directory.ts
542
463
  import * as os2 from "node:os";
543
464
  import * as path2 from "node:path";
@@ -576,7 +497,6 @@ var init_resolve_v1_secret_store_directory2 = __esm({
576
497
  var init_cli = __esm({
577
498
  "src/cli/index.ts"() {
578
499
  "use strict";
579
- init_e2e_bin2();
580
500
  init_read_env_base_url2();
581
501
  init_read_env_api_base2();
582
502
  init_read_env_auth_issuer2();
@@ -588,7 +508,6 @@ var init_cli = __esm({
588
508
  init_read_env_disable_id_shim2();
589
509
  init_read_env_discovery2();
590
510
  init_read_env_strict2();
591
- init_read_e2e_dev_env2();
592
511
  init_resolve_v1_secret_store_directory2();
593
512
  }
594
513
  });
@@ -4091,10 +4010,33 @@ var init_file_secret_store2 = __esm({
4091
4010
  });
4092
4011
 
4093
4012
  // src/key-lease/host-storage-secret-store/host-storage-secret-store.ts
4013
+ var HostStorageSecretStore;
4094
4014
  var init_host_storage_secret_store = __esm({
4095
4015
  "src/key-lease/host-storage-secret-store/host-storage-secret-store.ts"() {
4096
4016
  "use strict";
4097
4017
  init_adapters();
4018
+ HostStorageSecretStore = class {
4019
+ #key;
4020
+ #storage;
4021
+ constructor(options) {
4022
+ this.#key = options.key;
4023
+ this.#storage = options.storage;
4024
+ }
4025
+ /** Reads and parses the scoped gateway credential.
4026
+ * @returns The persisted credential, when present.
4027
+ */
4028
+ async get() {
4029
+ const value = await this.#storage.get(this.#key);
4030
+ return value === void 0 ? void 0 : parseGatewayKey(value);
4031
+ }
4032
+ /** Writes the scoped gateway credential only through host-owned storage.
4033
+ * @param key - The credential to persist, or undefined to remove it.
4034
+ * @returns A promise that settles after the host write or removal.
4035
+ */
4036
+ set(key) {
4037
+ return key === void 0 ? this.#storage.remove(this.#key) : this.#storage.set(this.#key, key.value);
4038
+ }
4039
+ };
4098
4040
  }
4099
4041
  });
4100
4042
 
@@ -5288,7 +5230,7 @@ var init_lease_installation_factory = __esm({
5288
5230
  return existing;
5289
5231
  }
5290
5232
  const installation = {
5291
- keyName: `route33:lease:${scopeId}`,
5233
+ keyName: `route33_lease_${scopeId}`,
5292
5234
  secretStore: options.createSecretStore(scopeId),
5293
5235
  ...options.createStateStore === void 0 ? {} : { stateStore: options.createStateStore(scopeId) },
5294
5236
  state: LeaseState.restore(void 0)
@@ -5877,11 +5819,14 @@ var init_route33_runtime = __esm({
5877
5819
  * member-visible project listing, organisation names stitched from the
5878
5820
  * login's own memberships. Orgs the login merely administers carry no
5879
5821
  * budget row and drop out — the picker never offers a project whose
5880
- * keys the login cannot create.
5822
+ * keys the login cannot create. A `allowBrowser: false` policy makes
5823
+ * the call non-blocking: a dead session rejects instead of opening a
5824
+ * browser, so the picker's form registration never stalls a boot.
5825
+ * @param policy - Whether a dead session may open a browser login.
5881
5826
  * @returns Mintable projects with organisation context for the picker.
5882
5827
  */
5883
- async listMintableProjects() {
5884
- const credential = await this.#session.credential();
5828
+ async listMintableProjects(policy = {}) {
5829
+ const credential = await this.#session.credential(policy);
5885
5830
  const subject = this.#subject(credential);
5886
5831
  const client = this.#client();
5887
5832
  const [budgets, memberships] = await Promise.all([
@@ -7801,18 +7746,19 @@ var v2Autoconnect = async (context, options = {}) => {
7801
7746
  };
7802
7747
 
7803
7748
  // src/tui-entry/show-r33-menu/run-action/run-action.ts
7804
- var runR33MenuAction = (context, action) => {
7805
- const serverR33 = context.keymap?.commands?.().find(
7806
- (command) => command.id !== "route33.menu" && command.slash?.name === "r33"
7807
- );
7808
- if (serverR33?.id === void 0 || context.keymap?.dispatch === void 0) {
7749
+ var runR33MenuAction = async (context, action, deps) => {
7750
+ try {
7751
+ const reply = await executeR33Command({
7752
+ handlers: deps.handlers(),
7753
+ promptText: `/r33 ${action}`
7754
+ });
7755
+ context.ui.toast.show({ message: reply, variant: "info" });
7756
+ } catch (error) {
7809
7757
  context.ui.toast.show({
7810
- message: `Route 33 ${action} is unavailable \u2014 type /r33 ${action} in the prompt.`,
7758
+ message: error instanceof Error ? error.message : String(error),
7811
7759
  variant: "error"
7812
7760
  });
7813
- return;
7814
7761
  }
7815
- context.keymap.dispatch(serverR33.id, `r33 ${action}`);
7816
7762
  };
7817
7763
 
7818
7764
  // src/tui-entry/show-r33-menu/show-r33-menu.ts
@@ -7834,7 +7780,7 @@ var menuOptions2 = [
7834
7780
  value: "logout"
7835
7781
  }
7836
7782
  ];
7837
- var showR33Menu = async (context) => {
7783
+ var showR33Menu = async (context, deps) => {
7838
7784
  const selection = await context.ui.dialog.select({
7839
7785
  title: "Route 33 \u2014 choose an action",
7840
7786
  options: menuOptions2
@@ -7851,7 +7797,7 @@ var showR33Menu = async (context) => {
7851
7797
  await v2Autoconnect(context);
7852
7798
  return;
7853
7799
  }
7854
- runR33MenuAction(context, selection);
7800
+ await runR33MenuAction(context, selection, deps);
7855
7801
  };
7856
7802
 
7857
7803
  // src/tui-entry/v2-route33-model-candidate/v2-route33-model-candidate.ts
@@ -7909,11 +7855,12 @@ var v2AutoSelectModel = async ({
7909
7855
  // src/tui-entry/v2-boot-matrix/v2-boot-matrix.ts
7910
7856
  var v2BootMatrix = async ({
7911
7857
  probe,
7858
+ assumedAlive = false,
7912
7859
  attributed,
7913
7860
  globalFallback,
7914
7861
  wizard
7915
7862
  }) => {
7916
- if (await probe() === "dead") {
7863
+ if (!assumedAlive && await probe() === "dead") {
7917
7864
  return { kind: "silent" };
7918
7865
  }
7919
7866
  if (attributed()) {
@@ -7926,6 +7873,16 @@ var v2BootMatrix = async ({
7926
7873
  return { kind: "wizard-settled" };
7927
7874
  };
7928
7875
 
7876
+ // src/tui-entry/v2-boot-reentry/v2-boot-reentry.ts
7877
+ var registerV2BootReentry = (deps) => {
7878
+ deps.listen?.((event) => {
7879
+ if (!event.details.type.includes("integration")) return;
7880
+ if (deps.superseded()) return;
7881
+ if (!deps.pending()) return;
7882
+ void deps.start().catch(() => void 0);
7883
+ });
7884
+ };
7885
+
7929
7886
  // src/v2-entry/connect-copy/connect-copy.ts
7930
7887
  var CONNECT_COPY = {
7931
7888
  failFastClientId: "This Route 33 build has no OAuth client id. Reinstall it from the opencode-dist ref, or set ROUTE33_CLIENT_ID and restart OpenCode.",
@@ -7936,7 +7893,7 @@ var CONNECT_COPY = {
7936
7893
 
7937
7894
  // src/v2-entry/resolve-host-credential/resolve-host-credential.ts
7938
7895
  init_config();
7939
- var NO_USABLE_LEASE_MESSAGE = "Route 33 authorization completed without a usable gateway lease";
7896
+ var NO_USABLE_LEASE_MESSAGE = "Signed in to Route 33 \u2713. One more step: this folder has no gateway key yet \u2014 pick its budget to finish setup.";
7940
7897
 
7941
7898
  // src/tui-entry/v2-session-probe/v2-session-probe.ts
7942
7899
  var v2SessionProbe = async ({
@@ -8020,12 +7977,12 @@ var v2SetupLock = (deps) => {
8020
7977
  });
8021
7978
  }
8022
7979
  let running = false;
8023
- const settle = async () => {
7980
+ const settle = async (options) => {
8024
7981
  if (running) return;
8025
7982
  running = true;
8026
7983
  try {
8027
7984
  if (deps.pending()) {
8028
- await deps.run();
7985
+ await deps.run(options);
8029
7986
  }
8030
7987
  } finally {
8031
7988
  running = false;
@@ -8036,6 +7993,115 @@ var v2SetupLock = (deps) => {
8036
7993
  return { start: settle };
8037
7994
  };
8038
7995
 
7996
+ // src/tui-entry/v2-tui-runtime/v2-tui-runtime.ts
7997
+ init_cli();
7998
+ init_host_storage_secret_store2();
7999
+ init_key_lease();
8000
+ init_requested_client_id2();
8001
+ init_route33_runtime2();
8002
+ init_shared();
8003
+
8004
+ // src/v2-entry/host-lease-state-store/host-lease-state-store.ts
8005
+ init_adapters();
8006
+ init_lease_state2();
8007
+ var hostLeaseStateStore = (options) => ({
8008
+ get: async () => {
8009
+ const value = await options.storage.get(options.key);
8010
+ if (value === void 0) {
8011
+ return void 0;
8012
+ }
8013
+ if (typeof value !== "string") {
8014
+ throw new ContractParseError("lease metadata must be a JSON string");
8015
+ }
8016
+ return LeaseState.restore(JSON.parse(value)).snapshot();
8017
+ },
8018
+ set: async (state) => {
8019
+ if (state === void 0) {
8020
+ await options.storage.remove(options.key);
8021
+ return;
8022
+ }
8023
+ await options.storage.set(options.key, JSON.stringify(state));
8024
+ }
8025
+ });
8026
+
8027
+ // src/v2-entry/host-token-store/host-token-store.ts
8028
+ var DEFAULT_TOKEN_KEY = "route33_auth";
8029
+ var LEGACY_TOKEN_KEY = "route33:auth";
8030
+ var hostTokenStore = (options) => {
8031
+ const key = options.key ?? DEFAULT_TOKEN_KEY;
8032
+ return {
8033
+ get: async () => {
8034
+ const value = await options.storage.get(key);
8035
+ if (typeof value === "string") {
8036
+ return value;
8037
+ }
8038
+ const legacy = await options.storage.get(LEGACY_TOKEN_KEY);
8039
+ return typeof legacy === "string" ? legacy : void 0;
8040
+ },
8041
+ set: async (value) => {
8042
+ if (value === void 0) {
8043
+ await options.storage.remove(key);
8044
+ } else {
8045
+ await options.storage.set(key, value);
8046
+ }
8047
+ await options.storage.remove(LEGACY_TOKEN_KEY);
8048
+ }
8049
+ };
8050
+ };
8051
+
8052
+ // src/tui-entry/v2-tui-box-storage/v2-tui-box-storage.ts
8053
+ var v2TuiBoxStorage = (options) => {
8054
+ const [box, mutate] = options.storage.store(options.key, { initial: {} });
8055
+ return {
8056
+ get: () => Promise.resolve(box.value),
8057
+ remove: async () => {
8058
+ await mutate((draft) => {
8059
+ draft.value = void 0;
8060
+ });
8061
+ },
8062
+ set: async (_key, value) => {
8063
+ await mutate((draft) => {
8064
+ draft.value = value;
8065
+ });
8066
+ }
8067
+ };
8068
+ };
8069
+
8070
+ // src/tui-entry/v2-tui-runtime/v2-tui-runtime.ts
8071
+ var composeV2TuiRuntime = (context) => {
8072
+ const { storage } = context;
8073
+ if (storage === void 0) {
8074
+ return void 0;
8075
+ }
8076
+ const box = (key) => v2TuiBoxStorage({ key, storage });
8077
+ const location = context.location ?? context.data?.location.default();
8078
+ const clientId = readEnvClientId() ?? DEFAULT_ROUTE33_CLIENT_ID;
8079
+ const production = buildProductionRuntimeOptions({
8080
+ apiBaseUrl: readEnvApiBase() ?? DEFAULT_MANAGEMENT_API_BASE_URL,
8081
+ clientId,
8082
+ issuerUrl: readEnvAuthIssuer() ?? DEFAULT_AUTH_ISSUER_URL,
8083
+ tokenStore: hostTokenStore({ storage: box("route33_auth") })
8084
+ });
8085
+ return new Route33Runtime({
8086
+ ...production,
8087
+ auth: { ...production.auth, clientId },
8088
+ installation: createLeaseInstallationFactory({
8089
+ createSecretStore: (scopeId) => new HostStorageSecretStore({
8090
+ key: `route33_lease_${scopeId}`,
8091
+ storage: box(`route33_lease_${scopeId}`)
8092
+ }),
8093
+ createStateStore: (scopeId) => hostLeaseStateStore({
8094
+ key: `route33_lease_${scopeId}_state`,
8095
+ storage: box(`route33_lease_${scopeId}_state`)
8096
+ })
8097
+ }),
8098
+ state: {
8099
+ directory: location?.directory ?? "",
8100
+ outsideWorktree: "return-undefined"
8101
+ }
8102
+ });
8103
+ };
8104
+
8039
8105
  // src/tui-entry/v2-wizard-control/v2-wizard-control.ts
8040
8106
  var v2WizardControl = () => {
8041
8107
  let menuRequested = false;
@@ -8054,6 +8120,8 @@ var v2WizardControl = () => {
8054
8120
  var createV2Tui = () => ({
8055
8121
  id: "route33",
8056
8122
  setup: (context) => {
8123
+ const tuiRuntime = composeV2TuiRuntime(context);
8124
+ const menuHandlers = () => tuiRuntime?.commandHandlers();
8057
8125
  context.keymap?.layer(() => ({
8058
8126
  mode: "global",
8059
8127
  priority: 10,
@@ -8070,7 +8138,7 @@ var createV2Tui = () => ({
8070
8138
  run: async () => {
8071
8139
  wizard.menuRequested();
8072
8140
  try {
8073
- await showR33Menu(context);
8141
+ await showR33Menu(context, { handlers: menuHandlers });
8074
8142
  } finally {
8075
8143
  wizard.menuClosed();
8076
8144
  }
@@ -8110,8 +8178,9 @@ var createV2Tui = () => ({
8110
8178
  switchModel: (input) => client.session?.switchModel?.(input) ?? Promise.resolve()
8111
8179
  });
8112
8180
  };
8113
- const boot = async () => {
8181
+ const boot = async (options) => {
8114
8182
  const outcome = await v2BootMatrix({
8183
+ assumedAlive: options?.assumedAlive === true,
8115
8184
  attributed,
8116
8185
  globalFallback: async () => {
8117
8186
  const silent = await globalFallback();
@@ -8124,7 +8193,13 @@ var createV2Tui = () => ({
8124
8193
  locationInput: { directory },
8125
8194
  status
8126
8195
  }),
8127
- wizard: () => v2Autoconnect(context, { superseded: wizard.superseded })
8196
+ wizard: () => v2Autoconnect(
8197
+ // The wizard re-derives its directory from the context
8198
+ // location, which is undefined until the first route lands —
8199
+ // inject the boot location so the budget picker opens.
8200
+ { ...context, location },
8201
+ { superseded: wizard.superseded }
8202
+ )
8128
8203
  });
8129
8204
  if (outcome.kind === "wizard-settled") {
8130
8205
  void autoSelect().catch(() => void 0);
@@ -8144,13 +8219,11 @@ var createV2Tui = () => ({
8144
8219
  run: boot
8145
8220
  });
8146
8221
  void lock.start().catch(() => void 0);
8147
- context.data?.listen?.((event) => {
8148
- if (!event.details.type.includes("integration")) return;
8149
- if (wizard.superseded()) return;
8150
- if (v2SetupDirectory({ location: { directory } }) === void 0) {
8151
- return;
8152
- }
8153
- void lock.start().catch(() => void 0);
8222
+ registerV2BootReentry({
8223
+ listen: context.data?.listen,
8224
+ pending: () => v2SetupDirectory({ location: { directory } }) !== void 0,
8225
+ start: () => lock.start({ assumedAlive: true }),
8226
+ superseded: wizard.superseded
8154
8227
  });
8155
8228
  }
8156
8229
  });
@@ -2553,7 +2553,7 @@ var createLeaseInstallationFactory = (options) => {
2553
2553
  return existing;
2554
2554
  }
2555
2555
  const installation = {
2556
- keyName: `route33:lease:${scopeId}`,
2556
+ keyName: `route33_lease_${scopeId}`,
2557
2557
  secretStore: options.createSecretStore(scopeId),
2558
2558
  ...options.createStateStore === void 0 ? {} : { stateStore: options.createStateStore(scopeId) },
2559
2559
  state: LeaseState.restore(void 0)
@@ -2871,11 +2871,14 @@ var Route33Runtime = class {
2871
2871
  * member-visible project listing, organisation names stitched from the
2872
2872
  * login's own memberships. Orgs the login merely administers carry no
2873
2873
  * budget row and drop out — the picker never offers a project whose
2874
- * keys the login cannot create.
2874
+ * keys the login cannot create. A `allowBrowser: false` policy makes
2875
+ * the call non-blocking: a dead session rejects instead of opening a
2876
+ * browser, so the picker's form registration never stalls a boot.
2877
+ * @param policy - Whether a dead session may open a browser login.
2875
2878
  * @returns Mintable projects with organisation context for the picker.
2876
2879
  */
2877
- async listMintableProjects() {
2878
- const credential = await this.#session.credential();
2880
+ async listMintableProjects(policy = {}) {
2881
+ const credential = await this.#session.credential(policy);
2879
2882
  const subject = this.#subject(credential);
2880
2883
  const client = this.#client();
2881
2884
  const [budgets, memberships] = await Promise.all([
@@ -4082,7 +4085,6 @@ var bootstrapProvider = async (deps, sink) => {
4082
4085
  try {
4083
4086
  await runtime2.login({ allowBrowser: false });
4084
4087
  } catch {
4085
- return;
4086
4088
  }
4087
4089
  await deps.registerProjectForm().catch(() => void 0);
4088
4090
  try {
@@ -4203,39 +4205,31 @@ var createConnectAuthorize = (deps) => async (answer = {}) => {
4203
4205
  if (detectWorktreeRoot(deps.directory) === void 0) {
4204
4206
  throw new GatewayCredentialError(CONNECT_COPY.failFastWorktree);
4205
4207
  }
4206
- await applyWizardAnswer(deps, answer);
4207
- if (readAttribution(deps.state) !== void 0) {
4208
- const callback2 = deps.resolveCredential();
4209
- const decision2 = await deps.stash.urlForConnect(
4210
- callback2.then(() => void 0)
4211
- );
4212
- return {
4213
- callback: callback2,
4214
- instructions: decision2.instructions,
4215
- mode: "auto",
4216
- url: decision2.url
4217
- };
4218
- }
4219
- const runtime2 = deps.getRuntime();
4220
- if (runtime2 === void 0) {
4221
- throw new GatewayCredentialError(
4222
- "Route 33 authorization is unavailable in this host"
4223
- );
4224
- }
4225
4208
  const callback = (async () => {
4226
- await runtime2.login();
4227
- try {
4228
- return await deps.resolveCredential();
4229
- } catch (error) {
4230
- if (error instanceof AttributionPromptError && error.code === "ATTRIBUTION_PRESENTER_UNAVAILABLE") {
4209
+ const emptyAnswer = Object.keys(answer).length === 0;
4210
+ if (emptyAnswer && readAttribution(deps.state) === void 0) {
4211
+ const runtime2 = deps.getRuntime();
4212
+ if (runtime2 === void 0) {
4213
+ throw new GatewayCredentialError(
4214
+ "Route 33 authorization is unavailable in this host"
4215
+ );
4216
+ }
4217
+ await runtime2.login();
4218
+ try {
4219
+ return await deps.resolveCredential();
4220
+ } catch {
4231
4221
  await deps.registerProjectForm();
4232
4222
  throw new GatewayCredentialError(CONNECT_COPY.signedInNextStep);
4233
4223
  }
4234
- throw error;
4235
4224
  }
4225
+ await applyWizardAnswer(deps, answer);
4226
+ if (readAttribution(deps.state) === void 0) {
4227
+ throw new GatewayCredentialError(CONNECT_COPY.selectionInvalid);
4228
+ }
4229
+ return deps.resolveCredential();
4236
4230
  })();
4237
4231
  const decision = await deps.stash.urlForConnect(
4238
- callback.catch(() => void 0)
4232
+ callback.then(() => void 0)
4239
4233
  );
4240
4234
  return {
4241
4235
  callback,
@@ -4347,20 +4341,29 @@ var hostLeaseStateStore = (options) => ({
4347
4341
  });
4348
4342
 
4349
4343
  // src/v2-entry/host-token-store/host-token-store.ts
4350
- var DEFAULT_TOKEN_KEY = "route33:auth";
4351
- var hostTokenStore = (options) => ({
4352
- get: async () => {
4353
- const value = await options.storage.get(options.key ?? DEFAULT_TOKEN_KEY);
4354
- return typeof value === "string" ? value : void 0;
4355
- },
4356
- set: async (value) => {
4357
- if (value === void 0) {
4358
- await options.storage.remove(options.key ?? DEFAULT_TOKEN_KEY);
4359
- return;
4344
+ var DEFAULT_TOKEN_KEY = "route33_auth";
4345
+ var LEGACY_TOKEN_KEY = "route33:auth";
4346
+ var hostTokenStore = (options) => {
4347
+ const key = options.key ?? DEFAULT_TOKEN_KEY;
4348
+ return {
4349
+ get: async () => {
4350
+ const value = await options.storage.get(key);
4351
+ if (typeof value === "string") {
4352
+ return value;
4353
+ }
4354
+ const legacy = await options.storage.get(LEGACY_TOKEN_KEY);
4355
+ return typeof legacy === "string" ? legacy : void 0;
4356
+ },
4357
+ set: async (value) => {
4358
+ if (value === void 0) {
4359
+ await options.storage.remove(key);
4360
+ } else {
4361
+ await options.storage.set(key, value);
4362
+ }
4363
+ await options.storage.remove(LEGACY_TOKEN_KEY);
4360
4364
  }
4361
- await options.storage.set(options.key ?? DEFAULT_TOKEN_KEY, value);
4362
- }
4363
- });
4365
+ };
4366
+ };
4364
4367
 
4365
4368
  // src/v2-entry/mint-and-refresh/mint-and-refresh.ts
4366
4369
  var mintAndRefresh = async (deps, attribution, extras) => {
@@ -4369,66 +4372,6 @@ var mintAndRefresh = async (deps, attribution, extras) => {
4369
4372
  return minted;
4370
4373
  };
4371
4374
 
4372
- // src/v2-entry/format-inspect-reply/format-inspect-reply.ts
4373
- var formatInspectReply = (inspection) => {
4374
- const lines = [];
4375
- if (inspection.attribution === void 0) {
4376
- return "Route 33 is not connected in this folder \u2014 run /connect or /r33 to set a budget.";
4377
- }
4378
- lines.push(
4379
- inspection.attribution.kind === "personal" ? "Budget: Personal" : `Budget: Project ${inspection.attribution.projectId}`
4380
- );
4381
- if (inspection.key !== void 0) {
4382
- const scope = inspection.key.projectName === null ? "your personal budget" : `${inspection.key.organisationName ?? "unknown organisation"} \xB7 ${inspection.key.projectName}`;
4383
- lines.push(`Key: ${inspection.key.name} on ${scope}`);
4384
- }
4385
- if (inspection.lease !== void 0) {
4386
- lines.push(`Expires: ${inspection.lease.expiresAt}`);
4387
- lines.push(`Key id: ${inspection.lease.keyId}`);
4388
- }
4389
- return lines.join("\n");
4390
- };
4391
-
4392
- // src/v2-entry/parse-r33-subcommand/parse-r33-subcommand.ts
4393
- var SUBCOMMANDS = ["inspect", "logout", "rotate", "reset"];
4394
- var parseR33Subcommand = (promptText) => {
4395
- const [first = "", ...rest] = promptText.trim().split(/\s+/u).filter(Boolean);
4396
- const name = first.replace(/^\/+/u, "").split(":")[0] ?? "";
4397
- const argument = name === "r33" ? rest[0] : first;
4398
- if (argument === void 0 || argument === "") {
4399
- return "inspect";
4400
- }
4401
- return SUBCOMMANDS.includes(argument) ? argument : "help";
4402
- };
4403
-
4404
- // src/v2-entry/r33-command/r33-command.ts
4405
- var executeR33Command = async (input) => {
4406
- const subcommand = parseR33Subcommand(input.promptText);
4407
- if (input.handlers === void 0) {
4408
- return "Route 33 is not connected in this folder. Run /connect, choose Route 33, and follow the steps.";
4409
- }
4410
- if (subcommand === "help") {
4411
- return "Route 33 usage: /r33 [inspect|rotate|reset|logout] \u2014 inspect shows attribution and key rotation, rotate rotates the key now, reset clears the assigned budget (assign again with /connect).";
4412
- }
4413
- switch (subcommand) {
4414
- case "rotate": {
4415
- const lease = await input.handlers["rotate-now"]();
4416
- return `Route 33 key rotated. Key ${lease.keyId} is valid until ${lease.expiresAt}.`;
4417
- }
4418
- case "logout": {
4419
- await input.handlers["logout"]();
4420
- return "Logged out of Route 33 \u2014 the next OpenCode start signs in again.";
4421
- }
4422
- case "reset": {
4423
- await input.handlers["reset-attribution"]();
4424
- return "Route 33 attribution cleared. Run /connect, choose Route 33, and assign a budget again.";
4425
- }
4426
- default: {
4427
- return formatInspectReply(await input.handlers["inspect-session"]());
4428
- }
4429
- }
4430
- };
4431
-
4432
4375
  // src/v2-entry/model-gate-notify-from/model-gate-notify-from.ts
4433
4376
  var notifyFrom = async (session, sessionID, message) => {
4434
4377
  await session.synthetic?.({ delivery: "queue", sessionID, text: message });
@@ -4522,7 +4465,7 @@ var registerRoute33ModelGate = async (deps) => deps.session.hook(
4522
4465
  );
4523
4466
 
4524
4467
  // src/v2-entry/resolve-host-credential/resolve-host-credential.ts
4525
- var NO_USABLE_LEASE_MESSAGE = "Route 33 authorization completed without a usable gateway lease";
4468
+ var NO_USABLE_LEASE_MESSAGE = "Signed in to Route 33 \u2713. One more step: this folder has no gateway key yet \u2014 pick its budget to finish setup.";
4526
4469
  var resolveHostCredential = async (deps) => {
4527
4470
  await deps.config();
4528
4471
  deps.onProvider(deps.parseProvider(void 0));
@@ -4576,11 +4519,11 @@ var createRoute33V2Plugin = (options = {}) => {
4576
4519
  };
4577
4520
  const installation = createLeaseInstallationFactory({
4578
4521
  createSecretStore: (scopeId) => new HostStorageSecretStore({
4579
- key: `route33:lease:${scopeId}`,
4522
+ key: `route33_lease_${scopeId}`,
4580
4523
  storage: context.storage
4581
4524
  }),
4582
4525
  createStateStore: (scopeId) => hostLeaseStateStore({
4583
- key: `route33:lease:${scopeId}:state`,
4526
+ key: `route33_lease_${scopeId}_state`,
4584
4527
  storage: context.storage
4585
4528
  })
4586
4529
  });
@@ -4626,7 +4569,7 @@ var createRoute33V2Plugin = (options = {}) => {
4626
4569
  return;
4627
4570
  }
4628
4571
  const [projects, modelIds, personalKeyActive] = await Promise.all([
4629
- activeRuntime.listMintableProjects(),
4572
+ activeRuntime.listMintableProjects({ allowBrowser: false }).catch(() => []),
4630
4573
  activeRuntime.catalogModelIds(),
4631
4574
  activeRuntime.hasPersonalLease().catch(() => false)
4632
4575
  ]);
@@ -4680,23 +4623,6 @@ var createRoute33V2Plugin = (options = {}) => {
4680
4623
  });
4681
4624
  }
4682
4625
  );
4683
- const commandTransform = await context.command.transform((editor) => {
4684
- editor.add({
4685
- description: "Route 33 actions: /r33 [inspect|rotate|reset|logout] \u2014 inspect shows attribution and key details, rotate rotates the key now, reset clears the assigned budget, logout signs out of Route 33",
4686
- execute: async ({ prompt, sessionID }) => {
4687
- const text = await executeR33Command({
4688
- handlers: runtime2?.commandHandlers(),
4689
- promptText: prompt.text
4690
- });
4691
- await context.session.synthetic({
4692
- delivery: "queue",
4693
- sessionID,
4694
- text
4695
- });
4696
- },
4697
- name: "r33"
4698
- });
4699
- });
4700
4626
  const sessionHook = await context.session.hook(
4701
4627
  "http.request",
4702
4628
  createWorkspaceKeyHook({
@@ -4730,7 +4656,6 @@ var createRoute33V2Plugin = (options = {}) => {
4730
4656
  ]);
4731
4657
  return async () => {
4732
4658
  await Promise.all([
4733
- commandTransform.dispose(),
4734
4659
  integrationTransform.dispose(),
4735
4660
  providerTransform.dispose(),
4736
4661
  sessionHook.dispose(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r-33/opencode",
3
- "version": "0.4.7-rc.24",
3
+ "version": "0.4.7-rc.26",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,8 +46,8 @@
46
46
  "eslint": "10.13.0",
47
47
  "typescript": "6.0.3",
48
48
  "vitest": "5.0.5",
49
- "@cronos-ai-lab/typescript-config": "0.2.1-rc.2",
50
- "@cronos-ai-lab/eslint-config": "0.2.1-rc.2"
49
+ "@cronos-ai-lab/eslint-config": "0.2.1-rc.2",
50
+ "@cronos-ai-lab/typescript-config": "0.2.1-rc.2"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "esbuild src/index.ts src/v2-entry/index.ts src/tui-entry/index.ts src/cli/production-smoke/production-smoke.ts --bundle --format=esm --platform=node --packages=external --outbase=src --outdir=dist --alias:@opencode-ai/plugin-v2=@opencode/plugin --define:__ROUTE33_DEFAULT_CLIENT_ID__=\\\"${ROUTE33_DEFAULT_CLIENT_ID:-}\\\"",