@uru-intelligence/cli 0.5.1 → 0.5.2

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/CHANGELOG.md CHANGED
@@ -80,6 +80,8 @@
80
80
  - Action: No action is required. `uru doctor` gains a `data access` check and fails when a credential validates but cannot execute tools; a token supplied through `--token` or `URU_TOKEN` is no longer told to run `uru login`.
81
81
  - Send scope on uru automations create, honor --output/--json on uru tools run, and keep errorId plus httpStatus on JSON errors. — surfaces: cli; reference: apps/cli/src/local-commands.ts
82
82
  - Action: uru automations create now sends scope=workspace by default. Pass --scope personal when creating a personal automation. JSON errors include errorId and httpStatus when the API provides them.
83
+ - Stop repeated browser or device consent after a new session is rejected. Cancel browser sign-in cleanly, reject unrelated callbacks, and bound OAuth network waits. Explain the supported Codex, Claude, Cursor, and Manus connection paths. — surfaces: cli, docs; reference: docs/research/2026-09-10-cli-mcp-auth-compatibility.md
84
+ - Action: Install CLI 0.5.2 with the matching Uru server release. Run uru login once. Cursor uses the documented public client ID.
83
85
  - The CLI tells the server which Gem result envelope it reads, and a server that cannot answer in it refuses before it acts instead of after the write. — surfaces: cli; reference: https://linear.app/uru-intelligence/issue/URU-1000
84
86
  - Action: Nothing to do. If an older server answers with an envelope this CLI does not read, the error now says the operation may have completed and to check with uru library ls before retrying.
85
87
  - Tip library_fs read refusals toward library_query, and ship labels/list aliases that need a live catalog with list_labels/create_label. — surfaces: cli, docs; reference: PR #5379 CF001; PR #5381 staging labels catalog
package/README.md CHANGED
@@ -247,52 +247,23 @@ URU_CLI_MCP_STAGING_SMOKE_TARGET=staging \
247
247
  bun --filter=@uru-intelligence/cli run smoke:staging -- --json
248
248
  ```
249
249
 
250
- Publish the scoped CLI only through the **Publish Uru CLI to npm** workflow on
251
- `main`. A release request must identify the candidate certification workflow
252
- run ID, attempt, and exact retained bundle artifact ID; the publisher never
253
- selects `latest` evidence. Before it reads the release record, it verifies the
254
- candidate's GitHub DSSE/in-toto artifact attestations for both the canonical
255
- release record and the exact `uru_cli.tgz`, pins the builder repository,
256
- candidate workflow path, development ref policy, run/attempt, predicate type,
257
- and source-bundle identity, then recomputes the build-input inventory at
258
- `main`.
259
-
260
- The workflow publishes that retained tarball from a sterile private temporary
261
- directory with `npm publish --ignore-scripts`; it never rebuilds, repacks, or
262
- rewrites it. npm trusted publishing runs only from the protected `production`
263
- environment. The registry smoke compares npm `dist.integrity` to the certified
264
- SRI and runs `npm exec` from a clean OS temporary directory so the monorepo
265
- workspace cannot shadow the published package. It then invokes the complete
266
- published `cli_pin` certification matrix for both staging and production. A
267
- value-free publication-state artifact records the observed npm SRI even when a
268
- publish response or a later gate fails. Re-dispatching the same immutable
269
- candidate selector resumes only when npm already serves that exact certified
270
- SRI; it then repeats the registry and published-matrix proof before evidence,
271
- tag, or GitHub release creation. A different SRI fails closed. A changed source
272
- or failed certification needs a higher-version forward fix; no npm version is
273
- ever rewritten.
274
-
275
- The workflow requires the immutable, no-bypass CLI tag policy before npm
276
- publication and revalidates it before tag creation. GitHub hides a ruleset's
277
- bypass actors from an ordinary workflow token, so the two policy-check steps
278
- mint a short-lived, repository-scoped GitHub App token solely to inspect that
279
- property. The App's client ID is the `production` environment variable
280
- `CLI_RULESET_AUDIT_APP_CLIENT_ID`; its private key is the matching
281
- `CLI_RULESET_AUDIT_APP_PRIVATE_KEY` environment secret. Its administration
282
- write grant is required for visibility only and is never available to the npm
283
- publication step or the tag/release creation step. Only after published evidence
284
- is retained does the workflow create the annotated
285
- `uru-cli-vX.Y.Z` tag at the exact dispatched `main` commit and a GitHub release
286
- with generated notes. The final job verifies an existing tag is annotated and
287
- points to that same commit before it can resume an interrupted GitHub-release
288
- request; it never changes the npm package, repoints a tag, or treats a draft or
289
- prerelease as success. Before the first use, repository policy must contain an
290
- active, no-bypass `refs/tags/uru-cli-v*` rule that blocks both updates and
291
- deletions; the workflow queries and requires it before creating the tag.
292
-
293
- ```bash
294
- bun --filter=@uru-intelligence/cli run smoke:registry
295
- ```
250
+ Publish the scoped CLI through the **Publish Uru CLI to npm** workflow
251
+ (`.github/workflows/publish-uru-cli.yml`) from `staging` or `main`. Pass the exact
252
+ `apps/cli/package.json` version as its `version` input. The workflow rejects
253
+ other branches or a version mismatch.
254
+
255
+ The workflow runs the source gates, builds one tarball, and retains its integrity
256
+ values. Package smoke tests check that tarball before npm trusted publishing
257
+ runs from the protected environment. Publication uses the retained tarball with
258
+ `--ignore-scripts`, rather than rebuilding it. A retry may reuse an already
259
+ published version only when its integrity is identical. A different package
260
+ needs a higher version.
261
+
262
+ The final job rebuilds the checked-out CLI and tests it against staging using
263
+ credentials supplied by Infisical. It does not install the registry package.
264
+ Check that job and its retained smoke report, then install the exact published
265
+ version in a clean directory and verify the intended behavior. A successful npm
266
+ upload or source smoke alone does not complete registry verification.
296
267
 
297
268
  The npm package remains the canonical install path. Release builds can also
298
269
  produce standalone Bun-compiled binaries for the planned macOS/Linux/Windows
package/dist/library.mjs CHANGED
@@ -6429,7 +6429,7 @@ var zArtifactProjectFileUpdateRequest = object({
6429
6429
  content: string2().nullish(),
6430
6430
  contentBase64: string2().nullish(),
6431
6431
  createIfMissing: boolean2().optional().default(false),
6432
- path: string2().min(1).max(1024)
6432
+ path: string2().min(1).max(240)
6433
6433
  });
6434
6434
  var zArtifactRenderEventRequest = object({
6435
6435
  dependencyNames: array(string2()).nullish(),
@@ -11264,17 +11264,17 @@ var zThreadFileView = object({
11264
11264
  "quarantined",
11265
11265
  "failed"
11266
11266
  ]),
11267
- bytes: int().nullish(),
11267
+ bytes: int().nullable(),
11268
11268
  createdAtMs: int(),
11269
11269
  fileId: uuid2(),
11270
11270
  filename: string2(),
11271
11271
  folder: _enum(["uploads", "outputs"]),
11272
11272
  kind: _enum(["file", "image", "audio", "video"]),
11273
- mime: string2().nullish(),
11273
+ mime: string2().nullable(),
11274
11274
  modelAccess: _enum(["direct", "sandbox_only"]),
11275
11275
  previewUrl: string2().nullable(),
11276
11276
  threadId: uuid2(),
11277
- url: string2().nullish()
11277
+ url: string2().nullable()
11278
11278
  });
11279
11279
  var zThreadFileListResponse = object({
11280
11280
  files: array(zThreadFileView),
@@ -11634,10 +11634,7 @@ var zThreadShareLink = object({
11634
11634
  snapshotLeafMessageId: string2().nullable(),
11635
11635
  threadId: string2()
11636
11636
  });
11637
- var zThreadShareListResponse = object({
11638
- links: array(zThreadShareLink)
11639
- });
11640
- var zThreadShareMintResponse = object({
11637
+ var zThreadShareEnsureResponse = object({
11641
11638
  link: zThreadShareLink,
11642
11639
  token: string2(),
11643
11640
  url: string2().nullable()
@@ -11983,6 +11980,8 @@ var zThreadMessagesListResponse = object({
11983
11980
  siblings: record(string2(), array(string2()))
11984
11981
  });
11985
11982
  var zThreadShareSnapshot = object({
11983
+ files: array(zThreadFileView),
11984
+ generatedAt: string2(),
11986
11985
  messages: array(zThreadExportMessage),
11987
11986
  schema: _enum(["uru.thread-share"]),
11988
11987
  sharedAt: string2(),
@@ -13024,7 +13023,9 @@ var zGetUserDetailApiAdminUsageUsersUserIdGetResponse = record(string2(), unknow
13024
13023
  var zAdminListUsersApiAdminUsersGetQuery = object({
13025
13024
  limit: int().gte(1).lte(100).optional().default(50),
13026
13025
  offset: int().gte(0).nullish().default(0),
13027
- search: string2().max(200).optional()
13026
+ search: string2().max(200).optional(),
13027
+ status: _enum(["active", "deactivated"]).optional(),
13028
+ workspaces: _enum(["one", "many"]).optional()
13028
13029
  });
13029
13030
  var zAdminGetUserApiAdminUsersUserIdGetPath = object({
13030
13031
  userId: string2()
@@ -14238,6 +14239,7 @@ var zAuthorizeRequestApiOauthAuthorizeRequestGetQuery = object({
14238
14239
  var zAuthorizeRequestApiOauthAuthorizeRequestGetResponse = object({
14239
14240
  client_id: string2(),
14240
14241
  client_name: string2(),
14242
+ redirectUri: url(),
14241
14243
  resource: url(),
14242
14244
  scope: string2(),
14243
14245
  workspace_id: string2().nullable(),
@@ -14587,7 +14589,7 @@ var zGetArtifactProjectFileContentApiPlatformArtifactsArtifactSlugProjectFilesCo
14587
14589
  artifactSlug: string2()
14588
14590
  });
14589
14591
  var zGetArtifactProjectFileContentApiPlatformArtifactsArtifactSlugProjectFilesContentGetQuery = object({
14590
- path: string2().min(1).max(1024)
14592
+ path: string2().min(1).max(240)
14591
14593
  });
14592
14594
  var zGetArtifactProjectFileContentApiPlatformArtifactsArtifactSlugProjectFilesContentGetResponse = object({
14593
14595
  artifactId: string2(),
@@ -17289,10 +17291,7 @@ var zThreadSandboxListPath = object({
17289
17291
  var zThreadSandboxListQuery = object({
17290
17292
  path: string2().max(512).optional()
17291
17293
  });
17292
- var zThreadShareListPath = object({
17293
- threadId: uuid2()
17294
- });
17295
- var zThreadShareMintPath = object({
17294
+ var zThreadShareEnsurePath = object({
17296
17295
  threadId: uuid2()
17297
17296
  });
17298
17297
  var zThreadShareRevokePath = object({
@@ -17562,7 +17561,7 @@ function pickString(record2, keys) {
17562
17561
  // package.json
17563
17562
  var package_default = {
17564
17563
  name: "@uru-intelligence/cli",
17565
- version: "0.5.1",
17564
+ version: "0.5.2",
17566
17565
  private: false,
17567
17566
  description: "Uru full-platform command line interface",
17568
17567
  repository: {
package/dist/uru.mjs CHANGED
@@ -993,16 +993,11 @@ var RETIRED_FROZEN_GEM_DATASET_TOOL_NAMES = Object.freeze([
993
993
  "UPDATE_DATASET",
994
994
  "DATASET_UPDATE",
995
995
  "LIST_DATASET_ROWS",
996
- "DATASET_QUERY",
997
996
  "GET_DATASET",
998
- "DATASET_GET",
999
997
  "UPSERT_DATASET_ROWS",
1000
998
  "DELETE_DATASET_ROWS",
1001
999
  "RESTORE_DATASET_ROWS",
1002
- "DATASET_ROWS",
1003
- "DATASET_SQL",
1004
- "DATASET_SQL_READ",
1005
- "DATASET_SQL_WRITE"
1000
+ "DATASET_SQL_READ"
1006
1001
  ]);
1007
1002
  var DATASET_TOOL_NAMES = new Map([
1008
1003
  ["CREATE_DATASET", "dataset_manage"],
@@ -1010,15 +1005,11 @@ var DATASET_TOOL_NAMES = new Map([
1010
1005
  ["UPDATE_DATASET", "dataset_manage"],
1011
1006
  ["DATASET_UPDATE", "dataset_manage"],
1012
1007
  ["LIST_DATASET_ROWS", "dataset_query"],
1013
- ["DATASET_QUERY", "dataset_query"],
1014
1008
  ["GET_DATASET", "dataset_get"],
1015
- ["DATASET_GET", "dataset_get"],
1016
1009
  ["UPSERT_DATASET_ROWS", "dataset_rows"],
1017
1010
  ["DELETE_DATASET_ROWS", "dataset_rows"],
1018
1011
  ["RESTORE_DATASET_ROWS", "dataset_rows"],
1019
- ["DATASET_ROWS", "dataset_rows"],
1020
- ["DATASET_SQL_READ", "dataset_sql"],
1021
- ["DATASET_SQL_WRITE", "dataset_sql_write"]
1012
+ ["DATASET_SQL_READ", "dataset_sql"]
1022
1013
  ]);
1023
1014
  var DATASET_ROW_OPERATIONS = new Map([
1024
1015
  ["UPSERT_DATASET_ROWS", "upsert"],
@@ -3061,7 +3052,7 @@ function spec(id, summary, auth, workspace, safety, outputModes, cancellation =
3061
3052
  // package.json
3062
3053
  var package_default = {
3063
3054
  name: "@uru-intelligence/cli",
3064
- version: "0.5.1",
3055
+ version: "0.5.2",
3065
3056
  private: false,
3066
3057
  description: "Uru full-platform command line interface",
3067
3058
  repository: {
@@ -3310,7 +3301,83 @@ function applyValueFlag(flags, flag, value) {
3310
3301
 
3311
3302
  // src/auth-commands.ts
3312
3303
  import { readFile } from "node:fs/promises";
3304
+
3305
+ // src/oauth-callback.ts
3313
3306
  import { createServer } from "node:http";
3307
+ var OAUTH_CALLBACK_PATH = "/oauth/callback";
3308
+ async function listenForOAuthCallback(args) {
3309
+ args.signal.throwIfAborted();
3310
+ const server = createServer();
3311
+ const completion = Promise.withResolvers();
3312
+ completion.promise.catch(() => {
3313
+ return;
3314
+ });
3315
+ let settled = false;
3316
+ const close = () => {
3317
+ clearTimeout(timeout);
3318
+ args.signal.removeEventListener("abort", cancel);
3319
+ server.close();
3320
+ server.closeAllConnections();
3321
+ };
3322
+ const fail = (error) => {
3323
+ if (settled)
3324
+ return;
3325
+ settled = true;
3326
+ close();
3327
+ completion.reject(error);
3328
+ };
3329
+ const cancel = () => fail(new CliError("Cancelled.", { code: ExitCode.Cancelled }));
3330
+ const timeout = setTimeout(() => fail(new CliError("OAuth login timed out waiting for browser callback.", { code: ExitCode.AuthRequired, errorCode: "oauth_callback_timeout" })), 5 * 60 * 1000);
3331
+ args.signal.addEventListener("abort", cancel, { once: true });
3332
+ server.on("request", (request, response) => {
3333
+ const url = new URL(request.url ?? "/", `http://${args.host}`);
3334
+ response.setHeader("Cache-Control", "no-store");
3335
+ if (request.method !== "GET" || url.pathname !== OAUTH_CALLBACK_PATH) {
3336
+ response.writeHead(404).end("Not found");
3337
+ return;
3338
+ }
3339
+ if (url.searchParams.get("state") !== args.state || !url.searchParams.has("code") && !url.searchParams.has("error")) {
3340
+ response.writeHead(400).end("Invalid sign-in response. Return to the sign-in window.");
3341
+ return;
3342
+ }
3343
+ response.setHeader("content-type", "text/html; charset=utf-8");
3344
+ response.end('<!doctype html><meta charset="utf-8"><title>Uru CLI sign-in</title><h1>Sign-in response received</h1><p>Return to your terminal to check whether sign-in completed. You can close this window.</p>');
3345
+ if (!settled) {
3346
+ settled = true;
3347
+ clearTimeout(timeout);
3348
+ args.signal.removeEventListener("abort", cancel);
3349
+ server.close();
3350
+ completion.resolve(url.toString());
3351
+ }
3352
+ });
3353
+ server.on("error", (cause) => fail(new CliError("Could not start OAuth callback server.", {
3354
+ code: ExitCode.AuthRequired,
3355
+ errorCode: "oauth_callback_server_failed",
3356
+ cause
3357
+ })));
3358
+ try {
3359
+ await new Promise((resolve, reject) => {
3360
+ server.once("error", reject);
3361
+ server.listen(args.port, args.host, resolve);
3362
+ });
3363
+ args.signal.throwIfAborted();
3364
+ const address = server.address();
3365
+ if (address === null || typeof address === "string") {
3366
+ throw new CliError("Could not determine OAuth callback port.");
3367
+ }
3368
+ return { port: address.port, result: completion.promise, close };
3369
+ } catch (cause) {
3370
+ close();
3371
+ if (args.signal.aborted) {
3372
+ throw new CliError("Cancelled.", { code: ExitCode.Cancelled });
3373
+ }
3374
+ throw new CliError("Could not start OAuth callback server.", {
3375
+ code: ExitCode.AuthRequired,
3376
+ errorCode: "oauth_callback_server_failed",
3377
+ cause
3378
+ });
3379
+ }
3380
+ }
3314
3381
 
3315
3382
  // ../../node_modules/.bun/zod@4.4.3/node_modules/zod/v4/core/core.js
3316
3383
  var _a;
@@ -9728,7 +9795,7 @@ var zArtifactProjectFileUpdateRequest = object({
9728
9795
  content: string2().nullish(),
9729
9796
  contentBase64: string2().nullish(),
9730
9797
  createIfMissing: boolean2().optional().default(false),
9731
- path: string2().min(1).max(1024)
9798
+ path: string2().min(1).max(240)
9732
9799
  });
9733
9800
  var zArtifactRenderEventRequest = object({
9734
9801
  dependencyNames: array(string2()).nullish(),
@@ -14563,17 +14630,17 @@ var zThreadFileView = object({
14563
14630
  "quarantined",
14564
14631
  "failed"
14565
14632
  ]),
14566
- bytes: int().nullish(),
14633
+ bytes: int().nullable(),
14567
14634
  createdAtMs: int(),
14568
14635
  fileId: uuid2(),
14569
14636
  filename: string2(),
14570
14637
  folder: _enum(["uploads", "outputs"]),
14571
14638
  kind: _enum(["file", "image", "audio", "video"]),
14572
- mime: string2().nullish(),
14639
+ mime: string2().nullable(),
14573
14640
  modelAccess: _enum(["direct", "sandbox_only"]),
14574
14641
  previewUrl: string2().nullable(),
14575
14642
  threadId: uuid2(),
14576
- url: string2().nullish()
14643
+ url: string2().nullable()
14577
14644
  });
14578
14645
  var zThreadFileListResponse = object({
14579
14646
  files: array(zThreadFileView),
@@ -14933,10 +15000,7 @@ var zThreadShareLink = object({
14933
15000
  snapshotLeafMessageId: string2().nullable(),
14934
15001
  threadId: string2()
14935
15002
  });
14936
- var zThreadShareListResponse = object({
14937
- links: array(zThreadShareLink)
14938
- });
14939
- var zThreadShareMintResponse = object({
15003
+ var zThreadShareEnsureResponse = object({
14940
15004
  link: zThreadShareLink,
14941
15005
  token: string2(),
14942
15006
  url: string2().nullable()
@@ -15282,6 +15346,8 @@ var zThreadMessagesListResponse = object({
15282
15346
  siblings: record(string2(), array(string2()))
15283
15347
  });
15284
15348
  var zThreadShareSnapshot = object({
15349
+ files: array(zThreadFileView),
15350
+ generatedAt: string2(),
15285
15351
  messages: array(zThreadExportMessage),
15286
15352
  schema: _enum(["uru.thread-share"]),
15287
15353
  sharedAt: string2(),
@@ -16323,7 +16389,9 @@ var zGetUserDetailApiAdminUsageUsersUserIdGetResponse = record(string2(), unknow
16323
16389
  var zAdminListUsersApiAdminUsersGetQuery = object({
16324
16390
  limit: int().gte(1).lte(100).optional().default(50),
16325
16391
  offset: int().gte(0).nullish().default(0),
16326
- search: string2().max(200).optional()
16392
+ search: string2().max(200).optional(),
16393
+ status: _enum(["active", "deactivated"]).optional(),
16394
+ workspaces: _enum(["one", "many"]).optional()
16327
16395
  });
16328
16396
  var zAdminGetUserApiAdminUsersUserIdGetPath = object({
16329
16397
  userId: string2()
@@ -17537,6 +17605,7 @@ var zAuthorizeRequestApiOauthAuthorizeRequestGetQuery = object({
17537
17605
  var zAuthorizeRequestApiOauthAuthorizeRequestGetResponse = object({
17538
17606
  client_id: string2(),
17539
17607
  client_name: string2(),
17608
+ redirectUri: url(),
17540
17609
  resource: url(),
17541
17610
  scope: string2(),
17542
17611
  workspace_id: string2().nullable(),
@@ -17886,7 +17955,7 @@ var zGetArtifactProjectFileContentApiPlatformArtifactsArtifactSlugProjectFilesCo
17886
17955
  artifactSlug: string2()
17887
17956
  });
17888
17957
  var zGetArtifactProjectFileContentApiPlatformArtifactsArtifactSlugProjectFilesContentGetQuery = object({
17889
- path: string2().min(1).max(1024)
17958
+ path: string2().min(1).max(240)
17890
17959
  });
17891
17960
  var zGetArtifactProjectFileContentApiPlatformArtifactsArtifactSlugProjectFilesContentGetResponse = object({
17892
17961
  artifactId: string2(),
@@ -20588,10 +20657,7 @@ var zThreadSandboxListPath = object({
20588
20657
  var zThreadSandboxListQuery = object({
20589
20658
  path: string2().max(512).optional()
20590
20659
  });
20591
- var zThreadShareListPath = object({
20592
- threadId: uuid2()
20593
- });
20594
- var zThreadShareMintPath = object({
20660
+ var zThreadShareEnsurePath = object({
20595
20661
  threadId: uuid2()
20596
20662
  });
20597
20663
  var zThreadShareRevokePath = object({
@@ -21578,6 +21644,7 @@ function normalizeTool(value) {
21578
21644
 
21579
21645
  // src/oauth.ts
21580
21646
  import { createHash, randomBytes } from "node:crypto";
21647
+ import { setTimeout as sleepTimer } from "node:timers/promises";
21581
21648
  var DEFAULT_PKCE_VERIFIER_BYTES = 32;
21582
21649
  var DEFAULT_STATE_BYTES = 24;
21583
21650
  var OAUTH_DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
@@ -21625,7 +21692,7 @@ function buildAuthorizationUrl(args) {
21625
21692
  }
21626
21693
  return url2.toString();
21627
21694
  }
21628
- function parseOAuthCallbackUrl(callbackUrl, expectedState) {
21695
+ function parseOAuthCallbackUrl(callbackUrl, expectedState, expectedIssuer, issuerRequired = false) {
21629
21696
  const url2 = new URL(callbackUrl);
21630
21697
  const state = url2.searchParams.get("state") ?? "";
21631
21698
  if (state === "" || state !== expectedState) {
@@ -21634,6 +21701,13 @@ function parseOAuthCallbackUrl(callbackUrl, expectedState) {
21634
21701
  errorCode: "oauth_state_mismatch"
21635
21702
  });
21636
21703
  }
21704
+ const issuers = url2.searchParams.getAll("iss");
21705
+ if (issuerRequired && issuers.length === 0 || issuers.length > 1 || issuers.length === 1 && issuers[0] !== expectedIssuer) {
21706
+ throw new CliError("OAuth callback issuer did not match the sign-in server.", {
21707
+ code: ExitCode.AuthRequired,
21708
+ errorCode: "oauth_issuer_mismatch"
21709
+ });
21710
+ }
21637
21711
  const error2 = url2.searchParams.get("error");
21638
21712
  if (error2 !== null && error2 !== "") {
21639
21713
  throw new CliError("OAuth authorization failed. Start sign-in again and approve access.", { code: ExitCode.AuthRequired, errorCode: "oauth_authorization_failed" });
@@ -21670,6 +21744,24 @@ async function resolveOAuthClientMetadata(args) {
21670
21744
  scope: optionalStringField(response, "scope") ?? "mcp offline_access"
21671
21745
  };
21672
21746
  }
21747
+ async function discoverOAuthIssuer(args) {
21748
+ const expectedIssuer = normalizeApiUrl(args.apiUrl);
21749
+ const metadata = await fetchOAuthGet({
21750
+ apiUrl: args.apiUrl,
21751
+ path: "/.well-known/oauth-authorization-server",
21752
+ ...args.fetch === undefined ? {} : { fetch: args.fetch }
21753
+ });
21754
+ if (!isRecord(metadata) || metadata["issuer"] !== expectedIssuer) {
21755
+ throw new CliError("OAuth discovery issuer did not match the sign-in server.", {
21756
+ code: ExitCode.AuthRequired,
21757
+ errorCode: "oauth_issuer_mismatch"
21758
+ });
21759
+ }
21760
+ return {
21761
+ issuer: expectedIssuer,
21762
+ issuerRequired: metadata["authorization_response_iss_parameter_supported"] === true
21763
+ };
21764
+ }
21673
21765
  async function discoverOAuthResource(args) {
21674
21766
  const response = await fetchOAuthGet({
21675
21767
  apiUrl: args.apiUrl,
@@ -21759,8 +21851,9 @@ async function startDeviceAuthorization(args) {
21759
21851
  }
21760
21852
  async function pollDeviceToken(args) {
21761
21853
  let intervalSeconds = Math.max(1, args.intervalSeconds);
21762
- const sleep = args.sleep ?? defaultSleep;
21854
+ const sleep = args.sleep ?? ((milliseconds) => sleepTimer(milliseconds, undefined, { signal: args.signal }));
21763
21855
  for (let attempt = 0;attempt < args.maxPolls; attempt += 1) {
21856
+ args.signal?.throwIfAborted();
21764
21857
  if (attempt > 0) {
21765
21858
  await sleep(intervalSeconds * 1000);
21766
21859
  }
@@ -21789,6 +21882,7 @@ async function pollDeviceToken(args) {
21789
21882
  errorCode: "oauth_device_failed"
21790
21883
  });
21791
21884
  }
21885
+ args.signal?.throwIfAborted();
21792
21886
  return toOAuthTokenResponse(zOAuthTokenResponse.parse(response));
21793
21887
  }
21794
21888
  throw new CliError("OAuth device login timed out before authorization completed.", {
@@ -21800,6 +21894,7 @@ async function fetchOAuthJson(args) {
21800
21894
  const fetchImpl = args.fetch ?? fetch;
21801
21895
  const response = await fetchImpl(oauthEndpoint(args.apiUrl, args.path), {
21802
21896
  method: "POST",
21897
+ signal: AbortSignal.timeout(30000),
21803
21898
  headers: {
21804
21899
  Accept: "application/json",
21805
21900
  "Content-Type": "application/json",
@@ -21820,6 +21915,7 @@ async function fetchOAuthGet(args) {
21820
21915
  const fetchImpl = args.fetch ?? fetch;
21821
21916
  const response = await fetchImpl(oauthEndpoint(args.apiUrl, args.path), {
21822
21917
  method: "GET",
21918
+ signal: AbortSignal.timeout(30000),
21823
21919
  headers: { Accept: "application/json" }
21824
21920
  });
21825
21921
  const payload = parseJsonResponse(await response.text());
@@ -21838,6 +21934,7 @@ async function fetchOAuthForm(args) {
21838
21934
  const fetchImpl = args.fetch ?? fetch;
21839
21935
  const response = await fetchImpl(oauthEndpoint(args.apiUrl, args.path), {
21840
21936
  method: "POST",
21937
+ signal: AbortSignal.timeout(30000),
21841
21938
  headers: {
21842
21939
  Accept: "application/json",
21843
21940
  "Content-Type": "application/x-www-form-urlencoded"
@@ -21985,9 +22082,6 @@ function errorMessage2(payload) {
21985
22082
  return;
21986
22083
  }
21987
22084
  }
21988
- function defaultSleep(milliseconds) {
21989
- return new Promise((resolve) => setTimeout(resolve, milliseconds));
21990
- }
21991
22085
 
21992
22086
  // src/visual.ts
21993
22087
  var PLAIN_VISUAL = { rich: false, width: 80 };
@@ -22866,8 +22960,6 @@ function objectPayload(value) {
22866
22960
  }
22867
22961
 
22868
22962
  // src/auth-commands.ts
22869
- var OAUTH_CALLBACK_PATH = "/oauth/callback";
22870
- var OAUTH_CALLBACK_TIMEOUT_MS = 5 * 60 * 1000;
22871
22963
  var DEVICE_MAX_POLLS = 120;
22872
22964
  var CIMD_CALLBACK_PORT = 8765;
22873
22965
  async function resolveStoredToken(options) {
@@ -23046,7 +23138,7 @@ async function validateSessionToken(ctx, token) {
23046
23138
  apiUrl: ctx.apiUrl,
23047
23139
  token,
23048
23140
  ...workspaceId === undefined ? {} : { workspaceId },
23049
- ...ctx.fetch !== undefined ? { fetch: ctx.fetch } : {}
23141
+ fetch: loginFetch(ctx)
23050
23142
  });
23051
23143
  return loginClient.validateToken();
23052
23144
  }
@@ -23081,7 +23173,7 @@ function canCompleteBrowserLogin(ctx) {
23081
23173
  async function loginWithDeviceCode(ctx) {
23082
23174
  const resource = await discoverOAuthResource({
23083
23175
  apiUrl: ctx.apiUrl,
23084
- ...ctx.fetch === undefined ? {} : { fetch: ctx.fetch }
23176
+ fetch: loginFetch(ctx)
23085
23177
  });
23086
23178
  const clientMetadata = await resolveOAuthClientMetadata({
23087
23179
  apiUrl: ctx.apiUrl,
@@ -23090,14 +23182,14 @@ async function loginWithDeviceCode(ctx) {
23090
23182
  port: CIMD_CALLBACK_PORT,
23091
23183
  path: OAUTH_CALLBACK_PATH
23092
23184
  }),
23093
- ...ctx.fetch !== undefined ? { fetch: ctx.fetch } : {}
23185
+ fetch: loginFetch(ctx)
23094
23186
  });
23095
23187
  const authorization = await startDeviceAuthorization({
23096
23188
  apiUrl: ctx.apiUrl,
23097
23189
  clientId: clientMetadata.clientId,
23098
23190
  scope: clientMetadata.scope,
23099
23191
  resource,
23100
- ...ctx.fetch !== undefined ? { fetch: ctx.fetch } : {}
23192
+ fetch: loginFetch(ctx)
23101
23193
  });
23102
23194
  const complete = authorization.verificationUriComplete ?? authorization.verificationUri;
23103
23195
  await maybeCopyLoginUrl(ctx, complete);
@@ -23110,8 +23202,9 @@ async function loginWithDeviceCode(ctx) {
23110
23202
  clientId: clientMetadata.clientId,
23111
23203
  deviceCode: authorization.deviceCode,
23112
23204
  intervalSeconds: authorization.interval,
23205
+ signal: ctx.abortSignal,
23113
23206
  maxPolls: Math.min(DEVICE_MAX_POLLS, Math.ceil(authorization.expiresIn / Math.max(1, authorization.interval))),
23114
- ...ctx.fetch !== undefined ? { fetch: ctx.fetch } : {}
23207
+ fetch: loginFetch(ctx)
23115
23208
  });
23116
23209
  return exchangeOAuthTokenForSession(ctx, token, clientMetadata.clientId, resource);
23117
23210
  }
@@ -23120,14 +23213,17 @@ async function loginWithBrowser(ctx) {
23120
23213
  if (ctx.callbackPort !== undefined && ctx.callbackPort !== CIMD_CALLBACK_PORT) {
23121
23214
  throw new CliError(`Uru CLI requires callback port ${CIMD_CALLBACK_PORT} for OAuth Client ID Metadata.`);
23122
23215
  }
23123
- const callback = await waitForOAuthCallback({
23216
+ const state = generateOAuthState();
23217
+ const callback = await listenForOAuthCallback({
23124
23218
  host: callbackHost,
23125
- port: CIMD_CALLBACK_PORT
23219
+ port: CIMD_CALLBACK_PORT,
23220
+ state,
23221
+ signal: ctx.abortSignal
23126
23222
  });
23127
23223
  try {
23128
23224
  const resource = await discoverOAuthResource({
23129
23225
  apiUrl: ctx.apiUrl,
23130
- ...ctx.fetch === undefined ? {} : { fetch: ctx.fetch }
23226
+ fetch: loginFetch(ctx)
23131
23227
  });
23132
23228
  const redirectUri = buildLoopbackRedirectUri({
23133
23229
  host: callbackHost,
@@ -23137,10 +23233,10 @@ async function loginWithBrowser(ctx) {
23137
23233
  const clientMetadata = await resolveOAuthClientMetadata({
23138
23234
  apiUrl: ctx.apiUrl,
23139
23235
  redirectUri,
23140
- ...ctx.fetch !== undefined ? { fetch: ctx.fetch } : {}
23236
+ fetch: loginFetch(ctx)
23141
23237
  });
23238
+ const issuer = await discoverOAuthIssuer({ apiUrl: ctx.apiUrl, fetch: loginFetch(ctx) });
23142
23239
  const pkce = generatePkcePair();
23143
- const state = generateOAuthState();
23144
23240
  const authorizationUrl = buildAuthorizationUrl({
23145
23241
  authorizationEndpoint: `${normalizeApiUrl(ctx.apiUrl)}/oauth/authorize`,
23146
23242
  clientId: clientMetadata.clientId,
@@ -23160,7 +23256,7 @@ async function loginWithBrowser(ctx) {
23160
23256
  `);
23161
23257
  }
23162
23258
  const callbackUrl = await callback.result;
23163
- const authorization = parseOAuthCallbackUrl(callbackUrl, state);
23259
+ const authorization = parseOAuthCallbackUrl(callbackUrl, state, issuer.issuer, issuer.issuerRequired);
23164
23260
  const token = await exchangeAuthorizationCode({
23165
23261
  apiUrl: ctx.apiUrl,
23166
23262
  clientId: clientMetadata.clientId,
@@ -23168,7 +23264,7 @@ async function loginWithBrowser(ctx) {
23168
23264
  redirectUri,
23169
23265
  codeVerifier: pkce.verifier,
23170
23266
  resource,
23171
- ...ctx.fetch !== undefined ? { fetch: ctx.fetch } : {}
23267
+ fetch: loginFetch(ctx)
23172
23268
  });
23173
23269
  return exchangeOAuthTokenForSession(ctx, token, clientMetadata.clientId, resource);
23174
23270
  } finally {
@@ -23181,7 +23277,7 @@ async function exchangeOAuthTokenForSession(ctx, token, clientId, resource) {
23181
23277
  apiUrl: ctx.apiUrl,
23182
23278
  oauthAccessToken: token.accessToken,
23183
23279
  ...ctx.workspace !== undefined ? { workspaceId: ctx.workspace } : {},
23184
- ...ctx.fetch !== undefined ? { fetch: ctx.fetch } : {}
23280
+ fetch: loginFetch(ctx)
23185
23281
  });
23186
23282
  if (session.oauthResource !== resource) {
23187
23283
  throw new CliError("CLI session OAuth resource did not match discovery.", {
@@ -23270,61 +23366,14 @@ async function maybeCopyLoginUrl(ctx, url2) {
23270
23366
  ctx.io.stderr.write(`Copied login URL to clipboard.
23271
23367
  `);
23272
23368
  }
23273
- async function waitForOAuthCallback(args) {
23274
- const server = createServer();
23275
- const result = new Promise((resolve, reject) => {
23276
- const timeout = setTimeout(() => {
23277
- server.close();
23278
- reject(new CliError("OAuth login timed out waiting for browser callback.", {
23279
- code: ExitCode.AuthRequired,
23280
- errorCode: "oauth_callback_timeout"
23281
- }));
23282
- }, OAUTH_CALLBACK_TIMEOUT_MS);
23283
- server.on("request", (request, response) => {
23284
- handleOAuthCallbackRequest(request, response, {
23285
- host: args.host,
23286
- onComplete: (callbackUrl) => {
23287
- clearTimeout(timeout);
23288
- server.close();
23289
- resolve(callbackUrl);
23290
- }
23291
- });
23292
- });
23293
- server.on("error", (error2) => {
23294
- clearTimeout(timeout);
23295
- reject(new CliError("Could not start OAuth callback server.", {
23296
- code: ExitCode.AuthRequired,
23297
- errorCode: "oauth_callback_server_failed",
23298
- cause: error2
23299
- }));
23300
- });
23301
- });
23302
- await new Promise((resolve, reject) => {
23303
- server.listen(args.port ?? 0, args.host, resolve);
23304
- server.once("error", reject);
23369
+ function loginFetch(ctx) {
23370
+ return (input, init) => (ctx.fetch ?? fetch)(input, {
23371
+ ...init,
23372
+ signal: AbortSignal.any([
23373
+ ctx.abortSignal,
23374
+ init?.signal ?? AbortSignal.timeout(30000)
23375
+ ])
23305
23376
  });
23306
- const address = server.address();
23307
- if (address === null || typeof address === "string") {
23308
- server.close();
23309
- throw new CliError("Could not determine OAuth callback port.", {
23310
- code: ExitCode.AuthRequired,
23311
- errorCode: "oauth_callback_server_failed"
23312
- });
23313
- }
23314
- return { port: address.port, result, close: () => server.close() };
23315
- }
23316
- function handleOAuthCallbackRequest(request, response, args) {
23317
- const requestUrl = request.url ?? "/";
23318
- const parsed = new URL(requestUrl, `http://${args.host}`);
23319
- if (parsed.pathname !== OAUTH_CALLBACK_PATH) {
23320
- response.statusCode = 404;
23321
- response.end("Not found");
23322
- return;
23323
- }
23324
- response.statusCode = 200;
23325
- response.setHeader("content-type", "text/html; charset=utf-8");
23326
- response.end('<!doctype html><meta charset="utf-8"><title>Uru CLI login</title><body><h1>Uru CLI login complete</h1><p>You can close this window and return to your terminal.</p></body>');
23327
- args.onComplete(`http://${args.host}${requestUrl}`);
23328
23377
  }
23329
23378
 
23330
23379
  // src/cli-helpers.ts
@@ -32186,6 +32235,10 @@ function throwIfCancelled(signal) {
32186
32235
  throw new CliError("Cancelled.", { code: ExitCode.Cancelled, cause: reason });
32187
32236
  }
32188
32237
  async function dispatchWithImplicitLogin(ctx, command, linkedProject) {
32238
+ if (command[0] === "login") {
32239
+ await dispatchCliCommand(ctx, command, linkedProject);
32240
+ return;
32241
+ }
32189
32242
  let activeCtx = ctx;
32190
32243
  let recoveredFromSessionRevoked = false;
32191
32244
  for (;; ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uru-intelligence/cli",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "private": false,
5
5
  "description": "Uru full-platform command line interface",
6
6
  "repository": {