indusagi-coding-agent 0.1.28 → 0.1.30
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 +23 -0
- package/LICENSE.md +22 -0
- package/README.md +2 -0
- package/dist/core/messages.d.ts +1 -76
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +1 -122
- package/dist/core/messages.js.map +1 -1
- package/dist/core/session-manager.d.ts +1 -447
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +1 -1203
- package/dist/core/session-manager.js.map +1 -1
- package/package.json +2 -2
- package/docs/COMPLETE-GUIDE.md +0 -300
- package/docs/COMPREHENSIVE-CLI-SUMMARY.md +0 -900
- package/docs/MODES-ARCHITECTURE.md +0 -565
- package/docs/PRINT-MODE-GUIDE.md +0 -456
- package/docs/README.md +0 -78
- package/docs/RPC-GUIDE.md +0 -705
- package/docs/UTILS-IMPLEMENTATION-SUMMARY.md +0 -647
- package/docs/UTILS-MODULE-OVERVIEW.md +0 -1480
- package/docs/UTILS-QA-CHECKLIST.md +0 -1061
- package/docs/UTILS-USAGE-GUIDE.md +0 -1419
- package/docs/compaction.md +0 -390
- package/docs/custom-provider.md +0 -538
- package/docs/development.md +0 -69
- package/docs/extensions.md +0 -1733
- package/docs/hooks.md +0 -378
- package/docs/images/doom-extension.png +0 -0
- package/docs/images/interactive-mode.png +0 -0
- package/docs/images/tree-view.png +0 -0
- package/docs/json.md +0 -79
- package/docs/keybindings.md +0 -162
- package/docs/models.md +0 -193
- package/docs/packages.md +0 -163
- package/docs/prompt-templates.md +0 -67
- package/docs/providers.md +0 -147
- package/docs/rpc.md +0 -1048
- package/docs/sdk.md +0 -969
- package/docs/session.md +0 -412
- package/docs/settings.md +0 -219
- package/docs/shell-aliases.md +0 -13
- package/docs/skills.md +0 -226
- package/docs/subagents.md +0 -225
- package/docs/terminal-setup.md +0 -65
- package/docs/themes.md +0 -295
- package/docs/tree.md +0 -219
- package/docs/tui.md +0 -887
- package/docs/web-tools.md +0 -304
- package/docs/windows.md +0 -17
- package/examples/README.md +0 -25
- package/examples/extensions/README.md +0 -192
- package/examples/extensions/antigravity-image-gen.ts +0 -414
- package/examples/extensions/auto-commit-on-exit.ts +0 -49
- package/examples/extensions/bookmark.ts +0 -50
- package/examples/extensions/claude-rules.ts +0 -86
- package/examples/extensions/confirm-destructive.ts +0 -59
- package/examples/extensions/custom-compaction.ts +0 -115
- package/examples/extensions/custom-footer.ts +0 -65
- package/examples/extensions/custom-header.ts +0 -73
- package/examples/extensions/custom-provider-anthropic/index.ts +0 -605
- package/examples/extensions/custom-provider-anthropic/package-lock.json +0 -24
- package/examples/extensions/custom-provider-anthropic/package.json +0 -19
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +0 -350
- package/examples/extensions/custom-provider-gitlab-duo/package.json +0 -16
- package/examples/extensions/custom-provider-gitlab-duo/test.ts +0 -83
- package/examples/extensions/dirty-repo-guard.ts +0 -56
- package/examples/extensions/doom-overlay/README.md +0 -46
- package/examples/extensions/doom-overlay/doom/build/doom.js +0 -21
- package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
- package/examples/extensions/doom-overlay/doom/build.sh +0 -152
- package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +0 -72
- package/examples/extensions/doom-overlay/doom-component.ts +0 -133
- package/examples/extensions/doom-overlay/doom-engine.ts +0 -173
- package/examples/extensions/doom-overlay/doom-keys.ts +0 -105
- package/examples/extensions/doom-overlay/index.ts +0 -74
- package/examples/extensions/doom-overlay/wad-finder.ts +0 -51
- package/examples/extensions/event-bus.ts +0 -43
- package/examples/extensions/file-trigger.ts +0 -41
- package/examples/extensions/git-checkpoint.ts +0 -53
- package/examples/extensions/handoff.ts +0 -151
- package/examples/extensions/hello.ts +0 -25
- package/examples/extensions/inline-bash.ts +0 -94
- package/examples/extensions/input-transform.ts +0 -43
- package/examples/extensions/interactive-shell.ts +0 -196
- package/examples/extensions/mac-system-theme.ts +0 -47
- package/examples/extensions/message-renderer.ts +0 -60
- package/examples/extensions/modal-editor.ts +0 -86
- package/examples/extensions/model-status.ts +0 -31
- package/examples/extensions/notify.ts +0 -25
- package/examples/extensions/overlay-qa-tests.ts +0 -882
- package/examples/extensions/overlay-test.ts +0 -151
- package/examples/extensions/permission-gate.ts +0 -34
- package/examples/extensions/pirate.ts +0 -47
- package/examples/extensions/plan-mode/README.md +0 -65
- package/examples/extensions/plan-mode/index.ts +0 -341
- package/examples/extensions/plan-mode/utils.ts +0 -168
- package/examples/extensions/preset.ts +0 -399
- package/examples/extensions/protected-paths.ts +0 -30
- package/examples/extensions/qna.ts +0 -120
- package/examples/extensions/question.ts +0 -265
- package/examples/extensions/questionnaire.ts +0 -428
- package/examples/extensions/rainbow-editor.ts +0 -88
- package/examples/extensions/sandbox/index.ts +0 -318
- package/examples/extensions/sandbox/package-lock.json +0 -92
- package/examples/extensions/sandbox/package.json +0 -19
- package/examples/extensions/send-user-message.ts +0 -97
- package/examples/extensions/session-name.ts +0 -27
- package/examples/extensions/shutdown-command.ts +0 -63
- package/examples/extensions/snake.ts +0 -344
- package/examples/extensions/space-invaders.ts +0 -561
- package/examples/extensions/ssh.ts +0 -220
- package/examples/extensions/status-line.ts +0 -40
- package/examples/extensions/subagent/README.md +0 -172
- package/examples/extensions/subagent/agents/planner.md +0 -37
- package/examples/extensions/subagent/agents/reviewer.md +0 -35
- package/examples/extensions/subagent/agents/scout.md +0 -50
- package/examples/extensions/subagent/agents/worker.md +0 -24
- package/examples/extensions/subagent/agents.ts +0 -127
- package/examples/extensions/subagent/index.ts +0 -964
- package/examples/extensions/subagent/prompts/implement-and-review.md +0 -10
- package/examples/extensions/subagent/prompts/implement.md +0 -10
- package/examples/extensions/subagent/prompts/scout-and-plan.md +0 -9
- package/examples/extensions/summarize.ts +0 -196
- package/examples/extensions/timed-confirm.ts +0 -70
- package/examples/extensions/todo.ts +0 -300
- package/examples/extensions/tool-override.ts +0 -144
- package/examples/extensions/tools.ts +0 -147
- package/examples/extensions/trigger-compact.ts +0 -40
- package/examples/extensions/truncated-tool.ts +0 -193
- package/examples/extensions/widget-placement.ts +0 -17
- package/examples/extensions/with-deps/index.ts +0 -36
- package/examples/extensions/with-deps/package-lock.json +0 -31
- package/examples/extensions/with-deps/package.json +0 -22
- package/examples/sdk/01-minimal.ts +0 -22
- package/examples/sdk/02-custom-model.ts +0 -50
- package/examples/sdk/03-custom-prompt.ts +0 -55
- package/examples/sdk/04-skills.ts +0 -46
- package/examples/sdk/05-tools.ts +0 -56
- package/examples/sdk/06-extensions.ts +0 -88
- package/examples/sdk/07-context-files.ts +0 -40
- package/examples/sdk/08-prompt-templates.ts +0 -47
- package/examples/sdk/09-api-keys-and-oauth.ts +0 -48
- package/examples/sdk/10-settings.ts +0 -38
- package/examples/sdk/11-sessions.ts +0 -48
- package/examples/sdk/12-full-control.ts +0 -82
- package/examples/sdk/13-codex-oauth.ts +0 -37
- package/examples/sdk/README.md +0 -144
|
@@ -1,414 +0,0 @@
|
|
|
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>/.indusagi/generated-images/
|
|
15
|
-
* save=global - Save to ~/.indusagi/agent/generated-images/
|
|
16
|
-
* save=custom - Save to saveDir param or INDUSAGI_IMAGE_SAVE_DIR
|
|
17
|
-
*
|
|
18
|
-
* Environment variables:
|
|
19
|
-
* INDUSAGI_IMAGE_SAVE_MODE - Default save mode (none|project|global|custom)
|
|
20
|
-
* INDUSAGI_IMAGE_SAVE_DIR - Directory for custom save mode
|
|
21
|
-
*
|
|
22
|
-
* Config files (project overrides global):
|
|
23
|
-
* ~/.indusagi/agent/extensions/antigravity-image-gen.json
|
|
24
|
-
* <repo>/.indusagi/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 "indusagi/ai";
|
|
34
|
-
import type { ExtensionAPI } from "indusagi-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 INDUSAGI_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(), ".indusagi", "agent", "extensions", "antigravity-image-gen.json"));
|
|
186
|
-
const projectConfig = readConfigFile(join(cwd, ".indusagi", "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.INDUSAGI_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, ".indusagi", "generated-images") };
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (mode === "global") {
|
|
205
|
-
return { mode, outputDir: join(homedir(), ".indusagi", "agent", "generated-images") };
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (mode === "custom") {
|
|
209
|
-
const dir = params.saveDir || process.env.INDUSAGI_IMAGE_SAVE_DIR || config.saveDir;
|
|
210
|
-
if (!dir || !dir.trim()) {
|
|
211
|
-
throw new Error("save=custom requires saveDir or INDUSAGI_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(indusagi: ExtensionAPI) {
|
|
349
|
-
indusagi.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 INDUSAGI_IMAGE_SAVE_MODE/INDUSAGI_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
|
-
}
|
|
414
|
-
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-Commit on Exit Extension
|
|
3
|
-
*
|
|
4
|
-
* Automatically commits changes when the agent exits.
|
|
5
|
-
* Uses the last assistant message to generate a commit message.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { ExtensionAPI } from "indusagi-coding-agent";
|
|
9
|
-
|
|
10
|
-
export default function (indusagi: ExtensionAPI) {
|
|
11
|
-
indusagi.on("session_shutdown", async (_event, ctx) => {
|
|
12
|
-
// Check for uncommitted changes
|
|
13
|
-
const { stdout: status, code } = await indusagi.exec("git", ["status", "--porcelain"]);
|
|
14
|
-
|
|
15
|
-
if (code !== 0 || status.trim().length === 0) {
|
|
16
|
-
// Not a git repo or no changes
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Find the last assistant message for commit context
|
|
21
|
-
const entries = ctx.sessionManager.getEntries();
|
|
22
|
-
let lastAssistantText = "";
|
|
23
|
-
for (let i = entries.length - 1; i >= 0; i--) {
|
|
24
|
-
const entry = entries[i];
|
|
25
|
-
if (entry.type === "message" && entry.message.role === "assistant") {
|
|
26
|
-
const content = entry.message.content;
|
|
27
|
-
if (Array.isArray(content)) {
|
|
28
|
-
lastAssistantText = content
|
|
29
|
-
.filter((c): c is { type: "text"; text: string } => c.type === "text")
|
|
30
|
-
.map((c) => c.text)
|
|
31
|
-
.join("\n");
|
|
32
|
-
}
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Generate a simple commit message
|
|
38
|
-
const firstLine = lastAssistantText.split("\n")[0] || "Work in progress";
|
|
39
|
-
const commitMessage = `[indusagi] ${firstLine.slice(0, 50)}${firstLine.length > 50 ? "..." : ""}`;
|
|
40
|
-
|
|
41
|
-
// Stage and commit
|
|
42
|
-
await indusagi.exec("git", ["add", "-A"]);
|
|
43
|
-
const { code: commitCode } = await indusagi.exec("git", ["commit", "-m", commitMessage]);
|
|
44
|
-
|
|
45
|
-
if (commitCode === 0 && ctx.hasUI) {
|
|
46
|
-
ctx.ui.notify(`Auto-committed: ${commitMessage}`, "info");
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Entry bookmarking example.
|
|
3
|
-
*
|
|
4
|
-
* Shows setLabel to mark entries with labels for easy navigation in /tree.
|
|
5
|
-
* Labels appear in the tree view and help you find important points.
|
|
6
|
-
*
|
|
7
|
-
* Usage: /bookmark [label] - bookmark the last assistant message
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { ExtensionAPI } from "indusagi-coding-agent";
|
|
11
|
-
|
|
12
|
-
export default function (indusagi: ExtensionAPI) {
|
|
13
|
-
indusagi.registerCommand("bookmark", {
|
|
14
|
-
description: "Bookmark last message (usage: /bookmark [label])",
|
|
15
|
-
handler: async (args, ctx) => {
|
|
16
|
-
const label = args.trim() || `bookmark-${Date.now()}`;
|
|
17
|
-
|
|
18
|
-
// Find the last assistant message entry
|
|
19
|
-
const entries = ctx.sessionManager.getEntries();
|
|
20
|
-
for (let i = entries.length - 1; i >= 0; i--) {
|
|
21
|
-
const entry = entries[i];
|
|
22
|
-
if (entry.type === "message" && entry.message.role === "assistant") {
|
|
23
|
-
indusagi.setLabel(entry.id, label);
|
|
24
|
-
ctx.ui.notify(`Bookmarked as: ${label}`, "info");
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
ctx.ui.notify("No assistant message to bookmark", "warning");
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Remove bookmark
|
|
34
|
-
indusagi.registerCommand("unbookmark", {
|
|
35
|
-
description: "Remove bookmark from last labeled entry",
|
|
36
|
-
handler: async (_args, ctx) => {
|
|
37
|
-
const entries = ctx.sessionManager.getEntries();
|
|
38
|
-
for (let i = entries.length - 1; i >= 0; i--) {
|
|
39
|
-
const entry = entries[i];
|
|
40
|
-
const label = ctx.sessionManager.getLabel(entry.id);
|
|
41
|
-
if (label) {
|
|
42
|
-
indusagi.setLabel(entry.id, undefined);
|
|
43
|
-
ctx.ui.notify(`Removed bookmark: ${label}`, "info");
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
ctx.ui.notify("No bookmarked entry found", "warning");
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude Rules Extension
|
|
3
|
-
*
|
|
4
|
-
* Scans the project's .claude/rules/ folder for rule files and lists them
|
|
5
|
-
* in the system prompt. The agent can then use the read tool to load
|
|
6
|
-
* specific rules when needed.
|
|
7
|
-
*
|
|
8
|
-
* Best practices for .claude/rules/:
|
|
9
|
-
* - Keep rules focused: Each file should cover one topic (e.g., testing.md, api-design.md)
|
|
10
|
-
* - Use descriptive filenames: The filename should indicate what the rules cover
|
|
11
|
-
* - Use conditional rules sparingly: Only add paths frontmatter when rules truly apply to specific file types
|
|
12
|
-
* - Organize with subdirectories: Group related rules (e.g., frontend/, backend/)
|
|
13
|
-
*
|
|
14
|
-
* Usage:
|
|
15
|
-
* 1. Copy this file to ~/.indusagi/agent/extensions/ or your project's .indusagi/extensions/
|
|
16
|
-
* 2. Create .claude/rules/ folder in your project root
|
|
17
|
-
* 3. Add .md files with your rules
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import * as fs from "node:fs";
|
|
21
|
-
import * as path from "node:path";
|
|
22
|
-
import type { ExtensionAPI } from "indusagi-coding-agent";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Recursively find all .md files in a directory
|
|
26
|
-
*/
|
|
27
|
-
function findMarkdownFiles(dir: string, basePath: string = ""): string[] {
|
|
28
|
-
const results: string[] = [];
|
|
29
|
-
|
|
30
|
-
if (!fs.existsSync(dir)) {
|
|
31
|
-
return results;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
35
|
-
|
|
36
|
-
for (const entry of entries) {
|
|
37
|
-
const relativePath = basePath ? `${basePath}/${entry.name}` : entry.name;
|
|
38
|
-
|
|
39
|
-
if (entry.isDirectory()) {
|
|
40
|
-
results.push(...findMarkdownFiles(path.join(dir, entry.name), relativePath));
|
|
41
|
-
} else if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
42
|
-
results.push(relativePath);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return results;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default function claudeRulesExtension(indusagi: ExtensionAPI) {
|
|
50
|
-
let ruleFiles: string[] = [];
|
|
51
|
-
let rulesDir: string = "";
|
|
52
|
-
|
|
53
|
-
// Scan for rules on session start
|
|
54
|
-
indusagi.on("session_start", async (_event, ctx) => {
|
|
55
|
-
rulesDir = path.join(ctx.cwd, ".claude", "rules");
|
|
56
|
-
ruleFiles = findMarkdownFiles(rulesDir);
|
|
57
|
-
|
|
58
|
-
if (ruleFiles.length > 0) {
|
|
59
|
-
ctx.ui.notify(`Found ${ruleFiles.length} rule(s) in .claude/rules/`, "info");
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Append available rules to system prompt
|
|
64
|
-
indusagi.on("before_agent_start", async (event) => {
|
|
65
|
-
if (ruleFiles.length === 0) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const rulesList = ruleFiles.map((f) => `- .claude/rules/${f}`).join("\n");
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
systemPrompt:
|
|
73
|
-
event.systemPrompt +
|
|
74
|
-
`
|
|
75
|
-
|
|
76
|
-
## Project Rules
|
|
77
|
-
|
|
78
|
-
The following project rules are available in .claude/rules/:
|
|
79
|
-
|
|
80
|
-
${rulesList}
|
|
81
|
-
|
|
82
|
-
When working on tasks related to these rules, use the read tool to load the relevant rule files for guidance.
|
|
83
|
-
`,
|
|
84
|
-
};
|
|
85
|
-
});
|
|
86
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Confirm Destructive Actions Extension
|
|
3
|
-
*
|
|
4
|
-
* Prompts for confirmation before destructive session actions (clear, switch, branch).
|
|
5
|
-
* Demonstrates how to cancel session events using the before_* events.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { ExtensionAPI, SessionBeforeSwitchEvent, SessionMessageEntry } from "indusagi-coding-agent";
|
|
9
|
-
|
|
10
|
-
export default function (indusagi: ExtensionAPI) {
|
|
11
|
-
indusagi.on("session_before_switch", async (event: SessionBeforeSwitchEvent, ctx) => {
|
|
12
|
-
if (!ctx.hasUI) return;
|
|
13
|
-
|
|
14
|
-
if (event.reason === "new") {
|
|
15
|
-
const confirmed = await ctx.ui.confirm(
|
|
16
|
-
"Clear session?",
|
|
17
|
-
"This will delete all messages in the current session.",
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
if (!confirmed) {
|
|
21
|
-
ctx.ui.notify("Clear cancelled", "info");
|
|
22
|
-
return { cancel: true };
|
|
23
|
-
}
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// reason === "resume" - check if there are unsaved changes (messages since last assistant response)
|
|
28
|
-
const entries = ctx.sessionManager.getEntries();
|
|
29
|
-
const hasUnsavedWork = entries.some(
|
|
30
|
-
(e): e is SessionMessageEntry => e.type === "message" && e.message.role === "user",
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
if (hasUnsavedWork) {
|
|
34
|
-
const confirmed = await ctx.ui.confirm(
|
|
35
|
-
"Switch session?",
|
|
36
|
-
"You have messages in the current session. Switch anyway?",
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
if (!confirmed) {
|
|
40
|
-
ctx.ui.notify("Switch cancelled", "info");
|
|
41
|
-
return { cancel: true };
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
indusagi.on("session_before_fork", async (event, ctx) => {
|
|
47
|
-
if (!ctx.hasUI) return;
|
|
48
|
-
|
|
49
|
-
const choice = await ctx.ui.select(`Fork from entry ${event.entryId.slice(0, 8)}?`, [
|
|
50
|
-
"Yes, create fork",
|
|
51
|
-
"No, stay in current session",
|
|
52
|
-
]);
|
|
53
|
-
|
|
54
|
-
if (choice !== "Yes, create fork") {
|
|
55
|
-
ctx.ui.notify("Fork cancelled", "info");
|
|
56
|
-
return { cancel: true };
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|