gitclaw 0.3.0
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/README.md +440 -0
- package/dist/agents.d.ts +8 -0
- package/dist/agents.js +82 -0
- package/dist/audit.d.ts +27 -0
- package/dist/audit.js +55 -0
- package/dist/compliance.d.ts +30 -0
- package/dist/compliance.js +108 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.js +43 -0
- package/dist/examples.d.ts +6 -0
- package/dist/examples.js +40 -0
- package/dist/exports.d.ts +13 -0
- package/dist/exports.js +6 -0
- package/dist/hooks.d.ts +24 -0
- package/dist/hooks.js +108 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +542 -0
- package/dist/knowledge.d.ts +17 -0
- package/dist/knowledge.js +55 -0
- package/dist/loader.d.ts +64 -0
- package/dist/loader.js +222 -0
- package/dist/sandbox.d.ts +28 -0
- package/dist/sandbox.js +54 -0
- package/dist/sdk-hooks.d.ts +8 -0
- package/dist/sdk-hooks.js +31 -0
- package/dist/sdk-types.d.ts +127 -0
- package/dist/sdk-types.js +1 -0
- package/dist/sdk.d.ts +6 -0
- package/dist/sdk.js +444 -0
- package/dist/session.d.ts +15 -0
- package/dist/session.js +127 -0
- package/dist/skills.d.ts +18 -0
- package/dist/skills.js +104 -0
- package/dist/tool-loader.d.ts +3 -0
- package/dist/tool-loader.js +138 -0
- package/dist/tools/cli.d.ts +3 -0
- package/dist/tools/cli.js +86 -0
- package/dist/tools/index.d.ts +13 -0
- package/dist/tools/index.js +29 -0
- package/dist/tools/memory.d.ts +3 -0
- package/dist/tools/memory.js +128 -0
- package/dist/tools/read.d.ts +3 -0
- package/dist/tools/read.js +46 -0
- package/dist/tools/sandbox-cli.d.ts +4 -0
- package/dist/tools/sandbox-cli.js +48 -0
- package/dist/tools/sandbox-memory.d.ts +4 -0
- package/dist/tools/sandbox-memory.js +117 -0
- package/dist/tools/sandbox-read.d.ts +4 -0
- package/dist/tools/sandbox-read.js +25 -0
- package/dist/tools/sandbox-write.d.ts +4 -0
- package/dist/tools/sandbox-write.js +26 -0
- package/dist/tools/shared.d.ts +38 -0
- package/dist/tools/shared.js +69 -0
- package/dist/tools/write.d.ts +3 -0
- package/dist/tools/write.js +28 -0
- package/dist/workflows.d.ts +8 -0
- package/dist/workflows.js +81 -0
- package/package.json +57 -0
package/dist/loader.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { readFile, mkdir, writeFile } from "fs/promises";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { randomUUID } from "crypto";
|
|
4
|
+
import { execSync } from "child_process";
|
|
5
|
+
import { getModel } from "@mariozechner/pi-ai";
|
|
6
|
+
import yaml from "js-yaml";
|
|
7
|
+
import { discoverSkills, formatSkillsForPrompt } from "./skills.js";
|
|
8
|
+
import { loadKnowledge, formatKnowledgeForPrompt } from "./knowledge.js";
|
|
9
|
+
import { discoverWorkflows, formatWorkflowsForPrompt } from "./workflows.js";
|
|
10
|
+
import { loadEnvConfig } from "./config.js";
|
|
11
|
+
import { discoverSubAgents, formatSubAgentsForPrompt } from "./agents.js";
|
|
12
|
+
import { loadExamples, formatExamplesForPrompt } from "./examples.js";
|
|
13
|
+
import { validateCompliance, loadComplianceContext } from "./compliance.js";
|
|
14
|
+
async function readFileOr(path, fallback) {
|
|
15
|
+
try {
|
|
16
|
+
return await readFile(path, "utf-8");
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return fallback;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function parseModelString(modelStr) {
|
|
23
|
+
const colonIndex = modelStr.indexOf(":");
|
|
24
|
+
if (colonIndex === -1) {
|
|
25
|
+
throw new Error(`Invalid model format: "${modelStr}". Expected "provider:model" (e.g., "anthropic:claude-sonnet-4-5-20250929")`);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
provider: modelStr.slice(0, colonIndex),
|
|
29
|
+
modelId: modelStr.slice(colonIndex + 1),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async function ensureGitagentDir(agentDir) {
|
|
33
|
+
const gitagentDir = join(agentDir, ".gitagent");
|
|
34
|
+
await mkdir(gitagentDir, { recursive: true });
|
|
35
|
+
// Ensure .gitagent is in .gitignore
|
|
36
|
+
const gitignorePath = join(agentDir, ".gitignore");
|
|
37
|
+
try {
|
|
38
|
+
const gitignore = await readFile(gitignorePath, "utf-8");
|
|
39
|
+
if (!gitignore.includes(".gitagent")) {
|
|
40
|
+
await writeFile(gitignorePath, gitignore.trimEnd() + "\n.gitagent/\n", "utf-8");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// No .gitignore or can't read — that's fine
|
|
45
|
+
}
|
|
46
|
+
return gitagentDir;
|
|
47
|
+
}
|
|
48
|
+
async function writeSessionState(gitagentDir) {
|
|
49
|
+
const sessionId = randomUUID();
|
|
50
|
+
const state = {
|
|
51
|
+
session_id: sessionId,
|
|
52
|
+
started_at: new Date().toISOString(),
|
|
53
|
+
};
|
|
54
|
+
await writeFile(join(gitagentDir, "state.json"), JSON.stringify(state, null, 2), "utf-8");
|
|
55
|
+
return sessionId;
|
|
56
|
+
}
|
|
57
|
+
function deepMerge(base, override) {
|
|
58
|
+
const result = { ...base };
|
|
59
|
+
for (const key of Object.keys(override)) {
|
|
60
|
+
if (result[key] &&
|
|
61
|
+
typeof result[key] === "object" &&
|
|
62
|
+
!Array.isArray(result[key]) &&
|
|
63
|
+
typeof override[key] === "object" &&
|
|
64
|
+
!Array.isArray(override[key])) {
|
|
65
|
+
result[key] = deepMerge(result[key], override[key]);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
result[key] = override[key];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
async function resolveInheritance(manifest, agentDir, gitagentDir) {
|
|
74
|
+
if (!manifest.extends) {
|
|
75
|
+
return { manifest, parentRules: "" };
|
|
76
|
+
}
|
|
77
|
+
const depsDir = join(gitagentDir, "deps");
|
|
78
|
+
await mkdir(depsDir, { recursive: true });
|
|
79
|
+
// Clone parent into .gitagent/deps/
|
|
80
|
+
const parentName = manifest.extends.split("/").pop()?.replace(/\.git$/, "") || "parent";
|
|
81
|
+
const parentDir = join(depsDir, parentName);
|
|
82
|
+
try {
|
|
83
|
+
execSync(`git clone --depth 1 "${manifest.extends}" "${parentDir}" 2>/dev/null || true`, {
|
|
84
|
+
cwd: agentDir,
|
|
85
|
+
stdio: "pipe",
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Clone failed, continue without parent
|
|
90
|
+
return { manifest, parentRules: "" };
|
|
91
|
+
}
|
|
92
|
+
// Load parent manifest
|
|
93
|
+
let parentManifest;
|
|
94
|
+
try {
|
|
95
|
+
const parentRaw = await readFile(join(parentDir, "agent.yaml"), "utf-8");
|
|
96
|
+
parentManifest = yaml.load(parentRaw);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return { manifest, parentRules: "" };
|
|
100
|
+
}
|
|
101
|
+
// Deep merge: child wins
|
|
102
|
+
const merged = deepMerge(parentManifest, manifest);
|
|
103
|
+
// Tools and skills: union, child shadows
|
|
104
|
+
if (parentManifest.tools && manifest.tools) {
|
|
105
|
+
const toolSet = new Set([...parentManifest.tools, ...manifest.tools]);
|
|
106
|
+
merged.tools = [...toolSet];
|
|
107
|
+
}
|
|
108
|
+
// Load parent RULES.md for appending (union)
|
|
109
|
+
const parentRules = await readFileOr(join(parentDir, "RULES.md"), "");
|
|
110
|
+
return { manifest: merged, parentRules };
|
|
111
|
+
}
|
|
112
|
+
async function resolveDependencies(manifest, agentDir, gitagentDir) {
|
|
113
|
+
if (!manifest.dependencies || manifest.dependencies.length === 0)
|
|
114
|
+
return;
|
|
115
|
+
const depsDir = join(gitagentDir, "deps");
|
|
116
|
+
await mkdir(depsDir, { recursive: true });
|
|
117
|
+
for (const dep of manifest.dependencies) {
|
|
118
|
+
const depDir = join(depsDir, dep.name);
|
|
119
|
+
try {
|
|
120
|
+
execSync(`git clone --depth 1 --branch "${dep.version}" "${dep.source}" "${depDir}" 2>/dev/null || true`, { cwd: agentDir, stdio: "pipe" });
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Clone failed, skip this dependency
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export async function loadAgent(agentDir, modelFlag, envFlag) {
|
|
128
|
+
// Parse agent.yaml
|
|
129
|
+
const manifestRaw = await readFile(join(agentDir, "agent.yaml"), "utf-8");
|
|
130
|
+
let manifest = yaml.load(manifestRaw);
|
|
131
|
+
// Load environment config
|
|
132
|
+
const envConfig = await loadEnvConfig(agentDir, envFlag);
|
|
133
|
+
// Ensure .gitagent/ directory and write session state
|
|
134
|
+
const gitagentDir = await ensureGitagentDir(agentDir);
|
|
135
|
+
const sessionId = await writeSessionState(gitagentDir);
|
|
136
|
+
// Resolve inheritance (Phase 2.4)
|
|
137
|
+
let parentRules = "";
|
|
138
|
+
if (manifest.extends) {
|
|
139
|
+
const resolved = await resolveInheritance(manifest, agentDir, gitagentDir);
|
|
140
|
+
manifest = resolved.manifest;
|
|
141
|
+
parentRules = resolved.parentRules;
|
|
142
|
+
}
|
|
143
|
+
// Resolve dependencies (Phase 2.5)
|
|
144
|
+
await resolveDependencies(manifest, agentDir, gitagentDir);
|
|
145
|
+
// Validate compliance (Phase 3)
|
|
146
|
+
const complianceWarnings = validateCompliance(manifest);
|
|
147
|
+
// Read identity files
|
|
148
|
+
const soul = await readFileOr(join(agentDir, "SOUL.md"), "");
|
|
149
|
+
const rules = await readFileOr(join(agentDir, "RULES.md"), "");
|
|
150
|
+
const duties = await readFileOr(join(agentDir, "DUTIES.md"), "");
|
|
151
|
+
const agentsMd = await readFileOr(join(agentDir, "AGENTS.md"), "");
|
|
152
|
+
// Build system prompt
|
|
153
|
+
const parts = [];
|
|
154
|
+
parts.push(`# ${manifest.name} v${manifest.version}\n${manifest.description}`);
|
|
155
|
+
if (soul)
|
|
156
|
+
parts.push(soul);
|
|
157
|
+
if (rules)
|
|
158
|
+
parts.push(rules);
|
|
159
|
+
if (parentRules)
|
|
160
|
+
parts.push(parentRules); // Append parent rules (union)
|
|
161
|
+
if (duties)
|
|
162
|
+
parts.push(duties);
|
|
163
|
+
if (agentsMd)
|
|
164
|
+
parts.push(agentsMd);
|
|
165
|
+
parts.push(`# Memory\n\nYou have a memory file at memory/MEMORY.md. Use the \`memory\` tool to load and save memories. Each save creates a git commit, so your memory has full history. You can also use the \`cli\` tool to run git commands for deeper memory inspection (git log, git diff, git show).`);
|
|
166
|
+
// Discover and load knowledge
|
|
167
|
+
const knowledge = await loadKnowledge(agentDir);
|
|
168
|
+
const knowledgeBlock = formatKnowledgeForPrompt(knowledge);
|
|
169
|
+
if (knowledgeBlock)
|
|
170
|
+
parts.push(knowledgeBlock);
|
|
171
|
+
// Discover skills (filtered by manifest.skills if set)
|
|
172
|
+
let skills = await discoverSkills(agentDir);
|
|
173
|
+
if (manifest.skills && manifest.skills.length > 0) {
|
|
174
|
+
const allowed = new Set(manifest.skills);
|
|
175
|
+
skills = skills.filter((s) => allowed.has(s.name));
|
|
176
|
+
}
|
|
177
|
+
const skillsBlock = formatSkillsForPrompt(skills);
|
|
178
|
+
if (skillsBlock)
|
|
179
|
+
parts.push(skillsBlock);
|
|
180
|
+
// Discover workflows
|
|
181
|
+
const workflows = await discoverWorkflows(agentDir);
|
|
182
|
+
const workflowsBlock = formatWorkflowsForPrompt(workflows);
|
|
183
|
+
if (workflowsBlock)
|
|
184
|
+
parts.push(workflowsBlock);
|
|
185
|
+
// Discover sub-agents (Phase 2.1)
|
|
186
|
+
const subAgents = await discoverSubAgents(agentDir);
|
|
187
|
+
const subAgentsBlock = formatSubAgentsForPrompt(subAgents);
|
|
188
|
+
if (subAgentsBlock)
|
|
189
|
+
parts.push(subAgentsBlock);
|
|
190
|
+
// Load examples (Phase 2.3)
|
|
191
|
+
const examples = await loadExamples(agentDir);
|
|
192
|
+
const examplesBlock = formatExamplesForPrompt(examples);
|
|
193
|
+
if (examplesBlock)
|
|
194
|
+
parts.push(examplesBlock);
|
|
195
|
+
// Load compliance context (Phase 3)
|
|
196
|
+
const complianceBlock = await loadComplianceContext(agentDir);
|
|
197
|
+
if (complianceBlock)
|
|
198
|
+
parts.push(complianceBlock);
|
|
199
|
+
const systemPrompt = parts.join("\n\n");
|
|
200
|
+
// Resolve model — env config model_override > CLI flag > manifest preferred
|
|
201
|
+
const modelStr = envConfig.model_override || modelFlag || manifest.model.preferred;
|
|
202
|
+
if (!modelStr) {
|
|
203
|
+
throw new Error('No model configured. Either:\n - Set model.preferred in agent.yaml (e.g., "anthropic:claude-sonnet-4-5-20250929")\n - Pass --model provider:model on the command line');
|
|
204
|
+
}
|
|
205
|
+
const { provider, modelId } = parseModelString(modelStr);
|
|
206
|
+
const model = getModel(provider, modelId);
|
|
207
|
+
return {
|
|
208
|
+
systemPrompt,
|
|
209
|
+
manifest,
|
|
210
|
+
model,
|
|
211
|
+
skills,
|
|
212
|
+
knowledge,
|
|
213
|
+
workflows,
|
|
214
|
+
subAgents,
|
|
215
|
+
examples,
|
|
216
|
+
envConfig,
|
|
217
|
+
sessionId,
|
|
218
|
+
agentDir,
|
|
219
|
+
gitagentDir,
|
|
220
|
+
complianceWarnings,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface SandboxConfig {
|
|
2
|
+
provider: "e2b";
|
|
3
|
+
template?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
repository?: string;
|
|
6
|
+
token?: string;
|
|
7
|
+
session?: string;
|
|
8
|
+
autoCommit?: boolean;
|
|
9
|
+
envs?: Record<string, string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Wraps the gitmachine GitMachine + Machine instances.
|
|
13
|
+
* Types are `any` because gitmachine is an optional peer dependency
|
|
14
|
+
* loaded via dynamic import — we don't have compile-time types.
|
|
15
|
+
*/
|
|
16
|
+
export interface SandboxContext {
|
|
17
|
+
/** GitMachine instance (gitmachine) — provides run(), commit(), start(), stop() */
|
|
18
|
+
gitMachine: any;
|
|
19
|
+
/** Underlying Machine instance — provides readFile(), writeFile() */
|
|
20
|
+
machine: any;
|
|
21
|
+
/** Absolute path to the repo root inside the sandbox (e.g. /home/user/repo) */
|
|
22
|
+
repoPath: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create a SandboxContext by dynamically importing gitmachine.
|
|
26
|
+
* Throws a clear error if gitmachine is not installed.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createSandboxContext(config: SandboxConfig, dir: string): Promise<SandboxContext>;
|
package/dist/sandbox.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
// ── Factory ─────────────────────────────────────────────────────────────
|
|
3
|
+
function detectRepoUrl(dir) {
|
|
4
|
+
try {
|
|
5
|
+
return execSync("git remote get-url origin", { cwd: dir, stdio: "pipe" })
|
|
6
|
+
.toString()
|
|
7
|
+
.trim();
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a SandboxContext by dynamically importing gitmachine.
|
|
15
|
+
* Throws a clear error if gitmachine is not installed.
|
|
16
|
+
*/
|
|
17
|
+
export async function createSandboxContext(config, dir) {
|
|
18
|
+
let gitmachine;
|
|
19
|
+
try {
|
|
20
|
+
// @ts-ignore — gitmachine is an optional peer dependency
|
|
21
|
+
gitmachine = await import("gitmachine");
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new Error("Sandbox mode requires the 'gitmachine' package.\n" +
|
|
25
|
+
"Install it with: npm install gitmachine");
|
|
26
|
+
}
|
|
27
|
+
const token = config.token
|
|
28
|
+
|| process.env.GITHUB_TOKEN
|
|
29
|
+
|| process.env.GIT_TOKEN;
|
|
30
|
+
const repository = config.repository || detectRepoUrl(dir);
|
|
31
|
+
if (!repository) {
|
|
32
|
+
throw new Error("Sandbox mode requires a repository URL. Provide it via --sandbox config, " +
|
|
33
|
+
"or ensure the working directory has a git remote named 'origin'.");
|
|
34
|
+
}
|
|
35
|
+
const gitMachine = new gitmachine.GitMachine({
|
|
36
|
+
provider: config.provider,
|
|
37
|
+
template: config.template,
|
|
38
|
+
timeout: config.timeout,
|
|
39
|
+
repository,
|
|
40
|
+
token,
|
|
41
|
+
session: config.session,
|
|
42
|
+
autoCommit: config.autoCommit ?? true,
|
|
43
|
+
envs: config.envs,
|
|
44
|
+
});
|
|
45
|
+
// The repo path inside the sandbox is determined by gitmachine after start().
|
|
46
|
+
// Convention: /home/user/<repo-name>
|
|
47
|
+
const repoName = repository.split("/").pop()?.replace(/\.git$/, "") || "repo";
|
|
48
|
+
const repoPath = `/home/user/${repoName}`;
|
|
49
|
+
return {
|
|
50
|
+
gitMachine,
|
|
51
|
+
machine: gitMachine.machine,
|
|
52
|
+
repoPath,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
2
|
+
import type { GCHooks } from "./sdk-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Wraps a tool's execute function with programmatic SDK hook callbacks.
|
|
5
|
+
* Mirrors the pattern in hooks.ts:wrapToolWithHooks() but uses in-process
|
|
6
|
+
* callbacks instead of spawning shell scripts.
|
|
7
|
+
*/
|
|
8
|
+
export declare function wrapToolWithProgrammaticHooks(tool: AgentTool<any>, hooks: GCHooks, sessionId: string, agentName: string): AgentTool<any>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wraps a tool's execute function with programmatic SDK hook callbacks.
|
|
3
|
+
* Mirrors the pattern in hooks.ts:wrapToolWithHooks() but uses in-process
|
|
4
|
+
* callbacks instead of spawning shell scripts.
|
|
5
|
+
*/
|
|
6
|
+
export function wrapToolWithProgrammaticHooks(tool, hooks, sessionId, agentName) {
|
|
7
|
+
if (!hooks.preToolUse)
|
|
8
|
+
return tool;
|
|
9
|
+
const originalExecute = tool.execute;
|
|
10
|
+
const preToolUse = hooks.preToolUse;
|
|
11
|
+
return {
|
|
12
|
+
...tool,
|
|
13
|
+
execute: async (toolCallId, args, signal, onUpdate) => {
|
|
14
|
+
const ctx = {
|
|
15
|
+
sessionId,
|
|
16
|
+
agentName,
|
|
17
|
+
event: "PreToolUse",
|
|
18
|
+
toolName: tool.name,
|
|
19
|
+
args,
|
|
20
|
+
};
|
|
21
|
+
const result = await preToolUse(ctx);
|
|
22
|
+
if (result.action === "block") {
|
|
23
|
+
throw new Error(`Tool "${tool.name}" blocked by hook: ${result.reason || "no reason given"}`);
|
|
24
|
+
}
|
|
25
|
+
const finalArgs = result.action === "modify" && result.args
|
|
26
|
+
? result.args
|
|
27
|
+
: args;
|
|
28
|
+
return originalExecute.call(tool, toolCallId, finalArgs, signal, onUpdate);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { AgentManifest } from "./loader.js";
|
|
2
|
+
export type GCMessage = GCAssistantMessage | GCUserMessage | GCToolUseMessage | GCToolResultMessage | GCSystemMessage | GCStreamDelta;
|
|
3
|
+
export interface GCAssistantMessage {
|
|
4
|
+
type: "assistant";
|
|
5
|
+
content: string;
|
|
6
|
+
thinking?: string;
|
|
7
|
+
model: string;
|
|
8
|
+
provider: string;
|
|
9
|
+
stopReason: "stop" | "length" | "toolUse" | "error" | "aborted";
|
|
10
|
+
errorMessage?: string;
|
|
11
|
+
usage?: {
|
|
12
|
+
inputTokens: number;
|
|
13
|
+
outputTokens: number;
|
|
14
|
+
cacheReadTokens: number;
|
|
15
|
+
cacheWriteTokens: number;
|
|
16
|
+
totalTokens: number;
|
|
17
|
+
costUsd: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface GCUserMessage {
|
|
21
|
+
type: "user";
|
|
22
|
+
content: string;
|
|
23
|
+
}
|
|
24
|
+
export interface GCToolUseMessage {
|
|
25
|
+
type: "tool_use";
|
|
26
|
+
toolCallId: string;
|
|
27
|
+
toolName: string;
|
|
28
|
+
args: Record<string, any>;
|
|
29
|
+
}
|
|
30
|
+
export interface GCToolResultMessage {
|
|
31
|
+
type: "tool_result";
|
|
32
|
+
toolCallId: string;
|
|
33
|
+
toolName: string;
|
|
34
|
+
content: string;
|
|
35
|
+
isError: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface GCSystemMessage {
|
|
38
|
+
type: "system";
|
|
39
|
+
subtype: "session_start" | "session_end" | "hook_blocked" | "compliance_warning" | "error";
|
|
40
|
+
content: string;
|
|
41
|
+
metadata?: Record<string, any>;
|
|
42
|
+
}
|
|
43
|
+
export interface GCStreamDelta {
|
|
44
|
+
type: "delta";
|
|
45
|
+
deltaType: "text" | "thinking";
|
|
46
|
+
content: string;
|
|
47
|
+
}
|
|
48
|
+
export type GCHookEvent = "SessionStart" | "PreToolUse" | "PostResponse" | "OnError";
|
|
49
|
+
export interface GCHookContext {
|
|
50
|
+
sessionId: string;
|
|
51
|
+
agentName: string;
|
|
52
|
+
event: GCHookEvent;
|
|
53
|
+
}
|
|
54
|
+
export interface GCPreToolUseContext extends GCHookContext {
|
|
55
|
+
event: "PreToolUse";
|
|
56
|
+
toolName: string;
|
|
57
|
+
args: Record<string, any>;
|
|
58
|
+
}
|
|
59
|
+
export interface GCHookResult {
|
|
60
|
+
action: "allow" | "block" | "modify";
|
|
61
|
+
reason?: string;
|
|
62
|
+
args?: Record<string, any>;
|
|
63
|
+
}
|
|
64
|
+
export interface GCHooks {
|
|
65
|
+
onSessionStart?: (ctx: GCHookContext) => Promise<GCHookResult> | GCHookResult;
|
|
66
|
+
preToolUse?: (ctx: GCPreToolUseContext) => Promise<GCHookResult> | GCHookResult;
|
|
67
|
+
postResponse?: (ctx: GCHookContext) => Promise<void> | void;
|
|
68
|
+
onError?: (ctx: GCHookContext & {
|
|
69
|
+
error: string;
|
|
70
|
+
}) => Promise<void> | void;
|
|
71
|
+
}
|
|
72
|
+
export interface GCToolDefinition {
|
|
73
|
+
name: string;
|
|
74
|
+
description: string;
|
|
75
|
+
inputSchema: Record<string, any>;
|
|
76
|
+
handler: (args: any, signal?: AbortSignal) => Promise<string | {
|
|
77
|
+
text: string;
|
|
78
|
+
details?: any;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
export interface LocalRepoOptions {
|
|
82
|
+
url: string;
|
|
83
|
+
token: string;
|
|
84
|
+
dir?: string;
|
|
85
|
+
session?: string;
|
|
86
|
+
}
|
|
87
|
+
export interface SandboxOptions {
|
|
88
|
+
provider: "e2b";
|
|
89
|
+
template?: string;
|
|
90
|
+
timeout?: number;
|
|
91
|
+
repository?: string;
|
|
92
|
+
token?: string;
|
|
93
|
+
session?: string;
|
|
94
|
+
autoCommit?: boolean;
|
|
95
|
+
envs?: Record<string, string>;
|
|
96
|
+
}
|
|
97
|
+
export interface QueryOptions {
|
|
98
|
+
prompt: string | AsyncIterable<GCUserMessage>;
|
|
99
|
+
dir?: string;
|
|
100
|
+
model?: string;
|
|
101
|
+
env?: string;
|
|
102
|
+
systemPrompt?: string;
|
|
103
|
+
systemPromptSuffix?: string;
|
|
104
|
+
tools?: GCToolDefinition[];
|
|
105
|
+
replaceBuiltinTools?: boolean;
|
|
106
|
+
allowedTools?: string[];
|
|
107
|
+
disallowedTools?: string[];
|
|
108
|
+
repo?: LocalRepoOptions;
|
|
109
|
+
sandbox?: SandboxOptions | boolean;
|
|
110
|
+
hooks?: GCHooks;
|
|
111
|
+
maxTurns?: number;
|
|
112
|
+
abortController?: AbortController;
|
|
113
|
+
sessionId?: string;
|
|
114
|
+
constraints?: {
|
|
115
|
+
temperature?: number;
|
|
116
|
+
maxTokens?: number;
|
|
117
|
+
topP?: number;
|
|
118
|
+
topK?: number;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export interface Query extends AsyncGenerator<GCMessage, void, undefined> {
|
|
122
|
+
abort(): void;
|
|
123
|
+
steer(message: string): void;
|
|
124
|
+
sessionId(): string;
|
|
125
|
+
manifest(): AgentManifest;
|
|
126
|
+
messages(): GCMessage[];
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { GCToolDefinition, Query, QueryOptions } from "./sdk-types.js";
|
|
2
|
+
export declare function query(options: QueryOptions): Query;
|
|
3
|
+
export declare function tool(name: string, description: string, inputSchema: Record<string, any>, handler: (args: any, signal?: AbortSignal) => Promise<string | {
|
|
4
|
+
text: string;
|
|
5
|
+
details?: any;
|
|
6
|
+
}>): GCToolDefinition;
|