@oyasmi/pipiclaw 0.8.8 → 0.8.9-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/README.md +8 -3
- package/dist/agent/channel-runner.d.ts +1 -0
- package/dist/agent/channel-runner.js +3 -2
- package/dist/agent/effect-ledger.d.ts +11 -0
- package/dist/agent/effect-ledger.js +42 -0
- package/dist/agent/job-manager.d.ts +90 -13
- package/dist/agent/job-manager.js +235 -20
- package/dist/agent/prompt/sections.js +11 -2
- package/dist/agent/prompt/types.d.ts +7 -1
- package/dist/agent/runner-factory.d.ts +7 -0
- package/dist/agent/session-events.js +20 -1
- package/dist/index.d.ts +1 -1
- package/dist/log.d.ts +6 -0
- package/dist/log.js +12 -0
- package/dist/memory/consolidation.d.ts +5 -0
- package/dist/memory/consolidation.js +35 -147
- package/dist/memory/extraction.d.ts +45 -0
- package/dist/memory/extraction.js +227 -0
- package/dist/memory/lifecycle.js +5 -0
- package/dist/memory/maintenance-jobs.js +7 -0
- package/dist/memory/post-turn-review.d.ts +3 -1
- package/dist/memory/post-turn-review.js +20 -189
- package/dist/memory/recall.d.ts +0 -1
- package/dist/memory/recall.js +135 -77
- package/dist/memory/sidecar-worker.d.ts +7 -0
- package/dist/memory/sidecar-worker.js +23 -5
- package/dist/memory/task-digest.js +1 -1
- package/dist/paths.d.ts +1 -0
- package/dist/paths.js +11 -0
- package/dist/playbooks/background-jobs.md +40 -0
- package/dist/playbooks/catalog.d.ts +1 -7
- package/dist/playbooks/catalog.js +4 -14
- package/dist/playbooks/event-scheduling.md +8 -4
- package/dist/playbooks/memory-and-learning.md +1 -1
- package/dist/playbooks/outbound-media.md +45 -0
- package/dist/playbooks/runtime-orientation.md +1 -1
- package/dist/playbooks/task-closeout.md +12 -11
- package/dist/playbooks/task-delegation.md +11 -5
- package/dist/playbooks/task-driving.md +54 -21
- package/dist/playbooks/task-planning.md +46 -19
- package/dist/runtime/bootstrap.js +29 -4
- package/dist/runtime/channel-context.d.ts +33 -0
- package/dist/runtime/dingtalk.d.ts +22 -2
- package/dist/runtime/dingtalk.js +141 -0
- package/dist/runtime/durable-dispatch.d.ts +10 -0
- package/dist/runtime/durable-dispatch.js +42 -1
- package/dist/runtime/event-validation.d.ts +48 -0
- package/dist/runtime/event-validation.js +81 -0
- package/dist/runtime/events.d.ts +17 -8
- package/dist/runtime/events.js +96 -22
- package/dist/runtime/store.d.ts +1 -1
- package/dist/runtime/task-commands.js +29 -51
- package/dist/runtime/task-driver.d.ts +5 -8
- package/dist/runtime/task-driver.js +120 -93
- package/dist/runtime/task-migration.d.ts +11 -0
- package/dist/runtime/task-migration.js +70 -0
- package/dist/settings.d.ts +11 -0
- package/dist/settings.js +12 -0
- package/dist/shared/recoverable-error.d.ts +26 -0
- package/dist/shared/recoverable-error.js +29 -0
- package/dist/shared/task-events.d.ts +0 -26
- package/dist/shared/task-events.js +0 -15
- package/dist/shared/task-ledger.d.ts +32 -8
- package/dist/shared/task-ledger.js +66 -17
- package/dist/subagents/builtin/explorer.md +16 -0
- package/dist/subagents/builtin/researcher.md +17 -0
- package/dist/subagents/builtin/verifier.md +17 -0
- package/dist/subagents/discovery.d.ts +17 -3
- package/dist/subagents/discovery.js +88 -15
- package/dist/subagents/tool.d.ts +21 -1
- package/dist/subagents/tool.js +140 -12
- package/dist/tasks/control.d.ts +4 -0
- package/dist/tasks/control.js +3 -0
- package/dist/tasks/store.d.ts +28 -1
- package/dist/tasks/store.js +63 -6
- package/dist/tasks/transitions.d.ts +40 -0
- package/dist/tasks/transitions.js +82 -0
- package/dist/tools/bash.d.ts +2 -0
- package/dist/tools/bash.js +18 -5
- package/dist/tools/event-manage.js +28 -77
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +7 -2
- package/dist/tools/job.js +2 -2
- package/dist/tools/memory-manage.js +0 -1
- package/dist/tools/registry.d.ts +29 -8
- package/dist/tools/registry.js +39 -22
- package/dist/tools/send-media.d.ts +28 -0
- package/dist/tools/send-media.js +88 -0
- package/dist/tools/task-manage/create.d.ts +2 -0
- package/dist/tools/task-manage/create.js +35 -0
- package/dist/tools/task-manage/lifecycle.d.ts +6 -0
- package/dist/tools/task-manage/lifecycle.js +197 -0
- package/dist/tools/task-manage/schema.d.ts +43 -0
- package/dist/tools/task-manage/schema.js +90 -0
- package/dist/tools/task-manage/shared.d.ts +36 -0
- package/dist/tools/task-manage/shared.js +247 -0
- package/dist/tools/task-manage/types.d.ts +53 -0
- package/dist/tools/task-manage/types.js +1 -0
- package/dist/tools/task-manage/verification.d.ts +16 -0
- package/dist/tools/task-manage/verification.js +112 -0
- package/dist/tools/task-manage.d.ts +9 -89
- package/dist/tools/task-manage.js +8 -696
- package/dist/tools/tool-details.d.ts +44 -0
- package/dist/tools/tool-details.js +62 -0
- package/dist/tui/app.js +2 -0
- package/dist/tui/terminal-media-sender.d.ts +9 -0
- package/dist/tui/terminal-media-sender.js +15 -0
- package/package.json +2 -2
- package/dist/playbooks/task-recurring.md +0 -41
- package/dist/playbooks/task-repair.md +0 -45
package/dist/tools/bash.js
CHANGED
|
@@ -30,7 +30,13 @@ const bashSchema = Type.Object({
|
|
|
30
30
|
description: `Timeout in seconds. Defaults to ${DEFAULT_BASH_TIMEOUT_SECONDS}s; pass a larger value for long-running commands.`,
|
|
31
31
|
})),
|
|
32
32
|
async: Type.Optional(Type.Boolean({
|
|
33
|
-
description: "Run in the background and return immediately with a job id instead of blocking. Use for long commands so the channel stays responsive;
|
|
33
|
+
description: "Run in the background and return immediately with a job id instead of blocking. Use for long commands so the channel stays responsive; you are woken automatically when the job finishes.",
|
|
34
|
+
})),
|
|
35
|
+
notify: Type.Optional(Type.Boolean({
|
|
36
|
+
description: "For async jobs: wake this channel when the job finishes (default true). Set false only for fire-and-forget work whose result you will never need.",
|
|
37
|
+
})),
|
|
38
|
+
taskId: Type.Optional(Type.String({
|
|
39
|
+
description: "For async jobs: the task this job advances, so the completion wake lands in that context.",
|
|
34
40
|
})),
|
|
35
41
|
});
|
|
36
42
|
/**
|
|
@@ -92,7 +98,7 @@ export function createBashTool(executor, options = {}) {
|
|
|
92
98
|
label: "bash",
|
|
93
99
|
description: `Execute a bash command in the current working directory. Returns stdout, stderr, and the exit code (a non-zero exit code is reported in the output, not raised as an error). Output is truncated to the last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first). If truncated, the full output is saved to a temp file whose path is included. Commands time out after ${DEFAULT_BASH_TIMEOUT_SECONDS}s unless you pass a larger \`timeout\`.`,
|
|
94
100
|
parameters: bashSchema,
|
|
95
|
-
execute: async (_toolCallId, { label, command, timeout, async: runAsync, }, signal) => {
|
|
101
|
+
execute: async (_toolCallId, { label, command, timeout, async: runAsync, notify, taskId, }, signal) => {
|
|
96
102
|
if (securityConfig.enabled && securityConfig.commandGuard.enabled) {
|
|
97
103
|
const guardResult = guardCommand(command, securityConfig.commandGuard);
|
|
98
104
|
if (!guardResult.allowed) {
|
|
@@ -129,14 +135,21 @@ export function createBashTool(executor, options = {}) {
|
|
|
129
135
|
if (!options.jobManager) {
|
|
130
136
|
throw new Error("Background execution is not available here (enable tools.jobs.enabled, and note it is off for sub-agents). Run the command without async, or shorten it.");
|
|
131
137
|
}
|
|
132
|
-
const
|
|
138
|
+
const willNotify = notify ?? true;
|
|
139
|
+
const job = await options.jobManager.start(effectiveCommand, label, effectiveTimeout, {
|
|
140
|
+
signal,
|
|
141
|
+
notify: willNotify,
|
|
142
|
+
...(taskId ? { taskId } : {}),
|
|
143
|
+
});
|
|
133
144
|
return {
|
|
134
145
|
content: [
|
|
135
146
|
{
|
|
136
147
|
type: "text",
|
|
137
148
|
text: `Background job ${job.id} started: ${label}\n` +
|
|
138
|
-
|
|
139
|
-
|
|
149
|
+
(willNotify
|
|
150
|
+
? "It runs off-turn; end your turn now. You will be woken automatically when it finishes, " +
|
|
151
|
+
"with its exit code and output — do not schedule a check-in for it."
|
|
152
|
+
: "It runs off-turn and will NOT wake you when it finishes; check it with the job tool (op:poll/list)."),
|
|
140
153
|
},
|
|
141
154
|
],
|
|
142
155
|
details: { kind: "bash", async: { state: "running", jobId: job.id } },
|
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { readdir, readFile, unlink } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
|
-
import { Cron } from "croner";
|
|
5
4
|
import { Type } from "typebox";
|
|
6
5
|
import { resolveEventPath } from "../runtime/event-commands.js";
|
|
6
|
+
import { EventValidationError, MAX_EVENT_FILES, validateScheduledEvent } from "../runtime/event-validation.js";
|
|
7
7
|
import { parseScheduledEventContent } from "../runtime/events.js";
|
|
8
|
-
import { guardCommand } from "../security/command-guard.js";
|
|
9
8
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
9
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
10
10
|
import { errorMessage } from "../shared/text-utils.js";
|
|
11
11
|
import { isRecord } from "../shared/type-guards.js";
|
|
12
|
-
/** one-shot events must be scheduled at least this far out; anything sooner is effectively self-triggering. */
|
|
13
|
-
const MIN_ONE_SHOT_LEAD_MS = 2 * 60 * 1000;
|
|
14
|
-
/** periodic events without a preAction gate may fire no more often than this. */
|
|
15
|
-
const MIN_PERIODIC_INTERVAL_MS = 30 * 60 * 1000;
|
|
16
|
-
/**
|
|
17
|
-
* periodic events WITH a preAction gate may fire this often: the sensor is the token guard
|
|
18
|
-
* (it exits non-zero and stays silent when there is nothing to do), so a tighter cadence is
|
|
19
|
-
* safe and is exactly the design-endorsed posture for completion-driven checks. A hard
|
|
20
|
-
* sub-floor still applies so a bogus
|
|
21
|
-
* always-pass preAction cannot drive an arbitrarily hot loop.
|
|
22
|
-
*/
|
|
23
|
-
const MIN_PERIODIC_INTERVAL_WITH_PREACTION_MS = 5 * 60 * 1000;
|
|
24
|
-
/** sanity cap on total event files to keep the directory (and the scheduler) from being flooded. */
|
|
25
|
-
const MAX_EVENT_FILES = 50;
|
|
26
12
|
const eventManageSchema = Type.Object({
|
|
27
13
|
label: Type.String({ description: "Brief description of the scheduling change (shown to the user)" }),
|
|
28
14
|
action: Type.Union([Type.Literal("create"), Type.Literal("update"), Type.Literal("delete")], {
|
|
@@ -39,53 +25,17 @@ function parseAction(action) {
|
|
|
39
25
|
if (action === "create" || action === "update" || action === "delete") {
|
|
40
26
|
return action;
|
|
41
27
|
}
|
|
42
|
-
throw new
|
|
43
|
-
}
|
|
44
|
-
function validateOneShot(event) {
|
|
45
|
-
const atTime = new Date(event.at).getTime();
|
|
46
|
-
if (!Number.isFinite(atTime)) {
|
|
47
|
-
throw new Error(`one-shot 'at' is not a valid date: ${event.at}`);
|
|
48
|
-
}
|
|
49
|
-
if (atTime < Date.now() + MIN_ONE_SHOT_LEAD_MS) {
|
|
50
|
-
throw new Error("one-shot 'at' must be at least 2 minutes in the future (self-triggering guard).");
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function validatePeriodic(event) {
|
|
54
|
-
let runs;
|
|
55
|
-
try {
|
|
56
|
-
const cron = new Cron(event.schedule);
|
|
57
|
-
runs = cron.nextRuns(3);
|
|
58
|
-
cron.stop();
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
const message = errorMessage(error);
|
|
62
|
-
throw new Error(`Invalid cron schedule "${event.schedule}": ${message}`);
|
|
63
|
-
}
|
|
64
|
-
// A preAction gate makes a tighter cadence safe (the sensor keeps most fires silent);
|
|
65
|
-
// without one, hold the 30-minute floor so a bare high-frequency cron can't burn tokens.
|
|
66
|
-
const floorMs = event.preAction ? MIN_PERIODIC_INTERVAL_WITH_PREACTION_MS : MIN_PERIODIC_INTERVAL_MS;
|
|
67
|
-
const floorMinutes = Math.round(floorMs / 60000);
|
|
68
|
-
// Fewer than two upcoming runs means no meaningful cadence to rate-limit (e.g. a one-off cron); allow it.
|
|
69
|
-
for (let i = 1; i < runs.length; i++) {
|
|
70
|
-
if (runs[i].getTime() - runs[i - 1].getTime() < floorMs) {
|
|
71
|
-
throw new Error(`periodic events must fire no more often than every ${floorMinutes} minutes` +
|
|
72
|
-
`${event.preAction ? " (even with a preAction gate)" : "; for tighter checks add a preAction gate (min 5 minutes) instead of a high-frequency cron"}.`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function validatePreAction(event, commandGuardConfig) {
|
|
77
|
-
if (!event.preAction)
|
|
78
|
-
return;
|
|
79
|
-
const result = guardCommand(event.preAction.command, commandGuardConfig);
|
|
80
|
-
if (!result.allowed) {
|
|
81
|
-
throw new Error(`preAction command blocked by guard: ${result.reason ?? "not allowed"}`);
|
|
82
|
-
}
|
|
28
|
+
throw new RecoverableToolError('Unsupported event action. Use "create", "update", or "delete".');
|
|
83
29
|
}
|
|
84
30
|
/**
|
|
85
31
|
* Validate an agent-supplied event definition and return the normalized, typed event.
|
|
86
32
|
* Rejects immediate events, near-term one-shots, high-frequency periodics, guard-blocked
|
|
87
33
|
* preActions, and cross-channel channelIds. The returned event is what gets persisted, so
|
|
88
34
|
* the file on disk is exactly what was validated.
|
|
35
|
+
*
|
|
36
|
+
* The scheduling rules themselves live in `runtime/event-validation.ts` and are re-applied by
|
|
37
|
+
* the watcher (spec 031, D4); this layer only adds tool-specific framing (channel ownership,
|
|
38
|
+
* and turning validation failures into recoverable tool errors the model can retry).
|
|
89
39
|
*/
|
|
90
40
|
function validateDefinition(rawDefinition, name, options) {
|
|
91
41
|
let data;
|
|
@@ -94,30 +44,32 @@ function validateDefinition(rawDefinition, name, options) {
|
|
|
94
44
|
}
|
|
95
45
|
catch (error) {
|
|
96
46
|
const message = errorMessage(error);
|
|
97
|
-
throw new
|
|
47
|
+
throw new RecoverableToolError(`definition is not valid JSON: ${message}`);
|
|
98
48
|
}
|
|
99
49
|
if (!isRecord(data)) {
|
|
100
|
-
throw new
|
|
50
|
+
throw new RecoverableToolError("definition must be a JSON object.");
|
|
101
51
|
}
|
|
102
52
|
const providedChannelId = data.channelId;
|
|
103
53
|
if (providedChannelId === undefined || providedChannelId === null || providedChannelId === "") {
|
|
104
54
|
data.channelId = options.channelId;
|
|
105
55
|
}
|
|
106
56
|
else if (providedChannelId !== options.channelId) {
|
|
107
|
-
throw new
|
|
57
|
+
throw new RecoverableToolError(`definition channelId "${String(providedChannelId)}" does not match the current channel "${options.channelId}".`);
|
|
108
58
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
throw new Error("event_manage cannot create or update immediate events (self-triggering loop guard); " +
|
|
59
|
+
if (data.type === "immediate") {
|
|
60
|
+
throw new RecoverableToolError("event_manage cannot create or update immediate events (self-triggering loop guard); " +
|
|
112
61
|
"do the work in the current turn instead.");
|
|
113
62
|
}
|
|
114
|
-
|
|
115
|
-
|
|
63
|
+
const event = parseScheduledEventContent(JSON.stringify(data), `${name}.json`);
|
|
64
|
+
try {
|
|
65
|
+
validateScheduledEvent(event, { commandGuardConfig: options.commandGuardConfig });
|
|
116
66
|
}
|
|
117
|
-
|
|
118
|
-
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error instanceof EventValidationError && error.recoverable) {
|
|
69
|
+
throw new RecoverableToolError(error.message);
|
|
70
|
+
}
|
|
71
|
+
throw error;
|
|
119
72
|
}
|
|
120
|
-
validatePreAction(event, options.commandGuardConfig);
|
|
121
73
|
return event;
|
|
122
74
|
}
|
|
123
75
|
async function readOwnedEvent(eventPath, name, options) {
|
|
@@ -130,7 +82,7 @@ async function readOwnedEvent(eventPath, name, options) {
|
|
|
130
82
|
throw new Error(`Existing event "${name}" could not be parsed (${message}); use /events to manage it directly.`);
|
|
131
83
|
}
|
|
132
84
|
if (existing.channelId !== options.channelId) {
|
|
133
|
-
throw new
|
|
85
|
+
throw new RecoverableToolError(`Event "${name}" belongs to another channel and cannot be modified from here.`);
|
|
134
86
|
}
|
|
135
87
|
return existing;
|
|
136
88
|
}
|
|
@@ -164,24 +116,23 @@ export async function manageEvent(options, request) {
|
|
|
164
116
|
};
|
|
165
117
|
}
|
|
166
118
|
if (!request.definition || request.definition.trim().length === 0) {
|
|
167
|
-
throw new
|
|
119
|
+
throw new RecoverableToolError(`${request.action} requires a non-empty definition.`);
|
|
168
120
|
}
|
|
169
121
|
if (request.action === "create") {
|
|
170
122
|
if (existsSync(eventPath)) {
|
|
171
|
-
throw new
|
|
123
|
+
throw new RecoverableToolError(`Event "${eventName}" already exists; use action "update" to replace it.`);
|
|
172
124
|
}
|
|
173
125
|
if ((await countEventFiles(eventsDir)) >= MAX_EVENT_FILES) {
|
|
174
|
-
throw new
|
|
126
|
+
throw new RecoverableToolError(`Too many event files (>= ${MAX_EVENT_FILES}) in workspace/events; clean up stale events before creating more.`);
|
|
175
127
|
}
|
|
176
128
|
}
|
|
177
129
|
else {
|
|
178
130
|
if (!existsSync(eventPath)) {
|
|
179
|
-
throw new
|
|
180
|
-
}
|
|
181
|
-
const existing = await readOwnedEvent(eventPath, eventName, options);
|
|
182
|
-
if (existing.type === "immediate") {
|
|
183
|
-
throw new Error(`Event "${eventName}" is an immediate event and cannot be updated via event_manage.`);
|
|
131
|
+
throw new RecoverableToolError(`Event "${eventName}" does not exist; use action "create" to add it.`);
|
|
184
132
|
}
|
|
133
|
+
// Ownership check only: an existing file that no longer parses (e.g. a legacy immediate
|
|
134
|
+
// event) is reported by readOwnedEvent and pointed at /events.
|
|
135
|
+
await readOwnedEvent(eventPath, eventName, options);
|
|
185
136
|
}
|
|
186
137
|
const event = validateDefinition(request.definition, eventName, options);
|
|
187
138
|
// Persist the canonical form: a tolerated legacy `timezone` is dropped so freshly written
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { Executor } from "../executor.js";
|
|
4
4
|
import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
5
|
+
import type { MediaSender } from "../runtime/channel-context.js";
|
|
5
6
|
import type { SecurityConfig } from "../security/types.js";
|
|
6
7
|
import type { PipiclawMemoryRecallSettings, PipiclawSessionSearchSettings } from "../settings.js";
|
|
7
8
|
import type { SubAgentDiscoveryResult } from "../subagents/discovery.js";
|
|
@@ -16,9 +17,12 @@ export interface CreatePipiclawToolsOptions {
|
|
|
16
17
|
channelId: string;
|
|
17
18
|
getSubAgentDiscovery: () => SubAgentDiscoveryResult;
|
|
18
19
|
getMemoryRecallSettings: () => PipiclawMemoryRecallSettings;
|
|
20
|
+
getSubAgentModelReference?: () => string | null;
|
|
19
21
|
getSessionSearchSettings: () => PipiclawSessionSearchSettings;
|
|
20
22
|
memoryCandidateStore: MemoryCandidateStore;
|
|
21
23
|
securityConfig?: SecurityConfig;
|
|
22
24
|
toolsConfig?: PipiclawToolsConfig;
|
|
25
|
+
/** Transport-provided attachment port; when present, enables the `send_media` tool. */
|
|
26
|
+
mediaSender?: MediaSender;
|
|
23
27
|
}
|
|
24
28
|
export declare function createPipiclawTools(options: CreatePipiclawToolsOptions): AgentTool<any>[];
|
package/dist/tools/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { loadSecurityConfig } from "../security/config.js";
|
|
|
4
4
|
import { createSubAgentTool } from "../subagents/tool.js";
|
|
5
5
|
import { loadToolsConfig } from "./config.js";
|
|
6
6
|
import { buildToolSet } from "./registry.js";
|
|
7
|
+
import { withToolDetails } from "./tool-details.js";
|
|
7
8
|
export function createPipiclawTools(options) {
|
|
8
9
|
const securityConfig = options.securityConfig ?? loadSecurityConfig(APP_HOME_DIR);
|
|
9
10
|
const toolsConfig = options.toolsConfig ?? loadToolsConfig(APP_HOME_DIR);
|
|
@@ -31,10 +32,13 @@ export function createPipiclawTools(options) {
|
|
|
31
32
|
resolveApiKey: options.resolveApiKey,
|
|
32
33
|
getSessionSearchSettings: options.getSessionSearchSettings,
|
|
33
34
|
memoryCandidateStore: options.memoryCandidateStore,
|
|
35
|
+
mediaSender: options.mediaSender,
|
|
34
36
|
});
|
|
35
37
|
return [
|
|
36
38
|
...leafTools,
|
|
37
|
-
|
|
39
|
+
// Bound to the same `details` contract as the registry's tools; it is registered here
|
|
40
|
+
// rather than in TOOL_REGISTRY only to avoid a registry ↔ subagents/tool import cycle.
|
|
41
|
+
withToolDetails(createSubAgentTool({
|
|
38
42
|
executor: options.executor,
|
|
39
43
|
getCurrentModel: options.getCurrentModel,
|
|
40
44
|
getAvailableModels: options.getAvailableModels,
|
|
@@ -43,6 +47,7 @@ export function createPipiclawTools(options) {
|
|
|
43
47
|
channelDir: options.channelDir,
|
|
44
48
|
getSubAgentDiscovery: options.getSubAgentDiscovery,
|
|
45
49
|
getMemoryRecallSettings: options.getMemoryRecallSettings,
|
|
50
|
+
getSubAgentModelReference: options.getSubAgentModelReference,
|
|
46
51
|
memoryCandidateStore: options.memoryCandidateStore,
|
|
47
52
|
securityConfig,
|
|
48
53
|
webConfig: toolsConfig.tools.web,
|
|
@@ -51,6 +56,6 @@ export function createPipiclawTools(options) {
|
|
|
51
56
|
workspaceDir: options.workspaceDir,
|
|
52
57
|
channelId: options.channelId,
|
|
53
58
|
},
|
|
54
|
-
}),
|
|
59
|
+
}), "subagent"),
|
|
55
60
|
];
|
|
56
61
|
}
|
package/dist/tools/job.js
CHANGED
|
@@ -38,7 +38,7 @@ export function createJobTool(options) {
|
|
|
38
38
|
label: "job",
|
|
39
39
|
description: "Inspect and control background bash jobs (started with bash async:true). op=list shows a snapshot; " +
|
|
40
40
|
"op=poll waits briefly for a running job to finish and returns its output; op=cancel stops jobs by id. " +
|
|
41
|
-
"
|
|
41
|
+
"A finished job wakes this channel by itself, so never schedule a check-in for one — end the turn instead.",
|
|
42
42
|
parameters: jobSchema,
|
|
43
43
|
execute: async (_toolCallId, { op, ids }, signal) => {
|
|
44
44
|
if (op === "cancel") {
|
|
@@ -81,7 +81,7 @@ export function createJobTool(options) {
|
|
|
81
81
|
}
|
|
82
82
|
if (running.length > 0) {
|
|
83
83
|
parts.push(`## Still running (${running.length})`, ...running.map(formatJobLine));
|
|
84
|
-
parts.push("Poll again to keep waiting, or
|
|
84
|
+
parts.push("Poll again to keep waiting, or just end your turn — you are woken when the job finishes.");
|
|
85
85
|
}
|
|
86
86
|
return {
|
|
87
87
|
content: [{ type: "text", text: parts.join("\n\n") }],
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ import type { Api, Model } from "@earendil-works/pi-ai";
|
|
|
3
3
|
import type { ChannelJobManager } from "../agent/job-manager.js";
|
|
4
4
|
import type { Executor } from "../executor.js";
|
|
5
5
|
import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
6
|
+
import type { MediaSender } from "../runtime/channel-context.js";
|
|
6
7
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
7
8
|
import type { PipiclawSessionSearchSettings } from "../settings.js";
|
|
8
9
|
import type { PipiclawToolsConfig, PipiclawWebToolsConfig } from "./config.js";
|
|
10
|
+
import { type ToolDetailsKind } from "./tool-details.js";
|
|
9
11
|
/**
|
|
10
12
|
* Unified build context passed to every tool's `create` closure. It carries the union
|
|
11
13
|
* of everything any registered tool might need; each closure reads only its own fields.
|
|
@@ -40,11 +42,15 @@ export interface ToolBuildContext {
|
|
|
40
42
|
resolveApiKey?: (model: Model<Api>) => Promise<string>;
|
|
41
43
|
getSessionSearchSettings?: () => PipiclawSessionSearchSettings;
|
|
42
44
|
memoryCandidateStore?: MemoryCandidateStore;
|
|
45
|
+
/**
|
|
46
|
+
* Present only on the main path, and only when the driving transport can deliver
|
|
47
|
+
* files. Gates the `send_media` tool; sub-agents never receive it.
|
|
48
|
+
*/
|
|
49
|
+
mediaSender?: MediaSender;
|
|
43
50
|
}
|
|
44
51
|
export interface ToolRegistration {
|
|
45
|
-
name
|
|
46
|
-
|
|
47
|
-
promptHint: string;
|
|
52
|
+
/** Also the tool's `details.kind`: the name is the authoritative discriminator. */
|
|
53
|
+
name: ToolDetailsKind;
|
|
48
54
|
/** Whether this tool is included in a sub-agent's tool set. */
|
|
49
55
|
availableToSubagents: boolean;
|
|
50
56
|
/** Config gate; when omitted the tool is always enabled. */
|
|
@@ -58,13 +64,28 @@ export interface ToolRegistration {
|
|
|
58
64
|
* sub-agent tool set is built by importing `buildToolSet` from this module).
|
|
59
65
|
*/
|
|
60
66
|
export declare const TOOL_REGISTRY: ToolRegistration[];
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Every tool name a tool set can contain: the registry plus `subagent`, which is registered
|
|
69
|
+
* outside it. Used to validate authored references to tools (playbook `requires-tools`), so a
|
|
70
|
+
* typo fails loudly instead of silently dropping the playbook from the catalog.
|
|
71
|
+
*
|
|
72
|
+
* This deliberately carries no per-tool prose. Tool name, description and parameter schema
|
|
73
|
+
* already reach the model with every request; spec 026 §3.2 removed the `## Available Tools`
|
|
74
|
+
* prompt section because repeating a hint for each tool cost ~180 prompt units per turn and
|
|
75
|
+
* added no capability. Guidance on *when* to prefer a tool belongs in that tool's own
|
|
76
|
+
* `description` (see `grep`, which tells the model to prefer it over `bash grep -rn`).
|
|
77
|
+
*/
|
|
78
|
+
export declare const TOOL_NAMES: ReadonlySet<string>;
|
|
65
79
|
export interface BuildToolSetOptions {
|
|
66
80
|
/** When true, include only tools flagged `availableToSubagents`. */
|
|
67
81
|
forSubagent?: boolean;
|
|
68
82
|
}
|
|
69
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Build a tool set from the registry, honoring sub-agent availability and config gates.
|
|
85
|
+
*
|
|
86
|
+
* Every tool is bound to the `details` contract here rather than in its own factory: the
|
|
87
|
+
* registration name is stamped as `details.kind`, and a `RecoverableToolError` becomes a
|
|
88
|
+
* normal result the model can act on. Doing it at this single seam means a new tool conforms
|
|
89
|
+
* without its author having to remember, and `kind` can never disagree with the name.
|
|
90
|
+
*/
|
|
70
91
|
export declare function buildToolSet(ctx: ToolBuildContext, options?: BuildToolSetOptions): AgentTool<any>[];
|
package/dist/tools/registry.js
CHANGED
|
@@ -5,9 +5,11 @@ import { createGrepTool } from "./grep.js";
|
|
|
5
5
|
import { createJobTool } from "./job.js";
|
|
6
6
|
import { createMemoryManageTool } from "./memory-manage.js";
|
|
7
7
|
import { createReadTool } from "./read.js";
|
|
8
|
+
import { createSendMediaTool } from "./send-media.js";
|
|
8
9
|
import { createSessionSearchTool } from "./session-search.js";
|
|
9
10
|
import { createSkillManageTool } from "./skill-manage.js";
|
|
10
11
|
import { createTaskManageTool } from "./task-manage.js";
|
|
12
|
+
import { withToolDetails } from "./tool-details.js";
|
|
11
13
|
import { createWebFetchTool } from "./web-fetch.js";
|
|
12
14
|
import { createWebSearchTool } from "./web-search.js";
|
|
13
15
|
import { createWriteTool } from "./write.js";
|
|
@@ -36,13 +38,11 @@ function webEnabled(ctx) {
|
|
|
36
38
|
export const TOOL_REGISTRY = [
|
|
37
39
|
{
|
|
38
40
|
name: "read",
|
|
39
|
-
promptHint: "Read files",
|
|
40
41
|
availableToSubagents: true,
|
|
41
42
|
create: (ctx) => createReadTool(ctx.executor, fileToolOptions(ctx)),
|
|
42
43
|
},
|
|
43
44
|
{
|
|
44
45
|
name: "bash",
|
|
45
|
-
promptHint: "Run shell commands and external programs",
|
|
46
46
|
availableToSubagents: true,
|
|
47
47
|
create: (ctx) => createBashTool(ctx.executor, {
|
|
48
48
|
...fileToolOptions(ctx),
|
|
@@ -56,25 +56,21 @@ export const TOOL_REGISTRY = [
|
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
name: "edit",
|
|
59
|
-
promptHint: "Surgical file edits",
|
|
60
59
|
availableToSubagents: true,
|
|
61
60
|
create: (ctx) => createEditTool(ctx.executor, fileToolOptions(ctx)),
|
|
62
61
|
},
|
|
63
62
|
{
|
|
64
63
|
name: "grep",
|
|
65
|
-
promptHint: "Search file contents with a regex; grouped, paginated, token-bounded — prefer over bash grep",
|
|
66
64
|
availableToSubagents: true,
|
|
67
65
|
create: (ctx) => createGrepTool(ctx.executor, fileToolOptions(ctx)),
|
|
68
66
|
},
|
|
69
67
|
{
|
|
70
68
|
name: "write",
|
|
71
|
-
promptHint: "Create or overwrite files when needed",
|
|
72
69
|
availableToSubagents: true,
|
|
73
70
|
create: (ctx) => createWriteTool(ctx.executor, fileToolOptions(ctx)),
|
|
74
71
|
},
|
|
75
72
|
{
|
|
76
73
|
name: "web_search",
|
|
77
|
-
promptHint: "Search the public web and return titles, URLs, and snippets",
|
|
78
74
|
availableToSubagents: true,
|
|
79
75
|
enabledBy: webEnabled,
|
|
80
76
|
create: (ctx) => createWebSearchTool({
|
|
@@ -86,7 +82,6 @@ export const TOOL_REGISTRY = [
|
|
|
86
82
|
},
|
|
87
83
|
{
|
|
88
84
|
name: "web_fetch",
|
|
89
|
-
promptHint: "Fetch a public URL and extract readable content",
|
|
90
85
|
availableToSubagents: true,
|
|
91
86
|
enabledBy: webEnabled,
|
|
92
87
|
create: (ctx) => createWebFetchTool({
|
|
@@ -97,9 +92,21 @@ export const TOOL_REGISTRY = [
|
|
|
97
92
|
channelDir: ctx.channelDir,
|
|
98
93
|
}),
|
|
99
94
|
},
|
|
95
|
+
{
|
|
96
|
+
name: "send_media",
|
|
97
|
+
availableToSubagents: false,
|
|
98
|
+
// Enabled only when the driving transport supplied a media sender (the DingTalk
|
|
99
|
+
// bot, or the terminal). Absent it, the tool is not built or advertised.
|
|
100
|
+
enabledBy: (ctx) => ctx.mediaSender != null,
|
|
101
|
+
create: (ctx) => createSendMediaTool(ctx.executor, {
|
|
102
|
+
mediaSender: req(ctx.mediaSender, "mediaSender"),
|
|
103
|
+
channelId: ctx.channelId,
|
|
104
|
+
securityConfig: ctx.securityConfig,
|
|
105
|
+
securityContext: ctx.securityContext,
|
|
106
|
+
}),
|
|
107
|
+
},
|
|
100
108
|
{
|
|
101
109
|
name: "session_search",
|
|
102
|
-
promptHint: "Search current-channel cold transcript storage for older conversation details",
|
|
103
110
|
availableToSubagents: false,
|
|
104
111
|
create: (ctx) => createSessionSearchTool({
|
|
105
112
|
channelId: ctx.channelId,
|
|
@@ -111,7 +118,6 @@ export const TOOL_REGISTRY = [
|
|
|
111
118
|
},
|
|
112
119
|
{
|
|
113
120
|
name: "memory_manage",
|
|
114
|
-
promptHint: "Save a durable fact, search stored memory on demand, or forget an entry — when the user asks",
|
|
115
121
|
availableToSubagents: false,
|
|
116
122
|
create: (ctx) => createMemoryManageTool({
|
|
117
123
|
channelId: ctx.channelId,
|
|
@@ -124,13 +130,11 @@ export const TOOL_REGISTRY = [
|
|
|
124
130
|
},
|
|
125
131
|
{
|
|
126
132
|
name: "skill_manage",
|
|
127
|
-
promptHint: "List, view, create, or maintain workspace-level procedural memory in skills/",
|
|
128
133
|
availableToSubagents: false,
|
|
129
134
|
create: (ctx) => createSkillManageTool({ workspaceDir: ctx.workspaceDir }),
|
|
130
135
|
},
|
|
131
136
|
{
|
|
132
137
|
name: "event_manage",
|
|
133
|
-
promptHint: "Create/update/delete validated one-shot reminders, periodic cadences, and preAction-gated sensors",
|
|
134
138
|
availableToSubagents: false,
|
|
135
139
|
create: (ctx) => createEventManageTool({
|
|
136
140
|
workspaceDir: ctx.workspaceDir,
|
|
@@ -140,7 +144,6 @@ export const TOOL_REGISTRY = [
|
|
|
140
144
|
},
|
|
141
145
|
{
|
|
142
146
|
name: "task_manage",
|
|
143
|
-
promptHint: "Create, checkpoint, govern, verify, complete, cancel, or list persistent tasks",
|
|
144
147
|
availableToSubagents: false,
|
|
145
148
|
// tools.tasks is the master switch for the whole autonomous long-running task
|
|
146
149
|
// mechanism; the TaskDriver and per-turn task digest honor the same flag.
|
|
@@ -154,7 +157,6 @@ export const TOOL_REGISTRY = [
|
|
|
154
157
|
},
|
|
155
158
|
{
|
|
156
159
|
name: "job",
|
|
157
|
-
promptHint: "Inspect/poll/cancel background bash jobs started with bash async:true",
|
|
158
160
|
availableToSubagents: false,
|
|
159
161
|
// Present only when a job manager was supplied (always on the main path,
|
|
160
162
|
// never for sub-agents).
|
|
@@ -162,14 +164,29 @@ export const TOOL_REGISTRY = [
|
|
|
162
164
|
create: (ctx) => createJobTool({ jobManager: req(ctx.jobManager, "jobManager") }),
|
|
163
165
|
},
|
|
164
166
|
];
|
|
165
|
-
/**
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Every tool name a tool set can contain: the registry plus `subagent`, which is registered
|
|
169
|
+
* outside it. Used to validate authored references to tools (playbook `requires-tools`), so a
|
|
170
|
+
* typo fails loudly instead of silently dropping the playbook from the catalog.
|
|
171
|
+
*
|
|
172
|
+
* This deliberately carries no per-tool prose. Tool name, description and parameter schema
|
|
173
|
+
* already reach the model with every request; spec 026 §3.2 removed the `## Available Tools`
|
|
174
|
+
* prompt section because repeating a hint for each tool cost ~180 prompt units per turn and
|
|
175
|
+
* added no capability. Guidance on *when* to prefer a tool belongs in that tool's own
|
|
176
|
+
* `description` (see `grep`, which tells the model to prefer it over `bash grep -rn`).
|
|
177
|
+
*/
|
|
178
|
+
export const TOOL_NAMES = new Set([
|
|
179
|
+
...TOOL_REGISTRY.map((registration) => registration.name),
|
|
180
|
+
"subagent",
|
|
181
|
+
]);
|
|
182
|
+
/**
|
|
183
|
+
* Build a tool set from the registry, honoring sub-agent availability and config gates.
|
|
184
|
+
*
|
|
185
|
+
* Every tool is bound to the `details` contract here rather than in its own factory: the
|
|
186
|
+
* registration name is stamped as `details.kind`, and a `RecoverableToolError` becomes a
|
|
187
|
+
* normal result the model can act on. Doing it at this single seam means a new tool conforms
|
|
188
|
+
* without its author having to remember, and `kind` can never disagree with the name.
|
|
189
|
+
*/
|
|
173
190
|
export function buildToolSet(ctx, options = {}) {
|
|
174
191
|
const result = [];
|
|
175
192
|
for (const registration of TOOL_REGISTRY) {
|
|
@@ -179,7 +196,7 @@ export function buildToolSet(ctx, options = {}) {
|
|
|
179
196
|
if (registration.enabledBy && !registration.enabledBy(ctx)) {
|
|
180
197
|
continue;
|
|
181
198
|
}
|
|
182
|
-
result.push(registration.create(ctx));
|
|
199
|
+
result.push(withToolDetails(registration.create(ctx), registration.name));
|
|
183
200
|
}
|
|
184
201
|
return result;
|
|
185
202
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import type { Executor } from "../executor.js";
|
|
4
|
+
import type { MediaSender } from "../runtime/channel-context.js";
|
|
5
|
+
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
6
|
+
declare const sendMediaSchema: Type.TObject<{
|
|
7
|
+
label: Type.TString;
|
|
8
|
+
path: Type.TString;
|
|
9
|
+
fileName: Type.TOptional<Type.TString>;
|
|
10
|
+
}>;
|
|
11
|
+
export interface SendMediaToolOptions {
|
|
12
|
+
/** Transport that actually delivers the attachment. Bound to `channelId`. */
|
|
13
|
+
mediaSender: MediaSender;
|
|
14
|
+
/** The channel this tool instance is bound to — supplied by the runtime, not the model. */
|
|
15
|
+
channelId: string;
|
|
16
|
+
securityConfig?: SecurityConfig;
|
|
17
|
+
securityContext?: SecurityRuntimeContext;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Send a workspace file to the current channel as a native attachment (inline
|
|
21
|
+
* image or downloadable file). Bound to its channel at build time — like `read`
|
|
22
|
+
* and `bash` — so the model never chooses the destination. The file is read
|
|
23
|
+
* through the `Executor` (base64, exactly as `read` does for images) so the tool
|
|
24
|
+
* works regardless of where the executor runs, and every path passes the same
|
|
25
|
+
* path-guard as the file tools before any bytes leave the box.
|
|
26
|
+
*/
|
|
27
|
+
export declare function createSendMediaTool(executor: Executor, options: SendMediaToolOptions): AgentTool<typeof sendMediaSchema>;
|
|
28
|
+
export {};
|