feat(session): validate agents and browse workspace directories

This commit is contained in:
weishu
2026-08-25 16:12:29 +08:00
parent a04275b51d
commit e5a8212f4a
77 changed files with 3409 additions and 312 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
import { spawn } from 'node:child_process'
import { getAgentLaunchCommand } from '@/agent/agentLaunchCommand'
import { AGY_MODEL_LABELS, AGY_MODEL_PRESETS } from '@hapi/protocol'
import type { AgyModelsResponse } from '@hapi/protocol/apiTypes'
@@ -127,7 +128,7 @@ function buildAgyProbeEnv(): NodeJS.ProcessEnv {
// unparseable output). An auth failure is surfaced so the UI can prompt sign-in.
async function fetchAgyModels(): Promise<ListAgyModelsResponse> {
return await new Promise((resolve) => {
const child = spawn('agy', ['models'], {
const child = spawn(getAgentLaunchCommand('agy'), ['models'], {
stdio: ['ignore', 'pipe', 'pipe'],
env: buildAgyProbeEnv(),
windowsHide: process.platform === 'win32',
+2 -1
View File
@@ -1,4 +1,5 @@
import { spawn } from 'node:child_process';
import { getAgentLaunchCommand } from '@/agent/agentLaunchCommand';
import type { CursorModelsResponse, CursorModelSummary } from '@hapi/protocol/apiTypes';
import {
releaseAgentCliSpawnLeaseSync,
@@ -226,7 +227,7 @@ async function runCursorModelProbe(): Promise<ListCursorModelsResponse> {
};
return await new Promise((resolve, reject) => {
const child = spawn('agent', ['--list-models'], {
const child = spawn(getAgentLaunchCommand('cursor'), ['--list-models'], {
env: process.env,
stdio: ['ignore', 'pipe', 'pipe'],
shell: process.platform === 'win32',
+3 -2
View File
@@ -1,4 +1,5 @@
import { spawn } from 'node:child_process'
import { getAgentLaunchCommand } from '@/agent/agentLaunchCommand'
import { asString, isObject } from '@hapi/protocol'
import type { GrokModelSummary, GrokModelsResponse, GrokReasoningEffortOption } from '@hapi/protocol/apiTypes'
import { AcpStdioTransport } from '@/agent/backends/acp/AcpStdioTransport'
@@ -107,7 +108,7 @@ export function parseGrokInitializeModels(response: unknown): {
async function runGrokModelsCliProbe(cwd: string): Promise<ListGrokModelsForCwdResponse> {
return await new Promise((resolve, reject) => {
const child = spawn('grok', buildGrokModelsArgs(cwd), {
const child = spawn(getAgentLaunchCommand('grok'), buildGrokModelsArgs(cwd), {
env: process.env,
stdio: ['ignore', 'pipe', 'pipe'],
shell: process.platform === 'win32',
@@ -153,7 +154,7 @@ async function runGrokModelsProbe(cwd: string): Promise<ListGrokModelsForCwdResp
// The primary ACP probe also uses shell mode on Windows through AcpStdioTransport.
assertSafeWindowsShellArg(cwd, 'cwd')
const transport = await AcpStdioTransport.create({
command: 'grok',
command: getAgentLaunchCommand('grok'),
args: ['--cwd', cwd, 'agent', '--reasoning-effort', 'low', 'stdio'],
env: Object.fromEntries(
Object.entries(process.env).filter((entry): entry is [string, string] => entry[1] !== undefined)
+2 -1
View File
@@ -3,6 +3,7 @@ import type { OpencodeModelsResponse, OpencodeModelSummary } from '@hapi/protoco
import { AcpStdioTransport } from '@/agent/backends/acp/AcpStdioTransport';
import packageJson from '../../../package.json';
import { getErrorMessage } from './rpcResponses';
import { getAgentLaunchCommand } from '@/agent/agentLaunchCommand';
export interface ListOpencodeModelsForCwdRequest {
cwd?: string;
@@ -85,7 +86,7 @@ function extractModelsFromResponse(response: unknown): {
async function runOpencodeProbe(cwd: string): Promise<ListOpencodeModelsForCwdResponse> {
const transport = await AcpStdioTransport.create({
command: 'opencode',
command: getAgentLaunchCommand('opencode'),
args: ['acp']
});
+2 -1
View File
@@ -1,4 +1,5 @@
import { spawn } from 'node:child_process'
import { getAgentLaunchCommand } from '@/agent/agentLaunchCommand'
import { homedir } from 'node:os'
import { parse } from 'node:path'
import type { PiModelSummary, PiModelsResponse } from '@hapi/protocol/apiTypes'
@@ -120,7 +121,7 @@ export function resolveProbeCwd(): string {
function runPiModelsProbe(): Promise<ListPiModelsForMachineResponse> {
return new Promise((resolve, reject) => {
const child = spawn('pi', [...PI_PROBE_ARGS], {
const child = spawn(getAgentLaunchCommand('pi'), [...PI_PROBE_ARGS], {
env: process.env,
// Probe from the runner's cwd, falling back to home at a
// filesystem root (see resolveProbeCwd).
+8 -1
View File
@@ -27,9 +27,16 @@ export interface SpawnSessionOptions {
startingMode?: 'remote' | 'pty'
/** Claude: spawn with --fork-session after --resume. */
forkSession?: boolean
/** Runner-internal post-create containment revalidation. Never serialized. */
validateDirectory?: (path: string) => Promise<boolean>
}
export type SpawnSessionResult =
| { type: 'success'; sessionId: string }
| { type: 'requestToApproveDirectoryCreation'; directory: string }
| { type: 'error'; errorMessage: string }
| {
type: 'error'
errorMessage: string
code?: 'agent_unavailable' | 'outside_workspace_roots'
agent?: AgentFlavor
}