@r-33/opencode 0.4.7-rc.23 → 0.4.7-rc.25

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.
@@ -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)
@@ -5662,7 +5604,7 @@ var REQUESTED_OAUTH_SCOPES;
5662
5604
  var init_requested_scopes = __esm({
5663
5605
  "src/requested-scopes/requested-scopes.ts"() {
5664
5606
  "use strict";
5665
- REQUESTED_OAUTH_SCOPES = "openid offline_access orgs:read projects:read keys:read keys:write";
5607
+ REQUESTED_OAUTH_SCOPES = "openid offline_access orgs:read projects:read users:read keys:read keys:write";
5666
5608
  }
5667
5609
  });
5668
5610
 
@@ -5871,6 +5813,56 @@ var init_route33_runtime = __esm({
5871
5813
  login(policy = {}) {
5872
5814
  return this.#session.result(policy);
5873
5815
  }
5816
+ /**
5817
+ * Lists exactly the projects the current management login can mint keys
5818
+ * on: the login's per-user budget rows intersected with the
5819
+ * member-visible project listing, organisation names stitched from the
5820
+ * login's own memberships. Orgs the login merely administers carry no
5821
+ * budget row and drop out — the picker never offers a project whose
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.
5826
+ * @returns Mintable projects with organisation context for the picker.
5827
+ */
5828
+ async listMintableProjects(policy = {}) {
5829
+ const credential = await this.#session.credential(policy);
5830
+ const subject = this.#subject(credential);
5831
+ const client = this.#client();
5832
+ const [budgets, memberships] = await Promise.all([
5833
+ client.listProjectBudgets(credential, subject),
5834
+ client.listMemberships(credential, subject)
5835
+ ]);
5836
+ const organisationNames = new Map(
5837
+ memberships.org_memberships.map(({ org_id, org_name }) => [
5838
+ org_id,
5839
+ org_name
5840
+ ])
5841
+ );
5842
+ const listings = await Promise.all(
5843
+ [...new Set(budgets.data.map(({ org_id }) => org_id))].map(
5844
+ (orgId) => client.listProjects(credential, orgId)
5845
+ )
5846
+ );
5847
+ const projectsById = new Map(
5848
+ listings.flatMap(({ data }) => data).map((project) => [project.id, project])
5849
+ );
5850
+ return budgets.data.flatMap(({ org_id, project_id }) => {
5851
+ const project = projectsById.get(project_id);
5852
+ if (project === void 0) {
5853
+ return [];
5854
+ }
5855
+ return [
5856
+ {
5857
+ ...project,
5858
+ organisation: {
5859
+ id: org_id,
5860
+ name: organisationNames.get(org_id) ?? org_id
5861
+ }
5862
+ }
5863
+ ];
5864
+ });
5865
+ }
5874
5866
  /**
5875
5867
  * Lists projects visible to the current management login.
5876
5868
  * @returns Projects with their listing organisation stitched in.
@@ -6110,7 +6102,7 @@ var init_route33_runtime = __esm({
6110
6102
  return resolveAttribution({
6111
6103
  loadProjects: async () => {
6112
6104
  await this.#session.credential();
6113
- return this.listProjects();
6105
+ return this.listMintableProjects();
6114
6106
  },
6115
6107
  ...this.#options.presenter === void 0 ? {} : { presenter: this.#options.presenter },
6116
6108
  state: this.#options.state
@@ -6357,6 +6349,34 @@ init_cli();
6357
6349
  // src/production-runtime-options/production-runtime-options.ts
6358
6350
  import { createAuthSession } from "@r-33/auth-browser";
6359
6351
 
6352
+ // src/management/drain-pages/drain-pages.ts
6353
+ var drainPages = async (fetchPage) => {
6354
+ const first = await fetchPage("");
6355
+ const data = [...first.data];
6356
+ let { page } = first;
6357
+ while (page.has_more && page.next_cursor !== null) {
6358
+ const next = await fetchPage(page.next_cursor);
6359
+ data.push(...next.data);
6360
+ ({ page } = next);
6361
+ }
6362
+ return { data, page: { ...page, has_more: false, next_cursor: null } };
6363
+ };
6364
+
6365
+ // src/management/management-error/management-error.ts
6366
+ var ManagementError = class extends Error {
6367
+ constructor(code, options) {
6368
+ super(
6369
+ "Route 33 management request failed",
6370
+ options?.cause === void 0 ? void 0 : { cause: "Route 33 management dependency failed" }
6371
+ );
6372
+ this.code = code;
6373
+ this.name = "ManagementError";
6374
+ this.statusCode = options?.statusCode;
6375
+ }
6376
+ code;
6377
+ statusCode;
6378
+ };
6379
+
6360
6380
  // src/management/sdk-management-keys/sdk-management-keys.ts
6361
6381
  init_adapters();
6362
6382
  import {
@@ -6533,6 +6553,41 @@ var parseOrganization = (value) => {
6533
6553
  };
6534
6554
  };
6535
6555
 
6556
+ // src/contract/management-keys/parse-project-budget-state/parse-project-budget-state.ts
6557
+ init_adapters();
6558
+ init_predicates();
6559
+ var parseProjectBudgetState = (value) => {
6560
+ if (!isRecord(value)) {
6561
+ throw new ContractParseError("invalid project budget");
6562
+ }
6563
+ const stringField = (name) => {
6564
+ const field = value[name];
6565
+ if (typeof field !== "string") {
6566
+ throw new ContractParseError("invalid project budget");
6567
+ }
6568
+ return field;
6569
+ };
6570
+ const cap = value["cap"];
6571
+ if (typeof cap !== "number") {
6572
+ throw new ContractParseError("invalid project budget");
6573
+ }
6574
+ const hasUsage = value["has_usage"];
6575
+ if (typeof hasUsage !== "boolean") {
6576
+ throw new ContractParseError("invalid project budget");
6577
+ }
6578
+ const source = value["source"];
6579
+ if (source !== "own_cap" && source !== "project_default" && source !== "org_default" && source !== "tenant_default" && source !== "platform_default") {
6580
+ throw new ContractParseError("invalid project budget");
6581
+ }
6582
+ return {
6583
+ cap,
6584
+ has_usage: hasUsage,
6585
+ org_id: stringField("org_id"),
6586
+ project_id: stringField("project_id"),
6587
+ source
6588
+ };
6589
+ };
6590
+
6536
6591
  // src/contract/management-keys/parse-project/parse-project.ts
6537
6592
  init_adapters();
6538
6593
  init_predicates();
@@ -6560,19 +6615,30 @@ var parseProject = (value) => {
6560
6615
  };
6561
6616
  };
6562
6617
 
6563
- // src/management/management-error/management-error.ts
6564
- var ManagementError = class extends Error {
6565
- constructor(code, options) {
6566
- super(
6567
- "Route 33 management request failed",
6568
- options?.cause === void 0 ? void 0 : { cause: "Route 33 management dependency failed" }
6569
- );
6570
- this.code = code;
6571
- this.name = "ManagementError";
6572
- this.statusCode = options?.statusCode;
6618
+ // src/contract/management-keys/parse-user-memberships/parse-user-memberships.ts
6619
+ init_adapters();
6620
+ init_predicates();
6621
+ var parseUserMemberships = (value) => {
6622
+ if (!isRecord(value)) {
6623
+ throw new ContractParseError("invalid user memberships");
6573
6624
  }
6574
- code;
6575
- statusCode;
6625
+ const rows = value["org_memberships"];
6626
+ if (!Array.isArray(rows)) {
6627
+ throw new ContractParseError("invalid user memberships");
6628
+ }
6629
+ return {
6630
+ org_memberships: rows.map((row) => {
6631
+ if (!isRecord(row)) {
6632
+ throw new ContractParseError("invalid user memberships");
6633
+ }
6634
+ const orgId = row["org_id"];
6635
+ const orgName = row["org_name"];
6636
+ if (typeof orgId !== "string" || typeof orgName !== "string") {
6637
+ throw new ContractParseError("invalid user memberships");
6638
+ }
6639
+ return { org_id: orgId, org_name: orgName };
6640
+ })
6641
+ };
6576
6642
  };
6577
6643
 
6578
6644
  // src/management/sdk-management-keys/sdk-management-keys.ts
@@ -6671,26 +6737,42 @@ var sdkManagementKeys = (options) => {
6671
6737
  await call(accessToken, (client) => client.GET("/api/v1/orgs", {})),
6672
6738
  parseOrganization
6673
6739
  ),
6740
+ listMemberships: async (accessToken, userId) => parseUserMemberships(
6741
+ await call(
6742
+ accessToken,
6743
+ (client) => client.GET("/api/v1/users/{user_id}/memberships", {
6744
+ params: { path: { user_id: userId } }
6745
+ })
6746
+ )
6747
+ ),
6748
+ listProjectBudgets: async (accessToken, userId) => parseCollection(
6749
+ await call(
6750
+ accessToken,
6751
+ (client) => client.GET("/api/v1/users/{user_id}/project-budgets", {
6752
+ params: { path: { user_id: userId } }
6753
+ })
6754
+ ),
6755
+ parseProjectBudgetState
6756
+ ),
6674
6757
  listProjects: async (accessToken, organisationId) => {
6675
6758
  if (organisationId.trim().length === 0) {
6676
6759
  throw new ManagementError("MANAGEMENT_ORGANISATION_ID_REQUIRED", {
6677
6760
  statusCode: 400
6678
6761
  });
6679
6762
  }
6680
- return parseCollection(
6681
- await call(
6682
- accessToken,
6683
- (client) => client.GET("/api/v1/projects", {
6684
- params: {
6685
- query: {
6686
- member_user_id: parseManagementSubject(accessToken),
6687
- org_id: organisationId
6688
- }
6689
- }
6690
- })
6691
- ),
6692
- parseProject
6693
- );
6763
+ const query = {
6764
+ member_user_id: parseManagementSubject(accessToken),
6765
+ org_id: organisationId
6766
+ };
6767
+ const fetchPage = (cursor) => call(
6768
+ accessToken,
6769
+ (client) => client.GET("/api/v1/projects", {
6770
+ params: {
6771
+ query: cursor === "" ? query : { ...query, cursor }
6772
+ }
6773
+ })
6774
+ ).then((page) => parseCollection(page, parseProject));
6775
+ return drainPages(fetchPage);
6694
6776
  },
6695
6777
  regenerate: async (accessToken, id, expiresAt) => parseKeyMaterial(
6696
6778
  await call(
@@ -7326,6 +7408,13 @@ var answerPass = async (deps) => {
7326
7408
  });
7327
7409
  return;
7328
7410
  }
7411
+ const openUrl = () => {
7412
+ try {
7413
+ void deps.openSystemBrowser(new URL(second.data.url)).catch(() => void 0);
7414
+ } catch {
7415
+ }
7416
+ };
7417
+ openUrl();
7329
7418
  const settled = await deps.pollTerminal(second.data.attemptID);
7330
7419
  if (settled.kind !== "complete") {
7331
7420
  deps.toast(v2OutcomeCopy(settled, V2_CONNECT_COPY.setupIncomplete));
@@ -7335,6 +7424,9 @@ var answerPass = async (deps) => {
7335
7424
  deps.toast({ message: V2_CONNECT_COPY.success, variant: "success" });
7336
7425
  };
7337
7426
 
7427
+ // src/tui-entry/v2-budget-picker/v2-budget-picker.ts
7428
+ import { openSystemBrowser } from "@r-33/auth-browser";
7429
+
7338
7430
  // src/tui-entry/v2-integration-surface/v2-integration-surface.ts
7339
7431
  var v2IntegrationSurface = (context) => context.client?.integration ?? context.client?.api?.integration;
7340
7432
 
@@ -7419,6 +7511,7 @@ var v2BudgetPicker = async (deps) => {
7419
7511
  }
7420
7512
  await answerPass({
7421
7513
  connect: deps.connect,
7514
+ openSystemBrowser: deps.openSystemBrowser ?? openSystemBrowser,
7422
7515
  dialog: deps.dialog,
7423
7516
  extras,
7424
7517
  form: deps.form,
@@ -7596,6 +7689,7 @@ var v2GuidedConnect = async (deps) => {
7596
7689
  dialog,
7597
7690
  form,
7598
7691
  locationInput,
7692
+ ...deps.openSystemBrowser === void 0 ? {} : { openSystemBrowser: deps.openSystemBrowser },
7599
7693
  pollTerminal,
7600
7694
  toast,
7601
7695
  unattributed
@@ -7658,24 +7752,26 @@ var v2Autoconnect = async (context, options = {}) => {
7658
7752
  }
7659
7753
  await v2GuidedConnect({
7660
7754
  context,
7755
+ ...options.openSystemBrowser === void 0 ? {} : { openSystemBrowser: options.openSystemBrowser },
7661
7756
  superseded: options.superseded,
7662
7757
  unattributed
7663
7758
  });
7664
7759
  };
7665
7760
 
7666
7761
  // src/tui-entry/show-r33-menu/run-action/run-action.ts
7667
- var runR33MenuAction = (context, action) => {
7668
- const serverR33 = context.keymap?.commands?.().find(
7669
- (command) => command.id !== "route33.menu" && command.slash?.name === "r33"
7670
- );
7671
- if (serverR33?.id === void 0 || context.keymap?.dispatch === void 0) {
7762
+ var runR33MenuAction = async (context, action, deps) => {
7763
+ try {
7764
+ const reply = await executeR33Command({
7765
+ handlers: deps.handlers(),
7766
+ promptText: `/r33 ${action}`
7767
+ });
7768
+ context.ui.toast.show({ message: reply, variant: "info" });
7769
+ } catch (error) {
7672
7770
  context.ui.toast.show({
7673
- message: `Route 33 ${action} is unavailable \u2014 type /r33 ${action} in the prompt.`,
7771
+ message: error instanceof Error ? error.message : String(error),
7674
7772
  variant: "error"
7675
7773
  });
7676
- return;
7677
7774
  }
7678
- context.keymap.dispatch(serverR33.id, `r33 ${action}`);
7679
7775
  };
7680
7776
 
7681
7777
  // src/tui-entry/show-r33-menu/show-r33-menu.ts
@@ -7697,7 +7793,7 @@ var menuOptions2 = [
7697
7793
  value: "logout"
7698
7794
  }
7699
7795
  ];
7700
- var showR33Menu = async (context) => {
7796
+ var showR33Menu = async (context, deps) => {
7701
7797
  const selection = await context.ui.dialog.select({
7702
7798
  title: "Route 33 \u2014 choose an action",
7703
7799
  options: menuOptions2
@@ -7711,10 +7807,12 @@ var showR33Menu = async (context) => {
7711
7807
  outsideWorktree: "return-undefined"
7712
7808
  });
7713
7809
  }
7714
- await v2Autoconnect(context);
7810
+ await v2Autoconnect(context, {
7811
+ ...deps.openSystemBrowser === void 0 ? {} : { openSystemBrowser: deps.openSystemBrowser }
7812
+ });
7715
7813
  return;
7716
7814
  }
7717
- runR33MenuAction(context, selection);
7815
+ await runR33MenuAction(context, selection, deps);
7718
7816
  };
7719
7817
 
7720
7818
  // src/tui-entry/v2-route33-model-candidate/v2-route33-model-candidate.ts
@@ -7772,12 +7870,14 @@ var v2AutoSelectModel = async ({
7772
7870
  // src/tui-entry/v2-boot-matrix/v2-boot-matrix.ts
7773
7871
  var v2BootMatrix = async ({
7774
7872
  probe,
7873
+ assumedAlive = false,
7775
7874
  attributed,
7776
7875
  globalFallback,
7777
7876
  wizard
7778
7877
  }) => {
7779
- if (await probe() === "dead") {
7780
- return { kind: "silent" };
7878
+ if (!assumedAlive && await probe() === "dead") {
7879
+ await wizard();
7880
+ return { kind: "wizard-settled" };
7781
7881
  }
7782
7882
  if (attributed()) {
7783
7883
  return { kind: "silent" };
@@ -7789,6 +7889,16 @@ var v2BootMatrix = async ({
7789
7889
  return { kind: "wizard-settled" };
7790
7890
  };
7791
7891
 
7892
+ // src/tui-entry/v2-boot-reentry/v2-boot-reentry.ts
7893
+ var registerV2BootReentry = (deps) => {
7894
+ deps.listen?.((event) => {
7895
+ if (!event.details.type.includes("integration")) return;
7896
+ if (deps.superseded()) return;
7897
+ if (!deps.pending()) return;
7898
+ void deps.start().catch(() => void 0);
7899
+ });
7900
+ };
7901
+
7792
7902
  // src/v2-entry/connect-copy/connect-copy.ts
7793
7903
  var CONNECT_COPY = {
7794
7904
  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.",
@@ -7799,7 +7909,7 @@ var CONNECT_COPY = {
7799
7909
 
7800
7910
  // src/v2-entry/resolve-host-credential/resolve-host-credential.ts
7801
7911
  init_config();
7802
- var NO_USABLE_LEASE_MESSAGE = "Route 33 authorization completed without a usable gateway lease";
7912
+ 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.";
7803
7913
 
7804
7914
  // src/tui-entry/v2-session-probe/v2-session-probe.ts
7805
7915
  var v2SessionProbe = async ({
@@ -7883,12 +7993,12 @@ var v2SetupLock = (deps) => {
7883
7993
  });
7884
7994
  }
7885
7995
  let running = false;
7886
- const settle = async () => {
7996
+ const settle = async (options) => {
7887
7997
  if (running) return;
7888
7998
  running = true;
7889
7999
  try {
7890
8000
  if (deps.pending()) {
7891
- await deps.run();
8001
+ await deps.run(options);
7892
8002
  }
7893
8003
  } finally {
7894
8004
  running = false;
@@ -7899,6 +8009,115 @@ var v2SetupLock = (deps) => {
7899
8009
  return { start: settle };
7900
8010
  };
7901
8011
 
8012
+ // src/tui-entry/v2-tui-runtime/v2-tui-runtime.ts
8013
+ init_cli();
8014
+ init_host_storage_secret_store2();
8015
+ init_key_lease();
8016
+ init_requested_client_id2();
8017
+ init_route33_runtime2();
8018
+ init_shared();
8019
+
8020
+ // src/v2-entry/host-lease-state-store/host-lease-state-store.ts
8021
+ init_adapters();
8022
+ init_lease_state2();
8023
+ var hostLeaseStateStore = (options) => ({
8024
+ get: async () => {
8025
+ const value = await options.storage.get(options.key);
8026
+ if (value === void 0) {
8027
+ return void 0;
8028
+ }
8029
+ if (typeof value !== "string") {
8030
+ throw new ContractParseError("lease metadata must be a JSON string");
8031
+ }
8032
+ return LeaseState.restore(JSON.parse(value)).snapshot();
8033
+ },
8034
+ set: async (state) => {
8035
+ if (state === void 0) {
8036
+ await options.storage.remove(options.key);
8037
+ return;
8038
+ }
8039
+ await options.storage.set(options.key, JSON.stringify(state));
8040
+ }
8041
+ });
8042
+
8043
+ // src/v2-entry/host-token-store/host-token-store.ts
8044
+ var DEFAULT_TOKEN_KEY = "route33_auth";
8045
+ var LEGACY_TOKEN_KEY = "route33:auth";
8046
+ var hostTokenStore = (options) => {
8047
+ const key = options.key ?? DEFAULT_TOKEN_KEY;
8048
+ return {
8049
+ get: async () => {
8050
+ const value = await options.storage.get(key);
8051
+ if (typeof value === "string") {
8052
+ return value;
8053
+ }
8054
+ const legacy = await options.storage.get(LEGACY_TOKEN_KEY);
8055
+ return typeof legacy === "string" ? legacy : void 0;
8056
+ },
8057
+ set: async (value) => {
8058
+ if (value === void 0) {
8059
+ await options.storage.remove(key);
8060
+ } else {
8061
+ await options.storage.set(key, value);
8062
+ }
8063
+ await options.storage.remove(LEGACY_TOKEN_KEY);
8064
+ }
8065
+ };
8066
+ };
8067
+
8068
+ // src/tui-entry/v2-tui-box-storage/v2-tui-box-storage.ts
8069
+ var v2TuiBoxStorage = (options) => {
8070
+ const [box, mutate] = options.storage.store(options.key, { initial: {} });
8071
+ return {
8072
+ get: () => Promise.resolve(box.value),
8073
+ remove: async () => {
8074
+ await mutate((draft) => {
8075
+ draft.value = void 0;
8076
+ });
8077
+ },
8078
+ set: async (_key, value) => {
8079
+ await mutate((draft) => {
8080
+ draft.value = value;
8081
+ });
8082
+ }
8083
+ };
8084
+ };
8085
+
8086
+ // src/tui-entry/v2-tui-runtime/v2-tui-runtime.ts
8087
+ var composeV2TuiRuntime = (context) => {
8088
+ const { storage } = context;
8089
+ if (storage === void 0) {
8090
+ return void 0;
8091
+ }
8092
+ const box = (key) => v2TuiBoxStorage({ key, storage });
8093
+ const location = context.location ?? context.data?.location.default();
8094
+ const clientId = readEnvClientId() ?? DEFAULT_ROUTE33_CLIENT_ID;
8095
+ const production = buildProductionRuntimeOptions({
8096
+ apiBaseUrl: readEnvApiBase() ?? DEFAULT_MANAGEMENT_API_BASE_URL,
8097
+ clientId,
8098
+ issuerUrl: readEnvAuthIssuer() ?? DEFAULT_AUTH_ISSUER_URL,
8099
+ tokenStore: hostTokenStore({ storage: box("route33_auth") })
8100
+ });
8101
+ return new Route33Runtime({
8102
+ ...production,
8103
+ auth: { ...production.auth, clientId },
8104
+ installation: createLeaseInstallationFactory({
8105
+ createSecretStore: (scopeId) => new HostStorageSecretStore({
8106
+ key: `route33_lease_${scopeId}`,
8107
+ storage: box(`route33_lease_${scopeId}`)
8108
+ }),
8109
+ createStateStore: (scopeId) => hostLeaseStateStore({
8110
+ key: `route33_lease_${scopeId}_state`,
8111
+ storage: box(`route33_lease_${scopeId}_state`)
8112
+ })
8113
+ }),
8114
+ state: {
8115
+ directory: location?.directory ?? "",
8116
+ outsideWorktree: "return-undefined"
8117
+ }
8118
+ });
8119
+ };
8120
+
7902
8121
  // src/tui-entry/v2-wizard-control/v2-wizard-control.ts
7903
8122
  var v2WizardControl = () => {
7904
8123
  let menuRequested = false;
@@ -7917,6 +8136,8 @@ var v2WizardControl = () => {
7917
8136
  var createV2Tui = () => ({
7918
8137
  id: "route33",
7919
8138
  setup: (context) => {
8139
+ const tuiRuntime = composeV2TuiRuntime(context);
8140
+ const menuHandlers = () => tuiRuntime?.commandHandlers();
7920
8141
  context.keymap?.layer(() => ({
7921
8142
  mode: "global",
7922
8143
  priority: 10,
@@ -7933,7 +8154,7 @@ var createV2Tui = () => ({
7933
8154
  run: async () => {
7934
8155
  wizard.menuRequested();
7935
8156
  try {
7936
- await showR33Menu(context);
8157
+ await showR33Menu(context, { handlers: menuHandlers });
7937
8158
  } finally {
7938
8159
  wizard.menuClosed();
7939
8160
  }
@@ -7973,8 +8194,9 @@ var createV2Tui = () => ({
7973
8194
  switchModel: (input) => client.session?.switchModel?.(input) ?? Promise.resolve()
7974
8195
  });
7975
8196
  };
7976
- const boot = async () => {
8197
+ const boot = async (options) => {
7977
8198
  const outcome = await v2BootMatrix({
8199
+ assumedAlive: options?.assumedAlive === true,
7978
8200
  attributed,
7979
8201
  globalFallback: async () => {
7980
8202
  const silent = await globalFallback();
@@ -7987,7 +8209,13 @@ var createV2Tui = () => ({
7987
8209
  locationInput: { directory },
7988
8210
  status
7989
8211
  }),
7990
- wizard: () => v2Autoconnect(context, { superseded: wizard.superseded })
8212
+ wizard: () => v2Autoconnect(
8213
+ // The wizard re-derives its directory from the context
8214
+ // location, which is undefined until the first route lands —
8215
+ // inject the boot location so the budget picker opens.
8216
+ { ...context, location },
8217
+ { superseded: wizard.superseded }
8218
+ )
7991
8219
  });
7992
8220
  if (outcome.kind === "wizard-settled") {
7993
8221
  void autoSelect().catch(() => void 0);
@@ -8007,13 +8235,11 @@ var createV2Tui = () => ({
8007
8235
  run: boot
8008
8236
  });
8009
8237
  void lock.start().catch(() => void 0);
8010
- context.data?.listen?.((event) => {
8011
- if (!event.details.type.includes("integration")) return;
8012
- if (wizard.superseded()) return;
8013
- if (v2SetupDirectory({ location: { directory } }) === void 0) {
8014
- return;
8015
- }
8016
- void lock.start().catch(() => void 0);
8238
+ registerV2BootReentry({
8239
+ listen: context.data?.listen,
8240
+ pending: () => v2SetupDirectory({ location: { directory } }) !== void 0,
8241
+ start: () => lock.start({ assumedAlive: true }),
8242
+ superseded: wizard.superseded
8017
8243
  });
8018
8244
  }
8019
8245
  });