@ekanos/cli 0.5.1 → 0.7.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.
- package/README.md +1 -1
- package/dist/apps-api.d.ts +27 -0
- package/dist/apps-api.js +80 -0
- package/dist/apps-api.js.map +1 -0
- package/dist/claude-docs.d.ts +39 -0
- package/dist/claude-docs.js +70 -0
- package/dist/claude-docs.js.map +1 -0
- package/dist/commands/agents-init.d.ts +34 -0
- package/dist/commands/agents-init.js +119 -0
- package/dist/commands/agents-init.js.map +1 -0
- package/dist/commands/agents.d.ts +5 -1
- package/dist/commands/agents.js +18 -5
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/apps.d.ts +25 -0
- package/dist/commands/apps.js +155 -0
- package/dist/commands/apps.js.map +1 -0
- package/dist/commands/catalog.js +3 -2
- package/dist/commands/catalog.js.map +1 -1
- package/dist/commands/init.d.ts +1 -1
- package/dist/commands/init.js +2 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/login.d.ts +4 -0
- package/dist/commands/login.js +16 -3
- package/dist/commands/login.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +34 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/templates/agents-claude.md.tmpl +14 -0
- package/templates/claude-skill.md.tmpl +4 -8
- package/templates/package.json.tmpl +4 -4
- package/templates/skills/build-agent/SKILL.md +118 -0
- package/templates/skills/build-agent/references/agent-json.md +85 -0
- package/templates/skills/build-agent/references/rollout.md +53 -0
- package/templates/skills/build-agent/references/triggers.md +47 -0
- package/templates/skills/ekanos-platform/SKILL.md +107 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/commands/agents.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAEL,uBAAuB,EAEvB,sBAAsB,GAGvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,SAAS,CAA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AAE,MAA2B;IACxD,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAC5B,MAAM,IAAI,GAAgB,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACjE,IAAI,MAAM,CAAC,OAAO,KAAK,WAAW,IAAI,MAAM,CAAC,OAAO,KAAK,aAAa,EAAE,CAAC;QACvE,IAAI,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,KAAK,GACT,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC;QAC9D,QAAQ,CAAC,gBAAgB,KAAK,QAAQ,CAAC,aAAa;QAClD,CAAC,CAAC;YACE,iEAAiE,QAAQ,CAAC,GAAG,eAAe;SAC7F;QACH,CAAC,CAAC,EAAE,CAAC;IACT,OAAO,EAAE,CAAC,MAAM,CAAC;QACf,KAAK,EAAE,GAAG,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,GAAG,EAAE;QAC1D,IAAI,EAAE,MAAM,CAAC,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI;QACpD,IAAI;QACJ,KAAK;KACN,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type AgentTemplateBody,\n AgentTemplateBodySchema,\n type AgentTemplateDetail,\n AgentTemplateKeySchema,\n type AgentTemplateList,\n type AgentTemplateResult,\n} from '@ekanos/integration-schema';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport {\n type AgentsApiResult,\n applyAgentTemplate,\n listAgentTemplates,\n publishAgentTemplate,\n showAgentTemplate,\n} from '../agents-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 {\n authRequiredError,\n notFoundError,\n usageError,\n validationError,\n} from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { classifyPath } from '../safe-fs';\nimport { resolveSourceTarget } from '../source-target';\nimport { type ResultRow, type Ui, pluralize } from '../ui';\nimport { promptYesNo } from './publish';\n\nexport const AGENTS_SUBCOMMANDS = [\n 'list',\n 'show',\n 'pull',\n 'apply',\n 'publish',\n 'rollback',\n] as const;\n\ntype AgentsSubcommand = (typeof AGENTS_SUBCOMMANDS)[number];\n\n/** The file `pull` writes and `apply` reads, inside an agent's directory. */\nexport const AGENT_FILE = 'agent.json';\n/** Instructions as Markdown, beside it. Used when `agent.json` has none. */\nexport const AGENT_INSTRUCTIONS_FILE = 'AGENT.md';\n\nexport interface AgentsArgs {\n host?: string;\n source?: string;\n subcommand?: string;\n /** A template key, or for `apply` a file or directory. */\n target?: string;\n /** `publish` / `rollback`: the version to make the one teams run. */\n to?: string;\n baseVersion?: string;\n overwrite: boolean;\n out?: string;\n yes: boolean;\n dir: string;\n env: Record<string, string | undefined>;\n stdinIsTTY?: boolean;\n confirm?: (question: string) => Promise<boolean>;\n}\n\n/**\n * `agents` — the Source's agent templates (plan 239.0 / 239.2). Ekanos holds\n * them; nothing here is deployed. `apply` stores a new version (a draft\n * until published), `publish` makes a version the one every team runs,\n * `rollback` publishes an older one. `pull` writes a template out as\n * `agent.json` + `AGENT.md` for review or Git, and `apply` reads the same\n * layout back.\n */\nexport async function runAgents(\n ctx: CliContext,\n args: AgentsArgs,\n): Promise<ExitCode> {\n const subcommand = parseSubcommand(args.subcommand);\n\n // Read the local input before any network call, so a bad file fails fast.\n const local =\n subcommand === 'apply' ? readAgentInput(args.target, args.dir) : null;\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 AgentsClient(env, resolved.session);\n const source = resolved.source;\n\n switch (subcommand) {\n case 'list': {\n const list = await client.call((token) =>\n listAgentTemplates(env.host, token, source),\n );\n return ctx.succeed(\n { host: env.host, ...list },\n listSummary(ctx.ui, list),\n );\n }\n case 'show': {\n const key = requireKey(args.target, 'show');\n const shown = await client.call((token) =>\n showAgentTemplate(env.host, token, source, key),\n );\n return ctx.succeed(\n { host: env.host, ...shown },\n templateDetail(ctx.ui, shown.template),\n );\n }\n case 'pull': {\n const key = requireKey(args.target, 'pull');\n const shown = await client.call((token) =>\n showAgentTemplate(env.host, token, source, key),\n );\n const outDir = path.resolve(\n args.dir,\n args.out ?? path.join('agents', key),\n );\n const written = writeAgentFiles(outDir, shown.template);\n return ctx.succeed(\n {\n host: env.host,\n key,\n version: shown.template.latestVersion,\n files: written,\n },\n ctx.ui.result({\n title: `Pulled ${key} v${shown.template.latestVersion}`,\n rows: written.map((file): ResultRow => ['Wrote', file]),\n notes: [\n `Edit, then \"ekanos agents apply ${path.relative(args.dir, outDir) || '.'}\".`,\n ],\n }),\n );\n }\n case 'apply': {\n const input = local!;\n const baseVersion =\n parseVersionFlag(args.baseVersion, '--base-version') ??\n input.baseVersion;\n const result = await client.call((token) =>\n applyAgentTemplate(env.host, token, {\n source,\n key: input.key,\n body: input.body,\n baseVersion,\n overwrite: args.overwrite,\n }),\n );\n if (input.file && result.outcome !== 'unchanged') {\n recordBaseVersion(input.file, result.version);\n }\n return ctx.succeed(\n { host: env.host, ...result },\n resultSummary(ctx.ui, result),\n );\n }\n case 'publish':\n case 'rollback': {\n const key = requireKey(args.target, subcommand);\n let version = parseVersionFlag(args.to, '--to') ?? undefined;\n if (subcommand === 'rollback' && version === undefined) {\n throw usageError(\n 'rollback needs the version to go back to.',\n `Pass \"--to <n>\". \"ekanos agents show ${key}\" lists them.`,\n );\n }\n // Refuse a script with no --yes before reading anything.\n if (!args.yes && !canPrompt(ctx, args)) {\n throw validationError(\n `${subcommand === 'rollback' ? 'Rolling back' : 'Publishing'} ${key} on ${source} needs confirmation.`,\n 'It reaches every team running this agent at once. Pass --yes to confirm.',\n );\n }\n // Publish names the version it confirmed, never \"whatever is latest\n // when the request lands\" — a draft applied in between is not shipped\n // unseen to every team.\n if (version === undefined) {\n const shown = await client.call((token) =>\n showAgentTemplate(env.host, token, source, key),\n );\n version = shown.template.latestVersion;\n }\n await confirmPublish(ctx, args, {\n key,\n source,\n what:\n subcommand === 'rollback'\n ? `Roll ${key} back to version ${version}`\n : `Publish ${key} version ${version}`,\n });\n const result = await client.call((token) =>\n publishAgentTemplate(env.host, token, subcommand, {\n source,\n key,\n version,\n }),\n );\n return ctx.succeed(\n { host: env.host, ...result },\n resultSummary(ctx.ui, result),\n );\n }\n }\n}\n\n/** Every call refreshes the session once on a 401, then gives up. */\nclass AgentsClient {\n constructor(\n private readonly env: AuthEnvironment,\n private session: StoredSession,\n ) {}\n\n async call<T>(\n send: (accessToken: string) => Promise<AgentsApiResult<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 agents call.`,\n `Run \"ekanos login --host ${this.env.host}\" and retry.`,\n );\n }\n}\n\nfunction parseSubcommand(value: string | undefined): AgentsSubcommand {\n const match = AGENTS_SUBCOMMANDS.find((name) => name === value);\n if (match) return match;\n throw usageError(\n value\n ? `Unknown agents subcommand \"${value}\".`\n : 'agents needs a subcommand.',\n `Run one of: ${AGENTS_SUBCOMMANDS.map((name) => `ekanos agents ${name}`).join(', ')}.`,\n );\n}\n\nfunction requireKey(value: string | undefined, verb: string): string {\n const parsed = AgentTemplateKeySchema.safeParse(value ?? '');\n if (parsed.success) return parsed.data;\n throw usageError(\n value\n ? `\"${value}\" is not an agent key.`\n : `agents ${verb} needs an agent key.`,\n `Pass the key, e.g. \"ekanos agents ${verb} support-triage\". ` +\n `\"ekanos agents list\" shows them.`,\n );\n}\n\nfunction parseVersionFlag(\n value: string | undefined,\n flag: string,\n): number | null {\n if (value === undefined) return null;\n const version = Number(value);\n if (Number.isInteger(version) && version >= 1) return version;\n throw usageError(\n `${flag} must be a version number (got \"${value}\").`,\n `\"ekanos agents show <key>\" lists the versions.`,\n );\n}\n\ninterface AgentInput {\n key: string;\n body: AgentTemplateBody;\n baseVersion: number | null;\n /** The agent.json read, when there was one, so the new version is recorded in it. */\n file: string | null;\n}\n\n/**\n * Read `apply`'s input: a directory holding `agent.json` (and optionally\n * `AGENT.md`), or a `.json` file. The key is the file's `key`, else the\n * directory's name. `baseVersion` in the file is the version it was pulled\n * or last applied at — what the host checks for a concurrent change.\n */\nexport function readAgentInput(\n target: string | undefined,\n cwd: string,\n): AgentInput {\n if (!target) {\n throw usageError(\n 'agents apply needs a file or directory.',\n `Pass an agent directory (\"ekanos agents apply agents/support\") or a ` +\n `JSON file. \"ekanos agents pull <key>\" writes the layout.`,\n );\n }\n const resolved = path.resolve(cwd, target);\n const kind = classifyPath(resolved);\n const dir = kind === 'directory' ? resolved : path.dirname(resolved);\n const file =\n kind === 'directory' ? path.join(resolved, AGENT_FILE) : resolved;\n\n if (classifyPath(file) !== 'file') {\n throw notFoundError(\n `No ${kind === 'directory' ? AGENT_FILE : 'file'} at ${file}.`,\n `\"ekanos agents pull <key>\" writes ${AGENT_FILE} and ${AGENT_INSTRUCTIONS_FILE}.`,\n );\n }\n\n let raw: unknown;\n try {\n raw = JSON.parse(fs.readFileSync(file, 'utf8'));\n } catch (error) {\n throw validationError(\n `${file} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n 'Fix the JSON and apply again.',\n );\n }\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n throw validationError(\n `${file} must hold a JSON object.`,\n 'See \"ekanos agents --help\".',\n );\n }\n\n const {\n key: rawKey,\n baseVersion: rawBase,\n $schema: _schema,\n ...rest\n } = raw as Record<string, unknown>;\n const fields: Record<string, unknown> = { ...rest };\n\n const instructionsFile = path.join(dir, AGENT_INSTRUCTIONS_FILE);\n if (\n fields.instructions === undefined &&\n classifyPath(instructionsFile) === 'file'\n ) {\n fields.instructions = fs.readFileSync(instructionsFile, 'utf8');\n }\n\n const key = AgentTemplateKeySchema.safeParse(\n typeof rawKey === 'string' ? rawKey : path.basename(dir),\n );\n if (!key.success) {\n throw validationError(\n `No usable agent key: set \"key\" in ${file}, or name the directory after it.`,\n key.error.issues[0]?.message ??\n 'Use lowercase letters, digits and hyphens.',\n );\n }\n\n const body = AgentTemplateBodySchema.safeParse(fields);\n if (!body.success) {\n throw validationError(\n [\n `${file} is not a valid agent:`,\n ...body.error.issues.map(\n (issue) => ` ${issue.path.join('.') || '(root)'}: ${issue.message}`,\n ),\n ].join('\\n'),\n `Fields: name, description, instructions (or ${AGENT_INSTRUCTIONS_FILE}), ` +\n `model, maxTurns, tools, policy, skills.`,\n );\n }\n\n const baseVersion =\n typeof rawBase === 'number' && Number.isInteger(rawBase) && rawBase >= 1\n ? rawBase\n : null;\n\n return { key: key.data, body: body.data, baseVersion, file };\n}\n\n/**\n * Write `agent.json` + `AGENT.md`. The instructions live in the Markdown so\n * they read and diff as prose; the JSON holds everything else plus the\n * version they came from.\n */\nfunction writeAgentFiles(\n outDir: string,\n template: AgentTemplateDetail,\n): string[] {\n fs.mkdirSync(outDir, { recursive: true });\n const { instructions, ...rest } = template.body;\n const json = {\n key: template.key,\n baseVersion: template.latestVersion,\n ...rest,\n };\n const jsonPath = path.join(outDir, AGENT_FILE);\n const mdPath = path.join(outDir, AGENT_INSTRUCTIONS_FILE);\n for (const target of [jsonPath, mdPath]) {\n const kind = classifyPath(target);\n if (kind !== 'missing' && kind !== 'file') {\n throw validationError(\n `Refusing to write through ${target} (${kind}).`,\n 'Remove it, or pass --out <dir>.',\n );\n }\n }\n fs.writeFileSync(jsonPath, `${JSON.stringify(json, null, 2)}\\n`);\n fs.writeFileSync(\n mdPath,\n instructions.endsWith('\\n') ? instructions : `${instructions}\\n`,\n );\n return [jsonPath, mdPath];\n}\n\n/** After a stored version, point the file at it, so the next apply is based on it. */\nfunction recordBaseVersion(file: string, version: number) {\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Record<\n string,\n unknown\n >;\n if (raw.baseVersion === version) return;\n const { key, baseVersion: _old, ...rest } = raw;\n const next =\n key === undefined\n ? { baseVersion: version, ...rest }\n : { key, baseVersion: version, ...rest };\n fs.writeFileSync(file, `${JSON.stringify(next, null, 2)}\\n`);\n}\n\nfunction canPrompt(ctx: CliContext, args: AgentsArgs): boolean {\n return !ctx.jsonMode && (args.stdinIsTTY ?? process.stdin.isTTY === true);\n}\n\n/**\n * Publishing changes what every team running the agent does, at once. A\n * human run asks first; a scripted or JSON run needs `--yes`.\n */\nasync function confirmPublish(\n ctx: CliContext,\n args: AgentsArgs,\n target: { key: string; source: string; what: string },\n) {\n if (args.yes) return;\n if (!canPrompt(ctx, args)) {\n throw validationError(\n `${target.what} on ${target.source} needs confirmation.`,\n 'It reaches every team running this agent at once. Pass --yes to confirm.',\n );\n }\n ctx.log(\n `${target.what} on ${target.source}. Every team running it follows at once.`,\n );\n const confirmed = await (args.confirm ?? promptYesNo)('Proceed? [y/N]');\n if (!confirmed) {\n throw validationError(\n `${target.what} was not confirmed.`,\n 'Nothing was changed.',\n );\n }\n}\n\nfunction versionLabel(template: {\n latestVersion: number;\n publishedVersion: number | null;\n}): string {\n if (template.publishedVersion === null)\n return `v${template.latestVersion} draft, never published`;\n if (template.publishedVersion === template.latestVersion)\n return `v${template.latestVersion} published`;\n return `v${template.publishedVersion} published, v${template.latestVersion} latest`;\n}\n\nfunction listSummary(ui: Ui, list: AgentTemplateList): string {\n if (list.templates.length === 0) {\n return ui.result({\n title: `No agents on ${list.source.slug} yet`,\n tone: 'warn',\n notes: ['\"ekanos agents apply <dir>\" stores the first one.'],\n });\n }\n return [\n ui.result({\n title: `${pluralize(list.templates.length, 'agent')} on ${list.source.slug}`,\n rows: list.templates.map((template): ResultRow => [\n template.key,\n [\n template.name,\n versionLabel(template),\n template.status === 'archived' ? 'archived' : null,\n template.teams\n ? `${pluralize(template.teams.enabled, 'team')}`\n : null,\n ]\n .filter(Boolean)\n .join(' · '),\n ]),\n }),\n ui.hint('\"ekanos agents show <key>\" shows one, with its versions.'),\n ].join('\\n\\n');\n}\n\nfunction templateDetail(ui: Ui, template: AgentTemplateDetail): string {\n const { body } = template;\n const rows: ResultRow[] = [\n ['Versions', versionLabel(template)],\n ['Model', body.model ?? 'house default'],\n ['Tools', describeTools(body)],\n [\n 'Approval',\n `reads ${body.policy.reads}, writes ${body.policy.writes}` +\n (Object.keys(body.policy.overrides).length > 0\n ? `, ${pluralize(Object.keys(body.policy.overrides).length, 'override')}`\n : ''),\n ],\n ['Skills', body.skills.length > 0 ? body.skills.join(', ') : 'none'],\n ['Connections', describeConnections(body)],\n ['Teams may add', describeCustomization(body)],\n ];\n if (template.teams) {\n rows.push([\n 'Teams',\n `${template.teams.enabled} running` +\n (template.teams.pinned > 0\n ? `, ${template.teams.pinned} pinned to an older version`\n : ''),\n ]);\n }\n rows.push([\n 'History',\n template.versions.map(\n (version) =>\n `v${version.version} ${version.createdAt.slice(0, 10)}` +\n (version.createdBy ? ` by ${version.createdBy}` : '') +\n (version.publishedAt\n ? ` · published ${version.publishedAt.slice(0, 10)}`\n : ''),\n ),\n ]);\n return ui.result({ title: `${body.name} (${template.key})`, rows });\n}\n\nfunction describeConnections(body: AgentTemplateBody): string[] {\n const owner = (connection: AgentTemplateBody['connections'][string]) =>\n connection.owner === 'source'\n ? 'one connection for the source'\n : `each team's own (${connection.team})`;\n const lines = [\n ...Object.entries(body.connections).map(\n ([slug, connection]) => `${slug}: ${owner(connection)}`,\n ),\n ...body.mcpServers.map(\n (server) => `${server.key} (MCP, ${server.url}): ${owner(server)}`,\n ),\n ];\n return lines.length > 0 ? lines : [\"each team's own (optional)\"];\n}\n\nfunction describeCustomization(body: AgentTemplateBody): string {\n const allowed = Object.entries(body.teamCustomization)\n .filter(([, on]) => on)\n .map(([knob]) => CUSTOMIZATION_LABEL[knob] ?? knob);\n return allowed.length > 0 ? allowed.join(', ') : 'nothing (template only)';\n}\n\nconst CUSTOMIZATION_LABEL: Record<string, string> = {\n mcpServers: 'own MCP servers',\n skills: 'own skills',\n integrations: 'more integrations',\n narrow: 'narrower tools',\n};\n\nfunction describeTools(body: AgentTemplateBody): string {\n if (body.tools.mode === 'read_only')\n return 'every read the team has connected';\n if (body.tools.mode === 'all') return 'every tool the team has connected';\n return (\n [...(body.tools.products ?? []), ...(body.tools.tools ?? [])].join(', ') ||\n 'none'\n );\n}\n\nconst OUTCOME_TITLE = {\n created: 'Created',\n updated: 'Stored a new version',\n unchanged: 'Unchanged',\n published: 'Published',\n 'rolled-back': 'Rolled back',\n} as const;\n\nfunction resultSummary(ui: Ui, result: AgentTemplateResult): string {\n const { template } = result;\n const rows: ResultRow[] = [['Versions', versionLabel(template)]];\n if (result.outcome === 'published' || result.outcome === 'rolled-back') {\n rows.push(['Teams updated', String(result.teamsUpdated)]);\n }\n const notes =\n (result.outcome === 'created' || result.outcome === 'updated') &&\n template.publishedVersion !== template.latestVersion\n ? [\n `Teams still run the published version. \"ekanos agents publish ${template.key}\" moves them.`,\n ]\n : [];\n return ui.result({\n title: `${OUTCOME_TITLE[result.outcome]}: ${template.key}`,\n tone: result.outcome === 'unchanged' ? 'warn' : 'ok',\n rows,\n notes,\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"agents.js","sourceRoot":"","sources":["../../src/commands/agents.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAEL,uBAAuB,EAEvB,sBAAsB,GAGvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAEL,oB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M,CAAC,CAAC,CAAC,IAAI;QACpD,IAAI;QACJ,KAAK;KACN,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type AgentTemplateBody,\n AgentTemplateBodySchema,\n type AgentTemplateDetail,\n AgentTemplateKeySchema,\n type AgentTemplateList,\n type AgentTemplateResult,\n} from '@ekanos/integration-schema';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\n\nimport {\n type AgentsApiResult,\n applyAgentTemplate,\n listAgentTemplates,\n publishAgentTemplate,\n showAgentTemplate,\n} from '../agents-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 {\n authRequiredError,\n notFoundError,\n usageError,\n validationError,\n} from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { classifyPath } from '../safe-fs';\nimport { resolveSourceTarget } from '../source-target';\nimport { type ResultRow, type Ui, pluralize } from '../ui';\nimport { runAgentsInit, withDocsHint } from './agents-init';\nimport { promptYesNo } from './publish';\n\nexport const AGENTS_SUBCOMMANDS = [\n 'init',\n 'list',\n 'show',\n 'pull',\n 'apply',\n 'publish',\n 'rollback',\n] as const;\n\ntype AgentsSubcommand = (typeof AGENTS_SUBCOMMANDS)[number];\n\n/** The file `pull` writes and `apply` reads, inside an agent's directory. */\nexport const AGENT_FILE = 'agent.json';\n/** Instructions as Markdown, beside it. Used when `agent.json` has none. */\nexport const AGENT_INSTRUCTIONS_FILE = 'AGENT.md';\n\nexport interface AgentsArgs {\n host?: string;\n source?: string;\n subcommand?: string;\n /** A template key, or for `apply` a file or directory. */\n target?: string;\n /** `publish` / `rollback`: the version to make the one teams run. */\n to?: string;\n baseVersion?: string;\n overwrite: boolean;\n out?: string;\n yes: boolean;\n /** `init`: replace the skills and CLAUDE.md even when they exist. */\n force?: boolean;\n /** `init`: `--claude` adds the docs to Claude Code without asking; `--no-claude` skips it. */\n claude?: boolean;\n dir: string;\n env: Record<string, string | undefined>;\n stdinIsTTY?: boolean;\n confirm?: (question: string) => Promise<boolean>;\n}\n\n/**\n * `agents` — the Source's agent templates (plan 239.0 / 239.2). Ekanos holds\n * them; nothing here is deployed. `apply` stores a new version (a draft\n * until published), `publish` makes a version the one every team runs,\n * `rollback` publishes an older one. `pull` writes a template out as\n * `agent.json` + `AGENT.md` for review or Git, and `apply` reads the same\n * layout back.\n */\nexport async function runAgents(\n ctx: CliContext,\n args: AgentsArgs,\n): Promise<ExitCode> {\n const subcommand = parseSubcommand(args.subcommand);\n\n // Local only: no host, no session.\n if (subcommand === 'init') {\n return runAgentsInit(ctx, {\n dir: path.resolve(args.dir, args.target ?? '.'),\n force: args.force === true,\n claude: args.claude,\n canPrompt: canPrompt(ctx, args),\n confirm: args.confirm ?? promptYesNo,\n env: args.env,\n });\n }\n\n // Read the local input before any network call, so a bad file fails fast.\n const local =\n subcommand === 'apply' ? readAgentInput(args.target, args.dir) : null;\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 AgentsClient(env, resolved.session);\n const source = resolved.source;\n\n switch (subcommand) {\n case 'list': {\n const list = await client.call((token) =>\n listAgentTemplates(env.host, token, source),\n );\n return ctx.succeed(\n { host: env.host, ...list },\n withDocsHint(ctx.ui, args.dir, listSummary(ctx.ui, list)),\n );\n }\n case 'show': {\n const key = requireKey(args.target, 'show');\n const shown = await client.call((token) =>\n showAgentTemplate(env.host, token, source, key),\n );\n return ctx.succeed(\n { host: env.host, ...shown },\n templateDetail(ctx.ui, shown.template),\n );\n }\n case 'pull': {\n const key = requireKey(args.target, 'pull');\n const shown = await client.call((token) =>\n showAgentTemplate(env.host, token, source, key),\n );\n const outDir = path.resolve(\n args.dir,\n args.out ?? path.join('agents', key),\n );\n const written = writeAgentFiles(outDir, shown.template);\n return ctx.succeed(\n {\n host: env.host,\n key,\n version: shown.template.latestVersion,\n files: written,\n },\n ctx.ui.result({\n title: `Pulled ${key} v${shown.template.latestVersion}`,\n rows: written.map((file): ResultRow => ['Wrote', file]),\n notes: [\n `Edit, then \"ekanos agents apply ${path.relative(args.dir, outDir) || '.'}\".`,\n ],\n }),\n );\n }\n case 'apply': {\n const input = local!;\n const baseVersion =\n parseVersionFlag(args.baseVersion, '--base-version') ??\n input.baseVersion;\n const result = await client.call((token) =>\n applyAgentTemplate(env.host, token, {\n source,\n key: input.key,\n body: input.body,\n baseVersion,\n overwrite: args.overwrite,\n }),\n );\n if (input.file && result.outcome !== 'unchanged') {\n recordBaseVersion(input.file, result.version);\n }\n return ctx.succeed(\n { host: env.host, ...result },\n resultSummary(ctx.ui, result),\n );\n }\n case 'publish':\n case 'rollback': {\n const key = requireKey(args.target, subcommand);\n let version = parseVersionFlag(args.to, '--to') ?? undefined;\n if (subcommand === 'rollback' && version === undefined) {\n throw usageError(\n 'rollback needs the version to go back to.',\n `Pass \"--to <n>\". \"ekanos agents show ${key}\" lists them.`,\n );\n }\n // Refuse a script with no --yes before reading anything.\n if (!args.yes && !canPrompt(ctx, args)) {\n throw validationError(\n `${subcommand === 'rollback' ? 'Rolling back' : 'Publishing'} ${key} on ${source} needs confirmation.`,\n 'It reaches every team running this agent at once. Pass --yes to confirm.',\n );\n }\n // Publish names the version it confirmed, never \"whatever is latest\n // when the request lands\" — a draft applied in between is not shipped\n // unseen to every team.\n if (version === undefined) {\n const shown = await client.call((token) =>\n showAgentTemplate(env.host, token, source, key),\n );\n version = shown.template.latestVersion;\n }\n await confirmPublish(ctx, args, {\n key,\n source,\n what:\n subcommand === 'rollback'\n ? `Roll ${key} back to version ${version}`\n : `Publish ${key} version ${version}`,\n });\n const result = await client.call((token) =>\n publishAgentTemplate(env.host, token, subcommand, {\n source,\n key,\n version,\n }),\n );\n return ctx.succeed(\n { host: env.host, ...result },\n resultSummary(ctx.ui, result),\n );\n }\n }\n}\n\n/** Every call refreshes the session once on a 401, then gives up. */\nclass AgentsClient {\n constructor(\n private readonly env: AuthEnvironment,\n private session: StoredSession,\n ) {}\n\n async call<T>(\n send: (accessToken: string) => Promise<AgentsApiResult<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 agents call.`,\n `Run \"ekanos login --host ${this.env.host}\" and retry.`,\n );\n }\n}\n\nfunction parseSubcommand(value: string | undefined): AgentsSubcommand {\n const match = AGENTS_SUBCOMMANDS.find((name) => name === value);\n if (match) return match;\n throw usageError(\n value\n ? `Unknown agents subcommand \"${value}\".`\n : 'agents needs a subcommand.',\n `Run one of: ${AGENTS_SUBCOMMANDS.map((name) => `ekanos agents ${name}`).join(', ')}.`,\n );\n}\n\nfunction requireKey(value: string | undefined, verb: string): string {\n const parsed = AgentTemplateKeySchema.safeParse(value ?? '');\n if (parsed.success) return parsed.data;\n throw usageError(\n value\n ? `\"${value}\" is not an agent key.`\n : `agents ${verb} needs an agent key.`,\n `Pass the key, e.g. \"ekanos agents ${verb} support-triage\". ` +\n `\"ekanos agents list\" shows them.`,\n );\n}\n\nfunction parseVersionFlag(\n value: string | undefined,\n flag: string,\n): number | null {\n if (value === undefined) return null;\n const version = Number(value);\n if (Number.isInteger(version) && version >= 1) return version;\n throw usageError(\n `${flag} must be a version number (got \"${value}\").`,\n `\"ekanos agents show <key>\" lists the versions.`,\n );\n}\n\ninterface AgentInput {\n key: string;\n body: AgentTemplateBody;\n baseVersion: number | null;\n /** The agent.json read, when there was one, so the new version is recorded in it. */\n file: string | null;\n}\n\n/**\n * Read `apply`'s input: a directory holding `agent.json` (and optionally\n * `AGENT.md`), or a `.json` file. The key is the file's `key`, else the\n * directory's name. `baseVersion` in the file is the version it was pulled\n * or last applied at — what the host checks for a concurrent change.\n */\nexport function readAgentInput(\n target: string | undefined,\n cwd: string,\n): AgentInput {\n if (!target) {\n throw usageError(\n 'agents apply needs a file or directory.',\n `Pass an agent directory (\"ekanos agents apply agents/support\") or a ` +\n `JSON file. \"ekanos agents pull <key>\" writes the layout.`,\n );\n }\n const resolved = path.resolve(cwd, target);\n const kind = classifyPath(resolved);\n const dir = kind === 'directory' ? resolved : path.dirname(resolved);\n const file =\n kind === 'directory' ? path.join(resolved, AGENT_FILE) : resolved;\n\n if (classifyPath(file) !== 'file') {\n throw notFoundError(\n `No ${kind === 'directory' ? AGENT_FILE : 'file'} at ${file}.`,\n `\"ekanos agents pull <key>\" writes ${AGENT_FILE} and ${AGENT_INSTRUCTIONS_FILE}.`,\n );\n }\n\n let raw: unknown;\n try {\n raw = JSON.parse(fs.readFileSync(file, 'utf8'));\n } catch (error) {\n throw validationError(\n `${file} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`,\n 'Fix the JSON and apply again.',\n );\n }\n if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {\n throw validationError(\n `${file} must hold a JSON object.`,\n 'See \"ekanos agents --help\".',\n );\n }\n\n const {\n key: rawKey,\n baseVersion: rawBase,\n $schema: _schema,\n ...rest\n } = raw as Record<string, unknown>;\n const fields: Record<string, unknown> = { ...rest };\n\n const instructionsFile = path.join(dir, AGENT_INSTRUCTIONS_FILE);\n if (\n fields.instructions === undefined &&\n classifyPath(instructionsFile) === 'file'\n ) {\n fields.instructions = fs.readFileSync(instructionsFile, 'utf8');\n }\n\n const key = AgentTemplateKeySchema.safeParse(\n typeof rawKey === 'string' ? rawKey : path.basename(dir),\n );\n if (!key.success) {\n throw validationError(\n `No usable agent key: set \"key\" in ${file}, or name the directory after it.`,\n key.error.issues[0]?.message ??\n 'Use lowercase letters, digits and hyphens.',\n );\n }\n\n const body = AgentTemplateBodySchema.safeParse(fields);\n if (!body.success) {\n throw validationError(\n [\n `${file} is not a valid agent:`,\n ...body.error.issues.map(\n (issue) => ` ${issue.path.join('.') || '(root)'}: ${issue.message}`,\n ),\n ].join('\\n'),\n `Fields: name, description, instructions (or ${AGENT_INSTRUCTIONS_FILE}), ` +\n `model, maxTurns, tools, policy, skills.`,\n );\n }\n\n const baseVersion =\n typeof rawBase === 'number' && Number.isInteger(rawBase) && rawBase >= 1\n ? rawBase\n : null;\n\n return { key: key.data, body: body.data, baseVersion, file };\n}\n\n/**\n * Write `agent.json` + `AGENT.md`. The instructions live in the Markdown so\n * they read and diff as prose; the JSON holds everything else plus the\n * version they came from.\n */\nfunction writeAgentFiles(\n outDir: string,\n template: AgentTemplateDetail,\n): string[] {\n fs.mkdirSync(outDir, { recursive: true });\n const { instructions, ...rest } = template.body;\n const json = {\n key: template.key,\n baseVersion: template.latestVersion,\n ...rest,\n };\n const jsonPath = path.join(outDir, AGENT_FILE);\n const mdPath = path.join(outDir, AGENT_INSTRUCTIONS_FILE);\n for (const target of [jsonPath, mdPath]) {\n const kind = classifyPath(target);\n if (kind !== 'missing' && kind !== 'file') {\n throw validationError(\n `Refusing to write through ${target} (${kind}).`,\n 'Remove it, or pass --out <dir>.',\n );\n }\n }\n fs.writeFileSync(jsonPath, `${JSON.stringify(json, null, 2)}\\n`);\n fs.writeFileSync(\n mdPath,\n instructions.endsWith('\\n') ? instructions : `${instructions}\\n`,\n );\n return [jsonPath, mdPath];\n}\n\n/** After a stored version, point the file at it, so the next apply is based on it. */\nfunction recordBaseVersion(file: string, version: number) {\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Record<\n string,\n unknown\n >;\n if (raw.baseVersion === version) return;\n const { key, baseVersion: _old, ...rest } = raw;\n const next =\n key === undefined\n ? { baseVersion: version, ...rest }\n : { key, baseVersion: version, ...rest };\n fs.writeFileSync(file, `${JSON.stringify(next, null, 2)}\\n`);\n}\n\nfunction canPrompt(ctx: CliContext, args: AgentsArgs): boolean {\n return !ctx.jsonMode && (args.stdinIsTTY ?? process.stdin.isTTY === true);\n}\n\n/**\n * Publishing changes what every team running the agent does, at once. A\n * human run asks first; a scripted or JSON run needs `--yes`.\n */\nasync function confirmPublish(\n ctx: CliContext,\n args: AgentsArgs,\n target: { key: string; source: string; what: string },\n) {\n if (args.yes) return;\n if (!canPrompt(ctx, args)) {\n throw validationError(\n `${target.what} on ${target.source} needs confirmation.`,\n 'It reaches every team running this agent at once. Pass --yes to confirm.',\n );\n }\n ctx.log(\n `${target.what} on ${target.source}. Every team running it follows at once.`,\n );\n const confirmed = await (args.confirm ?? promptYesNo)('Proceed? [y/N]');\n if (!confirmed) {\n throw validationError(\n `${target.what} was not confirmed.`,\n 'Nothing was changed.',\n );\n }\n}\n\nfunction versionLabel(template: {\n latestVersion: number;\n publishedVersion: number | null;\n}): string {\n if (template.publishedVersion === null)\n return `v${template.latestVersion} draft, never published`;\n if (template.publishedVersion === template.latestVersion)\n return `v${template.latestVersion} published`;\n return `v${template.publishedVersion} published, v${template.latestVersion} latest`;\n}\n\nfunction listSummary(ui: Ui, list: AgentTemplateList): string {\n if (list.templates.length === 0) {\n return ui.result({\n title: `No agents on ${list.source.slug} yet`,\n tone: 'warn',\n notes: ['\"ekanos agents apply <dir>\" stores the first one.'],\n });\n }\n return [\n ui.result({\n title: `${pluralize(list.templates.length, 'agent')} on ${list.source.slug}`,\n rows: list.templates.map((template): ResultRow => [\n template.key,\n [\n template.name,\n versionLabel(template),\n template.status === 'archived' ? 'archived' : null,\n template.teams\n ? `${pluralize(template.teams.enabled, 'team')}`\n : null,\n ]\n .filter(Boolean)\n .join(' · '),\n ]),\n }),\n ui.hint('\"ekanos agents show <key>\" shows one, with its versions.'),\n ].join('\\n\\n');\n}\n\nfunction templateDetail(ui: Ui, template: AgentTemplateDetail): string {\n const { body } = template;\n const rows: ResultRow[] = [\n ['Versions', versionLabel(template)],\n ['Model', body.model ?? 'house default'],\n ['Tools', describeTools(body)],\n [\n 'Approval',\n `reads ${body.policy.reads}, writes ${body.policy.writes}` +\n (Object.keys(body.policy.overrides).length > 0\n ? `, ${pluralize(Object.keys(body.policy.overrides).length, 'override')}`\n : ''),\n ],\n ['Skills', body.skills.length > 0 ? body.skills.join(', ') : 'none'],\n ['Connections', describeConnections(body)],\n ['Teams may add', describeCustomization(body)],\n ];\n if (template.teams) {\n rows.push([\n 'Teams',\n `${template.teams.enabled} running` +\n (template.teams.pinned > 0\n ? `, ${template.teams.pinned} pinned to an older version`\n : ''),\n ]);\n }\n rows.push([\n 'History',\n template.versions.map(\n (version) =>\n `v${version.version} ${version.createdAt.slice(0, 10)}` +\n (version.createdBy ? ` by ${version.createdBy}` : '') +\n (version.publishedAt\n ? ` · published ${version.publishedAt.slice(0, 10)}`\n : ''),\n ),\n ]);\n return ui.result({ title: `${body.name} (${template.key})`, rows });\n}\n\nfunction describeConnections(body: AgentTemplateBody): string[] {\n const owner = (connection: AgentTemplateBody['connections'][string]) =>\n connection.owner === 'source'\n ? 'one connection for the source'\n : `each team's own (${connection.team})`;\n const lines = [\n ...Object.entries(body.connections).map(\n ([slug, connection]) => `${slug}: ${owner(connection)}`,\n ),\n ...body.mcpServers.map(\n (server) => `${server.key} (MCP, ${server.url}): ${owner(server)}`,\n ),\n ];\n return lines.length > 0 ? lines : [\"each team's own (optional)\"];\n}\n\nfunction describeCustomization(body: AgentTemplateBody): string {\n const allowed = Object.entries(body.teamCustomization)\n .filter(([, on]) => on)\n .map(([knob]) => CUSTOMIZATION_LABEL[knob] ?? knob);\n return allowed.length > 0 ? allowed.join(', ') : 'nothing (template only)';\n}\n\nconst CUSTOMIZATION_LABEL: Record<string, string> = {\n mcpServers: 'own MCP servers',\n skills: 'own skills',\n integrations: 'more integrations',\n narrow: 'narrower tools',\n};\n\nfunction describeTools(body: AgentTemplateBody): string {\n if (body.tools.mode === 'read_only')\n return 'every read the team has connected';\n if (body.tools.mode === 'all') return 'every tool the team has connected';\n return (\n [...(body.tools.products ?? []), ...(body.tools.tools ?? [])].join(', ') ||\n 'none'\n );\n}\n\nconst OUTCOME_TITLE = {\n created: 'Created',\n updated: 'Stored a new version',\n unchanged: 'Unchanged',\n published: 'Published',\n 'rolled-back': 'Rolled back',\n} as const;\n\nfunction resultSummary(ui: Ui, result: AgentTemplateResult): string {\n const { template } = result;\n const rows: ResultRow[] = [['Versions', versionLabel(template)]];\n if (result.outcome === 'published' || result.outcome === 'rolled-back') {\n rows.push(['Teams updated', String(result.teamsUpdated)]);\n }\n const notes =\n (result.outcome === 'created' || result.outcome === 'updated') &&\n template.publishedVersion !== template.latestVersion\n ? [\n `Teams still run the published version. \"ekanos agents publish ${template.key}\" moves them.`,\n ]\n : [];\n return ui.result({\n title: `${OUTCOME_TITLE[result.outcome]}: ${template.key}`,\n tone: result.outcome === 'unchanged' ? 'warn' : 'ok',\n rows,\n notes,\n });\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CliContext } from '../context.js';
|
|
2
|
+
import type { ExitCode } from '../exit-codes.js';
|
|
3
|
+
export declare const APPS_SUBCOMMANDS: readonly ['show', 'set'];
|
|
4
|
+
export interface AppsArgs {
|
|
5
|
+
host?: string;
|
|
6
|
+
source?: string;
|
|
7
|
+
subcommand?: string;
|
|
8
|
+
product?: string;
|
|
9
|
+
dir: string;
|
|
10
|
+
env: Record<string, string | undefined>;
|
|
11
|
+
stdinIsTTY?: boolean;
|
|
12
|
+
/** Test seams for the questions `set` asks. */
|
|
13
|
+
ask?: (question: string) => Promise<string>;
|
|
14
|
+
askSecret?: (question: string) => Promise<string>;
|
|
15
|
+
confirm?: (question: string) => Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `apps` — a Source's provider apps: the OAuth client an integration signs
|
|
19
|
+
* every team in through (Linear's, say). `show` says whether the Source has
|
|
20
|
+
* one and which callback URL to register; `set` takes the client id and
|
|
21
|
+
* secret from the Source admin at the terminal — never from a flag, a file
|
|
22
|
+
* or a non-interactive run, so an agent driving the CLI never handles the
|
|
23
|
+
* secret.
|
|
24
|
+
*/
|
|
25
|
+
export declare function runApps(ctx: CliContext, args: AppsArgs): Promise<ExitCode>;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { setProviderApp, showProviderApp, } from '../apps-api.js';
|
|
2
|
+
import { refreshStoredSession, requireSession, resolveAuthEnvironment, } from '../auth/session.js';
|
|
3
|
+
import { authRequiredError, usageError, validationError } from '../errors.js';
|
|
4
|
+
import { resolveSourceTarget } from '../source-target.js';
|
|
5
|
+
import { promptYesNo } from './publish.js';
|
|
6
|
+
export const APPS_SUBCOMMANDS = ['show', 'set'];
|
|
7
|
+
/**
|
|
8
|
+
* `apps` — a Source's provider apps: the OAuth client an integration signs
|
|
9
|
+
* every team in through (Linear's, say). `show` says whether the Source has
|
|
10
|
+
* one and which callback URL to register; `set` takes the client id and
|
|
11
|
+
* secret from the Source admin at the terminal — never from a flag, a file
|
|
12
|
+
* or a non-interactive run, so an agent driving the CLI never handles the
|
|
13
|
+
* secret.
|
|
14
|
+
*/
|
|
15
|
+
export async function runApps(ctx, args) {
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
const subcommand = parseSubcommand(args.subcommand);
|
|
18
|
+
const product = requireProduct(args.product, subcommand);
|
|
19
|
+
if (subcommand === 'set' && !canPrompt(ctx, args)) {
|
|
20
|
+
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
|
+
}
|
|
22
|
+
const env = resolveAuthEnvironment(ctx, args.host, args.env, {
|
|
23
|
+
projectDir: args.dir,
|
|
24
|
+
});
|
|
25
|
+
const resolved = await resolveSourceTarget(env, requireSession(env.store, env.host), args);
|
|
26
|
+
const client = new AppsClient(env, resolved.session);
|
|
27
|
+
const source = resolved.source;
|
|
28
|
+
const status = await client.call((token) => showProviderApp(env.host, token, source, product));
|
|
29
|
+
if (subcommand === 'show') {
|
|
30
|
+
return ctx.succeed(Object.assign({ host: env.host }, status), summary(ctx, status));
|
|
31
|
+
}
|
|
32
|
+
ctx.log([
|
|
33
|
+
`${status.product.name} app for ${status.source.slug}`,
|
|
34
|
+
` 1. In ${status.product.name}, create an OAuth app (or open the one you use).`,
|
|
35
|
+
` 2. Register this callback URL exactly: ${status.callbackUrl}`,
|
|
36
|
+
` 3. Enter its client ID and secret below. The secret is stored in Ekanos's vault and never shown again.`,
|
|
37
|
+
].join('\n'));
|
|
38
|
+
if (status.configured) {
|
|
39
|
+
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]`);
|
|
40
|
+
if (!replace) {
|
|
41
|
+
throw validationError('Nothing was changed.', `Run "ekanos apps show ${product}" to see the current state.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const clientId = (await ((_b = args.ask) !== null && _b !== void 0 ? _b : promptLine)('Client ID: ')).trim();
|
|
45
|
+
const clientSecret = (await ((_c = args.askSecret) !== null && _c !== void 0 ? _c : promptHidden)('Client secret (hidden): ')).trim();
|
|
46
|
+
if (!clientId || !clientSecret) {
|
|
47
|
+
throw validationError('Both the client ID and the client secret are needed.', `Run "ekanos apps set ${product}" again.`);
|
|
48
|
+
}
|
|
49
|
+
const result = await client.call((token) => setProviderApp(env.host, token, {
|
|
50
|
+
source,
|
|
51
|
+
product,
|
|
52
|
+
clientId,
|
|
53
|
+
clientSecret,
|
|
54
|
+
}));
|
|
55
|
+
return ctx.succeed(Object.assign({ host: env.host }, result), ctx.ui.result({
|
|
56
|
+
title: result.replaced
|
|
57
|
+
? `Replaced the ${result.product.name} app`
|
|
58
|
+
: `Set up the ${result.product.name} app`,
|
|
59
|
+
rows: [
|
|
60
|
+
['Source', result.source.slug],
|
|
61
|
+
['Teams can connect', result.configured ? 'yes' : 'not yet'],
|
|
62
|
+
['Callback URL', result.callbackUrl],
|
|
63
|
+
],
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
function summary(ctx, status) {
|
|
67
|
+
const rows = [
|
|
68
|
+
['Source', status.source.slug],
|
|
69
|
+
[
|
|
70
|
+
'Set up',
|
|
71
|
+
status.configured
|
|
72
|
+
? 'yes — teams can connect'
|
|
73
|
+
: 'no — no team can connect yet',
|
|
74
|
+
],
|
|
75
|
+
['Callback URL', status.callbackUrl],
|
|
76
|
+
];
|
|
77
|
+
return [
|
|
78
|
+
ctx.ui.result({ title: `${status.product.name} app`, rows }),
|
|
79
|
+
...(status.configured
|
|
80
|
+
? []
|
|
81
|
+
: [
|
|
82
|
+
ctx.ui.hint(`Run "ekanos apps set ${status.product.slug}" in your terminal to enter its credentials.`),
|
|
83
|
+
]),
|
|
84
|
+
].join('\n');
|
|
85
|
+
}
|
|
86
|
+
class AppsClient {
|
|
87
|
+
constructor(env, session) {
|
|
88
|
+
this.env = env;
|
|
89
|
+
this.session = session;
|
|
90
|
+
}
|
|
91
|
+
async call(send) {
|
|
92
|
+
let result = await send(this.session.accessToken);
|
|
93
|
+
if (result.status === 'unauthorized') {
|
|
94
|
+
this.session = await refreshStoredSession(this.env, this.session);
|
|
95
|
+
result = await send(this.session.accessToken);
|
|
96
|
+
}
|
|
97
|
+
if (result.status === 'ok')
|
|
98
|
+
return result.data;
|
|
99
|
+
throw authRequiredError(`The session for ${this.env.host} could not authorize the apps call.`, `Run "ekanos login --host ${this.env.host}" and retry.`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function canPrompt(ctx, args) {
|
|
103
|
+
var _a;
|
|
104
|
+
return !ctx.jsonMode && ((_a = args.stdinIsTTY) !== null && _a !== void 0 ? _a : process.stdin.isTTY === true);
|
|
105
|
+
}
|
|
106
|
+
function parseSubcommand(value) {
|
|
107
|
+
const match = APPS_SUBCOMMANDS.find((name) => name === value);
|
|
108
|
+
if (match)
|
|
109
|
+
return match;
|
|
110
|
+
throw usageError(value ? `Unknown apps subcommand "${value}".` : 'apps needs a subcommand.', `Run one of: ${APPS_SUBCOMMANDS.map((name) => `ekanos apps ${name} <product>`).join(', ')}.`);
|
|
111
|
+
}
|
|
112
|
+
function requireProduct(value, verb) {
|
|
113
|
+
const slug = value === null || value === void 0 ? void 0 : value.trim().toLowerCase();
|
|
114
|
+
if (slug && /^[a-z0-9][a-z0-9-]*$/.test(slug))
|
|
115
|
+
return slug;
|
|
116
|
+
throw usageError(value
|
|
117
|
+
? `"${value}" is not a product slug.`
|
|
118
|
+
: `apps ${verb} needs a product.`, `Pass the product's slug, e.g. "ekanos apps ${verb} linear". "ekanos catalog" lists them.`);
|
|
119
|
+
}
|
|
120
|
+
async function promptLine(question) {
|
|
121
|
+
const readline = await import('node:readline/promises');
|
|
122
|
+
const rl = readline.createInterface({
|
|
123
|
+
input: process.stdin,
|
|
124
|
+
output: process.stderr,
|
|
125
|
+
});
|
|
126
|
+
try {
|
|
127
|
+
return await rl.question(question);
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
rl.close();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** Read a line without echoing it: the secret never appears on screen or in scrollback. */
|
|
134
|
+
async function promptHidden(question) {
|
|
135
|
+
const readline = await import('node:readline');
|
|
136
|
+
process.stderr.write(question);
|
|
137
|
+
const rl = readline.createInterface({
|
|
138
|
+
input: process.stdin,
|
|
139
|
+
output: process.stderr,
|
|
140
|
+
terminal: true,
|
|
141
|
+
});
|
|
142
|
+
// Swallow readline's echo of each keystroke; the question is already written.
|
|
143
|
+
rl._writeToOutput =
|
|
144
|
+
() => { };
|
|
145
|
+
try {
|
|
146
|
+
return await new Promise((resolve) => {
|
|
147
|
+
rl.question('', resolve);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
rl.close();
|
|
152
|
+
process.stderr.write('\n');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=apps.js.map
|
|
@@ -0,0 +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;AAEr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QAAgB;IAC1C,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;IAC/C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC/B,MAAM,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","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(\n [\n `${status.product.name} app for ${status.source.slug}`,\n ` 1. In ${status.product.name}, create an OAuth app (or open the one you use).`,\n ` 2. Register this callback URL exactly: ${status.callbackUrl}`,\n ` 3. Enter its client ID and secret below. The secret is stored in Ekanos's vault and never shown again.`,\n ].join('\\n'),\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 URL', result.callbackUrl],\n ],\n }),\n );\n}\n\nfunction summary(ctx: CliContext, status: ProviderAppStatus): string {\n const rows: ResultRow[] = [\n ['Source', status.source.slug],\n [\n 'Set up',\n status.configured\n ? 'yes — teams can connect'\n : 'no — no team can connect yet',\n ],\n ['Callback URL', status.callbackUrl],\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\nasync 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. */\nasync 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"]}
|
package/dist/commands/catalog.js
CHANGED
|
@@ -3,6 +3,7 @@ import { fetchSourceCatalog, } from '../catalog-api.js';
|
|
|
3
3
|
import { authRequiredError } from '../errors.js';
|
|
4
4
|
import { resolveSourceTarget } from '../source-target.js';
|
|
5
5
|
import { pluralize } from '../ui.js';
|
|
6
|
+
import { withDocsHint } from './agents-init.js';
|
|
6
7
|
/**
|
|
7
8
|
* `catalog` — what the Source can already do (plan 239.0). Lists every
|
|
8
9
|
* product the Source can use, with its tools, agent events and the steps
|
|
@@ -27,9 +28,9 @@ export async function runCatalog(ctx, args) {
|
|
|
27
28
|
result = await fetchSourceCatalog(env.host, session.accessToken, query);
|
|
28
29
|
}
|
|
29
30
|
const catalog = requireCatalog(result, env.host);
|
|
30
|
-
return ctx.succeed(Object.assign({ host: env.host }, catalog), args.product
|
|
31
|
+
return ctx.succeed(Object.assign({ host: env.host }, catalog), withDocsHint(ctx.ui, args.dir, args.product
|
|
31
32
|
? productDetail(ctx.ui, catalog.products[0])
|
|
32
|
-
: catalogSummary(ctx.ui, catalog));
|
|
33
|
+
: catalogSummary(ctx.ui, catalog)));
|
|
33
34
|
}
|
|
34
35
|
function requireCatalog(result, host) {
|
|
35
36
|
if (result.status === 'ok')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/commands/catalog.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAW,SAAS,EAAE,MAAM,OAAO,CAAC;AAW3C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAe,EACf,IAAiB;IAEjB,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,IAAI,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAElD,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAC/D,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IAE3B,MAAM,KAAK,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAA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olveAuthEnvironment,\n} from '../auth/session';\nimport {\n type FetchSourceCatalogResult,\n fetchSourceCatalog,\n} from '../catalog-api';\nimport type { CliContext } from '../context';\nimport { authRequiredError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { resolveSourceTarget } from '../source-target';\nimport { type Ui, pluralize } from '../ui';\n\nexport interface CatalogArgs {\n host?: string;\n source?: string;\n /** One product's detail, when given. */\n product?: string;\n dir: string;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `catalog` — what the Source can already do (plan 239.0). Lists every\n * product the Source can use, with its tools, agent events and the steps\n * left to set it up; `ekanos catalog <product>` shows one in full.\n *\n * Read before building: an agent migration asks it first, so a capability\n * the Source already has is set up rather than rebuilt. Works outside a\n * project — the Source comes from `--source`, else `ekanos.json`, else the\n * caller's only seat.\n */\nexport async function runCatalog(\n ctx: CliContext,\n args: CatalogArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n let session = requireSession(env.store, env.host);\n\n const resolved = await resolveSourceTarget(env, session, args);\n session = resolved.session;\n\n const query = { source: resolved.source, product: args.product };\n let result = await fetchSourceCatalog(env.host, session.accessToken, query);\n if (result.status === 'unauthorized') {\n session = await refreshStoredSession(env, session);\n result = await fetchSourceCatalog(env.host, session.accessToken, query);\n }\n const catalog = requireCatalog(result, env.host);\n\n return ctx.succeed(\n { host: env.host, ...catalog },\n args.product\n ? productDetail(ctx.ui, catalog.products[0]!)\n : catalogSummary(ctx.ui, catalog),\n );\n}\n\nfunction requireCatalog(\n result: FetchSourceCatalogResult,\n host: string,\n): SourceCatalog {\n if (result.status === 'ok') return result.catalog;\n throw authRequiredError(\n `The session for ${host} could not authorize the catalog read.`,\n `Run \"ekanos login --host ${host}\" and retry.`,\n );\n}\n\nconst AVAILABILITY_LABEL = {\n enabled: 'Enabled on this Source',\n 'turned-off': 'Granted but switched off',\n available: 'Available — ask Ekanos to enable',\n} as const;\n\nfunction catalogSummary(ui: Ui, catalog: SourceCatalog): string {\n const blocks = (['enabled', 'turned-off', 'available'] as const)\n .map((availability) => {\n const products = catalog.products.filter(\n (product) => product.availability === availability,\n );\n if (products.length === 0) return null;\n return ui.result({\n title: `${AVAILABILITY_LABEL[availability]} (${products.length})`,\n tone: availability === 'enabled' ? 'ok' : 'warn',\n rows: products.map((product): [string, string] => [\n product.slug,\n [product.name, describeShape(product), openSteps(product)]\n .filter(Boolean)\n .join(' · '),\n ]),\n });\n })\n .filter((block): block is string => block !== null);\n\n return [\n ...blocks,\n ui.hint(\n `${pluralize(catalog.products.length, 'product')} on ${catalog.source.slug}. ` +\n `\"ekanos catalog <product>\" shows tools, agent events and setup steps.`,\n ),\n ].join('\\n\\n');\n}\n\nfunction productDetail(ui: Ui, product: CatalogProduct): string {\n const rows: [string, string | string[]][] = [\n ['What', product.summary ?? '—'],\n [\n 'Kind',\n product.kind === 'experience' ? 'Ekanos Experience' : 'Integration',\n ],\n ['Status', AVAILABILITY_LABEL[product.availability]],\n ];\n if (product.connectedTeams !== null) {\n rows.push(['Teams connected', String(product.connectedTeams)]);\n }\n if (product.tools.length > 0) {\n rows.push([\n 'Tools',\n product.tools.map(\n (tool) =>\n `${tool.name} (${tool.effect}${tool.sensitivity === 'undeclared' ? '' : `, ${tool.sensitivity}`})`,\n ),\n ]);\n }\n if (product.agentEvents.length > 0) {\n rows.push([\n 'Agent triggers',\n product.agentEvents.map((event) => `${event.id} — ${event.label}`),\n ]);\n }\n if (product.agentReplyTool) {\n rows.push(['Replies with', product.agentReplyTool]);\n }\n rows.push([\n 'Setup',\n product.setupSteps.map(\n (step, index) =>\n `${index + 1}. [${step.state}] ${step.title} (${step.actor}) — ${step.detail}` +\n (step.guideUrl ? ` ${step.guideUrl}` : ''),\n ),\n ]);\n\n return ui.result({ title: `${product.name} (${product.slug})`, rows });\n}\n\nfunction describeShape(product: CatalogProduct): string {\n const parts = [\n product.tools.length > 0 ? pluralize(product.tools.length, 'tool') : null,\n product.agentEvents.length > 0\n ? pluralize(product.agentEvents.length, 'agent trigger')\n : null,\n ].filter(Boolean);\n return parts.join(', ');\n}\n\nfunction openSteps(product: CatalogProduct): string {\n const open = product.setupSteps.filter((step) => step.state === 'todo');\n return open.length === 0 ? '' : `${pluralize(open.length, 'step')} left`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/commands/catalog.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAW,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAW7C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,GAAe,EACf,IAAiB;IAEjB,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,IAAI,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IAElD,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAC/D,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;IAE3B,MAAM,KAAK,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IACjE,IAAI,MAAM,GAAG,MAAM,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAA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AK,KAAK,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,MAAM,EAAE;YAC9E,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC7C;KACF,CAAC,CAAC;IAEH,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,aAAa,CAAC,OAAuB;IAC5C,MAAM,KAAK,GAAG;QACZ,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI;QACzE,OAAO,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC;YAC5B,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC;YACxD,CAAC,CAAC,IAAI;KACT,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAClB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,SAAS,CAAC,OAAuB;IACxC,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;IACxE,OAAO,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC;AAC3E,CAAC","sourcesContent":["import type { CatalogProduct, SourceCatalog } from '@ekanos/integration-schema';\n\nimport {\n refreshStoredSession,\n requireSession,\n resolveAuthEnvironment,\n} from '../auth/session';\nimport {\n type FetchSourceCatalogResult,\n fetchSourceCatalog,\n} from '../catalog-api';\nimport type { CliContext } from '../context';\nimport { authRequiredError } from '../errors';\nimport type { ExitCode } from '../exit-codes';\nimport { resolveSourceTarget } from '../source-target';\nimport { type Ui, pluralize } from '../ui';\nimport { withDocsHint } from './agents-init';\n\nexport interface CatalogArgs {\n host?: string;\n source?: string;\n /** One product's detail, when given. */\n product?: string;\n dir: string;\n env: Record<string, string | undefined>;\n}\n\n/**\n * `catalog` — what the Source can already do (plan 239.0). Lists every\n * product the Source can use, with its tools, agent events and the steps\n * left to set it up; `ekanos catalog <product>` shows one in full.\n *\n * Read before building: an agent migration asks it first, so a capability\n * the Source already has is set up rather than rebuilt. Works outside a\n * project — the Source comes from `--source`, else `ekanos.json`, else the\n * caller's only seat.\n */\nexport async function runCatalog(\n ctx: CliContext,\n args: CatalogArgs,\n): Promise<ExitCode> {\n const env = resolveAuthEnvironment(ctx, args.host, args.env, {\n projectDir: args.dir,\n });\n let session = requireSession(env.store, env.host);\n\n const resolved = await resolveSourceTarget(env, session, args);\n session = resolved.session;\n\n const query = { source: resolved.source, product: args.product };\n let result = await fetchSourceCatalog(env.host, session.accessToken, query);\n if (result.status === 'unauthorized') {\n session = await refreshStoredSession(env, session);\n result = await fetchSourceCatalog(env.host, session.accessToken, query);\n }\n const catalog = requireCatalog(result, env.host);\n\n return ctx.succeed(\n { host: env.host, ...catalog },\n withDocsHint(\n ctx.ui,\n args.dir,\n args.product\n ? productDetail(ctx.ui, catalog.products[0]!)\n : catalogSummary(ctx.ui, catalog),\n ),\n );\n}\n\nfunction requireCatalog(\n result: FetchSourceCatalogResult,\n host: string,\n): SourceCatalog {\n if (result.status === 'ok') return result.catalog;\n throw authRequiredError(\n `The session for ${host} could not authorize the catalog read.`,\n `Run \"ekanos login --host ${host}\" and retry.`,\n );\n}\n\nconst AVAILABILITY_LABEL = {\n enabled: 'Enabled on this Source',\n 'turned-off': 'Granted but switched off',\n available: 'Available — ask Ekanos to enable',\n} as const;\n\nfunction catalogSummary(ui: Ui, catalog: SourceCatalog): string {\n const blocks = (['enabled', 'turned-off', 'available'] as const)\n .map((availability) => {\n const products = catalog.products.filter(\n (product) => product.availability === availability,\n );\n if (products.length === 0) return null;\n return ui.result({\n title: `${AVAILABILITY_LABEL[availability]} (${products.length})`,\n tone: availability === 'enabled' ? 'ok' : 'warn',\n rows: products.map((product): [string, string] => [\n product.slug,\n [product.name, describeShape(product), openSteps(product)]\n .filter(Boolean)\n .join(' · '),\n ]),\n });\n })\n .filter((block): block is string => block !== null);\n\n return [\n ...blocks,\n ui.hint(\n `${pluralize(catalog.products.length, 'product')} on ${catalog.source.slug}. ` +\n `\"ekanos catalog <product>\" shows tools, agent events and setup steps.`,\n ),\n ].join('\\n\\n');\n}\n\nfunction productDetail(ui: Ui, product: CatalogProduct): string {\n const rows: [string, string | string[]][] = [\n ['What', product.summary ?? '—'],\n [\n 'Kind',\n product.kind === 'experience' ? 'Ekanos Experience' : 'Integration',\n ],\n ['Status', AVAILABILITY_LABEL[product.availability]],\n ];\n if (product.connectedTeams !== null) {\n rows.push(['Teams connected', String(product.connectedTeams)]);\n }\n if (product.tools.length > 0) {\n rows.push([\n 'Tools',\n product.tools.map(\n (tool) =>\n `${tool.name} (${tool.effect}${tool.sensitivity === 'undeclared' ? '' : `, ${tool.sensitivity}`})`,\n ),\n ]);\n }\n if (product.agentEvents.length > 0) {\n rows.push([\n 'Agent triggers',\n product.agentEvents.map((event) => `${event.id} — ${event.label}`),\n ]);\n }\n if (product.agentReplyTool) {\n rows.push(['Replies with', product.agentReplyTool]);\n }\n rows.push([\n 'Setup',\n product.setupSteps.map(\n (step, index) =>\n `${index + 1}. [${step.state}] ${step.title} (${step.actor}) — ${step.detail}` +\n (step.guideUrl ? ` ${step.guideUrl}` : ''),\n ),\n ]);\n\n return ui.result({ title: `${product.name} (${product.slug})`, rows });\n}\n\nfunction describeShape(product: CatalogProduct): string {\n const parts = [\n product.tools.length > 0 ? pluralize(product.tools.length, 'tool') : null,\n product.agentEvents.length > 0\n ? pluralize(product.agentEvents.length, 'agent trigger')\n : null,\n ].filter(Boolean);\n return parts.join(', ');\n}\n\nfunction openSteps(product: CatalogProduct): string {\n const open = product.setupSteps.filter((step) => step.state === 'todo');\n return open.length === 0 ? '' : `${pluralize(open.length, 'step')} left`;\n}\n"]}
|
package/dist/commands/init.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ export declare function runInit(ctx: CliContext, args: InitArgs): Promise<ExitCo
|
|
|
103
103
|
*
|
|
104
104
|
* `skillsRoot` is injectable for tests; real callers take the default.
|
|
105
105
|
*/
|
|
106
|
-
export declare function copyBundledSkillTrees(targetDir: string, force: boolean, skillsRoot?: string, onRefusal?: 'throw' | 'collect'): {
|
|
106
|
+
export declare function copyBundledSkillTrees(targetDir: string, force: boolean, skillsRoot?: string, onRefusal?: 'throw' | 'collect', only?: readonly string[]): {
|
|
107
107
|
created: string[];
|
|
108
108
|
skipped: SkippedFile[];
|
|
109
109
|
refused: string[];
|
package/dist/commands/init.js
CHANGED
|
@@ -302,7 +302,7 @@ function renderEkanosConfig(vars, docs) {
|
|
|
302
302
|
*
|
|
303
303
|
* `skillsRoot` is injectable for tests; real callers take the default.
|
|
304
304
|
*/
|
|
305
|
-
export function copyBundledSkillTrees(targetDir, force, skillsRoot = path.join(templatesDir(), 'skills'), onRefusal = 'throw') {
|
|
305
|
+
export function copyBundledSkillTrees(targetDir, force, skillsRoot = path.join(templatesDir(), 'skills'), onRefusal = 'throw', only) {
|
|
306
306
|
if (!fs.existsSync(skillsRoot))
|
|
307
307
|
return { created: [], skipped: [], refused: [] };
|
|
308
308
|
const created = [];
|
|
@@ -312,6 +312,7 @@ export function copyBundledSkillTrees(targetDir, force, skillsRoot = path.join(t
|
|
|
312
312
|
.readdirSync(skillsRoot, { withFileTypes: true })
|
|
313
313
|
.filter((entry) => entry.isDirectory())
|
|
314
314
|
.map((entry) => entry.name)
|
|
315
|
+
.filter((name) => !only || only.includes(name))
|
|
315
316
|
.sort();
|
|
316
317
|
for (const name of skillDirs) {
|
|
317
318
|
const destBase = path.join('.claude', 'skills', name);
|