@oyasmi/pipiclaw 0.9.1 → 0.9.2-beta.2
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 +15 -1
- package/dist/agent/channel-runner.js +76 -24
- 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 +1 -1
- package/dist/agent/prompt/sections.js +8 -5
- package/dist/agent/session-events.d.ts +2 -0
- package/dist/agent/session-events.js +29 -14
- 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 +14 -0
- package/dist/executor.js +96 -24
- package/dist/file-store.d.ts +96 -0
- package/dist/file-store.js +189 -0
- package/dist/memory/consolidation.js +2 -26
- package/dist/memory/files.js +7 -7
- package/dist/memory/maintenance-jobs.js +2 -34
- package/dist/memory/maintenance-state.js +2 -1
- package/dist/memory/recall.d.ts +10 -0
- package/dist/memory/recall.js +15 -7
- package/dist/memory/session-search.js +6 -22
- package/dist/memory/transcript.d.ts +10 -0
- package/dist/memory/transcript.js +39 -0
- package/dist/playbooks/agent-delegation.md +7 -5
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.d.ts +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/event-scheduling.md +2 -0
- package/dist/playbooks/memory-and-learning.md +11 -11
- package/dist/playbooks/runtime-orientation.md +3 -3
- package/dist/playbooks/task-driving.md +7 -7
- package/dist/playbooks/task-planning.md +5 -5
- package/dist/runtime/app-home.js +1 -1
- package/dist/runtime/bootstrap.js +10 -0
- package/dist/runtime/dingtalk.js +3 -2
- package/dist/runtime/durable-dispatch.d.ts +26 -1
- package/dist/runtime/durable-dispatch.js +51 -5
- package/dist/runtime/event-commands.js +7 -16
- package/dist/runtime/events.d.ts +4 -2
- package/dist/runtime/events.js +15 -20
- package/dist/runtime/subagent-commands.js +1 -1
- package/dist/runtime/task-commands.d.ts +1 -1
- package/dist/runtime/task-commands.js +17 -12
- package/dist/runtime/task-driver.js +2 -2
- package/dist/runtime/task-wake.d.ts +2 -2
- package/dist/runtime/task-wake.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 +32 -14
- 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 +44 -17
- package/dist/subagents/discovery.js +82 -111
- package/dist/subagents/external/claude-code.js +1 -3
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/run.d.ts +6 -0
- package/dist/subagents/external/run.js +122 -58
- package/dist/subagents/external/settlement.d.ts +3 -0
- package/dist/subagents/external/settlement.js +19 -5
- package/dist/subagents/format.d.ts +3 -2
- package/dist/subagents/format.js +3 -7
- package/dist/subagents/runs.d.ts +45 -9
- package/dist/subagents/runs.js +184 -64
- package/dist/subagents/tool.d.ts +35 -24
- package/dist/subagents/tool.js +631 -577
- package/dist/subagents/verification-outcome.js +1 -1
- package/dist/subagents/workspace-lease.js +1 -1
- package/dist/tasks/artifact-subject.d.ts +30 -4
- package/dist/tasks/artifact-subject.js +257 -25
- 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 +24 -2
- package/dist/tasks/verification.js +113 -21
- package/dist/tools/bash.d.ts +0 -1
- package/dist/tools/bash.js +45 -40
- 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 +274 -86
- 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 +57 -42
- 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 +50 -40
- package/dist/tools/job.d.ts +0 -1
- package/dist/tools/job.js +1 -8
- package/dist/tools/line-index.d.ts +16 -0
- package/dist/tools/line-index.js +76 -0
- package/dist/tools/memory-manage.d.ts +20 -8
- package/dist/tools/memory-manage.js +65 -92
- 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 +97 -133
- 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 +16 -49
- 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 +0 -24
- 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 +60 -60
- 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 +56 -60
- 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 +5 -5
- package/dist/tools/task-manage/verification.js +18 -15
- 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 +5 -5
- package/dist/tools/truncate.js +5 -5
- package/dist/tools/web-fetch.d.ts +0 -1
- package/dist/tools/web-fetch.js +0 -1
- 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 -51
- package/dist/tools/write.d.ts +2 -3
- package/dist/tools/write.js +3 -4
- package/dist/tui/pitui-frontend.js +3 -3
- package/dist/usage/ledger.js +7 -4
- package/examples/sub-agents/README.md +13 -13
- package/examples/sub-agents/documenter.md +2 -1
- package/examples/sub-agents/reviewer.md +2 -0
- package/examples/sub-agents/scout.md +2 -1
- package/examples/sub-agents/verifier.md +6 -4
- package/examples/sub-agents/worker.md +2 -1
- package/package.json +5 -5
- package/dist/tools/skill-manage.d.ts +0 -41
- package/dist/tools/skill-manage.js +0 -232
|
@@ -9,31 +9,32 @@ import { hashMemoryContent } from "../memory/tombstones.js";
|
|
|
9
9
|
import { readOptionalTextFile } from "../shared/fs-utils.js";
|
|
10
10
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
11
11
|
import { errorMessage } from "../shared/text-utils.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Spec 047, P4: the old single `memory_manage` routed three fully disjoint payloads through an
|
|
14
|
+
* `op` enum. Splitting into one tool per payload shape drops the `op` routing prose and the
|
|
15
|
+
* "Required for save:" prefixes, and lets each op's one required field be schema-required
|
|
16
|
+
* instead of `Type.Optional` + a hand-rolled `rejectMissingArgument`. The streamed-argument
|
|
17
|
+
* truncation that `rejectMissingArgument` guarded against (M-write-03) is now caught by the SDK
|
|
18
|
+
* validator before `execute`; spec 047 D4.2 makes that rejection surface as a recoverable
|
|
19
|
+
* rejection rather than a user-visible error.
|
|
20
|
+
*/
|
|
21
|
+
const memorySaveSchema = Type.Object({
|
|
22
|
+
content: Type.String({
|
|
23
|
+
description: "The durable fact as a single self-contained, keyword-rich sentence on one line, written so future keyword search can find it.",
|
|
16
24
|
}),
|
|
17
|
-
content: Type.Optional(Type.String({
|
|
18
|
-
description: "Required for save: the durable fact as a single self-contained, keyword-rich sentence on one line, written so future keyword search can find it. A save without it is rejected and stores nothing.",
|
|
19
|
-
})),
|
|
20
|
-
query: Type.Optional(Type.String({ description: "For search: what to look for in stored memory." })),
|
|
21
|
-
target: Type.Optional(Type.String({
|
|
22
|
-
description: "For forget: text identifying the stored entry to remove. Must match exactly one entry; use search first to confirm the wording.",
|
|
23
|
-
})),
|
|
24
|
-
kind: Type.Optional(Type.Union([
|
|
25
|
-
Type.Literal("preference"),
|
|
26
|
-
Type.Literal("fact"),
|
|
27
|
-
Type.Literal("decision"),
|
|
28
|
-
Type.Literal("constraint"),
|
|
29
|
-
Type.Literal("open-loop"),
|
|
30
|
-
Type.Literal("lesson"),
|
|
31
|
-
], { description: "For save: what kind of durable memory this is." })),
|
|
32
25
|
supersedes: Type.Optional(Type.String({
|
|
33
|
-
description: "
|
|
26
|
+
description: "Only after this tool reported a similar existing entry: the entry id being replaced, " +
|
|
34
27
|
'or "none" to keep both.',
|
|
35
28
|
})),
|
|
36
29
|
});
|
|
30
|
+
const memorySearchSchema = Type.Object({
|
|
31
|
+
query: Type.String({ description: "What to look for in this channel's stored memory." }),
|
|
32
|
+
});
|
|
33
|
+
const memoryForgetSchema = Type.Object({
|
|
34
|
+
target: Type.String({
|
|
35
|
+
description: "Text identifying the stored entry to remove. Must match exactly one entry; use memory_search first to confirm the wording.",
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
37
38
|
/**
|
|
38
39
|
* Above this recall score, an existing entry is similar enough that saving alongside it — rather
|
|
39
40
|
* than superseding it — risks two contradictory durable facts competing at recall time. Set high
|
|
@@ -43,57 +44,15 @@ const memoryManageSchema = Type.Object({
|
|
|
43
44
|
* strong elsewhere in the pipeline is a reasonable place to start being strict here too.
|
|
44
45
|
*/
|
|
45
46
|
const SAVE_CONFLICT_SCORE = 8;
|
|
46
|
-
function normalizeMemoryKind(kind) {
|
|
47
|
-
return kind === "preference" ||
|
|
48
|
-
kind === "decision" ||
|
|
49
|
-
kind === "constraint" ||
|
|
50
|
-
kind === "open-loop" ||
|
|
51
|
-
kind === "lesson"
|
|
52
|
-
? kind
|
|
53
|
-
: "fact";
|
|
54
|
-
}
|
|
55
47
|
function textResult(text, details) {
|
|
56
48
|
return { content: [{ type: "text", text }], details };
|
|
57
49
|
}
|
|
58
|
-
|
|
59
|
-
* Reject a call whose op-specific payload never arrived.
|
|
60
|
-
*
|
|
61
|
-
* These arguments are `Type.Optional` because each one belongs to exactly one op, so the
|
|
62
|
-
* schema cannot express "required for save, absent for search" — which means the SDK
|
|
63
|
-
* validator lets a payload-less call straight through. Two failure modes reach here and both
|
|
64
|
-
* used to end in a calm `textResult` that read like a completed no-op:
|
|
65
|
-
*
|
|
66
|
-
* 1. The model genuinely omitted the argument.
|
|
67
|
-
* 2. The argument was *lost in transit*. Streamed tool-call arguments are accumulated as
|
|
68
|
-
* text and parsed leniently (`parseStreamingJson`): if the provider truncates or
|
|
69
|
-
* malforms the tail of the JSON — the common shape with OpenAI-compatible Chinese
|
|
70
|
-
* providers on long non-ASCII values — the trailing key is silently dropped and the
|
|
71
|
-
* call still executes. The assistant message is then persisted with the *parsed*
|
|
72
|
-
* arguments, so on the next turn the model reads back its own call with `content`
|
|
73
|
-
* already missing, copies it, and loops forever.
|
|
74
|
-
*
|
|
75
|
-
* A soft result makes (2) unrecoverable, so reject loudly instead: a `RecoverableToolError`
|
|
76
|
-
* surfaces to the model as an error it must fix rather than a saved memory, names the keys
|
|
77
|
-
* that actually arrived so a dropped argument is visible rather than inferred, and tells the
|
|
78
|
-
* model not to replay the previous call. The warning log is the operator-side evidence —
|
|
79
|
-
* `agent.tool.started` carries the raw args but only at debug level.
|
|
80
|
-
*/
|
|
81
|
-
function rejectMissingArgument(op, parameter, args) {
|
|
82
|
-
const received = Object.entries(args)
|
|
83
|
-
.filter(([, value]) => value !== undefined && value !== "")
|
|
84
|
-
.map(([key]) => key);
|
|
85
|
-
log.logWarning(`memory_manage ${op} called without "${parameter}"`, `received arguments: ${received.join(", ") || "(none)"}`);
|
|
86
|
-
throw new RecoverableToolError(`memory_manage op="${op}" requires a non-empty "${parameter}", but the call arrived with only: ${received.join(", ") || "(no arguments)"}. Nothing was ${op === "forget" ? "removed" : op === "save" ? "saved" : "searched"}. Do not repeat the previous ` +
|
|
87
|
-
`call as written — if an earlier call in this conversation is also missing "${parameter}", it was dropped in ` +
|
|
88
|
-
`transit, so re-issue it with "${parameter}" set explicitly and keep the value short and on one line.`);
|
|
89
|
-
}
|
|
90
|
-
export function createMemoryManageTool(options) {
|
|
50
|
+
function buildMemoryClosures(options) {
|
|
91
51
|
const queue = options.channelMemoryQueue ?? getDefaultChannelMemoryQueue();
|
|
92
|
-
async function save(
|
|
93
|
-
const
|
|
94
|
-
const trimmed = (content ?? "").trim();
|
|
52
|
+
async function save({ content, supersedes }) {
|
|
53
|
+
const trimmed = content.trim();
|
|
95
54
|
if (!trimmed) {
|
|
96
|
-
|
|
55
|
+
throw new RecoverableToolError("memory_save requires a non-empty content; nothing was saved.");
|
|
97
56
|
}
|
|
98
57
|
if (containsSecret(trimmed)) {
|
|
99
58
|
return textResult("This content looks like a credential or secret, so it was not saved. Store the secret in an approved secret manager and remember only its location.", { op: "save", saved: false, blockedReason: "secret" });
|
|
@@ -124,8 +83,10 @@ export function createMemoryManageTool(options) {
|
|
|
124
83
|
'\nRe-issue the save with "supersedes" set to the entry id this replaces, or to "none" if both facts are true at the same time.');
|
|
125
84
|
}
|
|
126
85
|
}
|
|
86
|
+
// The model no longer classifies explicit saves (spec 047, P2): background consolidation
|
|
87
|
+
// (`extraction.ts`) still writes real kinds; a model save is recorded as `fact`.
|
|
127
88
|
const metadata = {
|
|
128
|
-
kind:
|
|
89
|
+
kind: "fact",
|
|
129
90
|
sourceType: "user",
|
|
130
91
|
probationUntil: null,
|
|
131
92
|
};
|
|
@@ -140,17 +101,17 @@ export function createMemoryManageTool(options) {
|
|
|
140
101
|
]));
|
|
141
102
|
options.memoryCandidateStore.invalidate(getChannelMemoryPath(options.channelDir));
|
|
142
103
|
const message = result.added > 0 || result.superseded > 0
|
|
143
|
-
?
|
|
104
|
+
? "Saved to channel memory."
|
|
144
105
|
: "That memory is already present; no duplicate was added.";
|
|
145
106
|
return textResult(message, {
|
|
146
107
|
op: "save",
|
|
147
108
|
saved: result.added > 0 || result.superseded > 0 || result.skippedDuplicate > 0,
|
|
148
109
|
});
|
|
149
110
|
}
|
|
150
|
-
async function search(
|
|
151
|
-
const trimmed =
|
|
111
|
+
async function search({ query }) {
|
|
112
|
+
const trimmed = query.trim();
|
|
152
113
|
if (!trimmed) {
|
|
153
|
-
|
|
114
|
+
throw new RecoverableToolError("memory_search requires a non-empty query.");
|
|
154
115
|
}
|
|
155
116
|
// Reuse the recall scoring pipeline (single source of scoring truth) but scoped to the
|
|
156
117
|
// distilled durable files and with model rerank off, so this stays a cheap deterministic
|
|
@@ -181,10 +142,10 @@ export function createMemoryManageTool(options) {
|
|
|
181
142
|
resultCount: items.length,
|
|
182
143
|
});
|
|
183
144
|
}
|
|
184
|
-
async function forget(
|
|
185
|
-
const trimmed =
|
|
145
|
+
async function forget({ target }) {
|
|
146
|
+
const trimmed = target.trim();
|
|
186
147
|
if (!trimmed) {
|
|
187
|
-
|
|
148
|
+
throw new RecoverableToolError("memory_forget requires a non-empty target.");
|
|
188
149
|
}
|
|
189
150
|
const memoryPath = getChannelMemoryPath(options.channelDir);
|
|
190
151
|
const existing = await readOptionalTextFile(memoryPath);
|
|
@@ -217,24 +178,36 @@ export function createMemoryManageTool(options) {
|
|
|
217
178
|
});
|
|
218
179
|
return textResult("Removed the entry from active channel memory. Its exact content and source transcript window are tombstoned against automatic replay; if the fact is stated again later, it may be learned as new. Original session history and retention backups are unchanged.", { op: "forget", forgotten: true, entryId: removed.id });
|
|
219
180
|
}
|
|
181
|
+
return { save, search, forget };
|
|
182
|
+
}
|
|
183
|
+
export function createMemorySaveTool(options) {
|
|
184
|
+
const { save } = buildMemoryClosures(options);
|
|
220
185
|
return {
|
|
221
|
-
name: "
|
|
222
|
-
label: "
|
|
223
|
-
description: "
|
|
224
|
-
"
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
186
|
+
name: "memory_save",
|
|
187
|
+
label: "memory_save",
|
|
188
|
+
description: "Save a durable fact into this channel's MEMORY.md when the user asks you to remember it. Prefer this over editing " +
|
|
189
|
+
"MEMORY.md directly. Not for transient task state.",
|
|
190
|
+
parameters: memorySaveSchema,
|
|
191
|
+
execute: async (_toolCallId, args) => save(args),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
export function createMemorySearchTool(options) {
|
|
195
|
+
const { search } = buildMemoryClosures(options);
|
|
196
|
+
return {
|
|
197
|
+
name: "memory_search",
|
|
198
|
+
label: "memory_search",
|
|
199
|
+
description: "Search this channel's stored durable memory on demand mid-task.",
|
|
200
|
+
parameters: memorySearchSchema,
|
|
201
|
+
execute: async (_toolCallId, args) => search(args),
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
export function createMemoryForgetTool(options) {
|
|
205
|
+
const { forget } = buildMemoryClosures(options);
|
|
206
|
+
return {
|
|
207
|
+
name: "memory_forget",
|
|
208
|
+
label: "memory_forget",
|
|
209
|
+
description: "Forget a stored memory entry the user explicitly asked you to drop. Tombstones it against automatic replay.",
|
|
210
|
+
parameters: memoryForgetSchema,
|
|
211
|
+
execute: async (_toolCallId, args) => forget(args),
|
|
239
212
|
};
|
|
240
213
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { clipText } from "../shared/text-utils.js";
|
|
2
|
+
import { isRecord } from "../shared/type-guards.js";
|
|
3
|
+
/**
|
|
4
|
+
* Runtime-side projection from a tool call's raw arguments to the one-line Chinese progress
|
|
5
|
+
* string shown while it runs (`src/agent/session-events.ts`). Replaces the old model-authored,
|
|
6
|
+
* per-tool-required `label` argument (spec 045): the model no longer pays schema tokens or output
|
|
7
|
+
* tokens for a UI string on every single call, and the wording is deterministic instead of
|
|
8
|
+
* whatever the model happened to write.
|
|
9
|
+
*
|
|
10
|
+
* One function per tool name, keyed in a table rather than spread across each tool's own file:
|
|
11
|
+
* `session-events.ts` has only `toolName` + raw `args`, never the tool instance, so there is no
|
|
12
|
+
* natural per-file seam to hang this on without importing all sixteen modules into the session
|
|
13
|
+
* event handler. `test/tool-presentation.test.ts` is what actually prevents drift — it asserts
|
|
14
|
+
* every registered tool name has a describer and that each survives empty/missing args, since the
|
|
15
|
+
* model's args are not guaranteed well-formed at the moment a call starts.
|
|
16
|
+
*/
|
|
17
|
+
function str(args, key) {
|
|
18
|
+
if (!isRecord(args))
|
|
19
|
+
return undefined;
|
|
20
|
+
const value = args[key];
|
|
21
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
22
|
+
}
|
|
23
|
+
function bool(args, key) {
|
|
24
|
+
return isRecord(args) && args[key] === true;
|
|
25
|
+
}
|
|
26
|
+
function firstLine(text, maxChars) {
|
|
27
|
+
const line = text.split("\n")[0] ?? text;
|
|
28
|
+
return clipText(line, maxChars, { collapseWhitespace: true });
|
|
29
|
+
}
|
|
30
|
+
/** Host + path only, so a long query string never dominates the progress line. */
|
|
31
|
+
function hostAndPath(rawUrl) {
|
|
32
|
+
try {
|
|
33
|
+
const url = new URL(rawUrl);
|
|
34
|
+
return `${url.host}${url.pathname}`;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return clipText(rawUrl, 60, { collapseWhitespace: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const DESCRIBERS = {
|
|
41
|
+
read: (args) => {
|
|
42
|
+
const path = str(args, "path") ?? "?";
|
|
43
|
+
const offset = isRecord(args) && typeof args.offset === "number" ? args.offset : undefined;
|
|
44
|
+
return `读取 ${path}${offset !== undefined ? `:${offset}` : ""}`;
|
|
45
|
+
},
|
|
46
|
+
glob: (args) => {
|
|
47
|
+
const pattern = str(args, "pattern") ?? "?";
|
|
48
|
+
const path = str(args, "path");
|
|
49
|
+
return `查找 ${pattern}${path ? ` · ${path}` : ""}`;
|
|
50
|
+
},
|
|
51
|
+
grep: (args) => {
|
|
52
|
+
const pattern = str(args, "pattern") ?? "?";
|
|
53
|
+
const path = str(args, "path");
|
|
54
|
+
return `搜索 "${clipText(pattern, 40, { collapseWhitespace: true })}"${path ? ` · ${path}` : ""}`;
|
|
55
|
+
},
|
|
56
|
+
edit: (args) => `编辑 ${str(args, "path") ?? "?"}`,
|
|
57
|
+
write: (args) => `写入 ${str(args, "path") ?? "?"}`,
|
|
58
|
+
bash: (args) => {
|
|
59
|
+
const command = clipText(str(args, "command") ?? "?", 60, { collapseWhitespace: true });
|
|
60
|
+
return bool(args, "async") ? `后台执行 ${command}` : `执行 ${command}`;
|
|
61
|
+
},
|
|
62
|
+
web_search: (args) => `搜索 "${clipText(str(args, "query") ?? "?", 60, { collapseWhitespace: true })}"`,
|
|
63
|
+
web_fetch: (args) => `抓取 ${hostAndPath(str(args, "url") ?? "")}`,
|
|
64
|
+
send_media: (args) => `发送 ${str(args, "path") ?? "?"}`,
|
|
65
|
+
job: (args) => {
|
|
66
|
+
const op = str(args, "op") ?? "?";
|
|
67
|
+
const ids = isRecord(args) && Array.isArray(args.ids) ? args.ids.length : 0;
|
|
68
|
+
return `后台作业 ${op}${ids ? ` (${ids})` : ""}`;
|
|
69
|
+
},
|
|
70
|
+
session_search: (args) => `检索历史 "${clipText(str(args, "query") ?? "?", 40, { collapseWhitespace: true })}"`,
|
|
71
|
+
memory_save: (args) => `记忆保存${str(args, "content") ? `:${firstLine(str(args, "content") ?? "", 30)}` : ""}`,
|
|
72
|
+
memory_search: (args) => `记忆检索 "${clipText(str(args, "query") ?? "?", 40, { collapseWhitespace: true })}"`,
|
|
73
|
+
memory_forget: (args) => `记忆删除 "${clipText(str(args, "target") ?? "?", 40, { collapseWhitespace: true })}"`,
|
|
74
|
+
skill: (args) => {
|
|
75
|
+
const action = str(args, "action") ?? "?";
|
|
76
|
+
const name = str(args, "name");
|
|
77
|
+
return action === "read" ? `加载 skill ${name ?? "?"}` : "列出 skills";
|
|
78
|
+
},
|
|
79
|
+
event_manage: (args) => `事件 ${str(args, "action") ?? "?"} ${str(args, "name") ?? ""}`.trim(),
|
|
80
|
+
task_list: () => "列出任务",
|
|
81
|
+
task_create: (args) => `创建任务 ${str(args, "id") ?? "?"}`,
|
|
82
|
+
task_update: (args) => `更新任务 ${str(args, "id") ?? "?"}`,
|
|
83
|
+
task_close: (args) => `关闭任务 ${str(args, "id") ?? "?"}(${str(args, "outcome") ?? "?"})`,
|
|
84
|
+
task_verify: (args) => `导入验收 ${str(args, "id") ?? "?"}`,
|
|
85
|
+
subagent: (args) => {
|
|
86
|
+
const who = str(args, "agent") ?? "?";
|
|
87
|
+
const task = str(args, "task");
|
|
88
|
+
return `委派 ${who}${task ? `:${firstLine(task, 40)}` : ""}`;
|
|
89
|
+
},
|
|
90
|
+
subagent_inline: (args) => {
|
|
91
|
+
const task = str(args, "task");
|
|
92
|
+
return `内联委派${task ? `:${firstLine(task, 40)}` : ""}`;
|
|
93
|
+
},
|
|
94
|
+
subagent_list: () => "委派列表",
|
|
95
|
+
subagent_run: (args) => {
|
|
96
|
+
const op = str(args, "op") ?? "?";
|
|
97
|
+
const runId = str(args, "runId");
|
|
98
|
+
return `委派 ${op}${runId ? ` ${runId}` : ""}`;
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
/** Fallback for any tool name without a specific describer (e.g. an unrecognized/future tool). */
|
|
102
|
+
export function describeToolCall(toolName, args) {
|
|
103
|
+
try {
|
|
104
|
+
return DESCRIBERS[toolName]?.(args) || toolName;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return toolName;
|
|
108
|
+
}
|
|
109
|
+
}
|
package/dist/tools/read.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import type { Executor } from "../executor.js";
|
|
4
|
+
import type { FileStore } from "../file-store.js";
|
|
4
5
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
5
6
|
declare const readSchema: Type.TObject<{
|
|
6
|
-
label: Type.TString;
|
|
7
7
|
path: Type.TString;
|
|
8
8
|
offset: Type.TOptional<Type.TInteger>;
|
|
9
9
|
limit: Type.TOptional<Type.TInteger>;
|
|
@@ -13,5 +13,5 @@ export interface ReadToolOptions {
|
|
|
13
13
|
securityContext?: SecurityRuntimeContext;
|
|
14
14
|
channelId?: string;
|
|
15
15
|
}
|
|
16
|
-
export declare function createReadTool(executor: Executor, options?: ReadToolOptions): AgentTool<typeof readSchema>;
|
|
16
|
+
export declare function createReadTool(executor: Executor, fileStore: FileStore, options?: ReadToolOptions): AgentTool<typeof readSchema>;
|
|
17
17
|
export {};
|