@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
|
@@ -9,110 +9,109 @@ 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
|
-
|
|
18
|
-
description: "
|
|
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.",
|
|
25
|
+
supersedes: Type.Optional(Type.String({
|
|
26
|
+
description: "Only after this tool reported a similar existing entry: the entry id being replaced, " +
|
|
27
|
+
'or "none" to keep both.',
|
|
23
28
|
})),
|
|
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
29
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
function textResult(text, details) {
|
|
43
|
-
return { content: [{ type: "text", text }], details };
|
|
44
|
-
}
|
|
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
|
+
});
|
|
45
38
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* 1. The model genuinely omitted the argument.
|
|
54
|
-
* 2. The argument was *lost in transit*. Streamed tool-call arguments are accumulated as
|
|
55
|
-
* text and parsed leniently (`parseStreamingJson`): if the provider truncates or
|
|
56
|
-
* malforms the tail of the JSON — the common shape with OpenAI-compatible Chinese
|
|
57
|
-
* providers on long non-ASCII values — the trailing key is silently dropped and the
|
|
58
|
-
* call still executes. The assistant message is then persisted with the *parsed*
|
|
59
|
-
* arguments, so on the next turn the model reads back its own call with `content`
|
|
60
|
-
* already missing, copies it, and loops forever.
|
|
61
|
-
*
|
|
62
|
-
* A soft result makes (2) unrecoverable, so reject loudly instead: a `RecoverableToolError`
|
|
63
|
-
* surfaces to the model as an error it must fix rather than a saved memory, names the keys
|
|
64
|
-
* that actually arrived so a dropped argument is visible rather than inferred, and tells the
|
|
65
|
-
* model not to replay the previous call. The warning log is the operator-side evidence —
|
|
66
|
-
* `agent.tool.started` carries the raw args but only at debug level.
|
|
39
|
+
* Above this recall score, an existing entry is similar enough that saving alongside it — rather
|
|
40
|
+
* than superseding it — risks two contradictory durable facts competing at recall time. Set high
|
|
41
|
+
* on purpose: a false positive interrupts every plain save, a false negative just means the old
|
|
42
|
+
* conflict-resolution instruction ("say 'forget the old one'") still applies. Starts at the same
|
|
43
|
+
* value `recall.ts` uses to gate its own model rerank (`HIGH_CONFIDENCE_SCORE`) — a score that
|
|
44
|
+
* strong elsewhere in the pipeline is a reasonable place to start being strict here too.
|
|
67
45
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.map(([key]) => key);
|
|
72
|
-
log.logWarning(`memory_manage ${op} called without "${parameter}"`, `received arguments: ${received.join(", ") || "(none)"}`);
|
|
73
|
-
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 ` +
|
|
74
|
-
`call as written — if an earlier call in this conversation is also missing "${parameter}", it was dropped in ` +
|
|
75
|
-
`transit, so re-issue it with "${parameter}" set explicitly and keep the value short and on one line.`);
|
|
46
|
+
const SAVE_CONFLICT_SCORE = 8;
|
|
47
|
+
function textResult(text, details) {
|
|
48
|
+
return { content: [{ type: "text", text }], details };
|
|
76
49
|
}
|
|
77
|
-
|
|
50
|
+
function buildMemoryClosures(options) {
|
|
78
51
|
const queue = options.channelMemoryQueue ?? getDefaultChannelMemoryQueue();
|
|
79
|
-
async function save(
|
|
80
|
-
const
|
|
81
|
-
const trimmed = (content ?? "").trim();
|
|
52
|
+
async function save({ content, supersedes }) {
|
|
53
|
+
const trimmed = content.trim();
|
|
82
54
|
if (!trimmed) {
|
|
83
|
-
|
|
55
|
+
throw new RecoverableToolError("memory_save requires a non-empty content; nothing was saved.");
|
|
84
56
|
}
|
|
85
57
|
if (containsSecret(trimmed)) {
|
|
86
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" });
|
|
87
59
|
}
|
|
60
|
+
if (!supersedes) {
|
|
61
|
+
// Reuse the recall scoring pipeline (already the point-query path for `search`) as a
|
|
62
|
+
// deterministic, no-cost conflict check before writing a second fact that might
|
|
63
|
+
// contradict one already stored.
|
|
64
|
+
const model = options.getCurrentModel();
|
|
65
|
+
const { items } = await recallRelevantMemory({
|
|
66
|
+
query: trimmed,
|
|
67
|
+
channelId: options.channelId,
|
|
68
|
+
workspaceDir: options.workspaceDir,
|
|
69
|
+
channelDir: options.channelDir,
|
|
70
|
+
allowedSources: ["channel-memory"],
|
|
71
|
+
maxCandidates: 3,
|
|
72
|
+
maxInjected: 3,
|
|
73
|
+
maxChars: 1200,
|
|
74
|
+
rerankWithModel: false,
|
|
75
|
+
model,
|
|
76
|
+
resolveApiKey: options.resolveApiKey,
|
|
77
|
+
candidateStore: options.memoryCandidateStore,
|
|
78
|
+
});
|
|
79
|
+
const similar = items.filter((item) => item.entryId && item.score >= SAVE_CONFLICT_SCORE);
|
|
80
|
+
if (similar.length > 0) {
|
|
81
|
+
throw new RecoverableToolError(`Nothing was saved yet. This channel already stores ${similar.length} similar entr${similar.length === 1 ? "y" : "ies"}:\n` +
|
|
82
|
+
similar.map((item) => `- ${item.entryId}: ${item.content}`).join("\n") +
|
|
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.');
|
|
84
|
+
}
|
|
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`.
|
|
88
|
+
const metadata = {
|
|
89
|
+
kind: "fact",
|
|
90
|
+
sourceType: "user",
|
|
91
|
+
probationUntil: null,
|
|
92
|
+
};
|
|
88
93
|
// Serialize through the shared channel memory queue so this never races with background
|
|
89
94
|
// consolidation/maintenance on the same channel's files.
|
|
90
95
|
const result = await queue.run(options.channelId, () => applyChannelMemoryOps(options.channelDir, [
|
|
91
|
-
|
|
92
|
-
op: "
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
metadata: {
|
|
97
|
-
kind: normalizeMemoryKind(kind),
|
|
98
|
-
sourceType: "user",
|
|
99
|
-
probationUntil: null,
|
|
100
|
-
},
|
|
101
|
-
},
|
|
96
|
+
supersedes && supersedes !== "none"
|
|
97
|
+
? { op: "supersede", targetId: supersedes, content: trimmed, metadata }
|
|
98
|
+
: // A user explicitly saying "remember this" is never probationary, and restating a
|
|
99
|
+
// fact the runtime had already put on probation promotes it (spec 037, D7).
|
|
100
|
+
{ op: "add", content: trimmed, metadata },
|
|
102
101
|
]));
|
|
103
102
|
options.memoryCandidateStore.invalidate(getChannelMemoryPath(options.channelDir));
|
|
104
|
-
const message = result.added > 0
|
|
105
|
-
?
|
|
103
|
+
const message = result.added > 0 || result.superseded > 0
|
|
104
|
+
? "Saved to channel memory."
|
|
106
105
|
: "That memory is already present; no duplicate was added.";
|
|
107
106
|
return textResult(message, {
|
|
108
107
|
op: "save",
|
|
109
|
-
saved: result.added > 0 || result.skippedDuplicate > 0,
|
|
108
|
+
saved: result.added > 0 || result.superseded > 0 || result.skippedDuplicate > 0,
|
|
110
109
|
});
|
|
111
110
|
}
|
|
112
|
-
async function search(
|
|
113
|
-
const trimmed =
|
|
111
|
+
async function search({ query }) {
|
|
112
|
+
const trimmed = query.trim();
|
|
114
113
|
if (!trimmed) {
|
|
115
|
-
|
|
114
|
+
throw new RecoverableToolError("memory_search requires a non-empty query.");
|
|
116
115
|
}
|
|
117
116
|
// Reuse the recall scoring pipeline (single source of scoring truth) but scoped to the
|
|
118
117
|
// distilled durable files and with model rerank off, so this stays a cheap deterministic
|
|
@@ -143,10 +142,10 @@ export function createMemoryManageTool(options) {
|
|
|
143
142
|
resultCount: items.length,
|
|
144
143
|
});
|
|
145
144
|
}
|
|
146
|
-
async function forget(
|
|
147
|
-
const trimmed =
|
|
145
|
+
async function forget({ target }) {
|
|
146
|
+
const trimmed = target.trim();
|
|
148
147
|
if (!trimmed) {
|
|
149
|
-
|
|
148
|
+
throw new RecoverableToolError("memory_forget requires a non-empty target.");
|
|
150
149
|
}
|
|
151
150
|
const memoryPath = getChannelMemoryPath(options.channelDir);
|
|
152
151
|
const existing = await readOptionalTextFile(memoryPath);
|
|
@@ -162,7 +161,7 @@ export function createMemoryManageTool(options) {
|
|
|
162
161
|
if (matches.length > 1) {
|
|
163
162
|
// Never guess which entry to delete; make the model disambiguate.
|
|
164
163
|
const candidates = matches.map((entry, index) => `${index + 1}. ${entry.content}`).join("\n");
|
|
165
|
-
throw new
|
|
164
|
+
throw new RecoverableToolError(`"${trimmed}" matched ${matches.length} entries; be more specific so only one is removed:\n${candidates}`);
|
|
166
165
|
}
|
|
167
166
|
const removed = matches[0];
|
|
168
167
|
await queue.run(options.channelId, () => applyChannelMemoryOps(options.channelDir, [{ op: "forget", targetId: removed.id, reason: "user forget" }]));
|
|
@@ -179,24 +178,36 @@ export function createMemoryManageTool(options) {
|
|
|
179
178
|
});
|
|
180
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 });
|
|
181
180
|
}
|
|
181
|
+
return { save, search, forget };
|
|
182
|
+
}
|
|
183
|
+
export function createMemorySaveTool(options) {
|
|
184
|
+
const { save } = buildMemoryClosures(options);
|
|
182
185
|
return {
|
|
183
|
-
name: "
|
|
184
|
-
label: "
|
|
185
|
-
description: "
|
|
186
|
-
"
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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),
|
|
201
212
|
};
|
|
202
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 {};
|