@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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
4
|
+
import { checkPathGuard } from "../security/path-guard-check.js";
|
|
5
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
6
|
+
import { compileGlobPattern } from "./glob-match.js";
|
|
7
|
+
import { IGNORED_DIR_SEGMENTS } from "./ignore-dirs.js";
|
|
8
|
+
import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
|
|
9
|
+
/**
|
|
10
|
+
* Path discovery by glob pattern, over `FileStore.walkFiles` rather than a `find` shell-out: no
|
|
11
|
+
* GNU/BSD flag drift to worry about, and the walk (prune, entry cap) and the match/sort/format
|
|
12
|
+
* pipeline are both ours to bound. Complements `grep` (content search) — this tool never reads
|
|
13
|
+
* file bytes.
|
|
14
|
+
*/
|
|
15
|
+
/** Hard bound on directory entries the walk itself will traverse, regardless of match count. */
|
|
16
|
+
const MAX_SCAN_ENTRIES = 50_000;
|
|
17
|
+
/** Matched files are only `stat`-ed (for mtime ordering) up to this many; beyond it, scan order stands. */
|
|
18
|
+
const MAX_STAT_FOR_SORT = 2_000;
|
|
19
|
+
/** Paths shown inline; matching `grep`'s FILE_PAGE_LIMIT order of magnitude for a discovery tool. */
|
|
20
|
+
const GLOB_MAX_RESULTS = 100;
|
|
21
|
+
const globSchema = Type.Object({
|
|
22
|
+
pattern: Type.String({
|
|
23
|
+
description: 'Glob pattern to match file paths against (e.g. "**/*.ts", "src/**/*.test.js"). A pattern with no "/" ' +
|
|
24
|
+
'matches the basename at any depth, so "*" and "*.ts" both search the whole tree; include a "/" to anchor the depth.',
|
|
25
|
+
}),
|
|
26
|
+
path: Type.Optional(Type.String({ description: "Directory to search in. Defaults to the workspace/project root." })),
|
|
27
|
+
});
|
|
28
|
+
export function createGlobTool(fileStore, options = {}) {
|
|
29
|
+
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
30
|
+
const securityContext = options.securityContext ?? {
|
|
31
|
+
agentWorkspaceDir: process.cwd(),
|
|
32
|
+
projectRoot: process.cwd(),
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
name: "glob",
|
|
36
|
+
label: "glob",
|
|
37
|
+
description: "Find files whose paths match a glob pattern. Returns matching file paths only (never directories), " +
|
|
38
|
+
"including hidden files; VCS/build directories (node_modules, .git, dist, ...) are excluded. Prefer this " +
|
|
39
|
+
"over `bash find`/`ls -R` for path discovery — it is bounded and sorted by modification time (newest first) " +
|
|
40
|
+
`when few enough files match; up to ${GLOB_MAX_RESULTS} paths come back inline.`,
|
|
41
|
+
parameters: globSchema,
|
|
42
|
+
execute: async (_toolCallId, { pattern, path }, signal) => {
|
|
43
|
+
if (!pattern.trim()) {
|
|
44
|
+
throw new RecoverableToolError("Pattern must not be empty.");
|
|
45
|
+
}
|
|
46
|
+
const searchPath = path?.trim() || ".";
|
|
47
|
+
const target = await checkPathGuard(searchPath, "read", securityConfig, securityContext, {
|
|
48
|
+
tool: "glob",
|
|
49
|
+
channelId: options.channelId,
|
|
50
|
+
});
|
|
51
|
+
let matcher;
|
|
52
|
+
try {
|
|
53
|
+
matcher = compileGlobPattern(pattern);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new RecoverableToolError(`Invalid glob pattern: ${pattern}`);
|
|
57
|
+
}
|
|
58
|
+
const walk = await fileStore.walkFiles(target, {
|
|
59
|
+
maxEntries: MAX_SCAN_ENTRIES,
|
|
60
|
+
prune: (name) => IGNORED_DIR_SEGMENTS.has(name),
|
|
61
|
+
signal,
|
|
62
|
+
});
|
|
63
|
+
const matched = walk.files.filter((relativePath) => matcher.test(relativePath));
|
|
64
|
+
if (matched.length === 0) {
|
|
65
|
+
const scope = path ? `${searchPath}` : "the workspace";
|
|
66
|
+
const text = walk.truncated
|
|
67
|
+
? `Scan of ${scope} hit the ${MAX_SCAN_ENTRIES.toLocaleString()}-file limit before any path matched "${pattern}". ` +
|
|
68
|
+
"Narrow path to a smaller subtree so the scan can complete."
|
|
69
|
+
: `No files matching "${pattern}" in ${scope}.`;
|
|
70
|
+
return { content: [{ type: "text", text }], details: { matchCount: 0 } };
|
|
71
|
+
}
|
|
72
|
+
const sortableByMtime = matched.length <= MAX_STAT_FOR_SORT;
|
|
73
|
+
let ordered;
|
|
74
|
+
if (sortableByMtime) {
|
|
75
|
+
const withMtime = [];
|
|
76
|
+
for (const relativePath of matched) {
|
|
77
|
+
const stat = await fileStore.stat(join(target, ...relativePath.split("/")));
|
|
78
|
+
withMtime.push({ relativePath, mtimeMs: stat?.mtimeMs ?? 0 });
|
|
79
|
+
}
|
|
80
|
+
withMtime.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
81
|
+
ordered = withMtime.map((entry) => entry.relativePath);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
ordered = matched;
|
|
85
|
+
}
|
|
86
|
+
const page = ordered.slice(0, GLOB_MAX_RESULTS);
|
|
87
|
+
const footerParts = [];
|
|
88
|
+
if (ordered.length > page.length) {
|
|
89
|
+
footerParts.push(`Showing ${page.length} of ${ordered.length} matches${sortableByMtime ? ", newest first" : ""}. ` +
|
|
90
|
+
"Narrow the pattern, or pass path=<subdir>, to see the rest.");
|
|
91
|
+
}
|
|
92
|
+
else if (!sortableByMtime) {
|
|
93
|
+
footerParts.push(`${ordered.length} matches, in scan order (too many to sort by modification time).`);
|
|
94
|
+
}
|
|
95
|
+
if (walk.truncated) {
|
|
96
|
+
footerParts.push(`Scan stopped after ${MAX_SCAN_ENTRIES.toLocaleString()} files; results may be incomplete. Narrow path to search a smaller subtree.`);
|
|
97
|
+
}
|
|
98
|
+
const body = page.join("\n");
|
|
99
|
+
const truncation = truncateHead(body);
|
|
100
|
+
let outputText = truncation.content;
|
|
101
|
+
if (footerParts.length > 0) {
|
|
102
|
+
outputText += `\n\n[${footerParts.join(" ")}]`;
|
|
103
|
+
}
|
|
104
|
+
if (truncation.truncated) {
|
|
105
|
+
outputText += `\n\n[Output truncated at ${formatSize(DEFAULT_MAX_BYTES)}; narrow the pattern or path to see the rest.]`;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
content: [{ type: "text", text: outputText }],
|
|
109
|
+
details: { matchCount: ordered.length, shownCount: page.length, scanTruncated: walk.truncated },
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
package/dist/tools/grep.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { Type } from "typebox";
|
|
|
3
3
|
import type { Executor } from "../executor.js";
|
|
4
4
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
5
5
|
declare const grepSchema: Type.TObject<{
|
|
6
|
-
label: Type.TString;
|
|
7
6
|
pattern: Type.TString;
|
|
8
7
|
path: Type.TOptional<Type.TString>;
|
|
9
8
|
glob: Type.TOptional<Type.TString>;
|
package/dist/tools/grep.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { checkPathGuard } from "../security/path-guard-check.js";
|
|
4
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
5
5
|
import { shellEscape } from "../shared/shell-escape.js";
|
|
6
|
-
import {
|
|
6
|
+
import { IGNORED_DIR_SEGMENTS } from "./ignore-dirs.js";
|
|
7
|
+
import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
|
|
7
8
|
/**
|
|
8
9
|
* Structured content search over the filesystem. The execution layer is deliberately thin — one
|
|
9
10
|
* `grep -rnH -B1 -A3` invocation through the shared Executor, with no native dependency. The value
|
|
@@ -19,10 +20,15 @@ const SINGLE_FILE_MATCHES = 200;
|
|
|
19
20
|
/** Files shown per page; `skip` pages through the rest. */
|
|
20
21
|
const FILE_PAGE_LIMIT = 20;
|
|
21
22
|
const SEARCH_TIMEOUT_SECONDS = 30;
|
|
22
|
-
/**
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Raw `grep` stdout capture cap (spec 044, D5.2). Bounded well under the executor's 10MB default so
|
|
25
|
+
* a broad search can never flood memory, and `ExecResult.stdoutTruncated` (D6.2) says honestly
|
|
26
|
+
* whether the cap was hit -- unlike piping through `head -n`, this leaves `result.code` as grep's
|
|
27
|
+
* own exit status, so a real `grep` error (bad regex, missing path) still surfaces as one instead
|
|
28
|
+
* of being masked by `head` exiting 0 regardless of what fed it.
|
|
29
|
+
*/
|
|
30
|
+
const MAX_RAW_RESULT_BYTES = 768 * 1024;
|
|
24
31
|
const grepSchema = Type.Object({
|
|
25
|
-
label: Type.String({ description: "Brief description of what you're searching for and why (shown to user)" }),
|
|
26
32
|
pattern: Type.String({ description: "Extended regular expression (ERE) to search for in file contents." }),
|
|
27
33
|
path: Type.Optional(Type.String({ description: "File or directory to search. Defaults to the workspace root." })),
|
|
28
34
|
glob: Type.Optional(Type.String({
|
|
@@ -31,16 +37,6 @@ const grepSchema = Type.Object({
|
|
|
31
37
|
caseSensitive: Type.Optional(Type.Boolean({ description: "Case-sensitive match. Defaults to true." })),
|
|
32
38
|
skip: Type.Optional(Type.Integer({ minimum: 0, description: "File-page offset for paging through many matching files." })),
|
|
33
39
|
});
|
|
34
|
-
function formatPathBlockMessage(resolvedPath, category, reason) {
|
|
35
|
-
const lines = [`Path blocked${category ? ` [${category}]` : ""}`];
|
|
36
|
-
if (reason) {
|
|
37
|
-
lines.push(`Reason: ${reason}`);
|
|
38
|
-
}
|
|
39
|
-
if (resolvedPath) {
|
|
40
|
-
lines.push(`Resolved path: ${resolvedPath}`);
|
|
41
|
-
}
|
|
42
|
-
return lines.join("\n");
|
|
43
|
-
}
|
|
44
40
|
/** Convert a simple `*`/`?` glob into an anchored regex matched against a basename. */
|
|
45
41
|
function globToRegExp(glob) {
|
|
46
42
|
const escaped = glob
|
|
@@ -146,39 +142,53 @@ export function createGrepTool(executor, options = {}) {
|
|
|
146
142
|
parameters: grepSchema,
|
|
147
143
|
execute: async (_toolCallId, { pattern, path, glob, caseSensitive, skip, }, signal) => {
|
|
148
144
|
if (!pattern.trim()) {
|
|
149
|
-
throw new
|
|
145
|
+
throw new RecoverableToolError("Pattern must not be empty.");
|
|
150
146
|
}
|
|
151
147
|
const searchPath = path?.trim() || ".";
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
operation: "read",
|
|
161
|
-
resolvedPath: guardResult.resolvedPath,
|
|
162
|
-
category: guardResult.category,
|
|
163
|
-
reason: guardResult.reason,
|
|
164
|
-
});
|
|
165
|
-
throw new Error(formatPathBlockMessage(guardResult.resolvedPath, guardResult.category, guardResult.reason));
|
|
166
|
-
}
|
|
167
|
-
}
|
|
148
|
+
// Resolved once, then used for both the guard's judgment and the actual `grep` target
|
|
149
|
+
// (spec 044, D1.1): no separate `cwd` needed on the executor call, so there is no chance of
|
|
150
|
+
// the guard resolving against `projectRoot` while the shell actually runs against the
|
|
151
|
+
// daemon's own cwd (F6).
|
|
152
|
+
const target = await checkPathGuard(searchPath, "read", securityConfig, securityContext, {
|
|
153
|
+
tool: "grep",
|
|
154
|
+
channelId: options.channelId,
|
|
155
|
+
});
|
|
168
156
|
const flags = ["-rnH", "-E", `-B${CONTEXT_BEFORE}`, `-A${CONTEXT_AFTER}`];
|
|
169
157
|
if (caseSensitive === false) {
|
|
170
158
|
flags.push("-i");
|
|
171
159
|
}
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
|
|
160
|
+
// Push directory and glob filters down into `grep` itself (D5.1) so a huge `node_modules`
|
|
161
|
+
// is never scanned in the first place, rather than being scanned, capped, and then
|
|
162
|
+
// filtered away in JS after it already ate the whole result budget (F7). The JS-side
|
|
163
|
+
// `isIgnoredPath`/`globRegExp` filtering below stays as a backstop for a `grep` whose
|
|
164
|
+
// `--exclude-dir` semantics differ.
|
|
165
|
+
for (const segment of IGNORED_DIR_SEGMENTS) {
|
|
166
|
+
flags.push(`--exclude-dir=${segment}`);
|
|
167
|
+
}
|
|
168
|
+
if (glob) {
|
|
169
|
+
flags.push(`--include=${glob}`);
|
|
170
|
+
}
|
|
171
|
+
// `--` terminates flags so a pattern beginning with `-` is not read as one. Bounded via
|
|
172
|
+
// `maxCaptureBytes` (D5.2) rather than a `| head -n` pipe: piping through `head` would
|
|
173
|
+
// have `sh -c` (no pipefail) report `head`'s exit status instead of grep's, silently
|
|
174
|
+
// masking a real grep error (bad regex, missing path) behind `head`'s always-0 exit.
|
|
175
|
+
const command = `grep ${flags.join(" ")} -- ${shellEscape(pattern)} ${shellEscape(target)}`;
|
|
176
|
+
const result = await executor.exec(command, {
|
|
177
|
+
timeout: SEARCH_TIMEOUT_SECONDS,
|
|
178
|
+
signal,
|
|
179
|
+
maxCaptureBytes: MAX_RAW_RESULT_BYTES,
|
|
180
|
+
});
|
|
175
181
|
// grep exit code 1 = no matches (normal), 0 = matches, >=2 = error.
|
|
176
182
|
if (result.code >= 2) {
|
|
177
183
|
const stderr = result.stderr.trim();
|
|
178
|
-
throw new
|
|
184
|
+
throw new RecoverableToolError(`grep failed: ${stderr || `exit code ${result.code}`}. Check the regex (ERE syntax) and that the path exists.`);
|
|
179
185
|
}
|
|
186
|
+
const rawTruncated = result.stdoutTruncated === true;
|
|
187
|
+
// A truncated capture may end mid-line; drop that dangling partial line rather than feed
|
|
188
|
+
// it to the parser, which expects each line to be a complete match or context line.
|
|
189
|
+
const boundedStdout = rawTruncated ? result.stdout.slice(0, result.stdout.lastIndexOf("\n")) : result.stdout;
|
|
180
190
|
const globRegExp = glob ? globToRegExp(glob) : undefined;
|
|
181
|
-
const parsed = parseGrepOutput(
|
|
191
|
+
const parsed = parseGrepOutput(boundedStdout);
|
|
182
192
|
// Filter ignored dirs and (for directory scopes) the optional glob, on the basename.
|
|
183
193
|
const files = [];
|
|
184
194
|
for (const [file, entries] of parsed) {
|
|
@@ -196,13 +206,16 @@ export function createGrepTool(executor, options = {}) {
|
|
|
196
206
|
}
|
|
197
207
|
if (files.length === 0) {
|
|
198
208
|
const scope = glob ? `${searchPath} (glob ${glob})` : searchPath;
|
|
209
|
+
// D5.3: a result set that hit the raw-line cap but still filtered down to nothing must
|
|
210
|
+
// not be reported as "no matches" -- that tells the model to try a *broader* search,
|
|
211
|
+
// which is exactly backwards when the real problem is that the cap was hit before
|
|
212
|
+
// filtering ever got a chance to keep anything.
|
|
213
|
+
const text = rawTruncated
|
|
214
|
+
? `Search hit the ${formatSize(MAX_RAW_RESULT_BYTES)} raw result cap before any match survived filtering in ${scope}. ` +
|
|
215
|
+
"Narrow the path or pattern so fewer raw hits are needed."
|
|
216
|
+
: `No matches found in ${scope}. Try a broader pattern, drop the glob, or widen the path.`;
|
|
199
217
|
return {
|
|
200
|
-
content: [
|
|
201
|
-
{
|
|
202
|
-
type: "text",
|
|
203
|
-
text: `No matches found in ${scope}. Try a broader pattern, drop the glob, or widen the path.`,
|
|
204
|
-
},
|
|
205
|
-
],
|
|
218
|
+
content: [{ type: "text", text }],
|
|
206
219
|
details: { matchCount: 0, fileCount: 0 },
|
|
207
220
|
};
|
|
208
221
|
}
|
|
@@ -239,6 +252,9 @@ export function createGrepTool(executor, options = {}) {
|
|
|
239
252
|
if (moreFiles > 0) {
|
|
240
253
|
footerLines.push(`[${moreFiles} more matching file(s). Use skip=${startOffset + page.length} for the next page.]`);
|
|
241
254
|
}
|
|
255
|
+
if (rawTruncated) {
|
|
256
|
+
footerLines.push(`[Search hit the ${formatSize(MAX_RAW_RESULT_BYTES)} raw result cap; there may be matches beyond what's shown above. Narrow the path or pattern to see them.]`);
|
|
257
|
+
}
|
|
242
258
|
const body = blocks.join("\n\n");
|
|
243
259
|
const footer = footerLines.length > 0 ? `\n\n${footerLines.join("\n")}` : "";
|
|
244
260
|
const truncation = truncateHead(body);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directory names that discovery/search tools should never descend into. Shared by `grep` (pushed
|
|
3
|
+
* down as `grep --exclude-dir=`) and `glob` (pushed down as a walk-time prune), so the two tools
|
|
4
|
+
* agree on what "noise" means instead of drifting independently.
|
|
5
|
+
*/
|
|
6
|
+
export declare const IGNORED_DIR_SEGMENTS: Set<string>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Directory names that discovery/search tools should never descend into. Shared by `grep` (pushed
|
|
3
|
+
* down as `grep --exclude-dir=`) and `glob` (pushed down as a walk-time prune), so the two tools
|
|
4
|
+
* agree on what "noise" means instead of drifting independently.
|
|
5
|
+
*/
|
|
6
|
+
export const IGNORED_DIR_SEGMENTS = new Set([
|
|
7
|
+
"node_modules",
|
|
8
|
+
".git",
|
|
9
|
+
".hg",
|
|
10
|
+
".svn",
|
|
11
|
+
"dist",
|
|
12
|
+
"build",
|
|
13
|
+
".next",
|
|
14
|
+
".cache",
|
|
15
|
+
]);
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { Executor } from "../executor.js";
|
|
4
|
+
import type { FileStore } from "../file-store.js";
|
|
4
5
|
import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
5
6
|
import type { MediaSender } from "../runtime/channel-context.js";
|
|
6
7
|
import type { ProjectScope } from "../security/project-scope.js";
|
|
@@ -10,6 +11,8 @@ import { type SubAgentDiscoveryResult } from "../subagents/discovery.js";
|
|
|
10
11
|
import type { PipiclawToolsConfig } from "./config.js";
|
|
11
12
|
export interface CreatePipiclawToolsOptions {
|
|
12
13
|
executor: Executor;
|
|
14
|
+
/** File-content port for the generic file tools (spec 044, D1); `Executor` stays command-only. */
|
|
15
|
+
fileStore: FileStore;
|
|
13
16
|
getCurrentModel: () => Model<Api>;
|
|
14
17
|
getAvailableModels: () => Model<Api>[];
|
|
15
18
|
resolveApiKey: (model: Model<Api>) => Promise<string>;
|
package/dist/tools/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import { getChannelJobManager } from "../agent/job-manager.js";
|
|
|
2
2
|
import { APP_HOME_DIR } from "../paths.js";
|
|
3
3
|
import { loadSecurityConfig } from "../security/config.js";
|
|
4
4
|
import { withSubAgentsDirWriteDeny } from "../subagents/discovery.js";
|
|
5
|
-
import { createSubAgentTool } from "../subagents/tool.js";
|
|
5
|
+
import { createSubAgentInlineTool, createSubAgentTool } from "../subagents/tool.js";
|
|
6
6
|
import { loadToolsConfig } from "./config.js";
|
|
7
7
|
import { buildToolSet } from "./registry.js";
|
|
8
|
-
import {
|
|
8
|
+
import { createSubAgentListTool, createSubAgentRunTool } from "./subagent-manage.js";
|
|
9
9
|
import { withToolDetails } from "./tool-details.js";
|
|
10
10
|
export function createPipiclawTools(options) {
|
|
11
11
|
// Spec 040, D8.1: the main agent's own write/edit tools can write a self-authorizing
|
|
@@ -16,6 +16,10 @@ export function createPipiclawTools(options) {
|
|
|
16
16
|
agentWorkspaceDir: options.workspaceDir,
|
|
17
17
|
projectRoot: options.projectScope.projectRoot,
|
|
18
18
|
boundary: options.projectScope.boundary,
|
|
19
|
+
// The main agent is channel-bound, so its own SESSION/MEMORY/HISTORY/tasks stay reachable
|
|
20
|
+
// even when `boundary: "project"` puts the rest of the workspace out of bounds — a task wake
|
|
21
|
+
// names `tasks/<id>.md` and expects the model to be able to open it (spec 043, D5).
|
|
22
|
+
channelDir: options.channelDir,
|
|
19
23
|
};
|
|
20
24
|
// The leaf tools (files, web, memory, skills) come from the single declarative
|
|
21
25
|
// registry so this set, the sub-agent set, and the prompt hints share one source.
|
|
@@ -23,6 +27,7 @@ export function createPipiclawTools(options) {
|
|
|
23
27
|
// and keeping it out of the registry avoids a registry ↔ subagents/tool import cycle.
|
|
24
28
|
const leafTools = buildToolSet({
|
|
25
29
|
executor: options.executor,
|
|
30
|
+
fileStore: options.fileStore,
|
|
26
31
|
securityConfig,
|
|
27
32
|
securityContext,
|
|
28
33
|
channelId: options.channelId,
|
|
@@ -39,47 +44,56 @@ export function createPipiclawTools(options) {
|
|
|
39
44
|
memoryCandidateStore: options.memoryCandidateStore,
|
|
40
45
|
mediaSender: options.mediaSender,
|
|
41
46
|
});
|
|
47
|
+
const subAgentToolOptions = {
|
|
48
|
+
executor: options.executor,
|
|
49
|
+
fileStore: options.fileStore,
|
|
50
|
+
getCurrentModel: options.getCurrentModel,
|
|
51
|
+
getAvailableModels: options.getAvailableModels,
|
|
52
|
+
resolveApiKey: options.resolveApiKey,
|
|
53
|
+
workspaceDir: options.workspaceDir,
|
|
54
|
+
// D6.2: an internal sub-agent defaults to the parent's ProjectRoot; a model-requested
|
|
55
|
+
// explicit workingDirectory is validated (in subagents/tool.ts) to stay within it.
|
|
56
|
+
workingDirectory: options.projectScope.projectRoot,
|
|
57
|
+
projectBoundary: options.projectScope.boundary,
|
|
58
|
+
channelDir: options.channelDir,
|
|
59
|
+
getSubAgentDiscovery: options.getSubAgentDiscovery,
|
|
60
|
+
getMemoryRecallSettings: options.getMemoryRecallSettings,
|
|
61
|
+
getSubAgentModelReference: options.getSubAgentModelReference,
|
|
62
|
+
memoryCandidateStore: options.memoryCandidateStore,
|
|
63
|
+
securityConfig,
|
|
64
|
+
webConfig: toolsConfig.tools.web,
|
|
65
|
+
rtkEnabled: toolsConfig.tools.rtk.enabled,
|
|
66
|
+
runtimeContext: {
|
|
67
|
+
workspaceDir: options.workspaceDir,
|
|
68
|
+
channelId: options.channelId,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
const subAgentManageOptions = {
|
|
72
|
+
channelId: options.channelId,
|
|
73
|
+
channelDir: options.channelDir,
|
|
74
|
+
getSubAgentDiscovery: options.getSubAgentDiscovery,
|
|
75
|
+
workspaceDir: options.workspaceDir,
|
|
76
|
+
workingDirectory: options.projectScope.projectRoot,
|
|
77
|
+
projectBoundary: options.projectScope.boundary,
|
|
78
|
+
securityConfig,
|
|
79
|
+
// Spec 042 D7: follow_up builds its envelope through the same buildContextualBlocks
|
|
80
|
+
// the initial dispatch uses, which needs these to resolve a memory: relevant recall.
|
|
81
|
+
getCurrentModel: options.getCurrentModel,
|
|
82
|
+
resolveApiKey: options.resolveApiKey,
|
|
83
|
+
getMemoryRecallSettings: options.getMemoryRecallSettings,
|
|
84
|
+
memoryCandidateStore: options.memoryCandidateStore,
|
|
85
|
+
};
|
|
42
86
|
return [
|
|
43
87
|
...leafTools,
|
|
44
88
|
// Bound to the same `details` contract as the registry's tools; it is registered here
|
|
45
89
|
// rather than in TOOL_REGISTRY only to avoid a registry ↔ subagents/tool import cycle.
|
|
46
|
-
withToolDetails(createSubAgentTool(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
workingDirectory: options.projectScope.projectRoot,
|
|
55
|
-
projectBoundary: options.projectScope.boundary,
|
|
56
|
-
channelDir: options.channelDir,
|
|
57
|
-
getSubAgentDiscovery: options.getSubAgentDiscovery,
|
|
58
|
-
getMemoryRecallSettings: options.getMemoryRecallSettings,
|
|
59
|
-
getSubAgentModelReference: options.getSubAgentModelReference,
|
|
60
|
-
memoryCandidateStore: options.memoryCandidateStore,
|
|
61
|
-
securityConfig,
|
|
62
|
-
webConfig: toolsConfig.tools.web,
|
|
63
|
-
rtkEnabled: toolsConfig.tools.rtk.enabled,
|
|
64
|
-
runtimeContext: {
|
|
65
|
-
workspaceDir: options.workspaceDir,
|
|
66
|
-
channelId: options.channelId,
|
|
67
|
-
},
|
|
68
|
-
}), "subagent"),
|
|
69
|
-
withToolDetails(createSubAgentManageTool({
|
|
70
|
-
channelId: options.channelId,
|
|
71
|
-
channelDir: options.channelDir,
|
|
72
|
-
getSubAgentDiscovery: options.getSubAgentDiscovery,
|
|
73
|
-
workspaceDir: options.workspaceDir,
|
|
74
|
-
workingDirectory: options.projectScope.projectRoot,
|
|
75
|
-
projectBoundary: options.projectScope.boundary,
|
|
76
|
-
securityConfig,
|
|
77
|
-
// Spec 042 D7: follow_up builds its envelope through the same buildContextualBlocks
|
|
78
|
-
// the initial dispatch uses, which needs these to resolve a memory: relevant recall.
|
|
79
|
-
getCurrentModel: options.getCurrentModel,
|
|
80
|
-
resolveApiKey: options.resolveApiKey,
|
|
81
|
-
getMemoryRecallSettings: options.getMemoryRecallSettings,
|
|
82
|
-
memoryCandidateStore: options.memoryCandidateStore,
|
|
83
|
-
}), "subagent_manage"),
|
|
90
|
+
withToolDetails(createSubAgentTool(subAgentToolOptions), "subagent"),
|
|
91
|
+
// Spec 046, D2.3: gated by `tools.json` (deployer decision, not a model-visible field) —
|
|
92
|
+
// omitted from the tool set entirely when off, not merely rejected at call time.
|
|
93
|
+
...(toolsConfig.tools.subagentInline.enabled
|
|
94
|
+
? [withToolDetails(createSubAgentInlineTool(subAgentToolOptions), "subagent_inline")]
|
|
95
|
+
: []),
|
|
96
|
+
withToolDetails(createSubAgentListTool(subAgentManageOptions), "subagent_list"),
|
|
97
|
+
withToolDetails(createSubAgentRunTool(subAgentManageOptions), "subagent_run"),
|
|
84
98
|
];
|
|
85
99
|
}
|
package/dist/tools/job.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import type { ChannelJobManager } from "../agent/job-manager.js";
|
|
4
4
|
declare const jobSchema: Type.TObject<{
|
|
5
|
-
label: Type.TString;
|
|
6
5
|
op: Type.TUnion<[Type.TLiteral<"list">, Type.TLiteral<"poll">, Type.TLiteral<"cancel">]>;
|
|
7
6
|
ids: Type.TOptional<Type.TArray<Type.TString>>;
|
|
8
7
|
}>;
|
package/dist/tools/job.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
+
import { formatDuration } from "../shared/duration.js";
|
|
3
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
2
4
|
import { truncateTail } from "./truncate.js";
|
|
3
5
|
const jobSchema = Type.Object({
|
|
4
|
-
label: Type.String({ description: "Brief description of what you're checking (shown to user)" }),
|
|
5
6
|
op: Type.Union([Type.Literal("list"), Type.Literal("poll"), Type.Literal("cancel")], {
|
|
6
7
|
description: '"list" a snapshot of background jobs, "poll" to wait (briefly) for one to finish, or "cancel" jobs by id.',
|
|
7
8
|
}),
|
|
@@ -9,13 +10,6 @@ const jobSchema = Type.Object({
|
|
|
9
10
|
description: "Job ids for poll/cancel. For poll, omit to watch all running jobs.",
|
|
10
11
|
})),
|
|
11
12
|
});
|
|
12
|
-
function formatDuration(ms) {
|
|
13
|
-
const seconds = Math.round(ms / 1000);
|
|
14
|
-
if (seconds < 60) {
|
|
15
|
-
return `${seconds}s`;
|
|
16
|
-
}
|
|
17
|
-
return `${Math.floor(seconds / 60)}m${seconds % 60}s`;
|
|
18
|
-
}
|
|
19
13
|
function formatJobLine(job) {
|
|
20
14
|
const exit = job.exitCode !== undefined ? `, exit ${job.exitCode}` : "";
|
|
21
15
|
return `- [${job.id}] ${job.label} — ${job.status} (${formatDuration(job.durationMs)}${exit})`;
|
|
@@ -43,7 +37,7 @@ export function createJobTool(options) {
|
|
|
43
37
|
execute: async (_toolCallId, { op, ids }, signal) => {
|
|
44
38
|
if (op === "cancel") {
|
|
45
39
|
if (!ids || ids.length === 0) {
|
|
46
|
-
throw new
|
|
40
|
+
throw new RecoverableToolError("cancel requires at least one job id.");
|
|
47
41
|
}
|
|
48
42
|
const outcomes = await jobManager.cancel(ids, signal);
|
|
49
43
|
const text = outcomes.map((outcome) => `- [${outcome.id}] ${outcome.status}`).join("\n");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FileStat, FileStore } from "../file-store.js";
|
|
2
|
+
/** Only for tests: line-index state must not leak between unrelated test files sharing a path. */
|
|
3
|
+
export declare function clearLineIndexCacheForTests(): void;
|
|
4
|
+
export interface LineOffsetResult {
|
|
5
|
+
/** Byte offset where `line` starts, or `undefined` if the index has not reached that line (yet, or ever). */
|
|
6
|
+
offset: number | undefined;
|
|
7
|
+
/** Whether the index has scanned to EOF -- `knownLines` is exact only when this is true. */
|
|
8
|
+
eof: boolean;
|
|
9
|
+
/** Lines discovered so far. Exact total when `eof`; otherwise a lower bound (D4.3: "of >= N"). */
|
|
10
|
+
knownLines: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the byte offset of `line` (1-indexed), scanning forward from wherever this file's index
|
|
14
|
+
* last left off. Never re-scans bytes already indexed.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveLineOffset(fileStore: FileStore, path: string, stat: FileStat, line: number, signal?: AbortSignal): Promise<LineOffsetResult>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const CACHE_CAPACITY = 32;
|
|
2
|
+
const SCAN_CHUNK_BYTES = 256 * 1024;
|
|
3
|
+
class LineIndexLru {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.map = new Map();
|
|
6
|
+
}
|
|
7
|
+
get(key) {
|
|
8
|
+
const value = this.map.get(key);
|
|
9
|
+
if (value) {
|
|
10
|
+
this.map.delete(key);
|
|
11
|
+
this.map.set(key, value);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
set(key, value) {
|
|
16
|
+
this.map.delete(key);
|
|
17
|
+
this.map.set(key, value);
|
|
18
|
+
if (this.map.size > CACHE_CAPACITY) {
|
|
19
|
+
const oldest = this.map.keys().next().value;
|
|
20
|
+
if (oldest !== undefined) {
|
|
21
|
+
this.map.delete(oldest);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
clear() {
|
|
26
|
+
this.map.clear();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const cache = new LineIndexLru();
|
|
30
|
+
function cacheKey(path, stat) {
|
|
31
|
+
return `${path}\0${stat.size}\0${stat.mtimeMs}`;
|
|
32
|
+
}
|
|
33
|
+
/** Only for tests: line-index state must not leak between unrelated test files sharing a path. */
|
|
34
|
+
export function clearLineIndexCacheForTests() {
|
|
35
|
+
cache.clear();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the byte offset of `line` (1-indexed), scanning forward from wherever this file's index
|
|
39
|
+
* last left off. Never re-scans bytes already indexed.
|
|
40
|
+
*/
|
|
41
|
+
export async function resolveLineOffset(fileStore, path, stat, line, signal) {
|
|
42
|
+
const key = cacheKey(path, stat);
|
|
43
|
+
let entry = cache.get(key);
|
|
44
|
+
if (!entry) {
|
|
45
|
+
entry = { lineOffsets: [0], scannedBytes: 0, eof: stat.size === 0 };
|
|
46
|
+
cache.set(key, entry);
|
|
47
|
+
}
|
|
48
|
+
while (entry.lineOffsets.length < line && !entry.eof) {
|
|
49
|
+
const { data, eof } = await fileStore.readBytes(path, {
|
|
50
|
+
start: entry.scannedBytes,
|
|
51
|
+
maxBytes: SCAN_CHUNK_BYTES,
|
|
52
|
+
signal,
|
|
53
|
+
});
|
|
54
|
+
for (let i = 0; i < data.length; i++) {
|
|
55
|
+
if (data[i] === 0x0a) {
|
|
56
|
+
entry.lineOffsets.push(entry.scannedBytes + i + 1);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
entry.scannedBytes += data.length;
|
|
60
|
+
if (eof) {
|
|
61
|
+
entry.eof = true;
|
|
62
|
+
}
|
|
63
|
+
if (data.length === 0) {
|
|
64
|
+
break; // Defensive: readBytes returned nothing without reporting eof.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const lastOffset = entry.lineOffsets[entry.lineOffsets.length - 1];
|
|
68
|
+
// A file ending exactly on a newline should not count a phantom empty final line -- mirrors
|
|
69
|
+
// the old `content.endsWith("\n") ? lines.length - 1 : lines.length` in truncate.ts's caller.
|
|
70
|
+
// Once `eof` is reached, that phantom entry (if any) is also not a valid *offset* to resolve --
|
|
71
|
+
// asking for line N+1 of an N-line file must report out of bounds, not silently hand back EOF.
|
|
72
|
+
const knownLines = entry.eof && lastOffset === stat.size ? entry.lineOffsets.length - 1 : entry.lineOffsets.length;
|
|
73
|
+
const resolvableLines = entry.eof ? knownLines : entry.lineOffsets.length;
|
|
74
|
+
const offset = line <= resolvableLines ? entry.lineOffsets[line - 1] : undefined;
|
|
75
|
+
return { offset, eof: entry.eof, knownLines };
|
|
76
|
+
}
|
|
@@ -3,13 +3,24 @@ import type { Api, Model } from "@earendil-works/pi-ai";
|
|
|
3
3
|
import { Type } from "typebox";
|
|
4
4
|
import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
5
5
|
import { type ChannelMemoryQueue } from "../memory/channel-maintenance-queue.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Spec 047, P4: the old single `memory_manage` routed three fully disjoint payloads through an
|
|
8
|
+
* `op` enum. Splitting into one tool per payload shape drops the `op` routing prose and the
|
|
9
|
+
* "Required for save:" prefixes, and lets each op's one required field be schema-required
|
|
10
|
+
* instead of `Type.Optional` + a hand-rolled `rejectMissingArgument`. The streamed-argument
|
|
11
|
+
* truncation that `rejectMissingArgument` guarded against (M-write-03) is now caught by the SDK
|
|
12
|
+
* validator before `execute`; spec 047 D4.2 makes that rejection surface as a recoverable
|
|
13
|
+
* rejection rather than a user-visible error.
|
|
14
|
+
*/
|
|
15
|
+
declare const memorySaveSchema: Type.TObject<{
|
|
16
|
+
content: Type.TString;
|
|
17
|
+
supersedes: Type.TOptional<Type.TString>;
|
|
18
|
+
}>;
|
|
19
|
+
declare const memorySearchSchema: Type.TObject<{
|
|
20
|
+
query: Type.TString;
|
|
21
|
+
}>;
|
|
22
|
+
declare const memoryForgetSchema: Type.TObject<{
|
|
23
|
+
target: Type.TString;
|
|
13
24
|
}>;
|
|
14
25
|
export interface MemoryManageToolOptions {
|
|
15
26
|
channelId: string;
|
|
@@ -20,5 +31,7 @@ export interface MemoryManageToolOptions {
|
|
|
20
31
|
resolveApiKey: (model: Model<Api>) => Promise<string>;
|
|
21
32
|
channelMemoryQueue?: ChannelMemoryQueue;
|
|
22
33
|
}
|
|
23
|
-
export declare function
|
|
34
|
+
export declare function createMemorySaveTool(options: MemoryManageToolOptions): AgentTool<typeof memorySaveSchema>;
|
|
35
|
+
export declare function createMemorySearchTool(options: MemoryManageToolOptions): AgentTool<typeof memorySearchSchema>;
|
|
36
|
+
export declare function createMemoryForgetTool(options: MemoryManageToolOptions): AgentTool<typeof memoryForgetSchema>;
|
|
24
37
|
export {};
|