@standardagents/cli 0.25.2 → 0.25.4

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/dist/index.js CHANGED
@@ -121,10 +121,13 @@ async function parseError(response) {
121
121
  return fallback;
122
122
  }
123
123
  }
124
- async function startCliAuthSession(endpoint) {
124
+ async function startCliAuthSession(endpoint, options = {}) {
125
125
  const response = await fetch(`${endpoint}/cli/auth/start`, {
126
126
  method: "POST",
127
- headers: { "Content-Type": "application/json" }
127
+ headers: { "Content-Type": "application/json" },
128
+ // purpose 'auth' routes the browser to the platform's dedicated /cli-auth
129
+ // page (instant, no-wizard handshake) instead of project onboarding.
130
+ body: options.purpose ? JSON.stringify({ purpose: options.purpose }) : void 0
128
131
  });
129
132
  if (!response.ok) {
130
133
  throw new Error(await parseError(response));
@@ -239,7 +242,7 @@ function getScaffoldStandardAgentsVersion() {
239
242
  if (process.env.STANDARDAGENTS_WORKSPACE === "1") {
240
243
  return "workspace:*";
241
244
  }
242
- return "0.25.2";
245
+ return "0.25.4";
243
246
  }
244
247
  function findViteConfig(cwd) {
245
248
  const candidates = ["vite.config.ts", "vite.config.js", "vite.config.mts", "vite.config.mjs"];
@@ -1534,7 +1537,7 @@ async function ensurePlatformAuth(options, quietLogs = false, context = {}) {
1534
1537
  return { connected: true, mode: "standardagents" };
1535
1538
  }
1536
1539
  function getCliVersion() {
1537
- return "0.25.2";
1540
+ return "0.25.4";
1538
1541
  }
1539
1542
  function getSipVersion() {
1540
1543
  return "1.0.1";
@@ -2992,6 +2995,7 @@ function parseCliGitAuthRecord(value) {
2992
2995
  version: 1,
2993
2996
  endpoint: candidate.endpoint,
2994
2997
  session_cookie: candidate.session_cookie,
2998
+ ...typeof candidate.api_key === "string" && candidate.api_key.length > 0 ? { api_key: candidate.api_key } : {},
2995
2999
  account_id: candidate.account_id,
2996
3000
  account_slug: typeof candidate.account_slug === "string" ? candidate.account_slug : void 0,
2997
3001
  user_id: candidate.user_id,
@@ -3013,6 +3017,7 @@ function saveCliGitAuth(input) {
3013
3017
  version: 1,
3014
3018
  endpoint: input.endpoint.replace(/\/+$/, ""),
3015
3019
  session_cookie: input.sessionCookie,
3020
+ ...input.apiKey ? { api_key: input.apiKey } : {},
3016
3021
  account_id: input.account.id,
3017
3022
  account_slug: input.account.slug,
3018
3023
  user_id: input.user.id,
@@ -4980,6 +4985,7 @@ async function availableModels(options = {}) {
4980
4985
  writeError(message);
4981
4986
  }
4982
4987
  }
4988
+ var GIT_LOGIN_COMMAND = "npx @standardagents/cli@latest git-login";
4983
4989
  function parseKeyValueLines(input) {
4984
4990
  const result = {};
4985
4991
  for (const line of input.split(/\r?\n/)) {
@@ -5030,6 +5036,12 @@ function loadLocalConfig(options) {
5030
5036
  if (requestedEndpoint && requestedEndpoint !== globalAuth.endpoint) {
5031
5037
  return null;
5032
5038
  }
5039
+ if (globalAuth.api_key) {
5040
+ return {
5041
+ endpoint: globalAuth.endpoint,
5042
+ auth: { kind: "api-key", apiKey: globalAuth.api_key }
5043
+ };
5044
+ }
5033
5045
  return {
5034
5046
  endpoint: globalAuth.endpoint,
5035
5047
  auth: { kind: "session-cookie", cookie: globalAuth.session_cookie }
@@ -5050,11 +5062,18 @@ async function readStdin() {
5050
5062
  }
5051
5063
  async function gitCredential(operation, options = {}) {
5052
5064
  if (operation !== "get") return;
5053
- const config = loadLocalConfig(options);
5054
- if (!config) return;
5065
+ const warn = options.warn ?? ((text) => {
5066
+ process.stderr.write(`standardagents: ${text}
5067
+ `);
5068
+ });
5055
5069
  const input = options.input ?? await readStdin();
5056
5070
  const remote = remoteFromCredentialRequest(parseKeyValueLines(input));
5057
5071
  if (!remote) return;
5072
+ const config = loadLocalConfig(options);
5073
+ if (!config) {
5074
+ warn(`No Standard Agents git credentials found. Run: ${GIT_LOGIN_COMMAND}`);
5075
+ return;
5076
+ }
5058
5077
  const fetchImpl = options.fetchImpl ?? fetch;
5059
5078
  const headers = {
5060
5079
  "Content-Type": "application/json"
@@ -5069,10 +5088,24 @@ async function gitCredential(operation, options = {}) {
5069
5088
  headers,
5070
5089
  body: JSON.stringify({ remote, scope: "write" })
5071
5090
  }).catch(() => null);
5072
- if (!response?.ok) return;
5091
+ if (!response?.ok) {
5092
+ if (!response) {
5093
+ warn(`Could not reach ${config.endpoint} to mint git credentials \u2014 check your connection and retry.`);
5094
+ } else if (response.status === 401 || response.status === 403) {
5095
+ warn(
5096
+ config.auth.kind === "api-key" ? `Your Standard Agents API key was revoked or lost access. Run: ${GIT_LOGIN_COMMAND}` : `Your Standard Agents sign-in expired. Run: ${GIT_LOGIN_COMMAND}`
5097
+ );
5098
+ } else {
5099
+ warn(`Minting git credentials failed (HTTP ${response.status}). Retry, or re-auth with: ${GIT_LOGIN_COMMAND}`);
5100
+ }
5101
+ return;
5102
+ }
5073
5103
  const body = await response.json().catch(() => null);
5074
5104
  const tokenSecret = body?.artifact_git?.token_secret;
5075
- if (!tokenSecret) return;
5105
+ if (!tokenSecret) {
5106
+ warn(`The platform returned no git token for ${remote}. Re-auth with: ${GIT_LOGIN_COMMAND}`);
5107
+ return;
5108
+ }
5076
5109
  const write = options.write ?? ((text) => {
5077
5110
  process.stdout.write(text);
5078
5111
  });
@@ -5166,7 +5199,7 @@ async function completeBrowserGitLogin(options, endpoint) {
5166
5199
  let wsUrl = null;
5167
5200
  let wsExpiresAt = 0;
5168
5201
  try {
5169
- const started = await startCliAuthSession(endpoint);
5202
+ const started = await startCliAuthSession(endpoint, { purpose: "auth" });
5170
5203
  sessionId = started.session_id;
5171
5204
  authAppUrl = started.auth_url;
5172
5205
  wsUrl = started.ws_url;
@@ -5218,9 +5251,14 @@ async function gitLogin(options = {}) {
5218
5251
  if (!state.session_cookie) {
5219
5252
  throw new Error("Platform login did not return a session cookie for Git authentication.");
5220
5253
  }
5254
+ const apiKey = await mintGitAccessApiKey(endpoint, state.session_cookie, options.fetchImpl);
5255
+ if (!apiKey) {
5256
+ logger.warning("Could not mint a long-lived API key \u2014 falling back to the browser session (expires in a few days).");
5257
+ }
5221
5258
  const record = saveCliGitAuth({
5222
5259
  endpoint,
5223
5260
  sessionCookie: state.session_cookie,
5261
+ apiKey,
5224
5262
  account: state.account,
5225
5263
  user: state.user
5226
5264
  });
@@ -5235,8 +5273,29 @@ async function gitLogin(options = {}) {
5235
5273
  if (configured) {
5236
5274
  logger.log(`Credential helper: ${configured.helperCommand}${configured.helperAdded ? "" : " (already installed)"}`);
5237
5275
  }
5276
+ if (record.api_key) {
5277
+ logger.log("Credentials: long-lived API key (no expiry \u2014 revoke from the dashboard to sign out)");
5278
+ }
5238
5279
  logger.log("");
5239
5280
  }
5281
+ async function mintGitAccessApiKey(endpoint, sessionCookie, fetchImpl = fetch) {
5282
+ try {
5283
+ const label = `git (${os3.hostname()})`;
5284
+ const response = await fetchImpl(`${endpoint}/api-keys`, {
5285
+ method: "POST",
5286
+ headers: {
5287
+ "Content-Type": "application/json",
5288
+ Cookie: sessionCookie
5289
+ },
5290
+ body: JSON.stringify({ label })
5291
+ });
5292
+ if (!response.ok) return null;
5293
+ const body = await response.json().catch(() => null);
5294
+ return typeof body?.key === "string" && body.key.length > 0 ? body.key : null;
5295
+ } catch {
5296
+ return null;
5297
+ }
5298
+ }
5240
5299
 
5241
5300
  // src/index.ts
5242
5301
  async function settleStdinForInitHandoff(stdin = process.stdin) {
@@ -5257,7 +5316,7 @@ async function settleStdinForInitHandoff(stdin = process.stdin) {
5257
5316
  }
5258
5317
  }
5259
5318
  var program = new Command();
5260
- program.name("agents").description("CLI tool for Standard Agents / AgentBuilder").version("0.25.2");
5319
+ program.name("agents").description("CLI tool for Standard Agents / AgentBuilder").version("0.25.4");
5261
5320
  program.command("init [project-name]").description("Create a new Standard Agents project").option("-y, --yes", "Skip prompts and use defaults").option("--local", "Use local project scaffolding instead of browser platform onboarding").option("--cli", "Use classic line-by-line CLI prompts instead of the TUI wizard").option("--api-url <url>", "Standard Agents platform API URL").option("--endpoint <url>", "Platform API endpoint for auth/bootstrap exchange").option("--package-manager <manager>", "Package manager for generated project: npm, pnpm, yarn, or bun").option("--template <template>", "Vite template to use", "vanilla-ts").option("--workspace", "Install @standardagents packages as workspace:* (local pnpm workspace development)").option("--no-dev", "Clone and configure the project without starting the dev server").addOption(new Option("--bootstrap <code>", "Exchange a web onboarding bootstrap code")).action(init);
5262
5321
  program.command("login").description("Authenticate this machine (or use --bootstrap for project bootstrap auth)").option("--bootstrap <code>", "Bootstrap code from web onboarding").option("--endpoint <url>", "Platform API endpoint (default: https://api.standardagents.ai)").option("--no-open", "Do not auto-open browser URL").action(login);
5263
5322
  program.command("logout").description("Clear stored StandardAgents auth and local org-scoped project auth").option("--org <org-id-or-slug>", "Org ID or slug to logout (defaults to active org)").option("--endpoint <url>", "Platform API endpoint (default: https://api.standardagents.ai)").action(logout);