@ekanos/cli 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +1 -0
  2. package/dist/commands/agents-edit.d.ts +49 -0
  3. package/dist/commands/agents-edit.js +385 -0
  4. package/dist/commands/agents-edit.js.map +1 -0
  5. package/dist/commands/agents.d.ts +24 -1
  6. package/dist/commands/agents.js +117 -8
  7. package/dist/commands/agents.js.map +1 -1
  8. package/dist/commands/apps.d.ts +6 -2
  9. package/dist/commands/apps.js +249 -4
  10. package/dist/commands/apps.js.map +1 -1
  11. package/dist/commands/reviewers.d.ts +21 -0
  12. package/dist/commands/reviewers.js +162 -0
  13. package/dist/commands/reviewers.js.map +1 -0
  14. package/dist/commands/routes.d.ts +23 -0
  15. package/dist/commands/routes.js +277 -0
  16. package/dist/commands/routes.js.map +1 -0
  17. package/dist/commands/runs.d.ts +42 -0
  18. package/dist/commands/runs.js +362 -0
  19. package/dist/commands/runs.js.map +1 -0
  20. package/dist/commands/skills.d.ts +60 -0
  21. package/dist/commands/skills.js +397 -0
  22. package/dist/commands/skills.js.map +1 -0
  23. package/dist/commands/team-agents-agents.d.ts +9 -0
  24. package/dist/commands/team-agents-agents.js +188 -0
  25. package/dist/commands/team-agents-agents.js.map +1 -0
  26. package/dist/commands/team-agents-mcp.d.ts +4 -0
  27. package/dist/commands/team-agents-mcp.js +218 -0
  28. package/dist/commands/team-agents-mcp.js.map +1 -0
  29. package/dist/commands/team-agents-triggers.d.ts +12 -0
  30. package/dist/commands/team-agents-triggers.js +251 -0
  31. package/dist/commands/team-agents-triggers.js.map +1 -0
  32. package/dist/commands/team-agents.d.ts +31 -0
  33. package/dist/commands/team-agents.js +71 -0
  34. package/dist/commands/team-agents.js.map +1 -0
  35. package/dist/commands/teams-onboard.d.ts +51 -0
  36. package/dist/commands/teams-onboard.js +261 -0
  37. package/dist/commands/teams-onboard.js.map +1 -0
  38. package/dist/commands/teams.d.ts +16 -1
  39. package/dist/commands/teams.js +22 -3
  40. package/dist/commands/teams.js.map +1 -1
  41. package/dist/connections-api.d.ts +125 -0
  42. package/dist/connections-api.js +156 -0
  43. package/dist/connections-api.js.map +1 -0
  44. package/dist/index.js +226 -6
  45. package/dist/index.js.map +1 -1
  46. package/dist/reviewers-api.d.ts +33 -0
  47. package/dist/reviewers-api.js +81 -0
  48. package/dist/reviewers-api.js.map +1 -0
  49. package/dist/routes-api.d.ts +105 -0
  50. package/dist/routes-api.js +147 -0
  51. package/dist/routes-api.js.map +1 -0
  52. package/dist/runs-api.d.ts +34 -0
  53. package/dist/runs-api.js +112 -0
  54. package/dist/runs-api.js.map +1 -0
  55. package/dist/skills-api.d.ts +28 -0
  56. package/dist/skills-api.js +104 -0
  57. package/dist/skills-api.js.map +1 -0
  58. package/dist/teams-api.d.ts +45 -3
  59. package/dist/teams-api.js +72 -3
  60. package/dist/teams-api.js.map +1 -1
  61. package/package.json +2 -2
  62. package/templates/package.json.tmpl +4 -4
  63. package/templates/skills/build-agent/SKILL.md +94 -10
  64. package/templates/skills/build-agent/references/agent-json.md +85 -4
  65. package/templates/skills/build-agent/references/rollout.md +9 -1
  66. package/templates/skills/build-agent/references/set-up-an-integration.md +59 -3
  67. package/templates/skills/build-agent/references/skills.md +81 -0
  68. package/templates/skills/build-agent/references/triggers.md +25 -5
  69. package/templates/skills/ekanos-platform/SKILL.md +116 -5
@@ -1,9 +1,16 @@
1
1
  import { setProviderApp, showProviderApp, } from '../apps-api.js';
2
2
  import { refreshStoredSession, requireSession, resolveAuthEnvironment, } from '../auth/session.js';
3
- import { authRequiredError, usageError, validationError } from '../errors.js';
3
+ import { deleteConnection, listConnections, showConnection, startConnection, } from '../connections-api.js';
4
+ import { authRequiredError, invalidStateError, usageError, validationError, } from '../errors.js';
4
5
  import { resolveSourceTarget } from '../source-target.js';
5
6
  import { promptYesNo } from './publish.js';
6
- export const APPS_SUBCOMMANDS = ['show', 'set'];
7
+ export const APPS_SUBCOMMANDS = [
8
+ 'show',
9
+ 'set',
10
+ 'list',
11
+ 'connect',
12
+ 'disconnect',
13
+ ];
7
14
  /**
8
15
  * `apps` — a Source's provider apps: the OAuth client an integration signs
9
16
  * every team in through (Linear's, say). `show` says whether the Source has
@@ -15,7 +22,12 @@ export const APPS_SUBCOMMANDS = ['show', 'set'];
15
22
  export async function runApps(ctx, args) {
16
23
  var _a, _b, _c;
17
24
  const subcommand = parseSubcommand(args.subcommand);
25
+ if (subcommand === 'list')
26
+ return runList(ctx, args);
18
27
  const product = requireProduct(args.product, subcommand);
28
+ if (subcommand === 'connect' || subcommand === 'disconnect') {
29
+ return runConnection(ctx, args, subcommand, product);
30
+ }
19
31
  if (subcommand === 'set' && !canPrompt(ctx, args)) {
20
32
  throw usageError('apps set takes the client secret at a terminal, never in a script or an agent run.', `Run it yourself in your terminal: npx @ekanos/cli apps set ${product}${args.source ? ` --source ${args.source}` : ''}`);
21
33
  }
@@ -25,10 +37,10 @@ export async function runApps(ctx, args) {
25
37
  const resolved = await resolveSourceTarget(env, requireSession(env.store, env.host), args);
26
38
  const client = new AppsClient(env, resolved.session);
27
39
  const source = resolved.source;
28
- const status = await client.call((token) => showProviderApp(env.host, token, source, product));
29
40
  if (subcommand === 'show') {
30
- return ctx.succeed(Object.assign({ host: env.host }, status), summary(ctx, status));
41
+ return showApp(ctx, env.host, client, source, product);
31
42
  }
43
+ const status = await client.call((token) => showProviderApp(env.host, token, source, product));
32
44
  ctx.log(walkthrough(status).join('\n'));
33
45
  if (status.configured) {
34
46
  const replace = await ((_a = args.confirm) !== null && _a !== void 0 ? _a : promptYesNo)(`${status.source.slug} already has ${status.product.name} credentials. Replace them? [y/N]`);
@@ -117,6 +129,228 @@ function summary(ctx, status) {
117
129
  ]),
118
130
  ].join('\n');
119
131
  }
132
+ /**
133
+ * `apps show <product>`: the Source provider app, and — for an integration
134
+ * that supports one — the Source connection (plan 241). A `teamApp`
135
+ * integration (Zendesk) has no provider app but can have a Source
136
+ * connection, so either half may be absent.
137
+ */
138
+ async function showApp(ctx, host, client, source, product) {
139
+ const [app, connection] = await Promise.all([
140
+ client
141
+ .call((token) => showProviderApp(host, token, source, product))
142
+ .then((status) => ({ ok: true, status }), (error) => ({ ok: false, error })),
143
+ // A host without the connections routes (before plan 241), or one that
144
+ // refuses, leaves `show` exactly as it was: the provider app alone.
145
+ client
146
+ .connection((token) => showConnection(host, token, source, product))
147
+ .catch(() => ({ status: 'unavailable' })),
148
+ ]);
149
+ if (!app.ok && connection.status !== 'ok')
150
+ throw app.error;
151
+ const parts = [];
152
+ if (app.ok)
153
+ parts.push(summary(ctx, app.status));
154
+ if (connection.status === 'ok') {
155
+ parts.push(connectionSummary(ctx, connection.data.connection, {
156
+ sourceSlug: connection.data.source.slug,
157
+ callbackUrls: connection.data.callbackUrls,
158
+ }));
159
+ }
160
+ return ctx.succeed(Object.assign(Object.assign({ host }, (app.ok ? app.status : {})), (connection.status === 'ok'
161
+ ? {
162
+ sourceConnection: connection.data.connection,
163
+ sourceConnectionCallbackUrls: connection.data.callbackUrls,
164
+ }
165
+ : {})), parts.join('\n'));
166
+ }
167
+ /** `apps list`: every integration the Source can connect once, with status. */
168
+ async function runList(ctx, args) {
169
+ const { env, client, source } = await openClient(ctx, args);
170
+ const result = await client.connection((token) => listConnections(env.host, token, source));
171
+ if (result.status !== 'ok') {
172
+ throw invalidStateError('The host could not list the connections.', 'Retry shortly.');
173
+ }
174
+ const { connections } = result.data;
175
+ const rows = connections.map((connection) => [
176
+ `${connection.name} (${connection.slug})`,
177
+ connectionState(connection),
178
+ ]);
179
+ return ctx.succeed(Object.assign({ host: env.host }, result.data), connections.length === 0
180
+ ? ctx.ui.hint(`No integration on ${result.data.source.slug} supports one connection for the whole Source yet.`)
181
+ : ctx.ui.result({
182
+ title: `Source connections on ${result.data.source.slug}`,
183
+ rows,
184
+ }));
185
+ }
186
+ function connectionState(connection) {
187
+ if (connection.connected) {
188
+ return [
189
+ 'connected',
190
+ connection.connectedAt ? ` ${connection.connectedAt}` : '',
191
+ connection.connectedBy ? ` by ${connection.connectedBy}` : '',
192
+ ].join('');
193
+ }
194
+ return connection.missing.length > 0
195
+ ? `not connected — app fields missing: ${connection.missing.join(', ')}`
196
+ : 'not connected';
197
+ }
198
+ /**
199
+ * `apps connect <product>`: connect the integration ONCE for the whole Source,
200
+ * for the Source's provided agents whose template says `owner: "source"`.
201
+ * Asks for any missing app fields at the terminal (secrets hidden, never from
202
+ * a flag), prints the provider's consent URL, then waits until the browser
203
+ * finishes. `apps disconnect <product>` removes it.
204
+ */
205
+ async function runConnection(ctx, args, subcommand, product) {
206
+ const { env, client, source } = await openClient(ctx, args);
207
+ if (subcommand === 'disconnect') {
208
+ return disconnect(ctx, args, client, env.host, source, product);
209
+ }
210
+ const shown = await client.connection((token) => showConnection(env.host, token, source, product));
211
+ if (shown.status === 'unsupported') {
212
+ throw invalidStateError(shown.message, `Each team connects ${product} itself, from the team's Integrations page.`);
213
+ }
214
+ if (shown.status !== 'ok') {
215
+ throw invalidStateError('The host could not read the connection.', 'Retry shortly.');
216
+ }
217
+ const current = shown.data.connection;
218
+ if (current.app === 'fields') {
219
+ ctx.log([
220
+ `${current.name} app for ${shown.data.source.slug} (one for the whole Source)`,
221
+ ` Register this redirect URL in the app: ${shown.data.callbackUrls.join(', ')}`,
222
+ ].join('\n'));
223
+ }
224
+ const fields = await askFields(ctx, args, current, product);
225
+ const started = await client.connection((token) => startConnection(env.host, token, Object.assign({ source,
226
+ product }, (Object.keys(fields).length > 0 ? { fields } : {}))));
227
+ if (started.status === 'not-configured') {
228
+ throw validationError(`${current.name} is not set up for the Source yet — missing: ${started.missing.join(', ')}.`, current.app === 'source-app'
229
+ ? `Run "ekanos apps set ${product}" to enter the Source's app first.`
230
+ : `Run "ekanos apps connect ${product}" again and fill every field.`);
231
+ }
232
+ if (started.status !== 'ok') {
233
+ throw invalidStateError('The host could not start the connection.', 'Retry shortly.');
234
+ }
235
+ ctx.log([
236
+ `Open this link and approve ${current.name} as the account the Source's agents should act as:`,
237
+ ` ${started.data.authorizeUrl}`,
238
+ ].join('\n'));
239
+ if (args.noWait || ctx.jsonMode) {
240
+ return ctx.succeed({
241
+ host: env.host,
242
+ product,
243
+ authorizeUrl: started.data.authorizeUrl,
244
+ callbackUrl: started.data.callbackUrl,
245
+ connected: false,
246
+ }, ctx.ui.hint(`Then check with "ekanos apps show ${product}".`));
247
+ }
248
+ const deadline = Date.now() + 10 * 60 * 1000;
249
+ const before = current.connectedAt;
250
+ while (Date.now() < deadline) {
251
+ await new Promise((resolve) => { var _a; return setTimeout(resolve, (_a = args.pollDelayMs) !== null && _a !== void 0 ? _a : 3000); });
252
+ const polled = await client.connection((token) => showConnection(env.host, token, source, product));
253
+ if (polled.status === 'ok' &&
254
+ polled.data.connection.connected &&
255
+ polled.data.connection.connectedAt !== before) {
256
+ return ctx.succeed({ host: env.host, product, connection: polled.data.connection }, connectionSummary(ctx, polled.data.connection, {
257
+ sourceSlug: polled.data.source.slug,
258
+ callbackUrls: polled.data.callbackUrls,
259
+ }));
260
+ }
261
+ }
262
+ throw validationError('The connection did not finish within ten minutes.', `Run "ekanos apps connect ${product}" again for a fresh link.`);
263
+ }
264
+ async function askFields(ctx, args, current, product) {
265
+ var _a, _b;
266
+ const toAsk = current.fields.filter((field) => !field.set || current.missing.includes(field.name));
267
+ if (toAsk.length === 0)
268
+ return {};
269
+ if (!canPrompt(ctx, args)) {
270
+ throw usageError(`${current.name} needs its app fields entered for the Source: ${toAsk.map((field) => field.label).join(', ')}.`, `Run it yourself in your terminal: npx @ekanos/cli apps connect ${product}${args.source ? ` --source ${args.source}` : ''}`);
271
+ }
272
+ const fields = {};
273
+ for (const field of toAsk) {
274
+ const question = field.sensitive
275
+ ? `${field.label} (hidden): `
276
+ : `${field.label}: `;
277
+ const value = (await (field.sensitive
278
+ ? ((_a = args.askSecret) !== null && _a !== void 0 ? _a : promptHidden)
279
+ : ((_b = args.ask) !== null && _b !== void 0 ? _b : promptLine))(question)).trim();
280
+ if (value)
281
+ fields[field.name] = value;
282
+ }
283
+ return fields;
284
+ }
285
+ async function disconnect(ctx, args, client, host, source, product) {
286
+ var _a;
287
+ if (canPrompt(ctx, args)) {
288
+ const sure = await ((_a = args.confirm) !== null && _a !== void 0 ? _a : promptYesNo)(`Disconnect ${product} for every team's provided agents on ${source}? [y/N]`);
289
+ if (!sure) {
290
+ throw validationError('Nothing was changed.', `Run "ekanos apps show ${product}" to see the current state.`);
291
+ }
292
+ }
293
+ const result = await client.connection((token) => deleteConnection(host, token, source, product));
294
+ if (result.status === 'unsupported') {
295
+ throw invalidStateError(result.message, `Each team connects ${product} itself, from the team's Integrations page.`);
296
+ }
297
+ if (result.status !== 'ok') {
298
+ throw invalidStateError('The host could not disconnect.', 'Retry shortly.');
299
+ }
300
+ return ctx.succeed(Object.assign({ host, product }, result.data), ctx.ui.result({
301
+ title: result.data.removed
302
+ ? `Disconnected ${product} for ${source}`
303
+ : `${product} was not connected for ${source}`,
304
+ rows: [
305
+ [
306
+ 'Provided agents',
307
+ 'their tools for this product stop until you connect again',
308
+ ],
309
+ ],
310
+ }));
311
+ }
312
+ function connectionSummary(ctx, connection, meta) {
313
+ const rows = [
314
+ ['Source', meta.sourceSlug],
315
+ ['Connected', connectionState(connection)],
316
+ ...(connection.scope ? [['Scope', connection.scope]] : []),
317
+ ...(connection.fields.length > 0
318
+ ? [
319
+ [
320
+ 'App fields',
321
+ connection.fields.map((field) => { var _a; return `${field.label}: ${field.set ? ((_a = field.value) !== null && _a !== void 0 ? _a : 'set') : 'missing'}`; }),
322
+ ],
323
+ ]
324
+ : []),
325
+ ['Redirect URL', meta.callbackUrls],
326
+ [
327
+ 'Used by',
328
+ 'provided agents whose template says connections.<product>.owner: "source", in every team',
329
+ ],
330
+ ];
331
+ return [
332
+ ctx.ui.result({
333
+ title: `${connection.name} — one connection for the whole Source`,
334
+ rows,
335
+ }),
336
+ ...(connection.connected
337
+ ? []
338
+ : [
339
+ ctx.ui.hint(`Run "ekanos apps connect ${connection.slug}" in your terminal to connect it.`),
340
+ ]),
341
+ ].join('\n');
342
+ }
343
+ async function openClient(ctx, args) {
344
+ const env = resolveAuthEnvironment(ctx, args.host, args.env, {
345
+ projectDir: args.dir,
346
+ });
347
+ const resolved = await resolveSourceTarget(env, requireSession(env.store, env.host), args);
348
+ return {
349
+ env,
350
+ client: new AppsClient(env, resolved.session),
351
+ source: resolved.source,
352
+ };
353
+ }
120
354
  class AppsClient {
121
355
  constructor(env, session) {
122
356
  this.env = env;
@@ -132,6 +366,17 @@ class AppsClient {
132
366
  return result.data;
133
367
  throw authRequiredError(`The session for ${this.env.host} could not authorize the apps call.`, `Run "ekanos login --host ${this.env.host}" and retry.`);
134
368
  }
369
+ /** As `call`, for the connections client, whose 409s are answers. */
370
+ async connection(send) {
371
+ let result = await send(this.session.accessToken);
372
+ if (result.status === 'unauthorized') {
373
+ this.session = await refreshStoredSession(this.env, this.session);
374
+ result = await send(this.session.accessToken);
375
+ }
376
+ if (result.status !== 'unauthorized')
377
+ return result;
378
+ throw authRequiredError(`The session for ${this.env.host} could not authorize the connections call.`, `Run "ekanos login --host ${this.env.host}" and retry.`);
379
+ }
135
380
  }
136
381
  function canPrompt(ctx, args) {
137
382
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"apps.js","sourceRoot":"","sources":["../../src/commands/apps.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,cAAc,EACd,eAAe,GAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EAEL,oBAAoB,EACpB,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,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EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC;QAClC,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IACH,8EAA8E;IAC7E,EAA4D,CAAC,cAAc;QAC1E,GAAG,EAAE,GAAE,CAAC,CAAC;IACX,IAAI,CAAC;QACH,OAAO,MAAM,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,EAAE;YAC3C,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,wEAAwE;AACxE,SAAS,YAAY,CAAC,MAAyB;;IAC7C,OAAO,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,MAAM;QAChC,CAAC,CAAC,MAAM,CAAC,YAAY;QACrB,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import type { ProviderAppStatus } from '@ekanos/integration-schema';\n\nimport {\n type AppsApiResult,\n setProviderApp,\n showProviderApp,\n} from '../apps-api';\nimport type { StoredSession } from '../auth/credential-store';\nimport {\n type AuthEnvironment,\n refreshStoredSession,\n requireSession,\n resolveAuthEnvironment,\n} from '../auth/session';\nimport type { CliContext } from '../context';\nimport { authRequiredError, usageError, validationError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { resolveSourceTarget } from '../source-target';\nimport type { ResultRow } from '../ui';\nimport { promptYesNo } from './publish';\n\nexport const APPS_SUBCOMMANDS = ['show', 'set'] as const;\ntype AppsSubcommand = (typeof APPS_SUBCOMMANDS)[number];\n\nexport interface AppsArgs {\n host?: string;\n source?: string;\n subcommand?: string;\n product?: string;\n dir: string;\n env: Record<string, string | undefined>;\n stdinIsTTY?: boolean;\n /** Test seams for the questions `set` asks. */\n ask?: (question: string) => Promise<string>;\n askSecret?: (question: string) => Promise<string>;\n confirm?: (question: string) => Promise<boolean>;\n}\n\n/**\n * `apps` — a Source's provider apps: the OAuth client an integration signs\n * every team in through (Linear's, say). `show` says whether the Source has\n * one and which callback URL to register; `set` takes the client id and\n * secret from the Source admin at the terminal — never from a flag, a file\n * or a non-interactive run, so an agent driving the CLI never handles the\n * secret.\n */\nexport async function runApps(\n ctx: CliContext,\n args: AppsArgs,\n): Promise<ExitCode> {\n const subcommand = parseSubcommand(args.subcommand);\n const product = requireProduct(args.product, subcommand);\n\n if (subcommand === 'set' && !canPrompt(ctx, args)) {\n throw usageError(\n 'apps set takes the client secret at a terminal, never in a script or an agent run.',\n `Run it yourself in your terminal: npx @ekanos/cli apps set ${product}${args.source ? ` --source ${args.source}` : ''}`,\n );\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const resolved = await resolveSourceTarget(\n env,\n requireSession(env.store, env.host),\n args,\n );\n const client = new AppsClient(env, resolved.session);\n const source = resolved.source;\n\n const status = await client.call((token) =>\n showProviderApp(env.host, token, source, product),\n );\n\n if (subcommand === 'show') {\n return ctx.succeed({ host: env.host, ...status }, summary(ctx, status));\n }\n\n ctx.log(walkthrough(status).join('\\n'));\n if (status.configured) {\n const replace = await (args.confirm ?? promptYesNo)(\n `${status.source.slug} already has ${status.product.name} credentials. Replace them? [y/N]`,\n );\n if (!replace) {\n throw validationError(\n 'Nothing was changed.',\n `Run \"ekanos apps show ${product}\" to see the current state.`,\n );\n }\n }\n\n const clientId = (await (args.ask ?? promptLine)('Client ID: ')).trim();\n const clientSecret = (\n await (args.askSecret ?? promptHidden)('Client secret (hidden): ')\n ).trim();\n if (!clientId || !clientSecret) {\n throw validationError(\n 'Both the client ID and the client secret are needed.',\n `Run \"ekanos apps set ${product}\" again.`,\n );\n }\n\n const result = await client.call((token) =>\n setProviderApp(env.host, token, {\n source,\n product,\n clientId,\n clientSecret,\n }),\n );\n return ctx.succeed(\n { host: env.host, ...result },\n ctx.ui.result({\n title: result.replaced\n ? `Replaced the ${result.product.name} app`\n : `Set up the ${result.product.name} app`,\n rows: [\n ['Source', result.source.slug],\n ['Teams can connect', result.configured ? 'yes' : 'not yet'],\n ['Callback URLs', callbackUrls(result)],\n ],\n }),\n );\n}\n\n/**\n * How to create the app: the integration's own steps (`oauth.setup`, with the\n * callback URL filled in) when it declares them, else the generic three.\n */\nexport function walkthrough(status: ProviderAppStatus): string[] {\n const name = status.product.name;\n const lines = [`${name} app for ${status.source.slug}`];\n if (status.setup?.consoleUrl) {\n lines.push(` Open: ${status.setup.consoleUrl}`);\n }\n const steps = status.setup?.steps.length\n ? [\n ...status.setup.steps,\n `Check the app lists exactly: ${callbackUrls(status).join(', ')}`,\n ]\n : [\n `In ${name}, create an OAuth app (or open the one you use).`,\n `Register exactly these callback URLs: ${callbackUrls(status).join(', ')}`,\n ];\n steps.push(\n \"Enter its client ID and secret below. The secret is stored in Ekanos's vault and never shown again.\",\n );\n lines.push(...steps.map((step, index) => ` ${index + 1}. ${step}`));\n if (status.setup?.guideUrl) lines.push(` Guide: ${status.setup.guideUrl}`);\n return lines;\n}\n\nfunction summary(ctx: CliContext, status: ProviderAppStatus): string {\n const rows: ResultRow[] = [\n ['Source', status.source.slug],\n ...(status.setup\n ? ([\n [\n 'How to create it',\n [\n ...(status.setup.consoleUrl\n ? [`Open ${status.setup.consoleUrl}`]\n : []),\n ...status.setup.steps.map(\n (step, index) => `${index + 1}. ${step}`,\n ),\n ],\n ],\n ] as const)\n : []),\n [\n 'Set up',\n status.configured\n ? 'yes — teams can connect'\n : 'no — no team can connect yet',\n ],\n ['Callback URLs', callbackUrls(status)],\n ];\n return [\n ctx.ui.result({ title: `${status.product.name} app`, rows }),\n ...(status.configured\n ? []\n : [\n ctx.ui.hint(\n `Run \"ekanos apps set ${status.product.slug}\" in your terminal to enter its credentials.`,\n ),\n ]),\n ].join('\\n');\n}\n\nclass AppsClient {\n constructor(\n private readonly env: AuthEnvironment,\n private session: StoredSession,\n ) {}\n\n async call<T>(\n send: (accessToken: string) => Promise<AppsApiResult<T>>,\n ): Promise<T> {\n let result = await send(this.session.accessToken);\n if (result.status === 'unauthorized') {\n this.session = await refreshStoredSession(this.env, this.session);\n result = await send(this.session.accessToken);\n }\n if (result.status === 'ok') return result.data;\n throw authRequiredError(\n `The session for ${this.env.host} could not authorize the apps call.`,\n `Run \"ekanos login --host ${this.env.host}\" and retry.`,\n );\n }\n}\n\nfunction canPrompt(ctx: CliContext, args: AppsArgs): boolean {\n return !ctx.jsonMode && (args.stdinIsTTY ?? process.stdin.isTTY === true);\n}\n\nfunction parseSubcommand(value: string | undefined): AppsSubcommand {\n const match = APPS_SUBCOMMANDS.find((name) => name === value);\n if (match) return match;\n throw usageError(\n value ? `Unknown apps subcommand \"${value}\".` : 'apps needs a subcommand.',\n `Run one of: ${APPS_SUBCOMMANDS.map((name) => `ekanos apps ${name} <product>`).join(', ')}.`,\n );\n}\n\nfunction requireProduct(value: string | undefined, verb: string): string {\n const slug = value?.trim().toLowerCase();\n if (slug && /^[a-z0-9][a-z0-9-]*$/.test(slug)) return slug;\n throw usageError(\n value\n ? `\"${value}\" is not a product slug.`\n : `apps ${verb} needs a product.`,\n `Pass the product's slug, e.g. \"ekanos apps ${verb} linear\". \"ekanos catalog\" lists them.`,\n );\n}\n\nexport async function promptLine(question: string): Promise<string> {\n const readline = await import('node:readline/promises');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stderr,\n });\n try {\n return await rl.question(question);\n } finally {\n rl.close();\n }\n}\n\n/** Read a line without echoing it: the secret never appears on screen or in scrollback. */\nexport async function promptHidden(question: string): Promise<string> {\n const readline = await import('node:readline');\n process.stderr.write(question);\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stderr,\n terminal: true,\n });\n // Swallow readline's echo of each keystroke; the question is already written.\n (rl as unknown as { _writeToOutput: (text: string) => void })._writeToOutput =\n () => {};\n try {\n return await new Promise<string>((resolve) => {\n rl.question('', resolve);\n });\n } finally {\n rl.close();\n process.stderr.write('\\n');\n }\n}\n\n/** Every redirect URI to register; an older host sends only the one. */\nfunction callbackUrls(status: ProviderAppStatus): string[] {\n return status.callbackUrls?.length\n ? status.callbackUrls\n : [status.callbackUrl];\n}\n"]}
1
+ {"version":3,"file":"apps.js","sourceRoot":"","sources":["../../src/commands/apps.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,cAAc,EACd,eAAe,GAChB,MAAM,aAAa,CAAC;AAErB,OAAO,EAEL,oBAAoB,EACpB,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAGL,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,eAAe,GAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,MAAM;IACN,KAAK;IACL,MAAM;IACN,SAAS;IACT,YAAY;CACJ,CAAC;AAqBX;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,GAAe,EACf,IAAc;;IAEd,MAAM,UAAU,GAAG,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpD,IAAI,UAAU,KAAK,MAAM;QAAE,OAAO,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACzD,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,YAAY,EAAE,CAAC;QAC5D,OAAO,aAAa,CAAC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AC3B,CAAC","sourcesContent":["import type { ProviderAppStatus } from '@ekanos/integration-schema';\n\nimport {\n type AppsApiResult,\n setProviderApp,\n showProviderApp,\n} from '../apps-api';\nimport type { StoredSession } from '../auth/credential-store';\nimport {\n type AuthEnvironment,\n refreshStoredSession,\n requireSession,\n resolveAuthEnvironment,\n} from '../auth/session';\nimport {\n type ConnectionsApiResult,\n type SourceConnection,\n deleteConnection,\n listConnections,\n showConnection,\n startConnection,\n} from '../connections-api';\nimport type { CliContext } from '../context';\nimport {\n authRequiredError,\n invalidStateError,\n usageError,\n validationError,\n} from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { resolveSourceTarget } from '../source-target';\nimport type { ResultRow } from '../ui';\nimport { promptYesNo } from './publish';\n\nexport const APPS_SUBCOMMANDS = [\n 'show',\n 'set',\n 'list',\n 'connect',\n 'disconnect',\n] as const;\ntype AppsSubcommand = (typeof APPS_SUBCOMMANDS)[number];\n\nexport interface AppsArgs {\n host?: string;\n source?: string;\n subcommand?: string;\n product?: string;\n dir: string;\n env: Record<string, string | undefined>;\n stdinIsTTY?: boolean;\n /** Test seams for the questions `set` and `connect` ask. */\n ask?: (question: string) => Promise<string>;\n askSecret?: (question: string) => Promise<string>;\n confirm?: (question: string) => Promise<boolean>;\n /** Test seam: `connect`'s wait between status polls. */\n pollDelayMs?: number;\n /** `connect --no-wait`: print the URL and return without polling. */\n noWait?: boolean;\n}\n\n/**\n * `apps` — a Source's provider apps: the OAuth client an integration signs\n * every team in through (Linear's, say). `show` says whether the Source has\n * one and which callback URL to register; `set` takes the client id and\n * secret from the Source admin at the terminal — never from a flag, a file\n * or a non-interactive run, so an agent driving the CLI never handles the\n * secret.\n */\nexport async function runApps(\n ctx: CliContext,\n args: AppsArgs,\n): Promise<ExitCode> {\n const subcommand = parseSubcommand(args.subcommand);\n if (subcommand === 'list') return runList(ctx, args);\n const product = requireProduct(args.product, subcommand);\n if (subcommand === 'connect' || subcommand === 'disconnect') {\n return runConnection(ctx, args, subcommand, product);\n }\n\n if (subcommand === 'set' && !canPrompt(ctx, args)) {\n throw usageError(\n 'apps set takes the client secret at a terminal, never in a script or an agent run.',\n `Run it yourself in your terminal: npx @ekanos/cli apps set ${product}${args.source ? ` --source ${args.source}` : ''}`,\n );\n }\n\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const resolved = await resolveSourceTarget(\n env,\n requireSession(env.store, env.host),\n args,\n );\n const client = new AppsClient(env, resolved.session);\n const source = resolved.source;\n\n if (subcommand === 'show') {\n return showApp(ctx, env.host, client, source, product);\n }\n\n const status = await client.call((token) =>\n showProviderApp(env.host, token, source, product),\n );\n\n ctx.log(walkthrough(status).join('\\n'));\n if (status.configured) {\n const replace = await (args.confirm ?? promptYesNo)(\n `${status.source.slug} already has ${status.product.name} credentials. Replace them? [y/N]`,\n );\n if (!replace) {\n throw validationError(\n 'Nothing was changed.',\n `Run \"ekanos apps show ${product}\" to see the current state.`,\n );\n }\n }\n\n const clientId = (await (args.ask ?? promptLine)('Client ID: ')).trim();\n const clientSecret = (\n await (args.askSecret ?? promptHidden)('Client secret (hidden): ')\n ).trim();\n if (!clientId || !clientSecret) {\n throw validationError(\n 'Both the client ID and the client secret are needed.',\n `Run \"ekanos apps set ${product}\" again.`,\n );\n }\n\n const result = await client.call((token) =>\n setProviderApp(env.host, token, {\n source,\n product,\n clientId,\n clientSecret,\n }),\n );\n return ctx.succeed(\n { host: env.host, ...result },\n ctx.ui.result({\n title: result.replaced\n ? `Replaced the ${result.product.name} app`\n : `Set up the ${result.product.name} app`,\n rows: [\n ['Source', result.source.slug],\n ['Teams can connect', result.configured ? 'yes' : 'not yet'],\n ['Callback URLs', callbackUrls(result)],\n ],\n }),\n );\n}\n\n/**\n * How to create the app: the integration's own steps (`oauth.setup`, with the\n * callback URL filled in) when it declares them, else the generic three.\n */\nexport function walkthrough(status: ProviderAppStatus): string[] {\n const name = status.product.name;\n const lines = [`${name} app for ${status.source.slug}`];\n if (status.setup?.consoleUrl) {\n lines.push(` Open: ${status.setup.consoleUrl}`);\n }\n const steps = status.setup?.steps.length\n ? [\n ...status.setup.steps,\n `Check the app lists exactly: ${callbackUrls(status).join(', ')}`,\n ]\n : [\n `In ${name}, create an OAuth app (or open the one you use).`,\n `Register exactly these callback URLs: ${callbackUrls(status).join(', ')}`,\n ];\n steps.push(\n \"Enter its client ID and secret below. The secret is stored in Ekanos's vault and never shown again.\",\n );\n lines.push(...steps.map((step, index) => ` ${index + 1}. ${step}`));\n if (status.setup?.guideUrl) lines.push(` Guide: ${status.setup.guideUrl}`);\n return lines;\n}\n\nfunction summary(ctx: CliContext, status: ProviderAppStatus): string {\n const rows: ResultRow[] = [\n ['Source', status.source.slug],\n ...(status.setup\n ? ([\n [\n 'How to create it',\n [\n ...(status.setup.consoleUrl\n ? [`Open ${status.setup.consoleUrl}`]\n : []),\n ...status.setup.steps.map(\n (step, index) => `${index + 1}. ${step}`,\n ),\n ],\n ],\n ] as const)\n : []),\n [\n 'Set up',\n status.configured\n ? 'yes — teams can connect'\n : 'no — no team can connect yet',\n ],\n ['Callback URLs', callbackUrls(status)],\n ];\n return [\n ctx.ui.result({ title: `${status.product.name} app`, rows }),\n ...(status.configured\n ? []\n : [\n ctx.ui.hint(\n `Run \"ekanos apps set ${status.product.slug}\" in your terminal to enter its credentials.`,\n ),\n ]),\n ].join('\\n');\n}\n\n/**\n * `apps show <product>`: the Source provider app, and — for an integration\n * that supports one — the Source connection (plan 241). A `teamApp`\n * integration (Zendesk) has no provider app but can have a Source\n * connection, so either half may be absent.\n */\nasync function showApp(\n ctx: CliContext,\n host: string,\n client: AppsClient,\n source: string,\n product: string,\n): Promise<ExitCode> {\n const [app, connection] = await Promise.all([\n client\n .call((token) => showProviderApp(host, token, source, product))\n .then(\n (status) => ({ ok: true as const, status }),\n (error: unknown) => ({ ok: false as const, error }),\n ),\n // A host without the connections routes (before plan 241), or one that\n // refuses, leaves `show` exactly as it was: the provider app alone.\n client\n .connection((token) => showConnection(host, token, source, product))\n .catch(() => ({ status: 'unavailable' as const })),\n ]);\n\n if (!app.ok && connection.status !== 'ok') throw app.error;\n\n const parts: string[] = [];\n if (app.ok) parts.push(summary(ctx, app.status));\n if (connection.status === 'ok') {\n parts.push(\n connectionSummary(ctx, connection.data.connection, {\n sourceSlug: connection.data.source.slug,\n callbackUrls: connection.data.callbackUrls,\n }),\n );\n }\n\n return ctx.succeed(\n {\n host,\n ...(app.ok ? app.status : {}),\n ...(connection.status === 'ok'\n ? {\n sourceConnection: connection.data.connection,\n sourceConnectionCallbackUrls: connection.data.callbackUrls,\n }\n : {}),\n },\n parts.join('\\n'),\n );\n}\n\n/** `apps list`: every integration the Source can connect once, with status. */\nasync function runList(ctx: CliContext, args: AppsArgs): Promise<ExitCode> {\n const { env, client, source } = await openClient(ctx, args);\n const result = await client.connection((token) =>\n listConnections(env.host, token, source),\n );\n if (result.status !== 'ok') {\n throw invalidStateError(\n 'The host could not list the connections.',\n 'Retry shortly.',\n );\n }\n const { connections } = result.data;\n const rows: ResultRow[] = connections.map((connection) => [\n `${connection.name} (${connection.slug})`,\n connectionState(connection),\n ]);\n return ctx.succeed(\n { host: env.host, ...result.data },\n connections.length === 0\n ? ctx.ui.hint(\n `No integration on ${result.data.source.slug} supports one connection for the whole Source yet.`,\n )\n : ctx.ui.result({\n title: `Source connections on ${result.data.source.slug}`,\n rows,\n }),\n );\n}\n\nfunction connectionState(connection: SourceConnection): string {\n if (connection.connected) {\n return [\n 'connected',\n connection.connectedAt ? ` ${connection.connectedAt}` : '',\n connection.connectedBy ? ` by ${connection.connectedBy}` : '',\n ].join('');\n }\n return connection.missing.length > 0\n ? `not connected — app fields missing: ${connection.missing.join(', ')}`\n : 'not connected';\n}\n\n/**\n * `apps connect <product>`: connect the integration ONCE for the whole Source,\n * for the Source's provided agents whose template says `owner: \"source\"`.\n * Asks for any missing app fields at the terminal (secrets hidden, never from\n * a flag), prints the provider's consent URL, then waits until the browser\n * finishes. `apps disconnect <product>` removes it.\n */\nasync function runConnection(\n ctx: CliContext,\n args: AppsArgs,\n subcommand: 'connect' | 'disconnect',\n product: string,\n): Promise<ExitCode> {\n const { env, client, source } = await openClient(ctx, args);\n\n if (subcommand === 'disconnect') {\n return disconnect(ctx, args, client, env.host, source, product);\n }\n\n const shown = await client.connection((token) =>\n showConnection(env.host, token, source, product),\n );\n if (shown.status === 'unsupported') {\n throw invalidStateError(\n shown.message,\n `Each team connects ${product} itself, from the team's Integrations page.`,\n );\n }\n if (shown.status !== 'ok') {\n throw invalidStateError(\n 'The host could not read the connection.',\n 'Retry shortly.',\n );\n }\n const current = shown.data.connection;\n\n if (current.app === 'fields') {\n ctx.log(\n [\n `${current.name} app for ${shown.data.source.slug} (one for the whole Source)`,\n ` Register this redirect URL in the app: ${shown.data.callbackUrls.join(', ')}`,\n ].join('\\n'),\n );\n }\n\n const fields = await askFields(ctx, args, current, product);\n\n const started = await client.connection((token) =>\n startConnection(env.host, token, {\n source,\n product,\n ...(Object.keys(fields).length > 0 ? { fields } : {}),\n }),\n );\n if (started.status === 'not-configured') {\n throw validationError(\n `${current.name} is not set up for the Source yet — missing: ${started.missing.join(', ')}.`,\n current.app === 'source-app'\n ? `Run \"ekanos apps set ${product}\" to enter the Source's app first.`\n : `Run \"ekanos apps connect ${product}\" again and fill every field.`,\n );\n }\n if (started.status !== 'ok') {\n throw invalidStateError(\n 'The host could not start the connection.',\n 'Retry shortly.',\n );\n }\n\n ctx.log(\n [\n `Open this link and approve ${current.name} as the account the Source's agents should act as:`,\n ` ${started.data.authorizeUrl}`,\n ].join('\\n'),\n );\n\n if (args.noWait || ctx.jsonMode) {\n return ctx.succeed(\n {\n host: env.host,\n product,\n authorizeUrl: started.data.authorizeUrl,\n callbackUrl: started.data.callbackUrl,\n connected: false,\n },\n ctx.ui.hint(`Then check with \"ekanos apps show ${product}\".`),\n );\n }\n\n const deadline = Date.now() + 10 * 60 * 1000;\n const before = current.connectedAt;\n while (Date.now() < deadline) {\n await new Promise((resolve) =>\n setTimeout(resolve, args.pollDelayMs ?? 3000),\n );\n const polled = await client.connection((token) =>\n showConnection(env.host, token, source, product),\n );\n if (\n polled.status === 'ok' &&\n polled.data.connection.connected &&\n polled.data.connection.connectedAt !== before\n ) {\n return ctx.succeed(\n { host: env.host, product, connection: polled.data.connection },\n connectionSummary(ctx, polled.data.connection, {\n sourceSlug: polled.data.source.slug,\n callbackUrls: polled.data.callbackUrls,\n }),\n );\n }\n }\n throw validationError(\n 'The connection did not finish within ten minutes.',\n `Run \"ekanos apps connect ${product}\" again for a fresh link.`,\n );\n}\n\nasync function askFields(\n ctx: CliContext,\n args: AppsArgs,\n current: SourceConnection,\n product: string,\n): Promise<Record<string, string>> {\n const toAsk = current.fields.filter(\n (field) => !field.set || current.missing.includes(field.name),\n );\n if (toAsk.length === 0) return {};\n if (!canPrompt(ctx, args)) {\n throw usageError(\n `${current.name} needs its app fields entered for the Source: ${toAsk.map((field) => field.label).join(', ')}.`,\n `Run it yourself in your terminal: npx @ekanos/cli apps connect ${product}${args.source ? ` --source ${args.source}` : ''}`,\n );\n }\n const fields: Record<string, string> = {};\n for (const field of toAsk) {\n const question = field.sensitive\n ? `${field.label} (hidden): `\n : `${field.label}: `;\n const value = (\n await (\n field.sensitive\n ? (args.askSecret ?? promptHidden)\n : (args.ask ?? promptLine)\n )(question)\n ).trim();\n if (value) fields[field.name] = value;\n }\n return fields;\n}\n\nasync function disconnect(\n ctx: CliContext,\n args: AppsArgs,\n client: AppsClient,\n host: string,\n source: string,\n product: string,\n): Promise<ExitCode> {\n if (canPrompt(ctx, args)) {\n const sure = await (args.confirm ?? promptYesNo)(\n `Disconnect ${product} for every team's provided agents on ${source}? [y/N]`,\n );\n if (!sure) {\n throw validationError(\n 'Nothing was changed.',\n `Run \"ekanos apps show ${product}\" to see the current state.`,\n );\n }\n }\n const result = await client.connection((token) =>\n deleteConnection(host, token, source, product),\n );\n if (result.status === 'unsupported') {\n throw invalidStateError(\n result.message,\n `Each team connects ${product} itself, from the team's Integrations page.`,\n );\n }\n if (result.status !== 'ok') {\n throw invalidStateError('The host could not disconnect.', 'Retry shortly.');\n }\n return ctx.succeed(\n { host, product, ...result.data },\n ctx.ui.result({\n title: result.data.removed\n ? `Disconnected ${product} for ${source}`\n : `${product} was not connected for ${source}`,\n rows: [\n [\n 'Provided agents',\n 'their tools for this product stop until you connect again',\n ],\n ],\n }),\n );\n}\n\nfunction connectionSummary(\n ctx: CliContext,\n connection: SourceConnection,\n meta: { sourceSlug: string; callbackUrls: string[] },\n): string {\n const rows: ResultRow[] = [\n ['Source', meta.sourceSlug],\n ['Connected', connectionState(connection)],\n ...(connection.scope ? ([['Scope', connection.scope]] as ResultRow[]) : []),\n ...(connection.fields.length > 0\n ? ([\n [\n 'App fields',\n connection.fields.map(\n (field) =>\n `${field.label}: ${field.set ? (field.value ?? 'set') : 'missing'}`,\n ),\n ],\n ] as ResultRow[])\n : []),\n ['Redirect URL', meta.callbackUrls],\n [\n 'Used by',\n 'provided agents whose template says connections.<product>.owner: \"source\", in every team',\n ],\n ];\n return [\n ctx.ui.result({\n title: `${connection.name} — one connection for the whole Source`,\n rows,\n }),\n ...(connection.connected\n ? []\n : [\n ctx.ui.hint(\n `Run \"ekanos apps connect ${connection.slug}\" in your terminal to connect it.`,\n ),\n ]),\n ].join('\\n');\n}\n\nasync function openClient(ctx: CliContext, args: AppsArgs) {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n const resolved = await resolveSourceTarget(\n env,\n requireSession(env.store, env.host),\n args,\n );\n return {\n env,\n client: new AppsClient(env, resolved.session),\n source: resolved.source,\n };\n}\n\nclass AppsClient {\n constructor(\n private readonly env: AuthEnvironment,\n private session: StoredSession,\n ) {}\n\n async call<T>(\n send: (accessToken: string) => Promise<AppsApiResult<T>>,\n ): Promise<T> {\n let result = await send(this.session.accessToken);\n if (result.status === 'unauthorized') {\n this.session = await refreshStoredSession(this.env, this.session);\n result = await send(this.session.accessToken);\n }\n if (result.status === 'ok') return result.data;\n throw authRequiredError(\n `The session for ${this.env.host} could not authorize the apps call.`,\n `Run \"ekanos login --host ${this.env.host}\" and retry.`,\n );\n }\n\n /** As `call`, for the connections client, whose 409s are answers. */\n async connection<T>(\n send: (accessToken: string) => Promise<ConnectionsApiResult<T>>,\n ): Promise<Exclude<ConnectionsApiResult<T>, { status: 'unauthorized' }>> {\n let result = await send(this.session.accessToken);\n if (result.status === 'unauthorized') {\n this.session = await refreshStoredSession(this.env, this.session);\n result = await send(this.session.accessToken);\n }\n if (result.status !== 'unauthorized') return result;\n throw authRequiredError(\n `The session for ${this.env.host} could not authorize the connections call.`,\n `Run \"ekanos login --host ${this.env.host}\" and retry.`,\n );\n }\n}\n\nfunction canPrompt(ctx: CliContext, args: AppsArgs): boolean {\n return !ctx.jsonMode && (args.stdinIsTTY ?? process.stdin.isTTY === true);\n}\n\nfunction parseSubcommand(value: string | undefined): AppsSubcommand {\n const match = APPS_SUBCOMMANDS.find((name) => name === value);\n if (match) return match;\n throw usageError(\n value ? `Unknown apps subcommand \"${value}\".` : 'apps needs a subcommand.',\n `Run one of: ${APPS_SUBCOMMANDS.map((name) => `ekanos apps ${name} <product>`).join(', ')}.`,\n );\n}\n\nfunction requireProduct(value: string | undefined, verb: string): string {\n const slug = value?.trim().toLowerCase();\n if (slug && /^[a-z0-9][a-z0-9-]*$/.test(slug)) return slug;\n throw usageError(\n value\n ? `\"${value}\" is not a product slug.`\n : `apps ${verb} needs a product.`,\n `Pass the product's slug, e.g. \"ekanos apps ${verb} linear\". \"ekanos catalog\" lists them.`,\n );\n}\n\nexport async function promptLine(question: string): Promise<string> {\n const readline = await import('node:readline/promises');\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stderr,\n });\n try {\n return await rl.question(question);\n } finally {\n rl.close();\n }\n}\n\n/** Read a line without echoing it: the secret never appears on screen or in scrollback. */\nexport async function promptHidden(question: string): Promise<string> {\n const readline = await import('node:readline');\n process.stderr.write(question);\n const rl = readline.createInterface({\n input: process.stdin,\n output: process.stderr,\n terminal: true,\n });\n // Swallow readline's echo of each keystroke; the question is already written.\n (rl as unknown as { _writeToOutput: (text: string) => void })._writeToOutput =\n () => {};\n try {\n return await new Promise<string>((resolve) => {\n rl.question('', resolve);\n });\n } finally {\n rl.close();\n process.stderr.write('\\n');\n }\n}\n\n/** Every redirect URI to register; an older host sends only the one. */\nfunction callbackUrls(status: ProviderAppStatus): string[] {\n return status.callbackUrls?.length\n ? status.callbackUrls\n : [status.callbackUrl];\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import type { CliContext } from '../context.js';
2
+ import type { ExitCode } from '../exit-codes.js';
3
+ export declare const REVIEWERS_SUBCOMMANDS: readonly ['list', 'add', 'remove'];
4
+ export interface ReviewersArgs {
5
+ host?: string;
6
+ source?: string;
7
+ /** `list`, `add <email>`, `remove <email>`. */
8
+ positionals: readonly string[];
9
+ reach?: string;
10
+ team?: string;
11
+ dir: string;
12
+ env: Record<string, string | undefined>;
13
+ }
14
+ /**
15
+ * `reviewers` — a Source admin names who decides its agents' reply drafts
16
+ * held under an `approve` policy. A reviewer is one of the Source's own
17
+ * users, at a reach: `source` (drafts from every team's provided agents) or
18
+ * `team` (one named team's). `list` shows them; `add` names one; `remove`
19
+ * takes one off — every reach, or only the named team's with `--team`.
20
+ */
21
+ export declare function runReviewers(ctx: CliContext, args: ReviewersArgs): Promise<ExitCode>;
@@ -0,0 +1,162 @@
1
+ import { refreshStoredSession, requireSession, resolveAuthEnvironment, } from '../auth/session.js';
2
+ import { authRequiredError, usageError } from '../errors.js';
3
+ import { addReviewer, listReviewers, removeReviewer, } from '../reviewers-api.js';
4
+ import { resolveSourceTarget } from '../source-target.js';
5
+ export const REVIEWERS_SUBCOMMANDS = ['list', 'add', 'remove'];
6
+ const REACHES = ['source', 'team'];
7
+ /**
8
+ * `reviewers` — a Source admin names who decides its agents' reply drafts
9
+ * held under an `approve` policy. A reviewer is one of the Source's own
10
+ * users, at a reach: `source` (drafts from every team's provided agents) or
11
+ * `team` (one named team's). `list` shows them; `add` names one; `remove`
12
+ * takes one off — every reach, or only the named team's with `--team`.
13
+ */
14
+ export async function runReviewers(ctx, args) {
15
+ var _a;
16
+ var _b;
17
+ const [rawSubcommand, rawEmail, ...extra] = args.positionals;
18
+ const subcommand = parseSubcommand(rawSubcommand);
19
+ if (subcommand === 'list') {
20
+ if (rawEmail !== undefined || args.reach || args.team) {
21
+ throw usageError('reviewers list takes no arguments.', 'Run "ekanos reviewers list --source <slug>".');
22
+ }
23
+ }
24
+ else if (extra.length > 0) {
25
+ throw usageError(`Unexpected argument "${extra[0]}".`, 'See "ekanos reviewers --help".');
26
+ }
27
+ const email = subcommand === 'list' ? '' : requireEmail(rawEmail, subcommand);
28
+ const team = args.team === undefined ? undefined : requireTeam(args.team);
29
+ const reach = subcommand === 'add' ? requireReach(args.reach, email, team) : undefined;
30
+ if (subcommand === 'remove' && args.reach) {
31
+ throw usageError('reviewers remove takes no --reach.', `Run "ekanos reviewers remove ${email}" (every reach) or add "--team <slug>" for one team's.`);
32
+ }
33
+ const env = resolveAuthEnvironment(ctx, args.host, args.env, {
34
+ projectDir: args.dir,
35
+ });
36
+ const resolved = await resolveSourceTarget(env, requireSession(env.store, env.host), args);
37
+ const client = new ReviewersClient(env, resolved.session);
38
+ const source = resolved.source;
39
+ if (subcommand === 'list') {
40
+ const list = await client.call((token) => listReviewers(env.host, token, source));
41
+ if (list.reviewers.length === 0) {
42
+ return ctx.succeed(Object.assign({ host: env.host }, list), ctx.ui.result({
43
+ title: `No reviewers on ${list.source.slug}`,
44
+ tone: 'warn',
45
+ notes: [
46
+ 'Reply drafts under an "approve" policy wait for a named reviewer.',
47
+ 'Name one: "ekanos reviewers add <email> --reach source".',
48
+ ],
49
+ }));
50
+ }
51
+ return ctx.succeed(Object.assign({ host: env.host }, list), [
52
+ ctx.ui.bold(`Reviewers on ${list.source.slug}`),
53
+ ctx.ui.table(['Email', 'Name', 'Reach', 'Team'], list.reviewers.map(reviewerRow)),
54
+ ].join('\n'));
55
+ }
56
+ if (subcommand === 'add' && reach) {
57
+ const result = await client.call((token) => addReviewer(env.host, token, source, Object.assign({ email,
58
+ reach }, (team ? { team } : {}))));
59
+ const reviewer = result.reviewer;
60
+ return ctx.succeed(Object.assign({ host: env.host }, result), ctx.ui.result({
61
+ title: result.created
62
+ ? `Added ${who(reviewer)} as a reviewer`
63
+ : `${who(reviewer)} already reviews at that reach`,
64
+ tone: result.created ? 'ok' : 'warn',
65
+ rows: [
66
+ ['Source', source],
67
+ ['Reach', reachLabel(reviewer)],
68
+ ],
69
+ notes: [
70
+ reviewer.reach === 'source'
71
+ ? "Decides drafts from every team's provided agents, in the Source's review queue."
72
+ : `Decides ${(_b = (_a = reviewer.team) === null || _a === void 0 ? void 0 : _a.slug) !== null && _b !== void 0 ? _b : 'the team'}'s drafts, from its Approvals inbox or the Source's review queue.`,
73
+ ],
74
+ }));
75
+ }
76
+ const result = await client.call((token) => removeReviewer(env.host, token, source, Object.assign({ email }, (team ? { team } : {}))));
77
+ return ctx.succeed(Object.assign({ host: env.host }, result), ctx.ui.result({
78
+ title: `Removed ${email}${team ? ` from ${team}` : ''}`,
79
+ rows: [
80
+ ['Source', source],
81
+ [
82
+ 'Removed',
83
+ `${result.removed} reach${result.removed === 1 ? '' : 'es'}`,
84
+ ],
85
+ ],
86
+ }));
87
+ }
88
+ function reviewerRow(reviewer) {
89
+ var _a;
90
+ var _b, _c, _d;
91
+ return [
92
+ (_b = reviewer.email) !== null && _b !== void 0 ? _b : reviewer.userId,
93
+ (_c = reviewer.name) !== null && _c !== void 0 ? _c : '—',
94
+ reviewer.reach,
95
+ (_d = (_a = reviewer.team) === null || _a === void 0 ? void 0 : _a.slug) !== null && _d !== void 0 ? _d : '—',
96
+ ];
97
+ }
98
+ function reachLabel(reviewer) {
99
+ return reviewer.reach === 'team' && reviewer.team
100
+ ? `team ${reviewer.team.slug} (${reviewer.team.name})`
101
+ : 'source';
102
+ }
103
+ function who(reviewer) {
104
+ var _a, _b;
105
+ return (_b = (_a = reviewer.email) !== null && _a !== void 0 ? _a : reviewer.name) !== null && _b !== void 0 ? _b : reviewer.userId;
106
+ }
107
+ class ReviewersClient {
108
+ constructor(env, session) {
109
+ this.env = env;
110
+ this.session = session;
111
+ }
112
+ async call(send) {
113
+ let result = await send(this.session.accessToken);
114
+ if (result.status === 'unauthorized') {
115
+ this.session = await refreshStoredSession(this.env, this.session);
116
+ result = await send(this.session.accessToken);
117
+ }
118
+ if (result.status === 'ok')
119
+ return result.data;
120
+ throw authRequiredError(`The session for ${this.env.host} could not authorize the reviewers call.`, `Run "ekanos login --host ${this.env.host}" and retry.`);
121
+ }
122
+ }
123
+ function parseSubcommand(value) {
124
+ const match = REVIEWERS_SUBCOMMANDS.find((name) => name === value);
125
+ if (match)
126
+ return match;
127
+ throw usageError(value
128
+ ? `Unknown reviewers subcommand "${value}".`
129
+ : 'reviewers needs a subcommand.', 'Run one of: ekanos reviewers list, ekanos reviewers add <email> --reach source|team [--team <slug>], ekanos reviewers remove <email> [--team <slug>].');
130
+ }
131
+ function requireEmail(value, subcommand) {
132
+ const email = value === null || value === void 0 ? void 0 : value.trim().toLowerCase();
133
+ if (email && /^[^\s@]+@[^\s@]+$/.test(email))
134
+ return email;
135
+ throw usageError(value
136
+ ? `"${value}" is not an email address.`
137
+ : 'Name the reviewer by email.', subcommand === 'add'
138
+ ? 'e.g. "ekanos reviewers add ana@example.com --reach source".'
139
+ : '"ekanos reviewers list" shows who reviews.');
140
+ }
141
+ function requireTeam(value) {
142
+ const slug = value.trim().toLowerCase();
143
+ if (/^[a-z0-9][a-z0-9-]*$/.test(slug))
144
+ return slug;
145
+ throw usageError(`"${value}" is not a team slug.`, 'Run "ekanos teams list" to see the teams on this Source.');
146
+ }
147
+ function requireReach(value, email, team) {
148
+ const reach = REACHES.find((entry) => entry === (value === null || value === void 0 ? void 0 : value.trim().toLowerCase()));
149
+ if (!reach) {
150
+ throw usageError(value
151
+ ? `"${value}" is not a reach: use source or team.`
152
+ : 'Name the reach: --reach source or --reach team.', `e.g. "ekanos reviewers add ${email} --reach source", or "--reach team --team <slug>" for one team's drafts.`);
153
+ }
154
+ if (reach === 'team' && !team) {
155
+ throw usageError('A team-reach reviewer needs --team <slug>.', 'Run "ekanos teams list" to see the teams on this Source.');
156
+ }
157
+ if (reach === 'source' && team) {
158
+ throw usageError('A source-reach reviewer decides for every team; drop --team.', `Run "ekanos reviewers add ${email} --reach source", or use "--reach team --team ${team}".`);
159
+ }
160
+ return reach;
161
+ }
162
+ //# sourceMappingURL=reviewers.js.map