Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ platform API version.
reader last left it, in any diagram of the product (kept in the webview's
storage under `<settingsNamespace>.palette`, as the view options'
headings are).
- **The chat's agent starts when the chat is first used.** Each editor's
chat panel started its profile's agent at its handshake, whether or not
the chat was used: a product with two profiles kept two agents (an ACP
process and its server each, some 400 MB together) from its first editors
on, until the window closed. The agent now starts at the chat's first use:
a message sent, a chat made or opened from the list, a chat deleted (so
the agent's copy goes too), Diagnose Connection. Until then the panel
reads "Not started", and the first use shows "Connecting…". Once the
profile's last editor has closed and no turn has run for 30 s, the agent
is stopped; the next use starts it again, and each chat is loaded into it
again when it is next opened or written to, as after a reload. An editor
opened within the 30 s keeps it. A change of the connector setting starts
no agent before the first use. `DiagramChatConfig.agentStart: 'eager'`
(the toolkit's `chat.agentStart`) keeps the start at the handshake, and the
agent until the window closes.

### Fixed

Expand Down
30 changes: 26 additions & 4 deletions packages/diagram-client/src/chat-panel-integrated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ export class ChatPanel implements IDiagramStartup, ISelectionListener {
private currentModel = '';
/** True when the session is in a reverted state (shows the redo banner). */
private reverted = false;
private connection: 'unknown' | 'connected' | 'disconnected' = 'unknown';
/** `notStarted`: the host starts the agent at the chat's first use, not before. */
private connection: 'unknown' | 'connected' | 'disconnected' | 'notStarted' = 'unknown';
private connectionReason = '';
/** The ACP connector the chat is (or was) connected to, as the host names it. */
private connectionAgent = '';
Expand Down Expand Up @@ -758,7 +759,9 @@ export class ChatPanel implements IDiagramStartup, ISelectionListener {
break;

case 'chat.connectionStatus':
if (!data?.connected && data?.connecting) {
if (!data?.connected && data?.notStarted) {
this.setNotStarted();
} else if (!data?.connected && data?.connecting) {
this.setConnecting();
} else {
this.setConnectionStatus(!!data?.connected, data?.reason, data?.agent, data?.images);
Expand Down Expand Up @@ -1206,6 +1209,21 @@ export class ChatPanel implements IDiagramStartup, ISelectionListener {
this.update();
}

/** The agent starts at the chat's first use: "Not started", a state and
* not a fault, so no row in the timeline; the next status is news. */
private setNotStarted(): void {
this.receivedStatus = true;
if (this.statusHandshakeTimer !== null) {
clearTimeout(this.statusHandshakeTimer);
this.statusHandshakeTimer = null;
}
this.connection = 'notStarted';
this.connectionReason = '';
this.agentTakesImages = undefined;
this.lastStatusKey = '';
this.update();
}

// ── Outbound actions ───────────────────────────────────────────────────

private sendMessage(): void {
Expand Down Expand Up @@ -1957,13 +1975,17 @@ export class ChatPanel implements IDiagramStartup, ISelectionListener {
? this.handOver
? `In the CLI · ${this.handOver.agent}`
: 'Disconnected'
: 'Connecting…';
: status === 'notStarted'
? 'Not started'
: 'Connecting…';
const statusTitle =
status === 'disconnected' && this.connectionReason
? `${agent || 'agent'}: ${this.connectionReason}`
: status === 'connected' && agent
? `Connected to the ${agent} ACP connector`
: 'agent connection';
: status === 'notStarted'
? 'The agent starts when a message is sent, or a chat is made or opened'
: 'agent connection';
return html`
<header class="chat-topbar">
<span class="chat-title">
Expand Down
3 changes: 3 additions & 0 deletions packages/diagram-client/src/chat-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@
.chat-status.status-disconnected .chat-status-dot {
background: var(--vscode-testing-iconFailed, #f14c4c);
}
.chat-status.status-notStarted .chat-status-dot {
background: var(--chat-muted);
}

/* ── Message area: fixed-height drawer that slides open ── */
.chat-scroll {
Expand Down
24 changes: 24 additions & 0 deletions packages/diagram-client/test/chat-panel-connected-agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,27 @@ describe('a change of agent in the panel', () => {
expect((panel as any).models).toEqual([{ id: 'sonnet', name: 'Sonnet' }]);
});
});

describe('an agent the host starts at the chat\'s first use', () => {
const systemRows = (panel: ChatPanel) =>
((panel as any).timeline as any[]).filter((t) => t.kind === 'message' && t.role === 'system').map((t) => t.content);

it('reads "Not started", with no row, until the first use starts it', () => {
const panel = makePanel();
(panel as any).handleIncomingMessage('chat.connectionStatus', {
connected: false, notStarted: true, reason: 'the agent starts when the chat is first used'
});
const before = JSON.stringify((panel as any).topbarTemplate().values);
expect(before).toContain('Not started');
expect(before).not.toContain('Disconnected');
expect(systemRows(panel)).toEqual([]);
// The handshake was answered: no "No response from extension host" later.
expect((panel as any).receivedStatus).toBe(true);

(panel as any).handleIncomingMessage('chat.connectionStatus', { connected: false, connecting: true });
expect(JSON.stringify((panel as any).topbarTemplate().values)).toContain('Connecting…');
(panel as any).handleIncomingMessage('chat.connectionStatus', { connected: true, agent: 'opencode' });
expect(JSON.stringify((panel as any).topbarTemplate().values)).toContain('Connected · opencode');
expect(systemRows(panel)).toEqual([]);
});
});
10 changes: 10 additions & 0 deletions packages/extension-core/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ export interface DiagramChatConfig {
* opencode.
*/
acpConnector?: AcpConnectorConfig;
/**
* When the chat's agent processes start. `on-demand` (the default): at the
* chat's first use (a message sent, a chat made or opened, Diagnose
* Connection), not when an editor opens; once the profile's last editor
* has closed and no turn runs, they end after a short grace, and the next
* use starts them again, its chats loaded again. `eager`: when an editor's
* chat panel opens, kept until the window closes, as before this option.
* A Dialogram older than it ignores it and starts eagerly.
*/
agentStart?: "on-demand" | "eager";
}

/**
Expand Down
Loading
Loading