@oyasmi/pipiclaw 0.9.1-beta.2 → 0.9.2-beta.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/dist/agent/channel-runner.d.ts +9 -1
- package/dist/agent/channel-runner.js +51 -18
- package/dist/agent/command-extension.js +24 -27
- package/dist/agent/commands.d.ts +51 -7
- package/dist/agent/commands.js +199 -59
- package/dist/agent/effect-ledger.js +9 -2
- package/dist/agent/job-manager.d.ts +4 -0
- package/dist/agent/job-manager.js +17 -2
- package/dist/agent/prompt/manifest.d.ts +1 -1
- package/dist/agent/prompt/manifest.js +6 -7
- package/dist/agent/prompt/sections.js +9 -5
- package/dist/agent/reply-limits.d.ts +16 -0
- package/dist/agent/reply-limits.js +17 -0
- package/dist/agent/session-events.d.ts +2 -0
- package/dist/agent/session-events.js +29 -14
- package/dist/agent/status-render.js +12 -12
- package/dist/agent/turn-recovery.js +2 -2
- package/dist/agent/type-guards.js +5 -1
- package/dist/agent/workspace-resources.d.ts +2 -2
- package/dist/agent/workspace-resources.js +41 -3
- package/dist/executor.d.ts +28 -0
- package/dist/executor.js +120 -18
- package/dist/file-store.d.ts +96 -0
- package/dist/file-store.js +189 -0
- package/dist/main.js +3 -4
- package/dist/memory/commands.js +79 -38
- package/dist/memory/consolidation.d.ts +5 -1
- package/dist/memory/consolidation.js +35 -38
- package/dist/memory/extraction.d.ts +8 -1
- package/dist/memory/extraction.js +47 -4
- package/dist/memory/files.d.ts +0 -1
- package/dist/memory/files.js +31 -12
- package/dist/memory/lifecycle.js +9 -2
- package/dist/memory/maintenance-jobs.js +16 -38
- package/dist/memory/maintenance-state.js +2 -1
- package/dist/memory/metadata.d.ts +3 -0
- package/dist/memory/metadata.js +7 -0
- package/dist/memory/recall.d.ts +19 -0
- package/dist/memory/recall.js +116 -24
- package/dist/memory/review-log.d.ts +0 -2
- package/dist/memory/review-log.js +0 -0
- package/dist/memory/session-corpus.js +5 -0
- package/dist/memory/session-search.js +15 -22
- package/dist/memory/sidecar-worker.js +4 -0
- package/dist/memory/source-window.d.ts +0 -1
- package/dist/memory/source-window.js +0 -5
- package/dist/memory/transcript.d.ts +10 -0
- package/dist/memory/transcript.js +39 -0
- package/dist/playbooks/agent-delegation.md +34 -25
- package/dist/playbooks/background-jobs.md +8 -16
- package/dist/playbooks/catalog.d.ts +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/event-scheduling.md +15 -15
- package/dist/playbooks/memory-and-learning.md +30 -23
- package/dist/playbooks/outbound-media.md +15 -8
- package/dist/playbooks/runtime-orientation.md +40 -37
- package/dist/playbooks/task-driving.md +36 -38
- package/dist/playbooks/task-planning.md +21 -21
- package/dist/runtime/app-home.d.ts +6 -0
- package/dist/runtime/app-home.js +16 -7
- package/dist/runtime/bootstrap.js +54 -13
- package/dist/runtime/channel-context.d.ts +2 -1
- package/dist/runtime/delivery.js +3 -3
- package/dist/runtime/dingtalk.d.ts +9 -1
- package/dist/runtime/dingtalk.js +30 -15
- package/dist/runtime/durable-dispatch.d.ts +26 -1
- package/dist/runtime/durable-dispatch.js +51 -5
- package/dist/runtime/event-commands.d.ts +15 -0
- package/dist/runtime/event-commands.js +55 -56
- package/dist/runtime/events.d.ts +4 -2
- package/dist/runtime/events.js +15 -20
- package/dist/runtime/project-commands.d.ts +16 -0
- package/dist/runtime/project-commands.js +13 -17
- package/dist/runtime/subagent-commands.d.ts +20 -0
- package/dist/runtime/subagent-commands.js +61 -58
- package/dist/runtime/task-commands.d.ts +37 -0
- package/dist/runtime/task-commands.js +108 -66
- package/dist/runtime/task-driver.js +2 -2
- package/dist/security/block-message.d.ts +11 -0
- package/dist/security/block-message.js +12 -0
- package/dist/security/path-guard-check.d.ts +13 -0
- package/dist/security/path-guard-check.js +39 -0
- package/dist/security/path-guard.js +61 -12
- package/dist/security/types.d.ts +9 -0
- package/dist/settings.js +3 -2
- package/dist/shared/atomic-file.d.ts +17 -1
- package/dist/shared/atomic-file.js +50 -3
- package/dist/shared/duration.d.ts +2 -0
- package/dist/shared/duration.js +7 -0
- package/dist/shared/safe-id.d.ts +19 -0
- package/dist/shared/safe-id.js +24 -0
- package/dist/shared/text-utils.d.ts +1 -1
- package/dist/shared/text-utils.js +3 -8
- package/dist/shared/type-guards.d.ts +2 -0
- package/dist/shared/type-guards.js +4 -0
- package/dist/subagents/discovery.d.ts +51 -19
- package/dist/subagents/discovery.js +93 -98
- package/dist/subagents/external/claude-code.js +40 -2
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/run.js +61 -8
- package/dist/subagents/format.d.ts +3 -2
- package/dist/subagents/format.js +3 -7
- package/dist/subagents/runs.d.ts +1 -1
- package/dist/subagents/runs.js +10 -9
- package/dist/subagents/tool.d.ts +31 -18
- package/dist/subagents/tool.js +592 -562
- package/dist/subagents/workspace-lease.js +1 -1
- package/dist/tasks/control.js +7 -9
- package/dist/tasks/ledger.d.ts +2 -2
- package/dist/tasks/ledger.js +3 -7
- package/dist/tasks/transitions.d.ts +5 -1
- package/dist/tasks/transitions.js +2 -2
- package/dist/tasks/verification.d.ts +7 -5
- package/dist/tools/bash.d.ts +1 -2
- package/dist/tools/bash.js +99 -76
- package/dist/tools/config.d.ts +6 -1
- package/dist/tools/config.js +9 -0
- package/dist/tools/edit.d.ts +2 -3
- package/dist/tools/edit.js +276 -75
- package/dist/tools/event-manage.d.ts +13 -7
- package/dist/tools/event-manage.js +52 -14
- package/dist/tools/glob-match.d.ts +11 -0
- package/dist/tools/glob-match.js +75 -0
- package/dist/tools/glob.d.ts +15 -0
- package/dist/tools/glob.js +113 -0
- package/dist/tools/grep.d.ts +0 -1
- package/dist/tools/grep.js +60 -44
- package/dist/tools/ignore-dirs.d.ts +6 -0
- package/dist/tools/ignore-dirs.js +15 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.js +54 -40
- package/dist/tools/job.d.ts +0 -1
- package/dist/tools/job.js +3 -9
- package/dist/tools/line-index.d.ts +16 -0
- package/dist/tools/line-index.js +76 -0
- package/dist/tools/memory-manage.d.ts +21 -8
- package/dist/tools/memory-manage.js +114 -103
- package/dist/tools/presentation.d.ts +2 -0
- package/dist/tools/presentation.js +109 -0
- package/dist/tools/read.d.ts +2 -2
- package/dist/tools/read.js +100 -120
- package/dist/tools/registry.d.ts +4 -1
- package/dist/tools/registry.js +89 -22
- package/dist/tools/send-media.d.ts +6 -6
- package/dist/tools/send-media.js +21 -43
- package/dist/tools/session-search.d.ts +0 -1
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-security.d.ts +0 -2
- package/dist/tools/skill-security.js +1 -25
- package/dist/tools/skill.d.ts +31 -0
- package/dist/tools/skill.js +153 -0
- package/dist/tools/subagent-manage.d.ts +6 -5
- package/dist/tools/subagent-manage.js +47 -47
- package/dist/tools/task-manage/create.d.ts +2 -2
- package/dist/tools/task-manage/create.js +1 -3
- package/dist/tools/task-manage/lifecycle.d.ts +9 -6
- package/dist/tools/task-manage/lifecycle.js +49 -56
- package/dist/tools/task-manage/schema.d.ts +27 -15
- package/dist/tools/task-manage/schema.js +58 -74
- package/dist/tools/task-manage/shared.d.ts +11 -6
- package/dist/tools/task-manage/shared.js +30 -21
- package/dist/tools/task-manage/types.d.ts +14 -15
- package/dist/tools/task-manage/verification.d.ts +4 -4
- package/dist/tools/task-manage/verification.js +6 -8
- package/dist/tools/task-manage.d.ts +8 -11
- package/dist/tools/task-manage.js +63 -50
- package/dist/tools/tool-details.d.ts +17 -1
- package/dist/tools/tool-details.js +24 -0
- package/dist/tools/truncate.d.ts +8 -0
- package/dist/tools/truncate.js +8 -0
- package/dist/tools/web-fetch.d.ts +0 -1
- package/dist/tools/web-fetch.js +9 -2
- package/dist/tools/web-search.d.ts +0 -1
- package/dist/tools/web-search.js +0 -1
- package/dist/tools/write-content.d.ts +3 -3
- package/dist/tools/write-content.js +12 -41
- package/dist/tools/write.d.ts +2 -3
- package/dist/tools/write.js +3 -4
- package/dist/tui/app.js +1 -1
- package/dist/tui/commands.d.ts +1 -1
- package/dist/tui/commands.js +1 -1
- package/dist/tui/turn-controller.d.ts +1 -1
- package/dist/tui/turn-controller.js +14 -4
- package/dist/usage/ledger.js +7 -4
- package/dist/usage/render.js +10 -8
- package/examples/sub-agents/README.md +2 -0
- package/package.json +3 -2
- package/dist/tools/skill-manage.d.ts +0 -41
- package/dist/tools/skill-manage.js +0 -231
package/dist/tools/read.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { extname } from "path";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { checkPathGuard } from "../security/path-guard-check.js";
|
|
5
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
6
6
|
import { shellEscape } from "../shared/shell-escape.js";
|
|
7
|
-
import {
|
|
7
|
+
import { resolveLineOffset } from "./line-index.js";
|
|
8
|
+
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, MAX_INLINE_BINARY_BYTES, truncateHead, } from "./truncate.js";
|
|
8
9
|
/**
|
|
9
10
|
* Map of file extensions to MIME types for common image formats
|
|
10
11
|
*/
|
|
@@ -26,29 +27,20 @@ function isImageFile(filePath) {
|
|
|
26
27
|
const DIR_MAX_DEPTH = 2;
|
|
27
28
|
const DIR_PER_DIR_LIMIT = 12;
|
|
28
29
|
/**
|
|
29
|
-
* Render a depth-2 directory tree from
|
|
30
|
-
*
|
|
31
|
-
* `find -printf` / `stat` formats differ across BSD, GNU, and busybox; the structure is the value.
|
|
30
|
+
* Render a depth-2 directory tree from `FileStore.listDirectory` entries. Kept deliberately
|
|
31
|
+
* portable — no sizes or mtimes, since formats differ across platforms; the structure is the value.
|
|
32
32
|
*/
|
|
33
|
-
function renderDirectoryTree(
|
|
34
|
-
const rootPrefix = rootPath.endsWith("/") ? rootPath : `${rootPath}/`;
|
|
35
|
-
const entries = rawPaths
|
|
36
|
-
.split("\n")
|
|
37
|
-
.map((line) => line.trim())
|
|
38
|
-
.filter((line) => line.length > 0 && line !== rootPath && line !== rootPrefix)
|
|
39
|
-
.map((line) => (line.startsWith(rootPrefix) ? line.slice(rootPrefix.length) : line))
|
|
40
|
-
.sort((a, b) => a.replace(/\/$/, "").localeCompare(b.replace(/\/$/, "")));
|
|
33
|
+
function renderDirectoryTree(entries) {
|
|
41
34
|
if (entries.length === 0) {
|
|
42
35
|
return "(empty directory)";
|
|
43
36
|
}
|
|
37
|
+
const sorted = [...entries].sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
44
38
|
// Group by immediate parent so we can cap children per directory.
|
|
45
39
|
const perParentCount = new Map();
|
|
46
40
|
const lines = [];
|
|
47
41
|
const elided = new Map();
|
|
48
|
-
for (const entry of
|
|
49
|
-
const
|
|
50
|
-
const rel = isDir ? entry.slice(0, -1) : entry;
|
|
51
|
-
const segments = rel.split("/");
|
|
42
|
+
for (const entry of sorted) {
|
|
43
|
+
const segments = entry.relativePath.split("/");
|
|
52
44
|
const depth = segments.length - 1;
|
|
53
45
|
const parent = depth === 0 ? "" : segments.slice(0, -1).join("/");
|
|
54
46
|
const count = (perParentCount.get(parent) ?? 0) + 1;
|
|
@@ -57,7 +49,7 @@ function renderDirectoryTree(rootPath, rawPaths) {
|
|
|
57
49
|
elided.set(parent, (elided.get(parent) ?? 0) + 1);
|
|
58
50
|
continue;
|
|
59
51
|
}
|
|
60
|
-
lines.push(`${" ".repeat(depth)}${
|
|
52
|
+
lines.push(`${" ".repeat(depth)}${entry.name}${entry.isDirectory ? "/" : ""}`);
|
|
61
53
|
}
|
|
62
54
|
for (const [, count] of elided) {
|
|
63
55
|
lines.push(` [+${count} more]`);
|
|
@@ -65,7 +57,6 @@ function renderDirectoryTree(rootPath, rawPaths) {
|
|
|
65
57
|
return lines.join("\n");
|
|
66
58
|
}
|
|
67
59
|
const readSchema = Type.Object({
|
|
68
|
-
label: Type.String({ description: "Brief description of what you're reading and why (shown to user)" }),
|
|
69
60
|
path: Type.String({ description: "Path to the file to read (relative or absolute)" }),
|
|
70
61
|
offset: Type.Optional(Type.Integer({ minimum: 1, description: "Line number to start reading from (1-indexed)" })),
|
|
71
62
|
limit: Type.Optional(Type.Integer({ minimum: 1, description: "Maximum number of lines to read" })),
|
|
@@ -77,20 +68,7 @@ function countSplitLines(content, lines) {
|
|
|
77
68
|
}
|
|
78
69
|
return content.endsWith("\n") ? lines.length - 1 : lines.length;
|
|
79
70
|
}
|
|
80
|
-
function
|
|
81
|
-
return countSplitLines(content, content.split("\n"));
|
|
82
|
-
}
|
|
83
|
-
function formatPathBlockMessage(resolvedPath, category, reason) {
|
|
84
|
-
const lines = [`Path blocked${category ? ` [${category}]` : ""}`];
|
|
85
|
-
if (reason) {
|
|
86
|
-
lines.push(`Reason: ${reason}`);
|
|
87
|
-
}
|
|
88
|
-
if (resolvedPath) {
|
|
89
|
-
lines.push(`Resolved path: ${resolvedPath}`);
|
|
90
|
-
}
|
|
91
|
-
return lines.join("\n");
|
|
92
|
-
}
|
|
93
|
-
export function createReadTool(executor, options = {}) {
|
|
71
|
+
export function createReadTool(executor, fileStore, options = {}) {
|
|
94
72
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
95
73
|
const securityContext = options.securityContext ?? {
|
|
96
74
|
agentWorkspaceDir: process.cwd(),
|
|
@@ -102,44 +80,39 @@ export function createReadTool(executor, options = {}) {
|
|
|
102
80
|
description: `Read the contents of a file. Supports text files and images (jpg, png, gif, webp). Images are sent as attachments. For text files, output is truncated to ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). Use offset/limit for large files.`,
|
|
103
81
|
parameters: readSchema,
|
|
104
82
|
execute: async (_toolCallId, { path, offset, limit }, signal) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
type: "path",
|
|
110
|
-
tool: "read",
|
|
111
|
-
channelId: options.channelId,
|
|
112
|
-
rawPath: path,
|
|
113
|
-
operation: "read",
|
|
114
|
-
resolvedPath: guardResult.resolvedPath,
|
|
115
|
-
category: guardResult.category,
|
|
116
|
-
reason: guardResult.reason,
|
|
117
|
-
});
|
|
118
|
-
throw new Error(formatPathBlockMessage(guardResult.resolvedPath, guardResult.category, guardResult.reason));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
83
|
+
const target = await checkPathGuard(path, "read", securityConfig, securityContext, {
|
|
84
|
+
tool: "read",
|
|
85
|
+
channelId: options.channelId,
|
|
86
|
+
});
|
|
121
87
|
const mimeType = isImageFile(path);
|
|
122
88
|
if (mimeType) {
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
89
|
+
// Stat before reading: base64-encoding a file over the inline limit is pointless work,
|
|
90
|
+
// and doing it via `FileStore.readBytes` rather than shelling out to `base64` (spec 044,
|
|
91
|
+
// D7) means there is no 4/3 blow-up through a captured stdout string to worry about.
|
|
92
|
+
const stat = await fileStore.stat(target);
|
|
93
|
+
if (!stat || !stat.isFile) {
|
|
94
|
+
throw new RecoverableToolError(`Failed to read file: ${path}. Check the path — try \`read\` on its parent directory to confirm it exists.`);
|
|
95
|
+
}
|
|
96
|
+
if (stat.size > MAX_INLINE_BINARY_BYTES) {
|
|
97
|
+
throw new RecoverableToolError(`Image ${path} is ${formatSize(stat.size)}, over the ${formatSize(MAX_INLINE_BINARY_BYTES)} inline limit. ` +
|
|
98
|
+
"Compress or resize it first with bash (e.g. sips/convert/ffmpeg), or read it as text to inspect metadata only.");
|
|
127
99
|
}
|
|
128
|
-
const
|
|
100
|
+
const { data } = await fileStore.readBytes(target, { signal });
|
|
129
101
|
return {
|
|
130
102
|
content: [
|
|
131
103
|
{ type: "text", text: `Read image file [${mimeType}]` },
|
|
132
|
-
{ type: "image", data: base64, mimeType },
|
|
104
|
+
{ type: "image", data: data.toString("base64"), mimeType },
|
|
133
105
|
],
|
|
134
106
|
details: undefined,
|
|
135
107
|
};
|
|
136
108
|
}
|
|
137
109
|
// PDF documents are converted to text with pdftotext, then run through the same
|
|
138
|
-
// offset/limit/truncation pipeline as any text file.
|
|
110
|
+
// offset/limit/truncation pipeline as any text file. That's a command, not a file read, so
|
|
111
|
+
// it still goes through `Executor`.
|
|
139
112
|
const isPdf = extname(path).toLowerCase() === ".pdf";
|
|
140
113
|
let pdfText = "";
|
|
141
114
|
if (isPdf) {
|
|
142
|
-
const converted = await executor.exec(`pdftotext -layout ${shellEscape(
|
|
115
|
+
const converted = await executor.exec(`pdftotext -layout ${shellEscape(target)} - 2>&1`, { signal });
|
|
143
116
|
if (converted.code === 127) {
|
|
144
117
|
throw new Error(`Cannot read ${path}: pdftotext is not installed. Install poppler-utils, or ask the user to send a text version.`);
|
|
145
118
|
}
|
|
@@ -149,73 +122,78 @@ export function createReadTool(executor, options = {}) {
|
|
|
149
122
|
}
|
|
150
123
|
pdfText = converted.stdout;
|
|
151
124
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
let totalFileLines;
|
|
156
|
-
if (isPdf) {
|
|
157
|
-
totalFileLines = countTextLines(pdfText);
|
|
125
|
+
const stat = isPdf ? undefined : await fileStore.stat(target);
|
|
126
|
+
if (!isPdf && !stat) {
|
|
127
|
+
throw new RecoverableToolError(`Failed to read file: ${path}. Check the path — try \`read\` on its parent directory to confirm it exists.`);
|
|
158
128
|
}
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const listing = await executor.exec(`{ find ${shellEscape(path)} -maxdepth ${DIR_MAX_DEPTH} -type d | sed 's,$,/,'; ` +
|
|
166
|
-
`find ${shellEscape(path)} -maxdepth ${DIR_MAX_DEPTH} ! -type d; }`, { signal });
|
|
167
|
-
if (listing.code !== 0) {
|
|
168
|
-
throw new Error(listing.stderr || `Failed to list directory: ${path}`);
|
|
169
|
-
}
|
|
170
|
-
return {
|
|
171
|
-
content: [
|
|
172
|
-
{ type: "text", text: `Directory: ${path}\n\n${renderDirectoryTree(path, listing.stdout)}` },
|
|
173
|
-
],
|
|
174
|
-
details: undefined,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
totalFileLines = Number.parseInt(countResult.stdout.trim(), 10);
|
|
129
|
+
if (stat?.isDirectory) {
|
|
130
|
+
const entries = await fileStore.listDirectory(target, { maxDepth: DIR_MAX_DEPTH });
|
|
131
|
+
return {
|
|
132
|
+
content: [{ type: "text", text: `Directory: ${path}\n\n${renderDirectoryTree(entries)}` }],
|
|
133
|
+
details: undefined,
|
|
134
|
+
};
|
|
178
135
|
}
|
|
179
|
-
// Apply offset if specified (1-indexed)
|
|
180
136
|
const startLine = offset ? Math.max(1, offset) : 1;
|
|
181
137
|
const startLineDisplay = startLine;
|
|
182
|
-
//
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
: "The file is empty; omit offset.";
|
|
188
|
-
throw new Error(`Offset ${offset} is beyond end of file (${totalFileLines} lines total). ${guidance}`);
|
|
189
|
-
}
|
|
190
|
-
// Read content from the offset. PDF text is already in memory; files stream from disk.
|
|
138
|
+
// Resolve the byte offset of `startLine` via the incremental line index (D4.2). PDF text is
|
|
139
|
+
// small and already fully in memory, so it just splits directly. For a real file, the index
|
|
140
|
+
// scans forward from wherever it last left off; reaching EOF without finding `startLine`
|
|
141
|
+
// means the offset is out of bounds -- decided from what the scan actually observed (D4.3),
|
|
142
|
+
// never from a separate precomputed total.
|
|
191
143
|
let selectedContent;
|
|
144
|
+
let windowEof;
|
|
145
|
+
let linesBeforeWindow;
|
|
192
146
|
if (isPdf) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
.
|
|
147
|
+
const pdfLines = pdfText.split("\n");
|
|
148
|
+
const totalPdfLines = countSplitLines(pdfText, pdfLines);
|
|
149
|
+
if (startLine > Math.max(totalPdfLines, 1)) {
|
|
150
|
+
throw new RecoverableToolError(`Offset ${offset} is beyond end of file (${totalPdfLines} lines total). ` +
|
|
151
|
+
(totalPdfLines > 0
|
|
152
|
+
? `Use offset=${totalPdfLines} to read the last line, or omit offset to read from the start.`
|
|
153
|
+
: "The file is empty; omit offset."));
|
|
154
|
+
}
|
|
155
|
+
selectedContent = startLine === 1 ? pdfText : pdfLines.slice(startLine - 1).join("\n");
|
|
156
|
+
windowEof = true;
|
|
157
|
+
linesBeforeWindow = startLine - 1;
|
|
200
158
|
}
|
|
201
159
|
else {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
160
|
+
const fileStat = stat;
|
|
161
|
+
if (fileStat.size === 0) {
|
|
162
|
+
if (offset !== undefined && startLine > 1) {
|
|
163
|
+
throw new RecoverableToolError(`Offset ${offset} is beyond end of file (0 lines total). The file is empty; omit offset.`);
|
|
164
|
+
}
|
|
165
|
+
selectedContent = "";
|
|
166
|
+
windowEof = true;
|
|
167
|
+
linesBeforeWindow = 0;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
const located = await resolveLineOffset(fileStore, target, fileStat, startLine, signal);
|
|
171
|
+
if (located.offset === undefined) {
|
|
172
|
+
const guidance = located.knownLines > 0
|
|
173
|
+
? `Use offset=${located.knownLines} to read the last line, or omit offset to read from the start.`
|
|
174
|
+
: "The file is empty; omit offset.";
|
|
175
|
+
throw new RecoverableToolError(`Offset ${offset} is beyond end of file (${located.knownLines} lines total). ${guidance}`);
|
|
176
|
+
}
|
|
177
|
+
// Bounded at the source: read at most twice the byte cap, which always leaves
|
|
178
|
+
// `truncateHead` enough to apply whichever limit binds first (line or byte), however
|
|
179
|
+
// short the lines are.
|
|
180
|
+
const readWindowBytes = DEFAULT_MAX_BYTES * 2;
|
|
181
|
+
const { data, eof } = await fileStore.readBytes(target, {
|
|
182
|
+
start: located.offset,
|
|
183
|
+
maxBytes: readWindowBytes,
|
|
184
|
+
signal,
|
|
185
|
+
});
|
|
186
|
+
selectedContent = data.toString("utf-8");
|
|
187
|
+
windowEof = eof;
|
|
188
|
+
linesBeforeWindow = startLine - 1;
|
|
216
189
|
}
|
|
217
|
-
selectedContent = result.stdout;
|
|
218
190
|
}
|
|
191
|
+
// Total lines known so far, from the *whole* read window before any user `limit` slices
|
|
192
|
+
// it down: exact when the window reached the real EOF, a lower bound otherwise (D4.3) --
|
|
193
|
+
// never a number nobody actually counted.
|
|
194
|
+
const linesInWindow = countSplitLines(selectedContent, selectedContent.split("\n"));
|
|
195
|
+
const knownTotalLines = linesBeforeWindow + linesInWindow;
|
|
196
|
+
const totalIsExact = windowEof;
|
|
219
197
|
let userLimitedLines;
|
|
220
198
|
// Apply user limit if specified
|
|
221
199
|
if (limit !== undefined) {
|
|
@@ -238,23 +216,25 @@ export function createReadTool(executor, options = {}) {
|
|
|
238
216
|
// Truncation occurred - build actionable notice
|
|
239
217
|
const endLineDisplay = startLineDisplay + truncation.outputLines - 1;
|
|
240
218
|
const nextOffset = endLineDisplay + 1;
|
|
219
|
+
const totalLabel = totalIsExact ? `${knownTotalLines}` : `>=${knownTotalLines}`;
|
|
241
220
|
outputText = truncation.content;
|
|
242
221
|
if (truncation.truncatedBy === "lines") {
|
|
243
|
-
outputText += `\n\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${
|
|
222
|
+
outputText += `\n\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalLabel}. Use offset=${nextOffset} to continue]`;
|
|
244
223
|
}
|
|
245
224
|
else {
|
|
246
|
-
outputText += `\n\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${
|
|
225
|
+
outputText += `\n\n[Showing lines ${startLineDisplay}-${endLineDisplay} of ${totalLabel} (${formatSize(DEFAULT_MAX_BYTES)} limit). Use offset=${nextOffset} to continue]`;
|
|
247
226
|
}
|
|
248
227
|
details = { truncation };
|
|
249
228
|
}
|
|
250
229
|
else if (userLimitedLines !== undefined) {
|
|
251
230
|
// User specified limit, check if there's more content
|
|
252
231
|
const linesFromStart = startLine - 1 + userLimitedLines;
|
|
253
|
-
|
|
254
|
-
|
|
232
|
+
const moreAvailable = !windowEof || linesFromStart < knownTotalLines;
|
|
233
|
+
if (moreAvailable) {
|
|
255
234
|
const nextOffset = startLine + userLimitedLines;
|
|
256
235
|
outputText = truncation.content;
|
|
257
|
-
|
|
236
|
+
const remainingLabel = windowEof ? `${knownTotalLines - linesFromStart}` : "more";
|
|
237
|
+
outputText += `\n\n[${remainingLabel} more lines in file. Use offset=${nextOffset} to continue]`;
|
|
258
238
|
}
|
|
259
239
|
else {
|
|
260
240
|
outputText = truncation.content;
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { ChannelJobManager } from "../agent/job-manager.js";
|
|
4
4
|
import type { Executor } from "../executor.js";
|
|
5
|
+
import type { FileStore } from "../file-store.js";
|
|
5
6
|
import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
6
7
|
import type { MediaSender } from "../runtime/channel-context.js";
|
|
7
8
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
@@ -19,6 +20,8 @@ import { type ToolDetailsKind } from "./tool-details.js";
|
|
|
19
20
|
*/
|
|
20
21
|
export interface ToolBuildContext {
|
|
21
22
|
executor: Executor;
|
|
23
|
+
/** File-content port for the generic file tools (spec 044, D1); `Executor` stays command-only. */
|
|
24
|
+
fileStore: FileStore;
|
|
22
25
|
securityConfig: SecurityConfig;
|
|
23
26
|
securityContext: SecurityRuntimeContext;
|
|
24
27
|
channelId: string;
|
|
@@ -26,7 +29,7 @@ export interface ToolBuildContext {
|
|
|
26
29
|
workspaceDir: string;
|
|
27
30
|
/** Main set: `toolsConfig.tools.web`; sub-agent set: the sub-agent's own webConfig. */
|
|
28
31
|
webConfig?: PipiclawWebToolsConfig;
|
|
29
|
-
/** Present only on the main path; gates
|
|
32
|
+
/** Present only on the main path; gates the task_* tools and the bash interceptor. */
|
|
30
33
|
toolsConfig?: PipiclawToolsConfig;
|
|
31
34
|
/** Sub-agent set passes its per-invocation bash timeout; the main set relies on the built-in default. */
|
|
32
35
|
bashDefaultTimeoutSeconds?: number;
|
package/dist/tools/registry.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createBashTool } from "./bash.js";
|
|
2
2
|
import { createEditTool } from "./edit.js";
|
|
3
3
|
import { createEventManageTool } from "./event-manage.js";
|
|
4
|
+
import { createGlobTool } from "./glob.js";
|
|
4
5
|
import { createGrepTool } from "./grep.js";
|
|
5
6
|
import { createJobTool } from "./job.js";
|
|
6
|
-
import {
|
|
7
|
+
import { createMemoryForgetTool, createMemorySaveTool, createMemorySearchTool } from "./memory-manage.js";
|
|
7
8
|
import { createReadTool } from "./read.js";
|
|
8
9
|
import { createSendMediaTool } from "./send-media.js";
|
|
9
10
|
import { createSessionSearchTool } from "./session-search.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
11
|
+
import { createSkillTool } from "./skill.js";
|
|
12
|
+
import { createTaskCloseTool, createTaskCreateTool, createTaskListTool, createTaskUpdateTool, createTaskVerifyTool, } from "./task-manage.js";
|
|
12
13
|
import { withToolDetails } from "./tool-details.js";
|
|
13
14
|
import { createWebFetchTool } from "./web-fetch.js";
|
|
14
15
|
import { createWebSearchTool } from "./web-search.js";
|
|
@@ -26,6 +27,16 @@ function fileToolOptions(ctx) {
|
|
|
26
27
|
channelId: ctx.channelId,
|
|
27
28
|
};
|
|
28
29
|
}
|
|
30
|
+
function memoryToolOptions(ctx) {
|
|
31
|
+
return {
|
|
32
|
+
channelId: ctx.channelId,
|
|
33
|
+
channelDir: ctx.channelDir,
|
|
34
|
+
workspaceDir: ctx.workspaceDir,
|
|
35
|
+
memoryCandidateStore: req(ctx.memoryCandidateStore, "memoryCandidateStore"),
|
|
36
|
+
getCurrentModel: req(ctx.getCurrentModel, "getCurrentModel"),
|
|
37
|
+
resolveApiKey: req(ctx.resolveApiKey, "resolveApiKey"),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
29
40
|
function webEnabled(ctx) {
|
|
30
41
|
return ctx.webConfig != null && ctx.webConfig.enable !== false;
|
|
31
42
|
}
|
|
@@ -39,7 +50,7 @@ export const TOOL_REGISTRY = [
|
|
|
39
50
|
{
|
|
40
51
|
name: "read",
|
|
41
52
|
availableToSubagents: true,
|
|
42
|
-
create: (ctx) => createReadTool(ctx.executor, fileToolOptions(ctx)),
|
|
53
|
+
create: (ctx) => createReadTool(ctx.executor, ctx.fileStore, fileToolOptions(ctx)),
|
|
43
54
|
},
|
|
44
55
|
{
|
|
45
56
|
name: "bash",
|
|
@@ -57,17 +68,22 @@ export const TOOL_REGISTRY = [
|
|
|
57
68
|
{
|
|
58
69
|
name: "edit",
|
|
59
70
|
availableToSubagents: true,
|
|
60
|
-
create: (ctx) => createEditTool(ctx.
|
|
71
|
+
create: (ctx) => createEditTool(ctx.fileStore, fileToolOptions(ctx)),
|
|
61
72
|
},
|
|
62
73
|
{
|
|
63
74
|
name: "grep",
|
|
64
75
|
availableToSubagents: true,
|
|
65
76
|
create: (ctx) => createGrepTool(ctx.executor, fileToolOptions(ctx)),
|
|
66
77
|
},
|
|
78
|
+
{
|
|
79
|
+
name: "glob",
|
|
80
|
+
availableToSubagents: true,
|
|
81
|
+
create: (ctx) => createGlobTool(ctx.fileStore, fileToolOptions(ctx)),
|
|
82
|
+
},
|
|
67
83
|
{
|
|
68
84
|
name: "write",
|
|
69
85
|
availableToSubagents: true,
|
|
70
|
-
create: (ctx) => createWriteTool(ctx.
|
|
86
|
+
create: (ctx) => createWriteTool(ctx.fileStore, fileToolOptions(ctx)),
|
|
71
87
|
},
|
|
72
88
|
{
|
|
73
89
|
name: "web_search",
|
|
@@ -98,7 +114,7 @@ export const TOOL_REGISTRY = [
|
|
|
98
114
|
// Enabled only when the driving transport supplied a media sender (the DingTalk
|
|
99
115
|
// bot, or the terminal). Absent it, the tool is not built or advertised.
|
|
100
116
|
enabledBy: (ctx) => ctx.mediaSender != null,
|
|
101
|
-
create: (ctx) => createSendMediaTool(ctx.
|
|
117
|
+
create: (ctx) => createSendMediaTool(ctx.fileStore, {
|
|
102
118
|
mediaSender: req(ctx.mediaSender, "mediaSender"),
|
|
103
119
|
channelId: ctx.channelId,
|
|
104
120
|
securityConfig: ctx.securityConfig,
|
|
@@ -116,39 +132,88 @@ export const TOOL_REGISTRY = [
|
|
|
116
132
|
getSessionSearchSettings: req(ctx.getSessionSearchSettings, "getSessionSearchSettings"),
|
|
117
133
|
}),
|
|
118
134
|
},
|
|
135
|
+
// Spec 047, P4: one tool per payload shape. All three share the same build options.
|
|
119
136
|
{
|
|
120
|
-
name: "
|
|
137
|
+
name: "memory_save",
|
|
121
138
|
availableToSubagents: false,
|
|
122
|
-
create: (ctx) =>
|
|
139
|
+
create: (ctx) => createMemorySaveTool(memoryToolOptions(ctx)),
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: "memory_search",
|
|
143
|
+
availableToSubagents: false,
|
|
144
|
+
create: (ctx) => createMemorySearchTool(memoryToolOptions(ctx)),
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "memory_forget",
|
|
148
|
+
availableToSubagents: false,
|
|
149
|
+
create: (ctx) => createMemoryForgetTool(memoryToolOptions(ctx)),
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "skill",
|
|
153
|
+
availableToSubagents: false,
|
|
154
|
+
create: (ctx) => createSkillTool({ workspaceDir: ctx.workspaceDir, ...fileToolOptions(ctx) }),
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: "event_manage",
|
|
158
|
+
availableToSubagents: false,
|
|
159
|
+
create: (ctx) => createEventManageTool({
|
|
160
|
+
workspaceDir: ctx.workspaceDir,
|
|
123
161
|
channelId: ctx.channelId,
|
|
162
|
+
commandGuardConfig: ctx.securityConfig.commandGuard,
|
|
163
|
+
}),
|
|
164
|
+
},
|
|
165
|
+
// tools.tasks is the master switch for the whole autonomous long-running task mechanism;
|
|
166
|
+
// the TaskDriver and per-turn task digest honor the same flag. Five tools, one per payload
|
|
167
|
+
// shape (spec 046, D3.1) — all share it, since none is meaningful without the others.
|
|
168
|
+
{
|
|
169
|
+
name: "task_list",
|
|
170
|
+
availableToSubagents: false,
|
|
171
|
+
enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
|
|
172
|
+
create: (ctx) => createTaskListTool({
|
|
173
|
+
workspaceDir: ctx.workspaceDir,
|
|
124
174
|
channelDir: ctx.channelDir,
|
|
175
|
+
channelId: ctx.channelId,
|
|
176
|
+
workingDirectory: ctx.securityContext.projectRoot,
|
|
177
|
+
}),
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
name: "task_create",
|
|
181
|
+
availableToSubagents: false,
|
|
182
|
+
enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
|
|
183
|
+
create: (ctx) => createTaskCreateTool({
|
|
125
184
|
workspaceDir: ctx.workspaceDir,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
185
|
+
channelDir: ctx.channelDir,
|
|
186
|
+
channelId: ctx.channelId,
|
|
187
|
+
workingDirectory: ctx.securityContext.projectRoot,
|
|
129
188
|
}),
|
|
130
189
|
},
|
|
131
190
|
{
|
|
132
|
-
name: "
|
|
191
|
+
name: "task_update",
|
|
133
192
|
availableToSubagents: false,
|
|
134
|
-
|
|
193
|
+
enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
|
|
194
|
+
create: (ctx) => createTaskUpdateTool({
|
|
195
|
+
workspaceDir: ctx.workspaceDir,
|
|
196
|
+
channelDir: ctx.channelDir,
|
|
197
|
+
channelId: ctx.channelId,
|
|
198
|
+
workingDirectory: ctx.securityContext.projectRoot,
|
|
199
|
+
}),
|
|
135
200
|
},
|
|
136
201
|
{
|
|
137
|
-
name: "
|
|
202
|
+
name: "task_close",
|
|
138
203
|
availableToSubagents: false,
|
|
139
|
-
|
|
204
|
+
enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
|
|
205
|
+
create: (ctx) => createTaskCloseTool({
|
|
140
206
|
workspaceDir: ctx.workspaceDir,
|
|
207
|
+
channelDir: ctx.channelDir,
|
|
141
208
|
channelId: ctx.channelId,
|
|
142
|
-
|
|
209
|
+
workingDirectory: ctx.securityContext.projectRoot,
|
|
143
210
|
}),
|
|
144
211
|
},
|
|
145
212
|
{
|
|
146
|
-
name: "
|
|
213
|
+
name: "task_verify",
|
|
147
214
|
availableToSubagents: false,
|
|
148
|
-
// tools.tasks is the master switch for the whole autonomous long-running task
|
|
149
|
-
// mechanism; the TaskDriver and per-turn task digest honor the same flag.
|
|
150
215
|
enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
|
|
151
|
-
create: (ctx) =>
|
|
216
|
+
create: (ctx) => createTaskVerifyTool({
|
|
152
217
|
workspaceDir: ctx.workspaceDir,
|
|
153
218
|
channelDir: ctx.channelDir,
|
|
154
219
|
channelId: ctx.channelId,
|
|
@@ -178,7 +243,9 @@ export const TOOL_REGISTRY = [
|
|
|
178
243
|
export const TOOL_NAMES = new Set([
|
|
179
244
|
...TOOL_REGISTRY.map((registration) => registration.name),
|
|
180
245
|
"subagent",
|
|
181
|
-
"
|
|
246
|
+
"subagent_inline",
|
|
247
|
+
"subagent_list",
|
|
248
|
+
"subagent_run",
|
|
182
249
|
]);
|
|
183
250
|
/**
|
|
184
251
|
* Build a tool set from the registry, honoring sub-agent availability and config gates.
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
-
import type {
|
|
3
|
+
import type { FileStore } from "../file-store.js";
|
|
4
4
|
import type { MediaSender } from "../runtime/channel-context.js";
|
|
5
5
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
6
6
|
declare const sendMediaSchema: Type.TObject<{
|
|
7
|
-
label: Type.TString;
|
|
8
7
|
path: Type.TString;
|
|
9
8
|
fileName: Type.TOptional<Type.TString>;
|
|
10
9
|
}>;
|
|
@@ -20,9 +19,10 @@ export interface SendMediaToolOptions {
|
|
|
20
19
|
* Send a workspace file to the current channel as a native attachment (inline
|
|
21
20
|
* image or downloadable file). Bound to its channel at build time — like `read`
|
|
22
21
|
* and `bash` — so the model never chooses the destination. The file is read
|
|
23
|
-
* through
|
|
24
|
-
*
|
|
25
|
-
* path-guard as the file tools before any bytes leave
|
|
22
|
+
* through `FileStore` (spec 044, D7) rather than shelling out to `base64`, so
|
|
23
|
+
* there is no 4/3 blow-up through a captured stdout string to size against, and
|
|
24
|
+
* every path passes the same path-guard as the file tools before any bytes leave
|
|
25
|
+
* the box.
|
|
26
26
|
*/
|
|
27
|
-
export declare function createSendMediaTool(
|
|
27
|
+
export declare function createSendMediaTool(fileStore: FileStore, options: SendMediaToolOptions): AgentTool<typeof sendMediaSchema>;
|
|
28
28
|
export {};
|