@mariozechner/pi-coding-agent 0.49.2 → 0.49.3

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 (62) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +3 -2
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +1 -0
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/config.d.ts +2 -0
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +6 -0
  9. package/dist/config.js.map +1 -1
  10. package/dist/core/sdk.d.ts.map +1 -1
  11. package/dist/core/sdk.js +2 -2
  12. package/dist/core/sdk.js.map +1 -1
  13. package/dist/core/settings-manager.d.ts +5 -0
  14. package/dist/core/settings-manager.d.ts.map +1 -1
  15. package/dist/core/settings-manager.js +3 -0
  16. package/dist/core/settings-manager.js.map +1 -1
  17. package/dist/modes/interactive/components/assistant-message.d.ts +3 -2
  18. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  19. package/dist/modes/interactive/components/assistant-message.js +5 -3
  20. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  21. package/dist/modes/interactive/components/branch-summary-message.d.ts +3 -2
  22. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  23. package/dist/modes/interactive/components/branch-summary-message.js +4 -2
  24. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  25. package/dist/modes/interactive/components/compaction-summary-message.d.ts +3 -2
  26. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  27. package/dist/modes/interactive/components/compaction-summary-message.js +4 -2
  28. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  29. package/dist/modes/interactive/components/custom-message.d.ts +3 -2
  30. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  31. package/dist/modes/interactive/components/custom-message.js +4 -2
  32. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  33. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  34. package/dist/modes/interactive/components/footer.js +5 -0
  35. package/dist/modes/interactive/components/footer.js.map +1 -1
  36. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  37. package/dist/modes/interactive/components/tool-execution.js +7 -0
  38. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  39. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  40. package/dist/modes/interactive/components/tree-selector.js +2 -2
  41. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  42. package/dist/modes/interactive/components/user-message.d.ts +2 -2
  43. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  44. package/dist/modes/interactive/components/user-message.js +2 -2
  45. package/dist/modes/interactive/components/user-message.js.map +1 -1
  46. package/dist/modes/interactive/interactive-mode.d.ts +5 -0
  47. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  48. package/dist/modes/interactive/interactive-mode.js +33 -13
  49. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  50. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  51. package/dist/modes/interactive/theme/theme.js +7 -3
  52. package/dist/modes/interactive/theme/theme.js.map +1 -1
  53. package/dist/utils/shell.d.ts.map +1 -1
  54. package/dist/utils/shell.js +3 -2
  55. package/dist/utils/shell.js.map +1 -1
  56. package/examples/extensions/README.md +2 -0
  57. package/examples/extensions/antigravity-image-gen.ts +413 -0
  58. package/examples/extensions/inline-bash.ts +94 -0
  59. package/examples/extensions/space-invaders.ts +560 -0
  60. package/examples/extensions/with-deps/package-lock.json +2 -2
  61. package/examples/extensions/with-deps/package.json +1 -1
  62. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/utils/shell.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,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,EAAE,QAAQ;gBACf,QAAQ,EAAE,IAAI;aACd,CAAC,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACR,kCAAkC;QACnC,CAAC;IACF,CAAC;SAAM,CAAC;QACP,gCAAgC;QAChC,IAAI,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,iEAAiE;YACjE,IAAI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;QACF,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { spawn, spawnSync } from \"child_process\";\nimport { SettingsManager } from \"../core/settings-manager.js\";\n\nlet cachedShellConfig: { shell: string; args: string[] } | null = null;\n\n/**\n * Find bash executable on PATH (Windows)\n */\nfunction findBashOnPath(): string | null {\n\ttry {\n\t\tconst result = spawnSync(\"where\", [\"bash.exe\"], { encoding: \"utf-8\", timeout: 5000 });\n\t\tif (result.status === 0 && result.stdout) {\n\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\tif (firstMatch && existsSync(firstMatch)) {\n\t\t\t\treturn firstMatch;\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Ignore errors\n\t}\n\treturn null;\n}\n\n/**\n * Get shell configuration based on platform.\n * Resolution order:\n * 1. User-specified shellPath in settings.json\n * 2. On Windows: Git Bash in known locations, then bash on PATH\n * 3. On Unix: /bin/bash\n * 4. Fallback: sh\n */\nexport function getShellConfig(): { shell: string; args: string[] } {\n\tif (cachedShellConfig) {\n\t\treturn cachedShellConfig;\n\t}\n\n\tconst settings = SettingsManager.create();\n\tconst customShellPath = settings.getShellPath();\n\n\t// 1. Check user-specified shell path\n\tif (customShellPath) {\n\t\tif (existsSync(customShellPath)) {\n\t\t\tcachedShellConfig = { shell: customShellPath, args: [\"-c\"] };\n\t\t\treturn cachedShellConfig;\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Custom shell path not found: ${customShellPath}\\nPlease update shellPath in ~/.pi/agent/settings.json`,\n\t\t);\n\t}\n\n\tif (process.platform === \"win32\") {\n\t\t// 2. Try Git Bash in known locations\n\t\tconst paths: string[] = [];\n\t\tconst programFiles = process.env.ProgramFiles;\n\t\tif (programFiles) {\n\t\t\tpaths.push(`${programFiles}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\t\tconst programFilesX86 = process.env[\"ProgramFiles(x86)\"];\n\t\tif (programFilesX86) {\n\t\t\tpaths.push(`${programFilesX86}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\n\t\tfor (const path of paths) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\tcachedShellConfig = { shell: path, args: [\"-c\"] };\n\t\t\t\treturn cachedShellConfig;\n\t\t\t}\n\t\t}\n\n\t\t// 3. Fallback: search bash.exe on PATH (Cygwin, MSYS2, WSL, etc.)\n\t\tconst bashOnPath = findBashOnPath();\n\t\tif (bashOnPath) {\n\t\t\tcachedShellConfig = { shell: bashOnPath, args: [\"-c\"] };\n\t\t\treturn cachedShellConfig;\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`No bash shell found. Options:\\n` +\n\t\t\t\t` 1. Install Git for Windows: https://git-scm.com/download/win\\n` +\n\t\t\t\t` 2. Add your bash to PATH (Cygwin, MSYS2, etc.)\\n` +\n\t\t\t\t` 3. Set shellPath in ~/.pi/agent/settings.json\\n\\n` +\n\t\t\t\t`Searched Git Bash in:\\n${paths.map((p) => ` ${p}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\t// Unix: prefer bash over sh\n\tif (existsSync(\"/bin/bash\")) {\n\t\tcachedShellConfig = { shell: \"/bin/bash\", args: [\"-c\"] };\n\t\treturn cachedShellConfig;\n\t}\n\n\tcachedShellConfig = { shell: \"sh\", args: [\"-c\"] };\n\treturn cachedShellConfig;\n}\n\n/**\n * Sanitize binary output for display/storage.\n * Removes characters that crash string-width or cause display issues:\n * - Control characters (except tab, newline, carriage return)\n * - Lone surrogates\n * - Unicode Format characters (crash string-width due to a bug)\n * - Characters with undefined code points\n */\nexport function sanitizeBinaryOutput(str: string): string {\n\t// Use Array.from to properly iterate over code points (not code units)\n\t// This handles surrogate pairs correctly and catches edge cases where\n\t// codePointAt() might return undefined\n\treturn Array.from(str)\n\t\t.filter((char) => {\n\t\t\t// Filter out characters that cause string-width to crash\n\t\t\t// This includes:\n\t\t\t// - Unicode format characters\n\t\t\t// - Lone surrogates (already filtered by Array.from)\n\t\t\t// - Control chars except \\t \\n \\r\n\t\t\t// - Characters with undefined code points\n\n\t\t\tconst code = char.codePointAt(0);\n\n\t\t\t// Skip if code point is undefined (edge case with invalid strings)\n\t\t\tif (code === undefined) return false;\n\n\t\t\t// Allow tab, newline, carriage return\n\t\t\tif (code === 0x09 || code === 0x0a || code === 0x0d) return true;\n\n\t\t\t// Filter out control characters (0x00-0x1F, except 0x09, 0x0a, 0x0x0d)\n\t\t\tif (code <= 0x1f) return false;\n\n\t\t\t// Filter out Unicode format characters\n\t\t\tif (code >= 0xfff9 && code <= 0xfffb) return false;\n\n\t\t\treturn true;\n\t\t})\n\t\t.join(\"\");\n}\n\n/**\n * Kill a process and all its children (cross-platform)\n */\nexport function killProcessTree(pid: number): void {\n\tif (process.platform === \"win32\") {\n\t\t// Use taskkill on Windows to kill process tree\n\t\ttry {\n\t\t\tspawn(\"taskkill\", [\"/F\", \"/T\", \"/PID\", String(pid)], {\n\t\t\t\tstdio: \"ignore\",\n\t\t\t\tdetached: true,\n\t\t\t});\n\t\t} catch {\n\t\t\t// Ignore errors if taskkill fails\n\t\t}\n\t} else {\n\t\t// Use SIGKILL on Unix/Linux/Mac\n\t\ttry {\n\t\t\tprocess.kill(-pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// Fallback to killing just the child if process group kill fails\n\t\t\ttry {\n\t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AAI,IAAI,IAAI,MAAM;YAAE,OAAO,KAAK,CAAC;QAEnD,OAAO,IAAI,CAAC;IAAA,CACZ,CAAC;SACD,IAAI,CAAC,EAAE,CAAC,CAAC;AAAA,CACX;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW,EAAQ;IAClD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAClC,+CAA+C;QAC/C,IAAI,CAAC;YACJ,KAAK,CAAC,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;gBACpD,KAAK,EAAE,QAAQ;gBACf,QAAQ,EAAE,IAAI;aACd,CAAC,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACR,kCAAkC;QACnC,CAAC;IACF,CAAC;SAAM,CAAC;QACP,gCAAgC;QAChC,IAAI,CAAC;YACJ,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACR,iEAAiE;YACjE,IAAI,CAAC;gBACJ,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;QACF,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { spawn, spawnSync } from \"child_process\";\nimport { getSettingsPath } from \"../config.js\";\nimport { SettingsManager } from \"../core/settings-manager.js\";\n\nlet cachedShellConfig: { shell: string; args: string[] } | null = null;\n\n/**\n * Find bash executable on PATH (Windows)\n */\nfunction findBashOnPath(): string | null {\n\ttry {\n\t\tconst result = spawnSync(\"where\", [\"bash.exe\"], { encoding: \"utf-8\", timeout: 5000 });\n\t\tif (result.status === 0 && result.stdout) {\n\t\t\tconst firstMatch = result.stdout.trim().split(/\\r?\\n/)[0];\n\t\t\tif (firstMatch && existsSync(firstMatch)) {\n\t\t\t\treturn firstMatch;\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Ignore errors\n\t}\n\treturn null;\n}\n\n/**\n * Get shell configuration based on platform.\n * Resolution order:\n * 1. User-specified shellPath in settings.json\n * 2. On Windows: Git Bash in known locations, then bash on PATH\n * 3. On Unix: /bin/bash\n * 4. Fallback: sh\n */\nexport function getShellConfig(): { shell: string; args: string[] } {\n\tif (cachedShellConfig) {\n\t\treturn cachedShellConfig;\n\t}\n\n\tconst settings = SettingsManager.create();\n\tconst customShellPath = settings.getShellPath();\n\n\t// 1. Check user-specified shell path\n\tif (customShellPath) {\n\t\tif (existsSync(customShellPath)) {\n\t\t\tcachedShellConfig = { shell: customShellPath, args: [\"-c\"] };\n\t\t\treturn cachedShellConfig;\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Custom shell path not found: ${customShellPath}\\nPlease update shellPath in ${getSettingsPath()}`,\n\t\t);\n\t}\n\n\tif (process.platform === \"win32\") {\n\t\t// 2. Try Git Bash in known locations\n\t\tconst paths: string[] = [];\n\t\tconst programFiles = process.env.ProgramFiles;\n\t\tif (programFiles) {\n\t\t\tpaths.push(`${programFiles}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\t\tconst programFilesX86 = process.env[\"ProgramFiles(x86)\"];\n\t\tif (programFilesX86) {\n\t\t\tpaths.push(`${programFilesX86}\\\\Git\\\\bin\\\\bash.exe`);\n\t\t}\n\n\t\tfor (const path of paths) {\n\t\t\tif (existsSync(path)) {\n\t\t\t\tcachedShellConfig = { shell: path, args: [\"-c\"] };\n\t\t\t\treturn cachedShellConfig;\n\t\t\t}\n\t\t}\n\n\t\t// 3. Fallback: search bash.exe on PATH (Cygwin, MSYS2, WSL, etc.)\n\t\tconst bashOnPath = findBashOnPath();\n\t\tif (bashOnPath) {\n\t\t\tcachedShellConfig = { shell: bashOnPath, args: [\"-c\"] };\n\t\t\treturn cachedShellConfig;\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`No bash shell found. Options:\\n` +\n\t\t\t\t` 1. Install Git for Windows: https://git-scm.com/download/win\\n` +\n\t\t\t\t` 2. Add your bash to PATH (Cygwin, MSYS2, etc.)\\n` +\n\t\t\t\t` 3. Set shellPath in ${getSettingsPath()}\\n\\n` +\n\t\t\t\t`Searched Git Bash in:\\n${paths.map((p) => ` ${p}`).join(\"\\n\")}`,\n\t\t);\n\t}\n\n\t// Unix: prefer bash over sh\n\tif (existsSync(\"/bin/bash\")) {\n\t\tcachedShellConfig = { shell: \"/bin/bash\", args: [\"-c\"] };\n\t\treturn cachedShellConfig;\n\t}\n\n\tcachedShellConfig = { shell: \"sh\", args: [\"-c\"] };\n\treturn cachedShellConfig;\n}\n\n/**\n * Sanitize binary output for display/storage.\n * Removes characters that crash string-width or cause display issues:\n * - Control characters (except tab, newline, carriage return)\n * - Lone surrogates\n * - Unicode Format characters (crash string-width due to a bug)\n * - Characters with undefined code points\n */\nexport function sanitizeBinaryOutput(str: string): string {\n\t// Use Array.from to properly iterate over code points (not code units)\n\t// This handles surrogate pairs correctly and catches edge cases where\n\t// codePointAt() might return undefined\n\treturn Array.from(str)\n\t\t.filter((char) => {\n\t\t\t// Filter out characters that cause string-width to crash\n\t\t\t// This includes:\n\t\t\t// - Unicode format characters\n\t\t\t// - Lone surrogates (already filtered by Array.from)\n\t\t\t// - Control chars except \\t \\n \\r\n\t\t\t// - Characters with undefined code points\n\n\t\t\tconst code = char.codePointAt(0);\n\n\t\t\t// Skip if code point is undefined (edge case with invalid strings)\n\t\t\tif (code === undefined) return false;\n\n\t\t\t// Allow tab, newline, carriage return\n\t\t\tif (code === 0x09 || code === 0x0a || code === 0x0d) return true;\n\n\t\t\t// Filter out control characters (0x00-0x1F, except 0x09, 0x0a, 0x0x0d)\n\t\t\tif (code <= 0x1f) return false;\n\n\t\t\t// Filter out Unicode format characters\n\t\t\tif (code >= 0xfff9 && code <= 0xfffb) return false;\n\n\t\t\treturn true;\n\t\t})\n\t\t.join(\"\");\n}\n\n/**\n * Kill a process and all its children (cross-platform)\n */\nexport function killProcessTree(pid: number): void {\n\tif (process.platform === \"win32\") {\n\t\t// Use taskkill on Windows to kill process tree\n\t\ttry {\n\t\t\tspawn(\"taskkill\", [\"/F\", \"/T\", \"/PID\", String(pid)], {\n\t\t\t\tstdio: \"ignore\",\n\t\t\t\tdetached: true,\n\t\t\t});\n\t\t} catch {\n\t\t\t// Ignore errors if taskkill fails\n\t\t}\n\t} else {\n\t\t// Use SIGKILL on Unix/Linux/Mac\n\t\ttry {\n\t\t\tprocess.kill(-pid, \"SIGKILL\");\n\t\t} catch {\n\t\t\t// Fallback to killing just the child if process group kill fails\n\t\t\ttry {\n\t\t\t\tprocess.kill(pid, \"SIGKILL\");\n\t\t\t} catch {\n\t\t\t\t// Process already dead\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -34,6 +34,7 @@ cp permission-gate.ts ~/.pi/agent/extensions/
34
34
  | `questionnaire.ts` | Multi-question input with tab bar navigation between questions |
35
35
  | `tool-override.ts` | Override built-in tools (e.g., add logging/access control to `read`) |
36
36
  | `truncated-tool.ts` | Wraps ripgrep with proper output truncation (50KB/2000 lines) |
37
+ | `antigravity-image-gen.ts` | Generate images via Google Antigravity with optional save-to-disk modes |
37
38
  | `ssh.ts` | Delegate all tools to a remote machine via SSH using pluggable operations |
38
39
  | `subagent/` | Delegate tasks to specialized subagents with isolated context windows |
39
40
 
@@ -63,6 +64,7 @@ cp permission-gate.ts ~/.pi/agent/extensions/
63
64
  | `doom-overlay/` | DOOM game running as an overlay at 35 FPS (demonstrates real-time game rendering) |
64
65
  | `shutdown-command.ts` | Adds `/quit` command demonstrating `ctx.shutdown()` |
65
66
  | `interactive-shell.ts` | Run interactive commands (vim, htop) with full terminal via `user_bash` hook |
67
+ | `inline-bash.ts` | Expands `!{command}` patterns in prompts via `input` event transformation |
66
68
 
67
69
  ### Git Integration
68
70
 
@@ -0,0 +1,413 @@
1
+ /**
2
+ * Antigravity Image Generation
3
+ *
4
+ * Generates images via Google Antigravity's image models (gemini-3-pro-image, imagen-3).
5
+ * Returns images as tool result attachments for inline terminal rendering.
6
+ * Requires OAuth login via /login for google-antigravity.
7
+ *
8
+ * Usage:
9
+ * "Generate an image of a sunset over mountains"
10
+ * "Create a 16:9 wallpaper of a cyberpunk city"
11
+ *
12
+ * Save modes (tool param, env var, or config file):
13
+ * save=none - Don't save to disk (default)
14
+ * save=project - Save to <repo>/.pi/generated-images/
15
+ * save=global - Save to ~/.pi/agent/generated-images/
16
+ * save=custom - Save to saveDir param or PI_IMAGE_SAVE_DIR
17
+ *
18
+ * Environment variables:
19
+ * PI_IMAGE_SAVE_MODE - Default save mode (none|project|global|custom)
20
+ * PI_IMAGE_SAVE_DIR - Directory for custom save mode
21
+ *
22
+ * Config files (project overrides global):
23
+ * ~/.pi/agent/extensions/antigravity-image-gen.json
24
+ * <repo>/.pi/extensions/antigravity-image-gen.json
25
+ * Example: { "save": "global" }
26
+ */
27
+
28
+ import { randomUUID } from "node:crypto";
29
+ import { existsSync, readFileSync } from "node:fs";
30
+ import { mkdir, writeFile } from "node:fs/promises";
31
+ import { homedir } from "node:os";
32
+ import { join } from "node:path";
33
+ import { StringEnum } from "@mariozechner/pi-ai";
34
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
35
+ import { type Static, Type } from "@sinclair/typebox";
36
+
37
+ const PROVIDER = "google-antigravity";
38
+
39
+ const ASPECT_RATIOS = ["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"] as const;
40
+
41
+ type AspectRatio = (typeof ASPECT_RATIOS)[number];
42
+
43
+ const DEFAULT_MODEL = "gemini-3-pro-image";
44
+ const DEFAULT_ASPECT_RATIO: AspectRatio = "1:1";
45
+ const DEFAULT_SAVE_MODE = "none";
46
+
47
+ const SAVE_MODES = ["none", "project", "global", "custom"] as const;
48
+ type SaveMode = (typeof SAVE_MODES)[number];
49
+
50
+ const ANTIGRAVITY_ENDPOINT = "https://daily-cloudcode-pa.sandbox.googleapis.com";
51
+
52
+ const ANTIGRAVITY_HEADERS = {
53
+ "User-Agent": "antigravity/1.11.5 darwin/arm64",
54
+ "X-Goog-Api-Client": "google-cloud-sdk vscode_cloudshelleditor/0.1",
55
+ "Client-Metadata": JSON.stringify({
56
+ ideType: "IDE_UNSPECIFIED",
57
+ platform: "PLATFORM_UNSPECIFIED",
58
+ pluginType: "GEMINI",
59
+ }),
60
+ };
61
+
62
+ const IMAGE_SYSTEM_INSTRUCTION =
63
+ "You are an AI image generator. Generate images based on user descriptions. Focus on creating high-quality, visually appealing images that match the user's request.";
64
+
65
+ const TOOL_PARAMS = Type.Object({
66
+ prompt: Type.String({ description: "Image description." }),
67
+ model: Type.Optional(
68
+ Type.String({
69
+ description: "Image model id (e.g., gemini-3-pro-image, imagen-3). Default: gemini-3-pro-image.",
70
+ }),
71
+ ),
72
+ aspectRatio: Type.Optional(StringEnum(ASPECT_RATIOS)),
73
+ save: Type.Optional(StringEnum(SAVE_MODES)),
74
+ saveDir: Type.Optional(
75
+ Type.String({
76
+ description: "Directory to save image when save=custom. Defaults to PI_IMAGE_SAVE_DIR if set.",
77
+ }),
78
+ ),
79
+ });
80
+
81
+ type ToolParams = Static<typeof TOOL_PARAMS>;
82
+
83
+ interface CloudCodeAssistRequest {
84
+ project: string;
85
+ model: string;
86
+ request: {
87
+ contents: Content[];
88
+ sessionId?: string;
89
+ systemInstruction?: { role?: string; parts: { text: string }[] };
90
+ generationConfig?: {
91
+ maxOutputTokens?: number;
92
+ temperature?: number;
93
+ imageConfig?: { aspectRatio?: string };
94
+ candidateCount?: number;
95
+ };
96
+ safetySettings?: Array<{ category: string; threshold: string }>;
97
+ };
98
+ requestType?: string;
99
+ userAgent?: string;
100
+ requestId?: string;
101
+ }
102
+
103
+ interface CloudCodeAssistResponseChunk {
104
+ response?: {
105
+ candidates?: Array<{
106
+ content?: {
107
+ role: string;
108
+ parts?: Array<{
109
+ text?: string;
110
+ inlineData?: {
111
+ mimeType?: string;
112
+ data?: string;
113
+ };
114
+ }>;
115
+ };
116
+ }>;
117
+ usageMetadata?: {
118
+ promptTokenCount?: number;
119
+ candidatesTokenCount?: number;
120
+ thoughtsTokenCount?: number;
121
+ totalTokenCount?: number;
122
+ cachedContentTokenCount?: number;
123
+ };
124
+ modelVersion?: string;
125
+ responseId?: string;
126
+ };
127
+ traceId?: string;
128
+ }
129
+
130
+ interface Content {
131
+ role: "user" | "model";
132
+ parts: Part[];
133
+ }
134
+
135
+ interface Part {
136
+ text?: string;
137
+ inlineData?: {
138
+ mimeType?: string;
139
+ data?: string;
140
+ };
141
+ }
142
+
143
+ interface ParsedCredentials {
144
+ accessToken: string;
145
+ projectId: string;
146
+ }
147
+
148
+ interface ExtensionConfig {
149
+ save?: SaveMode;
150
+ saveDir?: string;
151
+ }
152
+
153
+ interface SaveConfig {
154
+ mode: SaveMode;
155
+ outputDir?: string;
156
+ }
157
+
158
+ function parseOAuthCredentials(raw: string): ParsedCredentials {
159
+ let parsed: { token?: string; projectId?: string };
160
+ try {
161
+ parsed = JSON.parse(raw) as { token?: string; projectId?: string };
162
+ } catch {
163
+ throw new Error("Invalid Google OAuth credentials. Run /login to re-authenticate.");
164
+ }
165
+ if (!parsed.token || !parsed.projectId) {
166
+ throw new Error("Missing token or projectId in Google OAuth credentials. Run /login.");
167
+ }
168
+ return { accessToken: parsed.token, projectId: parsed.projectId };
169
+ }
170
+
171
+ function readConfigFile(path: string): ExtensionConfig {
172
+ if (!existsSync(path)) {
173
+ return {};
174
+ }
175
+ try {
176
+ const content = readFileSync(path, "utf-8");
177
+ const parsed = JSON.parse(content) as ExtensionConfig;
178
+ return parsed ?? {};
179
+ } catch {
180
+ return {};
181
+ }
182
+ }
183
+
184
+ function loadConfig(cwd: string): ExtensionConfig {
185
+ const globalConfig = readConfigFile(join(homedir(), ".pi", "agent", "extensions", "antigravity-image-gen.json"));
186
+ const projectConfig = readConfigFile(join(cwd, ".pi", "extensions", "antigravity-image-gen.json"));
187
+ return { ...globalConfig, ...projectConfig };
188
+ }
189
+
190
+ function resolveSaveConfig(params: ToolParams, cwd: string): SaveConfig {
191
+ const config = loadConfig(cwd);
192
+ const envMode = (process.env.PI_IMAGE_SAVE_MODE || "").toLowerCase();
193
+ const paramMode = params.save;
194
+ const mode = (paramMode || envMode || config.save || DEFAULT_SAVE_MODE) as SaveMode;
195
+
196
+ if (!SAVE_MODES.includes(mode)) {
197
+ return { mode: DEFAULT_SAVE_MODE as SaveMode };
198
+ }
199
+
200
+ if (mode === "project") {
201
+ return { mode, outputDir: join(cwd, ".pi", "generated-images") };
202
+ }
203
+
204
+ if (mode === "global") {
205
+ return { mode, outputDir: join(homedir(), ".pi", "agent", "generated-images") };
206
+ }
207
+
208
+ if (mode === "custom") {
209
+ const dir = params.saveDir || process.env.PI_IMAGE_SAVE_DIR || config.saveDir;
210
+ if (!dir || !dir.trim()) {
211
+ throw new Error("save=custom requires saveDir or PI_IMAGE_SAVE_DIR.");
212
+ }
213
+ return { mode, outputDir: dir };
214
+ }
215
+
216
+ return { mode };
217
+ }
218
+
219
+ function imageExtension(mimeType: string): string {
220
+ const lower = mimeType.toLowerCase();
221
+ if (lower.includes("jpeg") || lower.includes("jpg")) return "jpg";
222
+ if (lower.includes("gif")) return "gif";
223
+ if (lower.includes("webp")) return "webp";
224
+ return "png";
225
+ }
226
+
227
+ async function saveImage(base64Data: string, mimeType: string, outputDir: string): Promise<string> {
228
+ await mkdir(outputDir, { recursive: true });
229
+ const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
230
+ const ext = imageExtension(mimeType);
231
+ const filename = `image-${timestamp}-${randomUUID().slice(0, 8)}.${ext}`;
232
+ const filePath = join(outputDir, filename);
233
+ await writeFile(filePath, Buffer.from(base64Data, "base64"));
234
+ return filePath;
235
+ }
236
+
237
+ function buildRequest(prompt: string, model: string, projectId: string, aspectRatio: string): CloudCodeAssistRequest {
238
+ return {
239
+ project: projectId,
240
+ model,
241
+ request: {
242
+ contents: [
243
+ {
244
+ role: "user",
245
+ parts: [{ text: prompt }],
246
+ },
247
+ ],
248
+ systemInstruction: {
249
+ parts: [{ text: IMAGE_SYSTEM_INSTRUCTION }],
250
+ },
251
+ generationConfig: {
252
+ imageConfig: { aspectRatio },
253
+ candidateCount: 1,
254
+ },
255
+ safetySettings: [
256
+ { category: "HARM_CATEGORY_HARASSMENT", threshold: "BLOCK_ONLY_HIGH" },
257
+ { category: "HARM_CATEGORY_HATE_SPEECH", threshold: "BLOCK_ONLY_HIGH" },
258
+ { category: "HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold: "BLOCK_ONLY_HIGH" },
259
+ { category: "HARM_CATEGORY_DANGEROUS_CONTENT", threshold: "BLOCK_ONLY_HIGH" },
260
+ { category: "HARM_CATEGORY_CIVIC_INTEGRITY", threshold: "BLOCK_ONLY_HIGH" },
261
+ ],
262
+ },
263
+ requestType: "agent",
264
+ requestId: `agent-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`,
265
+ userAgent: "antigravity",
266
+ };
267
+ }
268
+
269
+ async function parseSseForImage(
270
+ response: Response,
271
+ signal?: AbortSignal,
272
+ ): Promise<{ image: { data: string; mimeType: string }; text: string[] }> {
273
+ if (!response.body) {
274
+ throw new Error("No response body");
275
+ }
276
+
277
+ const reader = response.body.getReader();
278
+ const decoder = new TextDecoder();
279
+ let buffer = "";
280
+ const textParts: string[] = [];
281
+
282
+ try {
283
+ while (true) {
284
+ if (signal?.aborted) {
285
+ throw new Error("Request was aborted");
286
+ }
287
+
288
+ const { done, value } = await reader.read();
289
+ if (done) break;
290
+
291
+ buffer += decoder.decode(value, { stream: true });
292
+ const lines = buffer.split("\n");
293
+ buffer = lines.pop() || "";
294
+
295
+ for (const line of lines) {
296
+ if (!line.startsWith("data:")) continue;
297
+ const jsonStr = line.slice(5).trim();
298
+ if (!jsonStr) continue;
299
+
300
+ let chunk: CloudCodeAssistResponseChunk;
301
+ try {
302
+ chunk = JSON.parse(jsonStr) as CloudCodeAssistResponseChunk;
303
+ } catch {
304
+ continue;
305
+ }
306
+
307
+ const responseData = chunk.response;
308
+ if (!responseData?.candidates) continue;
309
+
310
+ for (const candidate of responseData.candidates) {
311
+ const parts = candidate.content?.parts;
312
+ if (!parts) continue;
313
+ for (const part of parts) {
314
+ if (part.text) {
315
+ textParts.push(part.text);
316
+ }
317
+ if (part.inlineData?.data) {
318
+ await reader.cancel();
319
+ return {
320
+ image: {
321
+ data: part.inlineData.data,
322
+ mimeType: part.inlineData.mimeType || "image/png",
323
+ },
324
+ text: textParts,
325
+ };
326
+ }
327
+ }
328
+ }
329
+ }
330
+ }
331
+ } finally {
332
+ reader.releaseLock();
333
+ }
334
+
335
+ throw new Error("No image data returned by the model");
336
+ }
337
+
338
+ async function getCredentials(ctx: {
339
+ modelRegistry: { getApiKeyForProvider: (provider: string) => Promise<string | undefined> };
340
+ }): Promise<ParsedCredentials> {
341
+ const apiKey = await ctx.modelRegistry.getApiKeyForProvider(PROVIDER);
342
+ if (!apiKey) {
343
+ throw new Error("Missing Google Antigravity OAuth credentials. Run /login for google-antigravity.");
344
+ }
345
+ return parseOAuthCredentials(apiKey);
346
+ }
347
+
348
+ export default function antigravityImageGen(pi: ExtensionAPI) {
349
+ pi.registerTool({
350
+ name: "generate_image",
351
+ label: "Generate image",
352
+ description:
353
+ "Generate an image via Google Antigravity image models. Returns the image as a tool result attachment. Optional saving via save=project|global|custom|none, or PI_IMAGE_SAVE_MODE/PI_IMAGE_SAVE_DIR.",
354
+ parameters: TOOL_PARAMS,
355
+ async execute(_toolCallId, params: ToolParams, onUpdate, ctx, signal) {
356
+ const { accessToken, projectId } = await getCredentials(ctx);
357
+ const model = params.model || DEFAULT_MODEL;
358
+ const aspectRatio = params.aspectRatio || DEFAULT_ASPECT_RATIO;
359
+
360
+ const requestBody = buildRequest(params.prompt, model, projectId, aspectRatio);
361
+ onUpdate?.({
362
+ content: [{ type: "text", text: `Requesting image from ${PROVIDER}/${model}...` }],
363
+ details: { provider: PROVIDER, model, aspectRatio },
364
+ });
365
+
366
+ const response = await fetch(`${ANTIGRAVITY_ENDPOINT}/v1internal:streamGenerateContent?alt=sse`, {
367
+ method: "POST",
368
+ headers: {
369
+ Authorization: `Bearer ${accessToken}`,
370
+ "Content-Type": "application/json",
371
+ Accept: "text/event-stream",
372
+ ...ANTIGRAVITY_HEADERS,
373
+ },
374
+ body: JSON.stringify(requestBody),
375
+ signal,
376
+ });
377
+
378
+ if (!response.ok) {
379
+ const errorText = await response.text();
380
+ throw new Error(`Image request failed (${response.status}): ${errorText}`);
381
+ }
382
+
383
+ const parsed = await parseSseForImage(response, signal);
384
+ const saveConfig = resolveSaveConfig(params, ctx.cwd);
385
+ let savedPath: string | undefined;
386
+ let saveError: string | undefined;
387
+ if (saveConfig.mode !== "none" && saveConfig.outputDir) {
388
+ try {
389
+ savedPath = await saveImage(parsed.image.data, parsed.image.mimeType, saveConfig.outputDir);
390
+ } catch (error) {
391
+ saveError = error instanceof Error ? error.message : String(error);
392
+ }
393
+ }
394
+ const summaryParts = [`Generated image via ${PROVIDER}/${model}.`, `Aspect ratio: ${aspectRatio}.`];
395
+ if (savedPath) {
396
+ summaryParts.push(`Saved image to: ${savedPath}`);
397
+ } else if (saveError) {
398
+ summaryParts.push(`Failed to save image: ${saveError}`);
399
+ }
400
+ if (parsed.text.length > 0) {
401
+ summaryParts.push(`Model notes: ${parsed.text.join(" ")}`);
402
+ }
403
+
404
+ return {
405
+ content: [
406
+ { type: "text", text: summaryParts.join(" ") },
407
+ { type: "image", data: parsed.image.data, mimeType: parsed.image.mimeType },
408
+ ],
409
+ details: { provider: PROVIDER, model, aspectRatio, savedPath, saveMode: saveConfig.mode },
410
+ };
411
+ },
412
+ });
413
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Inline Bash Extension - expands inline bash commands in user prompts.
3
+ *
4
+ * Start pi with this extension:
5
+ * pi -e ./examples/extensions/inline-bash.ts
6
+ *
7
+ * Then type prompts with inline bash:
8
+ * What's in !{pwd}?
9
+ * The current branch is !{git branch --show-current} and status: !{git status --short}
10
+ * My node version is !{node --version}
11
+ *
12
+ * The !{command} patterns are executed and replaced with their output before
13
+ * the prompt is sent to the agent.
14
+ *
15
+ * Note: Regular !command syntax (whole-line bash) is preserved and works as before.
16
+ */
17
+ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
18
+
19
+ export default function (pi: ExtensionAPI) {
20
+ const PATTERN = /!\{([^}]+)\}/g;
21
+ const TIMEOUT_MS = 30000;
22
+
23
+ pi.on("input", async (event, ctx) => {
24
+ const text = event.text;
25
+
26
+ // Don't process if it's a whole-line bash command (starts with !)
27
+ // This preserves the existing !command behavior
28
+ if (text.trimStart().startsWith("!") && !text.trimStart().startsWith("!{")) {
29
+ return { action: "continue" };
30
+ }
31
+
32
+ // Check if there are any inline bash patterns
33
+ if (!PATTERN.test(text)) {
34
+ return { action: "continue" };
35
+ }
36
+
37
+ // Reset regex state after test()
38
+ PATTERN.lastIndex = 0;
39
+
40
+ let result = text;
41
+ const expansions: Array<{ command: string; output: string; error?: string }> = [];
42
+
43
+ // Find all matches first (to avoid issues with replacing while iterating)
44
+ const matches: Array<{ full: string; command: string }> = [];
45
+ let match = PATTERN.exec(text);
46
+ while (match) {
47
+ matches.push({ full: match[0], command: match[1] });
48
+ match = PATTERN.exec(text);
49
+ }
50
+
51
+ // Execute each command and collect results
52
+ for (const { full, command } of matches) {
53
+ try {
54
+ const bashResult = await pi.exec("bash", ["-c", command], {
55
+ timeout: TIMEOUT_MS,
56
+ });
57
+
58
+ const output = bashResult.stdout || bashResult.stderr || "";
59
+ const trimmed = output.trim();
60
+
61
+ if (bashResult.code !== 0 && bashResult.stderr) {
62
+ expansions.push({
63
+ command,
64
+ output: trimmed,
65
+ error: `exit code ${bashResult.code}`,
66
+ });
67
+ } else {
68
+ expansions.push({ command, output: trimmed });
69
+ }
70
+
71
+ result = result.replace(full, trimmed);
72
+ } catch (err) {
73
+ const errorMsg = err instanceof Error ? err.message : String(err);
74
+ expansions.push({ command, output: "", error: errorMsg });
75
+ result = result.replace(full, `[error: ${errorMsg}]`);
76
+ }
77
+ }
78
+
79
+ // Show what was expanded (if UI available)
80
+ if (ctx.hasUI && expansions.length > 0) {
81
+ const summary = expansions
82
+ .map((e) => {
83
+ const status = e.error ? ` (${e.error})` : "";
84
+ const preview = e.output.length > 50 ? `${e.output.slice(0, 50)}...` : e.output;
85
+ return `!{${e.command}}${status} -> "${preview}"`;
86
+ })
87
+ .join("\n");
88
+
89
+ ctx.ui.notify(`Expanded ${expansions.length} inline command(s):\n${summary}`, "info");
90
+ }
91
+
92
+ return { action: "transform", text: result, images: event.images };
93
+ });
94
+ }