@oxagen/cli 3.0.1-816 → 3.0.1-817

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 (2) hide show
  1. package/oxagen.mjs +266 -75
  2. package/package.json +1 -1
package/oxagen.mjs CHANGED
@@ -16769,8 +16769,8 @@ var init_backfill = __esm({
16769
16769
  this.parentMs = ms;
16770
16770
  this.clock.ms = ms;
16771
16771
  }
16772
- const spawn9 = [];
16773
- return { events: this.mappedLine(parsed2, text6, offset, spawn9), spawn: spawn9 };
16772
+ const spawn10 = [];
16773
+ return { events: this.mappedLine(parsed2, text6, offset, spawn10), spawn: spawn10 };
16774
16774
  }
16775
16775
  /**
16776
16776
  * Begin a session still waiting for its facts once its last line is read:
@@ -16796,28 +16796,28 @@ var init_backfill = __esm({
16796
16796
  this.parentMs = timestampOf(first) ?? 0;
16797
16797
  this.clock.ms = this.parentMs;
16798
16798
  const events = this.collect(this.start(first, facts, permissionMode));
16799
- const spawn9 = [];
16799
+ const spawn10 = [];
16800
16800
  for (const item of early) {
16801
16801
  const ms = timestampOf(item.record);
16802
16802
  if (ms !== void 0) this.parentMs = Math.max(this.parentMs, ms);
16803
16803
  this.clock.ms = ms ?? this.parentMs;
16804
16804
  events.push(
16805
- ...this.mappedLine(item.record, item.text, item.offset, spawn9)
16805
+ ...this.mappedLine(item.record, item.text, item.offset, spawn10)
16806
16806
  );
16807
16807
  }
16808
16808
  this.clock.ms = this.parentMs;
16809
- return { events, spawn: spawn9 };
16809
+ return { events, spawn: spawn10 };
16810
16810
  }
16811
16811
  /** One parent line through the mapping, guarded. */
16812
- mappedLine(record2, text6, offset, spawn9) {
16812
+ mappedLine(record2, text6, offset, spawn10) {
16813
16813
  const spawnedBefore = this.spawned.size;
16814
- const spawnLength = spawn9.length;
16814
+ const spawnLength = spawn10.length;
16815
16815
  return this.guarded(
16816
16816
  offset,
16817
16817
  void 0,
16818
- () => this.mapped(record2, text6, spawn9),
16818
+ () => this.mapped(record2, text6, spawn10),
16819
16819
  () => {
16820
- spawn9.length = spawnLength;
16820
+ spawn10.length = spawnLength;
16821
16821
  for (const toolUseId of [...this.spawned.keys()].slice(spawnedBefore))
16822
16822
  this.spawned.delete(toolUseId);
16823
16823
  }
@@ -17034,7 +17034,7 @@ var init_backfill = __esm({
17034
17034
  })
17035
17035
  );
17036
17036
  }
17037
- mapped(record2, text6, spawn9) {
17037
+ mapped(record2, text6, spawn10) {
17038
17038
  const type = nonEmptyString(record2["type"]);
17039
17039
  const ms = timestampOf(record2);
17040
17040
  const events = [];
@@ -17167,7 +17167,7 @@ var init_backfill = __esm({
17167
17167
  ms
17168
17168
  )
17169
17169
  );
17170
- spawn9.push(subagent.agentId);
17170
+ spawn10.push(subagent.agentId);
17171
17171
  }
17172
17172
  return events;
17173
17173
  }
@@ -21051,14 +21051,14 @@ var init_recorder = __esm({
21051
21051
  const parent = this.options.parent;
21052
21052
  if (parent === void 0) return;
21053
21053
  const type = parent.subagentType === void 0 ? subagentType : void 0;
21054
- const spawn9 = parent.spawnToolUseId === void 0 ? spawnToolUseId : void 0;
21055
- if (type === void 0 && spawn9 === void 0) return;
21054
+ const spawn10 = parent.spawnToolUseId === void 0 ? spawnToolUseId : void 0;
21055
+ if (type === void 0 && spawn10 === void 0) return;
21056
21056
  this.options = {
21057
21057
  ...this.options,
21058
21058
  parent: {
21059
21059
  ...parent,
21060
21060
  ...type !== void 0 ? { subagentType: type } : {},
21061
- ...spawn9 !== void 0 ? { spawnToolUseId: spawn9 } : {}
21061
+ ...spawn10 !== void 0 ? { spawnToolUseId: spawn10 } : {}
21062
21062
  }
21063
21063
  };
21064
21064
  }
@@ -24774,12 +24774,12 @@ async function sealTranscript(candidate, deps, pass2) {
24774
24774
  const read2 = await readSlices(candidate.path, sliceBytes, async (lines) => {
24775
24775
  let index = 0;
24776
24776
  while (index < lines.length) {
24777
- const spawn9 = [];
24777
+ const spawn10 = [];
24778
24778
  await deps.exclusive(candidate.sessionId, () => {
24779
24779
  if (deps.heldLocally(candidate.sessionId)) throw new TakenLive();
24780
24780
  const out = [];
24781
24781
  let next = readTo;
24782
- while (spawn9.length === 0) {
24782
+ while (spawn10.length === 0) {
24783
24783
  const line = lines[index];
24784
24784
  if (line === void 0) break;
24785
24785
  index += 1;
@@ -24790,7 +24790,7 @@ async function sealTranscript(candidate, deps, pass2) {
24790
24790
  }
24791
24791
  const sealed = driver.line(line.text, line.offset);
24792
24792
  out.push(...sealed.events);
24793
- spawn9.push(...sealed.spawn);
24793
+ spawn10.push(...sealed.spawn);
24794
24794
  }
24795
24795
  emit(out);
24796
24796
  if (driver.hasChain) {
@@ -24798,7 +24798,7 @@ async function sealTranscript(candidate, deps, pass2) {
24798
24798
  partial2(readTo, { status: "partial" });
24799
24799
  }
24800
24800
  });
24801
- for (const agentId of spawn9) await feedSubagent(agentId);
24801
+ for (const agentId of spawn10) await feedSubagent(agentId);
24802
24802
  }
24803
24803
  await between();
24804
24804
  });
@@ -29915,7 +29915,7 @@ import { readFileSync as readFileSync10 } from "node:fs";
29915
29915
  import { dirname as dirname9, resolve as resolve3 } from "node:path";
29916
29916
  import { fileURLToPath } from "node:url";
29917
29917
  function readVersion() {
29918
- if (true) return "3.0.1-816";
29918
+ if (true) return "3.0.1-817";
29919
29919
  try {
29920
29920
  const here = dirname9(fileURLToPath(import.meta.url));
29921
29921
  const pkg = JSON.parse(
@@ -56272,7 +56272,7 @@ function serverEnvironment(env, settings) {
56272
56272
  function createCodeGraphSupervisor(deps) {
56273
56273
  const home = deps.home ?? homedir6();
56274
56274
  const root = codegraphRoot(deps.env, home);
56275
- const spawn9 = deps.spawn ?? spawnChild;
56275
+ const spawn10 = deps.spawn ?? spawnChild;
56276
56276
  const sleep2 = deps.sleep ?? ((ms) => new Promise((resolve29) => setTimeout(resolve29, ms)));
56277
56277
  const localFetch = deps.localFetch ?? ((url2, init) => globalThis.fetch(url2, init));
56278
56278
  const isExecutable2 = deps.isExecutable ?? defaultIsExecutable;
@@ -56325,7 +56325,7 @@ function createCodeGraphSupervisor(deps) {
56325
56325
  }
56326
56326
  function runOnce(bin, args) {
56327
56327
  return new Promise((resolve29) => {
56328
- const child = spawn9(bin, args, {
56328
+ const child = spawn10(bin, args, {
56329
56329
  env: serverEnvironment(deps.env, void 0),
56330
56330
  stdio: ["ignore", "ignore", "pipe"]
56331
56331
  });
@@ -56486,7 +56486,7 @@ function createCodeGraphSupervisor(deps) {
56486
56486
  );
56487
56487
  facts.memoryMb = memory.mb;
56488
56488
  facts.memoryFrom = memory.from;
56489
- const child = spawn9(
56489
+ const child = spawn10(
56490
56490
  bin,
56491
56491
  [
56492
56492
  "serve",
@@ -73448,7 +73448,7 @@ var init_package = __esm({
73448
73448
  "package.json"() {
73449
73449
  package_default = {
73450
73450
  name: "@oxagen/cli",
73451
- version: "3.0.1-816",
73451
+ version: "3.0.1-817",
73452
73452
  description: "Oxagen governance CLI: spend, source tracking, grounding, credentials, and audit (agentic coding lives in the stella CLI)",
73453
73453
  type: "module",
73454
73454
  main: "./dist/index.js",
@@ -92471,6 +92471,7 @@ __export(host_exports, {
92471
92471
  SCHTASKS_NAME: () => SCHTASKS_NAME,
92472
92472
  SERVICE_LABEL: () => SERVICE_LABEL,
92473
92473
  SESSION_END_TIMEOUT_S: () => SESSION_END_TIMEOUT_S,
92474
+ SETUP_TOKEN_EXIT_MARK: () => SETUP_TOKEN_EXIT_MARK,
92474
92475
  SPOOLED_HOOK_EVENTS: () => SPOOLED_HOOK_EVENTS,
92475
92476
  STATIC_TOKEN_HARNESSES: () => STATIC_TOKEN_HARNESSES,
92476
92477
  STATIC_TOKEN_RENEW_WINDOW_MS: () => STATIC_TOKEN_RENEW_WINDOW_MS,
@@ -92535,7 +92536,10 @@ __export(host_exports, {
92535
92536
  ensureDir: () => ensureDir,
92536
92537
  envOf: () => envOf,
92537
92538
  evaluatePreToolUse: () => evaluatePreToolUse,
92539
+ extractSetupToken: () => extractSetupToken,
92538
92540
  fileVersion: () => fileVersion,
92541
+ findClaudeBinary: () => findClaudeBinary,
92542
+ findHarnessBinary: () => findHarnessBinary,
92539
92543
  foldMcpServerCase: () => foldMcpServerCase,
92540
92544
  formatDaemonPid: () => formatDaemonPid,
92541
92545
  frameListLength: () => frameListLength,
@@ -92560,6 +92564,7 @@ __export(host_exports, {
92560
92564
  isDaemonImage: () => isDaemonImage,
92561
92565
  isModelProxyBaseUrl: () => isModelProxyBaseUrl,
92562
92566
  isProcessAlive: () => isProcessAlive,
92567
+ isSubscriptionToken: () => isSubscriptionToken,
92563
92568
  isTachoEntry: () => isTachoEntry,
92564
92569
  isTachoGroup: () => isTachoGroup,
92565
92570
  isTachoHelper: () => isTachoHelper,
@@ -92628,12 +92633,15 @@ __export(host_exports, {
92628
92633
  restoreModelCredentials: () => restoreModelCredentials,
92629
92634
  revokedSubjectDigest: () => revokedSubjectDigest,
92630
92635
  ruleMatches: () => ruleMatches,
92636
+ runClaudeSetupToken: () => runClaudeSetupToken,
92631
92637
  runTokenKeyFromHex: () => runTokenKeyFromHex,
92632
92638
  serializeJsonLike: () => serializeJsonLike,
92633
92639
  serviceManagerFor: () => serviceManagerFor,
92634
92640
  sessionScopeForEnrollment: () => sessionScopeForEnrollment,
92635
92641
  sessionScopeOf: () => sessionScopeOf,
92636
92642
  settingsShapeProblem: () => settingsShapeProblem,
92643
+ setupTokenCommand: () => setupTokenCommand,
92644
+ setupTokenShellLine: () => setupTokenShellLine,
92637
92645
  shellSegments: () => shellSegments,
92638
92646
  sidecarBeside: () => sidecarBeside,
92639
92647
  signBytes: () => signBytes,
@@ -92685,6 +92693,7 @@ var init_host = __esm({
92685
92693
  "use strict";
92686
92694
  init_agents();
92687
92695
  init_bundle();
92696
+ init_claude_setup_token();
92688
92697
  init_codex_writer();
92689
92698
  init_control_client();
92690
92699
  init_credential_store();
@@ -110454,14 +110463,21 @@ __export(credentials_exports, {
110454
110463
  LOGIN_HARNESSES: () => LOGIN_HARNESSES,
110455
110464
  PROVIDERS: () => PROVIDERS,
110456
110465
  SecretAborted: () => SecretAborted,
110457
- addBodyOf: () => addBodyOf,
110458
- credentialsAdd: () => credentialsAdd,
110466
+ createBodyOf: () => createBodyOf,
110467
+ createSetupTokenHider: () => createSetupTokenHider,
110468
+ credentialsCreate: () => credentialsCreate,
110459
110469
  credentialsList: () => credentialsList,
110460
110470
  credentialsRemove: () => credentialsRemove,
110461
110471
  credentialsRotate: () => credentialsRotate,
110462
110472
  credentialsUpdate: () => credentialsUpdate,
110463
- readSecret: () => readSecret
110473
+ hideSetupToken: () => hideSetupToken,
110474
+ readCodexAuthFile: () => readCodexAuthFile,
110475
+ readSecret: () => readSecret,
110476
+ runHarnessLogin: () => runHarnessLogin
110464
110477
  });
110478
+ import { spawn as spawn8 } from "node:child_process";
110479
+ import { homedir as homedir14 } from "node:os";
110480
+ import { join as join68 } from "node:path";
110465
110481
  function sharedBody(opts) {
110466
110482
  return opts.shared ? { scope: "workspace" } : {};
110467
110483
  }
@@ -110520,22 +110536,22 @@ function scopeFor(opts) {
110520
110536
  const ws = namedWorkspace(opts.workspaceSlug) ?? getWorkspaceId();
110521
110537
  if (!ws) {
110522
110538
  return {
110523
- error: "Name a workspace with --workspace-slug <slug> or OXAGEN_WORKSPACE. Your credentials belong to you, but the API still addresses them under a workspace."
110539
+ error: opts.shared ? "A workspace account belongs to one workspace. Run `oxagen workspace use <org/workspace>` to choose it, or name one with --workspace-slug <slug> or OXAGEN_WORKSPACE." : "Your credentials belong to you, not to a workspace, but the API still addresses them through one. Run `oxagen workspace use <org/workspace>` to choose the workspace this call goes through, or name one with --workspace-slug <slug> or OXAGEN_WORKSPACE."
110524
110540
  };
110525
110541
  }
110526
110542
  const org = getOrgId();
110527
110543
  if (!org) return { error: NO_ORG };
110528
110544
  return { org, ws };
110529
110545
  }
110530
- function addBodyOf(opts) {
110531
- const type = opts.type ?? "api-key";
110546
+ function createBodyOf(opts) {
110547
+ const harness = opts.harness;
110548
+ const type = opts.type ?? (harness !== void 0 ? "subscription" : "api-key");
110532
110549
  if (!(type in AUTH_TYPES)) {
110533
110550
  return {
110534
110551
  error: `Pass --type with one of: ${Object.keys(AUTH_TYPES).join(", ")}.`
110535
110552
  };
110536
110553
  }
110537
110554
  const authType = AUTH_TYPES[type];
110538
- const harness = opts.harness;
110539
110555
  if (harness !== void 0 && !LOGIN_HARNESSES.includes(harness)) {
110540
110556
  return {
110541
110557
  error: harness === "cursor" ? "Cursor's model calls do not pass through the gateway, so Oxagen cannot use a Cursor login." : `Pass --harness with one of: ${LOGIN_HARNESSES.join(", ")}.`
@@ -110543,7 +110559,7 @@ function addBodyOf(opts) {
110543
110559
  }
110544
110560
  if (opts.baseUrl !== void 0 && opts.provider !== CUSTOM_ENDPOINT_PROVIDER) {
110545
110561
  return {
110546
- error: `Only --provider ${CUSTOM_ENDPOINT_PROVIDER} takes --base-url. Anthropic and OpenAI keys use the vendor's own endpoint.`
110562
+ error: `Only --provider ${CUSTOM_ENDPOINT_PROVIDER} takes --base-url. Anthropic, OpenAI, and OpenRouter keys use the vendor's own endpoint.`
110547
110563
  };
110548
110564
  }
110549
110565
  if (authType === "subscription_token") {
@@ -110568,7 +110584,9 @@ function addBodyOf(opts) {
110568
110584
  }
110569
110585
  const provider = opts.provider;
110570
110586
  if (!provider || !PROVIDERS.includes(provider)) {
110571
- return { error: `Pass --provider with one of: ${PROVIDERS.join(", ")}.` };
110587
+ return {
110588
+ error: `Pass --provider with one of: ${PROVIDERS.join(", ")} to save a key, or --harness with one of: ${LOGIN_HARNESSES.join(", ")} to save a login.`
110589
+ };
110572
110590
  }
110573
110591
  if (provider === CUSTOM_ENDPOINT_PROVIDER) {
110574
110592
  const baseUrl = opts.baseUrl?.trim();
@@ -110595,26 +110613,178 @@ function addBodyOf(opts) {
110595
110613
  ...opts.label ? { label: opts.label } : {}
110596
110614
  };
110597
110615
  }
110598
- async function credentialsAdd(opts, writer = stdoutWriter, deps = {}) {
110616
+ function hideSetupToken(chunk) {
110617
+ return chunk.replace(SETUP_TOKEN_ON_SCREEN, "sk-ant-oat\u2026 (sent to Oxagen)");
110618
+ }
110619
+ function createSetupTokenHider(write) {
110620
+ let held = "";
110621
+ return {
110622
+ push(chunk) {
110623
+ const text6 = held + chunk;
110624
+ const tail = SETUP_TOKEN_TAIL.exec(text6);
110625
+ const cut = tail === null ? text6.length : tail.index;
110626
+ held = text6.slice(cut);
110627
+ if (cut > 0) write(hideSetupToken(text6.slice(0, cut)));
110628
+ },
110629
+ end() {
110630
+ if (held !== "") write(hideSetupToken(held));
110631
+ held = "";
110632
+ }
110633
+ };
110634
+ }
110635
+ function spawnCodexLogin(codex) {
110636
+ return new Promise((resolve29, reject) => {
110637
+ const child = spawn8(codex, ["login"], {
110638
+ stdio: ["inherit", 2, "inherit"],
110639
+ env: process.env
110640
+ });
110641
+ child.on("error", reject);
110642
+ child.on("close", (code) => resolve29(code ?? 1));
110643
+ });
110644
+ }
110645
+ async function runHarnessLogin(harness) {
110646
+ const host = await Promise.resolve().then(() => (init_host(), host_exports));
110647
+ if (harness === "claude-code") {
110648
+ const claude = host.findClaudeBinary(process.env, homedir14());
110649
+ if (claude === void 0) return { found: false };
110650
+ const screen = createSetupTokenHider((text6) => {
110651
+ process.stderr.write(text6);
110652
+ });
110653
+ const run3 = await host.runClaudeSetupToken({
110654
+ claude,
110655
+ interactive: true,
110656
+ write: screen.push
110657
+ });
110658
+ screen.end();
110659
+ return { found: true, code: run3.code, token: run3.token };
110660
+ }
110661
+ const codex = host.findHarnessBinary("codex", process.env, homedir14());
110662
+ if (codex === void 0) return { found: false };
110663
+ return { found: true, code: await spawnCodexLogin(codex), token: void 0 };
110664
+ }
110665
+ async function readCodexAuthFile() {
110666
+ const host = await Promise.resolve().then(() => (init_host(), host_exports));
110667
+ const path2 = join68(host.codexHomeFor(process.env, homedir14()), "auth.json");
110668
+ return { path: path2, text: host.readTextIfExists(path2) };
110669
+ }
110670
+ function keyFlagOf(key) {
110671
+ if (key === void 0) return { kind: "none" };
110672
+ const value = key.trim();
110673
+ if (value === "-") return { kind: "stdin" };
110674
+ if (value === "") {
110675
+ return {
110676
+ error: "--key needs the key, or - to read it from standard input."
110677
+ };
110678
+ }
110679
+ return { kind: "literal", value };
110680
+ }
110681
+ function whatOf(body2) {
110682
+ if (body2.authType === "subscription_token") return `${body2.harness} login`;
110683
+ if (body2.baseUrl !== void 0) return `key for ${body2.baseUrl}`;
110684
+ return `${body2.provider} credential`;
110685
+ }
110686
+ async function claudeLogin(out, read2, deps) {
110687
+ out.info("Running `claude setup-token`. Finish the sign-in in your browser.");
110688
+ const run3 = await (deps.runLogin ?? runHarnessLogin)("claude-code");
110689
+ if (!run3.found) {
110690
+ return {
110691
+ failure: "Claude Code is not installed, so `claude setup-token` cannot run. Install it, or pipe the token in: oxagen credentials create --harness claude-code --key -",
110692
+ code: "login"
110693
+ };
110694
+ }
110695
+ if (run3.code !== 0) {
110696
+ return {
110697
+ failure: `\`claude setup-token\` exited with ${run3.code}. Nothing was saved.`,
110698
+ code: "login"
110699
+ };
110700
+ }
110701
+ if (run3.token !== void 0) return { secret: run3.token };
110702
+ out.info(
110703
+ "The sign-in finished, but Oxagen could not read the token off its screen."
110704
+ );
110705
+ return { secret: await read2("Paste the token `claude setup-token` printed") };
110706
+ }
110707
+ async function codexLogin2(out, deps) {
110708
+ const readFile8 = deps.readCodexAuth ?? readCodexAuthFile;
110709
+ const saved = await readFile8();
110710
+ if (saved.text !== void 0) {
110711
+ out.info(`Using the Codex login in ${saved.path}.`);
110712
+ return { secret: saved.text.trim() };
110713
+ }
110714
+ out.info("Running `codex login`. Finish the sign-in in your browser.");
110715
+ const run3 = await (deps.runLogin ?? runHarnessLogin)("codex");
110716
+ if (!run3.found) {
110717
+ return {
110718
+ failure: `Codex is not installed, so \`codex login\` cannot run. Install it, or pipe a login in: ${CODEX_PIPE}`,
110719
+ code: "login"
110720
+ };
110721
+ }
110722
+ if (run3.code !== 0) {
110723
+ return {
110724
+ failure: `\`codex login\` exited with ${run3.code}. Nothing was saved.`,
110725
+ code: "login"
110726
+ };
110727
+ }
110728
+ const made = await readFile8();
110729
+ if (made.text === void 0) {
110730
+ return {
110731
+ failure: `\`codex login\` finished, but ${made.path} does not exist. Nothing was saved.`,
110732
+ code: "login"
110733
+ };
110734
+ }
110735
+ return { secret: made.text.trim() };
110736
+ }
110737
+ async function secretFor(body2, key, isTty, out, deps) {
110738
+ const read2 = deps.readSecret ?? readSecret;
110739
+ try {
110740
+ if (key.kind === "literal") return { secret: key.value };
110741
+ if (key.kind === "none" && isTty) {
110742
+ if (body2.harness === "claude-code") {
110743
+ return await claudeLogin(out, read2, deps);
110744
+ }
110745
+ if (body2.harness === "codex") return await codexLogin2(out, deps);
110746
+ }
110747
+ return { secret: await read2(`Paste the ${whatOf(body2)}`) };
110748
+ } catch (err2) {
110749
+ return {
110750
+ failure: err2,
110751
+ code: err2 instanceof SecretAborted ? "cancelled" : "input"
110752
+ };
110753
+ }
110754
+ }
110755
+ function notUsedYet(credential) {
110756
+ if (credential.authType === "subscription_token") {
110757
+ return credential.harness === "codex" ? "Codex runs don't use a ChatGPT login yet" : void 0;
110758
+ }
110759
+ return credential.provider === "openrouter" || credential.baseUrl ? "Sandbox runs don't use this key yet" : void 0;
110760
+ }
110761
+ function savedLine(credential, shared) {
110762
+ const what = credential.authType === "subscription_token" ? `the ${credential.harness ?? credential.provider} login` : credential.provider === "openrouter" ? "the openrouter key" : credential.baseUrl ? `the key for ${credential.baseUrl}` : `the ${credential.provider} key`;
110763
+ const saved = `Saved ${what} ending ${credential.hint} as ${credential.id}.`;
110764
+ const idle = notUsedYet(credential);
110765
+ if (shared) {
110766
+ return idle === void 0 ? `${saved} Runs whose account source names this workspace can use it.` : `${saved} It belongs to this workspace. ${idle}, and Oxagen keeps it until they do.`;
110767
+ }
110768
+ return idle === void 0 ? `${saved} Your runs in every workspace can use it.` : `${saved} It is yours in every workspace. ${idle}, and Oxagen keeps it until they do.`;
110769
+ }
110770
+ async function credentialsCreate(opts, writer = stdoutWriter, deps = {}) {
110599
110771
  const out = createOutput({ json: opts.json }, writer);
110600
- const body2 = addBodyOf(opts);
110772
+ const body2 = createBodyOf(opts);
110601
110773
  if ("error" in body2) return out.error(body2.error, "usage");
110602
- const isCodexLogin = body2.authType === "subscription_token" && body2.harness === "codex";
110603
- if (isCodexLogin && (deps.isTty ?? (() => process.stdin.isTTY === true))()) {
110774
+ const key = keyFlagOf(opts.key);
110775
+ if ("error" in key) return out.error(key.error, "usage");
110776
+ const isTty = (deps.isTty ?? (() => process.stdin.isTTY === true))();
110777
+ if (body2.harness === "codex" && (key.kind === "literal" || key.kind === "stdin" && isTty)) {
110604
110778
  return out.error(
110605
- "A ChatGPT login is a file. Pipe it in: oxagen credentials add --type subscription --harness codex < ~/.codex/auth.json",
110779
+ `A ChatGPT login is a file, so an argument or a prompt cannot carry it. Pipe it in: ${CODEX_PIPE}. To sign in on this terminal instead, leave out --key.`,
110606
110780
  "usage"
110607
110781
  );
110608
110782
  }
110609
110783
  const scope = scopeFor(opts);
110610
110784
  if ("error" in scope) return out.error(scope.error, "usage");
110611
- const what = body2.authType === "subscription_token" ? `${body2.harness} login` : body2.baseUrl !== void 0 ? `key for ${body2.baseUrl}` : `${body2.provider} credential`;
110612
- let secret;
110613
- try {
110614
- secret = await (deps.readSecret ?? readSecret)(`Paste the ${what}`);
110615
- } catch (err2) {
110616
- return out.error(err2, err2 instanceof SecretAborted ? "cancelled" : "input");
110617
- }
110785
+ const got = await secretFor(body2, key, isTty, out, deps);
110786
+ if ("failure" in got) return out.error(got.failure, got.code);
110787
+ const { secret } = got;
110618
110788
  if (secret.length < MIN_SECRET || secret.length > MAX_SECRET) {
110619
110789
  return out.error(
110620
110790
  `A credential is ${MIN_SECRET} to ${MAX_SECRET} characters. Nothing was stored.`,
@@ -110627,16 +110797,15 @@ async function credentialsAdd(opts, writer = stdoutWriter, deps = {}) {
110627
110797
  { ...body2, ...sharedBody(opts), secret },
110628
110798
  scope
110629
110799
  );
110630
- if (out.isJson) {
110631
- out.data({ credential });
110632
- return;
110633
- }
110634
- writer.write(
110635
- credential.baseUrl ? `Stored the key ending ${credential.hint} for ${credential.baseUrl} as ${credential.id}. Sandbox runs don't use your own endpoint yet. Oxagen keeps the key until they do.` : opts.shared ? `Stored the ${credential.provider} account ending ${credential.hint} as ${credential.id}. Runs whose account source names this workspace can use it.` : `Stored the ${credential.provider} credential ending ${credential.hint} as ${credential.id}. Only your own runs use it.`
110636
- );
110800
+ if (out.isJson) out.data({ credential });
110801
+ else writer.write(savedLine(credential, opts.shared === true));
110802
+ if (key.kind === "literal") writer.writeErr(KEY_IN_HISTORY);
110637
110803
  } catch (err2) {
110638
110804
  const refusal = refusalOf3(err2);
110639
- out.error(refusal.message, refusal.reason ?? "api");
110805
+ out.error(
110806
+ refusal.reason === "model_credential_duplicate" ? `${refusal.message} Run \`oxagen credentials list\` to see your credentials.` : refusal.message,
110807
+ refusal.reason ?? "api"
110808
+ );
110640
110809
  }
110641
110810
  }
110642
110811
  async function credentialsList(opts, writer = stdoutWriter) {
@@ -110655,7 +110824,7 @@ async function credentialsList(opts, writer = stdoutWriter) {
110655
110824
  }
110656
110825
  if (items.length === 0) {
110657
110826
  writer.write(
110658
- "You have no model credentials in Oxagen. Add one with `oxagen credentials add --provider anthropic`."
110827
+ "You have no model credentials in Oxagen. Save one with `oxagen credentials create --harness claude-code` or `oxagen credentials create --provider anthropic`."
110659
110828
  );
110660
110829
  return;
110661
110830
  }
@@ -110777,7 +110946,7 @@ async function credentialsRotate(credentialId, opts, writer = stdoutWriter, deps
110777
110946
  }
110778
110947
  if (current.authType !== "api_key") {
110779
110948
  return out.error(
110780
- "This credential is a subscription login, so it has no key to rotate. Add the new login, then remove this one.",
110949
+ "This credential is a subscription login, so it has no key to rotate. Create the new login, then remove this one.",
110781
110950
  "model_credential_not_rotatable"
110782
110951
  );
110783
110952
  }
@@ -110847,7 +111016,7 @@ async function credentialsRemove(credentialId, opts, writer = stdoutWriter) {
110847
111016
  out.error(refusal.message, refusal.reason ?? "api");
110848
111017
  }
110849
111018
  }
110850
- var PROVIDERS, CUSTOM_ENDPOINT_PROVIDER, AUTH_TYPES, LOGIN_HARNESSES, LOGIN_PROVIDER, MIN_SECRET, MAX_SECRET, CREDENTIAL_ID, SecretAborted;
111019
+ var PROVIDERS, CUSTOM_ENDPOINT_PROVIDER, AUTH_TYPES, LOGIN_HARNESSES, LOGIN_PROVIDER, MIN_SECRET, MAX_SECRET, CREDENTIAL_ID, SecretAborted, SETUP_TOKEN_ON_SCREEN, SETUP_TOKEN_START, SETUP_TOKEN_TAIL, KEY_IN_HISTORY, CODEX_PIPE;
110851
111020
  var init_credentials = __esm({
110852
111021
  "src/commands/credentials.ts"() {
110853
111022
  init_api();
@@ -110855,7 +111024,12 @@ var init_credentials = __esm({
110855
111024
  init_capture_writer();
110856
111025
  init_output();
110857
111026
  init_sandbox_run();
110858
- PROVIDERS = ["anthropic", "openai", "openai_compatible"];
111027
+ PROVIDERS = [
111028
+ "anthropic",
111029
+ "openai",
111030
+ "openrouter",
111031
+ "openai_compatible"
111032
+ ];
110859
111033
  CUSTOM_ENDPOINT_PROVIDER = "openai_compatible";
110860
111034
  AUTH_TYPES = {
110861
111035
  "api-key": "api_key",
@@ -110872,6 +111046,16 @@ var init_credentials = __esm({
110872
111046
  this.name = "SecretAborted";
110873
111047
  }
110874
111048
  };
111049
+ SETUP_TOKEN_ON_SCREEN = /sk-ant-oat[A-Za-z0-9_-]*/g;
111050
+ SETUP_TOKEN_START = "sk-ant-oat";
111051
+ SETUP_TOKEN_TAIL = new RegExp(
111052
+ `(?:${Array.from(
111053
+ { length: SETUP_TOKEN_START.length - 1 },
111054
+ (_, i2) => SETUP_TOKEN_START.slice(0, i2 + 1)
111055
+ ).join("|")}|${SETUP_TOKEN_START}[A-Za-z0-9_-]*)$`
111056
+ );
111057
+ KEY_IN_HISTORY = "The key you typed is in your shell history and visible in the process list. Next time, pass --key - to read it from standard input, or leave out --key for a hidden prompt.";
111058
+ CODEX_PIPE = "oxagen credentials create --harness codex --key - < ~/.codex/auth.json";
110875
111059
  }
110876
111060
  });
110877
111061
 
@@ -111875,7 +112059,7 @@ import {
111875
112059
  statSync as statSync20,
111876
112060
  writeFileSync as writeFileSync11
111877
112061
  } from "node:fs";
111878
- import { dirname as dirname36, join as join68 } from "node:path";
112062
+ import { dirname as dirname36, join as join69 } from "node:path";
111879
112063
  function isBundleName(name2) {
111880
112064
  return BUNDLE_FILES.has(name2) || isClaimBundleName(name2);
111881
112065
  }
@@ -111887,7 +112071,7 @@ function readDirectoryEntries(dir) {
111887
112071
  const entries2 = /* @__PURE__ */ new Map();
111888
112072
  const walk2 = (folder, prefix) => {
111889
112073
  for (const entry2 of readdirSync18(folder)) {
111890
- const path2 = join68(folder, entry2);
112074
+ const path2 = join69(folder, entry2);
111891
112075
  const name2 = `${prefix}${entry2}`;
111892
112076
  if (statSync20(path2).isDirectory()) {
111893
112077
  if (prefix === "" && (entry2 === "heads" || entry2 === "trust"))
@@ -112119,7 +112303,7 @@ async function writeSampleBundle(dir, writer = stdoutWriter) {
112119
112303
  const { files: files2, pins } = buildSampleClaimBundle();
112120
112304
  const zipped = {};
112121
112305
  for (const [name2, bytes] of files2) {
112122
- const path2 = join68(dir, name2);
112306
+ const path2 = join69(dir, name2);
112123
112307
  mkdirSync14(dirname36(path2), { recursive: true });
112124
112308
  writeFileSync11(path2, bytes);
112125
112309
  zipped[name2] = bytes;
@@ -130230,7 +130414,7 @@ var init_conversation = __esm({
130230
130414
  });
130231
130415
 
130232
130416
  // src/auth/open-browser.ts
130233
- import { spawn as spawn8 } from "node:child_process";
130417
+ import { spawn as spawn9 } from "node:child_process";
130234
130418
  function openBrowser(url2) {
130235
130419
  try {
130236
130420
  let cmd;
@@ -130248,7 +130432,7 @@ function openBrowser(url2) {
130248
130432
  cmd = "xdg-open";
130249
130433
  args = [url2];
130250
130434
  }
130251
- const child = spawn8(cmd, args, { detached: true, stdio: "ignore" });
130435
+ const child = spawn9(cmd, args, { detached: true, stdio: "ignore" });
130252
130436
  child.on("error", () => {
130253
130437
  });
130254
130438
  child.unref();
@@ -175139,7 +175323,7 @@ import {
175139
175323
  readlinkSync as readlinkSync4,
175140
175324
  statSync as statSync21
175141
175325
  } from "node:fs";
175142
- import { dirname as dirname37, isAbsolute as isAbsolute19, join as join69, relative as relative10, resolve as resolve28, sep as sep13 } from "node:path";
175326
+ import { dirname as dirname37, isAbsolute as isAbsolute19, join as join70, relative as relative10, resolve as resolve28, sep as sep13 } from "node:path";
175143
175327
  function cloneRepoKind(root) {
175144
175328
  const out = git4(root, ["remote", "get-url", "origin"]);
175145
175329
  const url2 = out?.toString("utf8").trim() ?? "";
@@ -175179,7 +175363,7 @@ function commitOf(root, ref) {
175179
175363
  return sha2.length > 0 ? sha2 : null;
175180
175364
  }
175181
175365
  function readWorkingFile(root, path2) {
175182
- const abs = join69(root, ...path2.split("/"));
175366
+ const abs = join70(root, ...path2.split("/"));
175183
175367
  try {
175184
175368
  const stat7 = lstatSync14(abs);
175185
175369
  if (stat7.isSymbolicLink()) return readlinkSync4(abs, "utf8");
@@ -175273,7 +175457,7 @@ function isDir(path2) {
175273
175457
  function findSteeringRoot(start) {
175274
175458
  let dir = resolve28(start);
175275
175459
  for (; ; ) {
175276
- if (isFile(join69(dir, WORKSPACE_TOML_PATH)) || isFile(join69(dir, AGENTS_MD_PATH)) && isDir(join69(dir, STEERING_DIR))) {
175460
+ if (isFile(join70(dir, WORKSPACE_TOML_PATH)) || isFile(join70(dir, AGENTS_MD_PATH)) && isDir(join70(dir, STEERING_DIR))) {
175277
175461
  return dir;
175278
175462
  }
175279
175463
  const parent = dirname37(dir);
@@ -175353,7 +175537,7 @@ function cacheFile(cacheDir, root) {
175353
175537
  key: token === void 0 ? null : createHash31("sha256").update(token).digest("hex").slice(0, 16)
175354
175538
  };
175355
175539
  const key = createHash31("sha256").update(JSON.stringify([root, identity])).digest("hex").slice(0, 32);
175356
- return join69(cacheDir, `${key}.json`);
175540
+ return join70(cacheDir, `${key}.json`);
175357
175541
  }
175358
175542
  function readCache(file, now) {
175359
175543
  let entry2;
@@ -175467,7 +175651,7 @@ function defaultDeps2() {
175467
175651
  return {
175468
175652
  fetchPublished: fetchSteeringIndex,
175469
175653
  cedar: cedarHooks,
175470
- cacheDir: join69(getConfigDir(), "cache", "steering-check"),
175654
+ cacheDir: join70(getConfigDir(), "cache", "steering-check"),
175471
175655
  now: () => Date.now()
175472
175656
  };
175473
175657
  }
@@ -178541,19 +178725,25 @@ function buildProgram() {
178541
178725
  });
178542
178726
  addRuntimeCommands(program2);
178543
178727
  const credentialsCmd = program2.command("credentials").alias("keys").description(
178544
- "Manage your own model credentials: API keys and Claude or ChatGPT logins. The gateway attaches them to your runs and never puts one in a sandbox. Also named keys"
178728
+ "Manage your model credentials: API keys and Claude or ChatGPT logins. They belong to your account, so every workspace you work in can use them. The gateway attaches them to your runs and never puts one in a sandbox. Also named keys"
178545
178729
  );
178546
- credentialsCmd.command("add").description(
178547
- "Add a credential. The secret comes from a hidden prompt or from standard input, never from an argument"
178548
- ).option("--type <type>", "api-key or subscription (default: api-key)").option(
178730
+ credentialsCmd.command("create").alias("add").description(
178731
+ "Save a credential on your account. With --harness it runs the harness's own sign-in and saves the login. With --provider it saves an API key. Several for one harness or provider are fine. Also named add"
178732
+ ).option(
178733
+ "--harness <name>",
178734
+ "Save the login of claude-code or codex. Runs the harness's own sign-in when no login is saved"
178735
+ ).option(
178549
178736
  "--provider <name>",
178550
- "anthropic, openai, or openai_compatible for your own endpoint (a subscription login takes it from its harness)"
178737
+ "Save an API key for anthropic, openai, openrouter, or openai_compatible for your own endpoint"
178738
+ ).option(
178739
+ "--key <value>",
178740
+ "The API key. Use - to read it from standard input. A key typed here stays in your shell history, so leave it out for a hidden prompt"
178741
+ ).option(
178742
+ "--type <type>",
178743
+ "api-key or subscription (default: subscription with --harness, otherwise api-key)"
178551
178744
  ).option(
178552
178745
  "--base-url <url>",
178553
178746
  "The https address of your own endpoint, with --provider openai_compatible"
178554
- ).option(
178555
- "--harness <name>",
178556
- "The harness a subscription login is for: claude-code or codex"
178557
178747
  ).option(
178558
178748
  "--label <name>",
178559
178749
  "A name for the credential, such as the account's email"
@@ -178564,7 +178754,7 @@ function buildProgram() {
178564
178754
  "--shared",
178565
178755
  "Act on this workspace's accounts instead of your own. Changing one needs a workspace Admin or an organization Owner"
178566
178756
  ).option("--json", "Output JSON").action(
178567
- async (opts) => (await Promise.resolve().then(() => (init_credentials(), credentials_exports))).credentialsAdd(opts)
178757
+ async (opts) => (await Promise.resolve().then(() => (init_credentials(), credentials_exports))).credentialsCreate(opts)
178568
178758
  );
178569
178759
  credentialsCmd.command("list").description("List your credentials in the order the gateway uses them").option(
178570
178760
  "--workspace-slug <slug>",
@@ -179370,6 +179560,7 @@ var init_program = __esm({
179370
179560
  "--token",
179371
179561
  "--input",
179372
179562
  "--endpoint",
179563
+ "--key",
179373
179564
  // `oxagen agent connect --request <token>` carries an enrollment token.
179374
179565
  "--request"
179375
179566
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxagen/cli",
3
- "version": "3.0.1-816",
3
+ "version": "3.0.1-817",
4
4
  "description": "Oxagen governance CLI: spend, source tracking, grounding, credentials, and audit (agentic coding lives in the stella CLI)",
5
5
  "type": "module",
6
6
  "bin": {