@mariozechner/pi-coding-agent 0.22.5 → 0.23.1
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 +20 -0
- package/README.md +54 -2
- package/dist/cli/args.d.ts +1 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +5 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session.d.ts +9 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +64 -11
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/custom-tools/index.d.ts +6 -0
- package/dist/core/custom-tools/index.d.ts.map +1 -0
- package/dist/core/custom-tools/index.js +5 -0
- package/dist/core/custom-tools/index.js.map +1 -0
- package/dist/core/custom-tools/loader.d.ts +24 -0
- package/dist/core/custom-tools/loader.d.ts.map +1 -0
- package/dist/core/custom-tools/loader.js +233 -0
- package/dist/core/custom-tools/loader.js.map +1 -0
- package/dist/core/custom-tools/types.d.ts +81 -0
- package/dist/core/custom-tools/types.d.ts.map +1 -0
- package/dist/core/custom-tools/types.js +8 -0
- package/dist/core/custom-tools/types.js.map +1 -0
- package/dist/core/hooks/index.d.ts +1 -1
- package/dist/core/hooks/index.d.ts.map +1 -1
- package/dist/core/hooks/index.js.map +1 -1
- package/dist/core/hooks/types.d.ts +14 -19
- package/dist/core/hooks/types.d.ts.map +1 -1
- package/dist/core/hooks/types.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +7 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +22 -3
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +4 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +71 -20
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +11 -2
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +66 -12
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +26 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +27 -2
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/docs/custom-tools.md +354 -0
- package/docs/hooks.md +54 -34
- package/examples/custom-tools/README.md +101 -0
- package/examples/custom-tools/hello.ts +20 -0
- package/examples/custom-tools/question.ts +83 -0
- package/examples/custom-tools/todo.ts +192 -0
- package/examples/hooks/README.md +79 -0
- package/examples/hooks/file-trigger.ts +36 -0
- package/examples/hooks/git-checkpoint.ts +48 -0
- package/examples/hooks/permission-gate.ts +38 -0
- package/examples/hooks/protected-paths.ts +30 -0
- package/package.json +7 -6
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom tool loader - loads TypeScript tool modules using jiti.
|
|
3
|
+
*/
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import * as fs from "node:fs";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import * as os from "node:os";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { createJiti } from "jiti";
|
|
11
|
+
import { getAgentDir } from "../../config.js";
|
|
12
|
+
// Create require function to resolve module paths at runtime
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
// Lazily computed aliases - resolved at runtime to handle global installs
|
|
15
|
+
let _aliases = null;
|
|
16
|
+
function getAliases() {
|
|
17
|
+
if (_aliases)
|
|
18
|
+
return _aliases;
|
|
19
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const packageIndex = path.resolve(__dirname, "../..", "index.js");
|
|
21
|
+
_aliases = {
|
|
22
|
+
"@mariozechner/pi-coding-agent": packageIndex,
|
|
23
|
+
"@mariozechner/pi-tui": require.resolve("@mariozechner/pi-tui"),
|
|
24
|
+
"@mariozechner/pi-ai": require.resolve("@mariozechner/pi-ai"),
|
|
25
|
+
"@sinclair/typebox": require.resolve("@sinclair/typebox"),
|
|
26
|
+
};
|
|
27
|
+
return _aliases;
|
|
28
|
+
}
|
|
29
|
+
const UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
|
|
30
|
+
function normalizeUnicodeSpaces(str) {
|
|
31
|
+
return str.replace(UNICODE_SPACES, " ");
|
|
32
|
+
}
|
|
33
|
+
function expandPath(p) {
|
|
34
|
+
const normalized = normalizeUnicodeSpaces(p);
|
|
35
|
+
if (normalized.startsWith("~/")) {
|
|
36
|
+
return path.join(os.homedir(), normalized.slice(2));
|
|
37
|
+
}
|
|
38
|
+
if (normalized.startsWith("~")) {
|
|
39
|
+
return path.join(os.homedir(), normalized.slice(1));
|
|
40
|
+
}
|
|
41
|
+
return normalized;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Resolve tool path.
|
|
45
|
+
* - Absolute paths used as-is
|
|
46
|
+
* - Paths starting with ~ expanded to home directory
|
|
47
|
+
* - Relative paths resolved from cwd
|
|
48
|
+
*/
|
|
49
|
+
function resolveToolPath(toolPath, cwd) {
|
|
50
|
+
const expanded = expandPath(toolPath);
|
|
51
|
+
if (path.isAbsolute(expanded)) {
|
|
52
|
+
return expanded;
|
|
53
|
+
}
|
|
54
|
+
// Relative paths resolved from cwd
|
|
55
|
+
return path.resolve(cwd, expanded);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Execute a command and return stdout/stderr/code.
|
|
59
|
+
*/
|
|
60
|
+
async function execCommand(command, args, cwd) {
|
|
61
|
+
return new Promise((resolve) => {
|
|
62
|
+
const proc = spawn(command, args, {
|
|
63
|
+
cwd,
|
|
64
|
+
shell: false,
|
|
65
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
66
|
+
});
|
|
67
|
+
let stdout = "";
|
|
68
|
+
let stderr = "";
|
|
69
|
+
proc.stdout.on("data", (data) => {
|
|
70
|
+
stdout += data.toString();
|
|
71
|
+
});
|
|
72
|
+
proc.stderr.on("data", (data) => {
|
|
73
|
+
stderr += data.toString();
|
|
74
|
+
});
|
|
75
|
+
proc.on("close", (code) => {
|
|
76
|
+
resolve({
|
|
77
|
+
stdout,
|
|
78
|
+
stderr,
|
|
79
|
+
code: code ?? 0,
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
proc.on("error", (err) => {
|
|
83
|
+
resolve({
|
|
84
|
+
stdout,
|
|
85
|
+
stderr: stderr || err.message,
|
|
86
|
+
code: 1,
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Create a no-op UI context for headless modes.
|
|
93
|
+
*/
|
|
94
|
+
function createNoOpUIContext() {
|
|
95
|
+
return {
|
|
96
|
+
select: async () => null,
|
|
97
|
+
confirm: async () => false,
|
|
98
|
+
input: async () => null,
|
|
99
|
+
notify: () => { },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Load a single tool module using jiti.
|
|
104
|
+
*/
|
|
105
|
+
async function loadTool(toolPath, cwd, sharedApi) {
|
|
106
|
+
const resolvedPath = resolveToolPath(toolPath, cwd);
|
|
107
|
+
try {
|
|
108
|
+
// Create jiti instance for TypeScript/ESM loading
|
|
109
|
+
// Use aliases to resolve package imports since tools are loaded from user directories
|
|
110
|
+
// (e.g. ~/.pi/agent/tools) but import from packages installed with pi-coding-agent
|
|
111
|
+
const jiti = createJiti(import.meta.url, {
|
|
112
|
+
alias: getAliases(),
|
|
113
|
+
});
|
|
114
|
+
// Import the module
|
|
115
|
+
const module = await jiti.import(resolvedPath, { default: true });
|
|
116
|
+
const factory = module;
|
|
117
|
+
if (typeof factory !== "function") {
|
|
118
|
+
return { tools: null, error: "Tool must export a default function" };
|
|
119
|
+
}
|
|
120
|
+
// Call factory with shared API
|
|
121
|
+
const result = await factory(sharedApi);
|
|
122
|
+
// Handle single tool or array of tools
|
|
123
|
+
const toolsArray = Array.isArray(result) ? result : [result];
|
|
124
|
+
const loadedTools = toolsArray.map((tool) => ({
|
|
125
|
+
path: toolPath,
|
|
126
|
+
resolvedPath,
|
|
127
|
+
tool,
|
|
128
|
+
}));
|
|
129
|
+
return { tools: loadedTools, error: null };
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
133
|
+
return { tools: null, error: `Failed to load tool: ${message}` };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Load all tools from configuration.
|
|
138
|
+
* @param paths - Array of tool file paths
|
|
139
|
+
* @param cwd - Current working directory for resolving relative paths
|
|
140
|
+
* @param builtInToolNames - Names of built-in tools to check for conflicts
|
|
141
|
+
*/
|
|
142
|
+
export async function loadCustomTools(paths, cwd, builtInToolNames) {
|
|
143
|
+
const tools = [];
|
|
144
|
+
const errors = [];
|
|
145
|
+
const seenNames = new Set(builtInToolNames);
|
|
146
|
+
// Shared API object - all tools get the same instance
|
|
147
|
+
const sharedApi = {
|
|
148
|
+
cwd,
|
|
149
|
+
exec: (command, args) => execCommand(command, args, cwd),
|
|
150
|
+
ui: createNoOpUIContext(),
|
|
151
|
+
hasUI: false,
|
|
152
|
+
};
|
|
153
|
+
for (const toolPath of paths) {
|
|
154
|
+
const { tools: loadedTools, error } = await loadTool(toolPath, cwd, sharedApi);
|
|
155
|
+
if (error) {
|
|
156
|
+
errors.push({ path: toolPath, error });
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (loadedTools) {
|
|
160
|
+
for (const loadedTool of loadedTools) {
|
|
161
|
+
// Check for name conflicts
|
|
162
|
+
if (seenNames.has(loadedTool.tool.name)) {
|
|
163
|
+
errors.push({
|
|
164
|
+
path: toolPath,
|
|
165
|
+
error: `Tool name "${loadedTool.tool.name}" conflicts with existing tool`,
|
|
166
|
+
});
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
seenNames.add(loadedTool.tool.name);
|
|
170
|
+
tools.push(loadedTool);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
tools,
|
|
176
|
+
errors,
|
|
177
|
+
setUIContext(uiContext, hasUI) {
|
|
178
|
+
sharedApi.ui = uiContext;
|
|
179
|
+
sharedApi.hasUI = hasUI;
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Discover tool files from a directory.
|
|
185
|
+
* Returns all .ts files in the directory (non-recursive).
|
|
186
|
+
*/
|
|
187
|
+
function discoverToolsInDir(dir) {
|
|
188
|
+
if (!fs.existsSync(dir)) {
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
193
|
+
return entries.filter((e) => e.isFile() && e.name.endsWith(".ts")).map((e) => path.join(dir, e.name));
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return [];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Discover and load tools from standard locations:
|
|
201
|
+
* 1. ~/.pi/agent/tools/*.ts (global)
|
|
202
|
+
* 2. cwd/.pi/tools/*.ts (project-local)
|
|
203
|
+
*
|
|
204
|
+
* Plus any explicitly configured paths from settings or CLI.
|
|
205
|
+
*
|
|
206
|
+
* @param configuredPaths - Explicit paths from settings.json and CLI --tool flags
|
|
207
|
+
* @param cwd - Current working directory
|
|
208
|
+
* @param builtInToolNames - Names of built-in tools to check for conflicts
|
|
209
|
+
*/
|
|
210
|
+
export async function discoverAndLoadCustomTools(configuredPaths, cwd, builtInToolNames) {
|
|
211
|
+
const allPaths = [];
|
|
212
|
+
const seen = new Set();
|
|
213
|
+
// Helper to add paths without duplicates
|
|
214
|
+
const addPaths = (paths) => {
|
|
215
|
+
for (const p of paths) {
|
|
216
|
+
const resolved = path.resolve(p);
|
|
217
|
+
if (!seen.has(resolved)) {
|
|
218
|
+
seen.add(resolved);
|
|
219
|
+
allPaths.push(p);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
// 1. Global tools: ~/.pi/agent/tools/
|
|
224
|
+
const globalToolsDir = path.join(getAgentDir(), "tools");
|
|
225
|
+
addPaths(discoverToolsInDir(globalToolsDir));
|
|
226
|
+
// 2. Project-local tools: cwd/.pi/tools/
|
|
227
|
+
const localToolsDir = path.join(cwd, ".pi", "tools");
|
|
228
|
+
addPaths(discoverToolsInDir(localToolsDir));
|
|
229
|
+
// 3. Explicitly configured paths (can override/add)
|
|
230
|
+
addPaths(configuredPaths.map((p) => resolveToolPath(p, cwd)));
|
|
231
|
+
return loadCustomTools(allPaths, cwd, builtInToolNames);
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/core/custom-tools/loader.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WA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7C,yCAAyC;IACzC,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACrD,QAAQ,CAAC,kBAAkB,CAAC,aAAa,CAAC,CAAC,CAAC;IAE5C,oDAAoD;IACpD,QAAQ,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAE9D,OAAO,eAAe,CAAC,QAAQ,EAAE,GAAG,EAAE,gBAAgB,CAAC,CAAC;AAAA,CACxD","sourcesContent":["/**\n * Custom tool loader - loads TypeScript tool modules using jiti.\n */\n\nimport { spawn } from \"node:child_process\";\nimport * as fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { createJiti } from \"jiti\";\nimport { getAgentDir } from \"../../config.js\";\nimport type { HookUIContext } from \"../hooks/types.js\";\nimport type { CustomToolFactory, CustomToolsLoadResult, ExecResult, LoadedCustomTool, ToolAPI } from \"./types.js\";\n\n// Create require function to resolve module paths at runtime\nconst require = createRequire(import.meta.url);\n\n// Lazily computed aliases - resolved at runtime to handle global installs\nlet _aliases: Record<string, string> | null = null;\nfunction getAliases(): Record<string, string> {\n\tif (_aliases) return _aliases;\n\n\tconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\tconst packageIndex = path.resolve(__dirname, \"../..\", \"index.js\");\n\n\t_aliases = {\n\t\t\"@mariozechner/pi-coding-agent\": packageIndex,\n\t\t\"@mariozechner/pi-tui\": require.resolve(\"@mariozechner/pi-tui\"),\n\t\t\"@mariozechner/pi-ai\": require.resolve(\"@mariozechner/pi-ai\"),\n\t\t\"@sinclair/typebox\": require.resolve(\"@sinclair/typebox\"),\n\t};\n\treturn _aliases;\n}\n\nconst UNICODE_SPACES = /[\\u00A0\\u2000-\\u200A\\u202F\\u205F\\u3000]/g;\n\nfunction normalizeUnicodeSpaces(str: string): string {\n\treturn str.replace(UNICODE_SPACES, \" \");\n}\n\nfunction expandPath(p: string): string {\n\tconst normalized = normalizeUnicodeSpaces(p);\n\tif (normalized.startsWith(\"~/\")) {\n\t\treturn path.join(os.homedir(), normalized.slice(2));\n\t}\n\tif (normalized.startsWith(\"~\")) {\n\t\treturn path.join(os.homedir(), normalized.slice(1));\n\t}\n\treturn normalized;\n}\n\n/**\n * Resolve tool path.\n * - Absolute paths used as-is\n * - Paths starting with ~ expanded to home directory\n * - Relative paths resolved from cwd\n */\nfunction resolveToolPath(toolPath: string, cwd: string): string {\n\tconst expanded = expandPath(toolPath);\n\n\tif (path.isAbsolute(expanded)) {\n\t\treturn expanded;\n\t}\n\n\t// Relative paths resolved from cwd\n\treturn path.resolve(cwd, expanded);\n}\n\n/**\n * Execute a command and return stdout/stderr/code.\n */\nasync function execCommand(command: string, args: string[], cwd: string): Promise<ExecResult> {\n\treturn new Promise((resolve) => {\n\t\tconst proc = spawn(command, args, {\n\t\t\tcwd,\n\t\t\tshell: false,\n\t\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t\t});\n\n\t\tlet stdout = \"\";\n\t\tlet stderr = \"\";\n\n\t\tproc.stdout.on(\"data\", (data) => {\n\t\t\tstdout += data.toString();\n\t\t});\n\n\t\tproc.stderr.on(\"data\", (data) => {\n\t\t\tstderr += data.toString();\n\t\t});\n\n\t\tproc.on(\"close\", (code) => {\n\t\t\tresolve({\n\t\t\t\tstdout,\n\t\t\t\tstderr,\n\t\t\t\tcode: code ?? 0,\n\t\t\t});\n\t\t});\n\n\t\tproc.on(\"error\", (err) => {\n\t\t\tresolve({\n\t\t\t\tstdout,\n\t\t\t\tstderr: stderr || err.message,\n\t\t\t\tcode: 1,\n\t\t\t});\n\t\t});\n\t});\n}\n\n/**\n * Create a no-op UI context for headless modes.\n */\nfunction createNoOpUIContext(): HookUIContext {\n\treturn {\n\t\tselect: async () => null,\n\t\tconfirm: async () => false,\n\t\tinput: async () => null,\n\t\tnotify: () => {},\n\t};\n}\n\n/**\n * Load a single tool module using jiti.\n */\nasync function loadTool(\n\ttoolPath: string,\n\tcwd: string,\n\tsharedApi: ToolAPI,\n): Promise<{ tools: LoadedCustomTool[] | null; error: string | null }> {\n\tconst resolvedPath = resolveToolPath(toolPath, cwd);\n\n\ttry {\n\t\t// Create jiti instance for TypeScript/ESM loading\n\t\t// Use aliases to resolve package imports since tools are loaded from user directories\n\t\t// (e.g. ~/.pi/agent/tools) but import from packages installed with pi-coding-agent\n\t\tconst jiti = createJiti(import.meta.url, {\n\t\t\talias: getAliases(),\n\t\t});\n\n\t\t// Import the module\n\t\tconst module = await jiti.import(resolvedPath, { default: true });\n\t\tconst factory = module as CustomToolFactory;\n\n\t\tif (typeof factory !== \"function\") {\n\t\t\treturn { tools: null, error: \"Tool must export a default function\" };\n\t\t}\n\n\t\t// Call factory with shared API\n\t\tconst result = await factory(sharedApi);\n\n\t\t// Handle single tool or array of tools\n\t\tconst toolsArray = Array.isArray(result) ? result : [result];\n\n\t\tconst loadedTools: LoadedCustomTool[] = toolsArray.map((tool) => ({\n\t\t\tpath: toolPath,\n\t\t\tresolvedPath,\n\t\t\ttool,\n\t\t}));\n\n\t\treturn { tools: loadedTools, error: null };\n\t} catch (err) {\n\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\treturn { tools: null, error: `Failed to load tool: ${message}` };\n\t}\n}\n\n/**\n * Load all tools from configuration.\n * @param paths - Array of tool file paths\n * @param cwd - Current working directory for resolving relative paths\n * @param builtInToolNames - Names of built-in tools to check for conflicts\n */\nexport async function loadCustomTools(\n\tpaths: string[],\n\tcwd: string,\n\tbuiltInToolNames: string[],\n): Promise<CustomToolsLoadResult> {\n\tconst tools: LoadedCustomTool[] = [];\n\tconst errors: Array<{ path: string; error: string }> = [];\n\tconst seenNames = new Set<string>(builtInToolNames);\n\n\t// Shared API object - all tools get the same instance\n\tconst sharedApi: ToolAPI = {\n\t\tcwd,\n\t\texec: (command: string, args: string[]) => execCommand(command, args, cwd),\n\t\tui: createNoOpUIContext(),\n\t\thasUI: false,\n\t};\n\n\tfor (const toolPath of paths) {\n\t\tconst { tools: loadedTools, error } = await loadTool(toolPath, cwd, sharedApi);\n\n\t\tif (error) {\n\t\t\terrors.push({ path: toolPath, error });\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (loadedTools) {\n\t\t\tfor (const loadedTool of loadedTools) {\n\t\t\t\t// Check for name conflicts\n\t\t\t\tif (seenNames.has(loadedTool.tool.name)) {\n\t\t\t\t\terrors.push({\n\t\t\t\t\t\tpath: toolPath,\n\t\t\t\t\t\terror: `Tool name \"${loadedTool.tool.name}\" conflicts with existing tool`,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tseenNames.add(loadedTool.tool.name);\n\t\t\t\ttools.push(loadedTool);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\ttools,\n\t\terrors,\n\t\tsetUIContext(uiContext, hasUI) {\n\t\t\tsharedApi.ui = uiContext;\n\t\t\tsharedApi.hasUI = hasUI;\n\t\t},\n\t};\n}\n\n/**\n * Discover tool files from a directory.\n * Returns all .ts files in the directory (non-recursive).\n */\nfunction discoverToolsInDir(dir: string): string[] {\n\tif (!fs.existsSync(dir)) {\n\t\treturn [];\n\t}\n\n\ttry {\n\t\tconst entries = fs.readdirSync(dir, { withFileTypes: true });\n\t\treturn entries.filter((e) => e.isFile() && e.name.endsWith(\".ts\")).map((e) => path.join(dir, e.name));\n\t} catch {\n\t\treturn [];\n\t}\n}\n\n/**\n * Discover and load tools from standard locations:\n * 1. ~/.pi/agent/tools/*.ts (global)\n * 2. cwd/.pi/tools/*.ts (project-local)\n *\n * Plus any explicitly configured paths from settings or CLI.\n *\n * @param configuredPaths - Explicit paths from settings.json and CLI --tool flags\n * @param cwd - Current working directory\n * @param builtInToolNames - Names of built-in tools to check for conflicts\n */\nexport async function discoverAndLoadCustomTools(\n\tconfiguredPaths: string[],\n\tcwd: string,\n\tbuiltInToolNames: string[],\n): Promise<CustomToolsLoadResult> {\n\tconst allPaths: string[] = [];\n\tconst seen = new Set<string>();\n\n\t// Helper to add paths without duplicates\n\tconst addPaths = (paths: string[]) => {\n\t\tfor (const p of paths) {\n\t\t\tconst resolved = path.resolve(p);\n\t\t\tif (!seen.has(resolved)) {\n\t\t\t\tseen.add(resolved);\n\t\t\t\tallPaths.push(p);\n\t\t\t}\n\t\t}\n\t};\n\n\t// 1. Global tools: ~/.pi/agent/tools/\n\tconst globalToolsDir = path.join(getAgentDir(), \"tools\");\n\taddPaths(discoverToolsInDir(globalToolsDir));\n\n\t// 2. Project-local tools: cwd/.pi/tools/\n\tconst localToolsDir = path.join(cwd, \".pi\", \"tools\");\n\taddPaths(discoverToolsInDir(localToolsDir));\n\n\t// 3. Explicitly configured paths (can override/add)\n\taddPaths(configuredPaths.map((p) => resolveToolPath(p, cwd)));\n\n\treturn loadCustomTools(allPaths, cwd, builtInToolNames);\n}\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom tool types.
|
|
3
|
+
*
|
|
4
|
+
* Custom tools are TypeScript modules that define additional tools for the agent.
|
|
5
|
+
* They can provide custom rendering for tool calls and results in the TUI.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentTool, AgentToolResult } from "@mariozechner/pi-ai";
|
|
8
|
+
import type { Component } from "@mariozechner/pi-tui";
|
|
9
|
+
import type { Static, TSchema } from "@sinclair/typebox";
|
|
10
|
+
import type { Theme } from "../../modes/interactive/theme/theme.js";
|
|
11
|
+
import type { HookUIContext } from "../hooks/types.js";
|
|
12
|
+
import type { SessionEntry } from "../session-manager.js";
|
|
13
|
+
/** Alias for clarity */
|
|
14
|
+
export type ToolUIContext = HookUIContext;
|
|
15
|
+
export interface ExecResult {
|
|
16
|
+
stdout: string;
|
|
17
|
+
stderr: string;
|
|
18
|
+
code: number;
|
|
19
|
+
}
|
|
20
|
+
/** API passed to custom tool factory (stable across session changes) */
|
|
21
|
+
export interface ToolAPI {
|
|
22
|
+
/** Current working directory */
|
|
23
|
+
cwd: string;
|
|
24
|
+
/** Execute a command */
|
|
25
|
+
exec(command: string, args: string[]): Promise<ExecResult>;
|
|
26
|
+
/** UI methods for user interaction (select, confirm, input, notify) */
|
|
27
|
+
ui: ToolUIContext;
|
|
28
|
+
/** Whether UI is available (false in print/RPC mode) */
|
|
29
|
+
hasUI: boolean;
|
|
30
|
+
}
|
|
31
|
+
/** Session event passed to onSession callback */
|
|
32
|
+
export interface SessionEvent {
|
|
33
|
+
/** All session entries (including pre-compaction history) */
|
|
34
|
+
entries: SessionEntry[];
|
|
35
|
+
/** Current session file path, or null in --no-session mode */
|
|
36
|
+
sessionFile: string | null;
|
|
37
|
+
/** Previous session file path, or null for "start" and "clear" */
|
|
38
|
+
previousSessionFile: string | null;
|
|
39
|
+
/** Reason for the session event */
|
|
40
|
+
reason: "start" | "switch" | "branch" | "clear";
|
|
41
|
+
}
|
|
42
|
+
/** Rendering options passed to renderResult */
|
|
43
|
+
export interface RenderResultOptions {
|
|
44
|
+
/** Whether the result view is expanded */
|
|
45
|
+
expanded: boolean;
|
|
46
|
+
/** Whether this is a partial/streaming result */
|
|
47
|
+
isPartial: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** Custom tool with optional lifecycle and rendering methods */
|
|
50
|
+
export interface CustomAgentTool<TParams extends TSchema = TSchema, TDetails = any> extends AgentTool<TParams, TDetails> {
|
|
51
|
+
/** Called on session start/switch/branch/clear - use to reconstruct state from entries */
|
|
52
|
+
onSession?: (event: SessionEvent) => void | Promise<void>;
|
|
53
|
+
/** Custom rendering for tool call display - return a Component */
|
|
54
|
+
renderCall?: (args: Static<TParams>, theme: Theme) => Component;
|
|
55
|
+
/** Custom rendering for tool result display - return a Component */
|
|
56
|
+
renderResult?: (result: AgentToolResult<TDetails>, options: RenderResultOptions, theme: Theme) => Component;
|
|
57
|
+
/** Called when session ends - cleanup resources */
|
|
58
|
+
dispose?: () => Promise<void> | void;
|
|
59
|
+
}
|
|
60
|
+
/** Factory function that creates a custom tool or array of tools */
|
|
61
|
+
export type CustomToolFactory = (pi: ToolAPI) => CustomAgentTool<any> | CustomAgentTool[] | Promise<CustomAgentTool | CustomAgentTool[]>;
|
|
62
|
+
/** Loaded custom tool with metadata */
|
|
63
|
+
export interface LoadedCustomTool {
|
|
64
|
+
/** Original path (as specified) */
|
|
65
|
+
path: string;
|
|
66
|
+
/** Resolved absolute path */
|
|
67
|
+
resolvedPath: string;
|
|
68
|
+
/** The tool instance */
|
|
69
|
+
tool: CustomAgentTool;
|
|
70
|
+
}
|
|
71
|
+
/** Result from loading custom tools */
|
|
72
|
+
export interface CustomToolsLoadResult {
|
|
73
|
+
tools: LoadedCustomTool[];
|
|
74
|
+
errors: Array<{
|
|
75
|
+
path: string;
|
|
76
|
+
error: string;
|
|
77
|
+
}>;
|
|
78
|
+
/** Update the UI context for all loaded tools. Call when mode initializes. */
|
|
79
|
+
setUIContext(uiContext: ToolUIContext, hasUI: boolean): void;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/custom-tools/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,wBAAwB;AACxB,MAA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AK,EAAE,KAAK,KAAK,SAAS,CAAC;IAChE,oEAAoE;IACpE,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,mBAAmB,EAAE,KAAK,EAAE,KAAK,KAAK,SAAS,CAAC;IAC5G,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACrC;AAED,oEAAoE;AACpE,MAAM,MAAM,iBAAiB,GAAG,CAC/B,EAAE,EAAE,OAAO,KACP,eAAe,CAAC,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,OAAO,CAAC,eAAe,GAAG,eAAe,EAAE,CAAC,CAAC;AAE7F,uCAAuC;AACvC,MAAM,WAAW,gBAAgB;IAChC,mCAAmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,wBAAwB;IACxB,IAAI,EAAE,eAAe,CAAC;CACtB;AAED,uCAAuC;AACvC,MAAM,WAAW,qBAAqB;IACrC,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,8EAA8E;IAC9E,YAAY,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC7D","sourcesContent":["/**\n * Custom tool types.\n *\n * Custom tools are TypeScript modules that define additional tools for the agent.\n * They can provide custom rendering for tool calls and results in the TUI.\n */\n\nimport type { AgentTool, AgentToolResult } from \"@mariozechner/pi-ai\";\nimport type { Component } from \"@mariozechner/pi-tui\";\nimport type { Static, TSchema } from \"@sinclair/typebox\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { HookUIContext } from \"../hooks/types.js\";\nimport type { SessionEntry } from \"../session-manager.js\";\n\n/** Alias for clarity */\nexport type ToolUIContext = HookUIContext;\n\nexport interface ExecResult {\n\tstdout: string;\n\tstderr: string;\n\tcode: number;\n}\n\n/** API passed to custom tool factory (stable across session changes) */\nexport interface ToolAPI {\n\t/** Current working directory */\n\tcwd: string;\n\t/** Execute a command */\n\texec(command: string, args: string[]): Promise<ExecResult>;\n\t/** UI methods for user interaction (select, confirm, input, notify) */\n\tui: ToolUIContext;\n\t/** Whether UI is available (false in print/RPC mode) */\n\thasUI: boolean;\n}\n\n/** Session event passed to onSession callback */\nexport interface SessionEvent {\n\t/** All session entries (including pre-compaction history) */\n\tentries: SessionEntry[];\n\t/** Current session file path, or null in --no-session mode */\n\tsessionFile: string | null;\n\t/** Previous session file path, or null for \"start\" and \"clear\" */\n\tpreviousSessionFile: string | null;\n\t/** Reason for the session event */\n\treason: \"start\" | \"switch\" | \"branch\" | \"clear\";\n}\n\n/** Rendering options passed to renderResult */\nexport interface RenderResultOptions {\n\t/** Whether the result view is expanded */\n\texpanded: boolean;\n\t/** Whether this is a partial/streaming result */\n\tisPartial: boolean;\n}\n\n/** Custom tool with optional lifecycle and rendering methods */\nexport interface CustomAgentTool<TParams extends TSchema = TSchema, TDetails = any>\n\textends AgentTool<TParams, TDetails> {\n\t/** Called on session start/switch/branch/clear - use to reconstruct state from entries */\n\tonSession?: (event: SessionEvent) => void | Promise<void>;\n\t/** Custom rendering for tool call display - return a Component */\n\trenderCall?: (args: Static<TParams>, theme: Theme) => Component;\n\t/** Custom rendering for tool result display - return a Component */\n\trenderResult?: (result: AgentToolResult<TDetails>, options: RenderResultOptions, theme: Theme) => Component;\n\t/** Called when session ends - cleanup resources */\n\tdispose?: () => Promise<void> | void;\n}\n\n/** Factory function that creates a custom tool or array of tools */\nexport type CustomToolFactory = (\n\tpi: ToolAPI,\n) => CustomAgentTool<any> | CustomAgentTool[] | Promise<CustomAgentTool | CustomAgentTool[]>;\n\n/** Loaded custom tool with metadata */\nexport interface LoadedCustomTool {\n\t/** Original path (as specified) */\n\tpath: string;\n\t/** Resolved absolute path */\n\tresolvedPath: string;\n\t/** The tool instance */\n\ttool: CustomAgentTool;\n}\n\n/** Result from loading custom tools */\nexport interface CustomToolsLoadResult {\n\ttools: LoadedCustomTool[];\n\terrors: Array<{ path: string; error: string }>;\n\t/** Update the UI context for all loaded tools. Call when mode initializes. */\n\tsetUIContext(uiContext: ToolUIContext, hasUI: boolean): void;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/custom-tools/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","sourcesContent":["/**\n * Custom tool types.\n *\n * Custom tools are TypeScript modules that define additional tools for the agent.\n * They can provide custom rendering for tool calls and results in the TUI.\n */\n\nimport type { AgentTool, AgentToolResult } from \"@mariozechner/pi-ai\";\nimport type { Component } from \"@mariozechner/pi-tui\";\nimport type { Static, TSchema } from \"@sinclair/typebox\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.js\";\nimport type { HookUIContext } from \"../hooks/types.js\";\nimport type { SessionEntry } from \"../session-manager.js\";\n\n/** Alias for clarity */\nexport type ToolUIContext = HookUIContext;\n\nexport interface ExecResult {\n\tstdout: string;\n\tstderr: string;\n\tcode: number;\n}\n\n/** API passed to custom tool factory (stable across session changes) */\nexport interface ToolAPI {\n\t/** Current working directory */\n\tcwd: string;\n\t/** Execute a command */\n\texec(command: string, args: string[]): Promise<ExecResult>;\n\t/** UI methods for user interaction (select, confirm, input, notify) */\n\tui: ToolUIContext;\n\t/** Whether UI is available (false in print/RPC mode) */\n\thasUI: boolean;\n}\n\n/** Session event passed to onSession callback */\nexport interface SessionEvent {\n\t/** All session entries (including pre-compaction history) */\n\tentries: SessionEntry[];\n\t/** Current session file path, or null in --no-session mode */\n\tsessionFile: string | null;\n\t/** Previous session file path, or null for \"start\" and \"clear\" */\n\tpreviousSessionFile: string | null;\n\t/** Reason for the session event */\n\treason: \"start\" | \"switch\" | \"branch\" | \"clear\";\n}\n\n/** Rendering options passed to renderResult */\nexport interface RenderResultOptions {\n\t/** Whether the result view is expanded */\n\texpanded: boolean;\n\t/** Whether this is a partial/streaming result */\n\tisPartial: boolean;\n}\n\n/** Custom tool with optional lifecycle and rendering methods */\nexport interface CustomAgentTool<TParams extends TSchema = TSchema, TDetails = any>\n\textends AgentTool<TParams, TDetails> {\n\t/** Called on session start/switch/branch/clear - use to reconstruct state from entries */\n\tonSession?: (event: SessionEvent) => void | Promise<void>;\n\t/** Custom rendering for tool call display - return a Component */\n\trenderCall?: (args: Static<TParams>, theme: Theme) => Component;\n\t/** Custom rendering for tool result display - return a Component */\n\trenderResult?: (result: AgentToolResult<TDetails>, options: RenderResultOptions, theme: Theme) => Component;\n\t/** Called when session ends - cleanup resources */\n\tdispose?: () => Promise<void> | void;\n}\n\n/** Factory function that creates a custom tool or array of tools */\nexport type CustomToolFactory = (\n\tpi: ToolAPI,\n) => CustomAgentTool<any> | CustomAgentTool[] | Promise<CustomAgentTool | CustomAgentTool[]>;\n\n/** Loaded custom tool with metadata */\nexport interface LoadedCustomTool {\n\t/** Original path (as specified) */\n\tpath: string;\n\t/** Resolved absolute path */\n\tresolvedPath: string;\n\t/** The tool instance */\n\ttool: CustomAgentTool;\n}\n\n/** Result from loading custom tools */\nexport interface CustomToolsLoadResult {\n\ttools: LoadedCustomTool[];\n\terrors: Array<{ path: string; error: string }>;\n\t/** Update the UI context for all loaded tools. Call when mode initializes. */\n\tsetUIContext(uiContext: ToolUIContext, hasUI: boolean): void;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { discoverAndLoadHooks, type LoadedHook, type LoadHooksResult, loadHooks, type SendHandler } from "./loader.js";
|
|
2
2
|
export { type HookErrorListener, HookRunner } from "./runner.js";
|
|
3
3
|
export { wrapToolsWithHooks, wrapToolWithHooks } from "./tool-wrapper.js";
|
|
4
|
-
export type { AgentEndEvent, AgentStartEvent, BranchEvent, BranchEventResult, ExecResult, HookAPI, HookError, HookEvent, HookEventContext, HookFactory, HookUIContext,
|
|
4
|
+
export type { AgentEndEvent, AgentStartEvent, BranchEvent, BranchEventResult, ExecResult, HookAPI, HookError, HookEvent, HookEventContext, HookFactory, HookUIContext, SessionEvent, ToolCallEvent, ToolCallEventResult, ToolResultEvent, ToolResultEventResult, TurnEndEvent, TurnStartEvent, } from "./types.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACvH,OAAO,EAAE,KAAK,iBAAiB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,YAAY,EACX,aAAa,EACb,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,OAAO,EACP,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,UAAU,EAAE,KAAK,eAAe,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACvH,OAAO,EAAE,KAAK,iBAAiB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,YAAY,EACX,aAAa,EACb,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,OAAO,EACP,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,cAAc,GACd,MAAM,YAAY,CAAC","sourcesContent":["export { discoverAndLoadHooks, type LoadedHook, type LoadHooksResult, loadHooks, type SendHandler } from \"./loader.js\";\nexport { type HookErrorListener, HookRunner } from \"./runner.js\";\nexport { wrapToolsWithHooks, wrapToolWithHooks } from \"./tool-wrapper.js\";\nexport type {\n\tAgentEndEvent,\n\tAgentStartEvent,\n\tBranchEvent,\n\tBranchEventResult,\n\tExecResult,\n\tHookAPI,\n\tHookError,\n\tHookEvent,\n\tHookEventContext,\n\tHookFactory,\n\tHookUIContext,\n\tSessionEvent,\n\tToolCallEvent,\n\tToolCallEventResult,\n\tToolResultEvent,\n\tToolResultEventResult,\n\tTurnEndEvent,\n\tTurnStartEvent,\n} from \"./types.js\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAyC,SAAS,EAAoB,MAAM,aAAa,CAAC;AACvH,OAAO,EAA0B,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export { discoverAndLoadHooks, type LoadedHook, type LoadHooksResult, loadHooks, type SendHandler } from \"./loader.js\";\nexport { type HookErrorListener, HookRunner } from \"./runner.js\";\nexport { wrapToolsWithHooks, wrapToolWithHooks } from \"./tool-wrapper.js\";\nexport type {\n\tAgentEndEvent,\n\tAgentStartEvent,\n\tBranchEvent,\n\tBranchEventResult,\n\tExecResult,\n\tHookAPI,\n\tHookError,\n\tHookEvent,\n\tHookEventContext,\n\tHookFactory,\n\tHookUIContext,\n\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAyC,SAAS,EAAoB,MAAM,aAAa,CAAC;AACvH,OAAO,EAA0B,UAAU,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export { discoverAndLoadHooks, type LoadedHook, type LoadHooksResult, loadHooks, type SendHandler } from \"./loader.js\";\nexport { type HookErrorListener, HookRunner } from \"./runner.js\";\nexport { wrapToolsWithHooks, wrapToolWithHooks } from \"./tool-wrapper.js\";\nexport type {\n\tAgentEndEvent,\n\tAgentStartEvent,\n\tBranchEvent,\n\tBranchEventResult,\n\tExecResult,\n\tHookAPI,\n\tHookError,\n\tHookEvent,\n\tHookEventContext,\n\tHookFactory,\n\tHookUIContext,\n\tSessionEvent,\n\tToolCallEvent,\n\tToolCallEventResult,\n\tToolResultEvent,\n\tToolResultEventResult,\n\tTurnEndEvent,\n\tTurnStartEvent,\n} from \"./types.js\";\n"]}
|
|
@@ -57,24 +57,20 @@ export interface HookEventContext {
|
|
|
57
57
|
sessionFile: string | null;
|
|
58
58
|
}
|
|
59
59
|
/**
|
|
60
|
-
* Event data for
|
|
61
|
-
* Fired
|
|
60
|
+
* Event data for session event.
|
|
61
|
+
* Fired on startup and when session changes (switch or clear).
|
|
62
|
+
* Note: branch has its own event that fires BEFORE the branch happens.
|
|
62
63
|
*/
|
|
63
|
-
export interface
|
|
64
|
-
type: "
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
*/
|
|
70
|
-
export interface SessionSwitchEvent {
|
|
71
|
-
type: "session_switch";
|
|
72
|
-
/** New session file path, or null in --no-session mode */
|
|
73
|
-
newSessionFile: string | null;
|
|
74
|
-
/** Previous session file path, or null in --no-session mode */
|
|
64
|
+
export interface SessionEvent {
|
|
65
|
+
type: "session";
|
|
66
|
+
/** All session entries (including pre-compaction history) */
|
|
67
|
+
entries: SessionEntry[];
|
|
68
|
+
/** Current session file path, or null in --no-session mode */
|
|
69
|
+
sessionFile: string | null;
|
|
70
|
+
/** Previous session file path, or null for "start" and "clear" */
|
|
75
71
|
previousSessionFile: string | null;
|
|
76
|
-
/** Reason for the
|
|
77
|
-
reason: "
|
|
72
|
+
/** Reason for the session event */
|
|
73
|
+
reason: "start" | "switch" | "clear";
|
|
78
74
|
}
|
|
79
75
|
/**
|
|
80
76
|
* Event data for agent_start event.
|
|
@@ -150,7 +146,7 @@ export interface BranchEvent {
|
|
|
150
146
|
/**
|
|
151
147
|
* Union of all hook event types.
|
|
152
148
|
*/
|
|
153
|
-
export type HookEvent =
|
|
149
|
+
export type HookEvent = SessionEvent | AgentStartEvent | AgentEndEvent | TurnStartEvent | TurnEndEvent | ToolCallEvent | ToolResultEvent | BranchEvent;
|
|
154
150
|
/**
|
|
155
151
|
* Return type for tool_call event handlers.
|
|
156
152
|
* Allows hooks to block tool execution.
|
|
@@ -188,8 +184,7 @@ export type HookHandler<E, R = void> = (event: E, ctx: HookEventContext) => Prom
|
|
|
188
184
|
* Hooks use pi.on() to subscribe to events and pi.send() to inject messages.
|
|
189
185
|
*/
|
|
190
186
|
export interface HookAPI {
|
|
191
|
-
on(event: "
|
|
192
|
-
on(event: "session_switch", handler: HookHandler<SessionSwitchEvent>): void;
|
|
187
|
+
on(event: "session", handler: HookHandler<SessionEvent>): void;
|
|
193
188
|
on(event: "agent_start", handler: HookHandler<AgentStartEvent>): void;
|
|
194
189
|
on(event: "agent_end", handler: HookHandler<AgentEndEvent>): void;
|
|
195
190
|
on(event: "turn_start", handler: HookHandler<TurnStartEvent>): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBA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a,CAAC,GAAG,IAAI,CAAC;IAClE,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IACpE,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;IAChE,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,CAAC,aAAa,EAAE,mBAAmB,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IACnG,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,CAAC,eAAe,EAAE,qBAAqB,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IACzG,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE,iBAAiB,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IAE5F;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;CACrD;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;AAMhD;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACd","sourcesContent":["/**\n * Hook system types.\n *\n * Hooks are TypeScript modules that can subscribe to agent lifecycle events\n * and interact with the user via UI primitives.\n */\n\nimport type { AppMessage, Attachment } from \"@mariozechner/pi-agent-core\";\nimport type { SessionEntry } from \"../session-manager.js\";\n\n// ============================================================================\n// Execution Context\n// ============================================================================\n\n/**\n * Result of executing a command via ctx.exec()\n */\nexport interface ExecResult {\n\tstdout: string;\n\tstderr: string;\n\tcode: number;\n}\n\n/**\n * UI context for hooks to request interactive UI from the harness.\n * Each mode (interactive, RPC, print) provides its own implementation.\n */\nexport interface HookUIContext {\n\t/**\n\t * Show a selector and return the user's choice.\n\t * @param title - Title to display\n\t * @param options - Array of string options\n\t * @returns Selected option string, or null if cancelled\n\t */\n\tselect(title: string, options: string[]): Promise<string | null>;\n\n\t/**\n\t * Show a confirmation dialog.\n\t * @returns true if confirmed, false if cancelled\n\t */\n\tconfirm(title: string, message: string): Promise<boolean>;\n\n\t/**\n\t * Show a text input dialog.\n\t * @returns User input, or null if cancelled\n\t */\n\tinput(title: string, placeholder?: string): Promise<string | null>;\n\n\t/**\n\t * Show a notification to the user.\n\t */\n\tnotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void;\n}\n\n/**\n * Context passed to hook event handlers.\n */\nexport interface HookEventContext {\n\t/** Execute a command and return stdout/stderr/code */\n\texec(command: string, args: string[]): Promise<ExecResult>;\n\t/** UI methods for user interaction */\n\tui: HookUIContext;\n\t/** Whether UI is available (false in print mode) */\n\thasUI: boolean;\n\t/** Current working directory */\n\tcwd: string;\n\t/** Path to session file, or null if --no-session */\n\tsessionFile: string | null;\n}\n\n// ============================================================================\n// Events\n// ============================================================================\n\n/**\n * Event data for session_start event.\n * Fired once when the coding agent starts up.\n */\nexport interface SessionStartEvent {\n\ttype: \"session_start\";\n}\n\n/**\n * Event data for session_switch event.\n * Fired when the session changes (branch or session switch).\n */\nexport interface SessionSwitchEvent {\n\ttype: \"session_switch\";\n\t/** New session file path, or null in --no-session mode */\n\tnewSessionFile: string | null;\n\t/** Previous session file path, or null in --no-session mode */\n\tpreviousSessionFile: string | null;\n\t/** Reason for the switch */\n\treason: \"branch\" | \"switch\";\n}\n\n/**\n * Event data for agent_start event.\n * Fired when an agent loop starts (once per user prompt).\n */\nexport interface AgentStartEvent {\n\ttype: \"agent_start\";\n}\n\n/**\n * Event data for agent_end event.\n */\nexport interface AgentEndEvent {\n\ttype: \"agent_end\";\n\tmessages: AppMessage[];\n}\n\n/**\n * Event data for turn_start event.\n */\nexport interface TurnStartEvent {\n\ttype: \"turn_start\";\n\tturnIndex: number;\n\ttimestamp: number;\n}\n\n/**\n * Event data for turn_end event.\n */\nexport interface TurnEndEvent {\n\ttype: \"turn_end\";\n\tturnIndex: number;\n\tmessage: AppMessage;\n\ttoolResults: AppMessage[];\n}\n\n/**\n * Event data for tool_call event.\n * Fired before a tool is executed. Hooks can block execution.\n */\nexport interface ToolCallEvent {\n\ttype: \"tool_call\";\n\t/** Tool name (e.g., \"bash\", \"edit\", \"write\") */\n\ttoolName: string;\n\t/** Tool call ID */\n\ttoolCallId: string;\n\t/** Tool input parameters */\n\tinput: Record<string, unknown>;\n}\n\n/**\n * Event data for tool_result event.\n * Fired after a tool is executed. Hooks can modify the result.\n */\nexport interface ToolResultEvent {\n\ttype: \"tool_result\";\n\t/** Tool name (e.g., \"bash\", \"edit\", \"write\") */\n\ttoolName: string;\n\t/** Tool call ID */\n\ttoolCallId: string;\n\t/** Tool input parameters */\n\tinput: Record<string, unknown>;\n\t/** Tool result content (text) */\n\tresult: string;\n\t/** Whether the tool execution was an error */\n\tisError: boolean;\n}\n\n/**\n * Event data for branch event.\n */\nexport interface BranchEvent {\n\ttype: \"branch\";\n\t/** Index of the turn to branch from */\n\ttargetTurnIndex: number;\n\t/** Full session history */\n\tentries: SessionEntry[];\n}\n\n/**\n * Union of all hook event types.\n */\nexport type HookEvent =\n\t| SessionStartEvent\n\t| SessionSwitchEvent\n\t| AgentStartEvent\n\t| AgentEndEvent\n\t| TurnStartEvent\n\t| TurnEndEvent\n\t| ToolCallEvent\n\t| ToolResultEvent\n\t| BranchEvent;\n\n// ============================================================================\n// Event Results\n// ============================================================================\n\n/**\n * Return type for tool_call event handlers.\n * Allows hooks to block tool execution.\n */\nexport interface ToolCallEventResult {\n\t/** If true, block the tool from executing */\n\tblock?: boolean;\n\t/** Reason for blocking (returned to LLM as error) */\n\treason?: string;\n}\n\n/**\n * Return type for tool_result event handlers.\n * Allows hooks to modify tool results.\n */\nexport interface ToolResultEventResult {\n\t/** Modified result text (if not set, original result is used) */\n\tresult?: string;\n\t/** Override isError flag */\n\tisError?: boolean;\n}\n\n/**\n * Return type for branch event handlers.\n * Allows hooks to control branch behavior.\n */\nexport interface BranchEventResult {\n\t/** If true, skip restoring the conversation (only restore code) */\n\tskipConversationRestore?: boolean;\n}\n\n// ============================================================================\n// Hook API\n// ============================================================================\n\n/**\n * Handler function type for each event.\n */\nexport type HookHandler<E, R = void> = (event: E, ctx: HookEventContext) => Promise<R>;\n\n/**\n * HookAPI passed to hook factory functions.\n * Hooks use pi.on() to subscribe to events and pi.send() to inject messages.\n */\nexport interface HookAPI {\n\ton(event: \"session_start\", handler: HookHandler<SessionStartEvent>): void;\n\ton(event: \"session_switch\", handler: HookHandler<SessionSwitchEvent>): void;\n\ton(event: \"agent_start\", handler: HookHandler<AgentStartEvent>): void;\n\ton(event: \"agent_end\", handler: HookHandler<AgentEndEvent>): void;\n\ton(event: \"turn_start\", handler: HookHandler<TurnStartEvent>): void;\n\ton(event: \"turn_end\", handler: HookHandler<TurnEndEvent>): void;\n\ton(event: \"tool_call\", handler: HookHandler<ToolCallEvent, ToolCallEventResult | undefined>): void;\n\ton(event: \"tool_result\", handler: HookHandler<ToolResultEvent, ToolResultEventResult | undefined>): void;\n\ton(event: \"branch\", handler: HookHandler<BranchEvent, BranchEventResult | undefined>): void;\n\n\t/**\n\t * Send a message to the agent.\n\t * If the agent is streaming, the message is queued.\n\t * If the agent is idle, a new agent loop is started.\n\t */\n\tsend(text: string, attachments?: Attachment[]): void;\n}\n\n/**\n * Hook factory function type.\n * Hooks export a default function that receives the HookAPI.\n */\nexport type HookFactory = (pi: HookAPI) => void;\n\n// ============================================================================\n// Errors\n// ============================================================================\n\n/**\n * Error emitted when a hook fails.\n */\nexport interface HookError {\n\thookPath: string;\n\tevent: string;\n\terror: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/hooks/types.ts"],"names":[],"mappings":"AAAA;;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IAAI,CAAC;IAClE,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC;IACpE,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;IAChE,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,CAAC,aAAa,EAAE,mBAAmB,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IACnG,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,CAAC,eAAe,EAAE,qBAAqB,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IACzG,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,CAAC,WAAW,EAAE,iBAAiB,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;IAE5F;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;CACrD;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;AAMhD;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACd","sourcesContent":["/**\n * Hook system types.\n *\n * Hooks are TypeScript modules that can subscribe to agent lifecycle events\n * and interact with the user via UI primitives.\n */\n\nimport type { AppMessage, Attachment } from \"@mariozechner/pi-agent-core\";\nimport type { SessionEntry } from \"../session-manager.js\";\n\n// ============================================================================\n// Execution Context\n// ============================================================================\n\n/**\n * Result of executing a command via ctx.exec()\n */\nexport interface ExecResult {\n\tstdout: string;\n\tstderr: string;\n\tcode: number;\n}\n\n/**\n * UI context for hooks to request interactive UI from the harness.\n * Each mode (interactive, RPC, print) provides its own implementation.\n */\nexport interface HookUIContext {\n\t/**\n\t * Show a selector and return the user's choice.\n\t * @param title - Title to display\n\t * @param options - Array of string options\n\t * @returns Selected option string, or null if cancelled\n\t */\n\tselect(title: string, options: string[]): Promise<string | null>;\n\n\t/**\n\t * Show a confirmation dialog.\n\t * @returns true if confirmed, false if cancelled\n\t */\n\tconfirm(title: string, message: string): Promise<boolean>;\n\n\t/**\n\t * Show a text input dialog.\n\t * @returns User input, or null if cancelled\n\t */\n\tinput(title: string, placeholder?: string): Promise<string | null>;\n\n\t/**\n\t * Show a notification to the user.\n\t */\n\tnotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void;\n}\n\n/**\n * Context passed to hook event handlers.\n */\nexport interface HookEventContext {\n\t/** Execute a command and return stdout/stderr/code */\n\texec(command: string, args: string[]): Promise<ExecResult>;\n\t/** UI methods for user interaction */\n\tui: HookUIContext;\n\t/** Whether UI is available (false in print mode) */\n\thasUI: boolean;\n\t/** Current working directory */\n\tcwd: string;\n\t/** Path to session file, or null if --no-session */\n\tsessionFile: string | null;\n}\n\n// ============================================================================\n// Events\n// ============================================================================\n\n/**\n * Event data for session event.\n * Fired on startup and when session changes (switch or clear).\n * Note: branch has its own event that fires BEFORE the branch happens.\n */\nexport interface SessionEvent {\n\ttype: \"session\";\n\t/** All session entries (including pre-compaction history) */\n\tentries: SessionEntry[];\n\t/** Current session file path, or null in --no-session mode */\n\tsessionFile: string | null;\n\t/** Previous session file path, or null for \"start\" and \"clear\" */\n\tpreviousSessionFile: string | null;\n\t/** Reason for the session event */\n\treason: \"start\" | \"switch\" | \"clear\";\n}\n\n/**\n * Event data for agent_start event.\n * Fired when an agent loop starts (once per user prompt).\n */\nexport interface AgentStartEvent {\n\ttype: \"agent_start\";\n}\n\n/**\n * Event data for agent_end event.\n */\nexport interface AgentEndEvent {\n\ttype: \"agent_end\";\n\tmessages: AppMessage[];\n}\n\n/**\n * Event data for turn_start event.\n */\nexport interface TurnStartEvent {\n\ttype: \"turn_start\";\n\tturnIndex: number;\n\ttimestamp: number;\n}\n\n/**\n * Event data for turn_end event.\n */\nexport interface TurnEndEvent {\n\ttype: \"turn_end\";\n\tturnIndex: number;\n\tmessage: AppMessage;\n\ttoolResults: AppMessage[];\n}\n\n/**\n * Event data for tool_call event.\n * Fired before a tool is executed. Hooks can block execution.\n */\nexport interface ToolCallEvent {\n\ttype: \"tool_call\";\n\t/** Tool name (e.g., \"bash\", \"edit\", \"write\") */\n\ttoolName: string;\n\t/** Tool call ID */\n\ttoolCallId: string;\n\t/** Tool input parameters */\n\tinput: Record<string, unknown>;\n}\n\n/**\n * Event data for tool_result event.\n * Fired after a tool is executed. Hooks can modify the result.\n */\nexport interface ToolResultEvent {\n\ttype: \"tool_result\";\n\t/** Tool name (e.g., \"bash\", \"edit\", \"write\") */\n\ttoolName: string;\n\t/** Tool call ID */\n\ttoolCallId: string;\n\t/** Tool input parameters */\n\tinput: Record<string, unknown>;\n\t/** Tool result content (text) */\n\tresult: string;\n\t/** Whether the tool execution was an error */\n\tisError: boolean;\n}\n\n/**\n * Event data for branch event.\n */\nexport interface BranchEvent {\n\ttype: \"branch\";\n\t/** Index of the turn to branch from */\n\ttargetTurnIndex: number;\n\t/** Full session history */\n\tentries: SessionEntry[];\n}\n\n/**\n * Union of all hook event types.\n */\nexport type HookEvent =\n\t| SessionEvent\n\t| AgentStartEvent\n\t| AgentEndEvent\n\t| TurnStartEvent\n\t| TurnEndEvent\n\t| ToolCallEvent\n\t| ToolResultEvent\n\t| BranchEvent;\n\n// ============================================================================\n// Event Results\n// ============================================================================\n\n/**\n * Return type for tool_call event handlers.\n * Allows hooks to block tool execution.\n */\nexport interface ToolCallEventResult {\n\t/** If true, block the tool from executing */\n\tblock?: boolean;\n\t/** Reason for blocking (returned to LLM as error) */\n\treason?: string;\n}\n\n/**\n * Return type for tool_result event handlers.\n * Allows hooks to modify tool results.\n */\nexport interface ToolResultEventResult {\n\t/** Modified result text (if not set, original result is used) */\n\tresult?: string;\n\t/** Override isError flag */\n\tisError?: boolean;\n}\n\n/**\n * Return type for branch event handlers.\n * Allows hooks to control branch behavior.\n */\nexport interface BranchEventResult {\n\t/** If true, skip restoring the conversation (only restore code) */\n\tskipConversationRestore?: boolean;\n}\n\n// ============================================================================\n// Hook API\n// ============================================================================\n\n/**\n * Handler function type for each event.\n */\nexport type HookHandler<E, R = void> = (event: E, ctx: HookEventContext) => Promise<R>;\n\n/**\n * HookAPI passed to hook factory functions.\n * Hooks use pi.on() to subscribe to events and pi.send() to inject messages.\n */\nexport interface HookAPI {\n\ton(event: \"session\", handler: HookHandler<SessionEvent>): void;\n\ton(event: \"agent_start\", handler: HookHandler<AgentStartEvent>): void;\n\ton(event: \"agent_end\", handler: HookHandler<AgentEndEvent>): void;\n\ton(event: \"turn_start\", handler: HookHandler<TurnStartEvent>): void;\n\ton(event: \"turn_end\", handler: HookHandler<TurnEndEvent>): void;\n\ton(event: \"tool_call\", handler: HookHandler<ToolCallEvent, ToolCallEventResult | undefined>): void;\n\ton(event: \"tool_result\", handler: HookHandler<ToolResultEvent, ToolResultEventResult | undefined>): void;\n\ton(event: \"branch\", handler: HookHandler<BranchEvent, BranchEventResult | undefined>): void;\n\n\t/**\n\t * Send a message to the agent.\n\t * If the agent is streaming, the message is queued.\n\t * If the agent is idle, a new agent loop is started.\n\t */\n\tsend(text: string, attachments?: Attachment[]): void;\n}\n\n/**\n * Hook factory function type.\n * Hooks export a default function that receives the HookAPI.\n */\nexport type HookFactory = (pi: HookAPI) => void;\n\n// ============================================================================\n// Errors\n// ============================================================================\n\n/**\n * Error emitted when a hook fails.\n */\nexport interface HookError {\n\thookPath: string;\n\tevent: string;\n\terror: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","sourcesContent":["/**\n * Hook system types.\n *\n * Hooks are TypeScript modules that can subscribe to agent lifecycle events\n * and interact with the user via UI primitives.\n */\n\nimport type { AppMessage, Attachment } from \"@mariozechner/pi-agent-core\";\nimport type { SessionEntry } from \"../session-manager.js\";\n\n// ============================================================================\n// Execution Context\n// ============================================================================\n\n/**\n * Result of executing a command via ctx.exec()\n */\nexport interface ExecResult {\n\tstdout: string;\n\tstderr: string;\n\tcode: number;\n}\n\n/**\n * UI context for hooks to request interactive UI from the harness.\n * Each mode (interactive, RPC, print) provides its own implementation.\n */\nexport interface HookUIContext {\n\t/**\n\t * Show a selector and return the user's choice.\n\t * @param title - Title to display\n\t * @param options - Array of string options\n\t * @returns Selected option string, or null if cancelled\n\t */\n\tselect(title: string, options: string[]): Promise<string | null>;\n\n\t/**\n\t * Show a confirmation dialog.\n\t * @returns true if confirmed, false if cancelled\n\t */\n\tconfirm(title: string, message: string): Promise<boolean>;\n\n\t/**\n\t * Show a text input dialog.\n\t * @returns User input, or null if cancelled\n\t */\n\tinput(title: string, placeholder?: string): Promise<string | null>;\n\n\t/**\n\t * Show a notification to the user.\n\t */\n\tnotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void;\n}\n\n/**\n * Context passed to hook event handlers.\n */\nexport interface HookEventContext {\n\t/** Execute a command and return stdout/stderr/code */\n\texec(command: string, args: string[]): Promise<ExecResult>;\n\t/** UI methods for user interaction */\n\tui: HookUIContext;\n\t/** Whether UI is available (false in print mode) */\n\thasUI: boolean;\n\t/** Current working directory */\n\tcwd: string;\n\t/** Path to session file, or null if --no-session */\n\tsessionFile: string | null;\n}\n\n// ============================================================================\n// Events\n// ============================================================================\n\n/**\n * Event data for
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/hooks/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG","sourcesContent":["/**\n * Hook system types.\n *\n * Hooks are TypeScript modules that can subscribe to agent lifecycle events\n * and interact with the user via UI primitives.\n */\n\nimport type { AppMessage, Attachment } from \"@mariozechner/pi-agent-core\";\nimport type { SessionEntry } from \"../session-manager.js\";\n\n// ============================================================================\n// Execution Context\n// ============================================================================\n\n/**\n * Result of executing a command via ctx.exec()\n */\nexport interface ExecResult {\n\tstdout: string;\n\tstderr: string;\n\tcode: number;\n}\n\n/**\n * UI context for hooks to request interactive UI from the harness.\n * Each mode (interactive, RPC, print) provides its own implementation.\n */\nexport interface HookUIContext {\n\t/**\n\t * Show a selector and return the user's choice.\n\t * @param title - Title to display\n\t * @param options - Array of string options\n\t * @returns Selected option string, or null if cancelled\n\t */\n\tselect(title: string, options: string[]): Promise<string | null>;\n\n\t/**\n\t * Show a confirmation dialog.\n\t * @returns true if confirmed, false if cancelled\n\t */\n\tconfirm(title: string, message: string): Promise<boolean>;\n\n\t/**\n\t * Show a text input dialog.\n\t * @returns User input, or null if cancelled\n\t */\n\tinput(title: string, placeholder?: string): Promise<string | null>;\n\n\t/**\n\t * Show a notification to the user.\n\t */\n\tnotify(message: string, type?: \"info\" | \"warning\" | \"error\"): void;\n}\n\n/**\n * Context passed to hook event handlers.\n */\nexport interface HookEventContext {\n\t/** Execute a command and return stdout/stderr/code */\n\texec(command: string, args: string[]): Promise<ExecResult>;\n\t/** UI methods for user interaction */\n\tui: HookUIContext;\n\t/** Whether UI is available (false in print mode) */\n\thasUI: boolean;\n\t/** Current working directory */\n\tcwd: string;\n\t/** Path to session file, or null if --no-session */\n\tsessionFile: string | null;\n}\n\n// ============================================================================\n// Events\n// ============================================================================\n\n/**\n * Event data for session event.\n * Fired on startup and when session changes (switch or clear).\n * Note: branch has its own event that fires BEFORE the branch happens.\n */\nexport interface SessionEvent {\n\ttype: \"session\";\n\t/** All session entries (including pre-compaction history) */\n\tentries: SessionEntry[];\n\t/** Current session file path, or null in --no-session mode */\n\tsessionFile: string | null;\n\t/** Previous session file path, or null for \"start\" and \"clear\" */\n\tpreviousSessionFile: string | null;\n\t/** Reason for the session event */\n\treason: \"start\" | \"switch\" | \"clear\";\n}\n\n/**\n * Event data for agent_start event.\n * Fired when an agent loop starts (once per user prompt).\n */\nexport interface AgentStartEvent {\n\ttype: \"agent_start\";\n}\n\n/**\n * Event data for agent_end event.\n */\nexport interface AgentEndEvent {\n\ttype: \"agent_end\";\n\tmessages: AppMessage[];\n}\n\n/**\n * Event data for turn_start event.\n */\nexport interface TurnStartEvent {\n\ttype: \"turn_start\";\n\tturnIndex: number;\n\ttimestamp: number;\n}\n\n/**\n * Event data for turn_end event.\n */\nexport interface TurnEndEvent {\n\ttype: \"turn_end\";\n\tturnIndex: number;\n\tmessage: AppMessage;\n\ttoolResults: AppMessage[];\n}\n\n/**\n * Event data for tool_call event.\n * Fired before a tool is executed. Hooks can block execution.\n */\nexport interface ToolCallEvent {\n\ttype: \"tool_call\";\n\t/** Tool name (e.g., \"bash\", \"edit\", \"write\") */\n\ttoolName: string;\n\t/** Tool call ID */\n\ttoolCallId: string;\n\t/** Tool input parameters */\n\tinput: Record<string, unknown>;\n}\n\n/**\n * Event data for tool_result event.\n * Fired after a tool is executed. Hooks can modify the result.\n */\nexport interface ToolResultEvent {\n\ttype: \"tool_result\";\n\t/** Tool name (e.g., \"bash\", \"edit\", \"write\") */\n\ttoolName: string;\n\t/** Tool call ID */\n\ttoolCallId: string;\n\t/** Tool input parameters */\n\tinput: Record<string, unknown>;\n\t/** Tool result content (text) */\n\tresult: string;\n\t/** Whether the tool execution was an error */\n\tisError: boolean;\n}\n\n/**\n * Event data for branch event.\n */\nexport interface BranchEvent {\n\ttype: \"branch\";\n\t/** Index of the turn to branch from */\n\ttargetTurnIndex: number;\n\t/** Full session history */\n\tentries: SessionEntry[];\n}\n\n/**\n * Union of all hook event types.\n */\nexport type HookEvent =\n\t| SessionEvent\n\t| AgentStartEvent\n\t| AgentEndEvent\n\t| TurnStartEvent\n\t| TurnEndEvent\n\t| ToolCallEvent\n\t| ToolResultEvent\n\t| BranchEvent;\n\n// ============================================================================\n// Event Results\n// ============================================================================\n\n/**\n * Return type for tool_call event handlers.\n * Allows hooks to block tool execution.\n */\nexport interface ToolCallEventResult {\n\t/** If true, block the tool from executing */\n\tblock?: boolean;\n\t/** Reason for blocking (returned to LLM as error) */\n\treason?: string;\n}\n\n/**\n * Return type for tool_result event handlers.\n * Allows hooks to modify tool results.\n */\nexport interface ToolResultEventResult {\n\t/** Modified result text (if not set, original result is used) */\n\tresult?: string;\n\t/** Override isError flag */\n\tisError?: boolean;\n}\n\n/**\n * Return type for branch event handlers.\n * Allows hooks to control branch behavior.\n */\nexport interface BranchEventResult {\n\t/** If true, skip restoring the conversation (only restore code) */\n\tskipConversationRestore?: boolean;\n}\n\n// ============================================================================\n// Hook API\n// ============================================================================\n\n/**\n * Handler function type for each event.\n */\nexport type HookHandler<E, R = void> = (event: E, ctx: HookEventContext) => Promise<R>;\n\n/**\n * HookAPI passed to hook factory functions.\n * Hooks use pi.on() to subscribe to events and pi.send() to inject messages.\n */\nexport interface HookAPI {\n\ton(event: \"session\", handler: HookHandler<SessionEvent>): void;\n\ton(event: \"agent_start\", handler: HookHandler<AgentStartEvent>): void;\n\ton(event: \"agent_end\", handler: HookHandler<AgentEndEvent>): void;\n\ton(event: \"turn_start\", handler: HookHandler<TurnStartEvent>): void;\n\ton(event: \"turn_end\", handler: HookHandler<TurnEndEvent>): void;\n\ton(event: \"tool_call\", handler: HookHandler<ToolCallEvent, ToolCallEventResult | undefined>): void;\n\ton(event: \"tool_result\", handler: HookHandler<ToolResultEvent, ToolResultEventResult | undefined>): void;\n\ton(event: \"branch\", handler: HookHandler<BranchEvent, BranchEventResult | undefined>): void;\n\n\t/**\n\t * Send a message to the agent.\n\t * If the agent is streaming, the message is queued.\n\t * If the agent is idle, a new agent loop is started.\n\t */\n\tsend(text: string, attachments?: Attachment[]): void;\n}\n\n/**\n * Hook factory function type.\n * Hooks export a default function that receives the HookAPI.\n */\nexport type HookFactory = (pi: HookAPI) => void;\n\n// ============================================================================\n// Errors\n// ============================================================================\n\n/**\n * Error emitted when a hook fails.\n */\nexport interface HookError {\n\thookPath: string;\n\tevent: string;\n\terror: string;\n}\n"]}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { AgentSession, type AgentSessionConfig, type AgentSessionEvent, type AgentSessionEventListener, type CompactionResult, type ModelCycleResult, type PromptOptions, type SessionStats, } from "./agent-session.js";
|
|
5
5
|
export { type BashExecutorOptions, type BashResult, executeBash } from "./bash-executor.js";
|
|
6
|
+
export { type CustomAgentTool, type CustomToolFactory, type CustomToolsLoadResult, discoverAndLoadCustomTools, type ExecResult, type LoadedCustomTool, loadCustomTools, type RenderResultOptions, type ToolAPI, type ToolUIContext, } from "./custom-tools/index.js";
|
|
6
7
|
export { type HookAPI, type HookError, type HookEvent, type HookEventContext, type HookFactory, HookRunner, type HookUIContext, loadHooks, } from "./hooks/index.js";
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,YAAY,EACZ,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,UAAU,EACV,KAAK,aAAa,EAClB,SAAS,GACT,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * Core modules shared between all run modes.\n */\n\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype CompactionResult,\n\ttype ModelCycleResult,\n\ttype PromptOptions,\n\ttype SessionStats,\n} from \"./agent-session.js\";\nexport { type BashExecutorOptions, type BashResult, executeBash } from \"./bash-executor.js\";\nexport {\n\ttype HookAPI,\n\ttype HookError,\n\ttype HookEvent,\n\ttype HookEventContext,\n\ttype HookFactory,\n\tHookRunner,\n\ttype HookUIContext,\n\tloadHooks,\n} from \"./hooks/index.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,YAAY,EACZ,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,YAAY,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,0BAA0B,EAC1B,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,eAAe,EACf,KAAK,mBAAmB,EACxB,KAAK,OAAO,EACZ,KAAK,aAAa,GAClB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,UAAU,EACV,KAAK,aAAa,EAClB,SAAS,GACT,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * Core modules shared between all run modes.\n */\n\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype CompactionResult,\n\ttype ModelCycleResult,\n\ttype PromptOptions,\n\ttype SessionStats,\n} from \"./agent-session.js\";\nexport { type BashExecutorOptions, type BashResult, executeBash } from \"./bash-executor.js\";\nexport {\n\ttype CustomAgentTool,\n\ttype CustomToolFactory,\n\ttype CustomToolsLoadResult,\n\tdiscoverAndLoadCustomTools,\n\ttype ExecResult,\n\ttype LoadedCustomTool,\n\tloadCustomTools,\n\ttype RenderResultOptions,\n\ttype ToolAPI,\n\ttype ToolUIContext,\n} from \"./custom-tools/index.js\";\nexport {\n\ttype HookAPI,\n\ttype HookError,\n\ttype HookEvent,\n\ttype HookEventContext,\n\ttype HookFactory,\n\tHookRunner,\n\ttype HookUIContext,\n\tloadHooks,\n} from \"./hooks/index.js\";\n"]}
|
package/dist/core/index.js
CHANGED
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export { AgentSession, } from "./agent-session.js";
|
|
5
5
|
export { executeBash } from "./bash-executor.js";
|
|
6
|
+
export { discoverAndLoadCustomTools, loadCustomTools, } from "./custom-tools/index.js";
|
|
6
7
|
export { HookRunner, loadHooks, } from "./hooks/index.js";
|
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,YAAY,GAQZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAA6C,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAMN,UAAU,EAEV,SAAS,GACT,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * Core modules shared between all run modes.\n */\n\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype CompactionResult,\n\ttype ModelCycleResult,\n\ttype PromptOptions,\n\ttype SessionStats,\n} from \"./agent-session.js\";\nexport { type BashExecutorOptions, type BashResult, executeBash } from \"./bash-executor.js\";\nexport {\n\ttype HookAPI,\n\ttype HookError,\n\ttype HookEvent,\n\ttype HookEventContext,\n\ttype HookFactory,\n\tHookRunner,\n\ttype HookUIContext,\n\tloadHooks,\n} from \"./hooks/index.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACN,YAAY,GAQZ,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAA6C,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAIN,0BAA0B,EAG1B,eAAe,GAIf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAMN,UAAU,EAEV,SAAS,GACT,MAAM,kBAAkB,CAAC","sourcesContent":["/**\n * Core modules shared between all run modes.\n */\n\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype CompactionResult,\n\ttype ModelCycleResult,\n\ttype PromptOptions,\n\ttype SessionStats,\n} from \"./agent-session.js\";\nexport { type BashExecutorOptions, type BashResult, executeBash } from \"./bash-executor.js\";\nexport {\n\ttype CustomAgentTool,\n\ttype CustomToolFactory,\n\ttype CustomToolsLoadResult,\n\tdiscoverAndLoadCustomTools,\n\ttype ExecResult,\n\ttype LoadedCustomTool,\n\tloadCustomTools,\n\ttype RenderResultOptions,\n\ttype ToolAPI,\n\ttype ToolUIContext,\n} from \"./custom-tools/index.js\";\nexport {\n\ttype HookAPI,\n\ttype HookError,\n\ttype HookEvent,\n\ttype HookEventContext,\n\ttype HookFactory,\n\tHookRunner,\n\ttype HookUIContext,\n\tloadHooks,\n} from \"./hooks/index.js\";\n"]}
|