@ekanos/cli 0.1.1 → 0.1.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAE1E,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,GAAe,EACf,IAAe;;IAEf,MAAM,GAAG,GAAG,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAE7D,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAE1C,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAE/C,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,GAAG,CAAC,OAAO,CAChB;oBACE,IAAI,EAAE,GAAG,CAAC,IAAI;oBACd,MAAM,EAAE,uBAAuB;oBAC/B,IAAI,EAAE,QAAQ,CAAC,IAAI;oBACnB,SAAS,EAAE,QAAQ,CAAC,SAAS;oBAC7B,eAAe,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ;iBACpC,EACD,mCAAmC,GAAG,CAAC,IAAI,OACzC,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,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAElC,OAAO,GAAG,CAAC,OAAO,CAChB;QACE,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,MAAM,EAAE,eAAe;QACvB,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE;QAClD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,eAAe,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ;KACpC,EACD,2BAA2B,GAAG,CAAC,IAAI,OAAO,MAAA,OAAO,CAAC,KAAK,mCAAI,OAAO,CAAC,MAAM,GAAG,CAC7E,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,QAAQ,CACrB,GAA8C,EAC9C,QAAuB;IAKvB,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAEnE,OAAO;YACL,IAAI,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE;YAChD,SAAS,EAAE,OAAO,CAAC,SAAS;SAC7B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,KAAK,YAAY,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,aAAa,CAAC;AAC/E,CAAC","sourcesContent":["import type { StoredSession } from '../auth/credential-store';\nimport {\n pollForDeviceTokens,\n startDeviceAuthorization,\n} from '../auth/device-flow';\nimport { createFusionSession, fetchCliAuthConfig } from '../auth/fusion-api';\nimport { resolveAuthEnvironment, resolveIdentity } from '../auth/session';\nimport type { CliContext } from '../context';\nimport { CliError } from '../errors';\nimport { ERROR_CODES } from '../exit-codes';\nimport type { ExitCode } from '../exit-codes';\n\nexport interface LoginArgs {\n host?: string;\n /** Start a new browser login even if a working session is already stored. */\n force: boolean;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `login` — authenticate this machine against a Fusion deployment via the\n * Auth0 device authorization flow.\n *\n * Idempotent: with a stored session that still authenticates, it reports that\n * and exits 0 without opening a browser. `--force` skips the check.\n *\n * The user code and verification URL go to STDERR. They have to be visible\n * even when stdout is a pipe into an agent, and stdout in this CLI carries\n * exactly one JSON object.\n */\nexport async function runLogin(\n ctx: CliContext,\n args: LoginArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env);\n\n if (!args.force) {\n const existing = env.store.read(env.host);\n\n if (existing) {\n const reusable = await tryReuse(env, existing);\n\n if (reusable) {\n return ctx.succeed(\n {\n host: env.host,\n status: 'already-authenticated',\n user: reusable.user,\n expiresAt: reusable.expiresAt,\n credentialsPath: env.store.filePath,\n },\n `login: already authenticated to ${env.host} as ${\n reusable.user.email ?? reusable.user.id\n }.`,\n );\n }\n\n ctx.log('The stored session has expired. Starting a new login…');\n }\n }\n\n const config = await fetchCliAuthConfig(env.host);\n const authorization = await startDeviceAuthorization(config);\n\n ctx.log('');\n ctx.log(\n ` Open: ${authorization.verificationUriComplete ?? authorization.verificationUri}`,\n );\n ctx.log(` Code: ${authorization.userCode}`);\n\n if (authorization.verificationUriComplete) {\n ctx.log(\n ` (without the pre-filled code: ${authorization.verificationUri})`,\n );\n }\n\n ctx.log('');\n ctx.log('Waiting for approval…');\n\n const tokens = await pollForDeviceTokens(config, authorization);\n const session = await createFusionSession(env.host, tokens.accessToken);\n\n const stored: StoredSession = {\n auth0RefreshToken: tokens.refreshToken,\n accessToken: session.accessToken,\n expiresAt: session.expiresAt,\n userId: session.userId,\n email: session.email,\n updatedAt: new Date().toISOString(),\n };\n\n env.store.write(env.host, stored);\n\n return ctx.succeed(\n {\n host: env.host,\n status: 'authenticated',\n user: { id: session.userId, email: session.email },\n expiresAt: session.expiresAt,\n credentialsPath: env.store.filePath,\n },\n `login: authenticated to ${env.host} as ${session.email ?? session.userId}.`,\n );\n}\n\n/**\n * Probe a stored session. Returns null when it cannot be revived, so `login`\n * falls through to a fresh device flow rather than failing — \"log in again\"\n * is the whole point of the command being run.\n *\n * Only auth failures are absorbed. A network or configuration error still\n * propagates: silently starting a browser login because the host was\n * unreachable would be the wrong recovery, and would hide the real fault.\n */\nasync function tryReuse(\n env: ReturnType<typeof resolveAuthEnvironment>,\n existing: StoredSession,\n): Promise<{\n user: { id: string; email: string | null };\n expiresAt: string;\n} | null> {\n try {\n const { identity, session } = await resolveIdentity(env, existing);\n\n return {\n user: { id: identity.id, email: identity.email },\n expiresAt: session.expiresAt,\n };\n } catch (error) {\n if (isAuthFailure(error)) {\n return null;\n }\n\n throw error;\n }\n}\n\nfunction isAuthFailure(error: unknown): boolean {\n return error instanceof CliError && error.code === ERROR_CODES.AUTH_REQUIRED;\n}\n"]}
1
+ {"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AACA,OAAO,EACL,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAY5C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,GAAe,EACf,IAAe;;IAEf,0EAA0E;I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AAI;QACd,MAAM,EAAE,eAAe;QACvB,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE;QAClD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,eAAe,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ;KACpC,EACD,2BAA2B,GAAG,CAAC,IAAI,OAAO,MAAA,OAAO,CAAC,KAAK,mCAAI,OAAO,CAAC,MAAM,GAAG,CAC7E,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,QAAQ,CACrB,GAA8C,EAC9C,QAAuB;IAKvB,IAAI,CAAC;QACH,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAEnE,OAAO;YACL,IAAI,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE;YAChD,SAAS,EAAE,OAAO,CAAC,SAAS;SAC7B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,KAAK,YAAY,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,aAAa,CAAC;AAC/E,CAAC","sourcesContent":["import type { StoredSession } from '../auth/credential-store';\nimport {\n pollForDeviceTokens,\n startDeviceAuthorization,\n} from '../auth/device-flow';\nimport { createFusionSession, fetchCliAuthConfig } from '../auth/fusion-api';\nimport { resolveAuthEnvironment, resolveIdentity } from '../auth/session';\nimport { printBanner } from '../banner';\nimport type { CliContext } from '../context';\nimport { CliError } from '../errors';\nimport { ERROR_CODES } from '../exit-codes';\nimport type { ExitCode } from '../exit-codes';\n\nexport interface LoginArgs {\n host?: string;\n /** Start a new browser login even if a working session is already stored. */\n force: boolean;\n /** Where a project's ekanos.json may sit — read-only here, never written. */\n cwd: string;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `login` — authenticate this machine against a Fusion deployment via the\n * Auth0 device authorization flow.\n *\n * Idempotent: with a stored session that still authenticates, it reports that\n * and exits 0 without opening a browser. `--force` skips the check.\n *\n * The user code and verification URL go to STDERR. They have to be visible\n * even when stdout is a pipe into an agent, and stdout in this CLI carries\n * exactly one JSON object.\n */\nexport async function runLogin(\n ctx: CliContext,\n args: LoginArgs,\n): Promise<ExitCode> {\n // No `projectDir`: login is the one verb that CREATES credentials, so its\n // host must come from something the developer chose (--host, EKANOS_HOST)\n // or already trusts (the sole stored login) — never from a committed\n // ekanos.json, which an attacker can set in any cloned repo to point the\n // device flow at their own tenant. Every other verb may read the project\n // host because their bearer tokens are looked up per-host from the store:\n // an unfamiliar host simply has no session to present.\n const env = resolveAuthEnvironment(ctx, args.host, args.env);\n\n // Whether this host had a session stored BEFORE this command touched\n // anything — the sole signal for full banner (first login per host) vs\n // mini-mark (repeat), independent of --force or which branch below\n // actually produces the success.\n const hadSession = env.store.read(env.host) !== null;\n const bannerKind = hadSession ? 'mini' : 'full';\n\n if (!args.force) {\n const existing = env.store.read(env.host);\n\n if (existing) {\n const reusable = await tryReuse(env, existing);\n\n if (reusable) {\n printBanner(ctx, bannerKind);\n\n return ctx.succeed(\n {\n host: env.host,\n status: 'already-authenticated',\n user: reusable.user,\n expiresAt: reusable.expiresAt,\n credentialsPath: env.store.filePath,\n },\n `login: already authenticated to ${env.host} as ${\n reusable.user.email ?? reusable.user.id\n }.`,\n );\n }\n\n ctx.log('The stored session has expired. Starting a new login…');\n }\n }\n\n const config = await fetchCliAuthConfig(env.host);\n const authorization = await startDeviceAuthorization(config);\n\n ctx.log('');\n ctx.log(\n ` Open: ${authorization.verificationUriComplete ?? authorization.verificationUri}`,\n );\n ctx.log(` Code: ${authorization.userCode}`);\n\n if (authorization.verificationUriComplete) {\n ctx.log(\n ` (without the pre-filled code: ${authorization.verificationUri})`,\n );\n }\n\n ctx.log('');\n ctx.log('Waiting for approval…');\n\n const tokens = await pollForDeviceTokens(config, authorization);\n const session = await createFusionSession(env.host, tokens.accessToken);\n\n const stored: StoredSession = {\n auth0RefreshToken: tokens.refreshToken,\n accessToken: session.accessToken,\n expiresAt: session.expiresAt,\n userId: session.userId,\n email: session.email,\n updatedAt: new Date().toISOString(),\n };\n\n env.store.write(env.host, stored);\n\n printBanner(ctx, bannerKind);\n\n return ctx.succeed(\n {\n host: env.host,\n status: 'authenticated',\n user: { id: session.userId, email: session.email },\n expiresAt: session.expiresAt,\n credentialsPath: env.store.filePath,\n },\n `login: authenticated to ${env.host} as ${session.email ?? session.userId}.`,\n );\n}\n\n/**\n * Probe a stored session. Returns null when it cannot be revived, so `login`\n * falls through to a fresh device flow rather than failing — \"log in again\"\n * is the whole point of the command being run.\n *\n * Only auth failures are absorbed. A network or configuration error still\n * propagates: silently starting a browser login because the host was\n * unreachable would be the wrong recovery, and would hide the real fault.\n */\nasync function tryReuse(\n env: ReturnType<typeof resolveAuthEnvironment>,\n existing: StoredSession,\n): Promise<{\n user: { id: string; email: string | null };\n expiresAt: string;\n} | null> {\n try {\n const { identity, session } = await resolveIdentity(env, existing);\n\n return {\n user: { id: identity.id, email: identity.email },\n expiresAt: session.expiresAt,\n };\n } catch (error) {\n if (isAuthFailure(error)) {\n return null;\n }\n\n throw error;\n }\n}\n\nfunction isAuthFailure(error: unknown): boolean {\n return error instanceof CliError && error.code === ERROR_CODES.AUTH_REQUIRED;\n}\n"]}
@@ -4,6 +4,8 @@ export interface LogoutArgs {
4
4
  host?: string;
5
5
  /** Sign out of every host in the credentials file. */
6
6
  all: boolean;
7
+ /** Where a project's ekanos.json may sit, for its optional `host` field. */
8
+ cwd: string;
7
9
  env: Record<string, string | undefined>;
8
10
  }
9
11
  /**
@@ -16,7 +16,9 @@ export async function runLogout(ctx, args) {
16
16
  if (args.all) {
17
17
  return runLogoutAll(ctx, args);
18
18
  }
19
- const env = resolveAuthEnvironment(ctx, args.host, args.env);
19
+ const env = resolveAuthEnvironment(ctx, args.host, args.env, {
20
+ projectDir: args.cwd,
21
+ });
20
22
  const session = env.store.read(env.host);
21
23
  if (!session) {
22
24
  return ctx.succeed({ host: env.host, cleared: false, revoked: false }, `logout: no stored session for ${env.host}.`);
@@ -1 +1 @@
1
- {"version":3,"file":"logout.js","sourceRoot":"","sources":["../../src/commands/logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAWnE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAe,EACf,IAAgB;IAEhB,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,OAAO,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,GAAG,GAAG,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7D,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEzC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,OAAO,CAChB,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAClD,iCAAiC,GAAG,CAAC,IAAI,GAAG,CAC7C,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,OA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;QACvB,OAAO,GAAG,CAAC,OAAO,CAChB,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EACzB,6BAA6B,CAC9B,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAyC,EAAE,CAAC;IAEzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEjC,OAAO,CAAC,IAAI,CAAC;YACX,IAAI;YACJ,OAAO,EAAE,OAAO;gBACd,CAAC,CAAC,MAAM,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC;gBACvD,CAAC,CAAC,KAAK;SACV,CAAC,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAEjC,OAAO,GAAG,CAAC,OAAO,CAChB,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAC3B,yBAAyB,OAAO,QAAQ,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CACpE,CAAC;AACJ,CAAC","sourcesContent":["import { revokeRefreshToken } from '../auth/device-flow';\nimport { fetchCliAuthConfig } from '../auth/fusion-api';\nimport { newStore, resolveAuthEnvironment } from '../auth/session';\nimport type { CliContext } from '../context';\nimport type { ExitCode } from '../exit-codes';\n\nexport interface LogoutArgs {\n host?: string;\n /** Sign out of every host in the credentials file. */\n all: boolean;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `logout` — revoke the stored refresh token at Auth0, then delete it locally.\n *\n * Idempotent: logging out twice exits 0. `cleared: false` in the envelope says\n * there was nothing to remove; it is information, not a failure.\n *\n * Revocation is attempted first but never blocks the local delete. A logout\n * that only forgets the token would leave a rotating credential live for weeks;\n * a logout that REFUSES because the network is down would leave the token on\n * disk, which is worse. So: try to revoke, always delete, report both.\n */\nexport async function runLogout(\n ctx: CliContext,\n args: LogoutArgs,\n): Promise<ExitCode> {\n if (args.all) {\n return runLogoutAll(ctx, args);\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env);\n const session = env.store.read(env.host);\n\n if (!session) {\n return ctx.succeed(\n { host: env.host, cleared: false, revoked: false },\n `logout: no stored session for ${env.host}.`,\n );\n }\n\n const revoked = await tryRevoke(ctx, env.host, session.auth0RefreshToken);\n\n env.store.clear(env.host);\n\n if (!revoked) {\n ctx.warn(\n `ekanos: the local credentials were removed, but the refresh token ` +\n `could not be revoked at Auth0. It stays valid until it expires — ` +\n `revoke the session in Auth0 if this machine is compromised.`,\n );\n }\n\n return ctx.succeed(\n { host: env.host, cleared: true, revoked },\n `logout: signed out of ${env.host}${revoked ? ' and revoked the session' : ''}.`,\n );\n}\n\n/**\n * Never throws. Every failure mode here — an unreachable host, a deployment\n * without the CLI routes, an Auth0 outage — must still end in the local token\n * being deleted.\n */\nasync function tryRevoke(\n ctx: CliContext,\n host: string,\n refreshToken: string,\n): Promise<boolean> {\n try {\n const config = await fetchCliAuthConfig(host);\n\n return await revokeRefreshToken(config, refreshToken);\n } catch (error) {\n // Diagnostic only — the message never carries the token, and the outcome\n // is reported in the envelope's `revoked` field either way.\n ctx.warn(\n `ekanos: could not reach ${host} to revoke the session ` +\n `(${error instanceof Error ? error.message : String(error)}).`,\n );\n\n return false;\n }\n}\n\n/**\n * `logout --all` — the \"I am leaving this machine\" verb. Every host is revoked\n * independently and the local file is emptied regardless, for the same reason\n * the single-host path does not let a failed revocation block the delete.\n */\nasync function runLogoutAll(\n ctx: CliContext,\n args: LogoutArgs,\n): Promise<ExitCode> {\n const store = newStore(ctx, args.env);\n const hosts = store.hosts();\n\n if (hosts.length === 0) {\n return ctx.succeed(\n { hosts: [], cleared: 0 },\n 'logout: no stored sessions.',\n );\n }\n\n const results: { host: string; revoked: boolean }[] = [];\n\n for (const host of hosts) {\n const session = store.read(host);\n\n results.push({\n host,\n revoked: session\n ? await tryRevoke(ctx, host, session.auth0RefreshToken)\n : false,\n });\n }\n\n const cleared = store.clearAll();\n\n return ctx.succeed(\n { hosts: results, cleared },\n `logout: signed out of ${cleared} host${cleared === 1 ? '' : 's'}.`,\n );\n}\n"]}
1
+ {"version":3,"file":"logout.js","sourceRoot":"","sources":["../../src/commands/logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAanE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAe,EACf,IAAgB;IAEhB,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,OAAO,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,MAAM,GAAG,GAAG,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;QAC3D,UAAU,EAAE,IAAI,CAAC,GAAG;KACrB,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEzC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,OAAO,CAChB,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAClD,iCAAiC,GAAG,CAAC,IAAI,GAAG,CAC7C,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE1E,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;I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,CAC9B,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAyC,EAAE,CAAC;IAEzD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEjC,OAAO,CAAC,IAAI,CAAC;YACX,IAAI;YACJ,OAAO,EAAE,OAAO;gBACd,CAAC,CAAC,MAAM,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,iBAAiB,CAAC;gBACvD,CAAC,CAAC,KAAK;SACV,CAAC,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAEjC,OAAO,GAAG,CAAC,OAAO,CAChB,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAC3B,yBAAyB,OAAO,QAAQ,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,CACpE,CAAC;AACJ,CAAC","sourcesContent":["import { revokeRefreshToken } from '../auth/device-flow';\nimport { fetchCliAuthConfig } from '../auth/fusion-api';\nimport { newStore, resolveAuthEnvironment } from '../auth/session';\nimport type { CliContext } from '../context';\nimport type { ExitCode } from '../exit-codes';\n\nexport interface LogoutArgs {\n host?: string;\n /** Sign out of every host in the credentials file. */\n all: boolean;\n /** Where a project's ekanos.json may sit, for its optional `host` field. */\n cwd: string;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `logout` — revoke the stored refresh token at Auth0, then delete it locally.\n *\n * Idempotent: logging out twice exits 0. `cleared: false` in the envelope says\n * there was nothing to remove; it is information, not a failure.\n *\n * Revocation is attempted first but never blocks the local delete. A logout\n * that only forgets the token would leave a rotating credential live for weeks;\n * a logout that REFUSES because the network is down would leave the token on\n * disk, which is worse. So: try to revoke, always delete, report both.\n */\nexport async function runLogout(\n ctx: CliContext,\n args: LogoutArgs,\n): Promise<ExitCode> {\n if (args.all) {\n return runLogoutAll(ctx, args);\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.cwd,\n });\n const session = env.store.read(env.host);\n\n if (!session) {\n return ctx.succeed(\n { host: env.host, cleared: false, revoked: false },\n `logout: no stored session for ${env.host}.`,\n );\n }\n\n const revoked = await tryRevoke(ctx, env.host, session.auth0RefreshToken);\n\n env.store.clear(env.host);\n\n if (!revoked) {\n ctx.warn(\n `ekanos: the local credentials were removed, but the refresh token ` +\n `could not be revoked at Auth0. It stays valid until it expires — ` +\n `revoke the session in Auth0 if this machine is compromised.`,\n );\n }\n\n return ctx.succeed(\n { host: env.host, cleared: true, revoked },\n `logout: signed out of ${env.host}${revoked ? ' and revoked the session' : ''}.`,\n );\n}\n\n/**\n * Never throws. Every failure mode here — an unreachable host, a deployment\n * without the CLI routes, an Auth0 outage — must still end in the local token\n * being deleted.\n */\nasync function tryRevoke(\n ctx: CliContext,\n host: string,\n refreshToken: string,\n): Promise<boolean> {\n try {\n const config = await fetchCliAuthConfig(host);\n\n return await revokeRefreshToken(config, refreshToken);\n } catch (error) {\n // Diagnostic only — the message never carries the token, and the outcome\n // is reported in the envelope's `revoked` field either way.\n ctx.warn(\n `ekanos: could not reach ${host} to revoke the session ` +\n `(${error instanceof Error ? error.message : String(error)}).`,\n );\n\n return false;\n }\n}\n\n/**\n * `logout --all` — the \"I am leaving this machine\" verb. Every host is revoked\n * independently and the local file is emptied regardless, for the same reason\n * the single-host path does not let a failed revocation block the delete.\n */\nasync function runLogoutAll(\n ctx: CliContext,\n args: LogoutArgs,\n): Promise<ExitCode> {\n const store = newStore(ctx, args.env);\n const hosts = store.hosts();\n\n if (hosts.length === 0) {\n return ctx.succeed(\n { hosts: [], cleared: 0 },\n 'logout: no stored sessions.',\n );\n }\n\n const results: { host: string; revoked: boolean }[] = [];\n\n for (const host of hosts) {\n const session = store.read(host);\n\n results.push({\n host,\n revoked: session\n ? await tryRevoke(ctx, host, session.auth0RefreshToken)\n : false,\n });\n }\n\n const cleared = store.clearAll();\n\n return ctx.succeed(\n { hosts: results, cleared },\n `logout: signed out of ${cleared} host${cleared === 1 ? '' : 's'}.`,\n );\n}\n"]}
@@ -4,7 +4,7 @@ import { refreshStoredSession, requireSession, resolveAuthEnvironment, } from '.
4
4
  import { gateFailedError, preconditionError, validationError } from '../errors.js';
5
5
  import { packProject } from '../pack.js';
6
6
  import { loadProject, serializeProject } from '../project.js';
7
- import { stillUnauthorized, submitArchive } from '../publish-api.js';
7
+ import { MAX_MANIFEST_BYTES, stillUnauthorized, submitArchive, } from '../publish-api.js';
8
8
  import { collectAllFindings } from '../validate-findings.js';
9
9
  /**
10
10
  * `publish` — pack the project and submit it to a Fusion deployment.
@@ -20,7 +20,9 @@ import { collectAllFindings } from '../validate-findings.js';
20
20
  * so later publishes need no `--source`.
21
21
  */
22
22
  export async function runPublish(ctx, args) {
23
- const env = resolveAuthEnvironment(ctx, args.host, args.env);
23
+ const env = resolveAuthEnvironment(ctx, args.host, args.env, {
24
+ projectDir: args.dir,
25
+ });
24
26
  const session = requireSession(env.store, env.host);
25
27
  const loaded = loadProject(args.dir);
26
28
  const source = resolveSourceSlug(args.source, loaded);
@@ -37,14 +39,7 @@ export async function runPublish(ctx, args) {
37
39
  }
38
40
  ctx.log(`Packing ${slug}@${version}…`);
39
41
  const packed = packProject(loaded.projectDir);
40
- const manifest = JSON.stringify({
41
- project: loaded.project,
42
- integrations: loaded.integrations.map((i) => ({
43
- slug: i.slug,
44
- entry: i.entry,
45
- })),
46
- files: packed.files,
47
- });
42
+ const manifest = buildManifest(loaded, packed.files);
48
43
  ctx.log(`Submitting to ${env.host} (source "${source}")…`);
49
44
  const receipt = await submitWithOneRefresh(env, session, {
50
45
  source,
@@ -53,7 +48,16 @@ export async function runPublish(ctx, args) {
53
48
  manifest,
54
49
  archive: packed.archive,
55
50
  });
56
- const persistedSource = persistSourceSlug(loaded, source);
51
+ const persisted = persistProjectFields(loaded, source, env.host);
52
+ const persistedNote = [
53
+ ...(persisted.source ? [`"source": "${source}"`] : []),
54
+ ...(persisted.host ? [`"host": "${env.host}"`] : []),
55
+ ];
56
+ const overrideNote = persisted.hostOverride
57
+ ? ` NOTE: this publish went to ${env.host}, but ekanos.json keeps ` +
58
+ `"host": "${persisted.hostOverride}" — a one-off override never ` +
59
+ `replaces the saved host; edit ekanos.json to change it.`
60
+ : '';
57
61
  return ctx.succeed({
58
62
  host: env.host,
59
63
  source,
@@ -63,13 +67,16 @@ export async function runPublish(ctx, args) {
63
67
  state: receipt.state,
64
68
  archiveSha256: receipt.archiveSha256,
65
69
  files: packed.files,
66
- sourcePersisted: persistedSource,
70
+ sourcePersisted: persisted.source,
71
+ hostPersisted: persisted.host,
72
+ hostOverride: persisted.hostOverride,
67
73
  }, `publish: submitted ${receipt.slug}@${receipt.version} to ${env.host} ` +
68
74
  `(source "${source}", state "${receipt.state}").` +
69
- (persistedSource
70
- ? ` Saved "source": "${source}" to ekanos.json — future publishes ` +
71
- `won't need --source.`
72
- : ''));
75
+ (persistedNote.length > 0
76
+ ? ` Saved ${persistedNote.join(' and ')} to ekanos.json — future ` +
77
+ `publishes won't need the flag${persistedNote.length === 1 ? '' : 's'}.`
78
+ : '') +
79
+ overrideNote);
73
80
  }
74
81
  async function submitWithOneRefresh(env, session, payload) {
75
82
  const first = await submitArchive(env.host, session.accessToken, payload);
@@ -93,23 +100,74 @@ function resolveSourceSlug(flag, loaded) {
93
100
  return source.trim();
94
101
  }
95
102
  /**
96
- * Persist the chosen source into ekanos.json after a SUCCESSFUL publish, so
97
- * the next publish needs no flag. Returns whether anything was written. A
98
- * write failure is reported but never fails the command — the submission
99
- * already landed.
103
+ * Persist the chosen source AND host into ekanos.json after a SUCCESSFUL
104
+ * publish, so the next publish and every other host-taking verb needs no
105
+ * flag. Returns what was written. A write failure is reported but never fails
106
+ * the command — the submission already landed.
107
+ *
108
+ * `publish` is the only verb that writes ekanos.json: it is the one verb that
109
+ * proves the (host, source) pair actually works, and it always runs inside a
110
+ * project. `login` deliberately never writes — it is routinely run outside
111
+ * one, and the credential store's sole-host fallback covers it.
112
+ *
113
+ * `host` persists on FIRST WRITE ONLY. It decides where every future verb
114
+ * sends the bearer token and the source archive, so a one-off `--host`
115
+ * override (a staging test, say) must not silently become the project's
116
+ * sticky default; when the override differs from the stored host, the stored
117
+ * value is kept and the difference is called out in the result instead.
118
+ * Changing it is an explicit edit of ekanos.json. `source` keeps the simpler
119
+ * always-update semantics — it is scoped BY the host, and updating it is the
120
+ * documented way to repoint a project.
100
121
  */
101
- function persistSourceSlug(loaded, source) {
102
- if (loaded.project.source === source)
103
- return false;
122
+ function persistProjectFields(loaded, source, host) {
123
+ const wants = {
124
+ source: loaded.project.source !== source,
125
+ host: loaded.project.host === undefined,
126
+ };
127
+ const hostOverride = loaded.project.host !== undefined && loaded.project.host !== host
128
+ ? loaded.project.host
129
+ : null;
130
+ if (!wants.source && !wants.host) {
131
+ return { source: false, host: false, hostOverride };
132
+ }
104
133
  try {
105
- fs.writeFileSync(loaded.configPath, serializeProject(Object.assign(Object.assign({}, loaded.project), { source })));
106
- return true;
134
+ fs.writeFileSync(loaded.configPath, serializeProject(Object.assign(Object.assign({}, loaded.project), { source, host: wants.host ? host : loaded.project.host })));
135
+ return Object.assign(Object.assign({}, wants), { hostOverride });
107
136
  }
108
137
  catch (_a) {
109
138
  // Diagnostics-only: the publish succeeded; a read-only ekanos.json just
110
- // means the next publish needs --source again.
111
- return false;
139
+ // means the next publish needs the flags again.
140
+ return { source: false, host: false, hostOverride };
141
+ }
142
+ }
143
+ /**
144
+ * How many packed paths the manifest embeds before switching to a truncated
145
+ * list plus a `filesTruncated` total. The manifest is metadata — the archive
146
+ * itself is the payload — and the server caps it at MAX_MANIFEST_BYTES, so a
147
+ * many-small-files project must not be able to blow the cap with its file
148
+ * list alone.
149
+ */
150
+ const MANIFEST_FILE_LIST_CAP = 200;
151
+ /**
152
+ * The submission manifest: the parsed ekanos.json, the integration entries,
153
+ * and (a bounded prefix of) the packed file list. Refuses to build one over
154
+ * the server's byte cap — a clear VALIDATION error here beats the server's
155
+ * generic 400 after a 4 MiB upload.
156
+ */
157
+ function buildManifest(loaded, files) {
158
+ const manifest = JSON.stringify(Object.assign({ project: loaded.project, integrations: loaded.integrations.map((i) => ({
159
+ slug: i.slug,
160
+ entry: i.entry,
161
+ })), files: files.slice(0, MANIFEST_FILE_LIST_CAP) }, (files.length > MANIFEST_FILE_LIST_CAP
162
+ ? { filesTruncated: files.length }
163
+ : {})));
164
+ const bytes = Buffer.byteLength(manifest, 'utf8');
165
+ if (bytes > MAX_MANIFEST_BYTES) {
166
+ throw validationError(`The submission manifest is ${bytes} bytes, over the ` +
167
+ `${MAX_MANIFEST_BYTES}-byte server cap.`, 'The manifest embeds your ekanos.json — trim oversized fields there ' +
168
+ '(sourceGlobs is the usual culprit), then re-run "ekanos publish".');
112
169
  }
170
+ return manifest;
113
171
  }
114
172
  const SEMVER_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
115
173
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/commands/publish.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEhF,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAsB,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,kBAAkB,E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,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { StoredSession } from '../auth/credential-store';\nimport {\n refreshStoredSession,\n requireSession,\n resolveAuthEnvironment,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport { gateFailedError, preconditionError, validationError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { packProject } from '../pack';\nimport { type LoadedProject, loadProject, serializeProject } from '../project';\nimport { stillUnauthorized, submitArchive } from '../publish-api';\nimport { collectAllFindings } from '../validate-findings';\n\nexport interface PublishArgs {\n host?: string;\n /** Fusion source slug. Falls back to ekanos.json's \"source\" field. */\n source?: string;\n /** Project directory (contains ekanos.json). Defaults to cwd. */\n dir: string;\n /** Accepted for non-interactive ergonomics; publish never prompts regardless. */\n yes: boolean;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `publish` — pack the project and submit it to a Fusion deployment.\n *\n * The submission gate is the SAME findings pass `validate` runs (one\n * implementation, `validate-findings.ts`): any error-severity finding refuses\n * the publish with GATE_FAILED (exit 10) and the findings in `data`, so an\n * agent can branch on the code and fix-then-retry without re-running validate.\n *\n * Authorization is server-side — the dev seat on the target source — and the\n * stored session is refreshed once on a 401, mirroring `whoami`. On the first\n * successful publish the chosen source slug is persisted into `ekanos.json`\n * so later publishes need no `--source`.\n */\nexport async function runPublish(\n ctx: CliContext,\n args: PublishArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env);\n const session = requireSession(env.store, env.host);\n\n const loaded = loadProject(args.dir);\n const source = resolveSourceSlug(args.source, loaded);\n const version = readProjectVersion(loaded.projectDir);\n const slug = loaded.primary.slug;\n\n ctx.log(`Validating ${slug} before publishing…`);\n\n const findings = await collectAllFindings(loaded);\n const errorCount = findings.filter((f) => f.severity === 'error').length;\n\n if (errorCount > 0) {\n return ctx.fail(\n gateFailedError(\n `Refusing to publish: ${errorCount} validation finding` +\n `${errorCount === 1 ? '' : 's'}.`,\n 'Resolve the error-severity findings in data.findings (they are ' +\n 'exactly what \"ekanos validate\" reports), then re-run ' +\n '\"ekanos publish\".',\n ),\n { slug, version, findings },\n );\n }\n\n ctx.log(`Packing ${slug}@${version}…`);\n\n const packed = packProject(loaded.projectDir);\n\n const manifest = JSON.stringify({\n project: loaded.project,\n integrations: loaded.integrations.map((i) => ({\n slug: i.slug,\n entry: i.entry,\n })),\n files: packed.files,\n });\n\n ctx.log(`Submitting to ${env.host} (source \"${source}\")…`);\n\n const receipt = await submitWithOneRefresh(env, session, {\n source,\n slug,\n version,\n manifest,\n archive: packed.archive,\n });\n\n const persistedSource = persistSourceSlug(loaded, source);\n\n return ctx.succeed(\n {\n host: env.host,\n source,\n slug: receipt.slug,\n version: receipt.version,\n submissionId: receipt.submissionId,\n state: receipt.state,\n archiveSha256: receipt.archiveSha256,\n files: packed.files,\n sourcePersisted: persistedSource,\n },\n `publish: submitted ${receipt.slug}@${receipt.version} to ${env.host} ` +\n `(source \"${source}\", state \"${receipt.state}\").` +\n (persistedSource\n ? ` Saved \"source\": \"${source}\" to ekanos.json — future publishes ` +\n `won't need --source.`\n : ''),\n );\n}\n\nasync function submitWithOneRefresh(\n env: ReturnType<typeof resolveAuthEnvironment>,\n session: StoredSession,\n payload: Parameters<typeof submitArchive>[2],\n) {\n const first = await submitArchive(env.host, session.accessToken, payload);\n\n if (first.status === 'ok') return first.receipt;\n\n // The access token no longer authenticates — an ordinary event, not an\n // error. One refresh, one retry; a second 401 is authoritative.\n const refreshed = await refreshStoredSession(env, session);\n const second = await submitArchive(env.host, refreshed.accessToken, payload);\n\n if (second.status === 'ok') return second.receipt;\n\n return stillUnauthorized(env.host);\n}\n\nfunction resolveSourceSlug(\n flag: string | undefined,\n loaded: LoadedProject,\n): string {\n const source = flag ?? loaded.project.source;\n\n if (!source || source.trim().length === 0) {\n throw validationError(\n 'No Fusion source given for the submission.',\n 'Pass \"--source <slug>\" (your operator names the source), or set ' +\n '\"source\": \"<slug>\" in ekanos.json. A successful publish saves it ' +\n 'there for you.',\n );\n }\n\n return source.trim();\n}\n\n/**\n * Persist the chosen source into ekanos.json after a SUCCESSFUL publish, so\n * the next publish needs no flag. Returns whether anything was written. A\n * write failure is reported but never fails the command — the submission\n * already landed.\n */\nfunction persistSourceSlug(loaded: LoadedProject, source: string): boolean {\n if (loaded.project.source === source) return false;\n\n try {\n fs.writeFileSync(\n loaded.configPath,\n serializeProject({ ...loaded.project, source }),\n );\n\n return true;\n } catch {\n // Diagnostics-only: the publish succeeded; a read-only ekanos.json just\n // means the next publish needs --source again.\n return false;\n }\n}\n\nconst SEMVER_PATTERN =\n /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$/;\n\n/**\n * The submitted version is the project's own `package.json#version` — one\n * source of truth, the same field npm would publish.\n */\nfunction readProjectVersion(projectDir: string): string {\n const manifestPath = path.join(projectDir, 'package.json');\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n } catch (error) {\n throw preconditionError(\n `Could not read ${manifestPath}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n `Ensure the project has a valid package.json — its \"version\" field is ` +\n `what gets submitted.`,\n );\n }\n\n const version =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as { version?: unknown }).version\n : undefined;\n\n if (typeof version !== 'string' || !SEMVER_PATTERN.test(version)) {\n throw validationError(\n `package.json \"version\" is ${\n typeof version === 'string' ? `\"${version}\"` : 'missing'\n }, which is not a semver version.`,\n `Set \"version\" in ${manifestPath} to a semver string like \"0.1.0\", ` +\n `then re-run \"ekanos publish\".`,\n );\n }\n\n return version;\n}\n"]}
1
+ {"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/commands/publish.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,O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ACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { StoredSession } from '../auth/credential-store';\nimport {\n refreshStoredSession,\n requireSession,\n resolveAuthEnvironment,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport { gateFailedError, preconditionError, validationError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { packProject } from '../pack';\nimport { type LoadedProject, loadProject, serializeProject } from '../project';\nimport {\n MAX_MANIFEST_BYTES,\n stillUnauthorized,\n submitArchive,\n} from '../publish-api';\nimport { collectAllFindings } from '../validate-findings';\n\nexport interface PublishArgs {\n host?: string;\n /** Fusion source slug. Falls back to ekanos.json's \"source\" field. */\n source?: string;\n /** Project directory (contains ekanos.json). Defaults to cwd. */\n dir: string;\n /** Accepted for non-interactive ergonomics; publish never prompts regardless. */\n yes: boolean;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `publish` — pack the project and submit it to a Fusion deployment.\n *\n * The submission gate is the SAME findings pass `validate` runs (one\n * implementation, `validate-findings.ts`): any error-severity finding refuses\n * the publish with GATE_FAILED (exit 10) and the findings in `data`, so an\n * agent can branch on the code and fix-then-retry without re-running validate.\n *\n * Authorization is server-side — the dev seat on the target source — and the\n * stored session is refreshed once on a 401, mirroring `whoami`. On the first\n * successful publish the chosen source slug is persisted into `ekanos.json`\n * so later publishes need no `--source`.\n */\nexport async function runPublish(\n ctx: CliContext,\n args: PublishArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const session = requireSession(env.store, env.host);\n\n const loaded = loadProject(args.dir);\n const source = resolveSourceSlug(args.source, loaded);\n const version = readProjectVersion(loaded.projectDir);\n const slug = loaded.primary.slug;\n\n ctx.log(`Validating ${slug} before publishing…`);\n\n const findings = await collectAllFindings(loaded);\n const errorCount = findings.filter((f) => f.severity === 'error').length;\n\n if (errorCount > 0) {\n return ctx.fail(\n gateFailedError(\n `Refusing to publish: ${errorCount} validation finding` +\n `${errorCount === 1 ? '' : 's'}.`,\n 'Resolve the error-severity findings in data.findings (they are ' +\n 'exactly what \"ekanos validate\" reports), then re-run ' +\n '\"ekanos publish\".',\n ),\n { slug, version, findings },\n );\n }\n\n ctx.log(`Packing ${slug}@${version}…`);\n\n const packed = packProject(loaded.projectDir);\n const manifest = buildManifest(loaded, packed.files);\n\n ctx.log(`Submitting to ${env.host} (source \"${source}\")…`);\n\n const receipt = await submitWithOneRefresh(env, session, {\n source,\n slug,\n version,\n manifest,\n archive: packed.archive,\n });\n\n const persisted = persistProjectFields(loaded, source, env.host);\n\n const persistedNote = [\n ...(persisted.source ? [`\"source\": \"${source}\"`] : []),\n ...(persisted.host ? [`\"host\": \"${env.host}\"`] : []),\n ];\n\n const overrideNote = persisted.hostOverride\n ? ` NOTE: this publish went to ${env.host}, but ekanos.json keeps ` +\n `\"host\": \"${persisted.hostOverride}\" — a one-off override never ` +\n `replaces the saved host; edit ekanos.json to change it.`\n : '';\n\n return ctx.succeed(\n {\n host: env.host,\n source,\n slug: receipt.slug,\n version: receipt.version,\n submissionId: receipt.submissionId,\n state: receipt.state,\n archiveSha256: receipt.archiveSha256,\n files: packed.files,\n sourcePersisted: persisted.source,\n hostPersisted: persisted.host,\n hostOverride: persisted.hostOverride,\n },\n `publish: submitted ${receipt.slug}@${receipt.version} to ${env.host} ` +\n `(source \"${source}\", state \"${receipt.state}\").` +\n (persistedNote.length > 0\n ? ` Saved ${persistedNote.join(' and ')} to ekanos.json — future ` +\n `publishes won't need the flag${persistedNote.length === 1 ? '' : 's'}.`\n : '') +\n overrideNote,\n );\n}\n\nasync function submitWithOneRefresh(\n env: ReturnType<typeof resolveAuthEnvironment>,\n session: StoredSession,\n payload: Parameters<typeof submitArchive>[2],\n) {\n const first = await submitArchive(env.host, session.accessToken, payload);\n\n if (first.status === 'ok') return first.receipt;\n\n // The access token no longer authenticates — an ordinary event, not an\n // error. One refresh, one retry; a second 401 is authoritative.\n const refreshed = await refreshStoredSession(env, session);\n const second = await submitArchive(env.host, refreshed.accessToken, payload);\n\n if (second.status === 'ok') return second.receipt;\n\n return stillUnauthorized(env.host);\n}\n\nfunction resolveSourceSlug(\n flag: string | undefined,\n loaded: LoadedProject,\n): string {\n const source = flag ?? loaded.project.source;\n\n if (!source || source.trim().length === 0) {\n throw validationError(\n 'No Fusion source given for the submission.',\n 'Pass \"--source <slug>\" (your operator names the source), or set ' +\n '\"source\": \"<slug>\" in ekanos.json. A successful publish saves it ' +\n 'there for you.',\n );\n }\n\n return source.trim();\n}\n\n/**\n * Persist the chosen source AND host into ekanos.json after a SUCCESSFUL\n * publish, so the next publish — and every other host-taking verb — needs no\n * flag. Returns what was written. A write failure is reported but never fails\n * the command — the submission already landed.\n *\n * `publish` is the only verb that writes ekanos.json: it is the one verb that\n * proves the (host, source) pair actually works, and it always runs inside a\n * project. `login` deliberately never writes — it is routinely run outside\n * one, and the credential store's sole-host fallback covers it.\n *\n * `host` persists on FIRST WRITE ONLY. It decides where every future verb\n * sends the bearer token and the source archive, so a one-off `--host`\n * override (a staging test, say) must not silently become the project's\n * sticky default; when the override differs from the stored host, the stored\n * value is kept and the difference is called out in the result instead.\n * Changing it is an explicit edit of ekanos.json. `source` keeps the simpler\n * always-update semantics — it is scoped BY the host, and updating it is the\n * documented way to repoint a project.\n */\nfunction persistProjectFields(\n loaded: LoadedProject,\n source: string,\n host: string,\n): { source: boolean; host: boolean; hostOverride: string | null } {\n const wants = {\n source: loaded.project.source !== source,\n host: loaded.project.host === undefined,\n };\n\n const hostOverride =\n loaded.project.host !== undefined && loaded.project.host !== host\n ? loaded.project.host\n : null;\n\n if (!wants.source && !wants.host) {\n return { source: false, host: false, hostOverride };\n }\n\n try {\n fs.writeFileSync(\n loaded.configPath,\n serializeProject({\n ...loaded.project,\n source,\n host: wants.host ? host : loaded.project.host,\n }),\n );\n\n return { ...wants, hostOverride };\n } catch {\n // Diagnostics-only: the publish succeeded; a read-only ekanos.json just\n // means the next publish needs the flags again.\n return { source: false, host: false, hostOverride };\n }\n}\n\n/**\n * How many packed paths the manifest embeds before switching to a truncated\n * list plus a `filesTruncated` total. The manifest is metadata — the archive\n * itself is the payload — and the server caps it at MAX_MANIFEST_BYTES, so a\n * many-small-files project must not be able to blow the cap with its file\n * list alone.\n */\nconst MANIFEST_FILE_LIST_CAP = 200;\n\n/**\n * The submission manifest: the parsed ekanos.json, the integration entries,\n * and (a bounded prefix of) the packed file list. Refuses to build one over\n * the server's byte cap — a clear VALIDATION error here beats the server's\n * generic 400 after a 4 MiB upload.\n */\nfunction buildManifest(loaded: LoadedProject, files: string[]): string {\n const manifest = JSON.stringify({\n project: loaded.project,\n integrations: loaded.integrations.map((i) => ({\n slug: i.slug,\n entry: i.entry,\n })),\n files: files.slice(0, MANIFEST_FILE_LIST_CAP),\n ...(files.length > MANIFEST_FILE_LIST_CAP\n ? { filesTruncated: files.length }\n : {}),\n });\n\n const bytes = Buffer.byteLength(manifest, 'utf8');\n\n if (bytes > MAX_MANIFEST_BYTES) {\n throw validationError(\n `The submission manifest is ${bytes} bytes, over the ` +\n `${MAX_MANIFEST_BYTES}-byte server cap.`,\n 'The manifest embeds your ekanos.json — trim oversized fields there ' +\n '(sourceGlobs is the usual culprit), then re-run \"ekanos publish\".',\n );\n }\n\n return manifest;\n}\n\nconst SEMVER_PATTERN =\n /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$/;\n\n/**\n * The submitted version is the project's own `package.json#version` — one\n * source of truth, the same field npm would publish.\n */\nfunction readProjectVersion(projectDir: string): string {\n const manifestPath = path.join(projectDir, 'package.json');\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));\n } catch (error) {\n throw preconditionError(\n `Could not read ${manifestPath}: ${\n error instanceof Error ? error.message : String(error)\n }`,\n `Ensure the project has a valid package.json — its \"version\" field is ` +\n `what gets submitted.`,\n );\n }\n\n const version =\n typeof parsed === 'object' && parsed !== null\n ? (parsed as { version?: unknown }).version\n : undefined;\n\n if (typeof version !== 'string' || !SEMVER_PATTERN.test(version)) {\n throw validationError(\n `package.json \"version\" is ${\n typeof version === 'string' ? `\"${version}\"` : 'missing'\n }, which is not a semver version.`,\n `Set \"version\" in ${manifestPath} to a semver string like \"0.1.0\", ` +\n `then re-run \"ekanos publish\".`,\n );\n }\n\n return version;\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import type { CliContext } from '../context.js';
2
+ import { type ExitCode } from '../exit-codes.js';
3
+ export interface StatusArgs {
4
+ host?: string;
5
+ /** Project directory (may contain ekanos.json). Defaults to cwd. */
6
+ dir: string;
7
+ env: Record<string, string | undefined>;
8
+ }
9
+ /**
10
+ * `status` — the read verb: where am I pointed, who am I, and what has this
11
+ * project submitted?
12
+ *
13
+ * Three sections, each degrading gracefully rather than failing:
14
+ *
15
+ * - **session** — whoami's server-side identity check, but an absent or dead
16
+ * session reports `authenticated: false` with a hint instead of exit 4. A
17
+ * partner asking "what is my state?" must get an answer, not an error whose
18
+ * answer it is.
19
+ * - **project** — the ekanos.json in `--dir` (default cwd), when there is
20
+ * one. No project is an ordinary state for `status`, never an error.
21
+ * - **submissions** — `GET /api/partner/submissions?source=…` for the
22
+ * project's resolved source, only when both a session and a source exist.
23
+ * Server errors here DO map through the taxonomy: an unreachable host or a
24
+ * missing source is a fault to surface, not a state to absorb.
25
+ *
26
+ * Exit 0 whenever the report itself could be assembled.
27
+ */
28
+ export declare function runStatus(ctx: CliContext, args: StatusArgs): Promise<ExitCode>;
@@ -0,0 +1,146 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { refreshStoredSession, resolveAuthEnvironment, resolveIdentity, } from '../auth/session.js';
4
+ import { CliError, authRequiredError } from '../errors.js';
5
+ import { ERROR_CODES } from '../exit-codes.js';
6
+ import { EKANOS_CONFIG_FILENAME, loadProject } from '../project.js';
7
+ import { listSubmissions } from '../publish-api.js';
8
+ /**
9
+ * `status` — the read verb: where am I pointed, who am I, and what has this
10
+ * project submitted?
11
+ *
12
+ * Three sections, each degrading gracefully rather than failing:
13
+ *
14
+ * - **session** — whoami's server-side identity check, but an absent or dead
15
+ * session reports `authenticated: false` with a hint instead of exit 4. A
16
+ * partner asking "what is my state?" must get an answer, not an error whose
17
+ * answer it is.
18
+ * - **project** — the ekanos.json in `--dir` (default cwd), when there is
19
+ * one. No project is an ordinary state for `status`, never an error.
20
+ * - **submissions** — `GET /api/partner/submissions?source=…` for the
21
+ * project's resolved source, only when both a session and a source exist.
22
+ * Server errors here DO map through the taxonomy: an unreachable host or a
23
+ * missing source is a fault to surface, not a state to absorb.
24
+ *
25
+ * Exit 0 whenever the report itself could be assembled.
26
+ */
27
+ export async function runStatus(ctx, args) {
28
+ var _a, _b;
29
+ const env = resolveAuthEnvironment(ctx, args.host, args.env, {
30
+ projectDir: args.dir,
31
+ });
32
+ const stored = env.store.read(env.host);
33
+ const session = stored
34
+ ? await probeSession(env, stored)
35
+ : {
36
+ authenticated: false,
37
+ hint: `Run "ekanos login --host ${env.host}" to sign in.`,
38
+ };
39
+ // probeSession may have refreshed the session — persisting a NEW access
40
+ // token and ROTATING the refresh token on disk. Re-read before using it:
41
+ // the pre-probe object now holds a dead access token and an already-spent
42
+ // refresh token, and presenting those would turn "logged in, token was
43
+ // merely stale" into a hard exit-4 — the one failure this command promises
44
+ // never to produce.
45
+ const live = stored ? ((_a = env.store.read(env.host)) !== null && _a !== void 0 ? _a : stored) : null;
46
+ const project = readProjectReport(args.dir);
47
+ let submissions = null;
48
+ if ((project === null || project === void 0 ? void 0 : project.source) && session.authenticated && live) {
49
+ submissions = await listWithOneRefresh(env, live, project.source);
50
+ }
51
+ else if ((project === null || project === void 0 ? void 0 : project.source) && !session.authenticated) {
52
+ ctx.log(`ekanos: not logged in to ${env.host} — skipping the submission list. ` +
53
+ ((_b = session.hint) !== null && _b !== void 0 ? _b : ''));
54
+ }
55
+ else if (project && !project.source) {
56
+ ctx.log('ekanos: this project has no "source" in ekanos.json yet — the first ' +
57
+ '"ekanos publish --source <slug>" saves one, and status will list ' +
58
+ 'submissions from then on.');
59
+ }
60
+ return ctx.succeed(Object.assign(Object.assign({ host: env.host }, session), { credentialsPath: env.store.filePath, project,
61
+ submissions }), humanSummary(env.host, session, project, submissions));
62
+ }
63
+ /**
64
+ * whoami's identity resolution, with AUTH_REQUIRED absorbed into
65
+ * `authenticated: false`. Anything else — network, precondition, MFA mapped
66
+ * to auth by `fetchIdentity` — still propagates: "the host was unreachable"
67
+ * must never be reported as "you are logged out".
68
+ */
69
+ async function probeSession(env, stored) {
70
+ try {
71
+ const { identity, session } = await resolveIdentity(env, stored);
72
+ return {
73
+ authenticated: true,
74
+ user: { id: identity.id, email: identity.email, name: identity.name },
75
+ expiresAt: session.expiresAt,
76
+ };
77
+ }
78
+ catch (error) {
79
+ if (error instanceof CliError && error.code === ERROR_CODES.AUTH_REQUIRED) {
80
+ return { authenticated: false, hint: error.hint };
81
+ }
82
+ throw error;
83
+ }
84
+ }
85
+ /**
86
+ * Lenient project read: no ekanos.json means "not in a project", which is an
87
+ * answer, not an error. An ekanos.json that EXISTS but does not load keeps
88
+ * `loadProject`'s strict behaviour — a broken project file is a fault the
89
+ * partner needs named, whatever verb they ran.
90
+ */
91
+ function readProjectReport(dir) {
92
+ var _a;
93
+ const projectDir = path.resolve(dir);
94
+ if (!fs.existsSync(path.join(projectDir, EKANOS_CONFIG_FILENAME))) {
95
+ return null;
96
+ }
97
+ const loaded = loadProject(projectDir);
98
+ return {
99
+ dir: loaded.projectDir,
100
+ slug: loaded.primary.slug,
101
+ source: (_a = loaded.project.source) !== null && _a !== void 0 ? _a : null,
102
+ };
103
+ }
104
+ /** Mirrors publish's one-refresh-one-retry on a stale access token. */
105
+ async function listWithOneRefresh(env, session, source) {
106
+ const first = await listSubmissions(env.host, session.accessToken, source);
107
+ if (first.status === 'ok')
108
+ return first.integrations;
109
+ const refreshed = await refreshStoredSession(env, session);
110
+ const second = await listSubmissions(env.host, refreshed.accessToken, source);
111
+ if (second.status === 'ok')
112
+ return second.integrations;
113
+ // Authenticated a moment ago, unauthorized twice here: report the list as
114
+ // unavailable rather than the session as dead — probeSession already proved
115
+ // it. This is unreachable in practice; belt and braces for a racing revoke.
116
+ throw authRequiredError(`The session for ${env.host} could not authorize the submission list.`, `Run "ekanos login --host ${env.host}" and retry.`);
117
+ }
118
+ function humanSummary(host, session, project, submissions) {
119
+ var _a, _b, _c;
120
+ const lines = [];
121
+ lines.push(session.authenticated
122
+ ? `status: logged in to ${host} as ${(_b = (_a = session.user) === null || _a === void 0 ? void 0 : _a.email) !== null && _b !== void 0 ? _b : (_c = session.user) === null || _c === void 0 ? void 0 : _c.id}${session.expiresAt ? ` (session expires ${session.expiresAt})` : ''}.`
123
+ : `status: not logged in to ${host}.`);
124
+ if (project) {
125
+ lines.push(` project: ${project.slug} in ${project.dir}` +
126
+ (project.source
127
+ ? ` (source "${project.source}")`
128
+ : ' (no source configured yet)'));
129
+ }
130
+ else {
131
+ lines.push(' project: none (no ekanos.json here).');
132
+ }
133
+ if (submissions) {
134
+ if (submissions.length === 0) {
135
+ lines.push(' submissions: none yet.');
136
+ }
137
+ for (const integration of submissions) {
138
+ for (const version of integration.versions) {
139
+ lines.push(` submissions: ${integration.slug}@${version.version} — ` +
140
+ `${version.state}${version.submittedAt ? ` (submitted ${version.submittedAt})` : ''}`);
141
+ }
142
+ }
143
+ }
144
+ return lines.join('\n');
145
+ }
146
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,G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C,KAAK,CAAC,IAAI,CACR,kBAAkB,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,OAAO,KAAK;oBACxD,GAAG,OAAO,CAAC,KAAK,GACd,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,eAAe,OAAO,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,EAChE,EAAE,CACL,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC","sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport type { StoredSession } from '../auth/credential-store';\nimport {\n refreshStoredSession,\n resolveAuthEnvironment,\n resolveIdentity,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport { CliError, authRequiredError } from '../errors';\nimport { ERROR_CODES, type ExitCode } from '../exit-codes';\nimport { EKANOS_CONFIG_FILENAME, loadProject } from '../project';\nimport { type SubmissionListing, listSubmissions } from '../publish-api';\n\nexport interface StatusArgs {\n host?: string;\n /** Project directory (may contain ekanos.json). Defaults to cwd. */\n dir: string;\n env: Record<string, string | undefined>;\n}\n\ninterface SessionReport {\n authenticated: boolean;\n user?: { id: string; email: string | null; name: string | null };\n expiresAt?: string;\n hint?: string;\n}\n\ninterface ProjectReport {\n dir: string;\n slug: string;\n source: string | null;\n}\n\n/**\n * `status` — the read verb: where am I pointed, who am I, and what has this\n * project submitted?\n *\n * Three sections, each degrading gracefully rather than failing:\n *\n * - **session** — whoami's server-side identity check, but an absent or dead\n * session reports `authenticated: false` with a hint instead of exit 4. A\n * partner asking \"what is my state?\" must get an answer, not an error whose\n * answer it is.\n * - **project** — the ekanos.json in `--dir` (default cwd), when there is\n * one. No project is an ordinary state for `status`, never an error.\n * - **submissions** — `GET /api/partner/submissions?source=…` for the\n * project's resolved source, only when both a session and a source exist.\n * Server errors here DO map through the taxonomy: an unreachable host or a\n * missing source is a fault to surface, not a state to absorb.\n *\n * Exit 0 whenever the report itself could be assembled.\n */\nexport async function runStatus(\n ctx: CliContext,\n args: StatusArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n\n const stored = env.store.read(env.host);\n const session = stored\n ? await probeSession(env, stored)\n : {\n authenticated: false,\n hint: `Run \"ekanos login --host ${env.host}\" to sign in.`,\n };\n\n // probeSession may have refreshed the session — persisting a NEW access\n // token and ROTATING the refresh token on disk. Re-read before using it:\n // the pre-probe object now holds a dead access token and an already-spent\n // refresh token, and presenting those would turn \"logged in, token was\n // merely stale\" into a hard exit-4 — the one failure this command promises\n // never to produce.\n const live = stored ? (env.store.read(env.host) ?? stored) : null;\n\n const project = readProjectReport(args.dir);\n\n let submissions: SubmissionListing[] | null = null;\n\n if (project?.source && session.authenticated && live) {\n submissions = await listWithOneRefresh(env, live, project.source);\n } else if (project?.source && !session.authenticated) {\n ctx.log(\n `ekanos: not logged in to ${env.host} — skipping the submission list. ` +\n (session.hint ?? ''),\n );\n } else if (project && !project.source) {\n ctx.log(\n 'ekanos: this project has no \"source\" in ekanos.json yet — the first ' +\n '\"ekanos publish --source <slug>\" saves one, and status will list ' +\n 'submissions from then on.',\n );\n }\n\n return ctx.succeed(\n {\n host: env.host,\n ...session,\n credentialsPath: env.store.filePath,\n project,\n submissions,\n },\n humanSummary(env.host, session, project, submissions),\n );\n}\n\n/**\n * whoami's identity resolution, with AUTH_REQUIRED absorbed into\n * `authenticated: false`. Anything else — network, precondition, MFA mapped\n * to auth by `fetchIdentity` — still propagates: \"the host was unreachable\"\n * must never be reported as \"you are logged out\".\n */\nasync function probeSession(\n env: ReturnType<typeof resolveAuthEnvironment>,\n stored: StoredSession,\n): Promise<SessionReport> {\n try {\n const { identity, session } = await resolveIdentity(env, stored);\n\n return {\n authenticated: true,\n user: { id: identity.id, email: identity.email, name: identity.name },\n expiresAt: session.expiresAt,\n };\n } catch (error) {\n if (error instanceof CliError && error.code === ERROR_CODES.AUTH_REQUIRED) {\n return { authenticated: false, hint: error.hint };\n }\n\n throw error;\n }\n}\n\n/**\n * Lenient project read: no ekanos.json means \"not in a project\", which is an\n * answer, not an error. An ekanos.json that EXISTS but does not load keeps\n * `loadProject`'s strict behaviour — a broken project file is a fault the\n * partner needs named, whatever verb they ran.\n */\nfunction readProjectReport(dir: string): ProjectReport | null {\n const projectDir = path.resolve(dir);\n\n if (!fs.existsSync(path.join(projectDir, EKANOS_CONFIG_FILENAME))) {\n return null;\n }\n\n const loaded = loadProject(projectDir);\n\n return {\n dir: loaded.projectDir,\n slug: loaded.primary.slug,\n source: loaded.project.source ?? null,\n };\n}\n\n/** Mirrors publish's one-refresh-one-retry on a stale access token. */\nasync function listWithOneRefresh(\n env: ReturnType<typeof resolveAuthEnvironment>,\n session: StoredSession,\n source: string,\n): Promise<SubmissionListing[]> {\n const first = await listSubmissions(env.host, session.accessToken, source);\n\n if (first.status === 'ok') return first.integrations;\n\n const refreshed = await refreshStoredSession(env, session);\n const second = await listSubmissions(env.host, refreshed.accessToken, source);\n\n if (second.status === 'ok') return second.integrations;\n\n // Authenticated a moment ago, unauthorized twice here: report the list as\n // unavailable rather than the session as dead — probeSession already proved\n // it. This is unreachable in practice; belt and braces for a racing revoke.\n throw authRequiredError(\n `The session for ${env.host} could not authorize the submission list.`,\n `Run \"ekanos login --host ${env.host}\" and retry.`,\n );\n}\n\nfunction humanSummary(\n host: string,\n session: SessionReport,\n project: ProjectReport | null,\n submissions: SubmissionListing[] | null,\n): string {\n const lines: string[] = [];\n\n lines.push(\n session.authenticated\n ? `status: logged in to ${host} as ${\n session.user?.email ?? session.user?.id\n }${session.expiresAt ? ` (session expires ${session.expiresAt})` : ''}.`\n : `status: not logged in to ${host}.`,\n );\n\n if (project) {\n lines.push(\n ` project: ${project.slug} in ${project.dir}` +\n (project.source\n ? ` (source \"${project.source}\")`\n : ' (no source configured yet)'),\n );\n } else {\n lines.push(' project: none (no ekanos.json here).');\n }\n\n if (submissions) {\n if (submissions.length === 0) {\n lines.push(' submissions: none yet.');\n }\n\n for (const integration of submissions) {\n for (const version of integration.versions) {\n lines.push(\n ` submissions: ${integration.slug}@${version.version} — ` +\n `${version.state}${\n version.submittedAt ? ` (submitted ${version.submittedAt})` : ''\n }`,\n );\n }\n }\n }\n\n return lines.join('\\n');\n}\n"]}
@@ -2,6 +2,8 @@ import type { CliContext } from '../context.js';
2
2
  import type { ExitCode } from '../exit-codes.js';
3
3
  export interface WhoamiArgs {
4
4
  host?: string;
5
+ /** Where a project's ekanos.json may sit, for its optional `host` field. */
6
+ cwd: string;
5
7
  env: Record<string, string | undefined>;
6
8
  }
7
9
  /**
@@ -12,7 +12,9 @@ import { requireSession, resolveAuthEnvironment, resolveIdentity, } from '../aut
12
12
  */
13
13
  export async function runWhoami(ctx, args) {
14
14
  var _a;
15
- const env = resolveAuthEnvironment(ctx, args.host, args.env);
15
+ const env = resolveAuthEnvironment(ctx, args.host, args.env, {
16
+ projectDir: args.cwd,
17
+ });
16
18
  const stored = requireSession(env.store, env.host);
17
19
  const { identity, session } = await resolveIdentity(env, stored);
18
20
  return ctx.succeed({
@@ -1 +1 @@
1
- {"version":3,"file":"whoami.js","sourceRoot":"","sources":["../../src/commands/whoami.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AASzB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAe,EACf,IAAgB;;IAEhB,MAAM,GAAG,GAAG,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAEnD,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEjE,OAAO,GAAG,CAAC,OAAO,CAChB;QACE,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE;YACJ,EAAE,EAAE,QAAQ,CAAC,EAAE;YACf,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,IAAI,EAAE,QAAQ,CAAC,IAAI;SACpB;QACD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,eAAe,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ;KACpC,EACD,WAAW,MAAA,QAAQ,CAAC,KAAK,mCAAI,QAAQ,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,GAAG,CAC3D,CAAC;AACJ,CAAC","sourcesContent":["import {\n requireSession,\n resolveAuthEnvironment,\n resolveIdentity,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport type { ExitCode } from '../exit-codes';\n\nexport interface WhoamiArgs {\n host?: string;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `whoami` — prove the stored session still authenticates against Fusion.\n *\n * The identity is resolved server-side by `/api/auth/cli-whoami`, which reads\n * the account through RLS as the caller. Printing the locally cached email\n * would be a cheaper lie: it would keep saying \"logged in\" after the account\n * was deleted or the token revoked.\n *\n * Exit 4 (auth_required) when there is no session or it cannot be renewed —\n * the code a script should branch on to decide whether to run `ekanos login`.\n */\nexport async function runWhoami(\n ctx: CliContext,\n args: WhoamiArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env);\n const stored = requireSession(env.store, env.host);\n\n const { identity, session } = await resolveIdentity(env, stored);\n\n return ctx.succeed(\n {\n host: env.host,\n user: {\n id: identity.id,\n email: identity.email,\n name: identity.name,\n },\n expiresAt: session.expiresAt,\n credentialsPath: env.store.filePath,\n },\n `whoami: ${identity.email ?? identity.id} on ${env.host}.`,\n );\n}\n"]}
1
+ {"version":3,"file":"whoami.js","sourceRoot":"","sources":["../../src/commands/whoami.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,eAAe,GAChB,MAAM,iBAAiB,CAAC;AAWzB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,GAAe,EACf,IAAgB;;IAEhB,MAAM,GAAG,GAAG,sBAAsB,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;QAC3D,UAAU,EAAE,IAAI,CAAC,GAAG;KACrB,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAEnD,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEjE,OAAO,GAAG,CAAC,OAAO,CAChB;QACE,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,IAAI,EAAE;YACJ,EAAE,EAAE,QAAQ,CAAC,EAAE;YACf,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,IAAI,EAAE,QAAQ,CAAC,IAAI;SACpB;QACD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,eAAe,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ;KACpC,EACD,WAAW,MAAA,QAAQ,CAAC,KAAK,mCAAI,QAAQ,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,GAAG,CAC3D,CAAC;AACJ,CAAC","sourcesContent":["import {\n requireSession,\n resolveAuthEnvironment,\n resolveIdentity,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport type { ExitCode } from '../exit-codes';\n\nexport interface WhoamiArgs {\n host?: string;\n /** Where a project's ekanos.json may sit, for its optional `host` field. */\n cwd: string;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `whoami` — prove the stored session still authenticates against Fusion.\n *\n * The identity is resolved server-side by `/api/auth/cli-whoami`, which reads\n * the account through RLS as the caller. Printing the locally cached email\n * would be a cheaper lie: it would keep saying \"logged in\" after the account\n * was deleted or the token revoked.\n *\n * Exit 4 (auth_required) when there is no session or it cannot be renewed —\n * the code a script should branch on to decide whether to run `ekanos login`.\n */\nexport async function runWhoami(\n ctx: CliContext,\n args: WhoamiArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.cwd,\n });\n const stored = requireSession(env.store, env.host);\n\n const { identity, session } = await resolveIdentity(env, stored);\n\n return ctx.succeed(\n {\n host: env.host,\n user: {\n id: identity.id,\n email: identity.email,\n name: identity.name,\n },\n expiresAt: session.expiresAt,\n credentialsPath: env.store.filePath,\n },\n `whoami: ${identity.email ?? identity.id} on ${env.host}.`,\n );\n}\n"]}
package/dist/context.d.ts CHANGED
@@ -34,10 +34,18 @@ export interface ContextInput {
34
34
  */
35
35
  export declare class CliContext {
36
36
  readonly jsonMode: boolean;
37
+ /**
38
+ * The environment the context resolved against — exposed so decoration
39
+ * (the gradient banner) can honour `NO_COLOR` / `EKANOS_NO_BANNER` without
40
+ * every call site threading `process.env` through by hand.
41
+ */
42
+ readonly env: Readonly<Record<string, string | undefined>>;
37
43
  private readonly stdout;
38
44
  private readonly stderr;
39
45
  private settled;
40
46
  constructor(input?: ContextInput);
47
+ /** Whether stderr is a real terminal — decoration (the banner) gates on this. */
48
+ get stderrIsTTY(): boolean;
41
49
  /** Human/progress output — ALWAYS stderr, so stdout stays pure in JSON mode. */
42
50
  log(message: string): void;
43
51
  /** A warning — stderr, no ANSI. */
package/dist/context.js CHANGED
@@ -20,6 +20,7 @@ export class CliContext {
20
20
  const env = (_c = input.env) !== null && _c !== void 0 ? _c : process.env;
21
21
  this.stdout = stdout;
22
22
  this.stderr = stderr;
23
+ this.env = env;
23
24
  // Resolve JSON mode once. An EXPLICIT flag always wins: `--json` forces the
24
25
  // envelope on even at a terminal, `--no-json` forces the human form even
25
26
  // when piped. Only when the user expressed no preference is the mode
@@ -28,6 +29,10 @@ export class CliContext {
28
29
  const nonTty = stdout.isTTY !== true;
29
30
  this.jsonMode = (_d = input.jsonFlag) !== null && _d !== void 0 ? _d : (nonTty || env.CLAUDECODE === '1');
30
31
  }
32
+ /** Whether stderr is a real terminal — decoration (the banner) gates on this. */
33
+ get stderrIsTTY() {
34
+ return this.stderr.isTTY === true;
35
+ }
31
36
  /** Human/progress output — ALWAYS stderr, so stdout stays pure in JSON mode. */
32
37
  log(message) {
33
38
  this.stderr.write(`${message}\n`);