@ekanos/cli 0.28.1 → 0.30.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 +14 -5
- package/dist/auth/ekanos-api.d.ts +8 -1
- package/dist/auth/ekanos-api.js +14 -2
- package/dist/auth/ekanos-api.js.map +1 -1
- package/dist/bin.js +9 -1
- package/dist/bin.js.map +1 -1
- package/dist/commands/dev.js +5 -5
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/feedback.d.ts +38 -0
- package/dist/commands/feedback.js +234 -0
- package/dist/commands/feedback.js.map +1 -0
- package/dist/commands/publish.js +1 -1
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/sources.js +4 -1
- package/dist/commands/sources.js.map +1 -1
- package/dist/commands/status.js +1 -1
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/validate.js +2 -2
- package/dist/commands/validate.js.map +1 -1
- package/dist/context.d.ts +11 -1
- package/dist/context.js +12 -1
- package/dist/context.js.map +1 -1
- package/dist/feedback-api.d.ts +70 -0
- package/dist/feedback-api.js +111 -0
- package/dist/feedback-api.js.map +1 -0
- package/dist/feedback-context.d.ts +31 -0
- package/dist/feedback-context.js +209 -0
- package/dist/feedback-context.js.map +1 -0
- package/dist/feedback-updates.d.ts +16 -0
- package/dist/feedback-updates.js +174 -0
- package/dist/feedback-updates.js.map +1 -0
- package/dist/http-trace.d.ts +19 -0
- package/dist/http-trace.js +47 -0
- package/dist/http-trace.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +172 -13
- package/dist/index.js.map +1 -1
- package/dist/last-error.d.ts +17 -0
- package/dist/last-error.js +56 -0
- package/dist/last-error.js.map +1 -0
- package/dist/toolchain-api.d.ts +2 -1
- package/dist/toolchain-api.js +2 -2
- package/dist/toolchain-api.js.map +1 -1
- package/dist/toolchain-resolve.d.ts +4 -0
- package/dist/toolchain-resolve.js +11 -7
- package/dist/toolchain-resolve.js.map +1 -1
- package/dist/update-notice.d.ts +31 -8
- package/dist/update-notice.js +161 -31
- package/dist/update-notice.js.map +1 -1
- package/package.json +2 -2
- package/templates/AGENTS.md.tmpl +19 -0
- package/templates/claude-skill.md.tmpl +18 -0
- package/templates/experience/package.json.tmpl +4 -4
- package/templates/package.json.tmpl +4 -4
- package/templates/skills/build-agent/SKILL.md +18 -0
- package/templates/skills/build-integration/SKILL.md +18 -0
package/dist/context.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAiB,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAW,QAAQ,EAAE,MAAM,MAAM,CAAC;AAgDzC;;;;;;;;GAQG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,UAAU;IAuBrB,YAAY,KAAK,GAAiB,EAAE;;QAF5B,YAAO,GAAG,KAAK,CAAC;QAGtB,MAAM,MAAM,SAAG,KAAK,CAAC,MAAM,mCAAI,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7D,MAAM,MAAM,SAAG,KAAK,CAAC,MAAM,mCAAI,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7D,MAAM,GAAG,SAAG,KAAK,CAAC,GAAG,mCAAI,OAAO,CAAC,GAAG,CAAC;QAErC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,GAAG,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,KAAK,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;QAE1D,4EAA4E;QAC5E,yEAAyE;QACzE,qEAAqE;QACrE,4EAA4E;QAC5E,4BAA4B;QAC5B,MAAM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CAAC,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;YACvD,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,QAAQ,CAAC;IACzB,CAAC;IAEO,MAAM;QACZ,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,8DAA8D;gBAC5D,mEAAmE;gBACnE,wCAAwC,CAC3C,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAChC,GAAiD;IAEjD,OAAO,CACL,GAAG,CAAC,UAAU,KAAK,GAAG;QACtB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;QAC1B,GAAG,CAAC,YAAY,KAAK,GAAG;QACxB,GAAG,CAAC,UAAU,KAAK,GAAG;QACtB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CACtB,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,MAA0B;IAC/C,OAAO;QACL,KAAK,EAAE,CAAC,KAAa,EAAE,EAAE;YACvB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC;AACJ,CAAC","sourcesContent":["import { CliError } from './errors';\nimport { EXIT_CODES, type ExitCode } from './exit-codes';\nimport { echoInvocation } from './invocation';\nimport { type Ui, createUi } from './ui';\n\n/**\n * A single writable sink. Real streams satisfy this; tests pass a capturing\n * buffer so the stdout-purity invariant can be asserted byte-for-byte.\n */\nexport interface WriteStream {\n write(chunk: string): void;\n isTTY?: boolean;\n}\n\nexport interface ContextInput {\n /**\n * The user's EXPLICIT preference, already parsed: `true` for `--json`,\n * `false` for `--no-json`, `undefined` when neither was passed. The\n * undefined case is what allows the mode to be inferred instead.\n */\n jsonFlag?: boolean;\n stdout?: WriteStream;\n stderr?: WriteStream;\n /** Overrides process.env for CLAUDECODE detection (tests). */\n env?: Record<string, string | undefined>;\n}\n\n/** The success envelope. */\ninterface OkEnvelope {\n ok: true;\n data: unknown;\n}\n\n/** The error envelope. `data` is optional — validate carries its findings here. */\ninterface ErrEnvelope {\n ok: false;\n data?: unknown;\n error: { code: string; message: string; hint: string; docs?: string };\n}\n\n/** See `fail`'s doc comment — the human-mode epilogue seam for a command that already rendered a findings block. */\ninterface FindingsSummary {\n /** The command name to name in the summary line, e.g. \"ekanos validate\". */\n command: string;\n errorCount: number;\n}\n\nexport interface FailOptions {\n findingsSummary?: FindingsSummary;\n}\n\n/**\n * `data` is deliberately `unknown` above — each verb owns its own shape — but\n * one convention spans several of them: `validate`, `dev`, `publish` and\n * `status` all add an OPTIONAL `toolchain` field to `data` (never to the\n * envelope's top level) when the proactive update check in `update-notice.ts`\n * finds this CLI is behind. See that file's `ToolchainNoticeData` for the\n * shape, and `README.md`'s \"Keeping the toolchain current\" section for the\n * full contract. It is absent, not `null`, when there is nothing to report.\n */\n\n/**\n * The agent-native output envelope, resolved ONCE at startup and threaded\n * through every command.\n *\n * The load-bearing invariant: in JSON mode, stdout receives EXACTLY ONE JSON\n * object for the whole process — nothing else, ever. Every progress line, warn,\n * and scrap of human prose goes to stderr. This is the single most common way\n * an agent's tool call breaks (a stray log line on stdout makes the JSON\n * unparseable), so the context enforces it structurally: `succeed`/`fail` are\n * the only writers of stdout, and a `settled` latch makes a second call throw\n * rather than emit a second object.\n */\nexport class CliContext {\n readonly jsonMode: boolean;\n /**\n * The environment the context resolved against — exposed so decoration\n * (the gradient banner) can honour `NO_COLOR` / `EKANOS_NO_BANNER` without\n * every call site threading `process.env` through by hand.\n */\n readonly env: Readonly<Record<string, string | undefined>>;\n /**\n * The style layer (`ui.ts`), resolved once against stderr — the stream\n * every human-mode render target uses — so every command shares one color\n * decision instead of each re-deriving it. See `ui.ts` for the tokens and\n * components this carries.\n */\n readonly ui: Ui;\n /** A coding agent's marker is in the environment (`isAgentEnvironment`). */\n readonly agentDetected: boolean;\n /** `--json` was passed — not inferred from a pipe. */\n private readonly explicitJson: boolean;\n private readonly stdout: WriteStream;\n private readonly stderr: WriteStream;\n private settled = false;\n\n constructor(input: ContextInput = {}) {\n const stdout = input.stdout ?? defaultStream(process.stdout);\n const stderr = input.stderr ?? defaultStream(process.stderr);\n const env = input.env ?? process.env;\n\n this.stdout = stdout;\n this.stderr = stderr;\n this.env = env;\n this.ui = createUi({ isTTY: stderr.isTTY === true, env });\n\n // Resolve JSON mode once. An EXPLICIT flag always wins: `--json` forces the\n // envelope on even at a terminal, `--no-json` forces the human form even\n // when piped. Only when the user expressed no preference is the mode\n // inferred — from a non-TTY stdout (piped into another program or an agent)\n // or the CLAUDECODE marker.\n const nonTty = stdout.isTTY !== true;\n this.jsonMode = input.jsonFlag ?? (nonTty || env.CLAUDECODE === '1');\n this.explicitJson = input.jsonFlag === true;\n this.agentDetected = isAgentEnvironment(env);\n }\n\n /** Whether stderr is a real terminal — decoration (the banner) gates on this. */\n get stderrIsTTY(): boolean {\n return this.stderr.isTTY === true;\n }\n\n /**\n * Whether stdout is a real terminal — `wizard.ts`'s `canWizard` gates on\n * this (clack renders to stdout, unlike the rest of this CLI's human\n * output). `ctx.jsonMode` being false does not by itself guarantee this:\n * `--no-json` forces human mode even against a piped stdout.\n */\n get stdoutIsTTY(): boolean {\n return this.stdout.isTTY === true;\n }\n\n /** Human/progress output — ALWAYS stderr, so stdout stays pure in JSON mode. */\n log(message: string): void {\n this.stderr.write(`${echoInvocation(message)}\\n`);\n }\n\n /** A warning — stderr, no ANSI. */\n warn(message: string): void {\n this.stderr.write(`${echoInvocation(message)}\\n`);\n }\n\n /**\n * Emit the `claude-code-hint` protocol line to STDERR. Used on --help and on\n * an unknown command so an agent reading stderr is told what to do next\n * without the line ever touching stdout.\n */\n emitClaudeCodeHint(payload: Record<string, unknown>): void {\n // The protocol line is machine-readable JSON for an agent reading\n // stderr. It is written only when an agent is known to be reading: one\n // was detected in the environment, or `--json` was asked for. A person —\n // at a terminal, or piping into `less` or `grep` — gets the readable\n // error or help text, never a line of JSON above it.\n if (!this.explicitJson && !this.agentDetected) return;\n\n this.stderr.write(`claude-code-hint: ${JSON.stringify(payload)}\\n`);\n }\n\n /**\n * Terminal success. Writes the single stdout object (JSON mode) or a concise\n * human line (human mode). Returns the OK exit code so the caller can end the\n * process with it. Idempotent-by-latch: a second settle throws.\n */\n succeed(data: unknown, humanSummary?: string): ExitCode {\n this.settle();\n if (this.jsonMode) {\n const envelope: OkEnvelope = { ok: true, data };\n this.stdout.write(`${JSON.stringify(envelope)}\\n`);\n } else if (humanSummary !== '') {\n // An explicit empty summary means \"already said it\" — a wizard flow's\n // outro is the result, and a trailing line would just repeat it.\n this.stdout.write(`${echoInvocation(humanSummary ?? 'OK')}\\n`);\n }\n return EXIT_CODES.OK;\n }\n\n /**\n * Terminal failure. Writes the single stdout error object (JSON mode) or the\n * message + hint to stderr (human mode). Returns the error's exit code.\n *\n * `error.hint` is guaranteed non-empty by CliError's constructor, so the\n * envelope's \"every error carries a hint\" invariant holds for every path\n * that reaches here.\n *\n * `options.findingsSummary` is the seam for a command that has ALREADY\n * rendered the shared findings block to stderr (human mode) before calling\n * this — `validate`'s and `publish`'s gate-refusal paths. Passing it swaps\n * the default two-line `Error: … / Hint: …` epilogue (whose hint always\n * points at the JSON-only `data.findings`) for one short summary line,\n * `✖ <command> failed: <n> error(s)`, so a partner never reads the same\n * finding jargon twice. JSON mode is completely unaffected either way —\n * `error.hint` always carries the original, JSON-only-appropriate text in\n * the envelope.\n */\n fail(error: CliError, data?: unknown, options?: FailOptions): ExitCode {\n this.failWith({\n code: error.code,\n message: error.message,\n hint: error.hint,\n docs: error.docs,\n exitCode: error.exitCode,\n data,\n findingsSummary: options?.findingsSummary,\n });\n return error.exitCode;\n }\n\n /**\n * The low-level failure emitter. Used directly by `test`, whose exit code is\n * a TRANSPARENT passthrough of the delegated runner's exit code (which is not\n * one of the CLI's own frozen numeric conditions) and whose error `code` is\n * an out-of-taxonomy string. Enforces the same non-empty-hint invariant as\n * CliError so no failure path can emit an empty hint.\n */\n failWith(params: {\n code: string;\n message: string;\n hint: string;\n /** A docs URL for this error; JSON gets a `docs` field, human mode a line. */\n docs?: string;\n exitCode: number;\n data?: unknown;\n findingsSummary?: FindingsSummary;\n }): number {\n this.settle();\n if (!params.hint || params.hint.trim().length === 0) {\n throw new Error(\n `failWith for \"${params.message}\" was given an empty hint. Every CLI ` +\n 'error must carry an imperative remediation.',\n );\n }\n // The commands a hint names, as this run was invoked (`invocation.ts`).\n const message = echoInvocation(params.message);\n const hint = echoInvocation(params.hint);\n if (this.jsonMode) {\n const envelope: ErrEnvelope = {\n ok: false,\n ...(params.data !== undefined ? { data: params.data } : {}),\n error: {\n code: params.code,\n message,\n hint,\n ...(params.docs ? { docs: params.docs } : {}),\n },\n };\n this.stdout.write(`${JSON.stringify(envelope)}\\n`);\n } else if (params.findingsSummary) {\n const { command, errorCount } = params.findingsSummary;\n this.stderr.write(\n `${this.ui.err(\n `${this.ui.glyphs.err} ${command} failed: ${errorCount} error${\n errorCount === 1 ? '' : 's'\n }`,\n )}\\n`,\n );\n } else {\n this.stderr.write(`${this.ui.err('Error:')} ${message}\\n`);\n this.stderr.write(`${this.ui.dim('Hint:')} ${hint}\\n`);\n if (params.docs) {\n this.stderr.write(`${this.ui.dim('Docs:')} ${params.docs}\\n`);\n }\n }\n return params.exitCode;\n }\n\n private settle(): void {\n if (this.settled) {\n throw new Error(\n 'CliContext settled twice — a command tried to emit a second ' +\n 'terminal result. In JSON mode this would corrupt stdout with two ' +\n 'objects. This is a bug in the command.',\n );\n }\n this.settled = true;\n }\n}\n\n/**\n * The environment markers coding agents set in the shells they run:\n * Claude Code (`CLAUDECODE=1`), Codex (`CODEX_SANDBOX`), Cursor's agent\n * (`CURSOR_AGENT=1`), Gemini CLI (`GEMINI_CLI=1`), and the generic\n * `AI_AGENT`. A pipe alone is not one — a person piping into `grep` is not\n * an agent.\n */\nexport function isAgentEnvironment(\n env: Readonly<Record<string, string | undefined>>,\n): boolean {\n return (\n env.CLAUDECODE === '1' ||\n Boolean(env.CODEX_SANDBOX) ||\n env.CURSOR_AGENT === '1' ||\n env.GEMINI_CLI === '1' ||\n Boolean(env.AI_AGENT)\n );\n}\n\nfunction defaultStream(stream: NodeJS.WriteStream): WriteStream {\n return {\n write: (chunk: string) => {\n stream.write(chunk);\n },\n isTTY: stream.isTTY,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAiB,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAW,QAAQ,EAAE,MAAM,MAAM,CAAC;AAgDzC;;;;;;;;GAQG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,UAAU;IAwBrB,YAAY,KAAK,GAAiB,EAAE;;QAH5B,YAAO,GAAG,KAAK,CAAC;QAChB,WAAM,GAA8C,IAAI,CAAC;QAG/D,MAAM,MAAM,SAAG,KAAK,CAAC,MAAM,mCAAI,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7D,MAAM,MAAM,SAAG,KAAK,CAAC,MAAM,mCAAI,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7D,MAAM,GAAG,SAAG,KAAK,CAAC,GAAG,mCAAI,OAAO,CAAC,GAAG,CAAC;QAErC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,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,aAAa,CAAC,MAA0B;IAC/C,OAAO;QACL,KAAK,EAAE,CAAC,KAAa,EAAE,EAAE;YACvB,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC;AACJ,CAAC","sourcesContent":["import { CliError } from './errors';\nimport { EXIT_CODES, type ExitCode } from './exit-codes';\nimport { echoInvocation } from './invocation';\nimport { type Ui, createUi } from './ui';\n\n/**\n * A single writable sink. Real streams satisfy this; tests pass a capturing\n * buffer so the stdout-purity invariant can be asserted byte-for-byte.\n */\nexport interface WriteStream {\n write(chunk: string): void;\n isTTY?: boolean;\n}\n\nexport interface ContextInput {\n /**\n * The user's EXPLICIT preference, already parsed: `true` for `--json`,\n * `false` for `--no-json`, `undefined` when neither was passed. The\n * undefined case is what allows the mode to be inferred instead.\n */\n jsonFlag?: boolean;\n stdout?: WriteStream;\n stderr?: WriteStream;\n /** Overrides process.env for CLAUDECODE detection (tests). */\n env?: Record<string, string | undefined>;\n}\n\n/** The success envelope. */\ninterface OkEnvelope {\n ok: true;\n data: unknown;\n}\n\n/** The error envelope. `data` is optional — validate carries its findings here. */\ninterface ErrEnvelope {\n ok: false;\n data?: unknown;\n error: { code: string; message: string; hint: string; docs?: string };\n}\n\n/** See `fail`'s doc comment — the human-mode epilogue seam for a command that already rendered a findings block. */\ninterface FindingsSummary {\n /** The command name to name in the summary line, e.g. \"ekanos validate\". */\n command: string;\n errorCount: number;\n}\n\nexport interface FailOptions {\n findingsSummary?: FindingsSummary;\n}\n\n/**\n * `data` is deliberately `unknown` above — each verb owns its own shape — but\n * one convention spans several of them: `validate`, `dev`, `publish` and\n * `status` all add an OPTIONAL `toolchain` field to `data` (never to the\n * envelope's top level) when the proactive update check in `update-notice.ts`\n * finds this CLI is behind. See that file's `ToolchainNoticeData` for the\n * shape, and `README.md`'s \"Keeping the toolchain current\" section for the\n * full contract. It is absent, not `null`, when there is nothing to report.\n */\n\n/**\n * The agent-native output envelope, resolved ONCE at startup and threaded\n * through every command.\n *\n * The load-bearing invariant: in JSON mode, stdout receives EXACTLY ONE JSON\n * object for the whole process — nothing else, ever. Every progress line, warn,\n * and scrap of human prose goes to stderr. This is the single most common way\n * an agent's tool call breaks (a stray log line on stdout makes the JSON\n * unparseable), so the context enforces it structurally: `succeed`/`fail` are\n * the only writers of stdout, and a `settled` latch makes a second call throw\n * rather than emit a second object.\n */\nexport class CliContext {\n readonly jsonMode: boolean;\n /**\n * The environment the context resolved against — exposed so decoration\n * (the gradient banner) can honour `NO_COLOR` / `EKANOS_NO_BANNER` without\n * every call site threading `process.env` through by hand.\n */\n readonly env: Readonly<Record<string, string | undefined>>;\n /**\n * The style layer (`ui.ts`), resolved once against stderr — the stream\n * every human-mode render target uses — so every command shares one color\n * decision instead of each re-deriving it. See `ui.ts` for the tokens and\n * components this carries.\n */\n readonly ui: Ui;\n /** A coding agent's marker is in the environment (`isAgentEnvironment`). */\n readonly agentDetected: boolean;\n /** `--json` was passed — not inferred from a pipe. */\n private readonly explicitJson: boolean;\n private readonly stdout: WriteStream;\n private readonly stderr: WriteStream;\n private settled = false;\n private failed: { code: string; exitCode: number } | null = null;\n\n constructor(input: ContextInput = {}) {\n const stdout = input.stdout ?? defaultStream(process.stdout);\n const stderr = input.stderr ?? defaultStream(process.stderr);\n const env = input.env ?? process.env;\n\n this.stdout = stdout;\n this.stderr = stderr;\n this.env = env;\n this.ui = createUi({ isTTY: stderr.isTTY === true, env });\n\n // Resolve JSON mode once. An EXPLICIT flag always wins: `--json` forces the\n // envelope on even at a terminal, `--no-json` forces the human form even\n // when piped. Only when the user expressed no preference is the mode\n // inferred — from a non-TTY stdout (piped into another program or an agent)\n // or the CLAUDECODE marker.\n const nonTty = stdout.isTTY !== true;\n this.jsonMode = input.jsonFlag ?? (nonTty || env.CLAUDECODE === '1');\n this.explicitJson = input.jsonFlag === true;\n this.agentDetected = isAgentEnvironment(env);\n }\n\n /**\n * The code and exit code this run failed with, once it has — what a\n * recorded failure (`last-error.ts`) and the report hint name. Null on\n * success or before the run settles.\n */\n get failure(): { code: string; exitCode: number } | null {\n return this.failed;\n }\n\n /** Whether stderr is a real terminal — decoration (the banner) gates on this. */\n get stderrIsTTY(): boolean {\n return this.stderr.isTTY === true;\n }\n\n /**\n * Whether stdout is a real terminal — `wizard.ts`'s `canWizard` gates on\n * this (clack renders to stdout, unlike the rest of this CLI's human\n * output). `ctx.jsonMode` being false does not by itself guarantee this:\n * `--no-json` forces human mode even against a piped stdout.\n */\n get stdoutIsTTY(): boolean {\n return this.stdout.isTTY === true;\n }\n\n /** Human/progress output — ALWAYS stderr, so stdout stays pure in JSON mode. */\n log(message: string): void {\n this.stderr.write(`${echoInvocation(message)}\\n`);\n }\n\n /** A warning — stderr, no ANSI. */\n warn(message: string): void {\n this.stderr.write(`${echoInvocation(message)}\\n`);\n }\n\n /**\n * Emit the `claude-code-hint` protocol line to STDERR. Used on --help and on\n * an unknown command so an agent reading stderr is told what to do next\n * without the line ever touching stdout.\n */\n emitClaudeCodeHint(payload: Record<string, unknown>): boolean {\n // The protocol line is machine-readable JSON for an agent reading\n // stderr. It is written only when an agent is known to be reading: one\n // was detected in the environment, or `--json` was asked for. A person —\n // at a terminal, or piping into `less` or `grep` — gets the readable\n // error or help text, never a line of JSON above it.\n if (!this.explicitJson && !this.agentDetected) return false;\n\n this.stderr.write(`claude-code-hint: ${JSON.stringify(payload)}\\n`);\n return true;\n }\n\n /**\n * Terminal success. Writes the single stdout object (JSON mode) or a concise\n * human line (human mode). Returns the OK exit code so the caller can end the\n * process with it. Idempotent-by-latch: a second settle throws.\n */\n succeed(data: unknown, humanSummary?: string): ExitCode {\n this.settle();\n if (this.jsonMode) {\n const envelope: OkEnvelope = { ok: true, data };\n this.stdout.write(`${JSON.stringify(envelope)}\\n`);\n } else if (humanSummary !== '') {\n // An explicit empty summary means \"already said it\" — a wizard flow's\n // outro is the result, and a trailing line would just repeat it.\n this.stdout.write(`${echoInvocation(humanSummary ?? 'OK')}\\n`);\n }\n return EXIT_CODES.OK;\n }\n\n /**\n * Terminal failure. Writes the single stdout error object (JSON mode) or the\n * message + hint to stderr (human mode). Returns the error's exit code.\n *\n * `error.hint` is guaranteed non-empty by CliError's constructor, so the\n * envelope's \"every error carries a hint\" invariant holds for every path\n * that reaches here.\n *\n * `options.findingsSummary` is the seam for a command that has ALREADY\n * rendered the shared findings block to stderr (human mode) before calling\n * this — `validate`'s and `publish`'s gate-refusal paths. Passing it swaps\n * the default two-line `Error: … / Hint: …` epilogue (whose hint always\n * points at the JSON-only `data.findings`) for one short summary line,\n * `✖ <command> failed: <n> error(s)`, so a partner never reads the same\n * finding jargon twice. JSON mode is completely unaffected either way —\n * `error.hint` always carries the original, JSON-only-appropriate text in\n * the envelope.\n */\n fail(error: CliError, data?: unknown, options?: FailOptions): ExitCode {\n this.failWith({\n code: error.code,\n message: error.message,\n hint: error.hint,\n docs: error.docs,\n exitCode: error.exitCode,\n data,\n findingsSummary: options?.findingsSummary,\n });\n return error.exitCode;\n }\n\n /**\n * The low-level failure emitter. Used directly by `test`, whose exit code is\n * a TRANSPARENT passthrough of the delegated runner's exit code (which is not\n * one of the CLI's own frozen numeric conditions) and whose error `code` is\n * an out-of-taxonomy string. Enforces the same non-empty-hint invariant as\n * CliError so no failure path can emit an empty hint.\n */\n failWith(params: {\n code: string;\n message: string;\n hint: string;\n /** A docs URL for this error; JSON gets a `docs` field, human mode a line. */\n docs?: string;\n exitCode: number;\n data?: unknown;\n findingsSummary?: FindingsSummary;\n }): number {\n this.settle();\n this.failed = { code: params.code, exitCode: params.exitCode };\n if (!params.hint || params.hint.trim().length === 0) {\n throw new Error(\n `failWith for \"${params.message}\" was given an empty hint. Every CLI ` +\n 'error must carry an imperative remediation.',\n );\n }\n // The commands a hint names, as this run was invoked (`invocation.ts`).\n const message = echoInvocation(params.message);\n const hint = echoInvocation(params.hint);\n if (this.jsonMode) {\n const envelope: ErrEnvelope = {\n ok: false,\n ...(params.data !== undefined ? { data: params.data } : {}),\n error: {\n code: params.code,\n message,\n hint,\n ...(params.docs ? { docs: params.docs } : {}),\n },\n };\n this.stdout.write(`${JSON.stringify(envelope)}\\n`);\n } else if (params.findingsSummary) {\n const { command, errorCount } = params.findingsSummary;\n this.stderr.write(\n `${this.ui.err(\n `${this.ui.glyphs.err} ${command} failed: ${errorCount} error${\n errorCount === 1 ? '' : 's'\n }`,\n )}\\n`,\n );\n } else {\n this.stderr.write(`${this.ui.err('Error:')} ${message}\\n`);\n this.stderr.write(`${this.ui.dim('Hint:')} ${hint}\\n`);\n if (params.docs) {\n this.stderr.write(`${this.ui.dim('Docs:')} ${params.docs}\\n`);\n }\n }\n return params.exitCode;\n }\n\n private settle(): void {\n if (this.settled) {\n throw new Error(\n 'CliContext settled twice — a command tried to emit a second ' +\n 'terminal result. In JSON mode this would corrupt stdout with two ' +\n 'objects. This is a bug in the command.',\n );\n }\n this.settled = true;\n }\n}\n\n/**\n * The environment markers coding agents set in the shells they run:\n * Claude Code (`CLAUDECODE=1`), Codex (`CODEX_SANDBOX`), Cursor's agent\n * (`CURSOR_AGENT=1`), Gemini CLI (`GEMINI_CLI=1`), and the generic\n * `AI_AGENT`. A pipe alone is not one — a person piping into `grep` is not\n * an agent.\n */\nexport function isAgentEnvironment(\n env: Readonly<Record<string, string | undefined>>,\n): boolean {\n return (\n env.CLAUDECODE === '1' ||\n Boolean(env.CODEX_SANDBOX) ||\n env.CURSOR_AGENT === '1' ||\n env.GEMINI_CLI === '1' ||\n Boolean(env.AI_AGENT)\n );\n}\n\nfunction defaultStream(stream: NodeJS.WriteStream): WriteStream {\n return {\n write: (chunk: string) => {\n stream.write(chunk);\n },\n isTTY: stream.isTTY,\n };\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type FeedbackSubmitRequest } from '@ekanos/integration-schema';
|
|
2
|
+
/**
|
|
3
|
+
* The CLI's client for feedback (`ekanos feedback`, `ekanos sources
|
|
4
|
+
* feedback`, and the fix updates checked after other commands).
|
|
5
|
+
*
|
|
6
|
+
* POST /api/partner/feedback?source=<slug|id> file a report
|
|
7
|
+
* GET /api/partner/feedback your own reports
|
|
8
|
+
* GET /api/partner/feedback/updates fixes not yet shown
|
|
9
|
+
* POST /api/partner/feedback/updates/ack { ids } shown; idempotent
|
|
10
|
+
* GET|PUT|DELETE /api/partner/sources/feedback?source= the Source's switch
|
|
11
|
+
*
|
|
12
|
+
* → 401 / 3xx refresh once and retry
|
|
13
|
+
* → 403 FEEDBACK_DISABLED the Source's admin turned reports off
|
|
14
|
+
* → 403 SOURCE_ADMIN_REQUIRED changing the switch takes a Source admin
|
|
15
|
+
* → 429 RATE_LIMITED + Retry-After
|
|
16
|
+
*/
|
|
17
|
+
export type FeedbackApiResult<T> = {
|
|
18
|
+
status: 'ok';
|
|
19
|
+
data: T;
|
|
20
|
+
} | {
|
|
21
|
+
status: 'unauthorized';
|
|
22
|
+
};
|
|
23
|
+
export declare function submitFeedback(host: string, token: string, source: string, body: FeedbackSubmitRequest): Promise<FeedbackApiResult<{
|
|
24
|
+
id: string;
|
|
25
|
+
number: number;
|
|
26
|
+
}>>;
|
|
27
|
+
export declare function listOwnFeedback(host: string, token: string): Promise<FeedbackApiResult<{
|
|
28
|
+
reports: {
|
|
29
|
+
id: string;
|
|
30
|
+
number: number;
|
|
31
|
+
kind: "bug" | "confusing" | "missing" | "other";
|
|
32
|
+
status: "closed" | "issue_filed" | "new" | "triaged";
|
|
33
|
+
excerpt: string;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
fix: {
|
|
36
|
+
kind: "cli";
|
|
37
|
+
version: string;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "host";
|
|
40
|
+
} | null;
|
|
41
|
+
note: string | null;
|
|
42
|
+
}[];
|
|
43
|
+
}>>;
|
|
44
|
+
export declare function sourceFeedbackSetting(host: string, token: string, source: string, change?: boolean): Promise<FeedbackApiResult<{
|
|
45
|
+
source: {
|
|
46
|
+
id: string;
|
|
47
|
+
slug: string;
|
|
48
|
+
name: string | null;
|
|
49
|
+
};
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
changed?: boolean | undefined;
|
|
52
|
+
}>>;
|
|
53
|
+
/**
|
|
54
|
+
* The background calls behind the fix updates: untraced (they are not the
|
|
55
|
+
* command's), abortable, short, and they throw on anything but success,
|
|
56
|
+
* which their one caller swallows.
|
|
57
|
+
*/
|
|
58
|
+
export declare function fetchFeedbackUpdates(host: string, token: string, signal: AbortSignal): Promise<{
|
|
59
|
+
id: string;
|
|
60
|
+
number: number;
|
|
61
|
+
excerpt: string;
|
|
62
|
+
fix: {
|
|
63
|
+
kind: "cli";
|
|
64
|
+
version: string;
|
|
65
|
+
} | {
|
|
66
|
+
kind: "host";
|
|
67
|
+
};
|
|
68
|
+
note: string | null;
|
|
69
|
+
}[]>;
|
|
70
|
+
export declare function ackFeedbackUpdates(host: string, token: string, ids: readonly string[], signal: AbortSignal): Promise<number>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { FeedbackAckResultSchema, FeedbackOwnListSchema, FeedbackSubmitResultSchema, FeedbackUpdatesSchema, SourceFeedbackSettingSchema, } from '@ekanos/integration-schema';
|
|
2
|
+
import { request } from './auth/ekanos-api.js';
|
|
3
|
+
import { authRequiredError, forbiddenError, networkError, notFoundError, usageError, } from './errors.js';
|
|
4
|
+
export function submitFeedback(host, token, source, body) {
|
|
5
|
+
return call(host, token, FeedbackSubmitResultSchema, {
|
|
6
|
+
method: 'POST',
|
|
7
|
+
path: `/api/partner/feedback?${new URLSearchParams({ source })}`,
|
|
8
|
+
body,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export function listOwnFeedback(host, token) {
|
|
12
|
+
return call(host, token, FeedbackOwnListSchema, {
|
|
13
|
+
method: 'GET',
|
|
14
|
+
path: '/api/partner/feedback',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function sourceFeedbackSetting(host, token, source, change) {
|
|
18
|
+
return call(host, token, SourceFeedbackSettingSchema, {
|
|
19
|
+
method: change === undefined ? 'GET' : change ? 'PUT' : 'DELETE',
|
|
20
|
+
path: `/api/partner/sources/feedback?${new URLSearchParams({ source })}`,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async function call(host, accessToken, schema, init) {
|
|
24
|
+
var _a;
|
|
25
|
+
const response = await request(`${host}${init.path}`, Object.assign({ method: init.method, headers: Object.assign({ accept: 'application/json', authorization: `Bearer ${accessToken}` }, (init.body === undefined
|
|
26
|
+
? {}
|
|
27
|
+
: { 'content-type': 'application/json' })) }, (init.body === undefined ? {} : { body: JSON.stringify(init.body) })));
|
|
28
|
+
if (response.status === 401 ||
|
|
29
|
+
(response.status >= 300 && response.status < 400)) {
|
|
30
|
+
return { status: 'unauthorized' };
|
|
31
|
+
}
|
|
32
|
+
const body = await readOptionalJson(response);
|
|
33
|
+
const code = typeof body.code === 'string' ? body.code : null;
|
|
34
|
+
const message = typeof body.error === 'string' && body.error ? body.error : null;
|
|
35
|
+
if (response.status === 403 && code === 'MFA_REQUIRED') {
|
|
36
|
+
throw authRequiredError(message !== null && message !== void 0 ? message : `${host} requires multi-factor authentication.`, 'Complete MFA in the browser, then run "ekanos login" again.');
|
|
37
|
+
}
|
|
38
|
+
if (response.status === 403 && code === 'FEEDBACK_DISABLED') {
|
|
39
|
+
throw forbiddenError(message !== null && message !== void 0 ? message : 'Feedback from the CLI is turned off for this Source.', 'Nothing was sent. Its Source admin turns it back on with "ekanos sources feedback enable".');
|
|
40
|
+
}
|
|
41
|
+
if (response.status === 403 && code === 'SOURCE_ADMIN_REQUIRED') {
|
|
42
|
+
throw forbiddenError(message !== null && message !== void 0 ? message : 'Turning feedback on or off takes a Source admin seat.', '"ekanos sources feedback status" shows the setting; a Source admin changes it.');
|
|
43
|
+
}
|
|
44
|
+
if (response.status === 403) {
|
|
45
|
+
throw forbiddenError(message !== null && message !== void 0 ? message : 'Not permitted on this Source.', 'Run "ekanos sources" to list the sources you hold a seat on.');
|
|
46
|
+
}
|
|
47
|
+
if (response.status === 404) {
|
|
48
|
+
throw notFoundError(message !== null && message !== void 0 ? message : 'Not found.', 'Run "ekanos sources" to list the sources you hold a seat on.');
|
|
49
|
+
}
|
|
50
|
+
if (response.status === 429) {
|
|
51
|
+
const retryAfter = Number.parseInt((_a = response.headers.get('retry-after')) !== null && _a !== void 0 ? _a : '', 10);
|
|
52
|
+
throw networkError(message !== null && message !== void 0 ? message : 'Too many reports in a short time.', Number.isFinite(retryAfter) && retryAfter > 0
|
|
53
|
+
? `Retry in ${retryAfter} seconds.`
|
|
54
|
+
: 'Retry in a few minutes.');
|
|
55
|
+
}
|
|
56
|
+
if (response.status === 400) {
|
|
57
|
+
throw usageError(message !== null && message !== void 0 ? message : 'The host refused the report.', 'See "ekanos feedback --help".');
|
|
58
|
+
}
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
throw networkError(`${host}${init.path.split('?')[0]} responded ${response.status}.`, response.status >= 500
|
|
61
|
+
? 'The Ekanos deployment returned a server error. Retry shortly.'
|
|
62
|
+
: 'Confirm the host runs a build that includes the feedback routes ("ekanos upgrade" may help).');
|
|
63
|
+
}
|
|
64
|
+
const parsed = schema.safeParse(body.data);
|
|
65
|
+
if (!parsed.success) {
|
|
66
|
+
throw networkError(`${host}${init.path.split('?')[0]} answered in a shape this CLI does not read.`, 'Run "ekanos upgrade": the CLI and the host disagree on the feedback contract.');
|
|
67
|
+
}
|
|
68
|
+
return { status: 'ok', data: parsed.data };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The background calls behind the fix updates: untraced (they are not the
|
|
72
|
+
* command's), abortable, short, and they throw on anything but success,
|
|
73
|
+
* which their one caller swallows.
|
|
74
|
+
*/
|
|
75
|
+
export async function fetchFeedbackUpdates(host, token, signal) {
|
|
76
|
+
const response = await request(`${host}/api/partner/feedback/updates`, {
|
|
77
|
+
method: 'GET',
|
|
78
|
+
headers: { accept: 'application/json', authorization: `Bearer ${token}` },
|
|
79
|
+
}, { untraced: true, signal, timeoutMs: 5000 });
|
|
80
|
+
if (!response.ok)
|
|
81
|
+
throw new Error(`updates: ${response.status}`);
|
|
82
|
+
const body = await readOptionalJson(response);
|
|
83
|
+
return FeedbackUpdatesSchema.parse(body.data).updates;
|
|
84
|
+
}
|
|
85
|
+
export async function ackFeedbackUpdates(host, token, ids, signal) {
|
|
86
|
+
const response = await request(`${host}/api/partner/feedback/updates/ack`, {
|
|
87
|
+
method: 'POST',
|
|
88
|
+
headers: {
|
|
89
|
+
accept: 'application/json',
|
|
90
|
+
'content-type': 'application/json',
|
|
91
|
+
authorization: `Bearer ${token}`,
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify({ ids }),
|
|
94
|
+
}, { untraced: true, signal, timeoutMs: 5000 });
|
|
95
|
+
if (!response.ok)
|
|
96
|
+
throw new Error(`ack: ${response.status}`);
|
|
97
|
+
const body = await readOptionalJson(response);
|
|
98
|
+
return FeedbackAckResultSchema.parse(body.data).acknowledged;
|
|
99
|
+
}
|
|
100
|
+
async function readOptionalJson(response) {
|
|
101
|
+
try {
|
|
102
|
+
const parsed = await response.json();
|
|
103
|
+
return typeof parsed === 'object' && parsed !== null
|
|
104
|
+
? parsed
|
|
105
|
+
: {};
|
|
106
|
+
}
|
|
107
|
+
catch (_a) {
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=feedback-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback-api.js","sourceRoot":"","sources":["../src/feedback-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,aAAa,EACb,UAAU,GACX,MAA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M,EAAE,MAAM;QACd,OAAO,EAAE;YACP,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC;KAC9B,EACD,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAC5C,CAAC;IACF,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC7D,MAAM,IAAI,GAAG,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC9C,OAAO,uBAAuB,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC;AAC/D,CAAC;AAED,KAAK,UAAU,gBAAgB,CAC7B,QAAkB;IAElB,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC9C,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI;YAClD,CAAC,CAAE,MAAkC;YACrC,CAAC,CAAC,EAAE,CAAC;IACT,CAAC;eAAO,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC","sourcesContent":["import {\n type FeedbackSubmitRequest,\n FeedbackAckResultSchema,\n FeedbackOwnListSchema,\n FeedbackSubmitResultSchema,\n FeedbackUpdatesSchema,\n SourceFeedbackSettingSchema,\n} from '@ekanos/integration-schema';\nimport type { z } from 'zod';\n\nimport { request } from './auth/ekanos-api';\nimport {\n authRequiredError,\n forbiddenError,\n networkError,\n notFoundError,\n usageError,\n} from './errors';\n\n/**\n * The CLI's client for feedback (`ekanos feedback`, `ekanos sources\n * feedback`, and the fix updates checked after other commands).\n *\n * POST /api/partner/feedback?source=<slug|id> file a report\n * GET /api/partner/feedback your own reports\n * GET /api/partner/feedback/updates fixes not yet shown\n * POST /api/partner/feedback/updates/ack { ids } shown; idempotent\n * GET|PUT|DELETE /api/partner/sources/feedback?source= the Source's switch\n *\n * → 401 / 3xx refresh once and retry\n * → 403 FEEDBACK_DISABLED the Source's admin turned reports off\n * → 403 SOURCE_ADMIN_REQUIRED changing the switch takes a Source admin\n * → 429 RATE_LIMITED + Retry-After\n */\n\nexport type FeedbackApiResult<T> =\n | { status: 'ok'; data: T }\n | { status: 'unauthorized' };\n\nexport function submitFeedback(\n host: string,\n token: string,\n source: string,\n body: FeedbackSubmitRequest,\n) {\n return call(host, token, FeedbackSubmitResultSchema, {\n method: 'POST',\n path: `/api/partner/feedback?${new URLSearchParams({ source })}`,\n body,\n });\n}\n\nexport function listOwnFeedback(host: string, token: string) {\n return call(host, token, FeedbackOwnListSchema, {\n method: 'GET',\n path: '/api/partner/feedback',\n });\n}\n\nexport function sourceFeedbackSetting(\n host: string,\n token: string,\n source: string,\n change?: boolean,\n) {\n return call(host, token, SourceFeedbackSettingSchema, {\n method: change === undefined ? 'GET' : change ? 'PUT' : 'DELETE',\n path: `/api/partner/sources/feedback?${new URLSearchParams({ source })}`,\n });\n}\n\nasync function call<T>(\n host: string,\n accessToken: string,\n schema: z.ZodType<T>,\n init: {\n method: 'GET' | 'POST' | 'PUT' | 'DELETE';\n path: string;\n body?: unknown;\n },\n): Promise<FeedbackApiResult<T>> {\n const response = await request(`${host}${init.path}`, {\n method: init.method,\n headers: {\n accept: 'application/json',\n authorization: `Bearer ${accessToken}`,\n ...(init.body === undefined\n ? {}\n : { 'content-type': 'application/json' }),\n },\n ...(init.body === undefined ? {} : { body: JSON.stringify(init.body) }),\n });\n\n if (\n response.status === 401 ||\n (response.status >= 300 && response.status < 400)\n ) {\n return { status: 'unauthorized' };\n }\n\n const body = await readOptionalJson(response);\n const code = typeof body.code === 'string' ? body.code : null;\n const message =\n typeof body.error === 'string' && body.error ? body.error : null;\n\n if (response.status === 403 && code === 'MFA_REQUIRED') {\n throw authRequiredError(\n message ?? `${host} requires multi-factor authentication.`,\n 'Complete MFA in the browser, then run \"ekanos login\" again.',\n );\n }\n if (response.status === 403 && code === 'FEEDBACK_DISABLED') {\n throw forbiddenError(\n message ?? 'Feedback from the CLI is turned off for this Source.',\n 'Nothing was sent. Its Source admin turns it back on with \"ekanos sources feedback enable\".',\n );\n }\n if (response.status === 403 && code === 'SOURCE_ADMIN_REQUIRED') {\n throw forbiddenError(\n message ?? 'Turning feedback on or off takes a Source admin seat.',\n '\"ekanos sources feedback status\" shows the setting; a Source admin changes it.',\n );\n }\n if (response.status === 403) {\n throw forbiddenError(\n message ?? 'Not permitted on this Source.',\n 'Run \"ekanos sources\" to list the sources you hold a seat on.',\n );\n }\n if (response.status === 404) {\n throw notFoundError(\n message ?? 'Not found.',\n 'Run \"ekanos sources\" to list the sources you hold a seat on.',\n );\n }\n if (response.status === 429) {\n const retryAfter = Number.parseInt(\n response.headers.get('retry-after') ?? '',\n 10,\n );\n throw networkError(\n message ?? 'Too many reports in a short time.',\n Number.isFinite(retryAfter) && retryAfter > 0\n ? `Retry in ${retryAfter} seconds.`\n : 'Retry in a few minutes.',\n );\n }\n if (response.status === 400) {\n throw usageError(\n message ?? 'The host refused the report.',\n 'See \"ekanos feedback --help\".',\n );\n }\n if (!response.ok) {\n throw networkError(\n `${host}${init.path.split('?')[0]} responded ${response.status}.`,\n response.status >= 500\n ? 'The Ekanos deployment returned a server error. Retry shortly.'\n : 'Confirm the host runs a build that includes the feedback routes (\"ekanos upgrade\" may help).',\n );\n }\n\n const parsed = schema.safeParse(body.data);\n if (!parsed.success) {\n throw networkError(\n `${host}${init.path.split('?')[0]} answered in a shape this CLI does not read.`,\n 'Run \"ekanos upgrade\": the CLI and the host disagree on the feedback contract.',\n );\n }\n return { status: 'ok', data: parsed.data };\n}\n\n/**\n * The background calls behind the fix updates: untraced (they are not the\n * command's), abortable, short, and they throw on anything but success,\n * which their one caller swallows.\n */\nexport async function fetchFeedbackUpdates(\n host: string,\n token: string,\n signal: AbortSignal,\n) {\n const response = await request(\n `${host}/api/partner/feedback/updates`,\n {\n method: 'GET',\n headers: { accept: 'application/json', authorization: `Bearer ${token}` },\n },\n { untraced: true, signal, timeoutMs: 5000 },\n );\n if (!response.ok) throw new Error(`updates: ${response.status}`);\n const body = await readOptionalJson(response);\n return FeedbackUpdatesSchema.parse(body.data).updates;\n}\n\nexport async function ackFeedbackUpdates(\n host: string,\n token: string,\n ids: readonly string[],\n signal: AbortSignal,\n) {\n const response = await request(\n `${host}/api/partner/feedback/updates/ack`,\n {\n method: 'POST',\n headers: {\n accept: 'application/json',\n 'content-type': 'application/json',\n authorization: `Bearer ${token}`,\n },\n body: JSON.stringify({ ids }),\n },\n { untraced: true, signal, timeoutMs: 5000 },\n );\n if (!response.ok) throw new Error(`ack: ${response.status}`);\n const body = await readOptionalJson(response);\n return FeedbackAckResultSchema.parse(body.data).acknowledged;\n}\n\nasync function readOptionalJson(\n response: Response,\n): Promise<Record<string, unknown>> {\n try {\n const parsed: unknown = await response.json();\n return typeof parsed === 'object' && parsed !== null\n ? (parsed as Record<string, unknown>)\n : {};\n } catch {\n return {};\n }\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { FeedbackAgent, FeedbackContext } from '@ekanos/integration-schema';
|
|
2
|
+
/**
|
|
3
|
+
* `teams connect` from `["teams", "connect", "acme", "linear"]`: the command
|
|
4
|
+
* and the words after it that are the CLI's own, up to the first that is not.
|
|
5
|
+
*/
|
|
6
|
+
export declare function commandPathOf(tokens: readonly string[]): string | null;
|
|
7
|
+
/**
|
|
8
|
+
* The names of the flags in an argv, in order, once each: `--set a=b` gives
|
|
9
|
+
* `--set`, `--source=acme` gives `--source`. A token after `--` is the
|
|
10
|
+
* passthrough's, not a flag of this CLI, and is never read.
|
|
11
|
+
*/
|
|
12
|
+
export declare function flagNamesOf(argv: readonly string[]): string[];
|
|
13
|
+
/**
|
|
14
|
+
* A command line someone typed (`--command "ekanos teams connect acme
|
|
15
|
+
* linear --set clientId=x"`), reduced to its path and flag names. A leading
|
|
16
|
+
* `ekanos`, `npx @ekanos/cli[@version]` or package-runner prefix is dropped.
|
|
17
|
+
*/
|
|
18
|
+
export declare function describeCommandLine(line: string): {
|
|
19
|
+
command: string | null;
|
|
20
|
+
flags: string[];
|
|
21
|
+
};
|
|
22
|
+
/** Which coding agent is running this CLI, by its marker; never the value. */
|
|
23
|
+
export declare function detectFeedbackAgent(env: Readonly<Record<string, string | undefined>>): FeedbackAgent | null;
|
|
24
|
+
/** `darwin-arm64`, `linux-x64`. */
|
|
25
|
+
export declare function osLabel(): string | null;
|
|
26
|
+
export declare function nodeVersion(): string | null;
|
|
27
|
+
/** A context with nothing about a command: what a plain report carries. */
|
|
28
|
+
export declare function baseFeedbackContext(input: {
|
|
29
|
+
cliVersion: string;
|
|
30
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
31
|
+
}): FeedbackContext;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `ekanos feedback` may say about a command: its path in the CLI's own
|
|
3
|
+
* words and the NAMES of its flags. Never an argument, a flag's value, a
|
|
4
|
+
* file's contents or an environment value — this module is the one place a
|
|
5
|
+
* command line is reduced to that, for a recorded failure and for
|
|
6
|
+
* `--command` alike.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The words a command path is made of: the CLI's commands and the verbs and
|
|
10
|
+
* areas under them. A token that is not one of these ends the path, so a
|
|
11
|
+
* team, a product, an email or a key never joins it. A slug that happens to
|
|
12
|
+
* be one of these words says nothing more than the word.
|
|
13
|
+
*/
|
|
14
|
+
const COMMAND_WORDS = new Set([
|
|
15
|
+
// Commands.
|
|
16
|
+
'init',
|
|
17
|
+
'validate',
|
|
18
|
+
'dev',
|
|
19
|
+
'test',
|
|
20
|
+
'login',
|
|
21
|
+
'logout',
|
|
22
|
+
'whoami',
|
|
23
|
+
'status',
|
|
24
|
+
'sources',
|
|
25
|
+
'catalog',
|
|
26
|
+
'apps',
|
|
27
|
+
'teams',
|
|
28
|
+
'reviewers',
|
|
29
|
+
'routes',
|
|
30
|
+
'agents',
|
|
31
|
+
'skills',
|
|
32
|
+
'knowledge',
|
|
33
|
+
'runs',
|
|
34
|
+
'approvals',
|
|
35
|
+
'workflows',
|
|
36
|
+
'use',
|
|
37
|
+
'publish',
|
|
38
|
+
'upgrade',
|
|
39
|
+
'feedback',
|
|
40
|
+
// Areas and verbs.
|
|
41
|
+
'add',
|
|
42
|
+
'app',
|
|
43
|
+
'apply',
|
|
44
|
+
'approve',
|
|
45
|
+
'archive',
|
|
46
|
+
'attach',
|
|
47
|
+
'cancel',
|
|
48
|
+
'confirm',
|
|
49
|
+
'connect',
|
|
50
|
+
'create',
|
|
51
|
+
'default',
|
|
52
|
+
'define',
|
|
53
|
+
'delete',
|
|
54
|
+
'detach',
|
|
55
|
+
'disable',
|
|
56
|
+
'disconnect',
|
|
57
|
+
'edit',
|
|
58
|
+
'effect',
|
|
59
|
+
'enable',
|
|
60
|
+
'events',
|
|
61
|
+
'groups',
|
|
62
|
+
'health',
|
|
63
|
+
'invite',
|
|
64
|
+
'leave',
|
|
65
|
+
'links',
|
|
66
|
+
'list',
|
|
67
|
+
'llm-key',
|
|
68
|
+
'mcp',
|
|
69
|
+
'members',
|
|
70
|
+
'options',
|
|
71
|
+
'overrides',
|
|
72
|
+
'people',
|
|
73
|
+
'pin',
|
|
74
|
+
'policy',
|
|
75
|
+
'products',
|
|
76
|
+
'pull',
|
|
77
|
+
'push',
|
|
78
|
+
'refresh',
|
|
79
|
+
'reject',
|
|
80
|
+
'remove',
|
|
81
|
+
'rename',
|
|
82
|
+
'replay',
|
|
83
|
+
'resend',
|
|
84
|
+
'role',
|
|
85
|
+
'roles',
|
|
86
|
+
'rollback',
|
|
87
|
+
'rotate',
|
|
88
|
+
'scope',
|
|
89
|
+
'scopes',
|
|
90
|
+
'search',
|
|
91
|
+
'set',
|
|
92
|
+
'show',
|
|
93
|
+
'start',
|
|
94
|
+
'tags',
|
|
95
|
+
'token',
|
|
96
|
+
'triggers',
|
|
97
|
+
'unarchive',
|
|
98
|
+
'unpin',
|
|
99
|
+
'unrouted',
|
|
100
|
+
'unset',
|
|
101
|
+
'update',
|
|
102
|
+
'webhook',
|
|
103
|
+
'workspace',
|
|
104
|
+
]);
|
|
105
|
+
const MAX_PATH_WORDS = 4;
|
|
106
|
+
const FLAG_NAME = /^--[a-z0-9][a-z0-9-]{0,47}$/;
|
|
107
|
+
/**
|
|
108
|
+
* `teams connect` from `["teams", "connect", "acme", "linear"]`: the command
|
|
109
|
+
* and the words after it that are the CLI's own, up to the first that is not.
|
|
110
|
+
*/
|
|
111
|
+
export function commandPathOf(tokens) {
|
|
112
|
+
const words = [];
|
|
113
|
+
for (const token of tokens) {
|
|
114
|
+
if (words.length === MAX_PATH_WORDS || !COMMAND_WORDS.has(token))
|
|
115
|
+
break;
|
|
116
|
+
words.push(token);
|
|
117
|
+
}
|
|
118
|
+
return words.length > 0 ? words.join(' ') : null;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The names of the flags in an argv, in order, once each: `--set a=b` gives
|
|
122
|
+
* `--set`, `--source=acme` gives `--source`. A token after `--` is the
|
|
123
|
+
* passthrough's, not a flag of this CLI, and is never read.
|
|
124
|
+
*/
|
|
125
|
+
export function flagNamesOf(argv) {
|
|
126
|
+
const names = [];
|
|
127
|
+
for (const token of argv) {
|
|
128
|
+
if (token === '--')
|
|
129
|
+
break;
|
|
130
|
+
if (!token.startsWith('--'))
|
|
131
|
+
continue;
|
|
132
|
+
const name = token.split('=')[0].toLowerCase();
|
|
133
|
+
if (FLAG_NAME.test(name) && !names.includes(name))
|
|
134
|
+
names.push(name);
|
|
135
|
+
if (names.length === 40)
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
return names;
|
|
139
|
+
}
|
|
140
|
+
/** The leading words of an argv that are not flags, and not values of one. */
|
|
141
|
+
function bareTokens(argv) {
|
|
142
|
+
const tokens = [];
|
|
143
|
+
for (const token of argv) {
|
|
144
|
+
if (token === '--' || token.startsWith('-'))
|
|
145
|
+
break;
|
|
146
|
+
tokens.push(token);
|
|
147
|
+
}
|
|
148
|
+
return tokens;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A command line someone typed (`--command "ekanos teams connect acme
|
|
152
|
+
* linear --set clientId=x"`), reduced to its path and flag names. A leading
|
|
153
|
+
* `ekanos`, `npx @ekanos/cli[@version]` or package-runner prefix is dropped.
|
|
154
|
+
*/
|
|
155
|
+
export function describeCommandLine(line) {
|
|
156
|
+
const tokens = line
|
|
157
|
+
.trim()
|
|
158
|
+
.split(/\s+/)
|
|
159
|
+
.filter(Boolean)
|
|
160
|
+
.map((token) => token.replace(/^["']|["']$/g, ''));
|
|
161
|
+
const start = tokens.findIndex((token) => COMMAND_WORDS.has(token));
|
|
162
|
+
const relevant = start === -1 ? [] : tokens.slice(start);
|
|
163
|
+
// Only what follows a recognized command counts: a prefix such as
|
|
164
|
+
// `npx @ekanos/cli` is not part of it.
|
|
165
|
+
return {
|
|
166
|
+
command: commandPathOf(bareTokens(relevant)),
|
|
167
|
+
flags: flagNamesOf(relevant),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/** Which coding agent is running this CLI, by its marker; never the value. */
|
|
171
|
+
export function detectFeedbackAgent(env) {
|
|
172
|
+
if (env.CLAUDECODE === '1')
|
|
173
|
+
return 'claude-code';
|
|
174
|
+
if (env.CODEX_SANDBOX)
|
|
175
|
+
return 'codex';
|
|
176
|
+
if (env.CURSOR_AGENT === '1')
|
|
177
|
+
return 'cursor';
|
|
178
|
+
if (env.GEMINI_CLI === '1')
|
|
179
|
+
return 'gemini-cli';
|
|
180
|
+
if (env.AI_AGENT)
|
|
181
|
+
return 'other';
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
/** `darwin-arm64`, `linux-x64`. */
|
|
185
|
+
export function osLabel() {
|
|
186
|
+
const label = `${process.platform}-${process.arch}`.toLowerCase();
|
|
187
|
+
return /^[a-z0-9_-]{1,40}$/.test(label) ? label : null;
|
|
188
|
+
}
|
|
189
|
+
export function nodeVersion() {
|
|
190
|
+
const version = process.versions.node;
|
|
191
|
+
return /^\d+\.\d+\.\d+$/.test(version) ? version : null;
|
|
192
|
+
}
|
|
193
|
+
/** A context with nothing about a command: what a plain report carries. */
|
|
194
|
+
export function baseFeedbackContext(input) {
|
|
195
|
+
return {
|
|
196
|
+
cliVersion: input.cliVersion,
|
|
197
|
+
command: null,
|
|
198
|
+
flags: [],
|
|
199
|
+
errorCode: null,
|
|
200
|
+
exitCode: null,
|
|
201
|
+
httpStatus: null,
|
|
202
|
+
requestId: null,
|
|
203
|
+
agent: detectFeedbackAgent(input.env),
|
|
204
|
+
os: osLabel(),
|
|
205
|
+
node: nodeVersion(),
|
|
206
|
+
failedAt: null,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
//# sourceMappingURL=feedback-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feedback-context.js","sourceRoot":"","sources":["../src/feedback-context.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AAEH;;;;;GAKG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,YAAY;IACZ,MAAM;IACN,UAAU;IACV,KAAK;IACL,MAAM;IACN,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,MAAM;IACN,OAAO;IACP,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,MAAM;IACN,WAAW;IACX,WAAW;IACX,KAAK;IACL,SAAS;IACT,SAAS;IACT,UAAU;IACV,mBAAmB;IACnB,KAAK;IACL,KAAK;IACL,OAAO;IACP,SAAS;IACT,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,SAAS;IACT,QAAQ;IACR,SAAS;IACT,QAAQ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ACb,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,IAAI;QACd,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC,GAAG,CAAC;QACrC,EAAE,EAAE,OAAO,EAAE;QACb,IAAI,EAAE,WAAW,EAAE;QACnB,QAAQ,EAAE,IAAI;KACf,CAAC;AACJ,CAAC","sourcesContent":["import type {\n FeedbackAgent,\n FeedbackContext,\n} from '@ekanos/integration-schema';\n\n/**\n * What `ekanos feedback` may say about a command: its path in the CLI's own\n * words and the NAMES of its flags. Never an argument, a flag's value, a\n * file's contents or an environment value — this module is the one place a\n * command line is reduced to that, for a recorded failure and for\n * `--command` alike.\n */\n\n/**\n * The words a command path is made of: the CLI's commands and the verbs and\n * areas under them. A token that is not one of these ends the path, so a\n * team, a product, an email or a key never joins it. A slug that happens to\n * be one of these words says nothing more than the word.\n */\nconst COMMAND_WORDS = new Set([\n // Commands.\n 'init',\n 'validate',\n 'dev',\n 'test',\n 'login',\n 'logout',\n 'whoami',\n 'status',\n 'sources',\n 'catalog',\n 'apps',\n 'teams',\n 'reviewers',\n 'routes',\n 'agents',\n 'skills',\n 'knowledge',\n 'runs',\n 'approvals',\n 'workflows',\n 'use',\n 'publish',\n 'upgrade',\n 'feedback',\n // Areas and verbs.\n 'add',\n 'app',\n 'apply',\n 'approve',\n 'archive',\n 'attach',\n 'cancel',\n 'confirm',\n 'connect',\n 'create',\n 'default',\n 'define',\n 'delete',\n 'detach',\n 'disable',\n 'disconnect',\n 'edit',\n 'effect',\n 'enable',\n 'events',\n 'groups',\n 'health',\n 'invite',\n 'leave',\n 'links',\n 'list',\n 'llm-key',\n 'mcp',\n 'members',\n 'options',\n 'overrides',\n 'people',\n 'pin',\n 'policy',\n 'products',\n 'pull',\n 'push',\n 'refresh',\n 'reject',\n 'remove',\n 'rename',\n 'replay',\n 'resend',\n 'role',\n 'roles',\n 'rollback',\n 'rotate',\n 'scope',\n 'scopes',\n 'search',\n 'set',\n 'show',\n 'start',\n 'tags',\n 'token',\n 'triggers',\n 'unarchive',\n 'unpin',\n 'unrouted',\n 'unset',\n 'update',\n 'webhook',\n 'workspace',\n]);\n\nconst MAX_PATH_WORDS = 4;\nconst FLAG_NAME = /^--[a-z0-9][a-z0-9-]{0,47}$/;\n\n/**\n * `teams connect` from `[\"teams\", \"connect\", \"acme\", \"linear\"]`: the command\n * and the words after it that are the CLI's own, up to the first that is not.\n */\nexport function commandPathOf(tokens: readonly string[]): string | null {\n const words: string[] = [];\n for (const token of tokens) {\n if (words.length === MAX_PATH_WORDS || !COMMAND_WORDS.has(token)) break;\n words.push(token);\n }\n return words.length > 0 ? words.join(' ') : null;\n}\n\n/**\n * The names of the flags in an argv, in order, once each: `--set a=b` gives\n * `--set`, `--source=acme` gives `--source`. A token after `--` is the\n * passthrough's, not a flag of this CLI, and is never read.\n */\nexport function flagNamesOf(argv: readonly string[]): string[] {\n const names: string[] = [];\n for (const token of argv) {\n if (token === '--') break;\n if (!token.startsWith('--')) continue;\n const name = token.split('=')[0]!.toLowerCase();\n if (FLAG_NAME.test(name) && !names.includes(name)) names.push(name);\n if (names.length === 40) break;\n }\n return names;\n}\n\n/** The leading words of an argv that are not flags, and not values of one. */\nfunction bareTokens(argv: readonly string[]): string[] {\n const tokens: string[] = [];\n for (const token of argv) {\n if (token === '--' || token.startsWith('-')) break;\n tokens.push(token);\n }\n return tokens;\n}\n\n/**\n * A command line someone typed (`--command \"ekanos teams connect acme\n * linear --set clientId=x\"`), reduced to its path and flag names. A leading\n * `ekanos`, `npx @ekanos/cli[@version]` or package-runner prefix is dropped.\n */\nexport function describeCommandLine(line: string): {\n command: string | null;\n flags: string[];\n} {\n const tokens = line\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((token) => token.replace(/^[\"']|[\"']$/g, ''));\n const start = tokens.findIndex((token) => COMMAND_WORDS.has(token));\n const relevant = start === -1 ? [] : tokens.slice(start);\n // Only what follows a recognized command counts: a prefix such as\n // `npx @ekanos/cli` is not part of it.\n return {\n command: commandPathOf(bareTokens(relevant)),\n flags: flagNamesOf(relevant),\n };\n}\n\n/** Which coding agent is running this CLI, by its marker; never the value. */\nexport function detectFeedbackAgent(\n env: Readonly<Record<string, string | undefined>>,\n): FeedbackAgent | null {\n if (env.CLAUDECODE === '1') return 'claude-code';\n if (env.CODEX_SANDBOX) return 'codex';\n if (env.CURSOR_AGENT === '1') return 'cursor';\n if (env.GEMINI_CLI === '1') return 'gemini-cli';\n if (env.AI_AGENT) return 'other';\n return null;\n}\n\n/** `darwin-arm64`, `linux-x64`. */\nexport function osLabel(): string | null {\n const label = `${process.platform}-${process.arch}`.toLowerCase();\n return /^[a-z0-9_-]{1,40}$/.test(label) ? label : null;\n}\n\nexport function nodeVersion(): string | null {\n const version = process.versions.node;\n return /^\\d+\\.\\d+\\.\\d+$/.test(version) ? version : null;\n}\n\n/** A context with nothing about a command: what a plain report carries. */\nexport function baseFeedbackContext(input: {\n cliVersion: string;\n env: Readonly<Record<string, string | undefined>>;\n}): FeedbackContext {\n return {\n cliVersion: input.cliVersion,\n command: null,\n flags: [],\n errorCode: null,\n exitCode: null,\n httpStatus: null,\n requestId: null,\n agent: detectFeedbackAgent(input.env),\n os: osLabel(),\n node: nodeVersion(),\n failedAt: null,\n };\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FeedbackUpdate } from '@ekanos/integration-schema';
|
|
2
|
+
import type { CliContext } from './context.js';
|
|
3
|
+
import { type Invocation } from './invocation.js';
|
|
4
|
+
export declare const FEEDBACK_UPDATES_TTL_MS: number;
|
|
5
|
+
export interface FeedbackUpdatesCheck {
|
|
6
|
+
/** Print what is ready, remember it, and let go of anything still in flight. */
|
|
7
|
+
finish(ctx: CliContext): void;
|
|
8
|
+
/** Settles when the background work does (tests). */
|
|
9
|
+
readonly settled: Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function startFeedbackUpdatesCheck(params: {
|
|
12
|
+
env: Record<string, string | undefined>;
|
|
13
|
+
now?: number;
|
|
14
|
+
}): FeedbackUpdatesCheck | null;
|
|
15
|
+
/** One stderr line about one shipped fix. */
|
|
16
|
+
export declare function describeUpdate(update: FeedbackUpdate, installed: string, invocation: Invocation): string;
|