zapagent 1.14.28 → 1.14.29
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/README.md +2 -4
- package/README.zh-CN.md +1 -3
- package/bundled-dependencies.json +189 -189
- package/package.json +1 -1
- package/src/App.tsx +16 -14
- package/src/acp/agent.ts +2 -1
- package/src/agent/cacheScope.ts +11 -0
- package/src/agent/claude-code.ts +160 -0
- package/src/agent/official-agents.ts +83 -0
- package/src/agent/remote-agent.ts +3 -1
- package/src/agent/remote-turn.ts +17 -2
- package/src/agent/wireRunHandlers.ts +2 -5
- package/src/agent-factory.ts +3 -15
- package/src/codex-auth-command.ts +14 -27
- package/src/codex-auth.ts +25 -227
- package/src/codex-provider.ts +9 -11
- package/src/commands/dispatcher.ts +26 -9
- package/src/commands/status.ts +9 -7
- package/src/config.ts +18 -4
- package/src/headless/runHeadless.ts +9 -0
- package/src/hooks/useAgentRunner.ts +17 -6
- package/src/index.tsx +2 -2
- package/src/ui/dialog-codex-login.tsx +15 -19
- package/src/ui/dialog-config.tsx +3 -1
- package/src/ui/dialog-connect.tsx +9 -5
- package/src/ui/dialog-model.tsx +7 -4
- package/src/ui/provider-directory.tsx +5 -3
- package/zapsdk/acp-client/event-mapper.ts +7 -1
- package/zapsdk/acp-client/host-handlers.ts +18 -4
- package/zapsdk/acp-client/run.ts +1 -0
- package/zapsdk/acp-client/types.ts +2 -0
- package/zapsdk/execution/process.ts +9 -2
|
@@ -1,44 +1,40 @@
|
|
|
1
1
|
/** @jsxImportSource react */
|
|
2
2
|
import { useEffect, useRef, useState } from "react"
|
|
3
|
+
import { stripVTControlCharacters } from "node:util"
|
|
3
4
|
import { Text, useInput } from "ink"
|
|
4
|
-
import {
|
|
5
|
+
import { runCodexAuth } from "../codex-auth.js"
|
|
5
6
|
import { DialogFrame } from "./dialog-frame.js"
|
|
6
7
|
import { PickerDialog } from "./dialog-picker.js"
|
|
7
8
|
import { c } from "./theme.js"
|
|
8
9
|
|
|
9
10
|
export function CodexLoginDialog({ onSuccess, onCancel }: { onSuccess: () => void; onCancel: () => void }) {
|
|
10
|
-
const [method, setMethod] = useState<"browser" | "device" | null>(null)
|
|
11
|
-
const [details, setDetails] = useState
|
|
11
|
+
const [method, setMethod] = useState<"browser" | "device" | "existing" | null>(null)
|
|
12
|
+
const [details, setDetails] = useState("")
|
|
12
13
|
const [error, setError] = useState("")
|
|
13
|
-
const callbacks = useRef(
|
|
14
|
-
callbacks.current =
|
|
14
|
+
const callbacks = useRef(onSuccess)
|
|
15
|
+
callbacks.current = onSuccess
|
|
15
16
|
useInput((_input, key) => { if (method && key.escape) setMethod(null) })
|
|
16
17
|
useEffect(() => {
|
|
17
18
|
if (!method) return
|
|
18
19
|
const controller = new AbortController()
|
|
19
|
-
setDetails(
|
|
20
|
+
setDetails(""); setError("")
|
|
20
21
|
void (async () => {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
setDetails({ url: login.url, instructions: login.instructions })
|
|
24
|
-
openAuthBrowser(login.url)
|
|
25
|
-
const credentials = await login.complete
|
|
22
|
+
const status = await runCodexAuth(method === "existing" ? "status" : "login", { device: method === "device", signal: controller.signal,
|
|
23
|
+
onOutput: text => { if (!controller.signal.aborted) setDetails(previous => (previous + text).slice(-8192)) } })
|
|
26
24
|
if (controller.signal.aborted) return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
callbacks.current.onSuccess()
|
|
25
|
+
if (status !== 0) throw new Error("Codex login did not complete. Run codex login to retry.")
|
|
26
|
+
callbacks.current()
|
|
30
27
|
})().catch(error => { if (!controller.signal.aborted) setError(error instanceof Error ? error.message : "Codex login failed.") })
|
|
31
28
|
return () => controller.abort()
|
|
32
29
|
}, [method])
|
|
33
30
|
if (!method) return <PickerDialog title="OpenAI Codex · sign in with ChatGPT"
|
|
34
|
-
options={[{ id: "
|
|
31
|
+
options={[{ id: "existing", label: "Use existing Codex login", meta: "checks the local CLI session" },
|
|
32
|
+
{ id: "browser", label: "Browser login", meta: "opens ChatGPT sign-in · local callback on port 1455" },
|
|
35
33
|
{ id: "device", label: "Device code", meta: "for SSH, headless hosts, or a busy callback port" }]}
|
|
36
|
-
onCancel={onCancel} onSelect={id => setMethod(id as "browser" | "device")} />
|
|
34
|
+
onCancel={onCancel} onSelect={id => setMethod(id as "browser" | "device" | "existing")} />
|
|
37
35
|
return <DialogFrame title="OpenAI Codex · sign in with ChatGPT" hint="esc back / cancel login">
|
|
38
36
|
{error ? <Text color={c.warning}>{error}</Text> : <>
|
|
39
|
-
<Text>{details
|
|
40
|
-
{details && <Text color={c.accent}>{details.url}</Text>}
|
|
41
|
-
<Text color={c.text.faint}>If the browser did not open, open this URL manually. Waiting for authorization…</Text>
|
|
37
|
+
<Text>{stripVTControlCharacters(details) || "Starting the official Codex login…"}</Text>
|
|
42
38
|
</>}
|
|
43
39
|
</DialogFrame>
|
|
44
40
|
}
|
package/src/ui/dialog-config.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import { modelReasoningFor } from "../../zapsdk/core/reasoning-effort.js"
|
|
|
7
7
|
import { useEffect, useState } from "react"
|
|
8
8
|
import { discoverCodexModels } from "../codex-provider.js"
|
|
9
9
|
import {
|
|
10
|
-
effortModel,
|
|
10
|
+
agentManagingModel, effortModel,
|
|
11
11
|
upsertProvider,
|
|
12
12
|
getActiveProvider,
|
|
13
13
|
getEffort,
|
|
@@ -53,6 +53,8 @@ export function ModeDialog({ config, onCommit, onCancel }: DialogProps) {
|
|
|
53
53
|
// ── Effort picker ────────────────────────────────────────────────────────
|
|
54
54
|
export function EffortDialog({ config, onCommit, onCancel }: DialogProps) {
|
|
55
55
|
const provider = getActiveProvider(config)
|
|
56
|
+
const agent = agentManagingModel(config)
|
|
57
|
+
if (agent) return <PickerDialog title="Reasoning effort" options={[{ id: "agent", label: `Managed by ${agent}`, disabled: true }]} onCancel={onCancel} onSelect={onCancel} />
|
|
56
58
|
// A changed connection remounts the fetch and picker, including its cursor.
|
|
57
59
|
return <ModelEffortDialog key={provider ? `${provider.id}:${effortModel(config, provider)}` : "none"}
|
|
58
60
|
config={config} onCommit={onCommit} onCancel={onCancel} />
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { useRef, useState } from "react"
|
|
3
3
|
import { Box, Text, useInput } from "ink"
|
|
4
4
|
import { randomUUID } from "node:crypto"
|
|
5
|
-
import { buildConnectedProvider, inferLegacyContextWindowMode, presetForConnection, removeProvider, upsertProvider,
|
|
5
|
+
import { conversationAgentId, buildConnectedProvider, inferLegacyContextWindowMode, presetForConnection, removeProvider, upsertProvider,
|
|
6
6
|
type AppConfig, type ContextWindowMode, type Provider, type ProviderProtocol } from "../config.js"
|
|
7
7
|
import { ProviderDirectory } from "./provider-directory.js"
|
|
8
8
|
import { DialogFrame } from "./dialog-frame.js"
|
|
@@ -15,7 +15,7 @@ import { ContextWindowDialog } from "./dialog-context-window.js"
|
|
|
15
15
|
import { CodexLoginDialog } from "./dialog-codex-login.js"
|
|
16
16
|
import { connectCodexProvider } from "../codex-provider.js"
|
|
17
17
|
|
|
18
|
-
interface Props { config: AppConfig; onSave: (next: AppConfig) => void; onCommit: (next: AppConfig) => void; onCancel: () => void }
|
|
18
|
+
interface Props { onAgentSelected?: (message: string) => void; config: AppConfig; onSave: (next: AppConfig) => void; onCommit: (next: AppConfig) => void; onCancel: () => void }
|
|
19
19
|
type Draft = { name: string; baseURL: string; apiKey: string; protocol: ProviderProtocol;
|
|
20
20
|
authMode: "none" | "api-key"; catalogProviderId?: string; existing?: Provider;
|
|
21
21
|
contextWindow?: number; contextWindowMode?: ContextWindowMode }
|
|
@@ -46,7 +46,7 @@ export function saveConnection(config: AppConfig, draft: Draft): AppConfig {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/** Persist the connection first, then guide new connections through model selection. */
|
|
49
|
-
export function ConnectDialog({ config, onSave, onCommit, onCancel }: Props) {
|
|
49
|
+
export function ConnectDialog({ onAgentSelected, config, onSave, onCommit, onCancel }: Props) {
|
|
50
50
|
const [step, setStep] = useState<Step>("connections")
|
|
51
51
|
const [index, setIndex] = useState(0)
|
|
52
52
|
const [deleting, setDeleting] = useState(false)
|
|
@@ -91,9 +91,10 @@ export function ConnectDialog({ config, onSave, onCommit, onCancel }: Props) {
|
|
|
91
91
|
hint={deleting ? "d confirm removal · esc cancel" : "↑↓ navigate · enter/e edit · m models · d remove · esc close"}>
|
|
92
92
|
<Text color={c.text.faint}>Add a connection, then choose its model. Press m to manage models for an existing connection.</Text>
|
|
93
93
|
<Box flexDirection="column" marginTop={1}>
|
|
94
|
+
{conversationAgentId(config) === "claude-code" && <Text color={c.accent}>Claude Code · active local CLI</Text>}
|
|
94
95
|
{config.providers.map((provider, i) => <Box key={provider.id} flexDirection="column">
|
|
95
96
|
<Text color={i === index ? c.accent : c.text.primary}>{`${i === index ? "›" : " "} ${provider.name || "Unnamed connection"}`}</Text>
|
|
96
|
-
<Text color={c.text.faint}>{` ${provider.authMode === "codex-oauth" ? "Codex
|
|
97
|
+
<Text color={c.text.faint}>{` ${provider.authMode === "codex-oauth" ? "Official Codex agent · local CLI login" : `${provider.protocol ?? "openai"} · ${provider.apiKey ? "API key stored" : "no key"}`} · ${provider.models.length} saved models`}</Text>
|
|
97
98
|
<Text color={c.text.faint}>{` ${provider.baseURL}`}</Text>
|
|
98
99
|
</Box>)}
|
|
99
100
|
<Text color={index === config.providers.length ? c.accent : c.text.primary}>{`${index === config.providers.length ? "›" : " "} + New connection`}</Text>
|
|
@@ -107,7 +108,10 @@ export function ConnectDialog({ config, onSave, onCommit, onCancel }: Props) {
|
|
|
107
108
|
setModelTarget({ id: result.provider.id, setup: true })
|
|
108
109
|
}} />
|
|
109
110
|
|
|
110
|
-
if (step === "preset") return <ProviderDirectory onCodex={() => setStep("codex")}
|
|
111
|
+
if (step === "preset") return <ProviderDirectory onCodex={() => setStep("codex")} onClaude={() => {
|
|
112
|
+
onCommit({ ...config, activeAgent: undefined, subscriptionAgent: "claude-code" })
|
|
113
|
+
onAgentSelected?.("agent → Claude Code")
|
|
114
|
+
}}
|
|
111
115
|
onCancel={() => setStep("connections")} onSelect={provider => {
|
|
112
116
|
setDraft({ catalogProviderId: provider?.id, name: provider?.name ?? "", baseURL: provider?.api ?? "", apiKey: "",
|
|
113
117
|
protocol: provider?.protocol ?? "openai", authMode: "api-key" })
|
package/src/ui/dialog-model.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @jsxImportSource react */
|
|
2
2
|
import { useEffect, useRef, useState } from "react"
|
|
3
3
|
import { Box, Text, useInput } from "ink"
|
|
4
|
-
import { inferLegacyContextWindowMode, resolveProviderContextWindow, upsertProvider, type AppConfig } from "../config.js"
|
|
4
|
+
import { agentManagingModel, inferLegacyContextWindowMode, resolveProviderContextWindow, upsertProvider, type AppConfig } from "../config.js"
|
|
5
5
|
import { associateModelMetadata, describeCatalogRow, selectCatalogModel } from "../provider-catalog.js"
|
|
6
6
|
import { configuredModelRows, discoverConfiguredModels, modelCatalogKey, savedConnectionCatalogs, type ConnectionCatalog, type ConnectionModelRow } from "../model-catalog.js"
|
|
7
7
|
import { DialogFrame } from "./dialog-frame.js"
|
|
@@ -96,8 +96,11 @@ export function ModelDialog({ config, initialProviderId, setup = false, onSave,
|
|
|
96
96
|
}
|
|
97
97
|
})
|
|
98
98
|
|
|
99
|
+
const agent = agentManagingModel(config)
|
|
100
|
+
const agentModel = agent === "claude-code" ? "Claude Code · model selected by local CLI" : agent ? `${agent} · model selected by agent` : undefined
|
|
99
101
|
if (!provider) return <DialogFrame title="Models · /model" hint="esc close">
|
|
100
|
-
<Text>
|
|
102
|
+
{agentModel && <Text>Current: {agentModel}</Text>}
|
|
103
|
+
<Text>No provider models configured. Use /connect to add a model provider.</Text>
|
|
101
104
|
</DialogFrame>
|
|
102
105
|
if (phase === "metadata" && target && targetProvider) return <ModelMetadataDialog modelId={target.id}
|
|
103
106
|
onCancel={() => setPhase("models")} onSelect={metadata => {
|
|
@@ -141,7 +144,7 @@ export function ModelDialog({ config, initialProviderId, setup = false, onSave,
|
|
|
141
144
|
return <DialogFrame title={`${setup ? "Choose a model" : "Models"} · ${providerFilter === null ? "All connections" : provider.name || provider.baseURL}`}
|
|
142
145
|
hint={setup ? "↑↓ navigate · enter select and finish · m metadata · c context · / filter · t manual · esc choose later" : "↑↓ navigate · enter select · / search · p filter connections · m metadata · c context · r refresh · t manual · esc close"}>
|
|
143
146
|
{setup && <Text color={c.accent}>Connection saved. Choose a model to use it, or press esc to choose later with /model.</Text>}
|
|
144
|
-
<Text color={c.text.faint}>{truncateToWidth(`Current: ${config.active.model || "none"} · ${activeProvider?.name || "none"}`, width)}</Text>
|
|
147
|
+
<Text color={c.text.faint}>{truncateToWidth(`Current: ${agentModel ?? `${config.active.model || "none"} · ${activeProvider?.name || "none"}`}`, width)}</Text>
|
|
145
148
|
<Text color={c.text.faint}>{truncateToWidth(`${shown.length} models · ${scopedCatalogs.length} connections${loading ? ` · ${loading} discovering…` : ""}${failed ? ` · ${failed} discovery unavailable` : ""}${query ? ` · filter: ${query}` : ""}`, width)}</Text>
|
|
146
149
|
<Text color={c.text.faint}>{truncateToWidth((provider.contextWindowMode ?? inferLegacyContextWindowMode(provider)) === "manual"
|
|
147
150
|
? `${provider.name}: manual context ${provider.contextWindow.toLocaleString("en-US")} tokens · c to change`
|
|
@@ -149,7 +152,7 @@ export function ModelDialog({ config, initialProviderId, setup = false, onSave,
|
|
|
149
152
|
{error && <Text color={c.warning}>{truncateToWidth(`${provider.name}: ${error}`, width)}</Text>}
|
|
150
153
|
<Box flexDirection="column" marginTop={1}>
|
|
151
154
|
{shown.slice(start, start + count).map((row, i) => <Box key={modelCatalogKey(row.provider.id, row.id)} flexDirection="column">
|
|
152
|
-
<Text color={start + i === selectedIndex ? c.accent : c.text.primary} bold={start + i === selectedIndex}>{truncateToWidth(`${start + i === selectedIndex ? "›" : " "} ${row.id}${row.provider.id === config.active.providerId && row.id === config.active.model ? " (current)" : ""}`, width)}</Text>
|
|
155
|
+
<Text color={start + i === selectedIndex ? c.accent : c.text.primary} bold={start + i === selectedIndex}>{truncateToWidth(`${start + i === selectedIndex ? "›" : " "} ${row.id}${!agent && row.provider.id === config.active.providerId && row.id === config.active.model ? " (current)" : ""}`, width)}</Text>
|
|
153
156
|
<Text color={c.text.faint}>{truncateToWidth(` ${row.provider.name || row.provider.id} · ${row.provider.baseURL}`, width)}</Text>
|
|
154
157
|
<Text color={c.text.faint}>{truncateToWidth(` ${describeCatalogRow(row)}`, width)}</Text>
|
|
155
158
|
</Box>)}
|
|
@@ -10,11 +10,11 @@ import { useTermWidth } from "./term-width.js"
|
|
|
10
10
|
import { truncateToWidth } from "./truncate.js"
|
|
11
11
|
import { c } from "./theme.js"
|
|
12
12
|
|
|
13
|
-
interface Props { onSelect: (provider: ModelsDevConnection | null) => void; onCancel: () => void; metadataOnly?: boolean; onCodex?: () => void }
|
|
13
|
+
interface Props { onSelect: (provider: ModelsDevConnection | null) => void; onCancel: () => void; metadataOnly?: boolean; onCodex?: () => void; onClaude?: () => void }
|
|
14
14
|
|
|
15
15
|
/** Public directory data supplies vendor names and endpoints; adapters only
|
|
16
16
|
* constrain which wire protocols the installed runtime actually supports. */
|
|
17
|
-
export function ProviderDirectory({ onSelect, onCancel, metadataOnly = false, onCodex }: Props) {
|
|
17
|
+
export function ProviderDirectory({ onSelect, onCancel, metadataOnly = false, onCodex, onClaude }: Props) {
|
|
18
18
|
const [providers, setProviders] = useState<ModelsDevConnection[]>([])
|
|
19
19
|
const [loading, setLoading] = useState(true)
|
|
20
20
|
const [error, setError] = useState("")
|
|
@@ -60,13 +60,15 @@ export function ProviderDirectory({ onSelect, onCancel, metadataOnly = false, on
|
|
|
60
60
|
maxRows={Math.max(3, Math.min(10, (process.stdout.rows ?? 24) - 15))}
|
|
61
61
|
hint="↑↓ select · enter configure · / search · r reload · esc back"
|
|
62
62
|
options={[...(!metadataOnly ? [{ id: "__custom", label: "Custom endpoint", meta: "configure manually" }] : []),
|
|
63
|
-
...(!metadataOnly && onCodex ? [{ id: "__codex", label: "OpenAI Codex (ChatGPT)", meta: "
|
|
63
|
+
...(!metadataOnly && onCodex ? [{ id: "__codex", label: "OpenAI Codex (ChatGPT)", meta: "official agent · sign in with Codex CLI" }] : []),
|
|
64
|
+
...(!metadataOnly && onClaude ? [{ id: "__claude", label: "Claude Code", meta: "official agent · sign in with claude auth login" }] : []),
|
|
64
65
|
...visible.map(provider => ({ id: `catalog:${provider.id}`, label: truncateToWidth(provider.name, labelWidth),
|
|
65
66
|
meta: truncateToWidth(provider.protocol ? `${provider.protocol}${provider.api ? " · endpoint provided" : " · enter endpoint"}` : "unsupported adapter", width - labelWidth - 2),
|
|
66
67
|
disabled: !metadataOnly && !provider.protocol }))]}
|
|
67
68
|
onCancel={onCancel} onSelect={id => {
|
|
68
69
|
if (id === "__custom") onSelect(null)
|
|
69
70
|
else if (id === "__codex") onCodex?.()
|
|
71
|
+
else if (id === "__claude") onClaude?.()
|
|
70
72
|
else {
|
|
71
73
|
const provider = providers.find(item => item.id === id.slice("catalog:".length))
|
|
72
74
|
if (provider && (metadataOnly || provider.protocol)) onSelect(provider)
|
|
@@ -179,8 +179,14 @@ export function contentText(block: ContentBlock | undefined | null): string {
|
|
|
179
179
|
/** Usage from a prompt response or `_meta`, in zap's shape. */
|
|
180
180
|
export function acpUsage(usage: Usage | null | undefined): TokenUsage | undefined {
|
|
181
181
|
if (!usage) return undefined;
|
|
182
|
+
// Some ACP agents include cached tokens in inputTokens. Codex ACP reports
|
|
183
|
+
// disjoint fresh/read/write counts, whose sum reconciles with totalTokens.
|
|
184
|
+
const cached = (usage.cachedReadTokens ?? 0) + (usage.cachedWriteTokens ?? 0);
|
|
185
|
+
const sum = usage.inputTokens + cached + usage.outputTokens;
|
|
186
|
+
const disjoint = usage.inputTokens < cached || usage.totalTokens === sum
|
|
187
|
+
|| usage.totalTokens === sum + (usage.thoughtTokens ?? 0);
|
|
182
188
|
return {
|
|
183
|
-
inputTokens: Math.max(0, usage.inputTokens -
|
|
189
|
+
inputTokens: disjoint ? usage.inputTokens : Math.max(0, usage.inputTokens - cached),
|
|
184
190
|
outputTokens: usage.outputTokens,
|
|
185
191
|
cacheReadInputTokens: usage.cachedReadTokens ?? undefined,
|
|
186
192
|
cacheCreationInputTokens: usage.cachedWriteTokens ?? undefined,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
2
|
-
import { dirname, isAbsolute, join, sep } from "node:path";
|
|
2
|
+
import { dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
3
3
|
import { RequestError, type PermissionOption, type RequestPermissionRequest, type RequestPermissionResponse } from "@agentclientprotocol/sdk";
|
|
4
4
|
import type { ApprovalCallback, ApprovalContext, ApprovalResponse } from "../tools/executor.js";
|
|
5
5
|
import { resolveToolPathCanonical } from "../builtin-tools/filesystem.js";
|
|
@@ -45,7 +45,17 @@ export class AcpWorkspace {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
contains(path: string): boolean { return within(path, this.root); }
|
|
48
|
-
isProtected(path: string): boolean {
|
|
48
|
+
isProtected(path: string): boolean {
|
|
49
|
+
// Reserve control-directory spellings even when a new path has no
|
|
50
|
+
// on-disk casing for realpath to recover on macOS or Windows.
|
|
51
|
+
const fold = process.platform === "win32" || process.platform === "darwin";
|
|
52
|
+
return this.protectedRoots.some(root => fold ? within(path.toLowerCase(), root.toLowerCase()) : within(path, root));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
protectsWrite(path: string): boolean {
|
|
56
|
+
const absolute = resolve(this.root, path);
|
|
57
|
+
return this.isProtected(absolute) || this.isProtected(this.resolve(absolute));
|
|
58
|
+
}
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
function within(path: string, root: string): boolean {
|
|
@@ -86,7 +96,11 @@ export function createAcpHostHandlers(policy: AcpHostPolicy): AcpHostHandlers {
|
|
|
86
96
|
// must be answered "cancelled", not rejected.
|
|
87
97
|
const live = signalFor(signal);
|
|
88
98
|
if (live.aborted) return { outcome: { outcome: "cancelled" } };
|
|
89
|
-
const
|
|
99
|
+
const diffs = tool.content?.flatMap(item => item.type === "diff" ? [item.path] : []) ?? [];
|
|
100
|
+
const mutation = tool.kind === "edit" || tool.kind === "delete" || tool.kind === "move";
|
|
101
|
+
const paths = mutation ? [...diffs, ...(tool.locations ?? []).map(location => location.path)] : diffs;
|
|
102
|
+
const response = paths.some(path => workspace.protectsWrite(path))
|
|
103
|
+
? false : await approve(permissionTarget(policy.agentId, request, workspace), live);
|
|
90
104
|
if (live.aborted) return { outcome: { outcome: "cancelled" } };
|
|
91
105
|
const allowed = response === true;
|
|
92
106
|
decisions.push({ title, kind: tool.kind ?? undefined, allowed });
|
|
@@ -116,7 +130,7 @@ export function createAcpHostHandlers(policy: AcpHostPolicy): AcpHostHandlers {
|
|
|
116
130
|
|
|
117
131
|
async writeTextFile(request, signal) {
|
|
118
132
|
const path = workspace.resolve(request.path);
|
|
119
|
-
if (workspace.isProtected(path)) {
|
|
133
|
+
if (workspace.isProtected(request.path) || workspace.isProtected(path)) {
|
|
120
134
|
throw RequestError.internalError(undefined, "denied by zap: .git and .zapcode are protected and cannot be written");
|
|
121
135
|
}
|
|
122
136
|
const target: ApprovalTarget = workspace.contains(path)
|
package/zapsdk/acp-client/run.ts
CHANGED
|
@@ -84,6 +84,7 @@ export class AcpAgentSession {
|
|
|
84
84
|
}
|
|
85
85
|
const mode = options.mode ?? spec.mode;
|
|
86
86
|
if (mode) await session.attempt(`mode ${mode}`, () => connection.setMode(session.sessionId, mode));
|
|
87
|
+
if (spec.requireSettings && session.warnings.length) throw new Error(session.warnings.join("; "));
|
|
87
88
|
return session;
|
|
88
89
|
} catch (error) {
|
|
89
90
|
await connection.close();
|
|
@@ -26,6 +26,8 @@ export interface AcpAgentSpec {
|
|
|
26
26
|
model?: string;
|
|
27
27
|
/** Session mode to select after session/new (`session/set_mode`). */
|
|
28
28
|
mode?: string;
|
|
29
|
+
/** Reject the session if a requested mode, model or config option is refused. */
|
|
30
|
+
requireSettings?: boolean;
|
|
29
31
|
/** Session config options to apply after session/new
|
|
30
32
|
* (`session/set_config_option`), e.g. `{ thought_level: "high" }`. */
|
|
31
33
|
config?: Record<string, string>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { spawnSync, spawn, type ChildProcess } from "node:child_process";
|
|
2
3
|
import { localExecutionShell } from "./shell.js";
|
|
3
4
|
import { readProcessTable, snapshotDescendants } from "./process-tree.js";
|
|
4
5
|
import type {
|
|
@@ -135,7 +136,13 @@ export function terminateProcessTree(
|
|
|
135
136
|
let delivered = false;
|
|
136
137
|
const killChild = () => child.exitCode === null && child.signalCode === null && child.kill(signal);
|
|
137
138
|
try {
|
|
138
|
-
if (process.platform === "win32" ||
|
|
139
|
+
if (process.platform === "win32" && (signal === "SIGTERM" || signal === "SIGKILL") && child.pid && child.exitCode === null && child.signalCode === null) {
|
|
140
|
+
const systemRoot = process.env.SystemRoot ?? "C:\\Windows";
|
|
141
|
+
const result = spawnSync(join(systemRoot, "System32", "taskkill.exe"), ["/PID", String(child.pid), "/T", "/F"], {
|
|
142
|
+
stdio: "ignore", windowsHide: true, timeout: 3000,
|
|
143
|
+
});
|
|
144
|
+
delivered = result.status === 0 || killChild();
|
|
145
|
+
} else if (!child.pid || process.platform === "win32") delivered = killChild();
|
|
139
146
|
// The group can outlive its leader and keep stdout/stderr open. A leader's
|
|
140
147
|
// exit must not suppress escalation to surviving descendants.
|
|
141
148
|
else delivered = process.kill(-child.pid, signal);
|