@run402/sdk 4.97.0 → 4.99.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,403 @@
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 { basename } from "node:path";
30
+ import { describeRejectedValue } from "../../core-dist/redact.js";
31
+ import { findBindingKey, readBindingFile, updateBindingFile } from "../../core-dist/binding-file.js";
32
+ import { clearActiveOrgId, getActiveOrgId, setActiveOrgId, } from "../../core-dist/profile-state.js";
33
+ import { getActiveProjectId, getProject, updateProject } from "../../core-dist/keystore.js";
34
+ import { LocalError } from "../errors.js";
35
+ import { Orgs } from "../namespaces/org.js";
36
+ import { Rooms } from "../namespaces/rooms.js";
37
+ import { Projects } from "../namespaces/projects.js";
38
+ import { localAction } from "./local-actions.js";
39
+ export const ORG_ENV = "RUN402_ORG";
40
+ export const ROOM_ENV = "RUN402_ROOM";
41
+ export const PROJECT_ENV = "RUN402_PROJECT_ID";
42
+ /** `org_id` is a UUID at every API boundary. */
43
+ export const ORG_ID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
44
+ const CONTEXT = "resolving the organization";
45
+ const trimmed = (v) => (typeof v === "string" && v.trim() ? v.trim() : null);
46
+ export function listOrgsAction() {
47
+ return localAction("edit_request", {
48
+ command: "run402 orgs list",
49
+ why: "List the organizations this wallet belongs to.",
50
+ });
51
+ }
52
+ /** The recovery actions an `ORG_REQUIRED` refusal carries: every way to supply an org. */
53
+ export function orgRequiredActions() {
54
+ return [
55
+ localAction("edit_request", {
56
+ command: "run402 orgs use <org_id>",
57
+ why: "Select a current organization for this wallet profile.",
58
+ }),
59
+ listOrgsAction(),
60
+ localAction("edit_request", {
61
+ command: "run402 <command> --org <org_id>",
62
+ why: "Name the organization on this one call.",
63
+ }),
64
+ localAction("edit_request", {
65
+ command: "export RUN402_ORG=<org_id>",
66
+ why: "Name the organization for every call in this shell (harness wiring).",
67
+ }),
68
+ localAction("edit_request", {
69
+ command: `echo '{"org":"<org_id>"}' > .run402.json`,
70
+ why: "Bind this checkout to an organization so every agent in it inherits the same one.",
71
+ }),
72
+ localAction("edit_request", {
73
+ command: "run402 projects use <project_id>",
74
+ why: "Select a project; its owning organization becomes the current one.",
75
+ }),
76
+ ];
77
+ }
78
+ /**
79
+ * Shape-validate an organization id from a local source. Never checks
80
+ * membership. A rejected value may be a pasted secret, so it is redacted.
81
+ */
82
+ export function assertOrgIdShape(orgId, origin) {
83
+ if (ORG_ID_RE.test(orgId))
84
+ return orgId;
85
+ throw new LocalError(`Invalid organization id ${JSON.stringify(describeRejectedValue(orgId))} (from ${origin}).`, CONTEXT, {
86
+ code: "BAD_ORG_ID",
87
+ hint: "An org_id is a UUID. Run 'run402 orgs list' to see the organizations you belong to.",
88
+ details: { org_id: describeRejectedValue(orgId), origin },
89
+ next_actions: [listOrgsAction()],
90
+ });
91
+ }
92
+ /** The `ORG_REQUIRED` refusal, optionally naming a rejected positional. */
93
+ export function orgRequiredError(opts = {}) {
94
+ const rejected = opts.rejectedPositional;
95
+ return new LocalError(typeof rejected === "string"
96
+ ? `No organization specified and no current organization set (${JSON.stringify(rejected)} is not an org_id — an org_id is a UUID).`
97
+ : "No organization specified and no current organization set.", CONTEXT, {
98
+ code: "ORG_REQUIRED",
99
+ hint: opts.positionalHint
100
+ ? `Pass --org <org_id> (or a leading <org_id> positional), set ${ORG_ENV}, bind this directory in .run402.json, or run: run402 orgs use <org_id>`
101
+ : `Pass --org <org_id>, set ${ORG_ENV}, bind this directory in .run402.json, or run: run402 orgs use <org_id>`,
102
+ ...(typeof rejected === "string" ? { details: { rejected_positional: rejected } } : {}),
103
+ next_actions: orgRequiredActions(),
104
+ });
105
+ }
106
+ /** The org half of `RUN402_ROOM=<org_id>/<room_key>`, or null. */
107
+ function orgFromRoomEnv(env) {
108
+ const raw = trimmed(env[ROOM_ENV]);
109
+ if (!raw)
110
+ return null;
111
+ const slash = raw.indexOf("/");
112
+ if (slash <= 0 || slash === raw.length - 1)
113
+ return null;
114
+ return raw.slice(0, slash);
115
+ }
116
+ /**
117
+ * `r402.orgId` from `cwd`'s local git config: a vault checkout's pin first,
118
+ * then the bare org/room pin a room-only `rooms join` writes. Best-effort:
119
+ * no repository, no pin, or a malformed value is simply null.
120
+ */
121
+ async function readVaultPinnedOrgId(cwd) {
122
+ try {
123
+ const { readPinnedVaultRepo, readPinnedRoomBinding } = await import("./vault-address.js");
124
+ const pinned = await readPinnedVaultRepo(cwd);
125
+ const orgId = trimmed(pinned?.org_id);
126
+ if (orgId && ORG_ID_RE.test(orgId))
127
+ return orgId;
128
+ const bare = await readPinnedRoomBinding(cwd);
129
+ const bareOrgId = trimmed(bare?.org_id);
130
+ return bareOrgId && ORG_ID_RE.test(bareOrgId) ? bareOrgId : null;
131
+ }
132
+ catch {
133
+ return null;
134
+ }
135
+ }
136
+ /** A directory name coerced into a legal room key, or null. */
137
+ function roomKeyFromDir(dir) {
138
+ const base = basename(dir);
139
+ const slug = base.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+/, "").slice(0, 64);
140
+ return /^[a-z0-9]/.test(slug) ? slug : null;
141
+ }
142
+ /** Provenance triple for command output: bounded, never a resolution trace. */
143
+ export function orgProvenance(resolved) {
144
+ return resolved
145
+ ? { org_id: resolved.orgId, org_source: resolved.source, org_source_detail: resolved.sourceDetail }
146
+ : { org_id: null, org_source: null, org_source_detail: null };
147
+ }
148
+ /**
149
+ * `r.orgs` on the Node entry: the isomorphic org collection and identity
150
+ * verbs plus the local organization context.
151
+ */
152
+ export class NodeOrgs extends Orgs {
153
+ #client;
154
+ #rooms;
155
+ #projects;
156
+ /**
157
+ * @param namespaces the reads the resolver makes (a project's org, the
158
+ * project listing); default to fresh namespaces on `client`.
159
+ */
160
+ constructor(client, namespaces = {}) {
161
+ super(client);
162
+ this.#client = client;
163
+ this.#rooms = namespaces.rooms ?? new Rooms(client);
164
+ this.#projects = namespaces.projects ?? new Projects(client);
165
+ }
166
+ /**
167
+ * A project's owning org: the local key cache when it carries one, else one
168
+ * read. An explicitly named project (`required`) that cannot be resolved
169
+ * throws — falling to a lower class would act on a different org than the
170
+ * caller asked for; an implicit one returns null.
171
+ */
172
+ async #orgOfProject(projectId, required) {
173
+ const cached = (await this.#client.getProjectCredentials(projectId))?.org_id;
174
+ if (typeof cached === "string" && cached.length > 0)
175
+ return cached;
176
+ try {
177
+ return (await this.#rooms.forProject(projectId)).orgId;
178
+ }
179
+ catch (err) {
180
+ if (!required)
181
+ return null;
182
+ throw err;
183
+ }
184
+ }
185
+ /**
186
+ * The one resolver. Returns the org with its provenance, or null when
187
+ * `optional` and nothing supplies one; throws `BAD_ORG_ID`, `AMBIGUOUS_ORG`,
188
+ * or `ORG_REQUIRED` (each with its recovery actions) otherwise.
189
+ */
190
+ async resolve(input = {}, opts = {}) {
191
+ const { env = process.env, cwd = process.cwd(), optional = false, allowConflict = false } = opts;
192
+ // Class 1: flag.
193
+ const orgFlag = trimmed(input.org);
194
+ if (orgFlag)
195
+ return { orgId: assertOrgIdShape(orgFlag, "--org"), source: "flag", sourceDetail: "--org" };
196
+ const projectFlag = trimmed(input.project);
197
+ if (projectFlag) {
198
+ const orgId = await this.#orgOfProject(projectFlag, true);
199
+ if (orgId)
200
+ return { orgId, source: "flag", sourceDetail: "--project" };
201
+ }
202
+ // Classes 2 and 3: environment vs binding (the conflict pair).
203
+ const bindingHit = findBindingKey(cwd, "org");
204
+ const bindingOrg = bindingHit ? assertOrgIdShape(bindingHit.value, bindingHit.file) : null;
205
+ const envDirect = trimmed(env[ORG_ENV]);
206
+ const envRoomOrg = envDirect ? null : orgFromRoomEnv(env);
207
+ const envProject = envDirect || envRoomOrg ? null : trimmed(env[PROJECT_ENV]);
208
+ let envOrg = null;
209
+ let envDetail = null;
210
+ if (envDirect) {
211
+ envOrg = assertOrgIdShape(envDirect, ORG_ENV);
212
+ envDetail = ORG_ENV;
213
+ }
214
+ else if (envRoomOrg) {
215
+ envOrg = assertOrgIdShape(envRoomOrg, ROOM_ENV);
216
+ envDetail = ROOM_ENV;
217
+ }
218
+ else if (envProject && bindingOrg) {
219
+ // Only worth a lookup when a binding exists to disagree with.
220
+ envOrg = await this.#orgOfProject(envProject, false);
221
+ envDetail = PROJECT_ENV;
222
+ }
223
+ if (envOrg && bindingOrg && envOrg !== bindingOrg && !allowConflict) {
224
+ // A binding deliberately declared by a checkout outranks the profile
225
+ // selection silently; an ambient env var disagreeing with a committed
226
+ // file is the surprise worth stopping on.
227
+ throw new LocalError(`Ambiguous organization: ${envDetail}=${envOrg} but ${bindingHit.file} binds ${bindingOrg}.`, CONTEXT, {
228
+ code: "AMBIGUOUS_ORG",
229
+ hint: `Resolve with one of: pass --org <org_id>, unset ${envDetail}, or edit the binding file.`,
230
+ details: {
231
+ candidates: [
232
+ { org_id: envOrg, source: "env", source_detail: envDetail },
233
+ { org_id: bindingOrg, source: "binding", source_detail: bindingHit.file },
234
+ ],
235
+ },
236
+ next_actions: [
237
+ localAction("edit_request", {
238
+ command: "run402 <command> --org <org_id>",
239
+ why: "The flag resolves the conflict for this call.",
240
+ }),
241
+ ],
242
+ });
243
+ }
244
+ if (envOrg)
245
+ return { orgId: envOrg, source: "env", sourceDetail: envDetail };
246
+ if (envProject) {
247
+ const orgId = await this.#orgOfProject(envProject, false);
248
+ if (orgId)
249
+ return { orgId, source: "env", sourceDetail: PROJECT_ENV };
250
+ }
251
+ if (bindingOrg)
252
+ return { orgId: bindingOrg, source: "binding", sourceDetail: bindingHit.file };
253
+ // Class 3.5: this checkout's vault pin.
254
+ const pinnedOrg = await readVaultPinnedOrgId(cwd);
255
+ if (pinnedOrg)
256
+ return { orgId: pinnedOrg, source: "vault_pin", sourceDetail: "r402.orgId (local git config)" };
257
+ // Class 4: profile state.
258
+ const selected = trimmed(getActiveOrgId());
259
+ if (selected)
260
+ return { orgId: assertOrgIdShape(selected, "orgs use"), source: "profile", sourceDetail: "orgs use" };
261
+ const activeProject = trimmed(getActiveProjectId());
262
+ if (activeProject) {
263
+ const orgId = await this.#orgOfProject(activeProject, false);
264
+ if (orgId)
265
+ return { orgId, source: "profile", sourceDetail: "projects use" };
266
+ }
267
+ if (optional)
268
+ return null;
269
+ throw orgRequiredError();
270
+ }
271
+ /** Select the current organization for the active wallet profile (`orgs use`). */
272
+ async use(orgId) {
273
+ setActiveOrgId(assertOrgIdShape(orgId, "orgs use"));
274
+ return { org_id: orgId, selected: true, scope: "wallet_profile" };
275
+ }
276
+ /**
277
+ * The organization this directory and profile resolve to, with provenance,
278
+ * beside the profile's own selection. An empty selection is an explicit
279
+ * null state. Never fails on ambiguity: the command that reports the
280
+ * selection stays usable while it is ambiguous.
281
+ */
282
+ async current(opts = {}) {
283
+ const resolved = await this.resolve({}, { ...opts, optional: true, allowConflict: true });
284
+ return { ...orgProvenance(resolved), selected_org_id: this.selected() };
285
+ }
286
+ /** The profile's selected organization, without running the chain. */
287
+ selected() {
288
+ return trimmed(getActiveOrgId());
289
+ }
290
+ /** Clear the profile's selected organization. */
291
+ async clear() {
292
+ const previous = this.selected();
293
+ clearActiveOrgId();
294
+ return { org_id: null, selected: false, previous_org_id: previous ?? null };
295
+ }
296
+ /**
297
+ * Write this checkout's org (and room) into `.run402.json`. With no org, the
298
+ * caller's sole membership is used and written down: an explicit, recorded
299
+ * act, unlike the chain, which never infers. Two or more memberships refuse.
300
+ */
301
+ async bind(orgId, opts = {}) {
302
+ const cwd = opts.cwd ?? process.cwd();
303
+ let chosen = orgId || null;
304
+ let picked = "flag";
305
+ if (!chosen) {
306
+ const rows = await this.list();
307
+ if (rows.length === 0) {
308
+ throw new LocalError("This wallet is a member of no organization yet.", "binding the organization", {
309
+ code: "NO_ORGS",
310
+ hint: "Run 'run402 init' to provision one, or ask an owner to add you with 'run402 orgs members add'.",
311
+ next_actions: [localAction("initialize_wallet", { command: "run402 init", why: "Provision this wallet's organization, then retry." })],
312
+ });
313
+ }
314
+ if (rows.length > 1) {
315
+ throw new LocalError(`This wallet belongs to ${rows.length} organizations — name the one to bind.`, "binding the organization", {
316
+ code: "AMBIGUOUS_ORG",
317
+ hint: "run402 orgs bind --org <org_id>",
318
+ details: { orgs: rows.map((o) => ({ org_id: o.org_id, display_name: o.display_name ?? null, role: o.role ?? null })) },
319
+ next_actions: [localAction("edit_request", { command: "run402 orgs bind --org <org_id>", why: "Name which organization this checkout coordinates in." })],
320
+ });
321
+ }
322
+ chosen = rows[0].org_id;
323
+ picked = "sole_membership";
324
+ }
325
+ const room = opts.room ?? roomKeyFromDir(cwd);
326
+ const { contents, file } = updateBindingFile(cwd, {
327
+ org: assertOrgIdShape(chosen, picked === "flag" ? "--org" : "orgs list"),
328
+ ...(room ? { room } : {}),
329
+ });
330
+ return {
331
+ org_id: chosen,
332
+ room_key: room ?? null,
333
+ org_source: picked,
334
+ file: ".run402.json",
335
+ path: file,
336
+ bound: true,
337
+ safe_to_commit: true,
338
+ note: "Safe to commit — an org id is an identifier, not a credential; authorization stays server-side.",
339
+ binding: contents,
340
+ };
341
+ }
342
+ /** Remove the `org` and `room` keys from `./.run402.json`; the file goes when nothing else is left. */
343
+ async unbind(opts = {}) {
344
+ const cwd = opts.cwd ?? process.cwd();
345
+ const previous = readBindingFile(cwd);
346
+ const { contents, removed } = updateBindingFile(cwd, { org: null, room: null });
347
+ return {
348
+ file: ".run402.json",
349
+ unbound: previous.org !== undefined || previous.room !== undefined,
350
+ removed,
351
+ binding: contents,
352
+ };
353
+ }
354
+ /**
355
+ * Stamp a project's owning organization as the profile's selection
356
+ * (`projects use` does this: a project determines its org unambiguously).
357
+ * Best-effort: returns the org, or null, and never throws.
358
+ */
359
+ async selectFromProject(projectId) {
360
+ try {
361
+ const orgId = await this.#orgOfProject(projectId, false);
362
+ if (orgId) {
363
+ setActiveOrgId(orgId);
364
+ return orgId;
365
+ }
366
+ }
367
+ catch {
368
+ /* best-effort */
369
+ }
370
+ return null;
371
+ }
372
+ /**
373
+ * The organization that OWNS a specific project, or null. Distinct from
374
+ * {@link resolve} (which org a command is addressed at): an `--org` override
375
+ * here would be a mis-binding. Remembered in the local project entry after
376
+ * the first lookup, so the vault scaffold adds no network read on a
377
+ * returning machine; an exact id match is required.
378
+ */
379
+ async owningOrgOf(projectId) {
380
+ const cached = getProject(projectId)?.org_id;
381
+ if (typeof cached === "string" && cached.length > 0)
382
+ return cached;
383
+ try {
384
+ const listed = await this.#projects.list();
385
+ const rows = Array.isArray(listed?.projects) ? listed.projects : [];
386
+ const row = rows.find((p) => (p?.id ?? p?.project_id) === projectId);
387
+ const orgId = row?.org_id;
388
+ if (typeof orgId !== "string" || orgId.length === 0)
389
+ return null;
390
+ try {
391
+ updateProject(projectId, { org_id: orgId });
392
+ }
393
+ catch {
394
+ /* caching is an optimization */
395
+ }
396
+ return orgId;
397
+ }
398
+ catch {
399
+ return null;
400
+ }
401
+ }
402
+ }
403
+ //# sourceMappingURL=org-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"org-context.js","sourceRoot":"","sources":["../../src/node/org-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,cAAc,GACf,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAmB,MAAM,cAAc,CAAC;AAE3D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC;AACpC,MAAM,CAAC,MAAM,QA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CACF"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * `r.status()` — the organization's state in one read, owned by the Node
3
+ * SDK: the active wallet (`local_label`, `server_label`, address), its rail,
4
+ * on-chain and allowance balances, the tier and its lease, the projects
5
+ * (server-side, falling back to the local key cache), the active project, and
6
+ * the API target. This is the LOCAL view — which wallet this machine acts as —
7
+ * combined with the reads that wallet can make; it never returns key material.
8
+ *
9
+ * With no local wallet the answer is the bare local state (`wallet: null`,
10
+ * the locally known projects, the active project, the target) plus the next
11
+ * command; Run402 Core targets can still report it without a wallet.
12
+ * `run402 status` is a shim over this.
13
+ */
14
+ import type { Run402 } from "../index.js";
15
+ export interface StatusTarget {
16
+ api_base: string;
17
+ api_base_source: "env" | "profile" | "default";
18
+ kind: "cloud" | "core" | "unknown";
19
+ }
20
+ /** No local wallet: the local facts and the next command. */
21
+ export interface LocalOnlyStatus {
22
+ wallet: null;
23
+ target: StatusTarget;
24
+ projects: Array<{
25
+ project_id: string;
26
+ }>;
27
+ active_project: string | null;
28
+ hint: string;
29
+ }
30
+ /** A local wallet: the organization's state as that wallet sees it. */
31
+ export interface WalletStatus {
32
+ wallet: {
33
+ local_label: string;
34
+ server_label: string | null;
35
+ address: string;
36
+ };
37
+ rail: string;
38
+ remote_status: unknown;
39
+ next_actions: unknown;
40
+ projects_source: "remote" | "local_cache";
41
+ balances: {
42
+ on_chain_usd_micros: number | null;
43
+ on_chain_token: "USDC" | "pathUSD";
44
+ allowance_usd_micros: number | null;
45
+ held_usd_micros: number | null;
46
+ };
47
+ tier: {
48
+ name: string;
49
+ status: string;
50
+ expires: string | null;
51
+ } | null;
52
+ organization_lifecycle_state: string | null;
53
+ lease_perpetual: boolean | null;
54
+ projects: Array<Record<string, unknown> & {
55
+ project_id: string;
56
+ }>;
57
+ active_project: string | null;
58
+ target: StatusTarget;
59
+ }
60
+ export type StatusResult = LocalOnlyStatus | WalletStatus;
61
+ export declare function runStatus(r: Run402): Promise<StatusResult>;
62
+ //# sourceMappingURL=status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KAAE,GAAG,IAAI,CAAC;IACtE,4BAA4B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5C,eAAe,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,YAAY,CAAC;AA+C1D,wBAAsB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAsEhE"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * `r.status()` — the organization's state in one read, owned by the Node
3
+ * SDK: the active wallet (`local_label`, `server_label`, address), its rail,
4
+ * on-chain and allowance balances, the tier and its lease, the projects
5
+ * (server-side, falling back to the local key cache), the active project, and
6
+ * the API target. This is the LOCAL view — which wallet this machine acts as —
7
+ * combined with the reads that wallet can make; it never returns key material.
8
+ *
9
+ * With no local wallet the answer is the bare local state (`wallet: null`,
10
+ * the locally known projects, the active project, the target) plus the next
11
+ * command; Run402 Core targets can still report it without a wallet.
12
+ * `run402 status` is a shim over this.
13
+ */
14
+ import { getActiveProfile, getApiBase, getApiBaseSource, getApiTargetKind, } from "../../core-dist/config.js";
15
+ import { readLocalWallet } from "./wallets.js";
16
+ import { getActiveProjectId, loadKeyStore } from "../../core-dist/keystore.js";
17
+ import { readMeta } from "../../core-dist/profiles.js";
18
+ import { readRemoteStatus } from "./remote-status.js";
19
+ const USDC_ABI = [{ name: "balanceOf", type: "function", stateMutability: "view", inputs: [{ name: "account", type: "address" }], outputs: [{ name: "", type: "uint256" }] }];
20
+ const USDC_MAINNET = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
21
+ const USDC_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
22
+ const PATH_USD = "0x20c0000000000000000000000000000000000000";
23
+ const TEMPO_RPC = "https://rpc.moderato.tempo.xyz/";
24
+ /**
25
+ * The wallet's on-chain balance in USD micros for its rail: USDC on Base
26
+ * mainnet plus Base Sepolia (x402), or pathUSD on Tempo Moderato (mpp).
27
+ * Null when every read fails.
28
+ */
29
+ async function readWalletBalanceUsdMicros(rail, address) {
30
+ try {
31
+ const { createPublicClient, http, defineChain } = await import("viem");
32
+ if (rail === "mpp") {
33
+ const tempoModerato = defineChain({
34
+ id: 42431,
35
+ name: "Tempo Moderato",
36
+ nativeCurrency: { name: "pathUSD", symbol: "pathUSD", decimals: 6 },
37
+ rpcUrls: { default: { http: [TEMPO_RPC] } },
38
+ });
39
+ const client = createPublicClient({ chain: tempoModerato, transport: http() });
40
+ try {
41
+ const raw = await client.readContract({ address: PATH_USD, abi: USDC_ABI, functionName: "balanceOf", args: [address] });
42
+ return Number(raw);
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ }
48
+ const { base, baseSepolia } = await import("viem/chains");
49
+ const mainnetClient = createPublicClient({ chain: base, transport: http() });
50
+ const sepoliaClient = createPublicClient({ chain: baseSepolia, transport: http() });
51
+ const [mainnet, sepolia] = await Promise.all([
52
+ mainnetClient.readContract({ address: USDC_MAINNET, abi: USDC_ABI, functionName: "balanceOf", args: [address] }).then(Number).catch(() => null),
53
+ sepoliaClient.readContract({ address: USDC_SEPOLIA, abi: USDC_ABI, functionName: "balanceOf", args: [address] }).then(Number).catch(() => null),
54
+ ]);
55
+ if (mainnet === null && sepolia === null)
56
+ return null;
57
+ return (mainnet || 0) + (sepolia || 0);
58
+ }
59
+ catch {
60
+ return null;
61
+ }
62
+ }
63
+ /** Always expose `project_id` (the remote listing keys entries as `id`), never both. */
64
+ function normalizeProject(raw) {
65
+ if (!raw || typeof raw !== "object")
66
+ return raw;
67
+ const projectId = (raw.project_id || raw.id);
68
+ const { id: _dropId, project_id: _dropPid, ...rest } = raw;
69
+ return { project_id: projectId, ...rest };
70
+ }
71
+ export async function runStatus(r) {
72
+ const localWallet = readLocalWallet();
73
+ const target = {
74
+ api_base: getApiBase(),
75
+ api_base_source: getApiBaseSource(),
76
+ kind: getApiTargetKind(),
77
+ };
78
+ if (!localWallet) {
79
+ const store = loadKeyStore();
80
+ return {
81
+ wallet: null,
82
+ target,
83
+ projects: Object.keys(store.projects).map((id) => ({ project_id: id })),
84
+ active_project: getActiveProjectId() || null,
85
+ hint: target.kind === "core" ? "Run: run402 projects provision --name my-app" : "Run: run402 init",
86
+ };
87
+ }
88
+ const wallet = localWallet.address.toLowerCase();
89
+ const rail = localWallet.rail || "x402";
90
+ // Tier, allowance, and the membership-scoped project inventory, beside the
91
+ // on-chain balance, all best-effort.
92
+ const [status, walletBalance] = await Promise.all([
93
+ readRemoteStatus(r, wallet),
94
+ readWalletBalanceUsdMicros(rail, localWallet.address),
95
+ ]);
96
+ const { tier, billing, remote } = status;
97
+ const store = loadKeyStore();
98
+ const activeId = getActiveProjectId();
99
+ const projects = remote?.projects
100
+ ? remote.projects.map(normalizeProject)
101
+ : Object.keys(store.projects).map((id) => ({ project_id: id }));
102
+ const walletName = getActiveProfile();
103
+ const walletMeta = readMeta(walletName);
104
+ const hasBilling = billing && billing.exists !== false;
105
+ return {
106
+ wallet: {
107
+ local_label: walletName,
108
+ server_label: walletMeta?.label ?? null,
109
+ address: localWallet.address,
110
+ },
111
+ rail,
112
+ remote_status: status.availability,
113
+ next_actions: status.next_actions,
114
+ projects_source: remote ? "remote" : "local_cache",
115
+ balances: {
116
+ on_chain_usd_micros: walletBalance,
117
+ on_chain_token: rail === "mpp" ? "pathUSD" : "USDC",
118
+ allowance_usd_micros: hasBilling ? billing.allowance_usd_micros : null,
119
+ held_usd_micros: hasBilling ? (billing.held_usd_micros ?? 0) : null,
120
+ },
121
+ tier: tier && tier.tier
122
+ ? { name: tier.tier, status: tier.status, expires: tier.lease_perpetual === true ? null : tier.lease_expires_at }
123
+ : null,
124
+ // Lifecycle and the perpetual flag live on the organization; surfaced at the top.
125
+ organization_lifecycle_state: tier?.organization_lifecycle_state ?? null,
126
+ lease_perpetual: tier?.lease_perpetual ?? null,
127
+ projects,
128
+ active_project: activeId || null,
129
+ target,
130
+ };
131
+ }
132
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/node/status.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAEvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,QAAQ,GAAG,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,EAAE,CAAU,CAAC;AACvL,MAAM,YAAY,GAAG,4CAA4C,CAAC;AAClE,MAAM,YAAY,GAAG,4CAA4C,CAAC;AAClE,MAAM,QAAQ,GAAG,4CAA4C,CAAC;AAC9D,MAAM,SAAS,GAAG,iCAAiC,CAAC;AAwCpD;;;;GAIG;AACH,KAAK,UAAU,0BAA0B,CAAC,IAAY,EAAE,OAAe;IACrE,IAAI,CAAC;QACH,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAA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