@jc_stack/ez-agents 0.1.0-beta.48 → 0.1.0-beta.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +8 -6
- package/CHANGELOG.md +24 -0
- package/README.md +9 -5
- package/bin/ez +16 -7
- package/docker/broker-update-smoke.mjs +16 -2
- package/docker/upgrade-smoke.mjs +1 -1
- package/docs/architecture/ai-selection.md +9 -1
- package/docs/docker-runtime.md +46 -2
- package/docs/plugin-guide.md +3 -3
- package/docs/plugins.md +13 -10
- package/docs/scheduling.md +84 -6
- package/docs/setup.md +2 -2
- package/docs/standalone-cli.md +4 -4
- package/docs/upgrades.md +13 -23
- package/package.json +1 -1
- package/src/agent-guidance.ts +2 -2
- package/src/ai-cli.ts +28 -15
- package/src/ai.ts +90 -14
- package/src/application-channel.ts +18 -14
- package/src/auth-profile.ts +53 -0
- package/src/codex-session.ts +14 -3
- package/src/control-state.ts +28 -21
- package/src/delivery-socket.ts +2 -0
- package/src/executor.ts +38 -26
- package/src/host-executor-client.ts +19 -7
- package/src/host-executor.ts +35 -10
- package/src/index.ts +320 -122
- package/src/menu.ts +8 -7
- package/src/plugin-broker.mjs +4 -11
- package/src/plugins/manager.mjs +70 -48
- package/src/runs.ts +74 -5
- package/src/schedule-cli.ts +39 -7
- package/src/scheduled-tasks.ts +42 -8
- package/src/scheduler.ts +9 -4
- package/src/session-close.ts +17 -0
- package/src/setup-fallback.ts +159 -0
- package/src/task-executor.ts +3 -2
- package/src/tools-line.d.mts +1 -0
- package/src/tools-line.mjs +3 -0
- package/src/updates/binding.mjs +4 -10
- package/src/updates/control.mjs +3 -2
- package/src/updates/runtime.mjs +79 -41
- package/src/updates/supervisor.mjs +27 -6
- package/src/workspace.ts +12 -1
- package/test/ai.test.ts +48 -2
- package/test/application-channel.test.ts +24 -0
- package/test/application-controls.test.ts +4 -1
- package/test/auth-profiles.test.ts +187 -0
- package/test/intake-relay.test.ts +63 -2
- package/test/model-policy.test.ts +1 -1
- package/test/plugin-broker.test.mjs +51 -1
- package/test/plugin-manager.test.mjs +76 -38
- package/test/run-handoff.test.ts +132 -0
- package/test/scheduled-tasks.test.ts +24 -2
- package/test/session-close.test.ts +17 -0
- package/test/setup-fallback.test.ts +423 -0
- package/test/updates.test.mjs +77 -15
- package/test/workspace.test.ts +6 -0
package/src/executor.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { fileURLToPath } from 'node:url'
|
|
|
12
12
|
import { DESKTOP_UNAVAILABLE } from './desktop-bridge.js'
|
|
13
13
|
import { macosWorkspaceProfile, workspaceSiblingDenies } from './workspace-confine.js'
|
|
14
14
|
import { Scripts, type ScriptRunRef } from './scripts.js'
|
|
15
|
+
import { claudeAuthEnvironment, cliHome, provisionedHome } from './auth-profile.js'
|
|
15
16
|
|
|
16
17
|
export type ExecutorOptions = {
|
|
17
18
|
repairEnabled?: boolean
|
|
@@ -35,6 +36,8 @@ export type ExecutorOptions = {
|
|
|
35
36
|
model?: string
|
|
36
37
|
effort?: string
|
|
37
38
|
provider?: string
|
|
39
|
+
// Named owner-provisioned credential home; unset keeps the agent default.
|
|
40
|
+
authProfile?: string
|
|
38
41
|
codexSandbox?: 'external'
|
|
39
42
|
codexAutoCompactTokens?: number
|
|
40
43
|
codexProvider?: CodexProviderBinding
|
|
@@ -95,6 +98,10 @@ export const executorJobEnv = (
|
|
|
95
98
|
|
|
96
99
|
export const grokJobEnv = executorJobEnv
|
|
97
100
|
|
|
101
|
+
// The selected native CLI is not installed or not executable. Nothing ran, so a
|
|
102
|
+
// scheduled occurrence may advance to its next setup.
|
|
103
|
+
export class CliUnavailableError extends Error {}
|
|
104
|
+
|
|
98
105
|
// Package binDir is Ez tools (ezenciel-agents-message). Native CLIs come from the
|
|
99
106
|
// host PATH so one agent's wrapper cannot retarget another agent's CODEX_HOME.
|
|
100
107
|
export const resolveHostCommand = (command: string, pathValue = process.env.PATH): string => {
|
|
@@ -107,14 +114,14 @@ export const resolveHostCommand = (command: string, pathValue = process.env.PATH
|
|
|
107
114
|
return candidate
|
|
108
115
|
} catch { /* try the next PATH entry */ }
|
|
109
116
|
}
|
|
110
|
-
throw new
|
|
117
|
+
throw new CliUnavailableError(`Native CLI ${command} is not executable on the host PATH`)
|
|
111
118
|
}
|
|
112
119
|
export type CliAdapter = {
|
|
113
120
|
name: string
|
|
114
121
|
command: string
|
|
115
122
|
description: string
|
|
116
123
|
buildArgs: (
|
|
117
|
-
options: Pick<ExecutorOptions, 'workspace' | 'sessionId' | 'isResume' | 'model' | 'effort' | 'toolsHome' | 'sharedWorkspace' | 'additionalWorkspaces' | 'codexAutoCompactTokens' | 'codexSandbox' | 'codexProvider'> & { controlDir?: string },
|
|
124
|
+
options: Pick<ExecutorOptions, 'workspace' | 'sessionId' | 'isResume' | 'model' | 'effort' | 'toolsHome' | 'sharedWorkspace' | 'additionalWorkspaces' | 'codexAutoCompactTokens' | 'codexSandbox' | 'codexProvider' | 'nativeSession'> & { controlDir?: string },
|
|
118
125
|
promptFile: string,
|
|
119
126
|
promptText: string,
|
|
120
127
|
) => string[]
|
|
@@ -161,6 +168,9 @@ export const EXECUTOR_REGISTRY: Record<string, CliAdapter> = {
|
|
|
161
168
|
args.push('--session-id', opts.sessionId)
|
|
162
169
|
}
|
|
163
170
|
args.push('--print', '--dangerously-skip-permissions')
|
|
171
|
+
// Scheduled runs stream structured events so core can tell a provider
|
|
172
|
+
// rejection before work from a failure after work began.
|
|
173
|
+
if (opts.nativeSession) args.push('--output-format', 'stream-json', '--verbose')
|
|
164
174
|
for (const directory of [opts.controlDir, opts.sharedWorkspace, ...(opts.additionalWorkspaces ?? []), opts.toolsHome])
|
|
165
175
|
if (directory) args.push('--add-dir', directory)
|
|
166
176
|
if (opts.model) args.push('--model', opts.model)
|
|
@@ -294,7 +304,7 @@ export const opencodeDataHome = (controlDir: string): string | undefined => {
|
|
|
294
304
|
}
|
|
295
305
|
|
|
296
306
|
// Agent-bound Claude Code configuration directory (CLAUDE_CONFIG_DIR).
|
|
297
|
-
export const claudeConfigHome = (controlDir: string): string =>
|
|
307
|
+
export const claudeConfigHome = (controlDir: string, authProfile?: string): string => cliHome(controlDir, 'claude', authProfile)
|
|
298
308
|
|
|
299
309
|
// Pi resolves its provider/model catalog from an agent dir (settings.json,
|
|
300
310
|
// auth.json). Only a path is ever returned, never a secret.
|
|
@@ -336,6 +346,8 @@ export const startExecutorJob = async (
|
|
|
336
346
|
): Promise<{ child: ChildProcess; cleanup: () => Promise<void>; stdout: string }> => {
|
|
337
347
|
if (options.script && process.env.EZ_EXECUTOR_TRANSPORT !== 'host') return startScriptJob(options as ExecutorOptions & { script: ScriptLaunch })
|
|
338
348
|
options = executionDefaults(executorKey(options.cli), options)
|
|
349
|
+
// Named credential homes are owner-provisioned; fail closed before any launch state.
|
|
350
|
+
if (options.authProfile !== undefined) await provisionedHome(options.controlDir, executorKey(options.cli), options.authProfile)
|
|
339
351
|
// Routing is caller-owned: a restricted task run goes to the task runner
|
|
340
352
|
// unless the host transport must ship it across the boundary first.
|
|
341
353
|
if (options.taskRun && process.env.EZ_EXECUTOR_TRANSPORT !== 'host') return startTaskExecutor(options)
|
|
@@ -377,7 +389,7 @@ export const startExecutorJob = async (
|
|
|
377
389
|
}
|
|
378
390
|
if (!host && !gui && command === 'codex') {
|
|
379
391
|
// Share the existing authentication, never the user's memory/config/sessions.
|
|
380
|
-
const base =
|
|
392
|
+
const base = await provisionedHome(options.controlDir, 'codex', options.authProfile)
|
|
381
393
|
const home = nativeSession ? path.join(base,'tasks',options.runId) : base
|
|
382
394
|
await mkdir(home, {recursive:true,mode:0o700})
|
|
383
395
|
if(nativeSession){
|
|
@@ -387,9 +399,10 @@ export const startExecutorJob = async (
|
|
|
387
399
|
try{await writeFile(path.join(home,'config.toml'),await readFile(path.join(base,'config.toml')),{flag:'wx',mode:0o600})}
|
|
388
400
|
catch(error){if(!['ENOENT','EEXIST'].includes((error as NodeJS.ErrnoException).code || ''))throw error}
|
|
389
401
|
}
|
|
390
|
-
// Isolated agents keep auth in this CODEX_HOME.
|
|
391
|
-
// installer login. Never replace an
|
|
392
|
-
|
|
402
|
+
// Isolated agents and named profiles keep auth in this CODEX_HOME. The
|
|
403
|
+
// host-capable default may link the installer login. Never replace an
|
|
404
|
+
// existing binding.
|
|
405
|
+
const authLinks = process.env.EZ_ISOLATION === 'isolated' || options.authProfile !== undefined
|
|
393
406
|
? nativeSession ? [[path.join(home, 'auth.json'), path.join(base, 'auth.json')]] : []
|
|
394
407
|
: [[path.join(base, 'auth.json'), path.join(homedir(), '.codex', 'auth.json')],
|
|
395
408
|
...(nativeSession ? [[path.join(home, 'auth.json'), path.join(base, 'auth.json')]] : [])]
|
|
@@ -402,28 +415,18 @@ export const startExecutorJob = async (
|
|
|
402
415
|
if (!host && !gui && key === 'claude') {
|
|
403
416
|
// Mirror the Codex binding: agent-bound settings, memory, plugins and
|
|
404
417
|
// sessions; never the user's personal ~/.claude configuration.
|
|
405
|
-
const home =
|
|
418
|
+
const home = await provisionedHome(options.controlDir, 'claude', options.authProfile)
|
|
406
419
|
await mkdir(home, {recursive:true,mode:0o700})
|
|
407
|
-
|
|
408
|
-
//
|
|
409
|
-
// storage dir makes Claude use its default credential store (macOS
|
|
420
|
+
// Host-capable default homes share the installer login only. An empty
|
|
421
|
+
// secure storage dir makes Claude use its default credential store (macOS
|
|
410
422
|
// Keychain entry or ~/.claude/.credentials.json) in place, so token
|
|
411
423
|
// refreshes stay shared rather than diverging through a copy. Isolated
|
|
412
|
-
// agents keep their own login inside CLAUDE_CONFIG_DIR.
|
|
413
|
-
// runs unlabelled, so this matches the Codex auth-link
|
|
414
|
-
// resolveIsolation().
|
|
415
|
-
|
|
416
|
-
//
|
|
417
|
-
|
|
418
|
-
// agents invalidating each other's OAuth session.
|
|
419
|
-
const token = await readFile(path.join(home, 'oauth-token'), 'utf8').then(value => value.trim(), (error: NodeJS.ErrnoException) => {
|
|
420
|
-
if (error.code === 'ENOENT') return undefined
|
|
421
|
-
throw error
|
|
422
|
-
})
|
|
423
|
-
if (token !== undefined) {
|
|
424
|
-
if (!/^[A-Za-z0-9._-]{20,512}$/.test(token)) throw new Error('Invalid Claude token binding')
|
|
425
|
-
environment.CLAUDE_CODE_OAUTH_TOKEN = token
|
|
426
|
-
}
|
|
424
|
+
// agents and named profiles keep their own login inside CLAUDE_CONFIG_DIR.
|
|
425
|
+
// The host executor runs unlabelled, so this matches the Codex auth-link
|
|
426
|
+
// check, not resolveIsolation(). An optional owner-provisioned long-lived
|
|
427
|
+
// token (`claude setup-token`) never refreshes, so one file can be copied
|
|
428
|
+
// to every agent without them invalidating each other's OAuth session.
|
|
429
|
+
Object.assign(environment, await claudeAuthEnvironment(home, options.authProfile))
|
|
427
430
|
}
|
|
428
431
|
if (!host && !gui && key === 'opencode') {
|
|
429
432
|
// Point OpenCode at the agent-bound data home (cli/opencode/auth.json)
|
|
@@ -497,6 +500,15 @@ export const startExecutorJob = async (
|
|
|
497
500
|
|
|
498
501
|
export const startGrokJob = startExecutorJob
|
|
499
502
|
|
|
503
|
+
// Watch a host-transport run a previous relay submitted; it is never resubmitted.
|
|
504
|
+
export const attachHostJob = async (controlDir: string, runId: string): Promise<ChildProcess> => {
|
|
505
|
+
const invocation = executorInvocation(process.execPath, ['--import', fileURLToPath(new URL('../node_modules/tsx/dist/loader.mjs', import.meta.url)),
|
|
506
|
+
fileURLToPath(new URL('./host-executor-client.ts', import.meta.url)), controlDir, runId, '--attach'])
|
|
507
|
+
const child = spawn(invocation.command, invocation.args, { env: executorEnvironment(), stdio: ['ignore', 'pipe', 'pipe'], detached: process.platform !== 'win32' })
|
|
508
|
+
await new Promise<void>((resolve, reject) => { child.once('spawn', resolve); child.once('error', reject) })
|
|
509
|
+
return child
|
|
510
|
+
}
|
|
511
|
+
|
|
500
512
|
// Spawn a verified registered script with the executor identity, environment
|
|
501
513
|
// allowlist and workspace confinement. No shell, model, prompt or native session.
|
|
502
514
|
export const startScriptJob = async (
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
// File transport across the Docker/host boundary. The host chooses the CLI,
|
|
2
2
|
// workspace and environment; a request cannot choose a command or credentials.
|
|
3
|
-
import { mkdir, readFile, writeFile, rename, rm } from 'node:fs/promises'
|
|
3
|
+
import { mkdir, readFile, writeFile, rename, rm, stat } from 'node:fs/promises'
|
|
4
4
|
import path from 'node:path'
|
|
5
5
|
import { isHostRunId } from './host-executor-protocol.js'
|
|
6
|
-
const [control, id] = process.argv.slice(2)
|
|
7
|
-
if (!control || !isHostRunId(id || '')) throw new Error('Invalid executor binding')
|
|
6
|
+
const [control, id, mode] = process.argv.slice(2)
|
|
7
|
+
if (!control || !isHostRunId(id || '') || (mode !== undefined && mode !== '--attach')) throw new Error('Invalid executor binding')
|
|
8
8
|
const directory = path.join(control, 'host-executor')
|
|
9
9
|
await mkdir(directory, {recursive:true, mode:0o700})
|
|
10
|
-
let input = ''
|
|
11
|
-
for await (const chunk of process.stdin) input += chunk
|
|
12
10
|
const base = path.join(directory, id)
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
if (mode === '--attach') {
|
|
12
|
+
// A previous relay submitted this run: watch it, never resubmit. Without a
|
|
13
|
+
// request, claim or event record its outcome is unknown.
|
|
14
|
+
// Check in lifecycle order: claim renames the request, and the host writes
|
|
15
|
+
// the exit event before removing the claim, so a live run is always seen.
|
|
16
|
+
const exists = (suffix: string) => stat(base+suffix).then(() => true, error => { if (error.code === 'ENOENT') return false; throw error })
|
|
17
|
+
if (!await exists('.request.json') && !await exists('.running.json') && !await exists('.events')) {
|
|
18
|
+
console.error('Handed-off host run has no request, claim or result; its outcome is unknown')
|
|
19
|
+
process.exit(1)
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
let input = ''
|
|
23
|
+
for await (const chunk of process.stdin) input += chunk
|
|
24
|
+
await writeFile(base+'.tmp', input, {mode:0o600, flag:'wx'})
|
|
25
|
+
await rename(base+'.tmp', base+'.request.json')
|
|
26
|
+
}
|
|
15
27
|
let interrupted = false
|
|
16
28
|
for (const signal of ['SIGTERM','SIGINT'] as const) process.once(signal, () => {
|
|
17
29
|
if (interrupted) return
|
package/src/host-executor.ts
CHANGED
|
@@ -7,9 +7,11 @@ import { mkdir, readFile, writeFile, readdir, rename, rm, appendFile, realpath }
|
|
|
7
7
|
import path from 'node:path'
|
|
8
8
|
import { isHostRunId } from './host-executor-protocol.js'
|
|
9
9
|
import { fileURLToPath } from 'node:url'
|
|
10
|
-
import { startExecutorJob, terminateJob, resolveExecutor, validateCodexProvider, type CodexProviderBinding, type ExecutorOptions } from './executor.js'
|
|
10
|
+
import { CliUnavailableError, startExecutorJob, terminateJob, resolveExecutor, validateCodexProvider, type CodexProviderBinding, type ExecutorOptions } from './executor.js'
|
|
11
|
+
import { activeSetup } from './runs.js'
|
|
12
|
+
import { startupLine, startupObserver } from './setup-fallback.js'
|
|
11
13
|
import { parseIsolationClass, type IsolationClass } from './isolation.js'
|
|
12
|
-
import { readModels, validateSelection, validateOpencodeProviders, type ModelChoice } from './ai.js'
|
|
14
|
+
import { readModels, sameEngine, validateSelection, validateOpencodeProviders, type ModelChoice } from './ai.js'
|
|
13
15
|
import type { ChildProcess } from 'node:child_process'
|
|
14
16
|
import { packageVersion } from './version.js'
|
|
15
17
|
import { installedPluginVersions } from './software-status.js'
|
|
@@ -48,6 +50,8 @@ export const serveHostExecutor = async (installation: HostInstallation, signal:
|
|
|
48
50
|
new Set(installation.agents.map(a=>a.controlDir)).size !== installation.agents.length)
|
|
49
51
|
throw new Error('Each agent requires a separate workspace and control directory')
|
|
50
52
|
const active = new Map<string, ChildProcess>()
|
|
53
|
+
// A fallback attempt reuses its run ID; claim it only after the prior attempt's cleanup.
|
|
54
|
+
const claimed = new Set<string>()
|
|
51
55
|
const tasks = new Set<Promise<void>>()
|
|
52
56
|
let catalogRefresh: Promise<void> | undefined
|
|
53
57
|
const locks: string[] = []
|
|
@@ -148,6 +152,7 @@ export const serveHostExecutor = async (installation: HostInstallation, signal:
|
|
|
148
152
|
for (const file of await readdir(directory)) {
|
|
149
153
|
if (!file.endsWith('.request.json') || !isHostRunId(file.slice(0,-13))) continue
|
|
150
154
|
const id=file.slice(0,-13)
|
|
155
|
+
if (claimed.has(path.join(directory,id))) continue
|
|
151
156
|
let run
|
|
152
157
|
try {
|
|
153
158
|
run = await readRun(agent.controlDir, id)
|
|
@@ -170,6 +175,7 @@ export const serveHostExecutor = async (installation: HostInstallation, signal:
|
|
|
170
175
|
activeWorkspaces.set(agent, workspace)
|
|
171
176
|
}
|
|
172
177
|
workspace.lanes.set(id, scheduled)
|
|
178
|
+
claimed.add(base)
|
|
173
179
|
// Keep plugin workspace invocations excluded until all native jobs finish.
|
|
174
180
|
const releaseWorkspace = async () => {
|
|
175
181
|
workspace.lanes.delete(id)
|
|
@@ -179,11 +185,12 @@ export const serveHostExecutor = async (installation: HostInstallation, signal:
|
|
|
179
185
|
}
|
|
180
186
|
}
|
|
181
187
|
try { await rename(base+'.request.json',base+'.running.json') }
|
|
182
|
-
catch (error) { await releaseWorkspace(); throw error }
|
|
188
|
+
catch (error) { claimed.delete(base); await releaseWorkspace(); throw error }
|
|
183
189
|
const task=(async()=>{
|
|
184
190
|
let job: Awaited<ReturnType<typeof startExecutorJob>> | undefined
|
|
185
191
|
let cancellation: ReturnType<typeof setInterval> | undefined
|
|
186
192
|
let writes=Promise.resolve()
|
|
193
|
+
let observeClaude=false
|
|
187
194
|
const emit=(event:unknown)=>{writes=writes.then(()=>appendFile(base+'.events',JSON.stringify(event)+'\n',{mode:0o600}))}
|
|
188
195
|
try {
|
|
189
196
|
try { await readFile(base+'.cancel'); throw new Error('Cancelled') } catch(error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error }
|
|
@@ -203,12 +210,20 @@ export const serveHostExecutor = async (installation: HostInstallation, signal:
|
|
|
203
210
|
script:{...run.script,scheduleId:run.scheduled.id,scheduleRevision:run.scheduled.revision,dueAt:run.scheduled.dueAt}}
|
|
204
211
|
job=await launch(request.texts,options)
|
|
205
212
|
} else {
|
|
213
|
+
const cli = opts.cli || installation.cli
|
|
206
214
|
if (run?.scheduled) {
|
|
207
|
-
|
|
208
|
-
|
|
215
|
+
const setup = activeSetup(run)
|
|
216
|
+
assertScheduledModel(setup?.model)
|
|
217
|
+
if (opts.model !== setup!.model || cli !== setup!.cli) throw new Error('Scheduled run model does not match its saved task model')
|
|
218
|
+
observeClaude = cli === 'claude'
|
|
209
219
|
}
|
|
210
|
-
const cli = opts.cli || installation.cli
|
|
211
220
|
resolveExecutor(cli)
|
|
221
|
+
// The credential home comes from the authorized run's captured
|
|
222
|
+
// choice; a request can never move it to another account.
|
|
223
|
+
const captured = run?.scheduled ? activeSetup(run) : run?.execution?.preset
|
|
224
|
+
if ((opts.authProfile !== undefined || (captured?.cli === cli && captured.authProfile !== undefined)) &&
|
|
225
|
+
!(captured && sameEngine(captured, {cli, authProfile: opts.authProfile})))
|
|
226
|
+
throw new Error('Run auth profile does not match its captured AI selection')
|
|
212
227
|
const provider = cli === 'codex' && opts.provider
|
|
213
228
|
? (agent.codexProviders ?? []).map(validateCodexProvider).find(candidate=>candidate.id===opts.provider)
|
|
214
229
|
: undefined
|
|
@@ -221,17 +236,24 @@ export const serveHostExecutor = async (installation: HostInstallation, signal:
|
|
|
221
236
|
// Admission and execution must use the same catalog snapshot. A
|
|
222
237
|
// transient native-client probe failure must not reject a model
|
|
223
238
|
// that the host just advertised to the relay and application.
|
|
224
|
-
if (cli !== installation.cli) await validateSelection({id:'selected',name:'Selected model',cli,provider:opts.provider,model,effort:opts.effort},JSON.parse(await readFile(path.join(directory,'models.json'),'utf8')))
|
|
239
|
+
if (cli !== installation.cli || opts.authProfile !== undefined) await validateSelection({id:'selected',name:'Selected model',cli,provider:opts.provider,authProfile:opts.authProfile,model,effort:opts.effort},JSON.parse(await readFile(path.join(directory,'models.json'),'utf8')))
|
|
225
240
|
const options:ExecutorOptions={workspace:agent.workspace,controlDir:agent.controlDir,binDir:agent.binDir,toolsHome:agent.toolsHome,sharedWorkspace,additionalWorkspaces:additionalWorkspaces.get(agent),cli,
|
|
226
241
|
runId:path.basename(base),timeoutMs:0,repairEnabled:opts.repairEnabled,
|
|
227
|
-
sessionId:opts.sessionId,isResume:opts.isResume,model,effort:opts.effort,provider:opts.provider,codexAutoCompactTokens:opts.codexAutoCompactTokens,codexProvider:provider,
|
|
242
|
+
sessionId:opts.sessionId,isResume:opts.isResume,model,effort:opts.effort,provider:opts.provider,authProfile:opts.authProfile,codexAutoCompactTokens:opts.codexAutoCompactTokens,codexProvider:provider,
|
|
228
243
|
promptSuffix:runPromptSuffix(run),taskRun:Boolean(run?.taskId),nativeSession:Boolean(run?.scheduled)}
|
|
229
244
|
job=await launch(request.texts,options)
|
|
230
245
|
}
|
|
231
246
|
active.set(base,job.child)
|
|
232
247
|
await writeFile(base+'.process.json',JSON.stringify({pid:job.child.pid}),{mode:0o600})
|
|
233
248
|
if(signal.aborted)terminateJob(job.child)
|
|
234
|
-
|
|
249
|
+
// Scheduled Claude streams every event; forward only the startup summary.
|
|
250
|
+
const startup = observeClaude ? startupObserver() : undefined
|
|
251
|
+
let summary = ''
|
|
252
|
+
job.child.stdout?.setEncoding('utf8').on('data',(chunk:string)=>{
|
|
253
|
+
if (!startup) return emit({stream:'stdout',text:chunk})
|
|
254
|
+
startup.write(chunk)
|
|
255
|
+
if (startup.summary() !== summary) { summary = startup.summary(); emit({stream:'stdout',text:summary+'\n'}) }
|
|
256
|
+
})
|
|
235
257
|
job.child.stderr?.on('data',chunk=>emit({stream:'stderr',text:chunk.toString()}))
|
|
236
258
|
cancellation=setInterval(()=>{void readFile(base+'.cancel').then(()=>terminateJob(job!.child)).catch(()=>{})},250)
|
|
237
259
|
const code=await new Promise<number>(resolve=>job!.child.once('close',code=>resolve(code??1)))
|
|
@@ -239,7 +261,9 @@ export const serveHostExecutor = async (installation: HostInstallation, signal:
|
|
|
239
261
|
await job.cleanup()
|
|
240
262
|
job = undefined
|
|
241
263
|
emit({stream:'exit',code})
|
|
242
|
-
} catch (error) {
|
|
264
|
+
} catch (error) {
|
|
265
|
+
if (error instanceof CliUnavailableError) emit({stream:'stdout',text:startupLine({workBegan:false,rejection:{category:'cli-unavailable'}})+'\n'})
|
|
266
|
+
emit({stream:'stderr',text:'Host CLI execution failed: '+redactFailure(error instanceof Error ? error.message : 'Unknown error')+'\n'}); emit({stream:'exit',code:1}) }
|
|
243
267
|
finally {
|
|
244
268
|
if(cancellation)clearInterval(cancellation)
|
|
245
269
|
await job?.cleanup().catch(() => {})
|
|
@@ -249,6 +273,7 @@ export const serveHostExecutor = async (installation: HostInstallation, signal:
|
|
|
249
273
|
await rm(base+'.cancel',{force:true})
|
|
250
274
|
active.delete(base)
|
|
251
275
|
await releaseWorkspace()
|
|
276
|
+
claimed.delete(base)
|
|
252
277
|
}
|
|
253
278
|
})()
|
|
254
279
|
tasks.add(task); void task.finally(()=>tasks.delete(task))
|