@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.
Files changed (159) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +3 -3
  3. package/THIRD_PARTY_NOTICES.md +2 -23
  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 +12 -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/extensions/renderer/index.ts +7 -0
  64. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/agent-badge.ts +244 -0
  65. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +1 -1
  66. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +10 -3
  67. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/names.ts +18 -0
  68. package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
  69. package/node_modules/@herbertgao/pi-inline-skill-commands/README.md +18 -0
  70. package/node_modules/@herbertgao/pi-inline-skill-commands/package.json +1 -1
  71. package/node_modules/@herbertgao/pi-inline-skill-commands/src/index.ts +80 -0
  72. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +320 -102
  73. package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
  74. package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -30
  75. package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
  76. package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
  77. package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
  78. package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
  79. package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
  80. package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
  81. package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +27 -13
  82. package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
  83. package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
  84. package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +217 -41
  85. package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
  86. package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
  87. package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -93
  88. package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
  89. package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
  90. package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
  91. package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
  92. package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
  93. package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
  94. package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
  95. package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
  96. package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
  97. package/node_modules/pi-commandcode-provider/README.md +3 -2
  98. package/node_modules/pi-commandcode-provider/index.ts +120 -13
  99. package/node_modules/pi-commandcode-provider/package.json +4 -3
  100. package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
  101. package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
  102. package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
  103. package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
  104. package/package.json +12 -15
  105. package/node_modules/pi-antigravity/README.md +0 -298
  106. package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
  107. package/node_modules/pi-antigravity/package.json +0 -87
  108. package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
  109. package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
  110. package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
  111. package/node_modules/pi-antigravity/src/client/client.ts +0 -602
  112. package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
  113. package/node_modules/pi-antigravity/src/client/index.ts +0 -2
  114. package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
  115. package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
  116. package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
  117. package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
  118. package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
  119. package/node_modules/pi-antigravity/src/image/image.ts +0 -427
  120. package/node_modules/pi-antigravity/src/image/index.ts +0 -1
  121. package/node_modules/pi-antigravity/src/image/native.ts +0 -69
  122. package/node_modules/pi-antigravity/src/index.ts +0 -547
  123. package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
  124. package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
  125. package/node_modules/pi-antigravity/src/models/index.ts +0 -3
  126. package/node_modules/pi-antigravity/src/models/models.ts +0 -647
  127. package/node_modules/pi-antigravity/src/search/index.ts +0 -1
  128. package/node_modules/pi-antigravity/src/search/search.ts +0 -967
  129. package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
  130. package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
  131. package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
  132. package/node_modules/pi-antigravity/src/types/index.ts +0 -2
  133. package/node_modules/pi-antigravity/src/types/types.ts +0 -329
  134. package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
  135. package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
  136. package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
  137. package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
  138. package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
  139. package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
  140. package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
  141. package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
  142. package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
  143. package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
  144. package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
  145. package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
  146. package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
  147. package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
  148. package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
  149. package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
  150. package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
  151. package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
  152. package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
  153. package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
  154. package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
  155. package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
  156. package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
  157. package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
  158. package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
  159. package/node_modules/pi-antigravity/tsconfig.json +0 -21
@@ -1,217 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { getModelEnum } from "../models/models.js";
3
-
4
- export function antigravityEnv(name: string): string | undefined {
5
- return process.env[`ANTIGRAVITY_${name}`] || process.env[`NOAGY_${name}`];
6
- }
7
-
8
- /**
9
- * Whether a model-facing extra tool (`google_search`, `read_url_content`,
10
- * `generate_image`) is registered. `ANTIGRAVITY_NO_EXTRA_TOOLS=1` disables all of them;
11
- * `ANTIGRAVITY_NO_SEARCH_TOOL=1`, `ANTIGRAVITY_NO_FETCH_TOOL=1`, and
12
- * `ANTIGRAVITY_NO_IMAGE_TOOL=1` disable one, e.g. to avoid clashing with another provider.
13
- */
14
- export function isExtraToolEnabled(tool: "SEARCH" | "IMAGE" | "FETCH"): boolean {
15
- return antigravityEnv("NO_EXTRA_TOOLS") !== "1" && antigravityEnv(`NO_${tool}_TOOL`) !== "1";
16
- }
17
-
18
- /**
19
- * Defer extra tools when `ANTIGRAVITY_DEFER_TOOLS=1`.
20
- */
21
- export function extraToolExposure(): { exposure?: "deferred" } {
22
- return antigravityEnv("DEFER_TOOLS") === "1" ? { exposure: "deferred" } : {};
23
- }
24
-
25
- export function isRecord(value: unknown): value is Record<string, unknown> {
26
- return typeof value === "object" && value !== null && !Array.isArray(value);
27
- }
28
-
29
- export function asString(value: unknown): string | undefined {
30
- return typeof value === "string" && value ? value : undefined;
31
- }
32
-
33
- export function sanitizeText(text: unknown): string {
34
- const str = String(text ?? "");
35
- const toWellFormed = (str as unknown as { toWellFormed?: () => string }).toWellFormed;
36
- if (typeof toWellFormed === "function") {
37
- return toWellFormed.call(str);
38
- }
39
- return str.replace(
40
- /(?:[\uD800-\uDBFF](?![\uDC00-\uDFFF]))|(?:(?<![\uD800-\uDBFF])[\uDC00-\uDFFF])/g,
41
- "\uFFFD",
42
- );
43
- }
44
-
45
- export function escapeHtml(text: string): string {
46
- return text
47
- .replace(/&/g, "&amp;")
48
- .replace(/</g, "&lt;")
49
- .replace(/>/g, "&gt;")
50
- .replace(/"/g, "&quot;")
51
- .replace(/'/g, "&#39;");
52
- }
53
-
54
- export function escapeRegExp(text: string): string {
55
- return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
56
- }
57
-
58
- export function nowRequestId(): string {
59
- return antigravityRequestEnvelope("unknown", false).requestId;
60
- }
61
-
62
- /** Deterministic RFC 4122 v5 UUID from seed (survives restarts for the same session seed). */
63
- export function stableUuid(seed: string): string {
64
- const bytes = createHash("sha1").update(seed).digest().subarray(0, 16);
65
- bytes[6] = (bytes[6] & 0x0f) | 0x50;
66
- bytes[8] = (bytes[8] & 0x3f) | 0x80;
67
- const hex = [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
68
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
69
- }
70
-
71
- export type AntigravityEnvelopeOptions = {
72
- isClaude?: boolean;
73
- isNonGemini?: boolean;
74
- step?: number;
75
- lastStepIndex?: string;
76
- requestIndex?: number;
77
- userTurnIndex?: number;
78
- trajectoryId?: string;
79
- conversationId?: string;
80
- sessionId?: string;
81
- lastExecutionId?: string;
82
- };
83
-
84
- /** Signed int64 session ID: deterministic for nonempty seeds, random otherwise. */
85
- export function toInt64SessionId(seed?: string): string {
86
- if (seed?.trim()) {
87
- const s = seed.trim();
88
- if (/^-?\d+$/.test(s)) {
89
- const value = BigInt(s);
90
- if (value >= -(1n << 63n) && value <= (1n << 63n) - 1n) return s;
91
- }
92
- const hash = createHash("sha256").update(`antigravity:session:${s}`).digest();
93
- return String(new DataView(hash.buffer, hash.byteOffset, 8).getBigInt64(0, true));
94
- }
95
- const bytes = crypto.getRandomValues(new Uint8Array(8));
96
- return String(new DataView(bytes.buffer, bytes.byteOffset, 8).getBigInt64(0, true));
97
- }
98
-
99
- const sessionTrajectoryMap = new Map<
100
- string,
101
- { conversationId: string; trajectoryId: string; sessionId: string }
102
- >();
103
-
104
- /**
105
- * Resolve deterministic IDs from an explicit session ID or the first message's seed.
106
- * The fallback uses role, timestamp, and a 64-character content prefix: separate or
107
- * forked histories can alias, and compaction can change the seed. No cache behavior is guaranteed.
108
- */
109
- export function resolveSessionTrajectory(
110
- context?: {
111
- messages?: Array<{ role?: string; timestamp?: number; content?: unknown }>;
112
- },
113
- sessionId?: string,
114
- ): { conversationId: string; trajectoryId: string; sessionId: string } {
115
- if (sessionId?.trim()) {
116
- const seed = `session:${sessionId.trim()}`;
117
- let entry = sessionTrajectoryMap.get(seed);
118
- if (!entry) {
119
- entry = {
120
- conversationId: stableUuid(`antigravity:conv:${seed}`),
121
- trajectoryId: stableUuid(`antigravity:traj:${seed}`),
122
- sessionId: toInt64SessionId(sessionId),
123
- };
124
- sessionTrajectoryMap.set(seed, entry);
125
- if (sessionTrajectoryMap.size > 64) {
126
- const oldestKey = sessionTrajectoryMap.keys().next().value;
127
- if (oldestKey !== undefined) sessionTrajectoryMap.delete(oldestKey);
128
- }
129
- }
130
- return entry;
131
- }
132
-
133
- const firstMsg = context?.messages?.[0];
134
- if (!firstMsg) {
135
- return {
136
- conversationId: crypto.randomUUID(),
137
- trajectoryId: crypto.randomUUID(),
138
- sessionId: toInt64SessionId(),
139
- };
140
- }
141
- const contentSeed =
142
- typeof firstMsg.content === "string"
143
- ? firstMsg.content.slice(0, 64)
144
- : Array.isArray(firstMsg.content)
145
- ? JSON.stringify(firstMsg.content[0] ?? "").slice(0, 64)
146
- : "";
147
- const seed = `${firstMsg.role || "user"}:${firstMsg.timestamp || ""}:${contentSeed}`;
148
- let entry = sessionTrajectoryMap.get(seed);
149
- if (!entry) {
150
- entry = {
151
- conversationId: stableUuid(`antigravity:conv:${seed}`),
152
- trajectoryId: stableUuid(`antigravity:traj:${seed}`),
153
- sessionId: toInt64SessionId(seed),
154
- };
155
- sessionTrajectoryMap.set(seed, entry);
156
- if (sessionTrajectoryMap.size > 64) {
157
- const oldestKey = sessionTrajectoryMap.keys().next().value;
158
- if (oldestKey !== undefined) sessionTrajectoryMap.delete(oldestKey);
159
- }
160
- }
161
- return entry;
162
- }
163
-
164
- export function clearSessionTrajectoryMap(): void {
165
- sessionTrajectoryMap.clear();
166
- }
167
-
168
- /**
169
- * Build request metadata and model labels from legacy Claude flags or envelope options.
170
- * Supplied IDs are forwarded; absent IDs are generated. Execution labels appear after step 1.
171
- */
172
- export function antigravityRequestEnvelope(
173
- wireModelId: string,
174
- optionsOrIsClaude: boolean | AntigravityEnvelopeOptions = false,
175
- ): { requestId: string; sessionId: string; labels: Record<string, string> } {
176
- const options: AntigravityEnvelopeOptions =
177
- typeof optionsOrIsClaude === "boolean" ? { isClaude: optionsOrIsClaude } : optionsOrIsClaude;
178
-
179
- const isClaude = Boolean(options.isClaude);
180
- const isNonGemini = Boolean(options.isNonGemini || isClaude);
181
- const step = Math.max(1, options.step ?? 1);
182
- const lastStepIndex = options.lastStepIndex ?? String(Math.max(0, step - 1));
183
- const requestIndex = options.requestIndex ?? options.userTurnIndex ?? Math.max(0, step - 1);
184
- const agentId = options.conversationId || crypto.randomUUID();
185
- const trajectoryId = options.trajectoryId || crypto.randomUUID();
186
- const sessionId = options.sessionId || toInt64SessionId();
187
-
188
- const claudeLabel = isClaude ? "true" : "false";
189
- const nonGeminiLabel = isNonGemini ? "true" : "false";
190
-
191
- const labels: Record<string, string> = {
192
- last_step_index: lastStepIndex,
193
- request_id: `${trajectoryId}-${requestIndex}`,
194
- trajectory_id: trajectoryId,
195
- used_claude: claudeLabel,
196
- used_claude_conservative: claudeLabel,
197
- used_non_gemini_model: nonGeminiLabel,
198
- };
199
-
200
- const modelEnum = getModelEnum(wireModelId);
201
- if (modelEnum) {
202
- labels.model_enum = modelEnum;
203
- }
204
-
205
- // Pure agy CLI wire alignment: last_execution_id is the execution ID of the previous turn.
206
- // It is only present on subsequent turns (step > 1), never on the initial turn (step <= 1).
207
- if (step > 1) {
208
- labels.last_execution_id =
209
- options.lastExecutionId || stableUuid(`antigravity:exec:${trajectoryId}:${step - 1}`);
210
- }
211
-
212
- return {
213
- requestId: `agent/${agentId}/${Date.now()}/${trajectoryId}/${step}`,
214
- sessionId,
215
- labels,
216
- };
217
- }
@@ -1,83 +0,0 @@
1
- import { createDocument } from "@mixmark-io/domino";
2
- import { repairText } from "../utils/text.js";
3
-
4
- /** Work limits apply before the recursive DOM parser or converter sees a document. */
5
- export const MAX_DOCUMENT_CHARS = 2_000_000;
6
- const MAX_DOCUMENT_DEPTH = 128;
7
- export const MAX_DOCUMENT_NODES = 50_000;
8
- const VOID = new Set(
9
- "area base br col embed hr img input link meta param source track wbr".split(" "),
10
- );
11
- const TOKENS =
12
- /<!--[\s\S]*?(?:-->|$)|<(script|style|textarea|title|noscript|xmp|iframe|noembed|noframes|plaintext)\b[^>]*>[\s\S]*?(?:<\/\1\s*>|$)|<\/?([a-z][\w:-]*)\b(?:[^"'<>]|"[^"]*"|'[^']*')*>/gi;
13
-
14
- /** The page is beyond what the converter will take on; the source itself is fine. */
15
- export class DocumentLimitError extends Error {
16
- constructor(message: string) {
17
- super(message);
18
- this.name = "DocumentLimitError";
19
- }
20
- }
21
-
22
- /**
23
- * The parser accepts tag names such as `a<a` that the DOM later refuses to clone, which
24
- * would fail the whole read at conversion. Replace each with a span holding its children.
25
- */
26
- function neutralizeInvalidElements(document: Document): void {
27
- for (const element of Array.from(document.querySelectorAll("*"))) {
28
- try {
29
- document.createElement(element.localName);
30
- continue;
31
- } catch {
32
- // Invalid name: replace below.
33
- }
34
- const span = document.createElement("span");
35
- while (element.firstChild) span.appendChild(element.firstChild);
36
- element.parentNode?.replaceChild(span, element);
37
- }
38
- }
39
-
40
- /** Reject bounded-but-pathological input with an actionable page-level error. */
41
- export function parseDocument(source: string): Document {
42
- if (source.length > MAX_DOCUMENT_CHARS)
43
- throw new DocumentLimitError(
44
- "The page is too large to convert safely. Open it in a browser or request a smaller page.",
45
- );
46
- const stack: string[] = [];
47
- let nodes = 0;
48
- for (const match of source.matchAll(TOKENS)) {
49
- if (++nodes > MAX_DOCUMENT_NODES)
50
- throw new DocumentLimitError(
51
- "The page has too many elements to convert safely. Open it in a browser.",
52
- );
53
- const tag = match[2]?.toLowerCase();
54
- if (!tag || VOID.has(tag)) continue;
55
- if (match[0].startsWith("</")) {
56
- const index = stack.lastIndexOf(tag);
57
- if (index >= 0) stack.length = index;
58
- } else {
59
- // Optional end tags close a sibling and its descendants, not merely the
60
- // stack's top. Respect list/table boundaries so nested containers remain nested.
61
- const closeSibling = (names: string[], boundaries: string[]) => {
62
- const sibling = Math.max(...names.map((name) => stack.lastIndexOf(name)));
63
- const boundary = Math.max(-1, ...boundaries.map((name) => stack.lastIndexOf(name)));
64
- if (sibling > boundary) stack.length = sibling;
65
- };
66
- if (/^(?:p|div|section|article|main|h[1-6]|ul|ol|table|blockquote)$/.test(tag))
67
- closeSibling(["p"], []);
68
- if (tag === "li") closeSibling(["li"], ["ul", "ol"]);
69
- if (tag === "dt" || tag === "dd") closeSibling(["dt", "dd"], ["dl"]);
70
- if (tag === "tr") closeSibling(["tr"], ["table"]);
71
- if (tag === "td" || tag === "th") closeSibling(["td", "th"], ["tr"]);
72
- if (tag === "option") closeSibling(["option"], ["select", "datalist"]);
73
- stack.push(tag);
74
- if (stack.length > MAX_DOCUMENT_DEPTH)
75
- throw new DocumentLimitError(
76
- "The page is nested too deeply to convert safely. Open it in a browser.",
77
- );
78
- }
79
- }
80
- const document = createDocument(repairText(source));
81
- neutralizeInvalidElements(document);
82
- return document;
83
- }
@@ -1,24 +0,0 @@
1
- /** CommonMark fenced blocks, including blockquote containers. */
2
- export const FENCE_LINE = /^ {0,3}((?:>\s*)*)(`{3,}|~{3,})(.*)$/;
3
- export type Fence = { marker: string; length: number; prefix: string };
4
-
5
- export function advanceFence(open: Fence | undefined, line: string): Fence | undefined {
6
- const match = FENCE_LINE.exec(line);
7
- if (!match) return open;
8
- const [, prefix, delimiter, rest] = match;
9
- if (!open) {
10
- if (delimiter[0] === "`" && rest.includes("`")) return undefined;
11
- return { marker: delimiter[0], length: delimiter.length, prefix };
12
- }
13
- return delimiter[0] === open.marker &&
14
- delimiter.length >= open.length &&
15
- prefix === open.prefix &&
16
- !rest.trim()
17
- ? undefined
18
- : open;
19
- }
20
- export function unclosedFence(text: string): Fence | undefined {
21
- let open: Fence | undefined;
22
- for (const line of text.split("\n")) open = advanceFence(open, line);
23
- return open;
24
- }
@@ -1,97 +0,0 @@
1
- import type { WebFetchResult } from "./web-fetch.js";
2
- import { DEFAULT_WEB_FETCH_MAX_CHARS } from "./limits.js";
3
- import { METADATA_LIMITS } from "./metadata.js";
4
- import { cleanText, elideMiddle } from "../utils/text.js";
5
- import { redactSecrets } from "../utils/security.js";
6
-
7
- const sanitizeMetadataText = cleanText;
8
-
9
- /** Format the page header, with bounded fields and redacted URLs. */
10
- export function formatWebFetchHeader(result: WebFetchResult): string {
11
- const maxChars = result.maxChars ?? DEFAULT_WEB_FETCH_MAX_CHARS;
12
- // Provenance must fit inside the output budget, so a long URL cannot take it all.
13
- const headerBudget = Math.max(0, maxChars - Math.min(256, Math.floor(maxChars / 4)));
14
- const dropped = new Set<string>();
15
- const build = (urlLimit: number, titleLimit: number): string[] => {
16
- const text = (value: string | undefined, limit: number) =>
17
- sanitizeMetadataText(value === undefined ? undefined : redactSecrets(value), limit);
18
- const header = [
19
- "Page metadata (publisher claims):",
20
- `Title: ${text(result.title, titleLimit) ?? "Untitled page"}`,
21
- ];
22
- const add = (label: string, value: string | undefined) => {
23
- if (value === undefined || dropped.has(label)) return;
24
- header.push(`${label}: ${value}`);
25
- };
26
- add("Description", text(result.description, METADATA_LIMITS.description));
27
- add("Updated", text(result.updated, METADATA_LIMITS.updated));
28
- add("Author", text(result.author, METADATA_LIMITS.author));
29
- add("Published", text(result.published, METADATA_LIMITS.published));
30
- add("Language", text(result.language, METADATA_LIMITS.language));
31
- const url = (value: string) =>
32
- elideMiddle(sanitizeMetadataText(redactSecrets(value), 4_096) ?? "", urlLimit);
33
- if (result.representationUrl) header.push(`Representation: ${url(result.representationUrl)}`);
34
- if (!dropped.has("Retrieval") && result.attempts && result.attempts.length > 1) {
35
- const attempts = result.attempts.map(
36
- (attempt) =>
37
- `${attempt.stage ?? attempt.source}@${attempt.endpoint ? new URL(attempt.endpoint).hostname : "Google"}: ${text(attempt.outcome, 200) ?? ""}`,
38
- );
39
- header.push(`Retrieval: ${attempts.join(" → ")}`);
40
- }
41
- if (result.assessment && result.assessment !== "readable") {
42
- header.push(
43
- `Content assessment: ${result.assessment} (heuristic; source completeness does not establish article coverage).`,
44
- );
45
- }
46
- header.push("Retrieval provenance:");
47
- const requestedUrl = url(result.requestedUrl);
48
- const resolvedUrl = url(result.resolvedUrl);
49
- if (result.redirected || result.requestedUrl !== result.resolvedUrl)
50
- header.push(`Requested: ${requestedUrl}`);
51
- header.push(`Source: ${resolvedUrl} (${result.source === "live" ? "live" : "cache"})`);
52
- if (result.assessment === "empty" || result.assessment === "suspected-access-wall") {
53
- header.push(
54
- "Note: no reliable article was identified. Open the page in a browser or use another permitted source; do not keep retrying this URL.",
55
- );
56
- }
57
- if (result.assessment === "suspected-shell") {
58
- header.push(
59
- "Note: this appears to be a JavaScript-rendered page; this tool cannot render it. Open it in a browser.",
60
- );
61
- }
62
- if (result.partial === true) {
63
- header.push(
64
- result.content.trim()
65
- ? "Note: the crawler's copy ends mid-page, so some content may be missing."
66
- : "Note: the crawler's copy ends mid-page and holds no readable content.",
67
- );
68
- } else if (result.partial === null) {
69
- header.push(
70
- result.content.trim()
71
- ? "Note: the crawler's copy has no clear end marker, so completeness is unknown."
72
- : "Note: the crawler's copy has no clear end marker and holds no readable content.",
73
- );
74
- }
75
- for (const note of result.notes ?? []) add("Note", text(note, 300));
76
- return header;
77
- };
78
- let urlLimit = Math.max(64, Math.min(2_048, Math.floor(headerBudget / 4)));
79
- let titleLimit: number = METADATA_LIMITS.title;
80
- let header = build(urlLimit, titleLimit);
81
- // Optional metadata must not crowd provenance and the next captured range out.
82
- for (const label of ["Description", "Updated", "Author", "Published", "Language", "Retrieval"]) {
83
- if (header.join("\n").length + 7 <= headerBudget) break;
84
- dropped.add(label);
85
- header = build(urlLimit, titleLimit);
86
- }
87
- // A long URL must not crowd out the page content either.
88
- while (header.join("\n").length + 7 > headerBudget && urlLimit > 64) {
89
- urlLimit = Math.max(64, Math.floor(urlLimit / 2));
90
- header = build(urlLimit, titleLimit);
91
- }
92
- while (header.join("\n").length + 7 > headerBudget && titleLimit > 40) {
93
- titleLimit = Math.max(40, Math.floor(titleLimit / 2));
94
- header = build(urlLimit, titleLimit);
95
- }
96
- return `${header.join("\n")}\n\n---\n\n`;
97
- }
@@ -1,3 +0,0 @@
1
- export * from "./markdown.js";
2
- export * from "./save.js";
3
- export * from "./web-fetch.js";