@ekanos/cli 0.1.4 → 0.1.5

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.
@@ -0,0 +1,62 @@
1
+ import { requireSession, resolveAuthEnvironment } from '../auth/session.js';
2
+ import { forbiddenError, usageError } from '../errors.js';
3
+ import { loadProject } from '../project.js';
4
+ import { fetchSeatsWithOneRefresh } from '../seats.js';
5
+ import { stillUnauthorizedSourceSeats } from '../sources-api.js';
6
+ import { persistProjectFields } from './publish.js';
7
+ /**
8
+ * `use <source-slug>` — set this project's publish target, with the same
9
+ * seat verification `publish` runs: the slug must name a source the caller
10
+ * actually holds a seat on, so a project can never be pointed at a source by
11
+ * a typo alone.
12
+ *
13
+ * Persisted via the exact same mechanics `publish` uses after a successful
14
+ * submission (`persistProjectFields`), so `host` also sticks on first write
15
+ * and a later `publish` needs neither flag.
16
+ */
17
+ export async function runUse(ctx, args) {
18
+ var _a;
19
+ if (!args.slug || args.slug.trim().length === 0) {
20
+ throw usageError('No source slug given.', 'Run "ekanos use <source-slug>" — see "ekanos sources" for the ' +
21
+ 'slugs you hold a seat on.');
22
+ }
23
+ const slug = args.slug.trim();
24
+ // Requires a project up front: `use` sets ekanos.json's "source" field, so
25
+ // running it outside one is a precondition failure, not a network call.
26
+ const loaded = loadProject(args.dir);
27
+ const env = resolveAuthEnvironment(ctx, args.host, args.env, {
28
+ projectDir: args.dir,
29
+ });
30
+ const session = requireSession(env.store, env.host);
31
+ const result = await fetchSeatsWithOneRefresh(env, session);
32
+ if (result.status === 'unauthorized') {
33
+ stillUnauthorizedSourceSeats(env.host);
34
+ }
35
+ const seat = result.sources.find((s) => s.slug === slug);
36
+ if (!seat) {
37
+ throw forbiddenError(`This account does not hold a seat on source "${slug}" on ${env.host}.`, seatsHint(result.sources, env.host));
38
+ }
39
+ const persisted = persistProjectFields(loaded, seat.slug, env.host);
40
+ return ctx.succeed({
41
+ host: env.host,
42
+ source: {
43
+ id: seat.id,
44
+ slug: seat.slug,
45
+ name: seat.name,
46
+ roles: seat.roles,
47
+ },
48
+ sourcePersisted: persisted.source,
49
+ hostPersisted: persisted.host,
50
+ }, `use: ekanos.json now publishes to ${(_a = seat.name) !== null && _a !== void 0 ? _a : seat.slug} (${seat.slug}) on ${env.host}.`);
51
+ }
52
+ function seatsHint(sources, host) {
53
+ if (sources.length === 0) {
54
+ return (`You hold no seats on any source on ${host}. Ask a Fusion super-admin ` +
55
+ `to grant your account a seat on the intended source.`);
56
+ }
57
+ const list = sources
58
+ .map((s) => `${s.slug} (${s.roles.join(', ')})`)
59
+ .join(', ');
60
+ return `You hold a seat on: ${list}. Run "ekanos use <slug>" with one of these.`;
61
+ }
62
+ //# sourceMappingURL=use.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use.js","sourceRoot":"","sources":["../../src/commands/use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAmB,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAWjD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,GAAe,EACf,IAAa;;IAEb,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChD,MAAM,UAAU,CACd,uBAAuB,EACvB,gEAAgE;YAC9D,2BAA2B,CAC9B,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAE9B,2E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AAa,EAAE,SAAS,CAAC,IAAI;KAC9B,EACD,qCAAqC,MAAA,IAAI,CAAC,IAAI,mCAAI,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,QAAQ,GAAG,CAAC,IAAI,GAAG,CAC7F,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,OAAqB,EAAE,IAAY;IACpD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,CACL,sCAAsC,IAAI,6BAA6B;YACvE,sDAAsD,CACvD,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,OAAO;SACjB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;SAC/C,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO,uBAAuB,IAAI,8CAA8C,CAAC;AACnF,CAAC","sourcesContent":["import { requireSession, resolveAuthEnvironment } from '../auth/session';\nimport type { CliContext } from '../context';\nimport { forbiddenError, usageError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { loadProject } from '../project';\nimport { fetchSeatsWithOneRefresh } from '../seats';\nimport { type SourceSeat, stillUnauthorizedSourceSeats } from '../sources-api';\nimport { persistProjectFields } from './publish';\n\nexport interface UseArgs {\n host?: string;\n /** Project directory (contains ekanos.json). Defaults to cwd. */\n dir: string;\n /** The source slug to switch this project's publish target to. */\n slug?: string;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `use <source-slug>` — set this project's publish target, with the same\n * seat verification `publish` runs: the slug must name a source the caller\n * actually holds a seat on, so a project can never be pointed at a source by\n * a typo alone.\n *\n * Persisted via the exact same mechanics `publish` uses after a successful\n * submission (`persistProjectFields`), so `host` also sticks on first write\n * and a later `publish` needs neither flag.\n */\nexport async function runUse(\n ctx: CliContext,\n args: UseArgs,\n): Promise<ExitCode> {\n if (!args.slug || args.slug.trim().length === 0) {\n throw usageError(\n 'No source slug given.',\n 'Run \"ekanos use <source-slug>\" — see \"ekanos sources\" for the ' +\n 'slugs you hold a seat on.',\n );\n }\n\n const slug = args.slug.trim();\n\n // Requires a project up front: `use` sets ekanos.json's \"source\" field, so\n // running it outside one is a precondition failure, not a network call.\n const loaded = loadProject(args.dir);\n\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 result = await fetchSeatsWithOneRefresh(env, session);\n\n if (result.status === 'unauthorized') {\n stillUnauthorizedSourceSeats(env.host);\n }\n\n const seat = result.sources.find((s) => s.slug === slug);\n\n if (!seat) {\n throw forbiddenError(\n `This account does not hold a seat on source \"${slug}\" on ${env.host}.`,\n seatsHint(result.sources, env.host),\n );\n }\n\n const persisted = persistProjectFields(loaded, seat.slug, env.host);\n\n return ctx.succeed(\n {\n host: env.host,\n source: {\n id: seat.id,\n slug: seat.slug,\n name: seat.name,\n roles: seat.roles,\n },\n sourcePersisted: persisted.source,\n hostPersisted: persisted.host,\n },\n `use: ekanos.json now publishes to ${seat.name ?? seat.slug} (${seat.slug}) on ${env.host}.`,\n );\n}\n\nfunction seatsHint(sources: SourceSeat[], host: string): string {\n if (sources.length === 0) {\n return (\n `You hold no seats on any source on ${host}. Ask a Fusion super-admin ` +\n `to grant your account a seat on the intended source.`\n );\n }\n\n const list = sources\n .map((s) => `${s.slug} (${s.roles.join(', ')})`)\n .join(', ');\n\n return `You hold a seat on: ${list}. Run \"ekanos use <slug>\" with one of these.`;\n}\n"]}
@@ -16,5 +16,11 @@ export interface WhoamiArgs {
16
16
  *
17
17
  * Exit 4 (auth_required) when there is no session or it cannot be renewed —
18
18
  * the code a script should branch on to decide whether to run `ekanos login`.
19
+ *
20
+ * `seats` is a best-effort add-on from the same source-visibility endpoint
21
+ * `ekanos sources` uses, compacted to slug+roles. Its failure — network, MFA,
22
+ * a deployment that predates the route — must never turn a working `whoami`
23
+ * into a failing one, so any error here degrades to `seats: null` rather than
24
+ * propagating.
19
25
  */
20
26
  export declare function runWhoami(ctx: CliContext, args: WhoamiArgs): Promise<ExitCode>;
@@ -1,4 +1,5 @@
1
1
  import { requireSession, resolveAuthEnvironment, resolveIdentity, } from '../auth/session.js';
2
+ import { fetchSeatsWithOneRefresh } from '../seats.js';
2
3
  /**
3
4
  * `whoami` — prove the stored session still authenticates against Fusion.
4
5
  *
@@ -9,6 +10,12 @@ import { requireSession, resolveAuthEnvironment, resolveIdentity, } from '../aut
9
10
  *
10
11
  * Exit 4 (auth_required) when there is no session or it cannot be renewed —
11
12
  * the code a script should branch on to decide whether to run `ekanos login`.
13
+ *
14
+ * `seats` is a best-effort add-on from the same source-visibility endpoint
15
+ * `ekanos sources` uses, compacted to slug+roles. Its failure — network, MFA,
16
+ * a deployment that predates the route — must never turn a working `whoami`
17
+ * into a failing one, so any error here degrades to `seats: null` rather than
18
+ * propagating.
12
19
  */
13
20
  export async function runWhoami(ctx, args) {
14
21
  var _a;
@@ -17,6 +24,7 @@ export async function runWhoami(ctx, args) {
17
24
  });
18
25
  const stored = requireSession(env.store, env.host);
19
26
  const { identity, session } = await resolveIdentity(env, stored);
27
+ const seats = await fetchSeatsQuietly(env, session);
20
28
  return ctx.succeed({
21
29
  host: env.host,
22
30
  user: {
@@ -26,6 +34,23 @@ export async function runWhoami(ctx, args) {
26
34
  },
27
35
  expiresAt: session.expiresAt,
28
36
  credentialsPath: env.store.filePath,
29
- }, `whoami: ${(_a = identity.email) !== null && _a !== void 0 ? _a : identity.id} on ${env.host}.`);
37
+ seats,
38
+ }, `whoami: ${(_a = identity.email) !== null && _a !== void 0 ? _a : identity.id} on ${env.host}.` +
39
+ (seats
40
+ ? seats.length > 0
41
+ ? ` Seats: ${seats.map((s) => `${s.slug} [${s.roles.join(', ')}]`).join(', ')}.`
42
+ : ' No source seats.'
43
+ : ' (source seat lookup unavailable)'));
44
+ }
45
+ async function fetchSeatsQuietly(env, session) {
46
+ try {
47
+ const result = await fetchSeatsWithOneRefresh(env, session);
48
+ if (result.status !== 'ok')
49
+ return null;
50
+ return result.sources.map((s) => ({ slug: s.slug, roles: s.roles }));
51
+ }
52
+ catch (_a) {
53
+ return null;
54
+ }
30
55
  }
31
56
  //# sourceMappingURL=whoami.js.map
@@ -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;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"]}
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;AAGzB,OAAO,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AASpD;;;;;;;;;;;;;;;;GAgBG;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,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AE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACvE,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import {\n requireSession,\n resolveAuthEnvironment,\n resolveIdentity,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport type { ExitCode } from '../exit-codes';\nimport { fetchSeatsWithOneRefresh } from '../seats';\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 *\n * `seats` is a best-effort add-on from the same source-visibility endpoint\n * `ekanos sources` uses, compacted to slug+roles. Its failure — network, MFA,\n * a deployment that predates the route — must never turn a working `whoami`\n * into a failing one, so any error here degrades to `seats: null` rather than\n * propagating.\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 const seats = await fetchSeatsQuietly(env, session);\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 seats,\n },\n `whoami: ${identity.email ?? identity.id} on ${env.host}.` +\n (seats\n ? seats.length > 0\n ? ` Seats: ${seats.map((s) => `${s.slug} [${s.roles.join(', ')}]`).join(', ')}.`\n : ' No source seats.'\n : ' (source seat lookup unavailable)'),\n );\n}\n\nasync function fetchSeatsQuietly(\n env: Parameters<typeof fetchSeatsWithOneRefresh>[0],\n session: Parameters<typeof fetchSeatsWithOneRefresh>[1],\n): Promise<{ slug: string; roles: string[] }[] | null> {\n try {\n const result = await fetchSeatsWithOneRefresh(env, session);\n\n if (result.status !== 'ok') return null;\n\n return result.sources.map((s) => ({ slug: s.slug, roles: s.roles }));\n } catch {\n return null;\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -7,6 +7,14 @@ export interface RunOptions {
7
7
  stderr?: WriteStream;
8
8
  env?: Record<string, string | undefined>;
9
9
  cwd?: string;
10
+ /**
11
+ * Test-only overrides for `publish`'s interactive-confirm gate — see
12
+ * `PublishArgs` in `commands/publish.ts`. Never set these from real CLI
13
+ * wiring; they exist so a test can exercise the human y/N confirm branch
14
+ * without a real terminal.
15
+ */
16
+ stdinIsTTY?: boolean;
17
+ confirm?: (question: string) => Promise<boolean>;
10
18
  }
11
19
  /**
12
20
  * The single entry point. Resolves the agent-native envelope once, dispatches
package/dist/index.js CHANGED
@@ -4,8 +4,10 @@ import { runInit } from './commands/init.js';
4
4
  import { runLogin } from './commands/login.js';
5
5
  import { runLogout } from './commands/logout.js';
6
6
  import { runPublish } from './commands/publish.js';
7
+ import { runSources } from './commands/sources.js';
7
8
  import { runStatus } from './commands/status.js';
8
9
  import { runTest } from './commands/test.js';
10
+ import { runUse } from './commands/use.js';
9
11
  import { runValidate } from './commands/validate.js';
10
12
  import { runWhoami } from './commands/whoami.js';
11
13
  import { CliContext } from './context.js';
@@ -54,6 +56,14 @@ const COMMAND_SPECS = {
54
56
  host: { type: 'string' },
55
57
  dir: { type: 'string' },
56
58
  },
59
+ sources: {
60
+ host: { type: 'string' },
61
+ dir: { type: 'string' },
62
+ },
63
+ use: {
64
+ host: { type: 'string' },
65
+ dir: { type: 'string' },
66
+ },
57
67
  publish: {
58
68
  host: { type: 'string' },
59
69
  source: { type: 'string' },
@@ -61,6 +71,10 @@ const COMMAND_SPECS = {
61
71
  yes: { type: 'boolean' },
62
72
  },
63
73
  };
74
+ /** Commands that take a positional argument, and what it means. Every other command is positional-free. */
75
+ const POSITIONAL_COMMANDS = {
76
+ use: 'source-slug',
77
+ };
64
78
  const COMMANDS = Object.keys(COMMAND_SPECS);
65
79
  const USAGE = [
66
80
  'Usage: ekanos <command> [options]',
@@ -72,17 +86,26 @@ const USAGE = [
72
86
  ' test Run the project test script via its package manager (--json)',
73
87
  ' login Authenticate against a Fusion host in a browser (--host <url>)',
74
88
  ' logout Revoke and delete the stored session (--host <url> | --all)',
75
- ' whoami Print the identity the stored session authenticates as',
89
+ ' whoami Print the identity the stored session authenticates as, plus',
90
+ ' a compact list of the sources you hold a seat on',
76
91
  " status Show login state and this project's submissions on the host",
92
+ ' sources List every source you hold a developer/admin seat on',
93
+ ' use Set this project\'s publish target ("ekanos use <source-slug>")',
77
94
  ' publish Validate, pack and submit the integration to a Fusion host',
78
95
  '',
79
- 'Host resolution (logout, whoami, status, publish):',
96
+ 'Host resolution (logout, whoami, status, sources, use, publish):',
80
97
  ' --host, else EKANOS_HOST, else the "host" field in ekanos.json, else the',
81
98
  ' sole stored login. "ekanos publish" saves host and source to ekanos.json.',
82
99
  ' "ekanos login" never reads ekanos.json for a host (--host, else',
83
100
  ' EKANOS_HOST, else the sole stored login) — it is the verb that creates',
84
101
  ' credentials, so a committed file must never choose where they go.',
85
102
  '',
103
+ 'Publish targeting (see "ekanos sources" / "ekanos use"):',
104
+ ' publish refuses (FORBIDDEN) a source you hold no seat on. With multiple',
105
+ ' seats and an implicit (ekanos.json) source, a human run asks to confirm',
106
+ ' the target; a scripted/JSON run needs --source or --yes to proceed —',
107
+ ' it never prompts and never guesses.',
108
+ '',
86
109
  'Global options:',
87
110
  ' --json Emit a single JSON envelope on stdout (auto-on when piped);',
88
111
  ' --no-json forces the human-readable form',
@@ -143,9 +166,15 @@ export async function run(argv, options = {}) {
143
166
  if (parsed.flags.help === true) {
144
167
  return emitCommandHelp(ctx, command);
145
168
  }
146
- if (parsed.positionals.length > 0) {
169
+ const positionalName = POSITIONAL_COMMANDS[command];
170
+ if (!positionalName && parsed.positionals.length > 0) {
147
171
  throw usageError(`"${command}" takes no positional arguments (got "${parsed.positionals[0]}").`, `Pass options as flags, e.g. "--dir <path>". See "ekanos ${command} --help".`);
148
172
  }
173
+ if (positionalName && parsed.positionals.length > 1) {
174
+ throw usageError(`"${command}" takes at most one positional argument (a ` +
175
+ `${positionalName}), got ${parsed.positionals.length}.`, `Pass exactly one, e.g. "ekanos ${command} <${positionalName}>". ` +
176
+ `See "ekanos ${command} --help".`);
177
+ }
149
178
  const dir = (_c = parsed.flags.dir) !== null && _c !== void 0 ? _c : cwd;
150
179
  switch (command) {
151
180
  case 'init':
@@ -194,6 +223,19 @@ export async function run(argv, options = {}) {
194
223
  dir,
195
224
  env,
196
225
  });
226
+ case 'sources':
227
+ return await runSources(ctx, {
228
+ host: parsed.flags.host,
229
+ dir,
230
+ env,
231
+ });
232
+ case 'use':
233
+ return await runUse(ctx, {
234
+ host: parsed.flags.host,
235
+ dir,
236
+ slug: parsed.positionals[0],
237
+ env,
238
+ });
197
239
  case 'publish':
198
240
  return await runPublish(ctx, {
199
241
  host: parsed.flags.host,
@@ -201,6 +243,8 @@ export async function run(argv, options = {}) {
201
243
  dir,
202
244
  yes: parsed.flags.yes === true,
203
245
  env,
246
+ stdinIsTTY: options.stdinIsTTY,
247
+ confirm: options.confirm,
204
248
  });
205
249
  default:
206
250
  // Unreachable — COMMANDS gate above — but keeps the switch total.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CA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OAAO;QAChB,CAAC,CAAC,OAAO,CAAC;AACd,CAAC;AAED,SAAS,WAAW,CAAC,GAAe;IAClC,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;IAE9B,OAAO,GAAG,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED,SAAS,QAAQ,CAAC,GAAe;IAC/B,GAAG,CAAC,kBAAkB,CAAC;QACrB,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,QAAQ;QAClB,KAAK,EAAE,KAAK;QACZ,SAAS,EAAE,UAAU;KACtB,CAAC,CAAC;IACH,OAAO,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,eAAe,CAAC,GAAe,EAAE,OAAe;;IACvD,MAAM,KAAK,GAAG,MAAA,aAAa,CAAC,OAAO,CAAC,mCAAI,EAAE,CAAC;IAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,iBAAiB,OAAO,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAC/D,GAAG,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,OAAO,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import * as fs from 'node:fs';\n\nimport { runDev } from './commands/dev';\nimport { runInit } from './commands/init';\nimport { runLogin } from './commands/login';\nimport { runLogout } from './commands/logout';\nimport { runPublish } from './commands/publish';\nimport { runStatus } from './commands/status';\nimport { runTest } from './commands/test';\nimport { runValidate } from './commands/validate';\nimport { runWhoami } from './commands/whoami';\nimport { CliContext, type WriteStream } from './context';\nimport { toCliError, usageError } from './errors';\nimport { EXIT_CODES } from './exit-codes';\nimport { type FlagSpecs, parseArgv } from './parse-argv';\n\nexport { CliContext } from './context';\nexport { EXIT_CODES, ERROR_CODES } from './exit-codes';\nexport type { ExitCode, ErrorCode } from './exit-codes';\n\nconst GLOBAL_SPECS: FlagSpecs = {\n json: { type: 'boolean' },\n help: { type: 'boolean' },\n version: { type: 'boolean' },\n};\n\nconst COMMAND_SPECS: Record<string, FlagSpecs> = {\n init: {\n slug: { type: 'string' },\n dir: { type: 'string' },\n force: { type: 'boolean' },\n yes: { type: 'boolean' },\n },\n validate: {\n dir: { type: 'string' },\n },\n dev: {\n dir: { type: 'string' },\n port: { type: 'string' },\n host: { type: 'string' },\n force: { type: 'boolean' },\n start: { type: 'boolean' },\n },\n test: {\n dir: { type: 'string' },\n },\n login: {\n host: { type: 'string' },\n force: { type: 'boolean' },\n },\n logout: {\n host: { type: 'string' },\n all: { type: 'boolean' },\n },\n whoami: {\n host: { type: 'string' },\n },\n status: {\n host: { type: 'string' },\n dir: { type: 'string' },\n },\n publish: {\n host: { type: 'string' },\n source: { type: 'string' },\n dir: { type: 'string' },\n yes: { type: 'boolean' },\n },\n};\n\nconst COMMANDS = Object.keys(COMMAND_SPECS);\n\nconst USAGE = [\n 'Usage: ekanos <command> [options]',\n '',\n 'Commands:',\n ' init Scaffold a new integration project into ./<slug> (--slug <slug> --yes)',\n ' validate Validate ekanos.json + the integration definition (--json)',\n ' dev Scaffold .ekanos/harness and run it with your own Next',\n ' test Run the project test script via its package manager (--json)',\n ' login Authenticate against a Fusion host in a browser (--host <url>)',\n ' logout Revoke and delete the stored session (--host <url> | --all)',\n ' whoami Print the identity the stored session authenticates as',\n \" status Show login state and this project's submissions on the host\",\n ' publish Validate, pack and submit the integration to a Fusion host',\n '',\n 'Host resolution (logout, whoami, status, publish):',\n ' --host, else EKANOS_HOST, else the \"host\" field in ekanos.json, else the',\n ' sole stored login. \"ekanos publish\" saves host and source to ekanos.json.',\n ' \"ekanos login\" never reads ekanos.json for a host (--host, else',\n ' EKANOS_HOST, else the sole stored login) — it is the verb that creates',\n ' credentials, so a committed file must never choose where they go.',\n '',\n 'Global options:',\n ' --json Emit a single JSON envelope on stdout (auto-on when piped);',\n ' --no-json forces the human-readable form',\n ' --version Print the CLI version',\n ' --help Show this help',\n].join('\\n');\n\nexport interface RunOptions {\n stdout?: WriteStream;\n stderr?: WriteStream;\n env?: Record<string, string | undefined>;\n cwd?: string;\n}\n\n/**\n * The single entry point. Resolves the agent-native envelope once, dispatches\n * to a verb, and guarantees exactly one terminal emission (success or error).\n * Returns the process exit code — `bin.ts` is the only place that calls\n * `process.exit`, so this stays fully testable.\n */\nexport async function run(\n argv: readonly string[],\n options: RunOptions = {},\n): Promise<number> {\n const jsonFlag = scanJsonFlag(argv);\n const ctx = new CliContext({\n jsonFlag,\n stdout: options.stdout,\n stderr: options.stderr,\n env: options.env,\n });\n const cwd = options.cwd ?? process.cwd();\n const env = options.env ?? process.env;\n\n try {\n // `--version` is global and verb-independent, so it is answered before the\n // command is even resolved: `ekanos --version` and `ekanos validate\n // --version` both report the tool's version and exit 0.\n if (scanFlagPresence(argv, 'version')) {\n return emitVersion(ctx);\n }\n\n const { command, rest } = splitCommand(argv);\n\n // Top-level help / no command.\n if (!command) {\n if (scanFlagPresence(rest, 'help') || argv.length === 0) {\n return emitHelp(ctx);\n }\n // A leading token that is not a command (e.g. `--nonsense`).\n ctx.emitClaudeCodeHint({\n tool: 'ekanos',\n error: 'unknown-command',\n commands: COMMANDS,\n usage: USAGE,\n });\n throw usageError(\n `Unknown command or flag \"${argv[0]}\".`,\n `Run one of: ${COMMANDS.join(', ')}. See \"ekanos --help\".`,\n );\n }\n\n if (!COMMANDS.includes(command)) {\n ctx.emitClaudeCodeHint({\n tool: 'ekanos',\n error: 'unknown-command',\n given: command,\n commands: COMMANDS,\n usage: USAGE,\n });\n throw usageError(\n `Unknown command \"${command}\".`,\n `Run one of: ${COMMANDS.join(', ')}. See \"ekanos --help\".`,\n );\n }\n\n const specs: FlagSpecs = { ...GLOBAL_SPECS, ...COMMAND_SPECS[command] };\n const parsed = parseArgv(rest, specs);\n\n if (parsed.flags.help === true) {\n return emitCommandHelp(ctx, command);\n }\n\n if (parsed.positionals.length > 0) {\n throw usageError(\n `\"${command}\" takes no positional arguments (got \"${parsed.positionals[0]}\").`,\n `Pass options as flags, e.g. \"--dir <path>\". See \"ekanos ${command} --help\".`,\n );\n }\n\n const dir = (parsed.flags.dir as string | undefined) ?? cwd;\n\n switch (command) {\n case 'init':\n return runInit(ctx, {\n slug: parsed.flags.slug as string | undefined,\n dir: parsed.flags.dir as string | undefined,\n cwd,\n force: parsed.flags.force === true,\n yes: parsed.flags.yes === true,\n });\n case 'validate':\n return await runValidate(ctx, { dir });\n case 'dev':\n return await runDev(ctx, {\n dir,\n port: parsed.flags.port as string | undefined,\n host: parsed.flags.host as string | undefined,\n force: parsed.flags.force === true,\n start: parsed.flags.start as boolean | undefined,\n });\n case 'test':\n return await runTest(ctx, { dir, passthrough: parsed.passthrough });\n case 'login':\n return await runLogin(ctx, {\n host: parsed.flags.host as string | undefined,\n force: parsed.flags.force === true,\n cwd,\n env,\n });\n case 'logout':\n return await runLogout(ctx, {\n host: parsed.flags.host as string | undefined,\n all: parsed.flags.all === true,\n cwd,\n env,\n });\n case 'whoami':\n return await runWhoami(ctx, {\n host: parsed.flags.host as string | undefined,\n cwd,\n env,\n });\n case 'status':\n return await runStatus(ctx, {\n host: parsed.flags.host as string | undefined,\n dir,\n env,\n });\n case 'publish':\n return await runPublish(ctx, {\n host: parsed.flags.host as string | undefined,\n source: parsed.flags.source as string | undefined,\n dir,\n yes: parsed.flags.yes === true,\n env,\n });\n default:\n // Unreachable — COMMANDS gate above — but keeps the switch total.\n throw usageError(\n `Unknown command \"${command}\".`,\n `Run one of: ${COMMANDS.join(', ')}.`,\n );\n }\n } catch (error) {\n return ctx.fail(toCliError(error));\n }\n}\n\n/**\n * Presence of `--json` (or `--no-json`) BEFORE the first `--` passthrough.\n *\n * Tri-state on purpose. `undefined` means \"the user expressed no preference\",\n * which is what lets the context fall back to inferring the mode from a\n * non-TTY stdout or CLAUDECODE. Collapsing `--no-json` to `false` here would\n * make it indistinguishable from absence, and the flag could then never turn\n * JSON mode OFF in exactly the cases it exists for.\n */\nfunction scanJsonFlag(argv: readonly string[]): boolean | undefined {\n for (const token of argv) {\n if (token === '--') break;\n if (token === '--json') return true;\n if (token === '--no-json') return false;\n }\n return undefined;\n}\n\nfunction scanFlagPresence(argv: readonly string[], name: string): boolean {\n for (const token of argv) {\n if (token === '--') break;\n if (token === `--${name}`) return true;\n }\n return false;\n}\n\n/**\n * Split argv into the command (first bare token before `--`) and the rest\n * (everything else, order preserved, including global flags and the `--`\n * passthrough). Global flags are all booleans, so any bare token is the\n * command — no value-consumption ambiguity.\n */\nfunction splitCommand(argv: readonly string[]): {\n command: string | null;\n rest: string[];\n} {\n for (let i = 0; i < argv.length; i++) {\n const token = argv[i]!;\n if (token === '--') break;\n if (!token.startsWith('-')) {\n return {\n command: token,\n rest: [...argv.slice(0, i), ...argv.slice(i + 1)],\n };\n }\n }\n return { command: null, rest: [...argv] };\n}\n\n/**\n * The CLI's own version, read from the package manifest at runtime rather than\n * baked in by the build — one source of truth, so a release bump cannot leave\n * `--version` reporting a stale number. The path resolves identically from\n * `src/index.ts` and from the emitted `dist/index.js`, both of which sit one\n * directory below the package root.\n */\nfunction readVersion(): string {\n const manifest = new URL('../package.json', import.meta.url);\n const parsed: unknown = JSON.parse(fs.readFileSync(manifest, 'utf8'));\n\n return typeof parsed === 'object' &&\n parsed !== null &&\n 'version' in parsed &&\n typeof parsed.version === 'string'\n ? parsed.version\n : '0.0.0';\n}\n\nfunction emitVersion(ctx: CliContext): number {\n const version = readVersion();\n\n return ctx.succeed({ name: 'ekanos', version }, version);\n}\n\nfunction emitHelp(ctx: CliContext): number {\n ctx.emitClaudeCodeHint({\n tool: 'ekanos',\n commands: COMMANDS,\n usage: USAGE,\n exitCodes: EXIT_CODES,\n });\n return ctx.succeed({ usage: USAGE, commands: COMMANDS }, USAGE);\n}\n\nfunction emitCommandHelp(ctx: CliContext, command: string): number {\n const specs = COMMAND_SPECS[command] ?? {};\n const flags = Object.keys(specs).map((name) => `--${name}`);\n const help = `Usage: ekanos ${command} [${flags.join('] [')}]`;\n ctx.emitClaudeCodeHint({ tool: 'ekanos', command, flags });\n return ctx.succeed({ command, flags }, help);\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAoB,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO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AC,CAAC;AAClE,CAAC;AAED,SAAS,eAAe,CAAC,GAAe,EAAE,OAAe;;IACvD,MAAM,KAAK,GAAG,MAAA,aAAa,CAAC,OAAO,CAAC,mCAAI,EAAE,CAAC;IAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,iBAAiB,OAAO,KAAK,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAC/D,GAAG,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,OAAO,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import * as fs from 'node:fs';\n\nimport { runDev } from './commands/dev';\nimport { runInit } from './commands/init';\nimport { runLogin } from './commands/login';\nimport { runLogout } from './commands/logout';\nimport { runPublish } from './commands/publish';\nimport { runSources } from './commands/sources';\nimport { runStatus } from './commands/status';\nimport { runTest } from './commands/test';\nimport { runUse } from './commands/use';\nimport { runValidate } from './commands/validate';\nimport { runWhoami } from './commands/whoami';\nimport { CliContext, type WriteStream } from './context';\nimport { toCliError, usageError } from './errors';\nimport { EXIT_CODES } from './exit-codes';\nimport { type FlagSpecs, parseArgv } from './parse-argv';\n\nexport { CliContext } from './context';\nexport { EXIT_CODES, ERROR_CODES } from './exit-codes';\nexport type { ExitCode, ErrorCode } from './exit-codes';\n\nconst GLOBAL_SPECS: FlagSpecs = {\n json: { type: 'boolean' },\n help: { type: 'boolean' },\n version: { type: 'boolean' },\n};\n\nconst COMMAND_SPECS: Record<string, FlagSpecs> = {\n init: {\n slug: { type: 'string' },\n dir: { type: 'string' },\n force: { type: 'boolean' },\n yes: { type: 'boolean' },\n },\n validate: {\n dir: { type: 'string' },\n },\n dev: {\n dir: { type: 'string' },\n port: { type: 'string' },\n host: { type: 'string' },\n force: { type: 'boolean' },\n start: { type: 'boolean' },\n },\n test: {\n dir: { type: 'string' },\n },\n login: {\n host: { type: 'string' },\n force: { type: 'boolean' },\n },\n logout: {\n host: { type: 'string' },\n all: { type: 'boolean' },\n },\n whoami: {\n host: { type: 'string' },\n },\n status: {\n host: { type: 'string' },\n dir: { type: 'string' },\n },\n sources: {\n host: { type: 'string' },\n dir: { type: 'string' },\n },\n use: {\n host: { type: 'string' },\n dir: { type: 'string' },\n },\n publish: {\n host: { type: 'string' },\n source: { type: 'string' },\n dir: { type: 'string' },\n yes: { type: 'boolean' },\n },\n};\n\n/** Commands that take a positional argument, and what it means. Every other command is positional-free. */\nconst POSITIONAL_COMMANDS: Record<string, string> = {\n use: 'source-slug',\n};\n\nconst COMMANDS = Object.keys(COMMAND_SPECS);\n\nconst USAGE = [\n 'Usage: ekanos <command> [options]',\n '',\n 'Commands:',\n ' init Scaffold a new integration project into ./<slug> (--slug <slug> --yes)',\n ' validate Validate ekanos.json + the integration definition (--json)',\n ' dev Scaffold .ekanos/harness and run it with your own Next',\n ' test Run the project test script via its package manager (--json)',\n ' login Authenticate against a Fusion host in a browser (--host <url>)',\n ' logout Revoke and delete the stored session (--host <url> | --all)',\n ' whoami Print the identity the stored session authenticates as, plus',\n ' a compact list of the sources you hold a seat on',\n \" status Show login state and this project's submissions on the host\",\n ' sources List every source you hold a developer/admin seat on',\n ' use Set this project\\'s publish target (\"ekanos use <source-slug>\")',\n ' publish Validate, pack and submit the integration to a Fusion host',\n '',\n 'Host resolution (logout, whoami, status, sources, use, publish):',\n ' --host, else EKANOS_HOST, else the \"host\" field in ekanos.json, else the',\n ' sole stored login. \"ekanos publish\" saves host and source to ekanos.json.',\n ' \"ekanos login\" never reads ekanos.json for a host (--host, else',\n ' EKANOS_HOST, else the sole stored login) — it is the verb that creates',\n ' credentials, so a committed file must never choose where they go.',\n '',\n 'Publish targeting (see \"ekanos sources\" / \"ekanos use\"):',\n ' publish refuses (FORBIDDEN) a source you hold no seat on. With multiple',\n ' seats and an implicit (ekanos.json) source, a human run asks to confirm',\n ' the target; a scripted/JSON run needs --source or --yes to proceed —',\n ' it never prompts and never guesses.',\n '',\n 'Global options:',\n ' --json Emit a single JSON envelope on stdout (auto-on when piped);',\n ' --no-json forces the human-readable form',\n ' --version Print the CLI version',\n ' --help Show this help',\n].join('\\n');\n\nexport interface RunOptions {\n stdout?: WriteStream;\n stderr?: WriteStream;\n env?: Record<string, string | undefined>;\n cwd?: string;\n /**\n * Test-only overrides for `publish`'s interactive-confirm gate — see\n * `PublishArgs` in `commands/publish.ts`. Never set these from real CLI\n * wiring; they exist so a test can exercise the human y/N confirm branch\n * without a real terminal.\n */\n stdinIsTTY?: boolean;\n confirm?: (question: string) => Promise<boolean>;\n}\n\n/**\n * The single entry point. Resolves the agent-native envelope once, dispatches\n * to a verb, and guarantees exactly one terminal emission (success or error).\n * Returns the process exit code — `bin.ts` is the only place that calls\n * `process.exit`, so this stays fully testable.\n */\nexport async function run(\n argv: readonly string[],\n options: RunOptions = {},\n): Promise<number> {\n const jsonFlag = scanJsonFlag(argv);\n const ctx = new CliContext({\n jsonFlag,\n stdout: options.stdout,\n stderr: options.stderr,\n env: options.env,\n });\n const cwd = options.cwd ?? process.cwd();\n const env = options.env ?? process.env;\n\n try {\n // `--version` is global and verb-independent, so it is answered before the\n // command is even resolved: `ekanos --version` and `ekanos validate\n // --version` both report the tool's version and exit 0.\n if (scanFlagPresence(argv, 'version')) {\n return emitVersion(ctx);\n }\n\n const { command, rest } = splitCommand(argv);\n\n // Top-level help / no command.\n if (!command) {\n if (scanFlagPresence(rest, 'help') || argv.length === 0) {\n return emitHelp(ctx);\n }\n // A leading token that is not a command (e.g. `--nonsense`).\n ctx.emitClaudeCodeHint({\n tool: 'ekanos',\n error: 'unknown-command',\n commands: COMMANDS,\n usage: USAGE,\n });\n throw usageError(\n `Unknown command or flag \"${argv[0]}\".`,\n `Run one of: ${COMMANDS.join(', ')}. See \"ekanos --help\".`,\n );\n }\n\n if (!COMMANDS.includes(command)) {\n ctx.emitClaudeCodeHint({\n tool: 'ekanos',\n error: 'unknown-command',\n given: command,\n commands: COMMANDS,\n usage: USAGE,\n });\n throw usageError(\n `Unknown command \"${command}\".`,\n `Run one of: ${COMMANDS.join(', ')}. See \"ekanos --help\".`,\n );\n }\n\n const specs: FlagSpecs = { ...GLOBAL_SPECS, ...COMMAND_SPECS[command] };\n const parsed = parseArgv(rest, specs);\n\n if (parsed.flags.help === true) {\n return emitCommandHelp(ctx, command);\n }\n\n const positionalName = POSITIONAL_COMMANDS[command];\n\n if (!positionalName && parsed.positionals.length > 0) {\n throw usageError(\n `\"${command}\" takes no positional arguments (got \"${parsed.positionals[0]}\").`,\n `Pass options as flags, e.g. \"--dir <path>\". See \"ekanos ${command} --help\".`,\n );\n }\n\n if (positionalName && parsed.positionals.length > 1) {\n throw usageError(\n `\"${command}\" takes at most one positional argument (a ` +\n `${positionalName}), got ${parsed.positionals.length}.`,\n `Pass exactly one, e.g. \"ekanos ${command} <${positionalName}>\". ` +\n `See \"ekanos ${command} --help\".`,\n );\n }\n\n const dir = (parsed.flags.dir as string | undefined) ?? cwd;\n\n switch (command) {\n case 'init':\n return runInit(ctx, {\n slug: parsed.flags.slug as string | undefined,\n dir: parsed.flags.dir as string | undefined,\n cwd,\n force: parsed.flags.force === true,\n yes: parsed.flags.yes === true,\n });\n case 'validate':\n return await runValidate(ctx, { dir });\n case 'dev':\n return await runDev(ctx, {\n dir,\n port: parsed.flags.port as string | undefined,\n host: parsed.flags.host as string | undefined,\n force: parsed.flags.force === true,\n start: parsed.flags.start as boolean | undefined,\n });\n case 'test':\n return await runTest(ctx, { dir, passthrough: parsed.passthrough });\n case 'login':\n return await runLogin(ctx, {\n host: parsed.flags.host as string | undefined,\n force: parsed.flags.force === true,\n cwd,\n env,\n });\n case 'logout':\n return await runLogout(ctx, {\n host: parsed.flags.host as string | undefined,\n all: parsed.flags.all === true,\n cwd,\n env,\n });\n case 'whoami':\n return await runWhoami(ctx, {\n host: parsed.flags.host as string | undefined,\n cwd,\n env,\n });\n case 'status':\n return await runStatus(ctx, {\n host: parsed.flags.host as string | undefined,\n dir,\n env,\n });\n case 'sources':\n return await runSources(ctx, {\n host: parsed.flags.host as string | undefined,\n dir,\n env,\n });\n case 'use':\n return await runUse(ctx, {\n host: parsed.flags.host as string | undefined,\n dir,\n slug: parsed.positionals[0],\n env,\n });\n case 'publish':\n return await runPublish(ctx, {\n host: parsed.flags.host as string | undefined,\n source: parsed.flags.source as string | undefined,\n dir,\n yes: parsed.flags.yes === true,\n env,\n stdinIsTTY: options.stdinIsTTY,\n confirm: options.confirm,\n });\n default:\n // Unreachable — COMMANDS gate above — but keeps the switch total.\n throw usageError(\n `Unknown command \"${command}\".`,\n `Run one of: ${COMMANDS.join(', ')}.`,\n );\n }\n } catch (error) {\n return ctx.fail(toCliError(error));\n }\n}\n\n/**\n * Presence of `--json` (or `--no-json`) BEFORE the first `--` passthrough.\n *\n * Tri-state on purpose. `undefined` means \"the user expressed no preference\",\n * which is what lets the context fall back to inferring the mode from a\n * non-TTY stdout or CLAUDECODE. Collapsing `--no-json` to `false` here would\n * make it indistinguishable from absence, and the flag could then never turn\n * JSON mode OFF in exactly the cases it exists for.\n */\nfunction scanJsonFlag(argv: readonly string[]): boolean | undefined {\n for (const token of argv) {\n if (token === '--') break;\n if (token === '--json') return true;\n if (token === '--no-json') return false;\n }\n return undefined;\n}\n\nfunction scanFlagPresence(argv: readonly string[], name: string): boolean {\n for (const token of argv) {\n if (token === '--') break;\n if (token === `--${name}`) return true;\n }\n return false;\n}\n\n/**\n * Split argv into the command (first bare token before `--`) and the rest\n * (everything else, order preserved, including global flags and the `--`\n * passthrough). Global flags are all booleans, so any bare token is the\n * command — no value-consumption ambiguity.\n */\nfunction splitCommand(argv: readonly string[]): {\n command: string | null;\n rest: string[];\n} {\n for (let i = 0; i < argv.length; i++) {\n const token = argv[i]!;\n if (token === '--') break;\n if (!token.startsWith('-')) {\n return {\n command: token,\n rest: [...argv.slice(0, i), ...argv.slice(i + 1)],\n };\n }\n }\n return { command: null, rest: [...argv] };\n}\n\n/**\n * The CLI's own version, read from the package manifest at runtime rather than\n * baked in by the build — one source of truth, so a release bump cannot leave\n * `--version` reporting a stale number. The path resolves identically from\n * `src/index.ts` and from the emitted `dist/index.js`, both of which sit one\n * directory below the package root.\n */\nfunction readVersion(): string {\n const manifest = new URL('../package.json', import.meta.url);\n const parsed: unknown = JSON.parse(fs.readFileSync(manifest, 'utf8'));\n\n return typeof parsed === 'object' &&\n parsed !== null &&\n 'version' in parsed &&\n typeof parsed.version === 'string'\n ? parsed.version\n : '0.0.0';\n}\n\nfunction emitVersion(ctx: CliContext): number {\n const version = readVersion();\n\n return ctx.succeed({ name: 'ekanos', version }, version);\n}\n\nfunction emitHelp(ctx: CliContext): number {\n ctx.emitClaudeCodeHint({\n tool: 'ekanos',\n commands: COMMANDS,\n usage: USAGE,\n exitCodes: EXIT_CODES,\n });\n return ctx.succeed({ usage: USAGE, commands: COMMANDS }, USAGE);\n}\n\nfunction emitCommandHelp(ctx: CliContext, command: string): number {\n const specs = COMMAND_SPECS[command] ?? {};\n const flags = Object.keys(specs).map((name) => `--${name}`);\n const help = `Usage: ekanos ${command} [${flags.join('] [')}]`;\n ctx.emitClaudeCodeHint({ tool: 'ekanos', command, flags });\n return ctx.succeed({ command, flags }, help);\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import type { StoredSession } from './auth/credential-store.js';
2
+ import { type AuthEnvironment } from './auth/session.js';
3
+ import { type SourceSeat } from './sources-api.js';
4
+ /**
5
+ * `sources`, `use`, `publish`'s target verification, and `whoami`'s seats
6
+ * degradation all need the same thing: the caller's source-seat list, with
7
+ * the one-refresh-one-retry recovery every other verb in this CLI applies to
8
+ * a stale access token (see `resolveIdentity` in `auth/session.ts`).
9
+ * Centralized here so all four call sites share one refresh policy instead of
10
+ * four subtly different copies.
11
+ */
12
+ export type SeatsResult = {
13
+ status: 'ok';
14
+ sources: SourceSeat[];
15
+ session: StoredSession;
16
+ }
17
+ /** Unauthorized even after one refresh. */
18
+ | {
19
+ status: 'unauthorized';
20
+ };
21
+ export declare function fetchSeatsWithOneRefresh(env: AuthEnvironment, session: StoredSession): Promise<SeatsResult>;
package/dist/seats.js ADDED
@@ -0,0 +1,15 @@
1
+ import { refreshStoredSession } from './auth/session.js';
2
+ import { fetchSourceSeats } from './sources-api.js';
3
+ export async function fetchSeatsWithOneRefresh(env, session) {
4
+ const first = await fetchSourceSeats(env.host, session.accessToken);
5
+ if (first.status === 'ok') {
6
+ return { status: 'ok', sources: first.sources, session };
7
+ }
8
+ const refreshed = await refreshStoredSession(env, session);
9
+ const second = await fetchSourceSeats(env.host, refreshed.accessToken);
10
+ if (second.status === 'ok') {
11
+ return { status: 'ok', sources: second.sources, session: refreshed };
12
+ }
13
+ return { status: 'unauthorized' };
14
+ }
15
+ //# sourceMappingURL=seats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seats.js","sourceRoot":"","sources":["../src/seats.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAmB,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAelE,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,GAAoB,EACpB,OAAsB;IAEtB,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAEpE,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAC1B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;IAC3D,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;IAEvE,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QAC3B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;IACvE,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;AACpC,CAAC","sourcesContent":["import type { StoredSession } from './auth/credential-store';\nimport { type AuthEnvironment, refreshStoredSession } from './auth/session';\nimport { type SourceSeat, fetchSourceSeats } from './sources-api';\n\n/**\n * `sources`, `use`, `publish`'s target verification, and `whoami`'s seats\n * degradation all need the same thing: the caller's source-seat list, with\n * the one-refresh-one-retry recovery every other verb in this CLI applies to\n * a stale access token (see `resolveIdentity` in `auth/session.ts`).\n * Centralized here so all four call sites share one refresh policy instead of\n * four subtly different copies.\n */\nexport type SeatsResult =\n | { status: 'ok'; sources: SourceSeat[]; session: StoredSession }\n /** Unauthorized even after one refresh. */\n | { status: 'unauthorized' };\n\nexport async function fetchSeatsWithOneRefresh(\n env: AuthEnvironment,\n session: StoredSession,\n): Promise<SeatsResult> {\n const first = await fetchSourceSeats(env.host, session.accessToken);\n\n if (first.status === 'ok') {\n return { status: 'ok', sources: first.sources, session };\n }\n\n const refreshed = await refreshStoredSession(env, session);\n const second = await fetchSourceSeats(env.host, refreshed.accessToken);\n\n if (second.status === 'ok') {\n return { status: 'ok', sources: second.sources, session: refreshed };\n }\n\n return { status: 'unauthorized' };\n}\n"]}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The CLI's client for the Fusion source-seat visibility route.
3
+ *
4
+ * ---------------------------------------------------------------------------
5
+ * WIRE CONTRACT — the seam between this package and the Fusion web app.
6
+ *
7
+ * The server side lives in `apps/web/app/api/partner/sources/route.ts`. As
8
+ * with the auth routes and `publish-api.ts`, the two halves are coupled only
9
+ * by HTTP; tests stub `fetch`, never the route.
10
+ *
11
+ * GET /api/partner/sources [Authorization: Bearer <access_token>]
12
+ * → 200 { ok: true, data: { sources: [{ id, slug, name, roles }] } }
13
+ * roles is a non-empty array of "dev" | "admin", sorted; sources
14
+ * is sorted by slug. Empty array means no seats anywhere.
15
+ * → 401 { error, code: "AUTH_REQUIRED" } token absent or expired —
16
+ * refresh once and retry
17
+ * → 403 { error, code: "MFA_REQUIRED" }
18
+ * → 3xx treated as 401 (an
19
+ * auth-gated Fusion page
20
+ * answers 307)
21
+ * ---------------------------------------------------------------------------
22
+ */
23
+ export interface SourceSeat {
24
+ id: string;
25
+ slug: string;
26
+ name: string | null;
27
+ roles: string[];
28
+ }
29
+ export type FetchSourceSeatsResult = {
30
+ status: 'ok';
31
+ sources: SourceSeat[];
32
+ }
33
+ /** The bearer token did not authenticate — refresh and retry, once. */
34
+ | {
35
+ status: 'unauthorized';
36
+ };
37
+ /**
38
+ * List the sources the caller holds a seat on (any role). Authorization is
39
+ * entirely server-side (RLS on `source_memberships`): there is no client-side
40
+ * filter to get wrong here.
41
+ */
42
+ export declare function fetchSourceSeats(host: string, accessToken: string): Promise<FetchSourceSeatsResult>;
43
+ /** Guard for the "still unauthorized after one refresh" terminal case. */
44
+ export declare function stillUnauthorizedSourceSeats(host: string): never;
@@ -0,0 +1,69 @@
1
+ import { request } from './auth/fusion-api.js';
2
+ import { authRequiredError, networkError } from './errors.js';
3
+ /**
4
+ * List the sources the caller holds a seat on (any role). Authorization is
5
+ * entirely server-side (RLS on `source_memberships`): there is no client-side
6
+ * filter to get wrong here.
7
+ */
8
+ export async function fetchSourceSeats(host, accessToken) {
9
+ var _a, _b;
10
+ const response = await request(`${host}/api/partner/sources`, {
11
+ method: 'GET',
12
+ headers: {
13
+ accept: 'application/json',
14
+ authorization: `Bearer ${accessToken}`,
15
+ },
16
+ });
17
+ if (response.status === 401 || isRedirect(response.status)) {
18
+ return { status: 'unauthorized' };
19
+ }
20
+ const body = await readOptionalJson(response);
21
+ if (response.status === 403) {
22
+ throw authRequiredError((_a = str(body.error)) !== null && _a !== void 0 ? _a : `${host} requires multi-factor authentication for this account.`, `Complete MFA in the browser, then run "ekanos login" again.`);
23
+ }
24
+ if (!response.ok) {
25
+ throw networkError(`${host}/api/partner/sources responded ${response.status}.`, response.status >= 500
26
+ ? `The Fusion deployment returned a server error. Retry shortly; if ` +
27
+ `it persists, report it with the status code.`
28
+ : `Confirm the host is a Fusion deployment running a build that ` +
29
+ `includes the partner sources route.`);
30
+ }
31
+ const data = ((_b = body.data) !== null && _b !== void 0 ? _b : {});
32
+ const rows = Array.isArray(data.sources) ? data.sources : [];
33
+ const sources = rows
34
+ .filter((row) => typeof row === 'object' && row !== null)
35
+ .map((row) => {
36
+ var _a, _b;
37
+ return ({
38
+ id: (_a = str(row.id)) !== null && _a !== void 0 ? _a : '',
39
+ slug: (_b = str(row.slug)) !== null && _b !== void 0 ? _b : '',
40
+ name: str(row.name),
41
+ roles: Array.isArray(row.roles)
42
+ ? row.roles.filter((role) => typeof role === 'string')
43
+ : [],
44
+ });
45
+ });
46
+ return { status: 'ok', sources };
47
+ }
48
+ /** Guard for the "still unauthorized after one refresh" terminal case. */
49
+ export function stillUnauthorizedSourceSeats(host) {
50
+ throw authRequiredError(`The session for ${host} could not authorize the source seat lookup.`, `Run "ekanos login --host ${host}" and retry.`);
51
+ }
52
+ async function readOptionalJson(response) {
53
+ try {
54
+ const parsed = await response.json();
55
+ return typeof parsed === 'object' && parsed !== null
56
+ ? parsed
57
+ : {};
58
+ }
59
+ catch (_a) {
60
+ return {};
61
+ }
62
+ }
63
+ function isRedirect(status) {
64
+ return status >= 300 && status < 400;
65
+ }
66
+ function str(value) {
67
+ return typeof value === 'string' && value.length > 0 ? value : null;
68
+ }
69
+ //# sourceMappingURL=sources-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sources-api.js","sourceRoot":"","sources":["../src/sources-api.ts"],"names":[],"mapp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C;AACH,CAAC;AAED,SAAS,UAAU,CAAC,MAAc;IAChC,OAAO,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,CAAC;AACvC,CAAC;AAED,SAAS,GAAG,CAAC,KAAc;IACzB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACtE,CAAC","sourcesContent":["import { request } from './auth/fusion-api';\nimport { authRequiredError, networkError } from './errors';\n\n/**\n * The CLI's client for the Fusion source-seat visibility route.\n *\n * ---------------------------------------------------------------------------\n * WIRE CONTRACT — the seam between this package and the Fusion web app.\n *\n * The server side lives in `apps/web/app/api/partner/sources/route.ts`. As\n * with the auth routes and `publish-api.ts`, the two halves are coupled only\n * by HTTP; tests stub `fetch`, never the route.\n *\n * GET /api/partner/sources [Authorization: Bearer <access_token>]\n * → 200 { ok: true, data: { sources: [{ id, slug, name, roles }] } }\n * roles is a non-empty array of \"dev\" | \"admin\", sorted; sources\n * is sorted by slug. Empty array means no seats anywhere.\n * → 401 { error, code: \"AUTH_REQUIRED\" } token absent or expired —\n * refresh once and retry\n * → 403 { error, code: \"MFA_REQUIRED\" }\n * → 3xx treated as 401 (an\n * auth-gated Fusion page\n * answers 307)\n * ---------------------------------------------------------------------------\n */\n\nexport interface SourceSeat {\n id: string;\n slug: string;\n name: string | null;\n roles: string[];\n}\n\nexport type FetchSourceSeatsResult =\n | { status: 'ok'; sources: SourceSeat[] }\n /** The bearer token did not authenticate — refresh and retry, once. */\n | { status: 'unauthorized' };\n\n/**\n * List the sources the caller holds a seat on (any role). Authorization is\n * entirely server-side (RLS on `source_memberships`): there is no client-side\n * filter to get wrong here.\n */\nexport async function fetchSourceSeats(\n host: string,\n accessToken: string,\n): Promise<FetchSourceSeatsResult> {\n const response = await request(`${host}/api/partner/sources`, {\n method: 'GET',\n headers: {\n accept: 'application/json',\n authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (response.status === 401 || isRedirect(response.status)) {\n return { status: 'unauthorized' };\n }\n\n const body = await readOptionalJson(response);\n\n if (response.status === 403) {\n throw authRequiredError(\n str(body.error) ??\n `${host} requires multi-factor authentication for this account.`,\n `Complete MFA in the browser, then run \"ekanos login\" again.`,\n );\n }\n\n if (!response.ok) {\n throw networkError(\n `${host}/api/partner/sources responded ${response.status}.`,\n response.status >= 500\n ? `The Fusion deployment returned a server error. Retry shortly; if ` +\n `it persists, report it with the status code.`\n : `Confirm the host is a Fusion deployment running a build that ` +\n `includes the partner sources route.`,\n );\n }\n\n const data = (body.data ?? {}) as Record<string, unknown>;\n const rows = Array.isArray(data.sources) ? data.sources : [];\n\n const sources = rows\n .filter(\n (row): row is Record<string, unknown> =>\n typeof row === 'object' && row !== null,\n )\n .map((row) => ({\n id: str(row.id) ?? '',\n slug: str(row.slug) ?? '',\n name: str(row.name),\n roles: Array.isArray(row.roles)\n ? row.roles.filter((role): role is string => typeof role === 'string')\n : [],\n }));\n\n return { status: 'ok', sources };\n}\n\n/** Guard for the \"still unauthorized after one refresh\" terminal case. */\nexport function stillUnauthorizedSourceSeats(host: string): never {\n throw authRequiredError(\n `The session for ${host} could not authorize the source seat lookup.`,\n `Run \"ekanos login --host ${host}\" and retry.`,\n );\n}\n\nasync function readOptionalJson(\n response: Response,\n): Promise<Record<string, unknown>> {\n try {\n const parsed: unknown = await response.json();\n\n return typeof parsed === 'object' && parsed !== null\n ? (parsed as Record<string, unknown>)\n : {};\n } catch {\n return {};\n }\n}\n\nfunction isRedirect(status: number): boolean {\n return status >= 300 && status < 400;\n}\n\nfunction str(value: unknown): string | null {\n return typeof value === 'string' && value.length > 0 ? value : null;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekanos/cli",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "The Ekanos partner toolchain CLI: scaffold, validate, and test a Fusion integration against the published @ekanos packages. Agent-native — every verb speaks JSON with a stable exit-code taxonomy.",
6
6
  "license": "MIT",