From aa2ca79bd3379f84640f72ce70149cbe26333418 Mon Sep 17 00:00:00 2001 From: Biogenic Ooze Date: Tue, 17 Nov 2026 17:17:52 +0300 Subject: [PATCH 1/3] Make terminal agent cards clickable and show setup progress --- ...1-17-show-terminal-agent-setup-progress.md | 11 ++++++ docs/decisions/INDEX.md | 2 ++ .../server/connection-guide-actions.ts | 34 +++++++++++++++++-- .../workspace/server/connection-guide.test.ts | 28 +++++++++++++++ src/tui/workspace/server/server-overview.ts | 13 ++++++- 5 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 docs/decisions/2026-11-17-show-terminal-agent-setup-progress.md diff --git a/docs/decisions/2026-11-17-show-terminal-agent-setup-progress.md b/docs/decisions/2026-11-17-show-terminal-agent-setup-progress.md new file mode 100644 index 00000000..5ccd0ad7 --- /dev/null +++ b/docs/decisions/2026-11-17-show-terminal-agent-setup-progress.md @@ -0,0 +1,11 @@ +--- +date: 2026-11-17 +title: "Show progress when opening terminal agent setup" +--- + +# Show progress when opening terminal agent setup + +- **Context:** The server overview drew a full agent card, but only its Configure label accepted a click. After that click, model and engine reads could leave the terminal looking idle. +- **Decision:** Give the card one full-surface target and show a status while the connection guide reads local model and engine choices, using the existing setup deadline. +- **Consequences:** The title and body open the same review as Configure. Loading a model and preparing a connection still requires the review action. +- **Owner:** team. diff --git a/docs/decisions/INDEX.md b/docs/decisions/INDEX.md index 44381685..0a1ee739 100644 --- a/docs/decisions/INDEX.md +++ b/docs/decisions/INDEX.md @@ -11,6 +11,8 @@ add a new one that says which record it supersedes. ## Records +- **2026-11-17** — [Show progress when opening terminal agent setup](2026-11-17-show-terminal-agent-setup-progress.md) — make the full agent card clickable and show the options check. + - **2026-11-17** — [Pair terminal connection engines with models](2026-11-17-pair-terminal-connection-engines-with-models.md) — filter the connection guide by active engines and compatible downloads. - **2026-11-17** — [Open the dashboard from terminal onboarding](2026-11-17-open-dashboard-from-terminal-onboarding.md) — save completion and let downloads continue without loading the selected model. diff --git a/src/tui/workspace/server/connection-guide-actions.ts b/src/tui/workspace/server/connection-guide-actions.ts index 73dde8c4..5126922d 100644 --- a/src/tui/workspace/server/connection-guide-actions.ts +++ b/src/tui/workspace/server/connection-guide-actions.ts @@ -1,5 +1,6 @@ import type { ConnectionDraft } from '../../../contract/index.js' import { CONNECTION_AGENTS, DEFAULT_API_PORT, PROFILE_AGENTS } from '../../../contract/index.js' +import { setupWait } from '../../../terminal-setup/index.js' import type { ActionContext } from '../actions.js' import { workspaceLocation } from '../navigation/navigation-return.js' import { record } from '../library/library-model.js' @@ -17,6 +18,8 @@ const rows = (value: unknown) => : Array.isArray(record(value)['rows']) ? (record(value)['rows'] as unknown[]).map(record) : [] +const READING_CONNECTION_OPTIONS = 'Checking installed models and engines…' + export async function connectionGuideAction(id: string, ctx: ActionContext): Promise { if (connectionPickerAction(id, ctx)) return true const s = ctx.get(), @@ -43,8 +46,34 @@ export async function connectionGuideAction(id: string, ctx: ActionContext): Pro return true } if (id === 'guide-open' || id.startsWith('guide-agent:')) { - const [installed, connectionEngines] = await Promise.all([c.installed(), readConnectionEngines(c)]) - if (s.firstRun && ctx.get().firstRun !== s.firstRun) return true + if (s.message === READING_CONNECTION_OPTIONS) return true + const openingHere = () => { + const current = ctx.get() + return ( + current.message === READING_CONNECTION_OPTIONS && + current.page === s.page && + current.overlay === s.overlay && + current.firstRun === s.firstRun + ) + } + ctx.update((v) => ({ ...v, message: READING_CONNECTION_OPTIONS })) + const options = await setupWait( + Promise.all([c.installed(), readConnectionEngines(c)]), + new AbortController().signal + ).catch((error: unknown) => { + if (openingHere()) + ctx.update((v) => ({ + ...v, + message: `Could not open connection setup. ${error instanceof Error ? error.message : String(error)}`, + })) + return null + }) + if (!openingHere()) { + ctx.update((v) => (v.message === READING_CONNECTION_OPTIONS ? { ...v, message: '' } : v)) + return true + } + if (!options) return true + const [installed, connectionEngines] = options const download = connectionDownloadTarget(connectionDownload(s.workspace?.setups ?? [])) const preferred = s.setup?.selections[0]?.plan.model_id ?? s.setup?.path?.job?.model ?? (s.model || download.model) @@ -60,6 +89,7 @@ export async function connectionGuideAction(id: string, ctx: ActionContext): Pro connectionReturn: s.firstRun ? undefined : (s.connectionReturn ?? workspaceLocation(s)), overlay: 'connection-guide', focus: agent ? 'guide-configure' : 'guide-path:agent', + message: '', connection: { step: agent ? 'review' : 'choose', path: 'agent', diff --git a/src/tui/workspace/server/connection-guide.test.ts b/src/tui/workspace/server/connection-guide.test.ts index 89bcda42..a6e67325 100644 --- a/src/tui/workspace/server/connection-guide.test.ts +++ b/src/tui/workspace/server/connection-guide.test.ts @@ -10,6 +10,7 @@ import { workspaceFrame } from '../frame.js' import type { WorkspaceController } from '../controller.js' import { FIRST_RUN_STEPS } from '../../../contract/index.js' import { hit } from '../draw/canvas.js' +import { workspaceInput } from '../input.js' function fixture(fail = false) { let state = { ...createWorkspace('server'), setupComplete: true } const execute = vi.fn(async (name: string) => { @@ -52,6 +53,33 @@ it('opens an agent sidebar item at review and verifies before preparing its conn await activate('guide-copy', ctx) expect(ctx.copy).toHaveBeenCalledWith('atc connect codex --model local-model') }) +it('opens Hermes from the card title and shows progress while checking installed models', async () => { + const { ctx, execute } = fixture() + type Installed = Awaited> + let complete!: (models: Installed) => void + ctx.controller.installed = vi.fn( + () => + new Promise((resolve) => { + complete = resolve + }) + ) + ctx.update((s) => ({ ...s, serverQuery: 'Hermes Agent' })) + const frame = workspaceFrame(ctx.get(), 120, 36, 0) + const card = frame.targets.find((target) => target.id === 'server-agent:0')! + const { action } = workspaceInput(`\x1b[<0;${card.x + 8};${card.y + 2}M`, {} as never, ctx.get(), frame) + expect(action).toBe('server-agent:0') + const opening = activate(action!, ctx) + await vi.waitFor(() => expect(ctx.get().message).toBe('Checking installed models and engines…')) + expect(ctx.get().overlay).toBeNull() + complete([{ id: 'local-model', name: 'Local model', provider: 'llamacpp-upstream' }]) + await opening + expect(ctx.get()).toMatchObject({ + message: '', + overlay: 'connection-guide', + connection: { step: 'review', agent: 'hermes', model: 'local-model' }, + }) + expect(execute).not.toHaveBeenCalled() +}) it('returns failed inference to review without a success state or agent command', async () => { const { ctx, execute } = fixture(true) await activate('guide-agent:codex', ctx) diff --git a/src/tui/workspace/server/server-overview.ts b/src/tui/workspace/server/server-overview.ts index b473433a..9425791b 100644 --- a/src/tui/workspace/server/server-overview.ts +++ b/src/tui/workspace/server/server-overview.ts @@ -72,7 +72,18 @@ export function drawServerOverview( COLORS.muted, cardWidth - 4 ) - button(c, id, cx + 2, cy + 3, 'Configure >', `Configure ${agent.label}`, focus, false, true) + const active = focus === id + text( + c, + cx + 2, + cy + 3, + active ? '>Configure > ' : ' Configure > ', + active ? COLORS.ground : COLORS.text, + cardWidth - 4, + active ? COLORS.accent : COLORS.surface, + true + ) + c.targets.push({ id, x: cx, y: cy, width: cardWidth, height: 5, hint: `Configure ${agent.label}` }) }) scrollTrack(c, x + width - 1, y, rows * 5, offset, capacity, agents.length) if (!agents.length) text(c, x, y + 1, 'No matching agents.', COLORS.muted, width) From 5d610c9847aaf9217febc3f3e0825b68aac9f032 Mon Sep 17 00:00:00 2001 From: Biogenic Ooze Date: Tue, 17 Nov 2026 17:44:30 +0300 Subject: [PATCH 2/3] Configure agents through core and prepare v0.2.19 --- bun.lock | 3 + docs/commands.md | 2 +- ...026-11-17-configure-agents-through-core.md | 12 +++ docs/decisions/INDEX.md | 2 + docs/desktop-flow-parity.md | 2 +- package.json | 5 +- .../server/connection/ConnectionGuide.tsx | 20 +++- .../connection/connection-api-reuse.test.tsx | 20 ++++ patches/@atomic-chat%2Fcore@0.23.4.patch | 40 ++++++++ src/agent-launch/context-window.ts | 11 ++- src/agent-launch/core-integration.test.ts | 28 ++++++ src/agent-launch/core-integration.ts | 91 +++++++++++++++++++ src/agent-launch/index.ts | 2 + src/commands/access/connect.ts | 17 ++-- src/contract/desktop-flows.ts | 2 + src/contract/operations/server.ts | 14 +++ src/daemon/daemon.ts | 1 + src/tui/workspace/controller.ts | 8 +- src/tui/workspace/overlay.ts | 12 +-- src/tui/workspace/server/agent-actions.ts | 8 +- .../server/connection-dialog.test.ts | 1 + .../server/connection-error-layout.test.ts | 1 + .../server/connection-guide-actions.ts | 24 ++++- .../workspace/server/connection-guide-view.ts | 9 +- .../workspace/server/connection-guide.test.ts | 20 +++- src/tui/workspace/state.ts | 3 +- src/version.ts | 2 +- .../server-operations.test.ts | 50 +++++++++- src/workspace-service/server-operations.ts | 50 ++++++++-- src/workspace-service/service-options.ts | 3 + 30 files changed, 414 insertions(+), 49 deletions(-) create mode 100644 docs/decisions/2026-11-17-configure-agents-through-core.md create mode 100644 patches/@atomic-chat%2Fcore@0.23.4.patch create mode 100644 src/agent-launch/core-integration.test.ts create mode 100644 src/agent-launch/core-integration.ts diff --git a/bun.lock b/bun.lock index 7e90c21d..0ba89b55 100644 --- a/bun.lock +++ b/bun.lock @@ -63,6 +63,9 @@ }, }, }, + "patchedDependencies": { + "@atomic-chat/core@0.23.4": "patches/@atomic-chat%2Fcore@0.23.4.patch", + }, "packages": { "@adobe/css-tools": ["@adobe/css-tools@4.5.0", "", {}, "sha512-6OzddxPio9UiWTCemp4N8cYLV2ZN1ncRnV1cVGtve7dhPOtRkleRyx32GQCYSwDYgaHU3USMm84tNsvKzRCa1Q=="], diff --git a/docs/commands.md b/docs/commands.md index 226ee8b0..3184222d 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -362,7 +362,7 @@ Usage: atc connect [agent] [options] Connection details or launch an installed agent Arguments: - [agent] atomic-agent, claude, codex or opencode; omit for connection details + [agent] Agent ID from the connection catalog; omit for connection details Options: --model Model ID; defaults to first ready chat model diff --git a/docs/decisions/2026-11-17-configure-agents-through-core.md b/docs/decisions/2026-11-17-configure-agents-through-core.md new file mode 100644 index 00000000..4c2d6b03 --- /dev/null +++ b/docs/decisions/2026-11-17-configure-agents-through-core.md @@ -0,0 +1,12 @@ +--- +date: 2026-11-17 +title: "Configure agents through core" +--- + +# Configure agents through core + +- **Context:** Atomic Server offered isolated launch profiles for four agents. Agents such as Hermes required manual configuration even though core already knew how to edit their settings. +- **Decision:** Use the core integration catalog, host detection, configuration writers and launch arguments. The connection guide invokes a host operation after verifying the loaded model. CLI and terminal launches use core's launch environment, including for agents that select providers at startup. +- **Consequences:** Agents are configured for the server account where they are installed. Clients on other hosts and editors without a core writer receive endpoint details for manual setup. The host operation returns status and a launch command with a key ID, never the key. The isolated profile export remains available to existing CLI clients. +- **Compatibility:** The patch to core 0.23.4 exposes its existing integration module and adds the Muse arguments for an embedding server. Remove the patch when pinning a core release with both changes. +- **Owner:** team. diff --git a/docs/decisions/INDEX.md b/docs/decisions/INDEX.md index 0a1ee739..403513de 100644 --- a/docs/decisions/INDEX.md +++ b/docs/decisions/INDEX.md @@ -11,6 +11,8 @@ add a new one that says which record it supersedes. ## Records +- **2026-11-17** — [Configure agents through core](2026-11-17-configure-agents-through-core.md) — use the shared registry for host configuration and launches. + - **2026-11-17** — [Show progress when opening terminal agent setup](2026-11-17-show-terminal-agent-setup-progress.md) — make the full agent card clickable and show the options check. - **2026-11-17** — [Pair terminal connection engines with models](2026-11-17-pair-terminal-connection-engines-with-models.md) — filter the connection guide by active engines and compatible downloads. diff --git a/docs/desktop-flow-parity.md b/docs/desktop-flow-parity.md index 79be8450..805d6184 100644 --- a/docs/desktop-flow-parity.md +++ b/docs/desktop-flow-parity.md @@ -43,7 +43,7 @@ These are capability or terminal adaptations, not claims of exact desktop featur - Foundry Local uses the inline catalog family layout. A missing engine opens its installation controls; accelerator preparation runs from the family and returns there. Core compatibility blockers remain enforced. - Managed engine host permissions, engine-specific options and some diagnostics retain the existing server operation forms. Native desktop settings that have no server equivalent are not copied. - The terminal uses ASCII art and responsive text columns instead of raster model artwork. Search and credential text entry use a focused terminal editor. Compact terminals use a section menu and fewer metadata columns; supported minimum is 54×24. -- Hardware memory-fit estimates, undocumented model metadata and native provider OAuth are not fabricated. External agent installation/config-file writing is offered only where a supported launch profile exists; other agents receive manual connection details. +- Hardware memory-fit estimates, undocumented model metadata and native provider OAuth are not fabricated. The connection guide uses core to configure supported agents on the server host. Editors without a core writer and agents absent from that host receive manual connection details. - A working Cloudflare installation is required for remote tunnels. API/engine failures are shown as failures, not simulated success. ## User journeys and verification diff --git a/package.json b/package.json index 2391178f..8068701c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@atomicbot-ai/atc", - "version": "0.2.18", + "version": "0.2.19", "description": "atc — the Atomic Chat server CLI: install an inference engine, pull a model, serve it over an OpenAI-compatible API, and manage it from a local web admin.", "license": "Apache-2.0", "repository": { @@ -53,6 +53,9 @@ "pdfjs-dist": "4.8.69", "react": "^19.2.0" }, + "patchedDependencies": { + "@atomic-chat/core@0.23.4": "patches/@atomic-chat%2Fcore@0.23.4.patch" + }, "devDependencies": { "@eslint/js": "^9.36.0", "@types/node": "^22.18.0", diff --git a/packages/admin-ui/src/workspace/server/connection/ConnectionGuide.tsx b/packages/admin-ui/src/workspace/server/connection/ConnectionGuide.tsx index 9975b033..b931ce32 100644 --- a/packages/admin-ui/src/workspace/server/connection/ConnectionGuide.tsx +++ b/packages/admin-ui/src/workspace/server/connection/ConnectionGuide.tsx @@ -66,6 +66,7 @@ export function ConnectionGuide({ onConfigure?.() setStep('preparing') setError('') + setProfile(null) try { setStatus('Loading model') await execute('models.load', { provider: engine, model_id: modelId }) @@ -89,7 +90,14 @@ export function ConnectionGuide({ await execute('setup.complete', { model_id: modelId }) const info = record(await execute('connection.info')) setEndpoint(text(info.endpoint, `http://127.0.0.1:${port}${w.snapshot?.api.prefix ?? '/v1'}`)) - if (path === 'agent' && PROFILE_AGENTS.includes(agent)) { + if ( + path === 'agent' && + Array.isArray(info.configurable_agents) && + info.configurable_agents.includes(agent) + ) { + setStatus('Configuring agent on the server host') + setProfile(record(await execute('connection.configure', { agent, model: modelId, key_id: key }))) + } else if (path === 'agent' && PROFILE_AGENTS.includes(agent)) { setStatus('Preparing agent connection') setProfile(record(await execute('connection.profile', { agent, model: modelId, key_id: key }))) } @@ -202,14 +210,18 @@ export function ConnectionGuide({ return typeof v === 'string' ? v : text(record(v).token ?? record(v).key, '') }} /> - {path === 'agent' && !profile && ( + {path === 'agent' && !profile?.launch_command && !profile?.command && (

+ {profile?.reason ? `${text(profile.reason)} ` : ''} In {name}, choose an OpenAI-compatible provider and paste this endpoint, API key, and model ID.

)} - {profile && ( + {(profile?.launch_command || profile?.command) && ( <> -

Run this command to launch {name} with the prepared connection.

+

+ Run this command {profile.configured === true ? 'on the server host ' : ''}to launch {name}{' '} + with the prepared connection. +

{text(profile.launch_command ?? profile.command)}
diff --git a/packages/admin-ui/src/workspace/server/connection/connection-api-reuse.test.tsx b/packages/admin-ui/src/workspace/server/connection/connection-api-reuse.test.tsx index 93e1bae5..5e483e28 100644 --- a/packages/admin-ui/src/workspace/server/connection/connection-api-reuse.test.tsx +++ b/packages/admin-ui/src/workspace/server/connection/connection-api-reuse.test.tsx @@ -4,6 +4,26 @@ import { expect, it, vi } from 'vitest' import { workspaceFixture } from '@/test/workspace-fixture' import { ConnectionGuide } from './ConnectionGuide' +it('configures Hermes on the server host through core', async () => { + const { workspace, execute } = workspaceFixture({ + 'models.installed': [{ id: 'qwen', name: 'Qwen', providers: ['llamacpp-upstream'] }], + 'keys.list': [{ id: 'key' }], + 'connection.info': { endpoint: 'http://127.0.0.1:1339/v1', configurable_agents: ['hermes'] }, + 'connection.configure': { configured: true, launch_command: 'atc connect hermes --model qwen' }, + }) + render( + + ) + await userEvent.click(await screen.findByRole('button', { name: 'Configure & start' })) + expect(await screen.findByRole('button', { name: 'Copy launch command' })).toBeInTheDocument() + expect(execute).toHaveBeenCalledWith('connection.configure', { + agent: 'hermes', + model: 'qwen', + key_id: 'key', + }) + expect(screen.getByText(/on the server host to launch Hermes Agent/)).toBeInTheDocument() +}) + it.each([true, false])('connects without restarting the unchanged API (running=%s)', async (running) => { const { workspace, execute } = workspaceFixture({ 'models.installed': [{ id: 'qwen', name: 'Qwen', providers: ['llamacpp-upstream'] }], diff --git a/patches/@atomic-chat%2Fcore@0.23.4.patch b/patches/@atomic-chat%2Fcore@0.23.4.patch new file mode 100644 index 00000000..4b0e5d27 --- /dev/null +++ b/patches/@atomic-chat%2Fcore@0.23.4.patch @@ -0,0 +1,40 @@ +diff --git a/package.json b/package.json +--- a/package.json ++++ b/package.json +@@ -31,6 +31,10 @@ + "types": "./dist/host/index.d.ts", + "import": "./dist/host/index.js" + }, ++ "./integrations": { ++ "types": "./dist/integrations/index.d.ts", ++ "import": "./dist/integrations/index.js" ++ }, + "./models": { + "types": "./dist/models/index.d.ts", + "import": "./dist/models/index.js" +diff --git a/dist/integrations/catalog.js b/dist/integrations/catalog.js +--- a/dist/integrations/catalog.js ++++ b/dist/integrations/catalog.js +@@ -331,7 +331,9 @@ + * The arguments that start `agent` on `model`: its fixed `runArgs`, plus `--model atomic/` for + * Kilo, which otherwise opens on the model it last used before the one its config selects. + */ +-export function runArgsFor(agent, model) { ++export function runArgsFor(agent, model, apiUrl) { ++ if (agent.id === 'muse' && apiUrl) ++ return ['--provider', 'meta', '--base-url', apiUrl, ...(model ? ['--model', model] : [])]; + return agent.id === 'kilo' && model ? ['--model', `atomic/${model}`, ...agent.runArgs] : [...agent.runArgs]; + } + /** +diff --git a/dist/integrations/catalog.d.ts b/dist/integrations/catalog.d.ts +--- a/dist/integrations/catalog.d.ts ++++ b/dist/integrations/catalog.d.ts +@@ -63,7 +63,7 @@ + * The arguments that start `agent` on `model`: its fixed `runArgs`, plus `--model atomic/` for + * Kilo, which otherwise opens on the model it last used before the one its config selects. + */ +-export declare function runArgsFor(agent: Agent, model: string): string[]; ++export declare function runArgsFor(agent: Agent, model: string, apiUrl?: string): string[]; + /** + * Poolside's docs give the standalone base URL with its API prefix (`/v1`), so it is kept; only + * surrounding whitespace and trailing slashes go. diff --git a/src/agent-launch/context-window.ts b/src/agent-launch/context-window.ts index 57fed41a..2f228a0c 100644 --- a/src/agent-launch/context-window.ts +++ b/src/agent-launch/context-window.ts @@ -50,12 +50,17 @@ export async function readServedWindow( } /** Refuses a known window too small for the agent; an unknown one is left to the agent. */ -export function checkAgentWindow(agent: string, model: string, contextLength: number | undefined): void { - if (contextLength === undefined || contextLength >= AGENT_MIN_CONTEXT) return +export function checkAgentWindow( + agent: string, + model: string, + contextLength: number | undefined, + minimum = AGENT_MIN_CONTEXT +): void { + if (contextLength === undefined || contextLength >= minimum) return const tokens = (n: number) => n.toLocaleString('en-US') throw new AtcError( 'ATC_USAGE', - `${agent} needs a context window of at least ${tokens(AGENT_MIN_CONTEXT)} tokens; ${model} is served with ${tokens(contextLength)}.`, + `${agent} needs a context window of at least ${tokens(minimum)} tokens; ${model} is served with ${tokens(contextLength)}.`, { hint: 'Load the model with a larger context size (turn off "Fit context to device memory" in the engine settings), or choose a smaller model.', } diff --git a/src/agent-launch/core-integration.test.ts b/src/agent-launch/core-integration.test.ts new file mode 100644 index 00000000..9727149e --- /dev/null +++ b/src/agent-launch/core-integration.test.ts @@ -0,0 +1,28 @@ +import { expect, it, vi } from 'vitest' +import { tmpDataFolder } from '../../test/helpers/tmp-data-folder.js' +import { prepareCoreAgent } from './core-integration.js' + +it('uses core launch arguments and the server credential for Muse', async () => { + const tmp = tmpDataFolder() + try { + const home = tmp.paths.dataFolder + const endpoint = 'http://127.0.0.1:1339/v1' + const launch = await prepareCoreAgent('muse', endpoint, 'local-model', 'server-key', { + cwd: home, + folder: home, + platform: 'linux', + env: { HOME: home, OPENAI_API_KEY: 'other-provider' }, + exec: vi.fn(), + find: (bin) => (bin === 'muse' ? '/usr/bin/muse' : undefined), + request: async () => Response.json({ data: [{ id: 'local-model', context_length: 65536 }] }), + }) + expect(launch).toMatchObject({ + command: '/usr/bin/muse', + args: ['--provider', 'meta', '--base-url', endpoint, '--model', 'local-model'], + env: { META_API_KEY: 'server-key' }, + }) + expect(launch.env).not.toHaveProperty('OPENAI_API_KEY') + } finally { + tmp.cleanup() + } +}) diff --git a/src/agent-launch/core-integration.ts b/src/agent-launch/core-integration.ts new file mode 100644 index 00000000..c6cf4afd --- /dev/null +++ b/src/agent-launch/core-integration.ts @@ -0,0 +1,91 @@ +import { + apiUrlFor, + childEnv, + configureAgent, + CONFLICTING_PROVIDER_ENV, + detectAgent, + findAgent, + HERMES_CONTEXT_LENGTH, + registeredAgents, + runArgsFor, +} from '@atomic-chat/core/integrations' +import { AtcError } from '../errors/index.js' +import { checkAgentWindow, readServedWindow } from './context-window.js' +import type { AgentLaunch } from './plan.js' +import type { AgentHost } from './prepare.js' +import { spawnTarget } from './spawn-target.js' + +export type IntegrationHost = Pick +const writers = new Set(registeredAgents()) + +export function coreAgent(id: string) { + const agent = findAgent(id) + return agent && writers.has(agent.id) ? agent : undefined +} + +/** Configure the active profile on the host that owns the agent, using the core's writer. */ +export async function configureCoreAgent( + id: string, + endpoint: string, + model: string, + key: string, + host: IntegrationHost, + contextLength?: number +) { + const agent = coreAgent(id) + if (!agent) throw new AtcError('ATC_USAGE', 'This agent uses manual endpoint setup.') + const detection = await detectAgent(agent, { + platform: host.platform, + env: host.env, + onPath: async (bin) => Boolean(host.find(bin)), + }) + if (!detection.installed) return { reason: `${agent.name} was not found on the server host.` } as const + checkAgentWindow( + agent.name, + model, + contextLength, + agent.id === 'hermes' ? HERMES_CONTEXT_LENGTH : undefined + ) + const url = new URL(endpoint) + const apiPrefix = url.pathname.replace(/\/$/, '') + const apiUrl = apiUrlFor(agent, url.origin, apiPrefix) + await configureAgent(agent, apiUrl, model, key, { + env: host.env, + platform: host.platform, + program: detection.path ?? host.find(detection.program) ?? detection.program, + spawn: async (program, args) => { + const result = await host.exec(program, args, { env: host.env }) + return { code: result.code ?? 1, stdout: result.stdout, stderr: result.stderr } + }, + ...(contextLength ? { contextLength } : {}), + }) + return { agent, detection, apiUrl, apiPrefix } as const +} + +export async function prepareCoreAgent( + id: string, + endpoint: string, + model: string, + key: string, + host: AgentHost +): Promise { + const contextLength = await readServedWindow(host.request, endpoint, key, model) + const result = await configureCoreAgent(id, endpoint, model, key, host, contextLength) + if ('reason' in result) throw new AtcError('ATC_USAGE', result.reason) + const { agent, detection, apiUrl, apiPrefix } = result + const program = detection.path ?? host.find(detection.program) ?? detection.program + const args = runArgsFor(agent, model, apiUrl) + const env = { ...host.env } + for (const name of CONFLICTING_PROVIDER_ENV) delete env[name] + const target = spawnTarget(program, args, host.platform) + return { + command: target.file, + args: target.args, + cwd: host.cwd, + env: { + ...env, + ...childEnv(agent, apiUrl, model, key, { apiPrefix, ...(contextLength ? { contextLength } : {}) }), + }, + ...(target.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}), + } +} diff --git a/src/agent-launch/index.ts b/src/agent-launch/index.ts index 8b98112a..4ed9dbc1 100644 --- a/src/agent-launch/index.ts +++ b/src/agent-launch/index.ts @@ -5,3 +5,5 @@ export { prepareAgent } from './prepare.js' export type { AgentHost } from './prepare.js' export { runAgent } from './interactive.js' export { AGENT_MIN_CONTEXT, checkAgentWindow, servedWindow } from './context-window.js' +export { configureCoreAgent, coreAgent, prepareCoreAgent } from './core-integration.js' +export type { IntegrationHost } from './core-integration.js' diff --git a/src/commands/access/connect.ts b/src/commands/access/connect.ts index b56b2f95..1ffbdfb8 100644 --- a/src/commands/access/connect.ts +++ b/src/commands/access/connect.ts @@ -1,5 +1,5 @@ import { join } from 'node:path' -import { AGENTS, prepareAgent, runAgent } from '../../agent-launch/index.js' +import { AGENTS, coreAgent, prepareCoreAgent, runAgent } from '../../agent-launch/index.js' import { AtcError, defineCommand } from '../../cli/index.js' import { ClientKeys } from '../../terminal-data/index.js' import { workspace, operation } from '../server/control.js' @@ -8,7 +8,7 @@ export const connectCommand = defineCommand({ summary: 'Connection details or launch an installed agent', group: 'access', positionals: [ - { name: 'agent', description: 'atomic-agent, claude, codex or opencode; omit for connection details' }, + { name: 'agent', description: 'Agent ID from the connection catalog; omit for connection details' }, ], options: { 'model': { type: 'string', description: 'Model ID; defaults to first ready chat model' }, @@ -18,8 +18,7 @@ export const connectCommand = defineCommand({ run: async (inv, ctx) => { const id = inv.positionals[0] if (!id) return operation(ctx, 'connection.info') - const agent = AGENTS.find((a) => a.id === id) - if (!agent) throw new AtcError('ATC_USAGE', `Choose ${AGENTS.map((a) => a.id).join(', ')}.`) + if (!coreAgent(id)) throw new AtcError('ATC_USAGE', 'This agent uses manual endpoint setup.') const service = await workspace(ctx) const state = await service.snapshot() if (!state.api.running) @@ -33,14 +32,20 @@ export const connectCommand = defineCommand({ hint: 'atc models list; atc run ', }) const keyId = typeof inv.values['key-id'] === 'string' ? inv.values['key-id'] : undefined - if (inv.values['export'] || ctx.flags.json) + if (inv.values['export'] || ctx.flags.json) { + if (!AGENTS.some((agent) => agent.id === id)) + throw new AtcError( + 'ATC_USAGE', + 'This agent cannot export an isolated launch profile. Run connect in a terminal.' + ) return operation(ctx, 'connection.profile', { agent: id, model, ...(keyId ? { key_id: keyId } : {}) }) + } if (!ctx.io.isTTY.stdin || !ctx.io.isTTY.stdout) throw new AtcError('ATC_USAGE', 'Use --export in a script, or launch the agent from a terminal.') const keys = new ClientKeys(ctx.paths.atcDir) const key = await keys.get(keyId) if (!key) throw new AtcError('ATC_USAGE', 'The selected API key no longer exists.') - const launch = await prepareAgent(agent.id, state.api.endpoint, model, key, { + const launch = await prepareCoreAgent(id, state.api.endpoint, model, key, { env: ctx.io.env, cwd: ctx.io.cwd, folder: join(ctx.paths.atcDir, 'agents'), diff --git a/src/contract/desktop-flows.ts b/src/contract/desktop-flows.ts index e18e88c7..e0e73f41 100644 --- a/src/contract/desktop-flows.ts +++ b/src/contract/desktop-flows.ts @@ -53,6 +53,8 @@ export interface ConnectionDraft { status: string error: string command: string + agentConfigured?: boolean + agentSetupNote?: string endpoint: string keyId: string } diff --git a/src/contract/operations/server.ts b/src/contract/operations/server.ts index 2bbbba75..4491bb29 100644 --- a/src/contract/operations/server.ts +++ b/src/contract/operations/server.ts @@ -72,6 +72,20 @@ export const SERVER_OPERATIONS: readonly WorkspaceOperation[] = [ 'read', 'List the coding agents atc can configure to use this server.' ), + operation( + 'connection.configure', + 'Configure agent on this host', + 'execute', + 'Use core to configure an installed agent for the loaded model and an existing API key on the server host. Returns connection status and a launch command.', + { + properties: { + agent: { type: 'string' }, + model: { type: 'string' }, + key_id: { type: 'string' }, + }, + required: ['agent', 'model'], + } + ), operation( 'connection.profile', 'Prepare agent connection', diff --git a/src/daemon/daemon.ts b/src/daemon/daemon.ts index 29e6ee69..2fc8c432 100644 --- a/src/daemon/daemon.ts +++ b/src/daemon/daemon.ts @@ -153,6 +153,7 @@ export async function startDaemon(options: DaemonOptions): Promise { return listChatModels( diff --git a/src/tui/workspace/overlay.ts b/src/tui/workspace/overlay.ts index 925ffd42..97412998 100644 --- a/src/tui/workspace/overlay.ts +++ b/src/tui/workspace/overlay.ts @@ -20,7 +20,7 @@ import { drawEnginePanel } from './library/engine-panel.js' import { drawGoalSetup } from './setup/goal-setup.js' import { drawOperationOverlay } from './operations/operation-panel.js' import { sectionMenu } from './navigation/navigation.js' -import { AGENTS } from '../../agent-launch/index.js' +import { coreAgent } from '../../agent-launch/index.js' import { button, COLORS, text, wrap } from './draw/canvas.js' import type { Canvas } from './draw/canvas.js' import type { WorkspaceState } from './state.js' @@ -163,17 +163,11 @@ export function drawOverlay(c: Canvas, s: WorkspaceState, focus: string, seconds b('library:downloads', 9, 'Downloads', 'Review background downloads and resume interrupted jobs.') b('choose-goal', 10, 'Set up a service', 'Prepare an engine and model for your clients.') } else if (s.overlay === 'agent') { - put(2, `Use with ${AGENTS.find((a) => a.id === s.agent)?.name}`, COLORS.accent) + put(2, `Use with ${coreAgent(s.agent)?.name ?? s.agent}`, COLORS.accent) put(4, 'Atomic Server provides the model for this session.', COLORS.muted) b('agent-model', 6, `Model: ${s.agentModel}`, 'Choose the next available model.') put(8, 'Launch switches this terminal to the agent. Exit it to return.', COLORS.muted) - put( - 10, - s.agent === 'atomic-agent' - ? 'Uses a separate server profile for Atomic Agent.' - : 'Your existing provider settings are preserved.', - COLORS.muted - ) + put(10, 'Uses this host’s agent configuration.', COLORS.muted) b('launch-agent', h - 3, 'Launch and switch', 'Open the agent with Atomic Server as its model provider.') button(c, 'close', x + 25, y + h - 3, 'Cancel', 'Return to Server.', focus) return diff --git a/src/tui/workspace/server/agent-actions.ts b/src/tui/workspace/server/agent-actions.ts index d5b44393..d2eaea10 100644 --- a/src/tui/workspace/server/agent-actions.ts +++ b/src/tui/workspace/server/agent-actions.ts @@ -1,6 +1,5 @@ /** The agent sidebar: a model for the agent, a model switch, and the handoff that leaves the terminal. */ import type { ActionContext } from '../action-types.js' -import type { AgentId } from '../../../agent-launch/index.js' import { serverEndpoint } from './connection.js' import type { WorkspaceState } from '../state.js' @@ -24,9 +23,12 @@ export async function agentAction(id: string, ctx: ActionContext): Promise { +it('opens Hermes from the card title, shows progress, and configures it through core', async () => { const { ctx, execute } = fixture() + execute.mockImplementation(async (name) => { + if (name === 'keys.list') return [{ id: 'key' }] + if (name === 'connection.info') return { configurable_agents: ['hermes'] } + if (name === 'connection.configure') + return { configured: true, launch_command: 'atc connect hermes --model local-model' } + return {} + }) type Installed = Awaited> let complete!: (models: Installed) => void ctx.controller.installed = vi.fn( @@ -79,6 +86,17 @@ it('opens Hermes from the card title and shows progress while checking installed connection: { step: 'review', agent: 'hermes', model: 'local-model' }, }) expect(execute).not.toHaveBeenCalled() + await activate('guide-configure', ctx) + expect(execute).toHaveBeenCalledWith('connection.configure', { + agent: 'hermes', + model: 'local-model', + key_id: 'key', + }) + expect(ctx.get().connection).toMatchObject({ + step: 'done', + agentConfigured: true, + command: 'atc connect hermes --model local-model', + }) }) it('returns failed inference to review without a success state or agent command', async () => { const { ctx, execute } = fixture(true) diff --git a/src/tui/workspace/state.ts b/src/tui/workspace/state.ts index a79991fd..bbce1015 100644 --- a/src/tui/workspace/state.ts +++ b/src/tui/workspace/state.ts @@ -19,7 +19,6 @@ import type { LibraryRow, LibraryView } from './library/library-model.js' import type { WorkspaceSnapshot, WorkspaceOperation } from '../../contract/index.js' import type { Conversation, ConversationSummary, ClientKeyView } from '../../terminal-data/index.js' import type { SetupView, EngineChoice } from '../../terminal-setup/index.js' -import type { AgentId } from '../../agent-launch/index.js' import type { ChatImage, ChatMessage, RequestRow } from '../../terminal-service/index.js' import type { CommandRow } from '../command-list.js' import { initialState, type TuiState } from '../state.js' @@ -128,7 +127,7 @@ export interface WorkspaceState extends WorkspaceReturnState { engines: EngineChoice[] pickerBusy: boolean pickerError: string - agent: AgentId + agent: string agentModel: string commands: CommandRow[] base: TuiState diff --git a/src/version.ts b/src/version.ts index ea91e72e..86b535b2 100644 --- a/src/version.ts +++ b/src/version.ts @@ -7,7 +7,7 @@ declare const __ATC_GIT_SHA__: string | undefined declare const __ATC_BUILD_DATE__: string | undefined declare const __ATC_TARGET__: string | undefined -export const ATC_VERSION = '0.2.18' +export const ATC_VERSION = '0.2.19' export const ATC_GIT_SHA: string | undefined = typeof __ATC_GIT_SHA__ === 'string' && __ATC_GIT_SHA__ !== '' ? __ATC_GIT_SHA__ : undefined diff --git a/src/workspace-service/server-operations.test.ts b/src/workspace-service/server-operations.test.ts index 4c81c10d..67ed96a0 100644 --- a/src/workspace-service/server-operations.test.ts +++ b/src/workspace-service/server-operations.test.ts @@ -1,7 +1,10 @@ import { describe, expect, it, vi } from 'vitest' +import { mkdir, readFile, writeFile } from 'node:fs/promises' +import { join } from 'node:path' +import { tmpDataFolder } from '../../test/helpers/tmp-data-folder.js' import { defaultConfig } from '../config/index.js' import { fakeCoreLink } from '../../test/helpers/fake-core-link.js' -import { serverOperation } from './server-operations.js' +import { serverOperation, type ServerParts } from './server-operations.js' import { NOT_CORE } from './not-core.js' function parts(over: Record = {}) { @@ -93,6 +96,51 @@ describe('server operations', () => { }) }) + it('uses core to configure the active Hermes profile and returns a launch command without the key', async () => { + const tmp = tmpDataFolder() + try { + const home = tmp.paths.dataFolder + const root = join(home, '.hermes') + const profile = join(root, 'profiles', 'work') + await mkdir(profile, { recursive: true }) + await writeFile(join(root, 'active_profile'), 'work\n') + const config = join(profile, 'config.yaml') + await writeFile(config, '# Keep my comment\nmodel:\n default: previous\n') + const fixture = parts({ + request: async () => Response.json({ data: [{ id: 'm', context_length: 65536 }] }), + }) + const p = fixture.parts as ServerParts + p.options.agentHost = { + env: { HOME: home, HERMES_HOME: root }, + platform: 'linux', + find: (bin) => (bin === 'hermes' ? '/usr/bin/hermes' : undefined), + exec: vi.fn(), + } + fixture.link.snapshotValue.server.running = true + fixture.link.snapshotValue.sessions = [{ model_id: 'm' }] as never + const info = await serverOperation(p, 'connection.info', {}) + expect(info).toMatchObject({ + configurable_agents: expect.arrayContaining(['hermes', 'muse', 'claude']), + }) + expect(info).not.toMatchObject({ configurable_agents: expect.arrayContaining(['jetbrains']) }) + const result = await serverOperation(p, 'connection.configure', { + agent: 'hermes', + model: 'm', + key_id: 'k1', + }) + expect(result).toMatchObject({ configured: true, launch_command: expect.stringContaining('connect') }) + expect(JSON.stringify(result)).not.toContain('key-1') + const updated = await readFile(config, 'utf8') + expect(updated).toContain('# Keep my comment') + expect(updated).toContain('provider: custom') + expect(updated).toContain('key-1') + expect(updated).toContain('context_length: 65536') + expect(await readFile(config + '.atomic-chat-backup.json', 'utf8')).toContain('previous') + } finally { + tmp.cleanup() + } + }) + it('refuses to finish guided setup without a running API and a loaded model', async () => { const snapshot = async () => ({ api: { running: false }, services: [] }) await expect(serverOperation(parts({ snapshot }).parts, 'setup.complete', {})).rejects.toThrow( diff --git a/src/workspace-service/server-operations.ts b/src/workspace-service/server-operations.ts index 24975192..45d2ff85 100644 --- a/src/workspace-service/server-operations.ts +++ b/src/workspace-service/server-operations.ts @@ -2,9 +2,21 @@ import { join } from 'node:path' import { AtcError } from '../errors/index.js' -import { AGENTS, agentProfile, checkAgentWindow, servedWindow, type AgentId } from '../agent-launch/index.js' +import { + AGENTS, + agentProfile, + checkAgentWindow, + configureCoreAgent, + coreAgent, + servedWindow, +} from '../agent-launch/index.js' import type { ClientKeys } from '../terminal-data/index.js' -import { WORKSPACE_OPERATIONS, type WorkspaceInput, type WorkspaceSnapshot } from '../contract/index.js' +import { + CONNECTION_AGENTS, + WORKSPACE_OPERATIONS, + type WorkspaceInput, + type WorkspaceSnapshot, +} from '../contract/index.js' import type { WorkspaceServiceOptions } from './service-options.js' import type { WorkspaceMetrics } from './snapshot/metrics.js' import { object, sanitized } from './validation.js' @@ -17,6 +29,13 @@ import { workspaceLogs } from './workspace-logs.js' import { NOT_CORE } from './not-core.js' import { apiDownloadWait } from '../workspace-view/index.js' import { startApi } from '../terminal-service/index.js' +import { SerialWork } from './serial.js' + +const agentWrites = new SerialWork() +const agentCatalog = CONNECTION_AGENTS.flatMap(({ id }) => { + const agent = coreAgent(id) + return agent ? [{ id, name: agent.name, bins: [agent.detectBin], docs: agent.docsUrl }] : [] +}) export interface ServerParts { restoreSelection?: () => Promise @@ -72,12 +91,14 @@ export async function serverOperation( return { ...publicEndpoint(object(await link.server.status()), config), keys: await keys.list(), - agents: AGENTS, + agents: agentCatalog, + configurable_agents: options.agentHost ? agentCatalog.map(({ id }) => id) : [], } case 'connection.agents': - return AGENTS + return agentCatalog + case 'connection.configure': case 'connection.profile': { - const agent = String(input['agent']) as AgentId, + const agent = String(input['agent']), model = String(input['model']), state = await link.server.status(), base = publicEndpoint(object(state), config).endpoint, @@ -94,14 +115,27 @@ export async function serverOperation( ), model ) - checkAgentWindow(AGENTS.find((a) => a.id === agent)?.name ?? agent, model, context_length) + const launch_command = `${commandPrefix(options)} connect ${shellWord(agent)} --model ${shellWord(model)}${input['key_id'] ? ` --key-id ${shellWord(String(input['key_id']))}` : ''}` + if (operation === 'connection.configure') { + const host = options.agentHost + if (!host) throw new AtcError('ATC_USAGE', 'Agent configuration is unavailable on this host.') + const result = await agentWrites.run('agent-config', () => + configureCoreAgent(agent, base, model, key, host, context_length) + ) + return 'reason' in result + ? { configured: false, reason: result.reason } + : { configured: true, launch_command } + } + const legacy = AGENTS.find((a) => a.id === agent) + if (!legacy) throw new AtcError('ATC_USAGE', 'This agent does not have an isolated launch profile.') + checkAgentWindow(legacy.name, model, context_length) return { agent, endpoint: base, model, context_length: context_length ?? null, profile: agentProfile( - agent, + legacy.id, base, model, key, @@ -109,7 +143,7 @@ export async function serverOperation( 1, context_length ), - launch_command: `${commandPrefix(options)} connect ${agent} --model ${shellWord(model)}${input['key_id'] ? ` --key-id ${shellWord(String(input['key_id']))}` : ''}`, + launch_command, } } case 'keys.list': diff --git a/src/workspace-service/service-options.ts b/src/workspace-service/service-options.ts index a74529ea..642455f1 100644 --- a/src/workspace-service/service-options.ts +++ b/src/workspace-service/service-options.ts @@ -1,4 +1,5 @@ import type { CoreLink } from '../core-link/index.js' +import type { IntegrationHost } from '../agent-launch/index.js' import type { AtcConfig, AtcPaths } from '../config/index.js' import type { ErrorSink } from '../telemetry/index.js' import type { RemoteAccessSetup, WorkspaceAtc } from '../contract/index.js' @@ -12,6 +13,8 @@ export interface WorkspaceServiceOptions { selfCommand?: readonly string[] /** The server's environment: `HF_TOKEN` for gated model downloads. */ env?: NodeJS.ProcessEnv + /** The account and tools used to configure agents installed on the server host. */ + agentHost?: IntegrationHost /** atc's own error reports: failed model downloads go there. */ errors?: ErrorSink /** Is a port free on every address that can shadow it? `api.start` refuses a busy one. */ From 9bfa316ca92f4eedb5f89c40f77504c07c477d9f Mon Sep 17 00:00:00 2001 From: Biogenic Ooze Date: Tue, 17 Nov 2026 17:54:00 +0300 Subject: [PATCH 3/3] Keep agent launch and execution contracts compatible --- src/agent-launch/core-integration.ts | 34 +++++++++++++++-------- src/contract/workspace-operations.test.ts | 5 ++-- test/contract/agent-handoff.test.ts | 18 ++++++++++-- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/agent-launch/core-integration.ts b/src/agent-launch/core-integration.ts index c6cf4afd..7e82963d 100644 --- a/src/agent-launch/core-integration.ts +++ b/src/agent-launch/core-integration.ts @@ -11,7 +11,7 @@ import { } from '@atomic-chat/core/integrations' import { AtcError } from '../errors/index.js' import { checkAgentWindow, readServedWindow } from './context-window.js' -import type { AgentLaunch } from './plan.js' +import { AGENTS, type AgentLaunch } from './plan.js' import type { AgentHost } from './prepare.js' import { spawnTarget } from './spawn-target.js' @@ -23,6 +23,8 @@ export function coreAgent(id: string) { return agent && writers.has(agent.id) ? agent : undefined } +const legacyAgent = (id: string) => AGENTS.find((agent) => findAgent(agent.id)?.id === id) + /** Configure the active profile on the host that owns the agent, using the core's writer. */ export async function configureCoreAgent( id: string, @@ -30,16 +32,19 @@ export async function configureCoreAgent( model: string, key: string, host: IntegrationHost, - contextLength?: number + context?: number | (() => Promise) ) { const agent = coreAgent(id) if (!agent) throw new AtcError('ATC_USAGE', 'This agent uses manual endpoint setup.') + const onPath = (legacyAgent(agent.id)?.bins ?? [agent.detectBin]).map((bin) => host.find(bin)).find(Boolean) const detection = await detectAgent(agent, { platform: host.platform, env: host.env, - onPath: async (bin) => Boolean(host.find(bin)), + onPath: async () => Boolean(onPath), }) - if (!detection.installed) return { reason: `${agent.name} was not found on the server host.` } as const + if (!detection.installed) + return { agent, reason: `${agent.name} was not found on the server host.` } as const + const contextLength = typeof context === 'function' ? await context() : context checkAgentWindow( agent.name, model, @@ -49,17 +54,18 @@ export async function configureCoreAgent( const url = new URL(endpoint) const apiPrefix = url.pathname.replace(/\/$/, '') const apiUrl = apiUrlFor(agent, url.origin, apiPrefix) + const program = detection.path ?? onPath ?? detection.program await configureAgent(agent, apiUrl, model, key, { env: host.env, platform: host.platform, - program: detection.path ?? host.find(detection.program) ?? detection.program, + program, spawn: async (program, args) => { const result = await host.exec(program, args, { env: host.env }) return { code: result.code ?? 1, stdout: result.stdout, stderr: result.stderr } }, ...(contextLength ? { contextLength } : {}), }) - return { agent, detection, apiUrl, apiPrefix } as const + return { agent, program, apiUrl, apiPrefix, contextLength } as const } export async function prepareCoreAgent( @@ -69,11 +75,17 @@ export async function prepareCoreAgent( key: string, host: AgentHost ): Promise { - const contextLength = await readServedWindow(host.request, endpoint, key, model) - const result = await configureCoreAgent(id, endpoint, model, key, host, contextLength) - if ('reason' in result) throw new AtcError('ATC_USAGE', result.reason) - const { agent, detection, apiUrl, apiPrefix } = result - const program = detection.path ?? host.find(detection.program) ?? detection.program + const result = await configureCoreAgent(id, endpoint, model, key, host, () => + readServedWindow(host.request, endpoint, key, model) + ) + if ('reason' in result) { + const legacy = legacyAgent(result.agent.id) + throw new AtcError( + 'ATC_USAGE', + `${legacy?.name ?? result.agent.name} is not installed on PATH. Install it from ${legacy?.docs ?? result.agent.docsUrl}` + ) + } + const { agent, program, apiUrl, apiPrefix, contextLength } = result const args = runArgsFor(agent, model, apiUrl) const env = { ...host.env } for (const name of CONFLICTING_PROVIDER_ENV) delete env[name] diff --git a/src/contract/workspace-operations.test.ts b/src/contract/workspace-operations.test.ts index e44802ff..371849dc 100644 --- a/src/contract/workspace-operations.test.ts +++ b/src/contract/workspace-operations.test.ts @@ -18,10 +18,11 @@ describe('the workspace operation registry', () => { } ) - // A connector defines or runs a program on the host: an agent gets these only with `atc mcp --allow-exec`. - it('marks every operation that defines or runs a connector program as execute', () => { + // An operation can define or run a program on the host only with `atc mcp --allow-exec`. + it('marks operations that define or run a host program as execute', () => { const execute = WORKSPACE_OPERATIONS.filter((op) => op.effect === 'execute').map((op) => op.name) expect(execute.sort()).toEqual([ + 'connection.configure', 'connectors.call', 'connectors.check', 'connectors.import', diff --git a/test/contract/agent-handoff.test.ts b/test/contract/agent-handoff.test.ts index fd587fe8..bf4c0bf2 100644 --- a/test/contract/agent-handoff.test.ts +++ b/test/contract/agent-handoff.test.ts @@ -8,6 +8,7 @@ import { fakeTerminal, eventually } from '../helpers/fake-terminal.js' import { tmpDataFolder } from '../helpers/tmp-data-folder.js' import { createWorkspace } from '../../src/tui/workspace/state.js' import { workspaceFrame } from '../../src/tui/workspace/frame.js' +import { join } from 'node:path' it('releases mouse capture before handing off and returns to Server without stopping the API', async () => { const tmp = tmpDataFolder(), terminal = fakeTerminal(120, 36), @@ -26,8 +27,8 @@ it('releases mouse capture before handing off and returns to Server without stop agentHost: { folder: tmp.paths.dataFolder, cwd: tmp.paths.dataFolder, - env: {}, - find: () => '/fake/atag', + env: { HOME: tmp.paths.dataFolder }, + find: (name) => (name === 'atag' ? '/fake/atag' : undefined), exec: async () => ({ code: 0, stdout: '0.6.6', stderr: '', timedOut: false }), platform: 'linux', request: (async () => Response.json({ data: [{ id: 'test-model' }] })) as typeof fetch, @@ -35,7 +36,18 @@ it('releases mouse capture before handing off and returns to Server without stop launchAgent: async (launch) => { expect(terminal.stdout.writes.join('')).toContain('\u001b[?1006l') expect(launch.command).toBe('/fake/atag') - expect(launch.env['ATOMIC_AGENT_STATE_DIR']).toContain(tmp.paths.dataFolder) + const config = await readTextFile(join(tmp.paths.dataFolder, '.atomic-agent', 'config.json')) + expect(JSON.parse(config!)).toMatchObject({ + llm: { + activeTextProvider: 'atomic-chat', + providers: expect.arrayContaining([ + expect.objectContaining({ + id: 'atomic-chat', + defaultChatModel: 'test-model', + }), + ]), + }, + }) launched = true }, deps: {