@herbertgao/pi-extensions 2026.11.18 → 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 (151) hide show
  1. package/CHANGELOG.md +12 -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 +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/package.json +11 -14
  97. package/node_modules/pi-antigravity/README.md +0 -298
  98. package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
  99. package/node_modules/pi-antigravity/package.json +0 -87
  100. package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
  101. package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
  102. package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
  103. package/node_modules/pi-antigravity/src/client/client.ts +0 -602
  104. package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
  105. package/node_modules/pi-antigravity/src/client/index.ts +0 -2
  106. package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
  107. package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
  108. package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
  109. package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
  110. package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
  111. package/node_modules/pi-antigravity/src/image/image.ts +0 -427
  112. package/node_modules/pi-antigravity/src/image/index.ts +0 -1
  113. package/node_modules/pi-antigravity/src/image/native.ts +0 -69
  114. package/node_modules/pi-antigravity/src/index.ts +0 -547
  115. package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
  116. package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
  117. package/node_modules/pi-antigravity/src/models/index.ts +0 -3
  118. package/node_modules/pi-antigravity/src/models/models.ts +0 -647
  119. package/node_modules/pi-antigravity/src/search/index.ts +0 -1
  120. package/node_modules/pi-antigravity/src/search/search.ts +0 -967
  121. package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
  122. package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
  123. package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
  124. package/node_modules/pi-antigravity/src/types/index.ts +0 -2
  125. package/node_modules/pi-antigravity/src/types/types.ts +0 -329
  126. package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
  127. package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
  128. package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
  129. package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
  130. package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
  131. package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
  132. package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
  133. package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
  134. package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
  135. package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
  136. package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
  137. package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
  138. package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
  139. package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
  140. package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
  141. package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
  142. package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
  143. package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
  144. package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
  145. package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
  146. package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
  147. package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
  148. package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
  149. package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
  150. package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
  151. package/node_modules/pi-antigravity/tsconfig.json +0 -21
@@ -1,35 +0,0 @@
1
- # Reader guarantees
2
-
3
- The reader uses Google's crawler. It does not contact the origin directly, execute page scripts, download files, extract PDFs, or reconstruct missing article text. A closed HTML document or a complete saved page does not prove full article coverage.
4
-
5
- ## Contract and regression checks
6
-
7
- Run `yarn check` for the offline gate. The two reader scripts are included in TypeScript, ESLint, Prettier, and the default test chain.
8
-
9
- | Guarantee | Regression check | Owner |
10
- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ----------------------------------------- |
11
- | Unsafe caller URLs are rejected before credential lookup or progress. Search uses the same URL predicate, plus a best-effort DNS filter before contacting origins. | `scenarioGuards`; foundations URL policy cases; search citations tests | `utils/address.ts` |
12
- | URL credentials and recognized credential carriers are redacted on rendered surfaces. Ordinary diagnostic values and JSON structure survive. Exact caller/service URL echoes in page content are redacted before the page is shown or saved. Arbitrary secrets in page text are not promised filtered. | `scenarioSecrets`; foundations redaction and JSON cases | `utils/security.ts`, `web-fetch.ts` |
13
- | Malformed credentials cannot appear in parser errors or retained causes. | Foundations credential cases | `client/client.ts` |
14
- | Third-party text has valid UTF-16. Metadata is bounded and single-line; page bodies retain their line structure. | Foundations text, metadata, and body cases | `utils/text.ts` |
15
- | Relative redirects resolve normally. Explicit private, credential-bearing, or non-HTTP destinations fail closed. Only destinations reported by Google are visible; intermediate redirects and remote DNS are not independently checked. | `scenarioRedirects`; foundations URL policy | `web-fetch.ts` |
16
- | One shared ten-second network deadline and at most ten Google requests bound retrieval. Endpoint failover is transport-only. The caller's abort is respected. | `scenarioAlternateOnSecondEndpoint`; deadline and abort cases | `web-fetch.ts` |
17
- | Recovery retains a useful original when live or optional representation reads fail. At most one publisher representation URL is selected. | `scenarioRecovery`, `scenarioAlternate`, `scenarioPdf` | `web-fetch.ts` |
18
- | HTML work is bounded before parsing: 2,000,000 characters, 50,000 markup tokens, 128 nested elements. Script strings and comments do not count as nested markup. Independent blocks avoid repeated prefix joins. | Foundations size, node, depth, script/comment, and many-block cases | `document.ts`, `markdown.ts` |
19
- | Inspection uses an owned DOM, substantive content regions, and body evidence for access-wall judgments. A heading alone does not prove a wall or a JavaScript shell. | Foundations inspection and real-page fixtures; `scenarioStatusArticle` | `inspect.ts`, `markdown.ts` |
20
- | XML, SVG, Markdown, and text are not silently emptied as HTML. PDF refusal uses the reported media type, URL suffix, or line-start signature rather than prose mentioning a signature. | Foundations media cases; `scenarioDetection`, `scenarioPdf` | `media.ts`, `markdown.ts`, `web-fetch.ts` |
21
- | Source completeness, content assessment, and output truncation remain separate. Publisher metadata is labeled as publisher claims. Omitted publisher sections are noted. | `scenarioTruncatedCopy`; foundations MDN cases | `inspect.ts`, `mdn.ts`, `web-fetch.ts` |
22
- | Returned text plus serialized details share the configured character cap. Provenance and the saved-page footer count too. Small budgets can omit older attempt details; the omission count is explicit and doctor retains the bounded full history. | `scenarioReadablePage`, `scenarioBudget`, `scenarioLongFence`; live smoke cap checks | Feature entrypoint and formatter |
23
- | A page that does not fit is saved whole to a private temp file named in the answer and in `details.fullOutputPath`. A budget too small to answer leaves no file behind, and a failed save is reported in the answer without losing the page. Pages beyond the conversion limits are refused with Google's unconverted HTML saved. Raw mode returns the crawled source whatever its size and saves it without the provenance header. | `scenarioReadablePage`, `scenarioBudgetFailure`, `scenarioUnconverted` | `save.ts`, feature entrypoint |
24
- | Cut-off or unavailable Wikipedia articles and raw GitHub files recover only through a copy that names the requested article or file. Advertised, MDN, Wikipedia and GitHub copies share one representation contract. | `scenarioWikipedia`, `scenarioGithubRaw` | `sites.ts`, `web-fetch.ts` |
25
- | Successful degraded reads and failures leave sanitized diagnostics. | Deadline/degraded diagnostics cases | Reader and `diagnostics/` |
26
-
27
- Search caches expire after ten minutes and skip known secret-bearing keys or values. Client lookup caches use token digests rather than raw access tokens as keys.
28
-
29
- The response stream is capped at 5,000,000 bytes. Limits are refusals, not claims that a page is complete.
30
-
31
- ## Live check
32
-
33
- After `/login antigravity`, run `yarn smoke:fetch`. It exercises Example.com, GitHub Docs, and an old MDN URL, checks the complete output cap, and checks that a saved page can be read without network or credentials. Wrong page text is a failure. Explicit retrieval failures explaining a degraded copy and an unobserved canonical alias are warnings. Upstream availability warnings produce exit code 2; an alias-only warning does not. Exit code 2 means live coverage was insufficient; a passing offline gate does not replace this check.
34
-
35
- The saved fixture data comes from the existing main-branch corpus. Its provenance is listed in `scripts/fixtures/web-fetch/README.md`. The branch's registered-tool suite remains the implementation contract; main's incompatible reader suite is not imported.
@@ -1,87 +0,0 @@
1
- {
2
- "name": "pi-antigravity",
3
- "version": "0.14.0",
4
- "description": "Personal Antigravity / Cloud Code Assist provider for Pi Coding Agent",
5
- "author": "Rahul Arya",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/Rahularya01/pi-antigravity.git"
10
- },
11
- "homepage": "https://github.com/Rahularya01/pi-antigravity#readme",
12
- "bugs": {
13
- "url": "https://github.com/Rahularya01/pi-antigravity/issues"
14
- },
15
- "type": "module",
16
- "main": "./src/index.ts",
17
- "keywords": [
18
- "pi-package",
19
- "pi-extension",
20
- "antigravity",
21
- "google",
22
- "oauth",
23
- "provider"
24
- ],
25
- "files": [
26
- "LICENSE",
27
- "README.md",
28
- "docs/reader-guarantees.md",
29
- "src",
30
- "tsconfig.json"
31
- ],
32
- "packageManager": "yarn@4.18.0+sha512.fcb8716fe7cd0eece141ffc18b92193a9df9204c1ba83189c288835223fc0bbe64af473bab0d5e9927a7daeb5caf2bb07eb2787cc9338ca040ea125f2a1f2f7e",
33
- "engines": {
34
- "node": ">=22.19.0"
35
- },
36
- "scripts": {
37
- "typecheck": "tsc --noEmit",
38
- "lint": "eslint src scripts/test-web-fetch.ts scripts/test-reader-foundations.ts scripts/smoke-fetch-policy.ts",
39
- "lint:fix": "eslint src --fix",
40
- "format": "prettier --write .",
41
- "format:check": "prettier --check .",
42
- "security-check": "node scripts/run-ts.mjs scripts/security-check.ts",
43
- "test": "node scripts/run-ts.mjs scripts/test-sanitize-text.ts && node scripts/run-ts.mjs scripts/test-model-routing.ts && node scripts/run-ts.mjs scripts/test-model-discovery.ts && node scripts/run-ts.mjs scripts/test-usage-formatter.ts && node scripts/run-ts.mjs scripts/test-model-pricing.ts && node scripts/run-ts.mjs scripts/test-stream-sse.ts && node scripts/run-ts.mjs scripts/test-stream-header-deadline.ts && node scripts/run-ts.mjs scripts/test-http-proxy.ts && node scripts/run-ts.mjs scripts/test-oauth-fetch.ts && node scripts/run-ts.mjs scripts/test-image-gen.ts && node scripts/run-ts.mjs scripts/test-native-images.ts && node scripts/run-ts.mjs scripts/test-transcript-context.ts && node scripts/run-ts.mjs scripts/test-accounts.ts && node scripts/run-ts.mjs scripts/test-search.ts && node scripts/run-ts.mjs scripts/test-search-citations.ts && node scripts/run-ts.mjs scripts/test-web-fetch.ts && node scripts/run-ts.mjs scripts/test-reader-foundations.ts && node scripts/run-ts.mjs scripts/test-extra-tools-toggle.ts && node scripts/run-ts.mjs scripts/test-fetch-tool-toggle.ts && node scripts/run-ts.mjs scripts/test-provider-registration.ts && node scripts/run-ts.mjs scripts/test-stream-recovery.ts && node scripts/run-ts.mjs scripts/test-enterprise-and-capacity.ts",
44
- "smoke:fetch": "node scripts/run-ts.mjs scripts/smoke-web-fetch.mjs",
45
- "smoke:tools": "node scripts/run-ts.mjs scripts/smoke-tool-schema.ts",
46
- "smoke:models": "node scripts/run-ts.mjs scripts/smoke-all-models.mjs",
47
- "audit": "yarn npm audit --environment production --recursive && yarn npm audit --severity high --all --recursive",
48
- "check": "yarn typecheck && yarn lint && yarn format:check && yarn security-check && yarn test && yarn audit"
49
- },
50
- "pi": {
51
- "extensions": [
52
- "./src/index.ts",
53
- "./src/features/google-search.ts",
54
- "./src/features/read-url-content.ts",
55
- "./src/features/generate-image.ts"
56
- ]
57
- },
58
- "peerDependencies": {
59
- "@earendil-works/pi-ai": "*",
60
- "@earendil-works/pi-coding-agent": "*",
61
- "typebox": "*"
62
- },
63
- "devDependencies": {
64
- "@earendil-works/pi-ai": "^1.5.0",
65
- "@earendil-works/pi-coding-agent": "^1.5.0",
66
- "@eslint/js": "^10.0.1",
67
- "@types/node": "^26.6.2",
68
- "@types/turndown": "^5.0.6",
69
- "eslint": "^10.11.0",
70
- "eslint-config-prettier": "^10.1.8",
71
- "globals": "^17.7.0",
72
- "prettier": "^3.9.8",
73
- "typebox": "^1.3.27",
74
- "typescript": "^6.0.3",
75
- "typescript-eslint": "^8.64.0"
76
- },
77
- "dependencies": {
78
- "@mixmark-io/domino": "^2.2.0",
79
- "turndown": "^7.2.4",
80
- "turndown-plugin-gfm": "^1.0.2",
81
- "undici": "^8.12.3"
82
- },
83
- "resolutions": {
84
- "undici": "8.12.3",
85
- "minimatch": "11.0.3"
86
- }
87
- }
@@ -1,327 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { chmodSync, existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
3
- import { homedir } from "node:os";
4
- import { join } from "node:path";
5
- import type { OAuthCredentials } from "@earendil-works/pi-ai";
6
- import { defaultProjectId } from "../client/client.js";
7
- import type { AntigravityApiKey, AntigravityOAuthCredentials } from "../types/types.js";
8
- import { refreshAntigravityToken } from "./oauth.js";
9
-
10
- const ACCOUNTS_FILE = "antigravity-accounts.json";
11
- const AUTH_FILE = "auth.json";
12
- const REFRESH_SKEW_MS = 5 * 60 * 1000;
13
-
14
- export type StoredAccount = AntigravityOAuthCredentials & {
15
- accountId: string;
16
- addedAt: number;
17
- lastUsedAt: number;
18
- };
19
-
20
- type AccountsFile = {
21
- version: 1;
22
- activeAccountId?: string;
23
- accounts: Record<string, StoredAccount>;
24
- };
25
-
26
- export type AccountSummary = {
27
- accountId: string;
28
- email?: string;
29
- active: boolean;
30
- lastUsedAt: number;
31
- };
32
-
33
- function agentDir(): string {
34
- return process.env.PI_CODING_AGENT_DIR || join(homedir(), ".pi", "agent");
35
- }
36
-
37
- function accountsPath(): string {
38
- return join(agentDir(), ACCOUNTS_FILE);
39
- }
40
-
41
- function authPath(): string {
42
- return join(agentDir(), AUTH_FILE);
43
- }
44
-
45
- function readJsonObject(path: string): Record<string, unknown> | undefined {
46
- if (!existsSync(path)) return undefined;
47
- try {
48
- const parsed: unknown = JSON.parse(readFileSync(path, "utf8"));
49
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return undefined;
50
- return parsed as Record<string, unknown>;
51
- } catch {
52
- return undefined;
53
- }
54
- }
55
-
56
- function writePrivateJson(path: string, value: unknown): void {
57
- const tempPath = `${path}.${process.pid}.tmp`;
58
- writeFileSync(tempPath, `${JSON.stringify(value, null, 2)}\n`, { encoding: "utf8", mode: 0o600 });
59
- chmodSync(tempPath, 0o600);
60
- renameSync(tempPath, path);
61
- chmodSync(path, 0o600);
62
- }
63
-
64
- function emptyStore(): AccountsFile {
65
- return { version: 1, accounts: {} };
66
- }
67
-
68
- function isStoredAccount(value: unknown): value is StoredAccount {
69
- if (!value || typeof value !== "object") return false;
70
- const account = value as Partial<StoredAccount>;
71
- return typeof account.refresh === "string" && account.refresh.length > 0;
72
- }
73
-
74
- function normalizeStore(value: Record<string, unknown> | undefined): AccountsFile {
75
- if (!value || value.version !== 1 || !value.accounts || typeof value.accounts !== "object") {
76
- return emptyStore();
77
- }
78
- const accounts: Record<string, StoredAccount> = {};
79
- for (const [key, raw] of Object.entries(value.accounts as Record<string, unknown>)) {
80
- if (!isStoredAccount(raw)) continue;
81
- const accountId =
82
- typeof raw.accountId === "string" && raw.accountId.trim() ? raw.accountId : key;
83
- accounts[accountId] = { ...raw, accountId };
84
- }
85
- const activeAccountId =
86
- typeof value.activeAccountId === "string"
87
- ? value.activeAccountId
88
- : typeof value.activeEmail === "string"
89
- ? value.activeEmail
90
- : undefined;
91
- return {
92
- version: 1,
93
- activeAccountId: activeAccountId && accounts[activeAccountId] ? activeAccountId : undefined,
94
- accounts,
95
- };
96
- }
97
-
98
- export function loadAccountStore(): AccountsFile {
99
- return normalizeStore(readJsonObject(accountsPath()));
100
- }
101
-
102
- function saveAccountStore(store: AccountsFile): void {
103
- writePrivateJson(accountsPath(), store);
104
- }
105
-
106
- function accountIdFor(credentials: OAuthCredentials): string {
107
- const email = (credentials as AntigravityOAuthCredentials).email?.trim().toLowerCase();
108
- if (email) return email;
109
- return `account-${createHash("sha256").update(credentials.refresh).digest("hex").slice(0, 16)}`;
110
- }
111
-
112
- function accountFromCredentials(
113
- credentials: AntigravityOAuthCredentials,
114
- existing?: StoredAccount,
115
- ): StoredAccount {
116
- const now = Date.now();
117
- return {
118
- ...credentials,
119
- accountId: existing?.accountId || accountIdFor(credentials),
120
- addedAt: existing?.addedAt || now,
121
- lastUsedAt: now,
122
- };
123
- }
124
-
125
- function sortedAccounts(store: AccountsFile): StoredAccount[] {
126
- return Object.values(store.accounts).sort((a, b) => {
127
- if (a.addedAt !== b.addedAt) return a.addedAt - b.addedAt;
128
- return a.accountId.localeCompare(b.accountId);
129
- });
130
- }
131
-
132
- function findAccount(
133
- store: AccountsFile,
134
- credentials: OAuthCredentials,
135
- ): StoredAccount | undefined {
136
- const email = (credentials as AntigravityOAuthCredentials).email?.trim().toLowerCase();
137
- return Object.values(store.accounts).find(
138
- (account) =>
139
- account.refresh === credentials.refresh ||
140
- (email !== undefined && account.email?.trim().toLowerCase() === email),
141
- );
142
- }
143
-
144
- function findAccountId(store: AccountsFile, selector: string): string | undefined {
145
- const normalized = selector.trim().toLowerCase();
146
- if (!normalized) return undefined;
147
- const entries = sortedAccounts(store);
148
- if (/^\d+$/.test(normalized)) {
149
- const index = Number.parseInt(normalized, 10);
150
- if (index >= 1 && index <= entries.length) return entries[index - 1]?.accountId;
151
- return undefined;
152
- }
153
- return entries.find(
154
- (account) =>
155
- account.accountId.toLowerCase() === normalized ||
156
- account.email?.trim().toLowerCase() === normalized,
157
- )?.accountId;
158
- }
159
-
160
- function readAuthFile(): Record<string, unknown> {
161
- const path = authPath();
162
- if (!existsSync(path)) return {};
163
- const parsed = readJsonObject(path);
164
- if (!parsed) {
165
- throw new Error("Refusing to overwrite unreadable Pi auth.json");
166
- }
167
- return parsed;
168
- }
169
-
170
- function writeActiveCredential(account: StoredAccount | undefined): void {
171
- const auth = readAuthFile();
172
- if (account) {
173
- auth.antigravity = {
174
- type: "oauth",
175
- email: account.email,
176
- access: account.access,
177
- refresh: account.refresh,
178
- expires: account.expires,
179
- projectId: account.projectId,
180
- };
181
- } else {
182
- delete auth.antigravity;
183
- }
184
- writePrivateJson(authPath(), auth);
185
- }
186
-
187
- function currentAuthCredentials(): AntigravityOAuthCredentials | undefined {
188
- const current = readJsonObject(authPath())?.antigravity;
189
- if (!current || typeof current !== "object") return undefined;
190
- const record = current as Record<string, unknown>;
191
- if (typeof record.refresh !== "string" || !record.refresh) return undefined;
192
- return {
193
- access: typeof record.access === "string" ? record.access : "",
194
- refresh: record.refresh,
195
- expires: typeof record.expires === "number" ? record.expires : 0,
196
- projectId: typeof record.projectId === "string" ? record.projectId : undefined,
197
- email: typeof record.email === "string" ? record.email : undefined,
198
- };
199
- }
200
-
201
- export function syncCurrentAuth(): void {
202
- const credentials = currentAuthCredentials();
203
- if (!credentials) return;
204
- const store = loadAccountStore();
205
- const existing = findAccount(store, credentials);
206
- const account = accountFromCredentials(credentials, existing);
207
- store.accounts[account.accountId] = account;
208
- store.activeAccountId = account.accountId;
209
- saveAccountStore(store);
210
- }
211
-
212
- export function rememberAccount(credentials: AntigravityOAuthCredentials): StoredAccount {
213
- syncCurrentAuth();
214
- const store = loadAccountStore();
215
- const existing = findAccount(store, credentials);
216
- const account = accountFromCredentials(credentials, existing);
217
- store.accounts[account.accountId] = account;
218
- store.activeAccountId = account.accountId;
219
- saveAccountStore(store);
220
- return account;
221
- }
222
-
223
- export function updateRememberedAccount(
224
- previous: OAuthCredentials,
225
- credentials: AntigravityOAuthCredentials,
226
- ): void {
227
- const store = loadAccountStore();
228
- const existing = findAccount(store, previous);
229
- if (!existing) return;
230
- const account = accountFromCredentials(credentials, existing);
231
- delete store.accounts[existing.accountId];
232
- store.accounts[account.accountId] = account;
233
- if (store.activeAccountId === existing.accountId) {
234
- store.activeAccountId = account.accountId;
235
- }
236
- saveAccountStore(store);
237
- }
238
-
239
- export function listAccounts(): AccountSummary[] {
240
- syncCurrentAuth();
241
- const store = loadAccountStore();
242
- return sortedAccounts(store).map((account) => ({
243
- accountId: account.accountId,
244
- email: account.email,
245
- active: account.accountId === store.activeAccountId,
246
- lastUsedAt: account.lastUsedAt,
247
- }));
248
- }
249
-
250
- async function ensureFresh(account: StoredAccount): Promise<StoredAccount> {
251
- if (account.access && account.expires > Date.now() + REFRESH_SKEW_MS) return account;
252
- return accountFromCredentials(await refreshAntigravityToken(account), account);
253
- }
254
-
255
- function apiKeyFor(account: StoredAccount): AntigravityApiKey {
256
- const email = account.email?.trim();
257
- return {
258
- token: account.access,
259
- projectId: account.projectId || defaultProjectId(email || "antigravity-default"),
260
- };
261
- }
262
-
263
- export async function activateAccount(selector: string): Promise<StoredAccount> {
264
- syncCurrentAuth();
265
- const store = loadAccountStore();
266
- const accountId = findAccountId(store, selector);
267
- if (!accountId) throw new Error(`Antigravity account not found: ${selector}`);
268
- const existing = store.accounts[accountId];
269
- if (!existing) throw new Error(`Antigravity account not found: ${selector}`);
270
- const account = await ensureFresh(existing);
271
- account.lastUsedAt = Date.now();
272
- store.accounts[account.accountId] = account;
273
- store.activeAccountId = account.accountId;
274
- saveAccountStore(store);
275
- writeActiveCredential(account);
276
- return account;
277
- }
278
-
279
- export async function removeAccount(selector: string): Promise<StoredAccount | undefined> {
280
- syncCurrentAuth();
281
- const store = loadAccountStore();
282
- const accountId = findAccountId(store, selector);
283
- if (!accountId) throw new Error(`Antigravity account not found: ${selector}`);
284
- delete store.accounts[accountId];
285
- let next: StoredAccount | undefined;
286
- if (store.activeAccountId === accountId) {
287
- next = sortedAccounts(store).sort((a, b) => b.lastUsedAt - a.lastUsedAt)[0];
288
- if (next) {
289
- next = await ensureFresh(next);
290
- next.lastUsedAt = Date.now();
291
- store.accounts[next.accountId] = next;
292
- }
293
- store.activeAccountId = next?.accountId;
294
- writeActiveCredential(next);
295
- }
296
- saveAccountStore(store);
297
- return next;
298
- }
299
-
300
- /**
301
- * Switch to the next stored account that has not already been tried in this request.
302
- * Used when Antigravity returns a hard quota wall (HTTP 429).
303
- */
304
- export async function failoverToNextAccount(
305
- triedAccessTokens: ReadonlySet<string>,
306
- ): Promise<AntigravityApiKey | undefined> {
307
- syncCurrentAuth();
308
- const store = loadAccountStore();
309
- const candidates = sortedAccounts(store).filter(
310
- (account) => !triedAccessTokens.has(account.access),
311
- );
312
- for (const candidate of candidates) {
313
- try {
314
- const account = await ensureFresh(candidate);
315
- if (!account.access || triedAccessTokens.has(account.access)) continue;
316
- account.lastUsedAt = Date.now();
317
- store.accounts[account.accountId] = account;
318
- store.activeAccountId = account.accountId;
319
- saveAccountStore(store);
320
- writeActiveCredential(account);
321
- return apiKeyFor(account);
322
- } catch {
323
- // Skip accounts whose refresh token is no longer valid.
324
- }
325
- }
326
- return undefined;
327
- }
@@ -1,23 +0,0 @@
1
- export {
2
- loginAntigravity,
3
- refreshAntigravityToken,
4
- getApiKey,
5
- CLIENT_ID,
6
- CLIENT_SECRET,
7
- REDIRECT_URI,
8
- AUTH_URL,
9
- TOKEN_URL,
10
- SCOPES,
11
- CALLBACK_HOST,
12
- OAUTH_CALLBACK_TIMEOUT_MS,
13
- } from "./oauth.js";
14
- export type { OAuthCredentials, OAuthLoginCallbacks } from "./oauth.js";
15
- export {
16
- activateAccount,
17
- failoverToNextAccount,
18
- listAccounts,
19
- rememberAccount,
20
- removeAccount,
21
- updateRememberedAccount,
22
- } from "./accounts.js";
23
- export type { AccountSummary, StoredAccount } from "./accounts.js";