@herbertgao/pi-extensions 2026.11.17 → 2026.11.19
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/CHANGELOG.md +25 -0
- package/README.md +3 -3
- package/THIRD_PARTY_NOTICES.md +2 -23
- package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +956 -0
- package/node_modules/{pi-antigravity → @estebanforge/pi-antigravity-bridge}/LICENSE +1 -1
- package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +240 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +2117 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/connection.ts +644 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/driver.ts +1043 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/events.ts +323 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/home.ts +145 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/jsonrpc.ts +243 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/setup.ts +107 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/usage-estimate.ts +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agents.ts +64 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-install.ts +93 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-paths.ts +30 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-setup.ts +81 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-version.ts +289 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-detect.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-gate.ts +233 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-hook.ts +325 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts-ui.ts +88 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts.ts +144 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/ask-tool.ts +1221 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/background-watch.ts +225 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/bridge-catalog.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/daily-log.ts +196 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/dialog-lock.ts +48 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/diff-render.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver-types.ts +168 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver.ts +907 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/engine-picker.ts +160 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/frame-guard.ts +38 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/handoff-toast.ts +21 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-registration.ts +376 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-server.ts +618 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/models.ts +404 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/native-tools.ts +104 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/parked-turn.ts +125 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/patch-cleanup.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/poll-fold.ts +55 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/prompt-images.ts +92 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +2214 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/queued-messages.ts +152 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/quota-notice.ts +40 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/redact.ts +27 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sessions.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/skills.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-events.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-sanitizer.ts +180 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/subagent-roster.ts +245 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sysprompt-agent.ts +130 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks-ui.ts +90 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/usage.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/web-tools.ts +320 -0
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +12 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +3 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/index.ts +7 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/agent-badge.ts +244 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +10 -3
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/names.ts +18 -0
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
- package/node_modules/@herbertgao/pi-inline-skill-commands/README.md +18 -0
- package/node_modules/@herbertgao/pi-inline-skill-commands/package.json +1 -1
- package/node_modules/@herbertgao/pi-inline-skill-commands/src/index.ts +80 -0
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +320 -102
- package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -30
- package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
- package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +27 -13
- package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
- package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
- package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +217 -41
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
- package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -93
- package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
- package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
- package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
- package/node_modules/pi-commandcode-provider/README.md +3 -2
- package/node_modules/pi-commandcode-provider/index.ts +120 -13
- package/node_modules/pi-commandcode-provider/package.json +4 -3
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
- package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
- package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
- package/package.json +12 -15
- package/node_modules/pi-antigravity/README.md +0 -298
- package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
- package/node_modules/pi-antigravity/package.json +0 -87
- package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
- package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
- package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
- package/node_modules/pi-antigravity/src/client/client.ts +0 -602
- package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
- package/node_modules/pi-antigravity/src/client/index.ts +0 -2
- package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
- package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
- package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
- package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
- package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
- package/node_modules/pi-antigravity/src/image/image.ts +0 -427
- package/node_modules/pi-antigravity/src/image/index.ts +0 -1
- package/node_modules/pi-antigravity/src/image/native.ts +0 -69
- package/node_modules/pi-antigravity/src/index.ts +0 -547
- package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
- package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
- package/node_modules/pi-antigravity/src/models/index.ts +0 -3
- package/node_modules/pi-antigravity/src/models/models.ts +0 -647
- package/node_modules/pi-antigravity/src/search/index.ts +0 -1
- package/node_modules/pi-antigravity/src/search/search.ts +0 -967
- package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
- package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
- package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
- package/node_modules/pi-antigravity/src/types/index.ts +0 -2
- package/node_modules/pi-antigravity/src/types/types.ts +0 -329
- package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
- package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
- package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
- package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
- package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
- package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
- package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
- package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
- package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
- package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
- package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
- package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
- package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
- package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
- package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
- package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
- package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
- package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
- package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
- package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
- package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
- package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
- package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
- package/node_modules/pi-antigravity/tsconfig.json +0 -21
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
// Runtime config for the antigravity provider. Persisted at
|
|
2
|
+
// <agentDir>/antigravity-bridge/config.json so the /agy command can
|
|
3
|
+
// toggle settings that take effect on the next turn.
|
|
4
|
+
//
|
|
5
|
+
// Knobs today:
|
|
6
|
+
// mode "accept-edits" (default) or "plan". Drives agy's --mode.
|
|
7
|
+
// skipPermissions true (default). Passes --dangerously-skip-permissions so
|
|
8
|
+
// commands don't hang on an unanswerable prompt in -p mode.
|
|
9
|
+
//
|
|
10
|
+
// Env overrides (AGY_MODE, AGY_SKIP_PERMISSIONS) win over the file so tests
|
|
11
|
+
// and one-off runs can force a setting without editing the file.
|
|
12
|
+
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
16
|
+
import { normalizeAgyAgentName } from "./agents.js";
|
|
17
|
+
|
|
18
|
+
/** pi's agent dir (env override PI_CODING_AGENT_DIR, else ~/.pi/agent); every
|
|
19
|
+
* bridge-owned path derives from it so isolated or rebranded pi homes keep
|
|
20
|
+
* their state together (issue #17). */
|
|
21
|
+
export function bridgeDir(agentDir: string = getAgentDir()): string {
|
|
22
|
+
return path.join(agentDir, "antigravity-bridge");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function configPath(agentDir: string = getAgentDir()): string {
|
|
26
|
+
return path.join(bridgeDir(agentDir), "config.json");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Scoped extensions-data convention shared with other EstebanForge
|
|
30
|
+
* extensions: <configRoot>/extensions-data/<author>/<name>, anchored at
|
|
31
|
+
* dirname(getAgentDir()) so it relocates with the agent dir too. */
|
|
32
|
+
export function extensionsDataDir(agentDir: string = getAgentDir()): string {
|
|
33
|
+
return path.join(path.dirname(agentDir), "extensions-data", "estebanforge", "pi-antigravity-bridge");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Daily debug logs land here, sorted by day, for post-mortems and user
|
|
37
|
+
* support (see src/daily-log.ts). */
|
|
38
|
+
export function logsDir(agentDir: string = getAgentDir()): string {
|
|
39
|
+
return path.join(extensionsDataDir(agentDir), "logs");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Native `agy acp` is the default for new installs; stream-json remains
|
|
43
|
+
* a fully supported fallback. */
|
|
44
|
+
export type Engine = "stream-json" | "acp";
|
|
45
|
+
|
|
46
|
+
/** The engine a fresh install runs when nothing is configured (no file key,
|
|
47
|
+
* no AGY_ENGINE): the official ACP server. Unknown/stale stored values also
|
|
48
|
+
* fall back here. Startup checks that the required agy CLI is available. */
|
|
49
|
+
export const DEFAULT_ENGINE: Engine = "acp";
|
|
50
|
+
export type AgyMode = "accept-edits" | "plan";
|
|
51
|
+
export type ThinkingTier = "low" | "medium" | "high";
|
|
52
|
+
export type BridgeTools = "none" | "mcp" | "all";
|
|
53
|
+
|
|
54
|
+
/** How ACP turns report token usage while Gate B stands (agy sends none).
|
|
55
|
+
* "estimate" (default): word-boundary regex over prompt/response/thought
|
|
56
|
+
* text (pi-token-speed's mechanism). "direct": 1 token per streamed delta.
|
|
57
|
+
* "off": keep zero-usage. Real server usage (usageSeen latch) always wins. */
|
|
58
|
+
export type UsageEstimate = "estimate" | "direct" | "off";
|
|
59
|
+
|
|
60
|
+
/** How the approval gate activates (docs/TODO.md section 2.5).
|
|
61
|
+
*
|
|
62
|
+
* "auto" (default): OFF until a third-party pi permission extension is
|
|
63
|
+
* detected (src/approval-detect.ts). When one is found, the gate runs in
|
|
64
|
+
* "shadow" mode so that extension gates agy's native tool calls with zero
|
|
65
|
+
* configuration on its side.
|
|
66
|
+
*
|
|
67
|
+
* "shadow" / "dedicated": force the gate on in that shape. "off": never
|
|
68
|
+
* gate, even when a permission extension is installed. NOTE: "dedicated"
|
|
69
|
+
* currently stages the same shadow tools as "shadow" (warn-logged remap);
|
|
70
|
+
* the explicit antigravity_approve variant is planned - see docs/TODO.md. */
|
|
71
|
+
export type GateMode = "auto" | "shadow" | "dedicated" | "off";
|
|
72
|
+
|
|
73
|
+
/** Fallback decision when no extension blocked a gated call: "ask" uses
|
|
74
|
+
* ctx.ui.confirm (headless = deny, fail-closed), "allow" auto-approves,
|
|
75
|
+
* "deny" auto-rejects. */
|
|
76
|
+
export type GateAskMode = "ask" | "allow" | "deny";
|
|
77
|
+
|
|
78
|
+
export interface GateConfig {
|
|
79
|
+
gateMode: GateMode;
|
|
80
|
+
mode: GateAskMode;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface AcpConfig {
|
|
84
|
+
/** Gate B stopgap: client-side token estimates for ACP turns so pi's
|
|
85
|
+
* usage surfaces show nonzero numbers. Estimates are labeled as such in
|
|
86
|
+
* /agy doctor and auto-disable when the server sends real usage. */
|
|
87
|
+
usageEstimate: UsageEstimate;
|
|
88
|
+
/** Timeout in ms for ACP session operations (session/new, session/load,
|
|
89
|
+
* session/set_config_option, session/close). Default 20000 (20s); valid
|
|
90
|
+
* range 1000..300000. Env AGY_ACP_SESSION_TIMEOUT_MS wins over the file. */
|
|
91
|
+
sessionTimeoutMs: number;
|
|
92
|
+
/** Advanced: transparently retry session/new once when it times out while
|
|
93
|
+
* the ACP server is still alive. Default false. Warning: doubles the wait
|
|
94
|
+
* on genuinely dead networks (e.g. 40s at default 20s timeout) and may not
|
|
95
|
+
* recover if the server process itself has a wedged socket.
|
|
96
|
+
* Env AGY_ACP_SESSION_RETRY wins over the file. */
|
|
97
|
+
sessionRetryOnTimeout: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface AgyConfig {
|
|
101
|
+
/** Engine. Switching requires a pi restart (drivers wire at load). */
|
|
102
|
+
engine: Engine;
|
|
103
|
+
/** Official-server ACP engine options (used when engine = "acp"). */
|
|
104
|
+
acp: AcpConfig;
|
|
105
|
+
mode: AgyMode;
|
|
106
|
+
/** Fail-closed kill switch for provider turns. ON = every provider turn
|
|
107
|
+
* is refused visibly: the agy CLI has no review-only enforcement on any
|
|
108
|
+
* path (probed 2026-10-07, upstream #1181: plan mode stages a plan and
|
|
109
|
+
* executes the write in the same turn on -p and stream-json alike; the
|
|
110
|
+
* provider plan turns are refused on ACP too). Built for callers like
|
|
111
|
+
* `pi -p --no-tools` health checks that must never mutate a workspace
|
|
112
|
+
* and prefer a visible refusal over a write-capable turn. Wins over
|
|
113
|
+
* `mode`; the AskAntigravity delegation tool is refused while this is on
|
|
114
|
+
* (the CLI has no review-only enforcement, so nothing here can run
|
|
115
|
+
* read-only). Env AGY_READONLY wins over the file.
|
|
116
|
+
* Default false. */
|
|
117
|
+
readOnly: boolean;
|
|
118
|
+
/** Auto-approve all agy tool permission requests (--dangerously-skip-permissions).
|
|
119
|
+
* Required for non-interactive use: without it, any `run_command` triggers an
|
|
120
|
+
* interactive y/n prompt that hangs forever in `-p` mode. Defaults true.
|
|
121
|
+
* DANGEROUS: lets agy run arbitrary commands (including destructive ones)
|
|
122
|
+
* without review. The ask tool withholds the flag on plan runs;
|
|
123
|
+
* accept-edits runs need it to avoid hanging on the unanswerable prompt. */
|
|
124
|
+
skipPermissions: boolean;
|
|
125
|
+
/** AskAntigravity tool: default model alias (flash/pro/gemini or exact). */
|
|
126
|
+
defaultModel: string;
|
|
127
|
+
/** AskAntigravity tool: default thinking tier when the alias names none. */
|
|
128
|
+
defaultThinking: ThinkingTier;
|
|
129
|
+
/** Register the AskAntigravity one-shot delegation tool. Default on.
|
|
130
|
+
* off removes the tool entirely for users who want only the provider
|
|
131
|
+
* and models (no delegation tool in the model's window context).
|
|
132
|
+
* Takes effect at pi start (or /reload). */
|
|
133
|
+
askTool: boolean;
|
|
134
|
+
/** Register the agy_web_search + agy_read_url Pi tools. Default OFF:
|
|
135
|
+
* inside Antigravity sessions the model already has native web tools;
|
|
136
|
+
* these exist for NON-Antigravity provider sessions and every call
|
|
137
|
+
* spends Antigravity quota. Takes effect at pi start (or /reload). */
|
|
138
|
+
webTools: boolean;
|
|
139
|
+
/** Set after the one-time notice about a leftover legacy invokeTool patch
|
|
140
|
+
* on the installed pi. The notice never repeats; /agy patch-cleanup is
|
|
141
|
+
* always available. */
|
|
142
|
+
patchCleanupNotified?: boolean;
|
|
143
|
+
/** Custom agy agent for stream-json turns (`--agent`, /agy agent).
|
|
144
|
+
* Absent = agy's default agent. ACP turns ignore it (no protocol slot). */
|
|
145
|
+
agent?: string;
|
|
146
|
+
/** Which pi tools the MCP bridge exposes to agy: "none" (bridge off),
|
|
147
|
+
* "all" (every registered non-builtin tool incl. other Ask* delegations;
|
|
148
|
+
* default - users expect the bridge working out of the box, and the
|
|
149
|
+
* "mcp" surface serves an empty catalog on installs without
|
|
150
|
+
* pi-mcp-adapter), "mcp" (pi-mcp-adapter tools + skills bridge only). */
|
|
151
|
+
bridgeTools: BridgeTools;
|
|
152
|
+
/** Extra pi tool names that get the long (120s) synchronous escalation
|
|
153
|
+
* window, in addition to delegation-shaped names (subagent_run,
|
|
154
|
+
* agent_spawn/agent_wait, *delegate*; issue #6). For custom tools that
|
|
155
|
+
* legitimately run minutes-long but must return a plain result to an
|
|
156
|
+
* orchestrator. Env AGY_ESCALATE_LONG_TOOLS (comma-separated) wins over
|
|
157
|
+
* the file. Takes effect on the next bridge call. */
|
|
158
|
+
escalateLongTools?: string[];
|
|
159
|
+
/** Inject a delta digest of pi-side context (compaction summaries, turns
|
|
160
|
+
* handled by other providers or pi's own tools) into agy prompts.
|
|
161
|
+
*
|
|
162
|
+
* Default ON. The digest is self-gating: it ships only when the delta
|
|
163
|
+
* window is non-empty (a fresh agy conversation from a mid-session model
|
|
164
|
+
* switch or engine switch, another provider's turns, pi-side tool runs,
|
|
165
|
+
* or a compaction summary), and each piece ships once. Pure antigravity
|
|
166
|
+
* sessions get an empty delta, byte-stable prompts, and an intact
|
|
167
|
+
* server-side prompt cache.
|
|
168
|
+
*
|
|
169
|
+
* Turn off for agy-native behavior: prompts then contain only your
|
|
170
|
+
* message, and a conversation opened mid-session starts without prior
|
|
171
|
+
* pi-side context. */
|
|
172
|
+
digest: boolean;
|
|
173
|
+
/** Prepend pi's composed system prompt (pi tool guidance + the global
|
|
174
|
+
* agent-dir AGENTS.md and ancestor AGENTS.md/CLAUDE.md) to the FIRST
|
|
175
|
+
* prompt of each fresh agy conversation.
|
|
176
|
+
*
|
|
177
|
+
* Default ON: agy keeps its own history, so the prefix is sent once per
|
|
178
|
+
* conversation and stays byte-identical afterwards - agy's server-side
|
|
179
|
+
* prompt cache keeps hitting. This is why it is safe here while the G1
|
|
180
|
+
* digest (per-turn) is not. Turn off for agy-native behavior (agy's own
|
|
181
|
+
* system prompt only). */
|
|
182
|
+
systemPrompt: boolean;
|
|
183
|
+
/** Overall cap on ONE agy turn in minutes, both engines. When it fires, the
|
|
184
|
+
* bridge kills the agy process mid-task ("ACP turn exceeded the Xm
|
|
185
|
+
* deadline" / "agy exceeded the Xm turn timeout"). The ACP server binary
|
|
186
|
+
* exposes no timeout flag of its own (--helpfull: debug/notices only), so
|
|
187
|
+
* this bridge cap is the only knob.
|
|
188
|
+
*
|
|
189
|
+
* Default is TTY-aware: 0 (no cap) on an interactive pi - the user aborts
|
|
190
|
+
* with Esc and is the better backstop - and 20 on headless runs, where
|
|
191
|
+
* nobody can abort and one runaway turn blocks the drivers' serialized
|
|
192
|
+
* turn queue. Explicit values opt into the gate: 1..1440 valid, 0
|
|
193
|
+
* disables, anything else (garbage, negative, >1440) falls back to the
|
|
194
|
+
* TTY-aware default. The inactivity stall guard (5m silence) still bounds
|
|
195
|
+
* a hung server either way. Next-turn effect. Env AGY_TURN_TIMEOUT_MIN
|
|
196
|
+
* wins over the file. */
|
|
197
|
+
turnTimeoutMin: number;
|
|
198
|
+
/** Silence cap in minutes, both engines: no stream-json stdout / no ACP
|
|
199
|
+
* session/update for this long fails the turn as a stall. Default 5;
|
|
200
|
+
* 0 disables the guard. Next-turn effect.
|
|
201
|
+
* Env AGY_INACTIVITY_TIMEOUT_MIN wins over the file. */
|
|
202
|
+
inactivityTimeoutMin: number;
|
|
203
|
+
/** Approval gate over agy NATIVE tool calls (create_file, run_command,
|
|
204
|
+
* ...). pi tools agy calls already pass through pi's gates via the G9
|
|
205
|
+
* round-trip; this covers the rest. Default auto (off until a
|
|
206
|
+
* third-party permission extension is detected). See docs/TODO.md 2.5. */
|
|
207
|
+
approvals: GateConfig;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const DEFAULTS: AgyConfig = {
|
|
211
|
+
engine: DEFAULT_ENGINE,
|
|
212
|
+
mode: "accept-edits",
|
|
213
|
+
readOnly: false,
|
|
214
|
+
skipPermissions: true,
|
|
215
|
+
defaultModel: "gemini-4-hydrogen",
|
|
216
|
+
defaultThinking: "medium",
|
|
217
|
+
askTool: true,
|
|
218
|
+
webTools: false,
|
|
219
|
+
bridgeTools: "all",
|
|
220
|
+
digest: true,
|
|
221
|
+
systemPrompt: true,
|
|
222
|
+
turnTimeoutMin: 0, // placeholder: the real default is resolved per loadConfig call (defaultTurnTimeoutMin)
|
|
223
|
+
inactivityTimeoutMin: 5,
|
|
224
|
+
approvals: { gateMode: "auto", mode: "ask" },
|
|
225
|
+
acp: {
|
|
226
|
+
usageEstimate: "estimate",
|
|
227
|
+
sessionTimeoutMs: 20_000,
|
|
228
|
+
sessionRetryOnTimeout: false,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const MIN_ACP_SESSION_TIMEOUT_MS = 1_000;
|
|
233
|
+
const MAX_ACP_SESSION_TIMEOUT_MS = 300_000;
|
|
234
|
+
|
|
235
|
+
function parseSessionTimeoutMs(raw: unknown, fallback: number): number {
|
|
236
|
+
if (raw === undefined || raw === null || String(raw).trim() === "") return fallback;
|
|
237
|
+
const n = typeof raw === "number" ? raw : Number(String(raw).trim());
|
|
238
|
+
if (!Number.isSafeInteger(n)) return fallback;
|
|
239
|
+
return n >= MIN_ACP_SESSION_TIMEOUT_MS && n <= MAX_ACP_SESSION_TIMEOUT_MS ? n : fallback;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Hard ceiling for a free-typed turn cap: one day, in minutes. */
|
|
243
|
+
export const MAX_TURN_CAP_MIN = 1440;
|
|
244
|
+
|
|
245
|
+
/** TTY-aware default for the overall turn cap. An interactive user aborts
|
|
246
|
+
* with Esc and is the better backstop; the wall clock only earns its keep
|
|
247
|
+
* where nobody can abort (headless runs: one runaway turn also blocks the
|
|
248
|
+
* drivers' serialized turn queue). */
|
|
249
|
+
export function defaultTurnTimeoutMin(): number {
|
|
250
|
+
return process.stdout.isTTY || process.stdin.isTTY ? 0 : 20;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** Explicit cap minutes: 0 keeps (disable), 1..MAX_TURN_CAP_MIN keeps;
|
|
254
|
+
* garbage, negative, or out-of-range falls back to the caller's default.
|
|
255
|
+
* Pass Number.NaN as the fallback to detect rejection via isNaN. */
|
|
256
|
+
export function parseCapMinutes(raw: string | number | undefined, fallback: number): number {
|
|
257
|
+
if (raw === undefined || String(raw).trim() === "") return fallback;
|
|
258
|
+
const n = typeof raw === "number" ? raw : Number(String(raw).trim());
|
|
259
|
+
if (!Number.isFinite(n)) return fallback;
|
|
260
|
+
if (n === 0) return 0;
|
|
261
|
+
return n >= 1 && n <= MAX_TURN_CAP_MIN ? n : fallback;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Read the raw config file (no defaults, no env). Shared by loadConfig and
|
|
265
|
+
* saveConfig so persisted writes can never bake env overrides into the file. */
|
|
266
|
+
function readConfigFile(configPath: string): Partial<AgyConfig> {
|
|
267
|
+
try {
|
|
268
|
+
const raw = fs.readFileSync(configPath, "utf8");
|
|
269
|
+
const parsed = JSON.parse(raw);
|
|
270
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
271
|
+
return parsed as Partial<AgyConfig>;
|
|
272
|
+
}
|
|
273
|
+
} catch {
|
|
274
|
+
/* missing or corrupt - fall back to empty */
|
|
275
|
+
}
|
|
276
|
+
return {};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Strip the retired acp.bin key from the raw config file; returns true when
|
|
280
|
+
* removed. Raw passthrough on purpose (no defaults merge): users keep their
|
|
281
|
+
* minimal hand-edited shape instead of gaining the full default set. */
|
|
282
|
+
export function removeLegacyAcpBin(configFile: string = configPath()): boolean {
|
|
283
|
+
const file = readConfigFile(configFile) as Record<string, unknown>;
|
|
284
|
+
if (!file.acp || typeof file.acp !== "object" || Array.isArray(file.acp)) return false;
|
|
285
|
+
const acp = file.acp as Record<string, unknown>;
|
|
286
|
+
if (!("bin" in acp)) return false;
|
|
287
|
+
delete acp.bin;
|
|
288
|
+
// Rename would replace a dotfiles-managed symlink with a regular file;
|
|
289
|
+
// write through the resolved target so the link survives.
|
|
290
|
+
writeConfigJson(fs.realpathSync(configFile), file);
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Load config merged over defaults. Env vars override the file when set. */
|
|
295
|
+
export function loadConfig(configFile: string = configPath()): AgyConfig {
|
|
296
|
+
let file: Partial<AgyConfig> = readConfigFile(configFile);
|
|
297
|
+
|
|
298
|
+
// Env overrides file (matches the skipPermissions pattern).
|
|
299
|
+
// The naive OR `env === "plan" || file.mode === "plan"` would ignore an
|
|
300
|
+
// explicit AGY_MODE=accept-edits when the file says plan, violating the
|
|
301
|
+
// documented precedence. Check env first.
|
|
302
|
+
// Engine: narrow to the known set; anything else (incl. the pre-1.3.2
|
|
303
|
+
// "sqlite" value) falls back to the default engine, same as an absent key.
|
|
304
|
+
// One absence exception: a config file WITHOUT an engine key belongs to an
|
|
305
|
+
// existing install (saveConfig persists the resolved legacy engine), and
|
|
306
|
+
// the acp default is for new installs only - an existing install keeps
|
|
307
|
+
// the legacy stream-json engine. existsSync is false on EACCES too, which reads as fresh
|
|
308
|
+
// and picks acp; an unreadable config dir is a broken install either way.
|
|
309
|
+
const freshInstall = !fs.existsSync(configFile);
|
|
310
|
+
const engineFallback = freshInstall || file.engine !== undefined ? DEFAULT_ENGINE : "stream-json";
|
|
311
|
+
const engine = narrowEngine(String(process.env.AGY_ENGINE ?? file.engine ?? engineFallback).toLowerCase());
|
|
312
|
+
|
|
313
|
+
const mode: AgyMode =
|
|
314
|
+
process.env.AGY_MODE !== undefined
|
|
315
|
+
? process.env.AGY_MODE === "plan"
|
|
316
|
+
? "plan"
|
|
317
|
+
: "accept-edits"
|
|
318
|
+
: file.mode === "plan"
|
|
319
|
+
? "plan"
|
|
320
|
+
: "accept-edits";
|
|
321
|
+
|
|
322
|
+
const envPerm = process.env.AGY_SKIP_PERMISSIONS;
|
|
323
|
+
const skipPermissions =
|
|
324
|
+
envPerm !== undefined
|
|
325
|
+
? envPerm === "1" || envPerm.toLowerCase() === "true"
|
|
326
|
+
: file.skipPermissions ?? DEFAULTS.skipPermissions;
|
|
327
|
+
|
|
328
|
+
const envReadOnly = process.env.AGY_READONLY;
|
|
329
|
+
// Fail-closed parse for a safety knob: empty string means the user
|
|
330
|
+
// explicitly blanked it (off), but ANY other set value that is not a
|
|
331
|
+
// spelled-out falsity counts as ON. " 1", "yes", typos: all refuse.
|
|
332
|
+
const readOnly =
|
|
333
|
+
envReadOnly !== undefined
|
|
334
|
+
? envReadOnly === ""
|
|
335
|
+
? false
|
|
336
|
+
: !["0", "false", "off"].includes(envReadOnly.trim().toLowerCase())
|
|
337
|
+
: file.readOnly ?? DEFAULTS.readOnly;
|
|
338
|
+
|
|
339
|
+
const defaultModelRaw =
|
|
340
|
+
process.env.AGY_DEFAULT_MODEL ?? file.defaultModel ?? DEFAULTS.defaultModel;
|
|
341
|
+
const defaultModel =
|
|
342
|
+
typeof defaultModelRaw === "string" ? defaultModelRaw.trim() || DEFAULTS.defaultModel : DEFAULTS.defaultModel;
|
|
343
|
+
|
|
344
|
+
const envThink = process.env.AGY_DEFAULT_THINKING;
|
|
345
|
+
const thinkRaw = (envThink ?? file.defaultThinking ?? DEFAULTS.defaultThinking).toLowerCase();
|
|
346
|
+
const defaultThinking: ThinkingTier =
|
|
347
|
+
thinkRaw === "low" || thinkRaw === "high" ? thinkRaw : "medium";
|
|
348
|
+
|
|
349
|
+
const askTool = process.env.AGY_ASK_TOOL !== undefined
|
|
350
|
+
? ["1", "true", "on"].includes(process.env.AGY_ASK_TOOL.toLowerCase())
|
|
351
|
+
: file.askTool ?? DEFAULTS.askTool;
|
|
352
|
+
|
|
353
|
+
const webTools = process.env.AGY_WEB_TOOLS !== undefined
|
|
354
|
+
? ["1", "true", "on"].includes(process.env.AGY_WEB_TOOLS.toLowerCase())
|
|
355
|
+
: file.webTools ?? DEFAULTS.webTools;
|
|
356
|
+
|
|
357
|
+
const bridgeRaw = (process.env.AGY_BRIDGE_TOOLS ?? file.bridgeTools ?? DEFAULTS.bridgeTools).toLowerCase();
|
|
358
|
+
const bridgeTools: BridgeTools =
|
|
359
|
+
bridgeRaw === "none" || bridgeRaw === "all" || bridgeRaw === "mcp"
|
|
360
|
+
? bridgeRaw
|
|
361
|
+
: DEFAULTS.bridgeTools;
|
|
362
|
+
|
|
363
|
+
// Extra long-window tool names for the bridge escalation (issue #6).
|
|
364
|
+
// Comma-separated in the env; junk entries and junk shapes are dropped,
|
|
365
|
+
// not fatal - loadConfig runs per bridge call and must never throw.
|
|
366
|
+
const longToolsRaw: unknown =
|
|
367
|
+
process.env.AGY_ESCALATE_LONG_TOOLS ?? file.escalateLongTools;
|
|
368
|
+
const longToolsParts: unknown[] = typeof longToolsRaw === "string"
|
|
369
|
+
? longToolsRaw.split(",")
|
|
370
|
+
: Array.isArray(longToolsRaw) ? longToolsRaw : [];
|
|
371
|
+
const escalateLongTools = longToolsParts
|
|
372
|
+
.filter((s): s is string => typeof s === "string")
|
|
373
|
+
.map((s) => s.trim())
|
|
374
|
+
.filter((s) => s.length > 0)
|
|
375
|
+
.slice(0, 32);
|
|
376
|
+
|
|
377
|
+
const digest = process.env.AGY_DIGEST !== undefined
|
|
378
|
+
? ["1", "true", "on"].includes(process.env.AGY_DIGEST.toLowerCase())
|
|
379
|
+
: file.digest ?? true;
|
|
380
|
+
|
|
381
|
+
const envSys = process.env.AGY_SYSTEM_PROMPT;
|
|
382
|
+
const systemPrompt = envSys !== undefined
|
|
383
|
+
? ["1", "true", "on"].includes(envSys.toLowerCase())
|
|
384
|
+
: file.systemPrompt ?? DEFAULTS.systemPrompt;
|
|
385
|
+
|
|
386
|
+
// Turn caps, minutes. Env wins over the file (same pattern as mode).
|
|
387
|
+
const turnTimeoutMin = parseCapMinutes(
|
|
388
|
+
process.env.AGY_TURN_TIMEOUT_MIN ?? file.turnTimeoutMin,
|
|
389
|
+
defaultTurnTimeoutMin(),
|
|
390
|
+
);
|
|
391
|
+
const inactivityTimeoutMin = parseCapMinutes(
|
|
392
|
+
process.env.AGY_INACTIVITY_TIMEOUT_MIN ?? file.inactivityTimeoutMin,
|
|
393
|
+
DEFAULTS.inactivityTimeoutMin,
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
// Approval gate (docs/TODO.md 2.5). Unknown values fall back to "auto"
|
|
397
|
+
// so a typo can never silently force the gate on.
|
|
398
|
+
const gateRaw = (process.env.AGY_APPROVALS ?? file.approvals?.gateMode ?? DEFAULTS.approvals.gateMode).toLowerCase();
|
|
399
|
+
const gateMode: GateMode =
|
|
400
|
+
gateRaw === "shadow" || gateRaw === "dedicated" || gateRaw === "off"
|
|
401
|
+
? gateRaw
|
|
402
|
+
: "auto";
|
|
403
|
+
const askRaw = (process.env.AGY_APPROVALS_MODE ?? file.approvals?.mode ?? DEFAULTS.approvals.mode).toLowerCase();
|
|
404
|
+
const gateAskMode: GateAskMode =
|
|
405
|
+
askRaw === "allow" || askRaw === "deny"
|
|
406
|
+
? askRaw
|
|
407
|
+
: "ask";
|
|
408
|
+
|
|
409
|
+
const fileAcp = (typeof file.acp === "object" && file.acp !== null ? file.acp : {}) as Partial<AcpConfig>;
|
|
410
|
+
// Unknown values fall back to "estimate" (same narrow-parse pattern as
|
|
411
|
+
// gateMode: a typo must never silently change behavior).
|
|
412
|
+
const usageRaw = String(
|
|
413
|
+
process.env.AGY_USAGE_ESTIMATE ?? fileAcp.usageEstimate ?? DEFAULTS.acp.usageEstimate,
|
|
414
|
+
).toLowerCase();
|
|
415
|
+
const usageEstimate: UsageEstimate =
|
|
416
|
+
usageRaw === "direct" || usageRaw === "off" ? usageRaw : "estimate";
|
|
417
|
+
const sessionTimeoutMs = parseSessionTimeoutMs(
|
|
418
|
+
process.env.AGY_ACP_SESSION_TIMEOUT_MS ?? fileAcp.sessionTimeoutMs,
|
|
419
|
+
DEFAULTS.acp.sessionTimeoutMs,
|
|
420
|
+
);
|
|
421
|
+
const envSessionRetry = process.env.AGY_ACP_SESSION_RETRY;
|
|
422
|
+
const sessionRetryOnTimeout = envSessionRetry !== undefined
|
|
423
|
+
? ["1", "true", "on"].includes(envSessionRetry.toLowerCase())
|
|
424
|
+
: fileAcp.sessionRetryOnTimeout === true;
|
|
425
|
+
const acp: AcpConfig = { usageEstimate, sessionTimeoutMs, sessionRetryOnTimeout };
|
|
426
|
+
|
|
427
|
+
// Custom agent for stream-json turns (--agent). Env wins over the file
|
|
428
|
+
// (same pattern as mode). Normalized (trim/cap/control-strip); an empty
|
|
429
|
+
// result means agy's default agent.
|
|
430
|
+
const agent = normalizeAgyAgentName(process.env.AGY_AGENT ?? file.agent);
|
|
431
|
+
|
|
432
|
+
return {
|
|
433
|
+
engine,
|
|
434
|
+
acp,
|
|
435
|
+
mode,
|
|
436
|
+
readOnly,
|
|
437
|
+
skipPermissions,
|
|
438
|
+
defaultModel,
|
|
439
|
+
defaultThinking,
|
|
440
|
+
askTool,
|
|
441
|
+
webTools,
|
|
442
|
+
bridgeTools,
|
|
443
|
+
escalateLongTools,
|
|
444
|
+
digest,
|
|
445
|
+
systemPrompt,
|
|
446
|
+
turnTimeoutMin,
|
|
447
|
+
inactivityTimeoutMin,
|
|
448
|
+
agent,
|
|
449
|
+
approvals: { gateMode, mode: gateAskMode },
|
|
450
|
+
patchCleanupNotified: file.patchCleanupNotified === true,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/** Narrow a raw engine string to the known set; anything unknown (incl. the
|
|
455
|
+
* pre-1.3.2 "sqlite" value) falls to the default engine. Shared by
|
|
456
|
+
* loadConfig's effective-engine resolution and saveConfig's persistence so
|
|
457
|
+
* the two can never drift. */
|
|
458
|
+
function narrowEngine(raw: string): Engine {
|
|
459
|
+
return raw === "acp" || raw === "stream-json" ? raw : DEFAULT_ENGINE;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** Atomic JSON write (temp + rename, 0600) shared by every config writer. */
|
|
463
|
+
function writeConfigJson(configPath: string, value: unknown): void {
|
|
464
|
+
const dir = path.dirname(configPath);
|
|
465
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
466
|
+
const tmp = `${configPath}.${process.pid}.tmp`;
|
|
467
|
+
try {
|
|
468
|
+
fs.writeFileSync(tmp, JSON.stringify(value, null, 2) + "\n", { mode: 0o600 });
|
|
469
|
+
fs.renameSync(tmp, configPath);
|
|
470
|
+
} catch (err) {
|
|
471
|
+
try {
|
|
472
|
+
fs.unlinkSync(tmp);
|
|
473
|
+
} catch {
|
|
474
|
+
/* nothing to clean */
|
|
475
|
+
}
|
|
476
|
+
throw err;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** Atomically persist a config patch (temp + rename). Merges onto the RAW
|
|
481
|
+
* FILE values, never loadConfig(): env overrides must not be baked into the
|
|
482
|
+
* file (AGY_READONLY=1 in the env would otherwise persist readOnly: true to
|
|
483
|
+
* disk on any unrelated save, outliving the env var). Nested objects are
|
|
484
|
+
* re-normalized to their known keys: a raw passthrough would resurrect
|
|
485
|
+
* legacy keys (acp.permissions) that loadConfig normalization drops. */
|
|
486
|
+
export type ConfigPatch = Partial<Omit<AgyConfig, "acp">> & { acp?: Partial<AcpConfig> };
|
|
487
|
+
|
|
488
|
+
export function saveConfig(patch: ConfigPatch, configFile: string = configPath()): AgyConfig {
|
|
489
|
+
const file = readConfigFile(configFile);
|
|
490
|
+
// Null-safe on nested objects: a hand-edited or legacy file can carry
|
|
491
|
+
// "acp": null; loadConfig tolerates it, so must saveConfig. Key presence
|
|
492
|
+
// triggers normalization (a null becomes the default shape, never null).
|
|
493
|
+
const fileAcp: Partial<AcpConfig> = file.acp && typeof file.acp === "object" ? file.acp : {};
|
|
494
|
+
const fileApprovals: Partial<GateConfig> = file.approvals && typeof file.approvals === "object" ? file.approvals : {};
|
|
495
|
+
// Engine persistence follows loadConfig's continuity rule minus env (env
|
|
496
|
+
// must never be baked into the file). A legacy file without an engine key
|
|
497
|
+
// persists "stream-json": the bare DEFAULTS spread below would otherwise
|
|
498
|
+
// write the acp default into an existing install's file on any unrelated
|
|
499
|
+
// save, switching an existing install to ACP on the next start.
|
|
500
|
+
const persistedEngine = patch.engine ?? file.engine
|
|
501
|
+
?? (fs.existsSync(configFile) ? "stream-json" : DEFAULT_ENGINE);
|
|
502
|
+
const { acp: patchAcp, ...restPatch } = patch;
|
|
503
|
+
const mergedAcp: AcpConfig = {
|
|
504
|
+
usageEstimate: patchAcp?.usageEstimate ?? fileAcp.usageEstimate ?? DEFAULTS.acp.usageEstimate,
|
|
505
|
+
sessionTimeoutMs: parseSessionTimeoutMs(
|
|
506
|
+
patchAcp?.sessionTimeoutMs ?? fileAcp.sessionTimeoutMs,
|
|
507
|
+
DEFAULTS.acp.sessionTimeoutMs,
|
|
508
|
+
),
|
|
509
|
+
sessionRetryOnTimeout: patchAcp?.sessionRetryOnTimeout ?? (fileAcp.sessionRetryOnTimeout === true),
|
|
510
|
+
};
|
|
511
|
+
const next: AgyConfig = {
|
|
512
|
+
...DEFAULTS,
|
|
513
|
+
...file,
|
|
514
|
+
...(file.approvals !== undefined
|
|
515
|
+
? { approvals: { gateMode: fileApprovals.gateMode ?? DEFAULTS.approvals.gateMode, mode: fileApprovals.mode ?? DEFAULTS.approvals.mode } }
|
|
516
|
+
: {}),
|
|
517
|
+
...restPatch,
|
|
518
|
+
acp: mergedAcp,
|
|
519
|
+
engine: narrowEngine(String(persistedEngine).toLowerCase()),
|
|
520
|
+
};
|
|
521
|
+
writeConfigJson(configFile, next);
|
|
522
|
+
return next;
|
|
523
|
+
}
|