@run402/sdk 4.97.0 → 4.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +2 -2
  2. package/core-dist/binding-file.d.ts +14 -0
  3. package/core-dist/binding-file.js +28 -1
  4. package/core-dist/wallet.js +3 -3
  5. package/dist/errors.d.ts +24 -2
  6. package/dist/errors.d.ts.map +1 -1
  7. package/dist/errors.js +44 -2
  8. package/dist/errors.js.map +1 -1
  9. package/dist/index.d.ts +18 -3
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +12 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/kernel.d.ts +34 -0
  14. package/dist/kernel.d.ts.map +1 -1
  15. package/dist/kernel.js +15 -1
  16. package/dist/kernel.js.map +1 -1
  17. package/dist/namespaces/admin.d.ts.map +1 -1
  18. package/dist/namespaces/admin.js +8 -0
  19. package/dist/namespaces/admin.js.map +1 -1
  20. package/dist/namespaces/agent.d.ts +2 -2
  21. package/dist/namespaces/agent.d.ts.map +1 -1
  22. package/dist/namespaces/agent.js +4 -0
  23. package/dist/namespaces/agent.js.map +1 -1
  24. package/dist/namespaces/agent.types.d.ts +5 -0
  25. package/dist/namespaces/agent.types.d.ts.map +1 -1
  26. package/dist/namespaces/apps.d.ts.map +1 -1
  27. package/dist/namespaces/apps.js +2 -0
  28. package/dist/namespaces/apps.js.map +1 -1
  29. package/dist/namespaces/auth.d.ts.map +1 -1
  30. package/dist/namespaces/auth.js +9 -0
  31. package/dist/namespaces/auth.js.map +1 -1
  32. package/dist/namespaces/branches.d.ts.map +1 -1
  33. package/dist/namespaces/branches.js +2 -0
  34. package/dist/namespaces/branches.js.map +1 -1
  35. package/dist/namespaces/ci.d.ts.map +1 -1
  36. package/dist/namespaces/ci.js +2 -0
  37. package/dist/namespaces/ci.js.map +1 -1
  38. package/dist/namespaces/credentials.d.ts +0 -23
  39. package/dist/namespaces/credentials.d.ts.map +1 -1
  40. package/dist/namespaces/credentials.js +29 -0
  41. package/dist/namespaces/credentials.js.map +1 -1
  42. package/dist/namespaces/escalations.d.ts.map +1 -1
  43. package/dist/namespaces/escalations.js +2 -0
  44. package/dist/namespaces/escalations.js.map +1 -1
  45. package/dist/namespaces/grants.d.ts.map +1 -1
  46. package/dist/namespaces/grants.js +4 -0
  47. package/dist/namespaces/grants.js.map +1 -1
  48. package/dist/namespaces/live.d.ts +0 -16
  49. package/dist/namespaces/live.d.ts.map +1 -1
  50. package/dist/namespaces/live.js +19 -0
  51. package/dist/namespaces/live.js.map +1 -1
  52. package/dist/namespaces/me.d.ts.map +1 -1
  53. package/dist/namespaces/me.js +3 -0
  54. package/dist/namespaces/me.js.map +1 -1
  55. package/dist/namespaces/org.d.ts.map +1 -1
  56. package/dist/namespaces/org.js +3 -0
  57. package/dist/namespaces/org.js.map +1 -1
  58. package/dist/namespaces/projects.d.ts.map +1 -1
  59. package/dist/namespaces/projects.js +5 -0
  60. package/dist/namespaces/projects.js.map +1 -1
  61. package/dist/namespaces/repos.d.ts.map +1 -1
  62. package/dist/namespaces/repos.js +5 -0
  63. package/dist/namespaces/repos.js.map +1 -1
  64. package/dist/namespaces/rooms.d.ts.map +1 -1
  65. package/dist/namespaces/rooms.js +3 -0
  66. package/dist/namespaces/rooms.js.map +1 -1
  67. package/dist/namespaces/session.d.ts.map +1 -1
  68. package/dist/namespaces/session.js +18 -0
  69. package/dist/namespaces/session.js.map +1 -1
  70. package/dist/namespaces/transfers.d.ts.map +1 -1
  71. package/dist/namespaces/transfers.js +3 -0
  72. package/dist/namespaces/transfers.js.map +1 -1
  73. package/dist/namespaces/wallets.d.ts.map +1 -1
  74. package/dist/namespaces/wallets.js +2 -0
  75. package/dist/namespaces/wallets.js.map +1 -1
  76. package/dist/namespaces/write-approval.d.ts.map +1 -1
  77. package/dist/namespaces/write-approval.js +3 -0
  78. package/dist/namespaces/write-approval.js.map +1 -1
  79. package/dist/node/actions-node.d.ts.map +1 -1
  80. package/dist/node/actions-node.js +3 -0
  81. package/dist/node/actions-node.js.map +1 -1
  82. package/dist/node/buzz-doctor-contract.d.ts +155 -0
  83. package/dist/node/buzz-doctor-contract.d.ts.map +1 -0
  84. package/dist/node/buzz-doctor-contract.js +385 -0
  85. package/dist/node/buzz-doctor-contract.js.map +1 -0
  86. package/dist/node/buzz-doctor.d.ts +155 -0
  87. package/dist/node/buzz-doctor.d.ts.map +1 -0
  88. package/dist/node/buzz-doctor.js +810 -0
  89. package/dist/node/buzz-doctor.js.map +1 -0
  90. package/dist/node/credentials.d.ts +9 -4
  91. package/dist/node/credentials.d.ts.map +1 -1
  92. package/dist/node/credentials.js +1 -1
  93. package/dist/node/credentials.js.map +1 -1
  94. package/dist/node/diagnostics.d.ts +45 -0
  95. package/dist/node/diagnostics.d.ts.map +1 -0
  96. package/dist/node/diagnostics.js +67 -0
  97. package/dist/node/diagnostics.js.map +1 -0
  98. package/dist/node/doctor.d.ts +101 -0
  99. package/dist/node/doctor.d.ts.map +1 -0
  100. package/dist/node/doctor.js +618 -0
  101. package/dist/node/doctor.js.map +1 -0
  102. package/dist/node/index.d.ts +57 -5
  103. package/dist/node/index.d.ts.map +1 -1
  104. package/dist/node/index.js +36 -1
  105. package/dist/node/index.js.map +1 -1
  106. package/dist/node/init.d.ts +137 -0
  107. package/dist/node/init.d.ts.map +1 -0
  108. package/dist/node/init.js +507 -0
  109. package/dist/node/init.js.map +1 -0
  110. package/dist/node/lightning-wallet.d.ts +61 -0
  111. package/dist/node/lightning-wallet.d.ts.map +1 -0
  112. package/dist/node/lightning-wallet.js +126 -0
  113. package/dist/node/lightning-wallet.js.map +1 -0
  114. package/dist/node/local-actions.d.ts +23 -0
  115. package/dist/node/local-actions.d.ts.map +1 -0
  116. package/dist/node/local-actions.js +38 -0
  117. package/dist/node/local-actions.js.map +1 -0
  118. package/dist/node/org-context.d.ts +169 -0
  119. package/dist/node/org-context.d.ts.map +1 -0
  120. package/dist/node/org-context.js +403 -0
  121. package/dist/node/org-context.js.map +1 -0
  122. package/dist/node/status.d.ts +62 -0
  123. package/dist/node/status.d.ts.map +1 -0
  124. package/dist/node/status.js +132 -0
  125. package/dist/node/status.js.map +1 -0
  126. package/dist/node/vault-target.d.ts +49 -0
  127. package/dist/node/vault-target.d.ts.map +1 -0
  128. package/dist/node/vault-target.js +109 -0
  129. package/dist/node/vault-target.js.map +1 -0
  130. package/dist/node/wallets.d.ts +242 -0
  131. package/dist/node/wallets.d.ts.map +1 -0
  132. package/dist/node/wallets.js +484 -0
  133. package/dist/node/wallets.js.map +1 -0
  134. package/dist/secret-gate.d.ts +377 -0
  135. package/dist/secret-gate.d.ts.map +1 -0
  136. package/dist/secret-gate.js +273 -0
  137. package/dist/secret-gate.js.map +1 -0
  138. package/package.json +2 -1
@@ -0,0 +1,126 @@
1
+ /**
2
+ * The agent's Lightning wallet on the local machine: mint the budgeted wallet
3
+ * on Run402's Hub, keep its pairing in the active profile's `wallet.json`
4
+ * beside the Base key, report its balance, revoke it. Shared by `r.init`
5
+ * (`run402 init lightning`) and `run402 wallets lightning …`. The pairing
6
+ * secret is never returned by anything here.
7
+ */
8
+ import { readWallet, saveWallet } from "../../core-dist/wallet.js";
9
+ import { LocalError } from "../errors.js";
10
+ export const LIGHTNING_MINT_TIMEOUT_MS = 45_000;
11
+ /** Public facts only: never the pairing. */
12
+ export function describeLightning(localWallet, wallet = null, balance = null) {
13
+ const local = localWallet?.lightning ?? null;
14
+ if (!local && !wallet)
15
+ return null;
16
+ return {
17
+ wallet_id: wallet?.wallet_id ?? local?.wallet_id ?? null,
18
+ status: wallet?.status ?? (local ? "active" : null),
19
+ custody: "run402_hub",
20
+ custody_note: "The sats sit on Run402's Lightning Hub; this wallet is a budgeted connection to them, not self-custody.",
21
+ lightning_address: wallet?.lightning_address ?? local?.lightning_address ?? null,
22
+ budget_sats: wallet?.budget_sats ?? local?.budget_sats ?? null,
23
+ starter_sats: wallet?.starter_sats ?? local?.starter_sats ?? null,
24
+ has_pairing: Boolean(local?.nwc),
25
+ minted_at: local?.minted_at ?? wallet?.activated_at ?? null,
26
+ ...(balance ? balance : {}),
27
+ };
28
+ }
29
+ /** Balance and remaining budget over NWC, best-effort (null on any failure). */
30
+ export async function readLightningBalance(localWallet) {
31
+ const nwc = localWallet?.lightning?.nwc;
32
+ if (!nwc)
33
+ return null;
34
+ try {
35
+ const { NwcWallet, closeNwcConnections } = await import("./nwc.js");
36
+ const wallet = new NwcWallet(nwc, { timeoutMs: 15_000 });
37
+ const [balance_sats, budget] = await Promise.all([wallet.getBalanceSats(), wallet.getBudgetSats().catch(() => null)]);
38
+ closeNwcConnections();
39
+ return {
40
+ balance_sats,
41
+ budget_remaining_sats: budget && budget.totalSats !== null ? budget.totalSats - budget.usedSats : null,
42
+ };
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ function storePairing(localWallet, wallet) {
49
+ const next = {
50
+ ...localWallet,
51
+ rail: "lightning",
52
+ lightning: {
53
+ wallet_id: wallet.wallet_id,
54
+ nwc: wallet.pairing,
55
+ lightning_address: wallet.lightning_address ?? null,
56
+ budget_sats: wallet.budget_sats,
57
+ starter_sats: wallet.starter_sats,
58
+ custody: "run402_hub",
59
+ minted_at: wallet.activated_at ?? new Date().toISOString(),
60
+ },
61
+ };
62
+ saveWallet(next);
63
+ return next;
64
+ }
65
+ /**
66
+ * Ensure the active profile holds an active Lightning wallet. `outcome` is
67
+ * `stored` (pairing just saved), `present` (already held locally), `minting`
68
+ * (the platform is still minting; rerun later), `unavailable` (no Hub on this
69
+ * gateway), `pairing_lost` (active, but its one-time pairing went to another
70
+ * machine: revoke and mint again), or the wallet's own non-active status.
71
+ */
72
+ export async function ensureLightningWallet(agent, options = {}) {
73
+ let localWallet = readWallet();
74
+ if (!localWallet) {
75
+ throw new LocalError("no local wallet configured; run `run402 init` first", "ensuring the Lightning wallet", { code: "LIGHTNING_WALLET_FAILED" });
76
+ }
77
+ if (localWallet.lightning?.nwc) {
78
+ let wallet = null;
79
+ try {
80
+ wallet = await agent.lightningWallet.get();
81
+ }
82
+ catch { /* an offline read is fine */ }
83
+ if (wallet && wallet.status !== "active")
84
+ return { localWallet, wallet, outcome: wallet.status };
85
+ return { localWallet, wallet, outcome: "present" };
86
+ }
87
+ let wallet;
88
+ try {
89
+ wallet = await agent.lightningWallet.mint({ timeoutMs: options.timeoutMs ?? LIGHTNING_MINT_TIMEOUT_MS });
90
+ }
91
+ catch (err) {
92
+ const code = err?.body?.code ?? err?.code;
93
+ if (code === "LIGHTNING_WALLET_NOT_AVAILABLE")
94
+ return { localWallet, wallet: null, outcome: "unavailable", error: err };
95
+ if (code === "LIGHTNING_WALLET_STILL_MINTING")
96
+ return { localWallet, wallet: null, outcome: "minting", error: err };
97
+ throw err;
98
+ }
99
+ if (wallet.status === "minting")
100
+ return { localWallet, wallet, outcome: "minting" };
101
+ if (wallet.status !== "active")
102
+ return { localWallet, wallet, outcome: wallet.status };
103
+ if (typeof wallet.pairing !== "string")
104
+ return { localWallet, wallet, outcome: "pairing_lost" };
105
+ localWallet = storePairing(localWallet, wallet);
106
+ return { localWallet, wallet, outcome: "stored" };
107
+ }
108
+ /** Revoke on the platform and forget the pairing locally; the rail returns to x402. */
109
+ export async function revokeLightningWallet(agent) {
110
+ const localWallet = readWallet();
111
+ let wallet = null;
112
+ try {
113
+ wallet = await agent.lightningWallet.revoke();
114
+ }
115
+ catch (err) {
116
+ const code = err?.body?.code ?? err?.code;
117
+ if (code !== "LIGHTNING_WALLET_NOT_FOUND")
118
+ throw err;
119
+ }
120
+ if (localWallet) {
121
+ const { lightning: _dropped, ...rest } = localWallet;
122
+ saveWallet({ ...rest, rail: rest.rail === "lightning" ? "x402" : rest.rail });
123
+ }
124
+ return wallet;
125
+ }
126
+ //# sourceMappingURL=lightning-wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lightning-wallet.js","sourceRoot":"","sources":["../../src/node/lightning-wallet.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAA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AAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAChF,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The bootstrap `next_actions` the Node SDK's local-state verbs author
3
+ * (`wallets.current`, `init`, `status`, `doctor`), in the one spelling every
4
+ * surface prints. Each is the literal CLI invocation plus why, the same shape
5
+ * the gateway's `next_actions` carry extended with `command`.
6
+ */
7
+ import type { NextAction } from "../errors.js";
8
+ export declare function localAction(type: string, fields?: {
9
+ command?: string;
10
+ why?: string;
11
+ method?: string;
12
+ path?: string;
13
+ auth?: string;
14
+ }): NextAction;
15
+ export declare function initializeWalletAction(): NextAction;
16
+ export declare function deployAction(): NextAction;
17
+ /**
18
+ * The cold-start deploy when the account holds no tier yet: `run402 up -y`
19
+ * sets the prototype tier itself as part of the first deploy, so `init`
20
+ * hands the agent ONE command instead of `tier set` + a separate deploy.
21
+ */
22
+ export declare function upDeployAction(): NextAction;
23
+ //# sourceMappingURL=local-actions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-actions.d.ts","sourceRoot":"","sources":["../../src/node/local-actions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,UAAU,CAMpJ;AAED,wBAAgB,sBAAsB,IAAI,UAAU,CAKnD;AAED,wBAAgB,YAAY,IAAI,UAAU,CAKzC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,UAAU,CAK3C"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The bootstrap `next_actions` the Node SDK's local-state verbs author
3
+ * (`wallets.current`, `init`, `status`, `doctor`), in the one spelling every
4
+ * surface prints. Each is the literal CLI invocation plus why, the same shape
5
+ * the gateway's `next_actions` carry extended with `command`.
6
+ */
7
+ export function localAction(type, fields = {}) {
8
+ const action = { type };
9
+ for (const key of ["command", "method", "path", "auth", "why"]) {
10
+ if (fields[key] !== undefined)
11
+ action[key] = fields[key];
12
+ }
13
+ return action;
14
+ }
15
+ export function initializeWalletAction() {
16
+ return localAction("initialize_wallet", {
17
+ command: "run402 init",
18
+ why: "Create and fund a local wallet, then retry.",
19
+ });
20
+ }
21
+ export function deployAction() {
22
+ return localAction("deploy", {
23
+ command: "run402 deploy --manifest app.json",
24
+ why: "Deploy your release manifest.",
25
+ });
26
+ }
27
+ /**
28
+ * The cold-start deploy when the account holds no tier yet: `run402 up -y`
29
+ * sets the prototype tier itself as part of the first deploy, so `init`
30
+ * hands the agent ONE command instead of `tier set` + a separate deploy.
31
+ */
32
+ export function upDeployAction() {
33
+ return localAction("deploy", {
34
+ command: "run402 up -y",
35
+ why: "Deploy with run402 up -y — it sets the prototype tier (free on testnet) as part of the first deploy. Or set it separately: run402 tier set prototype.",
36
+ });
37
+ }
38
+ //# sourceMappingURL=local-actions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-actions.js","sourceRoot":"","sources":["../../src/node/local-actions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,SAA4F,EAAE;IACtI,MAAM,MAAM,GAAe,EAAE,IAAI,EAAE,CAAC;IACpC,KAAK,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAU,EAAE,CAAC;QACxE,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,WAAW,CAAC,mBAAmB,EAAE;QACtC,OAAO,EAAE,aAAa;QACtB,GAAG,EAAE,6CAA6C;KACnD,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,YAAY;IAC1B,OAAO,WAAW,CAAC,QAAQ,EAAE;QAC3B,OAAO,EAAE,mCAAmC;QAC5C,GAAG,EAAE,+BAA+B;KACrC,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,WAAW,CAAC,QAAQ,EAAE;QAC3B,OAAO,EAAE,cAAc;QACvB,GAAG,EAAE,uJAAuJ;KAC7J,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Organization context, owned by the Node SDK: the ONE resolver every
3
+ * org-scoped command consumes, and the verbs that select, report, and bind
4
+ * the current organization.
5
+ *
6
+ * The org is the ownership root — it owns projects, holds memberships, and is
7
+ * the scope for rooms, escalations, members, grants, and audit. Precedence is
8
+ * four INTENT CLASSES, highest first, and inside each class an organization
9
+ * named directly outranks one derived from a project named in that same class:
10
+ *
11
+ * 1. flag `org` (--org) else `project` (--project) -> its org
12
+ * 2. environment RUN402_ORG, else the org half else RUN402_PROJECT_ID -> its org
13
+ * of RUN402_ROOM
14
+ * 3. binding the `org` key of the nearest .run402(.local).json
15
+ * 3.5 vault pin `r402.orgId` in this checkout's local git config
16
+ * 4. profile state the profile's selected org else its active project -> org
17
+ *
18
+ * Naming a project IS naming its organization, so a stale profile selection
19
+ * never outranks it; classes 3 and 4 are what let an org that owns no project
20
+ * be addressed at all.
21
+ *
22
+ * Two things this deliberately does NOT do:
23
+ * - Infer the org from the caller's memberships, at any count: membership is
24
+ * server state that changes without the caller acting.
25
+ * - Validate membership locally: a well-formed id goes to the server and the
26
+ * server's answer is surfaced as returned, never retried against a lower
27
+ * class and never rewritten into a local not-found.
28
+ */
29
+ import { LocalError, type NextAction } from "../errors.js";
30
+ import type { Client } from "../kernel.js";
31
+ import { Orgs } from "../namespaces/org.js";
32
+ import { Rooms } from "../namespaces/rooms.js";
33
+ import { Projects } from "../namespaces/projects.js";
34
+ export declare const ORG_ENV = "RUN402_ORG";
35
+ export declare const ROOM_ENV = "RUN402_ROOM";
36
+ export declare const PROJECT_ENV = "RUN402_PROJECT_ID";
37
+ /** `org_id` is a UUID at every API boundary. */
38
+ export declare const ORG_ID_RE: RegExp;
39
+ export type OrgSource = "flag" | "env" | "binding" | "vault_pin" | "profile";
40
+ export interface ResolvedOrg {
41
+ orgId: string;
42
+ source: OrgSource;
43
+ sourceDetail: string;
44
+ }
45
+ export interface ResolveOrgInput {
46
+ /** The org named directly (the `--org` flag). */
47
+ org?: string | null;
48
+ /** A project named directly (the `--project` flag); its owning org decides. */
49
+ project?: string | null;
50
+ }
51
+ export interface ResolveOrgOptions {
52
+ env?: Record<string, string | undefined>;
53
+ /** Directory the binding walk starts from. Default `process.cwd()`. */
54
+ cwd?: string;
55
+ /** Return null instead of throwing `ORG_REQUIRED` when nothing supplies an org. */
56
+ optional?: boolean;
57
+ /** Skip the env-vs-binding `AMBIGUOUS_ORG` error (surfaces that must stay usable while ambiguous). */
58
+ allowConflict?: boolean;
59
+ }
60
+ export interface OrgProvenance {
61
+ org_id: string | null;
62
+ org_source: OrgSource | null;
63
+ org_source_detail: string | null;
64
+ }
65
+ export interface CurrentOrgResult extends OrgProvenance {
66
+ selected_org_id: string | null;
67
+ }
68
+ export interface OrgBindResult {
69
+ org_id: string;
70
+ room_key: string | null;
71
+ org_source: "flag" | "sole_membership";
72
+ file: ".run402.json";
73
+ path: string;
74
+ bound: true;
75
+ safe_to_commit: true;
76
+ note: string;
77
+ binding: Record<string, unknown> | null;
78
+ }
79
+ export interface OrgUnbindResult {
80
+ file: ".run402.json";
81
+ unbound: boolean;
82
+ removed: boolean;
83
+ binding: Record<string, unknown> | null;
84
+ }
85
+ export declare function listOrgsAction(): NextAction;
86
+ /** The recovery actions an `ORG_REQUIRED` refusal carries: every way to supply an org. */
87
+ export declare function orgRequiredActions(): NextAction[];
88
+ /**
89
+ * Shape-validate an organization id from a local source. Never checks
90
+ * membership. A rejected value may be a pasted secret, so it is redacted.
91
+ */
92
+ export declare function assertOrgIdShape(orgId: string, origin: string): string;
93
+ /** The `ORG_REQUIRED` refusal, optionally naming a rejected positional. */
94
+ export declare function orgRequiredError(opts?: {
95
+ rejectedPositional?: string;
96
+ positionalHint?: boolean;
97
+ }): LocalError;
98
+ /** Provenance triple for command output: bounded, never a resolution trace. */
99
+ export declare function orgProvenance(resolved: ResolvedOrg | null): OrgProvenance;
100
+ /**
101
+ * `r.orgs` on the Node entry: the isomorphic org collection and identity
102
+ * verbs plus the local organization context.
103
+ */
104
+ export declare class NodeOrgs extends Orgs {
105
+ #private;
106
+ /**
107
+ * @param namespaces the reads the resolver makes (a project's org, the
108
+ * project listing); default to fresh namespaces on `client`.
109
+ */
110
+ constructor(client: Client, namespaces?: {
111
+ rooms?: Pick<Rooms, "forProject">;
112
+ projects?: Pick<Projects, "list">;
113
+ });
114
+ /**
115
+ * The one resolver. Returns the org with its provenance, or null when
116
+ * `optional` and nothing supplies one; throws `BAD_ORG_ID`, `AMBIGUOUS_ORG`,
117
+ * or `ORG_REQUIRED` (each with its recovery actions) otherwise.
118
+ */
119
+ resolve(input?: ResolveOrgInput, opts?: ResolveOrgOptions): Promise<ResolvedOrg | null>;
120
+ /** Select the current organization for the active wallet profile (`orgs use`). */
121
+ use(orgId: string): Promise<{
122
+ org_id: string;
123
+ selected: true;
124
+ scope: "wallet_profile";
125
+ }>;
126
+ /**
127
+ * The organization this directory and profile resolve to, with provenance,
128
+ * beside the profile's own selection. An empty selection is an explicit
129
+ * null state. Never fails on ambiguity: the command that reports the
130
+ * selection stays usable while it is ambiguous.
131
+ */
132
+ current(opts?: Pick<ResolveOrgOptions, "env" | "cwd">): Promise<CurrentOrgResult>;
133
+ /** The profile's selected organization, without running the chain. */
134
+ selected(): string | null;
135
+ /** Clear the profile's selected organization. */
136
+ clear(): Promise<{
137
+ org_id: null;
138
+ selected: false;
139
+ previous_org_id: string | null;
140
+ }>;
141
+ /**
142
+ * Write this checkout's org (and room) into `.run402.json`. With no org, the
143
+ * caller's sole membership is used and written down: an explicit, recorded
144
+ * act, unlike the chain, which never infers. Two or more memberships refuse.
145
+ */
146
+ bind(orgId?: string | null, opts?: {
147
+ room?: string | null;
148
+ cwd?: string;
149
+ }): Promise<OrgBindResult>;
150
+ /** Remove the `org` and `room` keys from `./.run402.json`; the file goes when nothing else is left. */
151
+ unbind(opts?: {
152
+ cwd?: string;
153
+ }): Promise<OrgUnbindResult>;
154
+ /**
155
+ * Stamp a project's owning organization as the profile's selection
156
+ * (`projects use` does this: a project determines its org unambiguously).
157
+ * Best-effort: returns the org, or null, and never throws.
158
+ */
159
+ selectFromProject(projectId: string): Promise<string | null>;
160
+ /**
161
+ * The organization that OWNS a specific project, or null. Distinct from
162
+ * {@link resolve} (which org a command is addressed at): an `--org` override
163
+ * here would be a mis-binding. Remembered in the local project entry after
164
+ * the first lookup, so the vault scaffold adds no network read on a
165
+ * returning machine; an exact id match is required.
166
+ */
167
+ owningOrgOf(projectId: string): Promise<string | null>;
168
+ }
169
+ //# sourceMappingURL=org-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-context.d.ts","sourceRoot":"","sources":["../../src/node/org-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAWH,OAAO,EAAE,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,wB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