diff --git a/packages/cli/src/managed-local-embeddings.ts b/packages/cli/src/managed-local-embeddings.ts index 999b38c1..bca1349d 100644 --- a/packages/cli/src/managed-local-embeddings.ts +++ b/packages/cli/src/managed-local-embeddings.ts @@ -1,6 +1,6 @@ import type { KtxEmbeddingConfig } from './llm/types.js'; import type { KtxCliIo } from './cli-runtime.js'; -import { createCliSpinner } from './clack.js'; +import { createStaticCliSpinner } from './clack.js'; import { ensureManagedPythonCommandRuntime, type KtxManagedPythonInstallPolicy, @@ -66,8 +66,11 @@ export async function ensureManagedLocalEmbeddingsDaemon( io: options.io, feature: 'local-embeddings', }); - const spinner = createCliSpinner(options.io); - spinner.start('Starting ktx embedding daemon (first run downloads the model)…'); + // Static, stderr-only spinner on purpose: the animated clack spinner seizes + // stdin through @clack/core's block() and leaves the tty in raw mode, which + // stops Ctrl-C from generating SIGINT for the rest of the ingest. + const spinner = createStaticCliSpinner(options.io); + spinner.start('Starting ktx embedding daemon (first run downloads the model)\u2026'); let daemon: ManagedPythonDaemonStartResult; try { daemon = await startDaemon({ diff --git a/packages/cli/test/managed-local-embeddings.test.ts b/packages/cli/test/managed-local-embeddings.test.ts index 004e9302..e53e3ddf 100644 --- a/packages/cli/test/managed-local-embeddings.test.ts +++ b/packages/cli/test/managed-local-embeddings.test.ts @@ -8,12 +8,13 @@ import type { ManagedPythonCommandRuntime } from '../src/managed-python-command. import type { ManagedPythonDaemonStartResult } from '../src/managed-python-daemon.js'; import type { ManagedPythonDaemonLayout } from '../src/managed-python-runtime.js'; -function makeIo() { +function makeIo(stdoutIsTty = false) { let stdout = ''; let stderr = ''; return { io: { stdout: { + isTTY: stdoutIsTty, write: (chunk: string) => { stdout += chunk; }, @@ -161,6 +162,49 @@ describe('ensureManagedLocalEmbeddingsDaemon', () => { expect(io.stderr()).toContain('Using ktx daemon: http://127.0.0.1:61234'); }); + + it('keeps the spinner static on a TTY so the daemon start cannot leave stdin in raw mode', async () => { + // Regression test for #361. On a TTY the animated clack spinner takes + // stdin over through @clack/core's block(), which calls setRawMode(true) + // and is never undone, killing Ctrl-C for the rest of the ingest. The + // static spinner writes to stderr only and never touches stdin, so the + // giveaway is that stdout stays completely empty even when it is a TTY. + const io = makeIo(true); + + await ensureManagedLocalEmbeddingsDaemon({ + cliVersion: '0.2.0', + projectDir: '/work/proj', + installPolicy: 'auto', + io: io.io, + ensureRuntime: vi.fn(async () => runtime()), + startDaemon: vi.fn(async () => daemonResult('started')), + }); + + expect(io.stdout()).toBe(''); + expect(io.stderr()).toContain('Starting ktx embedding daemon'); + expect(io.stderr()).toContain('Started ktx daemon: http://127.0.0.1:61234'); + }); + + it('reports the failure through the same static spinner and rethrows', async () => { + const io = makeIo(true); + const boom = new Error('daemon exploded'); + + await expect( + ensureManagedLocalEmbeddingsDaemon({ + cliVersion: '0.2.0', + projectDir: '/work/proj', + installPolicy: 'auto', + io: io.io, + ensureRuntime: vi.fn(async () => runtime()), + startDaemon: vi.fn(async () => { + throw boom; + }), + }), + ).rejects.toBe(boom); + + expect(io.stdout()).toBe(''); + expect(io.stderr()).toContain('ktx embedding daemon failed to start'); + }); }); describe('tryUseManagedLocalEmbeddingsDaemon', () => {