@oyasmi/pipiclaw 0.7.5 → 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.
- package/README.md +5 -1
- package/dist/agent/job-manager.d.ts +79 -0
- package/dist/agent/job-manager.js +241 -0
- package/dist/agent/prompt-builder.js +13 -4
- package/dist/memory/review-log.d.ts +1 -1
- package/dist/tools/bash.d.ts +12 -0
- package/dist/tools/bash.js +67 -1
- package/dist/tools/config.d.ts +9 -0
- package/dist/tools/config.js +23 -0
- package/dist/tools/edit.js +0 -0
- package/dist/tools/grep.d.ts +19 -0
- package/dist/tools/grep.js +262 -0
- package/dist/tools/index.js +5 -0
- package/dist/tools/job.d.ts +13 -0
- package/dist/tools/job.js +92 -0
- package/dist/tools/memory-manage.d.ts +24 -0
- package/dist/tools/memory-manage.js +150 -0
- package/dist/tools/read.js +103 -16
- package/dist/tools/registry.d.ts +7 -1
- package/dist/tools/registry.js +28 -21
- package/dist/tools/session-search.js +4 -1
- package/dist/tools/skill-manage.d.ts +12 -5
- package/dist/tools/skill-manage.js +113 -15
- package/dist/tools/web-cache.d.ts +11 -0
- package/dist/tools/web-cache.js +62 -0
- package/dist/tools/web-fetch.d.ts +3 -0
- package/dist/tools/web-fetch.js +70 -5
- package/package.json +1 -1
- package/dist/tools/memory-save.d.ts +0 -16
- package/dist/tools/memory-save.js +0 -42
- package/dist/tools/skill-list.d.ts +0 -18
- package/dist/tools/skill-list.js +0 -86
- package/dist/tools/skill-view.d.ts +0 -13
- package/dist/tools/skill-view.js +0 -44
package/dist/tools/web-fetch.js
CHANGED
|
@@ -1,29 +1,94 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { resolveWebFetchRequest } from "../web/config.js";
|
|
3
3
|
import { runWebFetch } from "../web/fetch.js";
|
|
4
|
+
import { formatFetchedText, UNTRUSTED_WEB_CONTENT_BANNER } from "../web/format.js";
|
|
5
|
+
import { readWebCache, webCacheKey, writeWebCache } from "./web-cache.js";
|
|
6
|
+
// Large cap used to fetch the full readable body for caching; the displayed window is bounded by the
|
|
7
|
+
// configured/requested maxChars. Still smaller than maxResponseBytes so a hostile page can't OOM us.
|
|
8
|
+
const FULL_FETCH_MAX_CHARS = 2_000_000;
|
|
4
9
|
const webFetchSchema = Type.Object({
|
|
5
10
|
label: Type.String({ description: "Brief description of what you're fetching and why (shown to user)" }),
|
|
6
11
|
url: Type.String({ description: "HTTP or HTTPS URL to fetch" }),
|
|
7
12
|
extractMode: Type.Optional(Type.Union([Type.Literal("markdown"), Type.Literal("text")], {
|
|
8
13
|
description: "Preferred text extraction format for HTML pages",
|
|
9
14
|
})),
|
|
10
|
-
maxChars: Type.Optional(Type.Number({ description: "Maximum extracted text characters to return" })),
|
|
15
|
+
maxChars: Type.Optional(Type.Number({ description: "Maximum extracted text characters to return per call" })),
|
|
16
|
+
offset: Type.Optional(Type.Integer({
|
|
17
|
+
minimum: 0,
|
|
18
|
+
description: "Character offset into the page body to start from. Use the offset the previous call reported to page through a long page — it is served from cache with no refetch.",
|
|
19
|
+
})),
|
|
11
20
|
});
|
|
21
|
+
/** Strip the untrusted-content banner that runWebFetch prepends, so the cached body is clean. */
|
|
22
|
+
function stripBanner(text) {
|
|
23
|
+
if (text.startsWith(UNTRUSTED_WEB_CONTENT_BANNER)) {
|
|
24
|
+
return text.slice(UNTRUSTED_WEB_CONTENT_BANNER.length).replace(/^\n+/, "");
|
|
25
|
+
}
|
|
26
|
+
return text;
|
|
27
|
+
}
|
|
28
|
+
function windowResult(body, offset, maxChars, url, fromCache) {
|
|
29
|
+
const start = Math.min(offset, body.length);
|
|
30
|
+
const end = Math.min(start + maxChars, body.length);
|
|
31
|
+
const slice = body.slice(start, end);
|
|
32
|
+
let text = formatFetchedText(slice);
|
|
33
|
+
if (end < body.length) {
|
|
34
|
+
const cacheNote = fromCache ? " (served from cache, no refetch)" : "";
|
|
35
|
+
text += `\n\n[Showing chars ${start}-${end} of ${body.length}. Re-call web_fetch with the same url and offset=${end} to continue${cacheNote}.]`;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
content: [{ type: "text", text }],
|
|
39
|
+
details: {
|
|
40
|
+
kind: "web_fetch",
|
|
41
|
+
url,
|
|
42
|
+
offset: start,
|
|
43
|
+
shownChars: slice.length,
|
|
44
|
+
totalChars: body.length,
|
|
45
|
+
fromCache,
|
|
46
|
+
untrusted: true,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
12
50
|
export function createWebFetchTool(options) {
|
|
13
51
|
return {
|
|
14
52
|
name: "web_fetch",
|
|
15
53
|
label: "web_fetch",
|
|
16
|
-
description: "Fetch a public URL and extract readable content. Returns text for HTML/JSON/text pages and image content
|
|
54
|
+
description: "Fetch a public URL and extract readable content. Returns text for HTML/JSON/text pages and image content " +
|
|
55
|
+
"blocks for images. Long pages are cached per channel; page through them with offset (no refetch).",
|
|
17
56
|
parameters: webFetchSchema,
|
|
18
|
-
execute: async (_toolCallId, { url, extractMode, maxChars, }, signal) => {
|
|
57
|
+
execute: async (_toolCallId, { url, extractMode, maxChars, offset, }, signal) => {
|
|
19
58
|
const request = resolveWebFetchRequest(options.webConfig.fetch, url, extractMode, maxChars);
|
|
59
|
+
const displayMaxChars = request.maxChars;
|
|
60
|
+
const startOffset = offset && offset > 0 ? offset : 0;
|
|
61
|
+
// Cache is per-channel; when no channelDir is available (e.g. sub-agent path) fall back to a
|
|
62
|
+
// plain single-shot fetch with the requested maxChars.
|
|
63
|
+
if (!options.channelDir) {
|
|
64
|
+
return runWebFetch({
|
|
65
|
+
webConfig: options.webConfig,
|
|
66
|
+
securityConfig: options.securityConfig,
|
|
67
|
+
workspaceDir: options.workspaceDir,
|
|
68
|
+
channelId: options.channelId,
|
|
69
|
+
}, request, signal);
|
|
70
|
+
}
|
|
71
|
+
const key = webCacheKey(url, request.extractMode);
|
|
72
|
+
const cached = await readWebCache(options.channelDir, key);
|
|
73
|
+
if (cached) {
|
|
74
|
+
return windowResult(cached.body, startOffset, displayMaxChars, url, true);
|
|
75
|
+
}
|
|
76
|
+
// Cache miss: fetch the full readable body once, cache it, then serve the window.
|
|
20
77
|
const result = await runWebFetch({
|
|
21
78
|
webConfig: options.webConfig,
|
|
22
79
|
securityConfig: options.securityConfig,
|
|
23
80
|
workspaceDir: options.workspaceDir,
|
|
24
81
|
channelId: options.channelId,
|
|
25
|
-
}, request, signal);
|
|
26
|
-
|
|
82
|
+
}, { ...request, maxChars: FULL_FETCH_MAX_CHARS }, signal);
|
|
83
|
+
// Images (and any non-text result) are passed through unchanged — nothing to page or cache.
|
|
84
|
+
const hasImage = result.content.some((part) => part.type === "image");
|
|
85
|
+
const textPart = result.content.find((part) => part.type === "text");
|
|
86
|
+
if (hasImage || !textPart || textPart.type !== "text") {
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
const body = stripBanner(textPart.text);
|
|
90
|
+
await writeWebCache(options.channelDir, key, body);
|
|
91
|
+
return windowResult(body, startOffset, displayMaxChars, url, false);
|
|
27
92
|
},
|
|
28
93
|
};
|
|
29
94
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { Type } from "typebox";
|
|
3
|
-
import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
4
|
-
import { type ChannelMemoryQueue } from "../memory/channel-maintenance-queue.js";
|
|
5
|
-
declare const memorySaveSchema: Type.TObject<{
|
|
6
|
-
content: Type.TString;
|
|
7
|
-
kind: Type.TOptional<Type.TUnion<[Type.TLiteral<"preference">, Type.TLiteral<"fact">, Type.TLiteral<"decision">, Type.TLiteral<"constraint">, Type.TLiteral<"open-loop">]>>;
|
|
8
|
-
}>;
|
|
9
|
-
export interface MemorySaveToolOptions {
|
|
10
|
-
channelId: string;
|
|
11
|
-
channelDir: string;
|
|
12
|
-
memoryCandidateStore: MemoryCandidateStore;
|
|
13
|
-
channelMemoryQueue?: ChannelMemoryQueue;
|
|
14
|
-
}
|
|
15
|
-
export declare function createMemorySaveTool(options: MemorySaveToolOptions): AgentTool<typeof memorySaveSchema>;
|
|
16
|
-
export {};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Type } from "typebox";
|
|
2
|
-
import { getDefaultChannelMemoryQueue } from "../memory/channel-maintenance-queue.js";
|
|
3
|
-
import { applyChannelMemoryOps, getChannelMemoryPath } from "../memory/files.js";
|
|
4
|
-
const memorySaveSchema = Type.Object({
|
|
5
|
-
content: Type.String({
|
|
6
|
-
description: "The durable fact to remember, as a single self-contained, keyword-rich sentence. Write it so future keyword search can find it.",
|
|
7
|
-
}),
|
|
8
|
-
kind: Type.Optional(Type.Union([
|
|
9
|
-
Type.Literal("preference"),
|
|
10
|
-
Type.Literal("fact"),
|
|
11
|
-
Type.Literal("decision"),
|
|
12
|
-
Type.Literal("constraint"),
|
|
13
|
-
Type.Literal("open-loop"),
|
|
14
|
-
], { description: "What kind of durable memory this is." })),
|
|
15
|
-
});
|
|
16
|
-
export function createMemorySaveTool(options) {
|
|
17
|
-
const queue = options.channelMemoryQueue ?? getDefaultChannelMemoryQueue();
|
|
18
|
-
return {
|
|
19
|
-
name: "memory_save",
|
|
20
|
-
label: "memory_save",
|
|
21
|
-
description: "Save a durable fact to this channel's long-term MEMORY.md immediately. Use when the user explicitly asks you to remember something (a preference, decision, constraint, or long-running commitment), so it survives restarts and future sessions. Do not use for transient task state — that is captured automatically.",
|
|
22
|
-
parameters: memorySaveSchema,
|
|
23
|
-
execute: async (_toolCallId, { content, kind }) => {
|
|
24
|
-
const trimmed = content.trim();
|
|
25
|
-
if (!trimmed) {
|
|
26
|
-
return {
|
|
27
|
-
content: [{ type: "text", text: "No content provided; nothing was saved." }],
|
|
28
|
-
details: { kind: "memory_save", saved: false },
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
// Serialize through the shared channel memory queue so this never races with
|
|
32
|
-
// background consolidation/maintenance on the same channel's files.
|
|
33
|
-
const result = await queue.run(options.channelId, () => applyChannelMemoryOps(options.channelDir, [{ op: "add", content: trimmed }]));
|
|
34
|
-
// Make the new memory recallable within this same turn.
|
|
35
|
-
options.memoryCandidateStore.invalidate(getChannelMemoryPath(options.channelDir));
|
|
36
|
-
return {
|
|
37
|
-
content: [{ type: "text", text: `Saved to channel memory${kind ? ` (${kind})` : ""}.` }],
|
|
38
|
-
details: { kind: "memory_save", saved: result.added > 0 },
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { Type } from "typebox";
|
|
3
|
-
declare const skillListSchema: Type.TObject<{
|
|
4
|
-
label: Type.TString;
|
|
5
|
-
}>;
|
|
6
|
-
export interface WorkspaceSkillSummary {
|
|
7
|
-
name: string;
|
|
8
|
-
description: string;
|
|
9
|
-
path: string;
|
|
10
|
-
warning?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface SkillListToolOptions {
|
|
13
|
-
workspaceDir: string;
|
|
14
|
-
workspacePath: string;
|
|
15
|
-
}
|
|
16
|
-
export declare function listWorkspaceSkills(options: SkillListToolOptions): Promise<WorkspaceSkillSummary[]>;
|
|
17
|
-
export declare function createSkillListTool(options: SkillListToolOptions): AgentTool<typeof skillListSchema>;
|
|
18
|
-
export {};
|
package/dist/tools/skill-list.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { readdir, readFile, stat } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { Type } from "typebox";
|
|
4
|
-
import { validateSkillFrontmatter, validateSkillName } from "./skill-security.js";
|
|
5
|
-
const skillListSchema = Type.Object({
|
|
6
|
-
label: Type.String({ description: "Brief description of why you're listing workspace skills (shown to user)" }),
|
|
7
|
-
});
|
|
8
|
-
function extractDescription(content) {
|
|
9
|
-
const match = content.replace(/\r\n/g, "\n").match(/^---\n([\s\S]*?)\n---/);
|
|
10
|
-
if (!match) {
|
|
11
|
-
return "";
|
|
12
|
-
}
|
|
13
|
-
for (const line of (match[1] ?? "").split("\n")) {
|
|
14
|
-
const fieldMatch = line.match(/^description:\s*(.*)$/);
|
|
15
|
-
if (fieldMatch) {
|
|
16
|
-
return fieldMatch[1].replace(/^["']|["']$/g, "").trim();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return "";
|
|
20
|
-
}
|
|
21
|
-
function isNodeError(error) {
|
|
22
|
-
return error instanceof Error && "code" in error;
|
|
23
|
-
}
|
|
24
|
-
export async function listWorkspaceSkills(options) {
|
|
25
|
-
const skillsDir = join(options.workspaceDir, "skills");
|
|
26
|
-
let names;
|
|
27
|
-
try {
|
|
28
|
-
names = await readdir(skillsDir);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
if (isNodeError(error) && error.code === "ENOENT") {
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
const summaries = [];
|
|
37
|
-
for (const name of names.sort()) {
|
|
38
|
-
const nameValidation = validateSkillName(name);
|
|
39
|
-
if (!nameValidation.ok) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
const skillDir = join(skillsDir, name);
|
|
43
|
-
const skillStats = await stat(skillDir).catch(() => null);
|
|
44
|
-
if (!skillStats?.isDirectory()) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
const skillPath = join(skillDir, "SKILL.md");
|
|
48
|
-
let content;
|
|
49
|
-
try {
|
|
50
|
-
const skillFileStats = await stat(skillPath);
|
|
51
|
-
if (!skillFileStats.isFile()) {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
content = await readFile(skillPath, "utf-8");
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
if (isNodeError(error) && error.code === "ENOENT") {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
const validation = validateSkillFrontmatter(content, name);
|
|
63
|
-
summaries.push({
|
|
64
|
-
name,
|
|
65
|
-
description: extractDescription(content),
|
|
66
|
-
path: `${options.workspacePath}/skills/${name}/SKILL.md`,
|
|
67
|
-
warning: validation.ok ? undefined : validation.error,
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
return summaries;
|
|
71
|
-
}
|
|
72
|
-
export function createSkillListTool(options) {
|
|
73
|
-
return {
|
|
74
|
-
name: "skill_list",
|
|
75
|
-
label: "skill_list",
|
|
76
|
-
description: "List workspace-level Pipiclaw skills that can be viewed or managed.",
|
|
77
|
-
parameters: skillListSchema,
|
|
78
|
-
execute: async () => {
|
|
79
|
-
const skills = await listWorkspaceSkills(options);
|
|
80
|
-
return {
|
|
81
|
-
content: [{ type: "text", text: JSON.stringify({ skills }) }],
|
|
82
|
-
details: { kind: "skill_list", count: skills.length },
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import { Type } from "typebox";
|
|
3
|
-
declare const skillViewSchema: Type.TObject<{
|
|
4
|
-
label: Type.TString;
|
|
5
|
-
name: Type.TString;
|
|
6
|
-
filePath: Type.TOptional<Type.TString>;
|
|
7
|
-
}>;
|
|
8
|
-
export interface SkillViewToolOptions {
|
|
9
|
-
workspaceDir: string;
|
|
10
|
-
workspacePath: string;
|
|
11
|
-
}
|
|
12
|
-
export declare function createSkillViewTool(options: SkillViewToolOptions): AgentTool<typeof skillViewSchema>;
|
|
13
|
-
export {};
|
package/dist/tools/skill-view.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { Type } from "typebox";
|
|
4
|
-
import { resolveSkillPath, resolveSkillSupportingFile } from "./skill-security.js";
|
|
5
|
-
import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
|
|
6
|
-
const skillViewSchema = Type.Object({
|
|
7
|
-
label: Type.String({ description: "Brief description of why you're viewing this skill (shown to user)" }),
|
|
8
|
-
name: Type.String({ description: "Workspace skill name" }),
|
|
9
|
-
filePath: Type.Optional(Type.String({
|
|
10
|
-
description: "Optional file path inside the skill directory. Defaults to SKILL.md. Supporting files must be under references/, templates/, scripts/, or assets/.",
|
|
11
|
-
})),
|
|
12
|
-
});
|
|
13
|
-
function toWorkspacePath(options, hostPath) {
|
|
14
|
-
if (hostPath.startsWith(options.workspaceDir)) {
|
|
15
|
-
return `${options.workspacePath}${hostPath.slice(options.workspaceDir.length)}`;
|
|
16
|
-
}
|
|
17
|
-
return hostPath;
|
|
18
|
-
}
|
|
19
|
-
export function createSkillViewTool(options) {
|
|
20
|
-
return {
|
|
21
|
-
name: "skill_view",
|
|
22
|
-
label: "skill_view",
|
|
23
|
-
description: "View a workspace-level skill SKILL.md file or an allowed supporting file.",
|
|
24
|
-
parameters: skillViewSchema,
|
|
25
|
-
execute: async (_toolCallId, { name, filePath }) => {
|
|
26
|
-
const skillDir = resolveSkillPath(options.workspaceDir, name);
|
|
27
|
-
const targetPath = filePath ? resolveSkillSupportingFile(skillDir, filePath) : join(skillDir, "SKILL.md");
|
|
28
|
-
const workspacePath = toWorkspacePath(options, targetPath);
|
|
29
|
-
const content = await readFile(targetPath, "utf-8");
|
|
30
|
-
// Return the raw file content (not JSON-escaped) with a small header, and cap it
|
|
31
|
-
// with the shared truncation limits so a large supporting file cannot flood context.
|
|
32
|
-
const truncation = truncateHead(content);
|
|
33
|
-
let body = truncation.content;
|
|
34
|
-
if (truncation.truncated) {
|
|
35
|
-
body += `\n\n[Truncated at ${formatSize(DEFAULT_MAX_BYTES)}. Use the read tool on ${workspacePath} to page through the rest.]`;
|
|
36
|
-
}
|
|
37
|
-
const text = `Skill: ${name}\nPath: ${workspacePath}\n\n${body}`;
|
|
38
|
-
return {
|
|
39
|
-
content: [{ type: "text", text }],
|
|
40
|
-
details: { kind: "skill_view", name, path: workspacePath, truncated: truncation.truncated },
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|