@oyasmi/pipiclaw 0.7.4 → 0.7.6

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.
Files changed (59) hide show
  1. package/README.md +5 -1
  2. package/dist/agent/channel-runner.js +14 -0
  3. package/dist/agent/commands.d.ts +1 -1
  4. package/dist/agent/commands.js +6 -0
  5. package/dist/agent/job-manager.d.ts +79 -0
  6. package/dist/agent/job-manager.js +241 -0
  7. package/dist/agent/prompt-builder.js +13 -4
  8. package/dist/memory/review-log.d.ts +1 -1
  9. package/dist/memory/task-digest.d.ts +21 -0
  10. package/dist/memory/task-digest.js +66 -0
  11. package/dist/runtime/bootstrap.js +13 -1
  12. package/dist/runtime/dingtalk.d.ts +1 -0
  13. package/dist/runtime/dingtalk.js +6 -2
  14. package/dist/runtime/event-commands.d.ts +5 -0
  15. package/dist/runtime/event-commands.js +2 -2
  16. package/dist/runtime/task-commands.d.ts +6 -0
  17. package/dist/runtime/task-commands.js +133 -0
  18. package/dist/settings.d.ts +7 -0
  19. package/dist/settings.js +13 -0
  20. package/dist/shared/task-ledger.d.ts +53 -0
  21. package/dist/shared/task-ledger.js +149 -0
  22. package/dist/tools/bash.d.ts +12 -0
  23. package/dist/tools/bash.js +67 -1
  24. package/dist/tools/config.d.ts +15 -0
  25. package/dist/tools/config.js +37 -0
  26. package/dist/tools/edit.js +0 -0
  27. package/dist/tools/event-manage.d.ts +35 -0
  28. package/dist/tools/event-manage.js +238 -0
  29. package/dist/tools/grep.d.ts +19 -0
  30. package/dist/tools/grep.js +262 -0
  31. package/dist/tools/index.js +5 -0
  32. package/dist/tools/job.d.ts +13 -0
  33. package/dist/tools/job.js +92 -0
  34. package/dist/tools/memory-manage.d.ts +24 -0
  35. package/dist/tools/memory-manage.js +150 -0
  36. package/dist/tools/read.js +103 -16
  37. package/dist/tools/registry.d.ts +7 -1
  38. package/dist/tools/registry.js +54 -17
  39. package/dist/tools/session-search.js +4 -1
  40. package/dist/tools/skill-manage.d.ts +12 -5
  41. package/dist/tools/skill-manage.js +113 -15
  42. package/dist/tools/task-manage.d.ts +43 -0
  43. package/dist/tools/task-manage.js +226 -0
  44. package/dist/tools/web-cache.d.ts +11 -0
  45. package/dist/tools/web-cache.js +62 -0
  46. package/dist/tools/web-fetch.d.ts +3 -0
  47. package/dist/tools/web-fetch.js +70 -5
  48. package/dist/tui/app.js +2 -0
  49. package/dist/tui/commands.d.ts +1 -0
  50. package/dist/tui/commands.js +3 -0
  51. package/dist/tui/turn-controller.d.ts +1 -0
  52. package/dist/tui/turn-controller.js +1 -0
  53. package/package.json +1 -1
  54. package/dist/tools/memory-save.d.ts +0 -16
  55. package/dist/tools/memory-save.js +0 -42
  56. package/dist/tools/skill-list.d.ts +0 -18
  57. package/dist/tools/skill-list.js +0 -86
  58. package/dist/tools/skill-view.d.ts +0 -13
  59. package/dist/tools/skill-view.js +0 -44
@@ -0,0 +1,150 @@
1
+ import { Type } from "typebox";
2
+ import { getDefaultChannelMemoryQueue } from "../memory/channel-maintenance-queue.js";
3
+ import { applyChannelMemoryOps, getChannelMemoryPath, parseChannelMemoryEntries } from "../memory/files.js";
4
+ import { recallRelevantMemory } from "../memory/recall.js";
5
+ import { appendMemoryReviewLog } from "../memory/review-log.js";
6
+ import { readOptionalTextFile } from "../shared/fs-utils.js";
7
+ const memoryManageSchema = Type.Object({
8
+ label: Type.String({ description: "Brief description of the memory change (shown to user)" }),
9
+ op: Type.Union([Type.Literal("save"), Type.Literal("search"), Type.Literal("forget")], {
10
+ description: '"save" a durable fact, "search" this channel\'s stored memory on demand, or "forget" a stored entry the user asked you to drop.',
11
+ }),
12
+ content: Type.Optional(Type.String({
13
+ description: "For save: the durable fact as a single self-contained, keyword-rich sentence, written so future keyword search can find it.",
14
+ })),
15
+ query: Type.Optional(Type.String({ description: "For search: what to look for in stored memory." })),
16
+ target: Type.Optional(Type.String({
17
+ description: "For forget: text identifying the stored entry to remove. Must match exactly one entry; use search first to confirm the wording.",
18
+ })),
19
+ kind: Type.Optional(Type.Union([
20
+ Type.Literal("preference"),
21
+ Type.Literal("fact"),
22
+ Type.Literal("decision"),
23
+ Type.Literal("constraint"),
24
+ Type.Literal("open-loop"),
25
+ ], { description: "For save: what kind of durable memory this is." })),
26
+ });
27
+ function textResult(text, details) {
28
+ return { content: [{ type: "text", text }], details };
29
+ }
30
+ export function createMemoryManageTool(options) {
31
+ const queue = options.channelMemoryQueue ?? getDefaultChannelMemoryQueue();
32
+ async function save(content, kind) {
33
+ const trimmed = (content ?? "").trim();
34
+ if (!trimmed) {
35
+ return textResult("No content provided; nothing was saved.", {
36
+ kind: "memory_manage",
37
+ op: "save",
38
+ saved: false,
39
+ });
40
+ }
41
+ // Serialize through the shared channel memory queue so this never races with background
42
+ // consolidation/maintenance on the same channel's files.
43
+ const result = await queue.run(options.channelId, () => applyChannelMemoryOps(options.channelDir, [{ op: "add", content: trimmed }]));
44
+ options.memoryCandidateStore.invalidate(getChannelMemoryPath(options.channelDir));
45
+ return textResult(`Saved to channel memory${kind ? ` (${kind})` : ""}.`, {
46
+ kind: "memory_manage",
47
+ op: "save",
48
+ saved: result.added > 0,
49
+ });
50
+ }
51
+ async function search(query) {
52
+ const trimmed = (query ?? "").trim();
53
+ if (!trimmed) {
54
+ return textResult("Provide a query to search stored memory.", {
55
+ kind: "memory_manage",
56
+ op: "search",
57
+ resultCount: 0,
58
+ });
59
+ }
60
+ // Reuse the recall scoring pipeline (single source of scoring truth) but scoped to the
61
+ // distilled durable files and with model rerank off, so this stays a cheap deterministic
62
+ // point-query distinct from the passive per-turn recall injection.
63
+ const model = options.getCurrentModel();
64
+ const { items } = await recallRelevantMemory({
65
+ query: trimmed,
66
+ channelId: options.channelId,
67
+ workspaceDir: options.workspaceDir,
68
+ channelDir: options.channelDir,
69
+ allowedSources: ["channel-memory", "channel-history"],
70
+ maxCandidates: 8,
71
+ maxInjected: 8,
72
+ maxChars: 4000,
73
+ rerankWithModel: false,
74
+ autoRerank: false,
75
+ model,
76
+ resolveApiKey: options.resolveApiKey,
77
+ candidateStore: options.memoryCandidateStore,
78
+ });
79
+ if (items.length === 0) {
80
+ return textResult(`No stored memory matched "${trimmed}". Try a broader query, or the fact may not be saved yet.`, { kind: "memory_manage", op: "search", resultCount: 0 });
81
+ }
82
+ const rendered = items
83
+ .map((item, index) => `${index + 1}. [${item.source}/${item.title}] ${item.content}`)
84
+ .join("\n");
85
+ return textResult(`Found ${items.length} stored memory entr${items.length === 1 ? "y" : "ies"}:\n\n${rendered}`, {
86
+ kind: "memory_manage",
87
+ op: "search",
88
+ resultCount: items.length,
89
+ });
90
+ }
91
+ async function forget(target) {
92
+ const trimmed = (target ?? "").trim();
93
+ if (!trimmed) {
94
+ return textResult("Provide the text of the entry to forget.", {
95
+ kind: "memory_manage",
96
+ op: "forget",
97
+ forgotten: false,
98
+ });
99
+ }
100
+ const memoryPath = getChannelMemoryPath(options.channelDir);
101
+ const existing = await readOptionalTextFile(memoryPath);
102
+ const entries = parseChannelMemoryEntries(existing);
103
+ const needle = trimmed.toLowerCase();
104
+ const matches = entries.filter((entry) => entry.content === trimmed || entry.content.toLowerCase().includes(needle));
105
+ if (matches.length === 0) {
106
+ return textResult(`No stored memory entry matched "${trimmed}"; nothing was removed.`, {
107
+ kind: "memory_manage",
108
+ op: "forget",
109
+ forgotten: false,
110
+ });
111
+ }
112
+ if (matches.length > 1) {
113
+ // Never guess which entry to delete; make the model disambiguate.
114
+ const candidates = matches.map((entry, index) => `${index + 1}. ${entry.content}`).join("\n");
115
+ throw new Error(`"${trimmed}" matched ${matches.length} entries; be more specific so only one is removed:\n${candidates}`);
116
+ }
117
+ const removed = matches[0];
118
+ await queue.run(options.channelId, () => applyChannelMemoryOps(options.channelDir, [{ op: "invalidate", targetId: removed.id, reason: "user forget" }]));
119
+ options.memoryCandidateStore.invalidate(memoryPath);
120
+ // Audit trail: record what was forgotten so the maintenance log can answer "who dropped what,
121
+ // when, and why" — the `.memory-backups/` copy is a recovery aid, not an audit record.
122
+ await appendMemoryReviewLog(options.channelDir, {
123
+ timestamp: new Date().toISOString(),
124
+ channelId: options.channelId,
125
+ reason: "user-forget",
126
+ actions: [{ op: "forget", target: removed.content, matchedBy: trimmed }],
127
+ }).catch(() => { });
128
+ return textResult(`Forgot: ${removed.content}`, { kind: "memory_manage", op: "forget", forgotten: true });
129
+ }
130
+ return {
131
+ name: "memory_manage",
132
+ label: "memory_manage",
133
+ description: "Manage this channel's durable MEMORY.md: save a durable fact the user asks you to remember, search stored " +
134
+ "memory on demand mid-task, or forget an entry the user asks you to drop. Prefer this over editing MEMORY.md " +
135
+ "directly — it serializes with background consolidation and keeps memory recallable. Not for transient task state.",
136
+ parameters: memoryManageSchema,
137
+ execute: async (_toolCallId, args) => {
138
+ switch (args.op) {
139
+ case "save":
140
+ return save(args.content, args.kind);
141
+ case "search":
142
+ return search(args.query);
143
+ case "forget":
144
+ return forget(args.target);
145
+ default:
146
+ throw new Error('Unsupported memory op. Use "save", "search", or "forget".');
147
+ }
148
+ },
149
+ };
150
+ }
@@ -22,6 +22,48 @@ function isImageFile(filePath) {
22
22
  const ext = extname(filePath).toLowerCase();
23
23
  return IMAGE_MIME_TYPES[ext] || null;
24
24
  }
25
+ /** Directory tree caps, mirroring oh-my-pi's read: shallow and per-directory bounded. */
26
+ const DIR_MAX_DEPTH = 2;
27
+ const DIR_PER_DIR_LIMIT = 12;
28
+ /**
29
+ * Render a depth-2 directory tree from a newline-separated list of paths (directories carry a
30
+ * trailing `/`, produced by the shell). Kept deliberately portable — no sizes or mtimes, since
31
+ * `find -printf` / `stat` formats differ across BSD, GNU, and busybox; the structure is the value.
32
+ */
33
+ function renderDirectoryTree(rootPath, rawPaths) {
34
+ const rootPrefix = rootPath.endsWith("/") ? rootPath : `${rootPath}/`;
35
+ const entries = rawPaths
36
+ .split("\n")
37
+ .map((line) => line.trim())
38
+ .filter((line) => line.length > 0 && line !== rootPath && line !== rootPrefix)
39
+ .map((line) => (line.startsWith(rootPrefix) ? line.slice(rootPrefix.length) : line))
40
+ .sort((a, b) => a.replace(/\/$/, "").localeCompare(b.replace(/\/$/, "")));
41
+ if (entries.length === 0) {
42
+ return "(empty directory)";
43
+ }
44
+ // Group by immediate parent so we can cap children per directory.
45
+ const perParentCount = new Map();
46
+ const lines = [];
47
+ const elided = new Map();
48
+ for (const entry of entries) {
49
+ const isDir = entry.endsWith("/");
50
+ const rel = isDir ? entry.slice(0, -1) : entry;
51
+ const segments = rel.split("/");
52
+ const depth = segments.length - 1;
53
+ const parent = depth === 0 ? "" : segments.slice(0, -1).join("/");
54
+ const count = (perParentCount.get(parent) ?? 0) + 1;
55
+ perParentCount.set(parent, count);
56
+ if (count > DIR_PER_DIR_LIMIT) {
57
+ elided.set(parent, (elided.get(parent) ?? 0) + 1);
58
+ continue;
59
+ }
60
+ lines.push(`${" ".repeat(depth)}${segments[segments.length - 1]}${isDir ? "/" : ""}`);
61
+ }
62
+ for (const [, count] of elided) {
63
+ lines.push(` [+${count} more]`);
64
+ }
65
+ return lines.join("\n");
66
+ }
25
67
  const readSchema = Type.Object({
26
68
  label: Type.String({ description: "Brief description of what you're reading and why (shown to user)" }),
27
69
  path: Type.String({ description: "Path to the file to read (relative or absolute)" }),
@@ -89,33 +131,78 @@ export function createReadTool(executor, options = {}) {
89
131
  details: undefined,
90
132
  };
91
133
  }
92
- // Get total line count first
93
- const countResult = await executor.exec(`awk 'END { print NR }' ${shellEscape(path)}`, { signal });
94
- if (countResult.code !== 0) {
95
- throw new Error(countResult.stderr || `Failed to read file: ${path}`);
134
+ // PDF documents are converted to text with pdftotext, then run through the same
135
+ // offset/limit/truncation pipeline as any text file.
136
+ const isPdf = extname(path).toLowerCase() === ".pdf";
137
+ let pdfText = "";
138
+ if (isPdf) {
139
+ const converted = await executor.exec(`pdftotext -layout ${shellEscape(path)} - 2>&1`, { signal });
140
+ if (converted.code === 127) {
141
+ throw new Error(`Cannot read ${path}: pdftotext is not installed. Install poppler-utils (host) or rebuild the Docker sandbox image, or ask the user to send a text version.`);
142
+ }
143
+ if (converted.code !== 0 || !converted.stdout.trim()) {
144
+ throw new Error(`Cannot read .pdf file ${path}: ${converted.stdout.trim() || "conversion produced no text"}. ` +
145
+ `The file may be scanned/image-based — ask the user for a text version or a screenshot.`);
146
+ }
147
+ pdfText = converted.stdout;
148
+ }
149
+ // Get total line count. For non-PDF paths this same command also detects a directory
150
+ // (`cat`/`awk` on a directory would fail), so a directory read is a shallow tree rather
151
+ // than a confusing error — all in one exec to keep the call sequence unchanged.
152
+ let totalFileLines;
153
+ if (isPdf) {
154
+ totalFileLines = countTextLines(pdfText);
155
+ }
156
+ else {
157
+ const countResult = await executor.exec(`if [ -d ${shellEscape(path)} ]; then echo __DIR__; else awk 'END { print NR }' ${shellEscape(path)}; fi`, { signal });
158
+ if (countResult.code !== 0) {
159
+ throw new Error(countResult.stderr || `Failed to read file: ${path}`);
160
+ }
161
+ if (countResult.stdout.trim() === "__DIR__") {
162
+ const listing = await executor.exec(`{ find ${shellEscape(path)} -maxdepth ${DIR_MAX_DEPTH} -type d | sed 's,$,/,'; ` +
163
+ `find ${shellEscape(path)} -maxdepth ${DIR_MAX_DEPTH} ! -type d; }`, { signal });
164
+ if (listing.code !== 0) {
165
+ throw new Error(listing.stderr || `Failed to list directory: ${path}`);
166
+ }
167
+ return {
168
+ content: [
169
+ { type: "text", text: `Directory: ${path}\n\n${renderDirectoryTree(path, listing.stdout)}` },
170
+ ],
171
+ details: undefined,
172
+ };
173
+ }
174
+ totalFileLines = Number.parseInt(countResult.stdout.trim(), 10);
96
175
  }
97
- const totalFileLines = Number.parseInt(countResult.stdout.trim(), 10);
98
176
  // Apply offset if specified (1-indexed)
99
177
  const startLine = offset ? Math.max(1, offset) : 1;
100
178
  const startLineDisplay = startLine;
101
179
  // Check if offset is out of bounds
102
180
  if ((totalFileLines === 0 && offset !== undefined && startLine > 1) ||
103
181
  (totalFileLines > 0 && startLine > totalFileLines)) {
104
- throw new Error(`Offset ${offset} is beyond end of file (${totalFileLines} lines total)`);
182
+ const guidance = totalFileLines > 0
183
+ ? `Use offset=${totalFileLines} to read the last line, or omit offset to read from the start.`
184
+ : "The file is empty; omit offset.";
185
+ throw new Error(`Offset ${offset} is beyond end of file (${totalFileLines} lines total). ${guidance}`);
105
186
  }
106
- // Read content with offset
107
- let cmd;
108
- if (startLine === 1) {
109
- cmd = `cat ${shellEscape(path)}`;
187
+ // Read content from the offset. PDF text is already in memory; files stream from disk.
188
+ let selectedContent;
189
+ if (isPdf) {
190
+ selectedContent =
191
+ startLine === 1
192
+ ? pdfText
193
+ : pdfText
194
+ .split("\n")
195
+ .slice(startLine - 1)
196
+ .join("\n");
110
197
  }
111
198
  else {
112
- cmd = `tail -n +${startLine} ${shellEscape(path)}`;
113
- }
114
- const result = await executor.exec(cmd, { signal });
115
- if (result.code !== 0) {
116
- throw new Error(result.stderr || `Failed to read file: ${path}`);
199
+ const cmd = startLine === 1 ? `cat ${shellEscape(path)}` : `tail -n +${startLine} ${shellEscape(path)}`;
200
+ const result = await executor.exec(cmd, { signal });
201
+ if (result.code !== 0) {
202
+ throw new Error(result.stderr || `Failed to read file: ${path}`);
203
+ }
204
+ selectedContent = result.stdout;
117
205
  }
118
- let selectedContent = result.stdout;
119
206
  let userLimitedLines;
120
207
  // Apply user limit if specified
121
208
  if (limit !== undefined) {
@@ -1,5 +1,6 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import type { Api, Model } from "@earendil-works/pi-ai";
3
+ import type { ChannelJobManager } from "../agent/job-manager.js";
3
4
  import type { MemoryCandidateStore } from "../memory/candidates.js";
4
5
  import type { Executor } from "../sandbox.js";
5
6
  import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
@@ -24,12 +25,17 @@ export interface ToolBuildContext {
24
25
  workspacePath: string;
25
26
  /** Main set: `toolsConfig.tools.web`; sub-agent set: the sub-agent's own webConfig. */
26
27
  webConfig?: PipiclawWebToolsConfig;
27
- /** Present only on the main path; gates session_search / memory_save / skills. */
28
+ /** Present only on the main path; gates session_search / memory_manage / skills. */
28
29
  toolsConfig?: PipiclawToolsConfig;
29
30
  /** Sub-agent set passes its per-invocation bash timeout; the main set relies on the built-in default. */
30
31
  bashDefaultTimeoutSeconds?: number;
31
32
  /** Gates the bash tool's rtk command optimizer (`tools.rtk.enabled`). Threaded to both sets. */
32
33
  rtkEnabled?: boolean;
34
+ /**
35
+ * Present only on the main path when `tools.jobs.enabled` is on. Enables bash `async` and the
36
+ * `job` tool. The sub-agent set never supplies it, so sub-agents get neither.
37
+ */
38
+ jobManager?: ChannelJobManager;
33
39
  getCurrentModel?: () => Model<Api>;
34
40
  getAvailableModels?: () => Model<Api>[];
35
41
  resolveApiKey?: (model: Model<Api>) => Promise<string>;
@@ -1,11 +1,13 @@
1
1
  import { createBashTool } from "./bash.js";
2
2
  import { createEditTool } from "./edit.js";
3
- import { createMemorySaveTool } from "./memory-save.js";
3
+ import { createEventManageTool } from "./event-manage.js";
4
+ import { createGrepTool } from "./grep.js";
5
+ import { createJobTool } from "./job.js";
6
+ import { createMemoryManageTool } from "./memory-manage.js";
4
7
  import { createReadTool } from "./read.js";
5
8
  import { createSessionSearchTool } from "./session-search.js";
6
- import { createSkillListTool } from "./skill-list.js";
7
9
  import { createSkillManageTool } from "./skill-manage.js";
8
- import { createSkillViewTool } from "./skill-view.js";
10
+ import { createTaskManageTool } from "./task-manage.js";
9
11
  import { createWebFetchTool } from "./web-fetch.js";
10
12
  import { createWebSearchTool } from "./web-search.js";
11
13
  import { createWriteTool } from "./write.js";
@@ -45,6 +47,8 @@ export const TOOL_REGISTRY = [
45
47
  create: (ctx) => createBashTool(ctx.executor, {
46
48
  ...fileToolOptions(ctx),
47
49
  rtkEnabled: ctx.rtkEnabled === true,
50
+ interceptorEnabled: ctx.toolsConfig?.tools.bashInterceptor.enabled === true,
51
+ ...(ctx.jobManager ? { jobManager: ctx.jobManager } : {}),
48
52
  ...(ctx.bashDefaultTimeoutSeconds !== undefined
49
53
  ? { defaultTimeoutSeconds: ctx.bashDefaultTimeoutSeconds }
50
54
  : {}),
@@ -56,6 +60,13 @@ export const TOOL_REGISTRY = [
56
60
  availableToSubagents: true,
57
61
  create: (ctx) => createEditTool(ctx.executor, fileToolOptions(ctx)),
58
62
  },
63
+ {
64
+ name: "grep",
65
+ promptHint: "Search file contents with a regex; grouped, paginated, token-bounded — prefer over bash grep",
66
+ availableToSubagents: true,
67
+ enabledBy: (ctx) => ctx.toolsConfig?.tools.grep.enabled !== false,
68
+ create: (ctx) => createGrepTool(ctx.executor, fileToolOptions(ctx)),
69
+ },
59
70
  {
60
71
  name: "write",
61
72
  promptHint: "Create or overwrite files when needed",
@@ -84,6 +95,7 @@ export const TOOL_REGISTRY = [
84
95
  securityConfig: ctx.securityConfig,
85
96
  workspaceDir: ctx.workspaceDir,
86
97
  channelId: ctx.channelId,
98
+ channelDir: ctx.channelDir,
87
99
  }),
88
100
  },
89
101
  {
@@ -100,36 +112,61 @@ export const TOOL_REGISTRY = [
100
112
  }),
101
113
  },
102
114
  {
103
- name: "memory_save",
104
- promptHint: "Save a durable fact to this channel's long-term memory immediately when the user asks",
115
+ name: "memory_manage",
116
+ promptHint: "Save a durable fact, search stored memory on demand, or forget an entry — when the user asks",
105
117
  availableToSubagents: false,
106
118
  enabledBy: (ctx) => ctx.toolsConfig?.tools.memory.save.enabled !== false,
107
- create: (ctx) => createMemorySaveTool({
119
+ create: (ctx) => createMemoryManageTool({
108
120
  channelId: ctx.channelId,
109
121
  channelDir: ctx.channelDir,
122
+ workspaceDir: ctx.workspaceDir,
110
123
  memoryCandidateStore: req(ctx.memoryCandidateStore, "memoryCandidateStore"),
124
+ getCurrentModel: req(ctx.getCurrentModel, "getCurrentModel"),
125
+ resolveApiKey: req(ctx.resolveApiKey, "resolveApiKey"),
111
126
  }),
112
127
  },
113
128
  {
114
- name: "skill_list",
115
- promptHint: "List workspace-level procedural memory in skills/",
129
+ name: "skill_manage",
130
+ promptHint: "List, view, create, or maintain workspace-level procedural memory in skills/",
116
131
  availableToSubagents: false,
117
132
  enabledBy: (ctx) => ctx.toolsConfig?.tools.skills.manage.enabled !== false,
118
- create: (ctx) => createSkillListTool({ workspaceDir: ctx.workspaceDir, workspacePath: ctx.workspacePath }),
133
+ create: (ctx) => createSkillManageTool({ workspaceDir: ctx.workspaceDir, workspacePath: ctx.workspacePath }),
119
134
  },
120
135
  {
121
- name: "skill_view",
122
- promptHint: "Inspect a workspace-level skill's contents",
136
+ name: "event_manage",
137
+ promptHint: "Schedule your own follow-ups: create/update/delete one-shot check-ins and periodic cadences for this channel. " +
138
+ "Name task-owned events `task.<channelId>.<taskId>.<use>` (e.g. .checkin, .schedule) so they clean up together. " +
139
+ "Keep a task's `wake` and its .checkin one-shot in sync — move both, clear both. " +
140
+ "No immediate events; periodic no more often than every 30 min (or 5 min when it carries a preAction gate).",
123
141
  availableToSubagents: false,
124
- enabledBy: (ctx) => ctx.toolsConfig?.tools.skills.manage.enabled !== false,
125
- create: (ctx) => createSkillViewTool({ workspaceDir: ctx.workspaceDir, workspacePath: ctx.workspacePath }),
142
+ enabledBy: (ctx) => ctx.toolsConfig?.tools.events.enabled !== false,
143
+ create: (ctx) => createEventManageTool({
144
+ workspaceDir: ctx.workspaceDir,
145
+ workspacePath: ctx.workspacePath,
146
+ channelId: ctx.channelId,
147
+ commandGuardConfig: ctx.securityConfig.commandGuard,
148
+ }),
126
149
  },
127
150
  {
128
- name: "skill_manage",
129
- promptHint: "Create or maintain workspace-level procedural memory in skills/",
151
+ name: "task_manage",
152
+ promptHint: "Update the task ledger: set a task's status/wake/recurrence, close a task out (archives one-shot tasks and " +
153
+ "cleans up its residual events), or list active tasks. Write the task body with write/edit; this owns the frontmatter.",
130
154
  availableToSubagents: false,
131
- enabledBy: (ctx) => ctx.toolsConfig?.tools.skills.manage.enabled !== false,
132
- create: (ctx) => createSkillManageTool({ workspaceDir: ctx.workspaceDir, workspacePath: ctx.workspacePath }),
155
+ enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
156
+ create: (ctx) => createTaskManageTool({
157
+ workspaceDir: ctx.workspaceDir,
158
+ workspacePath: ctx.workspacePath,
159
+ channelDir: ctx.channelDir,
160
+ channelId: ctx.channelId,
161
+ }),
162
+ },
163
+ {
164
+ name: "job",
165
+ promptHint: "Inspect/poll/cancel background bash jobs started with bash async:true",
166
+ availableToSubagents: false,
167
+ // Present only when a job manager was supplied (tools.jobs.enabled on the main path).
168
+ enabledBy: (ctx) => ctx.jobManager !== undefined,
169
+ create: (ctx) => createJobTool({ jobManager: req(ctx.jobManager, "jobManager") }),
133
170
  },
134
171
  ];
135
172
  /** Prompt hint for the `subagent` tool, which is registered outside TOOL_REGISTRY. */
@@ -43,11 +43,14 @@ export function createSessionSearchTool(options) {
43
43
  model,
44
44
  resolveApiKey: options.resolveApiKey,
45
45
  });
46
+ const text = response.results.length === 0
47
+ ? `${JSON.stringify(response)}\n\nNo matches in cold transcript storage. Try a broader query, drop roleFilter, or read the distilled memory directly (MEMORY.md / HISTORY.md in this channel).`
48
+ : JSON.stringify(response);
46
49
  return {
47
50
  content: [
48
51
  {
49
52
  type: "text",
50
- text: JSON.stringify(response),
53
+ text,
51
54
  },
52
55
  ],
53
56
  details: {
@@ -2,16 +2,16 @@ import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import { Type } from "typebox";
3
3
  declare const skillManageSchema: Type.TObject<{
4
4
  label: Type.TString;
5
- action: Type.TUnion<[Type.TLiteral<"create">, Type.TLiteral<"patch">, Type.TLiteral<"write_file">]>;
6
- name: Type.TString;
5
+ action: Type.TUnion<[Type.TLiteral<"list">, Type.TLiteral<"view">, Type.TLiteral<"create">, Type.TLiteral<"patch">, Type.TLiteral<"write_file">]>;
6
+ name: Type.TOptional<Type.TString>;
7
7
  content: Type.TOptional<Type.TString>;
8
8
  filePath: Type.TOptional<Type.TString>;
9
9
  find: Type.TOptional<Type.TString>;
10
10
  replace: Type.TOptional<Type.TString>;
11
11
  }>;
12
- export type SkillManageAction = "create" | "patch" | "write_file";
12
+ type SkillWriteAction = "create" | "patch" | "write_file";
13
13
  export interface SkillManageResult {
14
- action: SkillManageAction;
14
+ action: SkillWriteAction;
15
15
  name: string;
16
16
  path: string;
17
17
  bytesWritten: number;
@@ -19,17 +19,24 @@ export interface SkillManageResult {
19
19
  notice: string;
20
20
  }
21
21
  export interface SkillManageRequest {
22
- action: SkillManageAction;
22
+ action: SkillWriteAction;
23
23
  name: string;
24
24
  content?: string;
25
25
  filePath?: string;
26
26
  find?: string;
27
27
  replace?: string;
28
28
  }
29
+ export interface WorkspaceSkillSummary {
30
+ name: string;
31
+ description: string;
32
+ path: string;
33
+ warning?: string;
34
+ }
29
35
  export interface SkillManageToolOptions {
30
36
  workspaceDir: string;
31
37
  workspacePath: string;
32
38
  }
39
+ export declare function listWorkspaceSkills(options: SkillManageToolOptions): Promise<WorkspaceSkillSummary[]>;
33
40
  export declare function manageWorkspaceSkill(options: SkillManageToolOptions, request: SkillManageRequest): Promise<SkillManageResult>;
34
41
  export declare function createSkillManageTool(options: SkillManageToolOptions): AgentTool<typeof skillManageSchema>;
35
42
  export {};