Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion src/main/claude/claude-at-rest-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { PrioritySemaphore } from '../../shared/priority-semaphore'
import type { AgentSessionRecord } from '../../shared/agent-session-record'
import {
isLegacyAgentSessionAccountHome,
requireLegacyAgentSessionAccountHome
requireLegacyAgentSessionAccountHome,
type AgentSessionAccountHome
} from '../../shared/agent-session-account-home'
import type { AgentSessionSlashCommand } from '../../shared/agent-session-wire'
import { structuredSlashCommands } from '../../shared/structured-agent-session-composer'
Expand All @@ -23,6 +24,8 @@ const MAX_PROBES_RUNNING = 2

export type ClaudeAtRestCommandsDeps = {
resolveWorkspacePath: (workspaceId: string) => Promise<string>
/** A resting chat's next start follows the selected account, not the one it was created on. */
resolveAccountHome?: () => Promise<AgentSessionAccountHome>
probe?: ClaudeCommandCatalogProbe
now?: () => number
discover?: typeof discoverSkills
Expand All @@ -39,6 +42,7 @@ export class ClaudeAtRestCommandCatalog extends AtRestCommandCatalog {
supportsClaudeStructuredLocation(record.location) &&
isLegacyAgentSessionAccountHome(record.accountHome),
resolveWorkspacePath: deps.resolveWorkspacePath,
...(deps.resolveAccountHome ? { resolveAccountHome: deps.resolveAccountHome } : {}),
scan: (record, cwd, isCurrent) => scanClaudeAtRest(deps, probes, record, cwd, isCurrent),
...(deps.now ? { now: deps.now } : {})
})
Expand Down
37 changes: 37 additions & 0 deletions src/main/claude/claude-structured-session-commands.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { describe, expect, it, vi } from 'vitest'
import { agentSessionRecordFixture } from '../../shared/agent-session-record.test-fixture'
import { ClaudeAtRestCommandCatalog } from './claude-at-rest-commands'
import {
bindAtRestCommandContexts,
retireAtRestCommandSettings
} from '../native-chat/agent-session-wire/at-rest-command-context'
import {
adapterFor,
fakeClaude,
Expand Down Expand Up @@ -129,3 +133,36 @@
const remote = { ...local, location: { ...local.location, executionHostId: 'ssh:box' as const } }
expect(catalog.read(remote)).toBeUndefined()
})

it("lists a resting chat's `/` menu from the account it would start on, following a switch", async () => {
let selected = '/accounts/b'
const probed: string[] = []
const catalog = new ClaudeAtRestCommandCatalog({
resolveWorkspacePath: async () => '/work',
resolveAccountHome: async () => ({ variable: 'CLAUDE_CONFIG_DIR', path: selected }),
probe: async ({ accountHomePath }) => {
probed.push(accountHomePath)
return [{ name: accountHomePath, kind: 'skill' }]
}
})
const release = bindAtRestCommandContexts([catalog])
try {
// Created on /home/user/.claude, but its next start uses the selected account.
const chat = agentSessionRecordFixture()
expect(await catalog.settled(chat, 1000)).toEqual([{ name: '/accounts/b', kind: 'skill' }])
const createdOnB = agentSessionRecordFixture({
sessionId: 'created-on-b',
accountHome: { variable: 'CLAUDE_CONFIG_DIR', path: '/accounts/b' }

Check failure on line 155 in src/main/claude/claude-structured-session-commands.test.ts

View workflow job for this annotation

GitHub Actions / static analysis and typecheck

TS2353

Object literal may only specify known properties, and 'accountHome' does not exist in type 'AgentSessionLease'.

Check failure on line 155 in src/main/claude/claude-structured-session-commands.test.ts

View workflow job for this annotation

GitHub Actions / static analysis and typecheck

Object literal may only specify known properties, and 'accountHome' does not exist in type 'AgentSessionLease'.
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
expect(await catalog.settled(createdOnB, 1000)).toEqual([
{ name: '/accounts/b', kind: 'skill' }
])
expect(probed).toEqual(['/accounts/b'])

selected = '/accounts/a'
retireAtRestCommandSettings(['activeClaudeManagedAccountId'])
expect(await catalog.settled(chat, 1000)).toEqual([{ name: '/accounts/a', kind: 'skill' }])
} finally {
release()
}
})
15 changes: 12 additions & 3 deletions src/main/native-chat/agent-session-wire/at-rest-command-catalog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { AgentSessionRecord } from '../../../shared/agent-session-record'
import type { AgentSessionSlashCommand } from '../../../shared/agent-session-wire'
import { requireLegacyAgentSessionAccountHome } from '../../../shared/agent-session-account-home'
import {
requireLegacyAgentSessionAccountHome,
type AgentSessionAccountHome
} from '../../../shared/agent-session-account-home'
import { agentSessionPinnedLaunchDirectory } from '../../runtime/agent-session-record-launch-directory'
import type { StructuredAgentSessionAtRestCommands } from './structured-agent-session-at-rest-commands'
import { atRestCommandContextReady } from './at-rest-command-context'
Expand Down Expand Up @@ -30,6 +33,8 @@ export type AtRestCommandSource = {
isCurrent: () => boolean
) => Promise<AtRestCommandScan>
resolveWorkspacePath: (workspaceId: string) => Promise<string>
/** The account a start uses now, read at scan time; absent scans the chat's saved account. */
resolveAccountHome?: () => Promise<AgentSessionAccountHome>
label: string
now?: () => number
}
Expand Down Expand Up @@ -121,7 +126,10 @@ export class AtRestCommandCatalog implements StructuredAgentSessionAtRestCommand
}
const key = JSON.stringify([
record.provider,
requireLegacyAgentSessionAccountHome(record.accountHome).path,
// A selected account changes through retireContext, not per chat.
this.source.resolveAccountHome
? null
: requireLegacyAgentSessionAccountHome(record.accountHome).path,
record.location.workspaceId,
agentSessionPinnedLaunchDirectory(record)
])
Expand Down Expand Up @@ -172,8 +180,9 @@ export class AtRestCommandCatalog implements StructuredAgentSessionAtRestCommand
const cwd =
agentSessionPinnedLaunchDirectory(record) ??
(await this.source.resolveWorkspacePath(record.location.workspaceId))
const accountHome = (await this.source.resolveAccountHome?.()) ?? record.accountHome
return isCurrent()
? this.source.scan(record, cwd, isCurrent)
? this.source.scan({ ...record, accountHome }, cwd, isCurrent)
: { commands: undefined, fromAgent: false }
})()
.then(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type { StructuredAgentSessionAtRestCommands } from './structured-agent-se
const listeners = new Set<(workspaceId?: string) => void>()
let readiness: Promise<void> | undefined
const launchSettings = new Set([
'activeClaudeManagedAccountId',
'activeClaudeManagedAccountIdsByRuntime',
'agentCmdOverrides',
'agentDefaultArgs',
'agentDefaultEnv',
Expand Down
2 changes: 2 additions & 0 deletions src/main/runtime/structured-agent-runtime-registrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ function createClaudeAdapter(
): StructuredAgentRuntimeAdapter {
const { deps, store, followUps, host } = context
const overlay = claudeLaunchEnvOverlay(deps).resolveEnv
const resolveAccountHome = deps.resolveAgentAccountHome
return createStructuredClaudeRuntimeAdapter({
store,
resolveWorkspacePath: deps.resolveWorkspacePath,
...(resolveAccountHome ? { resolveAccountHome: () => resolveAccountHome('claude') } : {}),
resolveLaunch: composeStructuredLaunch(
CLAUDE_STRUCTURED_AGENT,
structuredAgentLaunchSources(context),
Expand Down
7 changes: 6 additions & 1 deletion src/main/runtime/structured-claude-runtime-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
reviseAgentSessionProviderResumePoint
} from './agent-session/ownership/agent-session-provider-handle-transition'
import type { AgentSessionRecordStore } from './agent-session-record-store'
import { ClaudeAtRestCommandCatalog } from '../claude/claude-at-rest-commands'
import {
ClaudeAtRestCommandCatalog,
type ClaudeAtRestCommandsDeps
} from '../claude/claude-at-rest-commands'
import type { ClaudeCommandCatalogProbe } from '../claude/claude-command-catalog-probe'
import { openClaudeStreamJsonConnection } from '../claude/claude-stream-json-connection'
import type { ClaudeCliFlagSupport } from '../claude/claude-cli-flag-support'
Expand All @@ -22,6 +25,7 @@ import { prewarmClaudeCliFlags } from '../claude/claude-cli-flag-prewarm'
export type StructuredClaudeRuntimeAdapterDeps = {
store: AgentSessionRecordStore
resolveWorkspacePath: (workspaceId: string) => Promise<string>
resolveAccountHome?: ClaudeAtRestCommandsDeps['resolveAccountHome']
resolveLaunch: ClaudeStructuredSessionAdapterDeps['resolveLaunch']
/** The binary and env the startup version prewarm asks, as a launch would. */
resolveClaudeCommand?: typeof resolveClaudeCommand
Expand Down Expand Up @@ -88,6 +92,7 @@ export function createStructuredClaudeRuntimeAdapter(
return new ClaudeStructuredSessionAdapter({
atRestCommands: new ClaudeAtRestCommandCatalog({
resolveWorkspacePath: deps.resolveWorkspacePath,
...(deps.resolveAccountHome ? { resolveAccountHome: deps.resolveAccountHome } : {}),
...(deps.atRestCommandProbe ? { probe: deps.atRestCommandProbe } : {})
}),
resolveLaunch: deps.resolveLaunch,
Expand Down
Loading