@herbertgao/pi-extensions 2026.11.18 → 2026.11.20

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.
Files changed (177) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +5 -5
  3. package/THIRD_PARTY_NOTICES.md +3 -24
  4. package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +956 -0
  5. package/node_modules/{pi-antigravity → @estebanforge/pi-antigravity-bridge}/LICENSE +1 -1
  6. package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +240 -0
  7. package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +2117 -0
  8. package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +61 -0
  9. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/connection.ts +644 -0
  10. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/driver.ts +1043 -0
  11. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/events.ts +323 -0
  12. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/home.ts +145 -0
  13. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/jsonrpc.ts +243 -0
  14. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/setup.ts +107 -0
  15. package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/usage-estimate.ts +61 -0
  16. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agents.ts +64 -0
  17. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-install.ts +93 -0
  18. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-paths.ts +30 -0
  19. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-setup.ts +81 -0
  20. package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-version.ts +289 -0
  21. package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-detect.ts +161 -0
  22. package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-gate.ts +233 -0
  23. package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-hook.ts +325 -0
  24. package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts-ui.ts +88 -0
  25. package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts.ts +144 -0
  26. package/node_modules/@estebanforge/pi-antigravity-bridge/src/ask-tool.ts +1221 -0
  27. package/node_modules/@estebanforge/pi-antigravity-bridge/src/background-watch.ts +225 -0
  28. package/node_modules/@estebanforge/pi-antigravity-bridge/src/bridge-catalog.ts +197 -0
  29. package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +523 -0
  30. package/node_modules/@estebanforge/pi-antigravity-bridge/src/daily-log.ts +196 -0
  31. package/node_modules/@estebanforge/pi-antigravity-bridge/src/dialog-lock.ts +48 -0
  32. package/node_modules/@estebanforge/pi-antigravity-bridge/src/diff-render.ts +207 -0
  33. package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver-types.ts +168 -0
  34. package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver.ts +907 -0
  35. package/node_modules/@estebanforge/pi-antigravity-bridge/src/engine-picker.ts +160 -0
  36. package/node_modules/@estebanforge/pi-antigravity-bridge/src/frame-guard.ts +38 -0
  37. package/node_modules/@estebanforge/pi-antigravity-bridge/src/handoff-toast.ts +21 -0
  38. package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-registration.ts +376 -0
  39. package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-server.ts +618 -0
  40. package/node_modules/@estebanforge/pi-antigravity-bridge/src/models.ts +404 -0
  41. package/node_modules/@estebanforge/pi-antigravity-bridge/src/native-tools.ts +104 -0
  42. package/node_modules/@estebanforge/pi-antigravity-bridge/src/parked-turn.ts +125 -0
  43. package/node_modules/@estebanforge/pi-antigravity-bridge/src/patch-cleanup.ts +523 -0
  44. package/node_modules/@estebanforge/pi-antigravity-bridge/src/poll-fold.ts +55 -0
  45. package/node_modules/@estebanforge/pi-antigravity-bridge/src/prompt-images.ts +92 -0
  46. package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +2214 -0
  47. package/node_modules/@estebanforge/pi-antigravity-bridge/src/queued-messages.ts +152 -0
  48. package/node_modules/@estebanforge/pi-antigravity-bridge/src/quota-notice.ts +40 -0
  49. package/node_modules/@estebanforge/pi-antigravity-bridge/src/redact.ts +27 -0
  50. package/node_modules/@estebanforge/pi-antigravity-bridge/src/sessions.ts +197 -0
  51. package/node_modules/@estebanforge/pi-antigravity-bridge/src/skills.ts +207 -0
  52. package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-events.ts +161 -0
  53. package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-sanitizer.ts +180 -0
  54. package/node_modules/@estebanforge/pi-antigravity-bridge/src/subagent-roster.ts +245 -0
  55. package/node_modules/@estebanforge/pi-antigravity-bridge/src/sysprompt-agent.ts +130 -0
  56. package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks-ui.ts +90 -0
  57. package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks.ts +174 -0
  58. package/node_modules/@estebanforge/pi-antigravity-bridge/src/usage.ts +174 -0
  59. package/node_modules/@estebanforge/pi-antigravity-bridge/src/web-tools.ts +320 -0
  60. package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
  61. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +1 -1
  62. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +3 -1
  63. package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
  64. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +317 -105
  65. package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
  66. package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -36
  67. package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
  68. package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
  69. package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
  70. package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
  71. package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
  72. package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
  73. package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +20 -11
  74. package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
  75. package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
  76. package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +185 -44
  77. package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
  78. package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
  79. package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -116
  80. package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
  81. package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
  82. package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
  83. package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
  84. package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
  85. package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
  86. package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
  87. package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
  88. package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
  89. package/node_modules/pi-commandcode-provider/README.md +3 -2
  90. package/node_modules/pi-commandcode-provider/index.ts +120 -13
  91. package/node_modules/pi-commandcode-provider/package.json +4 -3
  92. package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
  93. package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
  94. package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
  95. package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
  96. package/node_modules/pi-typesafe/README.md +1 -1
  97. package/node_modules/pi-typesafe/dist/ask.js +6 -3
  98. package/node_modules/pi-typesafe/dist/auth.d.ts +31 -7
  99. package/node_modules/pi-typesafe/dist/auth.js +159 -55
  100. package/node_modules/pi-typesafe/dist/batch.d.ts +16 -2
  101. package/node_modules/pi-typesafe/dist/batch.js +62 -22
  102. package/node_modules/pi-typesafe/dist/calibrate.d.ts +38 -11
  103. package/node_modules/pi-typesafe/dist/calibrate.js +56 -24
  104. package/node_modules/pi-typesafe/dist/client.d.ts +13 -0
  105. package/node_modules/pi-typesafe/dist/client.js +67 -27
  106. package/node_modules/pi-typesafe/dist/errors.d.ts +20 -0
  107. package/node_modules/pi-typesafe/dist/errors.js +105 -2
  108. package/node_modules/pi-typesafe/dist/extension.d.ts +106 -0
  109. package/node_modules/pi-typesafe/dist/extension.js +206 -106
  110. package/node_modules/pi-typesafe/dist/index.d.ts +8 -8
  111. package/node_modules/pi-typesafe/dist/index.js +3 -3
  112. package/node_modules/pi-typesafe/dist/key-prompt.d.ts +20 -0
  113. package/node_modules/pi-typesafe/dist/key-prompt.js +23 -3
  114. package/node_modules/pi-typesafe/dist/login.d.ts +58 -1
  115. package/node_modules/pi-typesafe/dist/login.js +167 -13
  116. package/node_modules/pi-typesafe/dist/schema.d.ts +3 -0
  117. package/node_modules/pi-typesafe/dist/schema.js +47 -13
  118. package/node_modules/pi-typesafe/dist/ui.d.ts +2 -1
  119. package/node_modules/pi-typesafe/dist/usage.d.ts +53 -0
  120. package/node_modules/pi-typesafe/dist/usage.js +79 -40
  121. package/node_modules/pi-typesafe/package.json +3 -3
  122. package/package.json +12 -15
  123. package/node_modules/pi-antigravity/README.md +0 -298
  124. package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
  125. package/node_modules/pi-antigravity/package.json +0 -87
  126. package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
  127. package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
  128. package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
  129. package/node_modules/pi-antigravity/src/client/client.ts +0 -602
  130. package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
  131. package/node_modules/pi-antigravity/src/client/index.ts +0 -2
  132. package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
  133. package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
  134. package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
  135. package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
  136. package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
  137. package/node_modules/pi-antigravity/src/image/image.ts +0 -427
  138. package/node_modules/pi-antigravity/src/image/index.ts +0 -1
  139. package/node_modules/pi-antigravity/src/image/native.ts +0 -69
  140. package/node_modules/pi-antigravity/src/index.ts +0 -547
  141. package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
  142. package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
  143. package/node_modules/pi-antigravity/src/models/index.ts +0 -3
  144. package/node_modules/pi-antigravity/src/models/models.ts +0 -647
  145. package/node_modules/pi-antigravity/src/search/index.ts +0 -1
  146. package/node_modules/pi-antigravity/src/search/search.ts +0 -967
  147. package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
  148. package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
  149. package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
  150. package/node_modules/pi-antigravity/src/types/index.ts +0 -2
  151. package/node_modules/pi-antigravity/src/types/types.ts +0 -329
  152. package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
  153. package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
  154. package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
  155. package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
  156. package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
  157. package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
  158. package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
  159. package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
  160. package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
  161. package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
  162. package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
  163. package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
  164. package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
  165. package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
  166. package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
  167. package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
  168. package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
  169. package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
  170. package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
  171. package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
  172. package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
  173. package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
  174. package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
  175. package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
  176. package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
  177. package/node_modules/pi-antigravity/tsconfig.json +0 -21
@@ -0,0 +1,320 @@
1
+ // Web tools for Pi: agy_web_search + agy_read_url, backed by one-shot
2
+ // search-only `agy` runs. Off by default (config.webTools); their audience is
3
+ // sessions driven by NON-Antigravity providers - inside agy sessions the model
4
+ // already has search_web/read_url_content natively (live-probed 2026-09-23 on
5
+ // both engines).
6
+ //
7
+ // Each call spawns `agy --agent <temporary> --print <query> --mode plan
8
+ // --output-format stream-json` with a temporary agent restricted to
9
+ // search_web + read_url_content (bridge MCP inheritance off), then gates the
10
+ // answer on an observed allowed-tool step. Gate accepts both status spellings
11
+ // the CLI has shipped (driver.ts: "SUCCESS" live, "OK" older builds).
12
+ //
13
+ // Temp agent dirs live in the user-global ~/.gemini/config/agents (the only
14
+ // location agy 1.2.9 discovers; no --agent-dir flag exists). Normal cleanup is
15
+ // the `finally`; SIGKILL can orphan, so sweepStaleWebAgents() removes leftovers
16
+ // at registration - same hygiene doctrine as mcp-registration's pid sweep.
17
+
18
+ import { spawn } from "node:child_process";
19
+ import { randomBytes } from "node:crypto";
20
+ import { mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
21
+ import os from "node:os";
22
+ import path from "node:path";
23
+ import { Type } from "typebox";
24
+ import { redactText } from "./redact.js";
25
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
26
+
27
+ export const WEB_AGENT_PREFIX = "pi-bridge-web-";
28
+
29
+ const DEADLINE_MS = 120_000;
30
+ const MAX_OUTPUT_BYTES = 2 * 1024 * 1024;
31
+ const MAX_QUERY_CHARS = 2000;
32
+ const ALLOWED_TOOLS = new Set(["search_web", "read_url_content"]);
33
+ const ORPHAN_GRACE_MS = 24 * 60 * 60 * 1000;
34
+
35
+ /** ~/.gemini/config/agents - the directory agy scans for named agents. */
36
+ export function webAgentsRoot(): string {
37
+ return path.join(os.homedir(), ".gemini", "config", "agents");
38
+ }
39
+
40
+ /** Remove leftover pi-bridge agent dirs matching `prefix`: dead-pid markers
41
+ * always, and marker-less dirs only after a grace period (a live sibling
42
+ * process may be between mkdir and its pid write). Never touches foreign
43
+ * agent dirs. The ask-tool reuses this for its reviewer agents. */
44
+ export function sweepStaleWebAgents(
45
+ root: string = webAgentsRoot(),
46
+ now = Date.now(),
47
+ prefix: string = WEB_AGENT_PREFIX,
48
+ ): void {
49
+ let entries: string[];
50
+ try {
51
+ entries = readdirSync(root);
52
+ } catch {
53
+ return; // no agents dir yet: nothing to sweep
54
+ }
55
+ for (const entry of entries) {
56
+ if (!entry.startsWith(prefix)) continue;
57
+ try {
58
+ if (isStaleWebAgentDir(path.join(root, entry), now)) {
59
+ rmSync(path.join(root, entry), { recursive: true, force: true });
60
+ }
61
+ } catch {
62
+ // vanished mid-sweep: nothing to remove
63
+ }
64
+ }
65
+ }
66
+
67
+ /** Stale = a dead-pid marker, or no marker at all and older than the grace
68
+ * period (a live sibling may sit between mkdir and its pid write). */
69
+ function isStaleWebAgentDir(dir: string, now: number): boolean {
70
+ let raw = "";
71
+ try {
72
+ raw = readFileSync(path.join(dir, ".pid"), "utf8").trim();
73
+ } catch {
74
+ raw = ""; // no marker yet: decide by age
75
+ }
76
+ const pid = Number.parseInt(raw, 10);
77
+ if (Number.isInteger(pid) && pid > 0) return !pidAlive(pid);
78
+ try {
79
+ return now - statSync(dir).mtimeMs > ORPHAN_GRACE_MS;
80
+ } catch {
81
+ return true; // dir vanished mid-sweep
82
+ }
83
+ }
84
+
85
+ /** Best effort: a signal-able pid proves *a* live process, not the original
86
+ * owner; pid reuse can mask an orphan until the 24h age bound. Same residual
87
+ * as mcp-registration's sweep. */
88
+ function pidAlive(pid: number): boolean {
89
+ try {
90
+ process.kill(pid, 0);
91
+ return true;
92
+ } catch {
93
+ return false;
94
+ }
95
+ }
96
+
97
+ export type WebRunResult =
98
+ | { ok: true; response: string }
99
+ | { ok: false; error: string };
100
+
101
+ export interface WebRunOptions {
102
+ /** Query (agy_web_search) or URL-reading instruction (agy_read_url). */
103
+ prompt: string;
104
+ /** The single allowed tool whose DONE step the answer is gated on. */
105
+ gatedTool: "search_web" | "read_url_content";
106
+ /** Server binary; defaults to AGY_BIN or PATH, matching ask-tool. */
107
+ bin?: string;
108
+ /** Agents root override (tests); defaults to the user-global agy dir. */
109
+ agentsRoot?: string;
110
+ /** Working directory handed to agy. */
111
+ cwd?: string;
112
+ timeoutMs?: number;
113
+ signal?: AbortSignal;
114
+ log?: (event: string, data?: unknown, level?: "info" | "warn" | "error") => void;
115
+ }
116
+
117
+ /** agent.md for the one-shot web delegate: search-only, no inheritance. */
118
+ export function webAgentMd(name: string): string {
119
+ return `---\nname: ${name}\ndescription: Temporary Pi web delegate\nmainAgent: true\nsubagent: false\nmodel: inherit\nexcludeDefaultComponents: true\ninheritCustomizations: false\ninheritMcp: false\ncommandExecutionPolicy: auto\ntools:\n - search_web\n - read_url_content\nskills: []\nrules: []\nagents: []\nmcpServers: []\n---\n\nAnswer the user's query using search_web (and read_url_content when a page must be opened). Cite sources. Use no other tools.\n`;
120
+ }
121
+
122
+ /** One gated one-shot web run. Creates a unique restricted agent, streams the
123
+ * NDJSON frames, refuses answers with no observed allowed-tool step, and
124
+ * always removes the agent dir. */
125
+ export async function runWebAgent(opts: WebRunOptions): Promise<WebRunResult> {
126
+ const root = opts.agentsRoot ?? webAgentsRoot();
127
+ mkdirSync(root, { recursive: true });
128
+ // Nonce: two parallel tool calls in one process can share a millisecond;
129
+ // a shared dir would let one call's finally delete the other's agent.
130
+ const agentName = `${WEB_AGENT_PREFIX}${process.pid}-${Date.now().toString(36)}-${randomBytes(4).toString("hex")}`;
131
+ const agentDir = path.join(root, agentName);
132
+ mkdirSync(agentDir, { recursive: true, mode: 0o700 });
133
+ // commandExecutionPolicy stays at the live-validated "auto": the template's
134
+ // tools list has no command tool and plan mode blocks edits; an unvalidated
135
+ // stricter enum risks agent discovery failing outright.
136
+ writeFileSync(path.join(agentDir, "agent.md"), webAgentMd(agentName), {
137
+ mode: 0o600,
138
+ });
139
+ writeFileSync(path.join(agentDir, ".pid"), `${process.pid}\n`, { mode: 0o600 });
140
+
141
+ const bin = opts.bin ?? process.env.AGY_BIN ?? "agy";
142
+ const args = [
143
+ "--agent", agentName,
144
+ "--print", opts.prompt,
145
+ "--mode", "plan",
146
+ "--output-format", "stream-json",
147
+ "--disable-slash-commands",
148
+ ];
149
+ opts.log?.("web-run-start", { agent: agentName, gatedTool: opts.gatedTool });
150
+
151
+ const child = spawn(bin, args, { cwd: opts.cwd ?? process.cwd(), stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
152
+ const stop = () => {
153
+ if (!child.killed) child.kill();
154
+ };
155
+ const onAbort = () => stop();
156
+ opts.signal?.addEventListener("abort", onAbort, { once: true });
157
+ const timer = setTimeout(stop, opts.timeoutMs ?? DEADLINE_MS);
158
+
159
+ let buffer = "";
160
+ let bytes = 0;
161
+ let stderrTail = "";
162
+ let failed = "";
163
+ let allowedToolUsed = false;
164
+ let response = "";
165
+
166
+ try {
167
+ child.stdout?.on("data", (chunk: Buffer) => {
168
+ bytes += chunk.length;
169
+ if (bytes > MAX_OUTPUT_BYTES && !failed) {
170
+ failed = "Antigravity web run output exceeded the 2 MiB limit";
171
+ stop();
172
+ return;
173
+ }
174
+ buffer += chunk.toString("utf8");
175
+ let newline = buffer.indexOf("\n");
176
+ while (newline !== -1 && !failed) {
177
+ handleFrame(buffer.slice(0, newline));
178
+ buffer = buffer.slice(newline + 1);
179
+ newline = buffer.indexOf("\n");
180
+ }
181
+ });
182
+ child.stderr?.on("data", (chunk: Buffer) => {
183
+ stderrTail = (stderrTail + chunk.toString("utf8")).slice(-1000);
184
+ });
185
+ const code = await new Promise<number | null>((resolve, reject) => {
186
+ child.once("error", reject);
187
+ child.once("close", resolve);
188
+ });
189
+ if (!failed && opts.signal?.aborted) failed = "web run aborted";
190
+ if (!failed && code !== 0) failed = `agy exited with code ${code}${stderrTail ? `: ${redactText(stderrTail.trim()).slice(-300)}` : ""}`;
191
+ if (!failed && !allowedToolUsed) failed = `Antigravity returned an answer without an observed ${opts.gatedTool} step; refusing it as unverified`;
192
+ if (!failed && response === "") failed = "Antigravity web run produced no answer";
193
+ if (failed) {
194
+ opts.log?.("web-run-failed", { agent: agentName, error: failed }, "warn");
195
+ return { ok: false, error: failed };
196
+ }
197
+ opts.log?.("web-run-ok", { agent: agentName });
198
+ return { ok: true, response };
199
+ } catch (error) {
200
+ const message = error instanceof Error ? error.message : String(error);
201
+ opts.log?.("web-run-failed", { agent: agentName, error: message }, "warn");
202
+ return { ok: false, error: message };
203
+ } finally {
204
+ clearTimeout(timer);
205
+ opts.signal?.removeEventListener("abort", onAbort);
206
+ stop();
207
+ rmSync(agentDir, { recursive: true, force: true });
208
+ }
209
+
210
+ function handleFrame(line: string): void {
211
+ if (failed || !line.startsWith("{")) return;
212
+ let frame: unknown;
213
+ try {
214
+ frame = JSON.parse(line);
215
+ } catch {
216
+ return; // non-JSON chatter: ignore, matching the driver's line loop
217
+ }
218
+ if (typeof frame !== "object" || frame === null) return;
219
+ const record = frame as Record<string, unknown>;
220
+ if (record.event === "step_update" && typeof record.step_update === "object" && record.step_update !== null) {
221
+ const step = record.step_update as Record<string, unknown>;
222
+ if (step.step_type !== "tool" || typeof step.tool_name !== "string") return;
223
+ if (ALLOWED_TOOLS.has(step.tool_name)) {
224
+ // Drift tolerance: DONE today, OK on older builds (driver.ts:507).
225
+ if (step.state === "DONE" || step.state === "OK") allowedToolUsed = true;
226
+ } else if (step.state === "ACTIVE" || step.state === "DONE") {
227
+ failed = `Antigravity web agent used a disallowed tool: ${step.tool_name}`;
228
+ stop();
229
+ }
230
+ return;
231
+ }
232
+ if (record.event === "result" && typeof record.result === "object" && record.result !== null) {
233
+ const result = record.result as Record<string, unknown>;
234
+ if (result.status !== "SUCCESS" && result.status !== "OK") {
235
+ failed = `Antigravity web run reported status ${String(result.status)}`;
236
+ stop();
237
+ return;
238
+ }
239
+ if (typeof result.response === "string") response = result.response;
240
+ }
241
+ }
242
+ }
243
+
244
+ const QUOTA_NOTE =
245
+ "Each call spawns a one-shot Antigravity CLI process and consumes your Antigravity quota.";
246
+
247
+ const toolText = (text: string) => ({ content: [{ type: "text" as const, text }], details: {} });
248
+ const toolError = (text: string) => ({ content: [{ type: "text" as const, text }], isError: true as const, details: {} });
249
+
250
+ /** Register agy_web_search + agy_read_url. Call only when config.webTools is
251
+ * on - registration is the opt-in. */
252
+ export function registerWebTools(
253
+ pi: ExtensionAPI,
254
+ opts: { bin?: string; cwd?: string; timeoutMs?: number; log?: WebRunOptions["log"] } = {},
255
+ ): void {
256
+ sweepStaleWebAgents();
257
+
258
+ pi.registerTool({
259
+ name: "agy_web_search",
260
+ label: "Antigravity Web Search",
261
+ description: `Search the live web via Google Antigravity. Returns a short cited answer, not raw results. Use when the question needs current information. ${QUOTA_NOTE}`,
262
+ parameters: Type.Object({
263
+ query: Type.String({
264
+ description: `What to search for. Max ${MAX_QUERY_CHARS} characters.`,
265
+ }),
266
+ }),
267
+ async execute(_toolCallId, params, signal) {
268
+ const query = typeof params.query === "string" ? params.query.trim() : "";
269
+ if (query === "") return toolError("query must be a non-empty string");
270
+ if (query.length > MAX_QUERY_CHARS) return toolError(`query exceeds ${MAX_QUERY_CHARS} characters`);
271
+ const run = await runWebAgent({
272
+ prompt: query,
273
+ gatedTool: "search_web",
274
+ bin: opts.bin,
275
+ cwd: opts.cwd,
276
+ timeoutMs: opts.timeoutMs,
277
+ signal,
278
+ log: opts.log,
279
+ });
280
+ if (!run.ok) return toolError(`Web search failed: ${run.error}`);
281
+ return toolText(run.response);
282
+ },
283
+ });
284
+
285
+ pi.registerTool({
286
+ name: "agy_read_url",
287
+ label: "Antigravity Read URL",
288
+ description: `Fetch the content of a public http(s) URL via Google Antigravity and get its main content back as text. Use for pages you need to read. ${QUOTA_NOTE}`,
289
+ parameters: Type.Object({
290
+ url: Type.String({
291
+ description: "Absolute http(s) URL to read.",
292
+ }),
293
+ }),
294
+ async execute(_toolCallId, params, signal) {
295
+ const raw = typeof params.url === "string" ? params.url.trim() : "";
296
+ let url: URL;
297
+ try {
298
+ url = new URL(raw);
299
+ } catch {
300
+ return toolError("url must be an absolute http(s) URL");
301
+ }
302
+ // Allowlist: a URL parameter is untrusted input, and schemes like
303
+ // file: or javascript: must never reach the delegate.
304
+ if (url.protocol !== "http:" && url.protocol !== "https:") {
305
+ return toolError("only http and https URLs are supported");
306
+ }
307
+ const run = await runWebAgent({
308
+ prompt: `Read the content of ${url.toString()} with read_url_content and return its main content as plain text. Keep the structure (headings, lists) but drop navigation and ads.`,
309
+ gatedTool: "read_url_content",
310
+ bin: opts.bin,
311
+ cwd: opts.cwd,
312
+ timeoutMs: opts.timeoutMs,
313
+ signal,
314
+ log: opts.log,
315
+ });
316
+ if (!run.ok) return toolError(`URL read failed: ${run.error}`);
317
+ return toolText(run.response);
318
+ },
319
+ });
320
+ }
@@ -1,5 +1,11 @@
1
1
  # @herbertgao/pi-cc-extensions
2
2
 
3
+ ## 1.0.21-local.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#406](https://github.com/HerbertGao/pi-extensions/pull/406) [`364e65f`](https://github.com/HerbertGao/pi-extensions/commit/364e65f8a9e4bf7a9d79c58c0a54ebedd390dba4) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Fix input editor prefix rendering for Pi 1.6+ `render()` readonly line buffers.
8
+
3
9
  ## 1.0.21-local.3
4
10
 
5
11
  ### Patch Changes
@@ -1253,7 +1253,7 @@ export async function showCcstylePanel(
1253
1253
  render(width: number): string[] {
1254
1254
  const safeWidth = Math.max(0, Math.floor(width));
1255
1255
  const rule = renderPanelRule(theme, safeWidth);
1256
- const body = activeList().render(safeWidth);
1256
+ const body = [...activeList().render(safeWidth)];
1257
1257
  // Drop SettingsList's built-in hint — the panel footer below is the single source.
1258
1258
  while (body.length > 0 && body[body.length - 1] === "") body.pop();
1259
1259
  const listHintIndex = body.findIndex(
@@ -37,7 +37,9 @@ export class PromptEditor extends CustomEditor {
37
37
  userPaddingX = saved;
38
38
  self.paddingX = saved + PROMPT_COLS;
39
39
  try {
40
- const lines = super.render(width);
40
+ // Pi 1.6+:`render()` 可能返回缓存的 `readonly string[]`,不得原地改写父级缓冲区。
41
+ const parentLines = super.render(width);
42
+ const lines = [...parentLines];
41
43
  // 布局:lines[0] 顶边框,lines[1..n-2] 内容,lines[n-1] 底边框(autocomplete 在底边框后追加,
42
44
  // 首内容行恒为 index 1)。开头是 paddingX 个纯空格,前两列换成 ❯+空格,剩余 padding 保留;
43
45
  // 续行不动——Claude Code 行为。
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herbertgao/pi-cc-extensions",
3
- "version": "1.0.21-local.3",
3
+ "version": "1.0.21-local.4",
4
4
  "license": "MIT",
5
5
  "description": "A Pi productivity suite with Claude Code-style UI, context inspection, and agent/session references",
6
6
  "type": "module",