@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.
- package/CHANGELOG.md +18 -0
- package/README.md +5 -5
- package/THIRD_PARTY_NOTICES.md +3 -24
- 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 +6 -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/package.json +1 -1
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +317 -105
- package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -36
- 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 +20 -11
- 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 +185 -44
- 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 -116
- 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/node_modules/pi-typesafe/README.md +1 -1
- package/node_modules/pi-typesafe/dist/ask.js +6 -3
- package/node_modules/pi-typesafe/dist/auth.d.ts +31 -7
- package/node_modules/pi-typesafe/dist/auth.js +159 -55
- package/node_modules/pi-typesafe/dist/batch.d.ts +16 -2
- package/node_modules/pi-typesafe/dist/batch.js +62 -22
- package/node_modules/pi-typesafe/dist/calibrate.d.ts +38 -11
- package/node_modules/pi-typesafe/dist/calibrate.js +56 -24
- package/node_modules/pi-typesafe/dist/client.d.ts +13 -0
- package/node_modules/pi-typesafe/dist/client.js +67 -27
- package/node_modules/pi-typesafe/dist/errors.d.ts +20 -0
- package/node_modules/pi-typesafe/dist/errors.js +105 -2
- package/node_modules/pi-typesafe/dist/extension.d.ts +106 -0
- package/node_modules/pi-typesafe/dist/extension.js +206 -106
- package/node_modules/pi-typesafe/dist/index.d.ts +8 -8
- package/node_modules/pi-typesafe/dist/index.js +3 -3
- package/node_modules/pi-typesafe/dist/key-prompt.d.ts +20 -0
- package/node_modules/pi-typesafe/dist/key-prompt.js +23 -3
- package/node_modules/pi-typesafe/dist/login.d.ts +58 -1
- package/node_modules/pi-typesafe/dist/login.js +167 -13
- package/node_modules/pi-typesafe/dist/schema.d.ts +3 -0
- package/node_modules/pi-typesafe/dist/schema.js +47 -13
- package/node_modules/pi-typesafe/dist/ui.d.ts +2 -1
- package/node_modules/pi-typesafe/dist/usage.d.ts +53 -0
- package/node_modules/pi-typesafe/dist/usage.js +79 -40
- package/node_modules/pi-typesafe/package.json +3 -3
- 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,130 @@
|
|
|
1
|
+
// G10 delivery for the stream-json engine: staged system-prompt agent.
|
|
2
|
+
//
|
|
3
|
+
// agy's stream-json prompt path silently drops any turn past a ~25KB input
|
|
4
|
+
// cap (probed 2026-09-30, issue #2: status SUCCESS, empty response, zero
|
|
5
|
+
// usage, no error — and the dropped turn leaves the conversation permanently
|
|
6
|
+
// unresponsive to later input). The pi system prompt block used to ride the
|
|
7
|
+
// first prompt of every fresh conversation and routinely crossed that cap,
|
|
8
|
+
// killing the whole session. It now stages as an agy agent file discovered
|
|
9
|
+
// under ~/.gemini/config/agents and passed via --agent: the CLI reads agent
|
|
10
|
+
// files from disk, off the prompt line, so the cap never applies.
|
|
11
|
+
//
|
|
12
|
+
// Frontmatter keeps agy's DEFAULTS on purpose (no excludeDefaultComponents,
|
|
13
|
+
// no inheritMcp override): provider sessions need the bridge MCP config for
|
|
14
|
+
// G9 round-trips. Two deliberate exceptions. The tools list: omitting tools
|
|
15
|
+
// reads as "read-only defaults" upstream, not "all tools", which stripped
|
|
16
|
+
// write/edit/command from carrier sessions (issue #13; agy appends the
|
|
17
|
+
// resource/MCP tools itself, so G9 round-trips ride call_mcp_tool
|
|
18
|
+
// regardless). The subagent keys: agent-file presence already suppresses
|
|
19
|
+
// agy's native subagent tools (probed 2026-10-20, issue #7), and declaring
|
|
20
|
+
// it makes the suppression explicit instead of relying on the accident
|
|
21
|
+
// (whether the keys themselves mask, apart from presence, is unattributed).
|
|
22
|
+
// Contrast the ask-tool reviewer agent, which strips everything for
|
|
23
|
+
// sandboxing.
|
|
24
|
+
//
|
|
25
|
+
// Lifecycle: one agent dir per DISTINCT body (content-addressed by sha256);
|
|
26
|
+
// two conversations with different system prompts in one process stage two
|
|
27
|
+
// dirs and never overwrite each other, so a driver respawn mid-conversation
|
|
28
|
+
// always reloads that conversation's own instructions. Same body -> same dir
|
|
29
|
+
// (write-once; identical bytes are never rewritten). The name stays stable
|
|
30
|
+
// across the turns of a conversation so the driver's profile comparison
|
|
31
|
+
// never recycles on "agent" drift. The .pid marker lets sweepStaleWebAgents
|
|
32
|
+
// prune orphans (same doctrine as the web delegates and the ask-tool
|
|
33
|
+
// reviewer).
|
|
34
|
+
|
|
35
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
36
|
+
import fs from "node:fs";
|
|
37
|
+
import os from "node:os";
|
|
38
|
+
import path from "node:path";
|
|
39
|
+
import { sweepStaleWebAgents } from "./web-tools.js";
|
|
40
|
+
|
|
41
|
+
export const SYS_AGENT_PREFIX = "pi-bridge-sys-";
|
|
42
|
+
|
|
43
|
+
/** AGY_AGENTS_ROOT override for tests and sandboxes (same contract as the
|
|
44
|
+
* ask-tool reviewer root). */
|
|
45
|
+
export function syspromptAgentsRoot(): string {
|
|
46
|
+
return process.env.AGY_AGENTS_ROOT ?? path.join(os.homedir(), ".gemini", "config", "agents");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** agent.md for the carrier. The body is the pi system prompt composed by the
|
|
50
|
+
* provider (preamble + transcript system prompt + tool-priority note). */
|
|
51
|
+
export function syspromptAgentMd(name: string, body: string): string {
|
|
52
|
+
return [
|
|
53
|
+
"---",
|
|
54
|
+
`name: ${name}`,
|
|
55
|
+
// Quoted value: it contains ': ', invalid inside an unquoted plain
|
|
56
|
+
// scalar — agy then silently drops the agent (issue #5).
|
|
57
|
+
"description: \"Pi bridge system-prompt carrier: pi operating instructions plus project AGENTS.md context\"",
|
|
58
|
+
"mainAgent: true",
|
|
59
|
+
"model: inherit",
|
|
60
|
+
"subagent: false",
|
|
61
|
+
"agents: []",
|
|
62
|
+
"tools:",
|
|
63
|
+
// Block style, not flow: the web delegates (web-tools.ts) prove agy
|
|
64
|
+
// parses this shape; flow style is only proven in the issue report.
|
|
65
|
+
" - read_file",
|
|
66
|
+
" - edit_file",
|
|
67
|
+
" - write_file",
|
|
68
|
+
" - run_command",
|
|
69
|
+
" - manage_task",
|
|
70
|
+
" - search_web",
|
|
71
|
+
"---",
|
|
72
|
+
"",
|
|
73
|
+
body,
|
|
74
|
+
"",
|
|
75
|
+
].join("\n");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface Staged {
|
|
79
|
+
root: string;
|
|
80
|
+
name: string;
|
|
81
|
+
dir: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Content-addressed staging cache: body sha256 -> staged dir. Two
|
|
85
|
+
* conversations with different system prompts in one process must never
|
|
86
|
+
* share a carrier file (a rewrite would leak one conversation's instructions
|
|
87
|
+
* into the other's respawned agy process). */
|
|
88
|
+
const stagedByHash = new Map<string, Staged>();
|
|
89
|
+
|
|
90
|
+
function bodyHash(body: string): string {
|
|
91
|
+
return createHash("sha256").update(body).digest("hex").slice(0, 12);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Stage the carrier agent with `body` as its instructions. Content-addressed:
|
|
95
|
+
* the same body reuses its dir (no rewrite), a new body gets a fresh dir.
|
|
96
|
+
* Returns the agent name for --agent, or null when staging failed — the
|
|
97
|
+
* caller then falls back to the legacy inline prompt block, where the
|
|
98
|
+
* silent-drop guard keeps the cap risk visible. */
|
|
99
|
+
export function stageSyspromptAgent(
|
|
100
|
+
body: string,
|
|
101
|
+
opts: { agentsRoot?: string } = {},
|
|
102
|
+
): string | null {
|
|
103
|
+
try {
|
|
104
|
+
const root = opts.agentsRoot ?? syspromptAgentsRoot();
|
|
105
|
+
const hash = bodyHash(body);
|
|
106
|
+
const cached = stagedByHash.get(hash);
|
|
107
|
+
if (cached && cached.root === root) return cached.name;
|
|
108
|
+
sweepStaleWebAgents(root, Date.now(), SYS_AGENT_PREFIX);
|
|
109
|
+
fs.mkdirSync(root, { recursive: true });
|
|
110
|
+
// Nonce: two pi processes staging the same body must not fight over one
|
|
111
|
+
// dir; the pid plus nonce keeps every staging attempt self-contained.
|
|
112
|
+
const name = `${SYS_AGENT_PREFIX}${hash}-${process.pid}-${Date.now().toString(36)}-${randomBytes(4).toString("hex")}`;
|
|
113
|
+
const dir = path.join(root, name);
|
|
114
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
115
|
+
fs.writeFileSync(path.join(dir, ".pid"), `${process.pid}\n`, { mode: 0o600 });
|
|
116
|
+
fs.writeFileSync(path.join(dir, "agent.md"), syspromptAgentMd(name, body), {
|
|
117
|
+
mode: 0o600,
|
|
118
|
+
});
|
|
119
|
+
const entry: Staged = { root, name, dir };
|
|
120
|
+
stagedByHash.set(hash, entry);
|
|
121
|
+
return entry.name;
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Test hook: forget the staging cache without touching the filesystem. */
|
|
128
|
+
export function resetSyspromptAgentForTests(): void {
|
|
129
|
+
stagedByHash.clear();
|
|
130
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// /agy tasks overlay: SelectList over one conversation's background tasks.
|
|
2
|
+
//
|
|
3
|
+
// UI mirrors the artifacts browser (engine-picker pattern). Watch-only:
|
|
4
|
+
// enter closes (the list IS the dashboard), r rescans, esc closes. Tails
|
|
5
|
+
// live in the command form: /agy tasks tail <id> — a log tail is chat
|
|
6
|
+
// content, not overlay content.
|
|
7
|
+
|
|
8
|
+
import type { ExtensionUIContext } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { DynamicBorder } from "@earendil-works/pi-coding-agent";
|
|
10
|
+
import { Container, type SelectItem, SelectList, Spacer, Text } from "@earendil-works/pi-tui";
|
|
11
|
+
import { dialogBlocked } from "@estebanforge/pi-tui-dialogs";
|
|
12
|
+
import type { AgyTask } from "./tasks.js";
|
|
13
|
+
|
|
14
|
+
export type TasksBrowserAction = { type: "rescan" } | { type: "close" };
|
|
15
|
+
|
|
16
|
+
export function taskItems(tasks: AgyTask[]): SelectItem[] {
|
|
17
|
+
return tasks.map((t) => {
|
|
18
|
+
const when = new Date(t.modifiedMs);
|
|
19
|
+
const stamp = `${String(when.getHours()).padStart(2, "0")}:${String(when.getMinutes()).padStart(2, "0")}`;
|
|
20
|
+
const state = t.livenessKnown ? (t.active ? "ACTIVE" : "idle") : "liveness?";
|
|
21
|
+
return {
|
|
22
|
+
value: String(t.id),
|
|
23
|
+
label: `#${t.id} · ${state}`,
|
|
24
|
+
description: `${humanBytes(t.bytes)} · last write ${stamp}`,
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function humanBytes(n: number): string {
|
|
30
|
+
if (n < 1024) return `${n}B`;
|
|
31
|
+
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)}KB`;
|
|
32
|
+
return `${(n / (1024 * 1024)).toFixed(1)}MB`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Render the overlay. Resolves rescan (caller re-lists and reopens) or
|
|
36
|
+
* close. */
|
|
37
|
+
export async function showTasksBrowser(
|
|
38
|
+
ctx: ExtensionUIContext,
|
|
39
|
+
tasks: AgyTask[],
|
|
40
|
+
livenessKnown: boolean,
|
|
41
|
+
): Promise<TasksBrowserAction> {
|
|
42
|
+
const items = taskItems(tasks);
|
|
43
|
+
return ctx.custom<TasksBrowserAction>((tui, theme, _keybindings, done) => {
|
|
44
|
+
const container = new Container();
|
|
45
|
+
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
46
|
+
container.addChild(
|
|
47
|
+
new Text(theme.fg("accent", theme.bold(`Antigravity tasks (${tasks.length})`)), 1, 0),
|
|
48
|
+
);
|
|
49
|
+
if (!livenessKnown) {
|
|
50
|
+
container.addChild(
|
|
51
|
+
new Text(theme.fg("warning", "lsof not found; liveness unknown (install lsof for ACTIVE/idle)"), 1, 0),
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
container.addChild(new Spacer(1));
|
|
55
|
+
|
|
56
|
+
const list = new SelectList(items, Math.min(items.length, 12), {
|
|
57
|
+
selectedPrefix: (t: string) => theme.fg("accent", t),
|
|
58
|
+
selectedText: (t: string) => theme.fg("accent", t),
|
|
59
|
+
description: (t: string) => theme.fg("muted", t),
|
|
60
|
+
scrollInfo: (t: string) => theme.fg("dim", t),
|
|
61
|
+
noMatch: (t: string) => theme.fg("warning", t),
|
|
62
|
+
});
|
|
63
|
+
list.onSelect = () => done({ type: "close" });
|
|
64
|
+
list.onCancel = () => done({ type: "close" });
|
|
65
|
+
container.addChild(list);
|
|
66
|
+
|
|
67
|
+
container.addChild(new Spacer(1));
|
|
68
|
+
container.addChild(
|
|
69
|
+
new Text(theme.fg("dim", "↑↓ navigate · r rescan · esc close · /agy tasks tail <id> for a log"), 1, 0),
|
|
70
|
+
);
|
|
71
|
+
container.addChild(new DynamicBorder((s: string) => theme.fg("accent", s)));
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
render: (width: number) => container.render(width),
|
|
75
|
+
invalidate: () => container.invalidate(),
|
|
76
|
+
handleInput: (data: string) => {
|
|
77
|
+
if (data.trim().toLowerCase() === "r") {
|
|
78
|
+
done({ type: "rescan" });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
list.handleInput(data);
|
|
82
|
+
tui.requestRender();
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}, {
|
|
86
|
+
overlay: true,
|
|
87
|
+
overlayOptions: { anchor: "center" as const, width: 72, maxHeight: "85%" as const, margin: 1 },
|
|
88
|
+
blocked: dialogBlocked(`Antigravity tasks (${tasks.length})`),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Read-only task dashboard over one agy conversation's background tasks
|
|
2
|
+
// (.system_generated/tasks/task-<N>.log under the brain dir).
|
|
3
|
+
//
|
|
4
|
+
// WATCH-ONLY by design. The stream RPC never reports agy's background
|
|
5
|
+
// tasks, so visibility comes from this filesystem scan; liveness comes
|
|
6
|
+
// from one batched lsof call over every log path (per-file lsof would
|
|
7
|
+
// fork-storm). Ownership is deliberately NOT resolved: modern agy pipes
|
|
8
|
+
// task output through itself, so the process holding a log open proves
|
|
9
|
+
// nothing about which spawned job it is, and we never kill what we cannot
|
|
10
|
+
// prove we own. A task is "active" while any process holds its log open
|
|
11
|
+
// (a reader counts too — cat/less/tail -f will light it up; the dashboard
|
|
12
|
+
// is a watch, not a fact), "idle" otherwise; when lsof is missing,
|
|
13
|
+
// liveness is unknown and the dashboard says so instead of guessing.
|
|
14
|
+
|
|
15
|
+
import { readdir, stat } from "node:fs/promises";
|
|
16
|
+
import { spawn } from "node:child_process";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import { readTranscriptTail } from "./parked-turn.js";
|
|
19
|
+
|
|
20
|
+
const TASK_LOG_RE = /^task-(\d+)\.log$/;
|
|
21
|
+
const MAX_TASKS = 128;
|
|
22
|
+
const LSOFT_TIMEOUT_MS = 5_000;
|
|
23
|
+
const LSOFT_CAP_BYTES = 1024 * 1024;
|
|
24
|
+
export const TASK_TAIL_BYTES = 2 * 1024;
|
|
25
|
+
|
|
26
|
+
export interface AgyTask {
|
|
27
|
+
id: number;
|
|
28
|
+
logPath: string;
|
|
29
|
+
bytes: number;
|
|
30
|
+
modifiedMs: number;
|
|
31
|
+
/** Any process currently holds the log open. */
|
|
32
|
+
active: boolean;
|
|
33
|
+
/** false when lsof is unavailable (liveness could not be checked). */
|
|
34
|
+
livenessKnown: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Scan task logs under one conversation dir. Missing dirs return []
|
|
38
|
+
* (tasks are created on demand). Newest activity first, capped. */
|
|
39
|
+
export async function scanAgyTasks(conversationDir: string): Promise<AgyTask[]> {
|
|
40
|
+
const dir = path.join(conversationDir, ".system_generated", "tasks");
|
|
41
|
+
let entries;
|
|
42
|
+
try {
|
|
43
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
44
|
+
} catch {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
const tasks: AgyTask[] = [];
|
|
48
|
+
for (const entry of entries) {
|
|
49
|
+
if (!entry.isFile()) continue;
|
|
50
|
+
const match = TASK_LOG_RE.exec(entry.name);
|
|
51
|
+
if (!match) continue;
|
|
52
|
+
const logPath = path.join(dir, entry.name);
|
|
53
|
+
try {
|
|
54
|
+
const stats = await stat(logPath);
|
|
55
|
+
tasks.push({
|
|
56
|
+
id: Number(match[1]),
|
|
57
|
+
logPath,
|
|
58
|
+
bytes: stats.size,
|
|
59
|
+
modifiedMs: stats.mtimeMs,
|
|
60
|
+
active: false,
|
|
61
|
+
livenessKnown: false,
|
|
62
|
+
});
|
|
63
|
+
} catch {
|
|
64
|
+
continue; // vanished mid-scan
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
tasks.sort((a, b) => b.modifiedMs - a.modifiedMs || b.id - a.id);
|
|
68
|
+
return tasks.slice(0, MAX_TASKS);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Parse `lsof -nP -Fpn` output into path -> pids holding it open.
|
|
72
|
+
* Format: `p<PID>` starts a process block; `n<PATH>` marks a file of the
|
|
73
|
+
* current process. Pure; exported for tests.
|
|
74
|
+
* Known gap: a log unlinked while held open gets an "n<path> (deleted)"
|
|
75
|
+
* line whose key never equals the scanned path, so that holder is
|
|
76
|
+
* invisible and the task reads idle. Left as-is: stripping the suffix
|
|
77
|
+
* would attribute a rotation survivor to the REPLACEMENT file at the
|
|
78
|
+
* same path, which is a worse lie. */
|
|
79
|
+
export function parseLsofOwners(output: string): Map<string, Set<number>> {
|
|
80
|
+
const owners = new Map<string, Set<number>>();
|
|
81
|
+
let pid: number | undefined;
|
|
82
|
+
for (const line of output.split("\n")) {
|
|
83
|
+
if (line.startsWith("p")) {
|
|
84
|
+
const parsed = Number(line.slice(1));
|
|
85
|
+
pid = Number.isInteger(parsed) && parsed > 0 ? parsed : undefined;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (!line.startsWith("n")) continue;
|
|
89
|
+
if (pid === undefined) continue;
|
|
90
|
+
const filePath = line.slice(1);
|
|
91
|
+
if (!filePath) continue;
|
|
92
|
+
let set = owners.get(filePath);
|
|
93
|
+
if (!set) owners.set(filePath, (set = new Set()));
|
|
94
|
+
set.add(pid);
|
|
95
|
+
}
|
|
96
|
+
return owners;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
type SpawnRaw = (cmd: string, args: string[], timeoutMs: number, capBytes: number) => Promise<string>;
|
|
100
|
+
|
|
101
|
+
/** One batched lsof over every task log. Resolves undefined when lsof is
|
|
102
|
+
* missing or failed (spawn error / timeout); resolves "" when lsof ran
|
|
103
|
+
* and nothing is open (its normal exit-1-empty answer). */
|
|
104
|
+
async function lsofOwners(
|
|
105
|
+
logPaths: string[],
|
|
106
|
+
spawnRaw: SpawnRaw = defaultSpawnRaw,
|
|
107
|
+
): Promise<string | undefined> {
|
|
108
|
+
if (logPaths.length === 0) return "";
|
|
109
|
+
try {
|
|
110
|
+
return await spawnRaw("lsof", ["-nP", "-Fpn", ...logPaths], LSOFT_TIMEOUT_MS, LSOFT_CAP_BYTES);
|
|
111
|
+
} catch {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function defaultSpawnRaw(
|
|
117
|
+
cmd: string,
|
|
118
|
+
args: string[],
|
|
119
|
+
timeoutMs: number,
|
|
120
|
+
capBytes: number,
|
|
121
|
+
): Promise<string> {
|
|
122
|
+
return new Promise<string>((resolve, reject) => {
|
|
123
|
+
const child = spawn(cmd, args, { stdio: ["ignore", "pipe", "ignore"] });
|
|
124
|
+
let out = "";
|
|
125
|
+
let settled = false;
|
|
126
|
+
const done = (fn: () => void) => {
|
|
127
|
+
if (settled) return;
|
|
128
|
+
settled = true;
|
|
129
|
+
clearTimeout(timer);
|
|
130
|
+
fn();
|
|
131
|
+
};
|
|
132
|
+
const timer = setTimeout(() => {
|
|
133
|
+
child.kill("SIGKILL");
|
|
134
|
+
done(() => reject(new Error(`${cmd} timed out`)));
|
|
135
|
+
}, timeoutMs);
|
|
136
|
+
child.stdout.on("data", (d: Buffer) => {
|
|
137
|
+
if (out.length + d.length > capBytes) {
|
|
138
|
+
try {
|
|
139
|
+
child.kill("SIGKILL");
|
|
140
|
+
} catch {
|
|
141
|
+
/* already gone */
|
|
142
|
+
}
|
|
143
|
+
done(() => reject(new Error(`${cmd} output cap exceeded`)));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
out += d.toString("utf8");
|
|
147
|
+
});
|
|
148
|
+
child.on("error", (err) => done(() => reject(err)));
|
|
149
|
+
child.on("close", () => done(() => resolve(out)));
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Scan plus liveness in one call. Never throws; a missing or failed lsof
|
|
154
|
+
* leaves livenessKnown false rather than guessing. */
|
|
155
|
+
export async function listAgyTasks(
|
|
156
|
+
conversationDir: string,
|
|
157
|
+
spawnRaw?: SpawnRaw,
|
|
158
|
+
): Promise<AgyTask[]> {
|
|
159
|
+
const tasks = await scanAgyTasks(conversationDir);
|
|
160
|
+
if (tasks.length === 0) return tasks;
|
|
161
|
+
const rawOwners = await lsofOwners(tasks.map((t) => t.logPath), spawnRaw);
|
|
162
|
+
const owners = rawOwners === undefined ? undefined : parseLsofOwners(rawOwners);
|
|
163
|
+
for (const task of tasks) {
|
|
164
|
+
task.livenessKnown = owners !== undefined;
|
|
165
|
+
task.active = (owners?.get(task.logPath)?.size ?? 0) > 0;
|
|
166
|
+
}
|
|
167
|
+
return tasks;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Last bytes of a task log for the tail command. Empty string on any
|
|
171
|
+
* error — tails are best-effort views, not facts. */
|
|
172
|
+
export async function tailAgyTaskLog(logPath: string): Promise<string> {
|
|
173
|
+
return readTranscriptTail(logPath, TASK_TAIL_BYTES);
|
|
174
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Subscription quota view: `agy --print /usage --output-format json`.
|
|
2
|
+
//
|
|
3
|
+
// agy has no usage subcommand; the /usage slash command inside print mode
|
|
4
|
+
// returns the same structured payload the agy TUI panel shows and burns
|
|
5
|
+
// zero tokens (live-verified agy 1.2.10: status SUCCESS, usage all zeros,
|
|
6
|
+
// command.data.groups[] with window "weekly" | "5h" buckets carrying
|
|
7
|
+
// remaining_fraction and reset_time). Print mode answers in ~10s on this
|
|
8
|
+
// machine, so the spawn budget here is its own 30s, not the 8s discovery
|
|
9
|
+
// watchdog shared by models/agents.
|
|
10
|
+
//
|
|
11
|
+
// The quota is account-level: it reads the agy CLI's Google identity, so it
|
|
12
|
+
// is equally true for stream-json turns and ACP-server turns (same account)
|
|
13
|
+
// — but a pure-ACP install without the CLI cannot fetch it; the command
|
|
14
|
+
// layer fails closed with a pointer instead of a raw error.
|
|
15
|
+
|
|
16
|
+
import { spawnAgyRaw } from "./models.js";
|
|
17
|
+
|
|
18
|
+
export const USAGE_TIMEOUT_MS = 30_000;
|
|
19
|
+
const USAGE_CAP_BYTES = 1024 * 1024;
|
|
20
|
+
|
|
21
|
+
export interface AgyQuotaBucket {
|
|
22
|
+
id?: string;
|
|
23
|
+
name: string;
|
|
24
|
+
/** agy's window tag: "weekly" | "5h" (tolerant of future tags). */
|
|
25
|
+
window: string;
|
|
26
|
+
remainingFraction: number;
|
|
27
|
+
resetTime?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface AgyQuotaGroup {
|
|
31
|
+
name: string;
|
|
32
|
+
description?: string;
|
|
33
|
+
buckets: AgyQuotaBucket[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface AgyQuotaReport {
|
|
37
|
+
groups: AgyQuotaGroup[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type Json = Record<string, unknown>;
|
|
41
|
+
|
|
42
|
+
const asObject = (v: unknown): Json | undefined => (v !== null && typeof v === "object" ? (v as Json) : undefined);
|
|
43
|
+
const asString = (v: unknown): string | undefined => (typeof v === "string" ? v : undefined);
|
|
44
|
+
const asNumber = (v: unknown): number | undefined => (typeof v === "number" && Number.isFinite(v) ? v : undefined);
|
|
45
|
+
const firstString = (o: Json, keys: string[]): string | undefined => {
|
|
46
|
+
for (const k of keys) {
|
|
47
|
+
const v = asString(o[k]);
|
|
48
|
+
if (v !== undefined) return v;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function parseBucket(v: unknown): AgyQuotaBucket | undefined {
|
|
54
|
+
const o = asObject(v);
|
|
55
|
+
if (!o) return undefined;
|
|
56
|
+
const remaining = asNumber(o.remaining_fraction) ?? asNumber(o.remainingFraction) ?? asNumber(o.remaining);
|
|
57
|
+
const name = firstString(o, ["name", "id"]);
|
|
58
|
+
if (remaining === undefined || name === undefined) return undefined;
|
|
59
|
+
return {
|
|
60
|
+
id: asString(o.id),
|
|
61
|
+
name,
|
|
62
|
+
window: firstString(o, ["window"]) ?? "unknown",
|
|
63
|
+
remainingFraction: Math.max(0, Math.min(1, remaining)),
|
|
64
|
+
resetTime: firstString(o, ["reset_time", "resetTime"]),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function parseGroup(v: unknown): AgyQuotaGroup | undefined {
|
|
69
|
+
const o = asObject(v);
|
|
70
|
+
if (!o) return undefined;
|
|
71
|
+
const name = asString(o.name);
|
|
72
|
+
if (name === undefined) return undefined;
|
|
73
|
+
const buckets = Array.isArray(o.buckets)
|
|
74
|
+
? o.buckets.map(parseBucket).filter((b): b is AgyQuotaBucket => b !== undefined)
|
|
75
|
+
: [];
|
|
76
|
+
return { name, description: asString(o.description), buckets };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Parse the /usage JSON payload. Tolerant: unwraps a stream-json result
|
|
80
|
+
* envelope when present (print mode does not send one), accepts snake_case
|
|
81
|
+
* and camelCase field aliases, clamps fractions. Throws a short reason on
|
|
82
|
+
* any structural mismatch — callers render it, never stack it. */
|
|
83
|
+
export function parseAgyUsageJson(text: string): AgyQuotaReport {
|
|
84
|
+
let payload: Json | undefined;
|
|
85
|
+
try {
|
|
86
|
+
payload = asObject(JSON.parse(text));
|
|
87
|
+
} catch {
|
|
88
|
+
throw new Error("response was not JSON");
|
|
89
|
+
}
|
|
90
|
+
if (!payload) throw new Error("response was not an object");
|
|
91
|
+
// Print mode answers at the top level; if some future agy shells the
|
|
92
|
+
// command through its stream instead, the wrapper is the same event-keyed
|
|
93
|
+
// NDJSON grammar the driver already parses (see fake-agy-bin frames:
|
|
94
|
+
// {"event":"init",...}), so unwrap {event:"result", result:{...}}.
|
|
95
|
+
const inner = payload.event !== undefined ? asObject(payload.result) : payload;
|
|
96
|
+
if (!inner) throw new Error("result envelope carried no result object");
|
|
97
|
+
const status = (firstString(inner, ["status"]) ?? "").toUpperCase();
|
|
98
|
+
if (status !== "" && status !== "SUCCESS" && status !== "OK") {
|
|
99
|
+
throw new Error(`agy reported status ${status}`);
|
|
100
|
+
}
|
|
101
|
+
const command = asObject(inner.command);
|
|
102
|
+
if (command === undefined || command.name !== "usage") {
|
|
103
|
+
throw new Error("payload is not a /usage command result");
|
|
104
|
+
}
|
|
105
|
+
const data = asObject(command.data) ?? asObject(inner.data);
|
|
106
|
+
const rawGroups = data !== undefined && Array.isArray(data.groups) ? data.groups : undefined;
|
|
107
|
+
if (rawGroups === undefined) throw new Error("no quota groups in payload");
|
|
108
|
+
const groups = rawGroups.map(parseGroup).filter((g): g is AgyQuotaGroup => g !== undefined);
|
|
109
|
+
if (groups.length === 0) throw new Error("no quota groups returned");
|
|
110
|
+
return { groups };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Fetch quota through the CLI. Undefined on any fetch failure (missing
|
|
114
|
+
* binary, non-zero exit, timeout, cap) — same degrade-to-empty contract as
|
|
115
|
+
* the model catalog; the caller renders the difference. The spawn watchdog
|
|
116
|
+
* runs 5s past agy's own --print-timeout so the CLI's clean timeout-exit
|
|
117
|
+
* always wins the race over our SIGKILL. */
|
|
118
|
+
export async function fetchAgyQuota(binary: string): Promise<AgyQuotaReport | undefined> {
|
|
119
|
+
const raw = await spawnAgyRaw(
|
|
120
|
+
binary,
|
|
121
|
+
["--print", "/usage", "--output-format", "json", "--print-timeout", `${Math.ceil(USAGE_TIMEOUT_MS / 1000)}s`],
|
|
122
|
+
USAGE_TIMEOUT_MS + 5_000,
|
|
123
|
+
USAGE_CAP_BYTES,
|
|
124
|
+
);
|
|
125
|
+
if (raw === "") return undefined;
|
|
126
|
+
try {
|
|
127
|
+
return parseAgyUsageJson(raw);
|
|
128
|
+
} catch {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// --- rendering ---------------------------------------------------------------
|
|
134
|
+
|
|
135
|
+
/** 20-segment remaining bar. */
|
|
136
|
+
export function quotaBar(fraction: number): string {
|
|
137
|
+
const filled = Math.round(Math.max(0, Math.min(1, fraction)) * 20);
|
|
138
|
+
return `${"█".repeat(filled)}${"░".repeat(20 - filled)}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Clock-style reset label: "resets 19:53" today, else "resets 09:10 on 4 Sep". */
|
|
142
|
+
export function resetLabel(resetTime: string, now: Date): string {
|
|
143
|
+
const at = new Date(resetTime);
|
|
144
|
+
if (Number.isNaN(at.getTime())) return "";
|
|
145
|
+
const hhmm = `${String(at.getHours()).padStart(2, "0")}:${String(at.getMinutes()).padStart(2, "0")}`;
|
|
146
|
+
const sameDay =
|
|
147
|
+
at.getFullYear() === now.getFullYear() &&
|
|
148
|
+
at.getMonth() === now.getMonth() &&
|
|
149
|
+
at.getDate() === now.getDate();
|
|
150
|
+
if (sameDay) return `resets ${hhmm}`;
|
|
151
|
+
const day = at.getDate();
|
|
152
|
+
const mon = at.toLocaleString("en", { month: "short" });
|
|
153
|
+
return `resets ${hhmm} on ${day} ${mon}`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const WINDOW_RANK: Record<string, number> = { "5h": 0, weekly: 1 };
|
|
157
|
+
|
|
158
|
+
/** Full report text: per group, 5h bucket before weekly (the window users
|
|
159
|
+
* hit first), name labeled bar with percent and reset time. */
|
|
160
|
+
export function formatAgyQuotaReport(report: AgyQuotaReport, now: Date = new Date()): string {
|
|
161
|
+
const lines: string[] = ["Antigravity quota (account-level, both engines)"];
|
|
162
|
+
for (const group of report.groups) {
|
|
163
|
+
lines.push("", group.name);
|
|
164
|
+
const buckets = [...group.buckets].sort(
|
|
165
|
+
(a, b) => (WINDOW_RANK[a.window] ?? 9) - (WINDOW_RANK[b.window] ?? 9),
|
|
166
|
+
);
|
|
167
|
+
for (const bucket of buckets) {
|
|
168
|
+
const pct = Math.round(bucket.remainingFraction * 100);
|
|
169
|
+
const reset = bucket.resetTime !== undefined ? ` · ${resetLabel(bucket.resetTime, now)}` : "";
|
|
170
|
+
lines.push(` ${bucket.name}: ${quotaBar(bucket.remainingFraction)} ${pct}%${reset}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return lines.join("\n");
|
|
174
|
+
}
|