@oyasmi/pipiclaw 0.9.1 → 0.9.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/channel-runner.d.ts +15 -1
- package/dist/agent/channel-runner.js +76 -24
- package/dist/agent/effect-ledger.js +9 -2
- package/dist/agent/job-manager.d.ts +4 -0
- package/dist/agent/job-manager.js +17 -2
- package/dist/agent/prompt/manifest.d.ts +1 -1
- package/dist/agent/prompt/manifest.js +1 -1
- package/dist/agent/prompt/sections.js +8 -5
- package/dist/agent/session-events.d.ts +2 -0
- package/dist/agent/session-events.js +29 -14
- package/dist/agent/turn-recovery.js +2 -2
- package/dist/agent/type-guards.js +5 -1
- package/dist/agent/workspace-resources.d.ts +2 -2
- package/dist/agent/workspace-resources.js +41 -3
- package/dist/executor.d.ts +14 -0
- package/dist/executor.js +96 -24
- package/dist/file-store.d.ts +96 -0
- package/dist/file-store.js +189 -0
- package/dist/memory/consolidation.js +2 -26
- package/dist/memory/files.js +7 -7
- package/dist/memory/maintenance-jobs.js +2 -34
- package/dist/memory/maintenance-state.js +2 -1
- package/dist/memory/recall.d.ts +10 -0
- package/dist/memory/recall.js +15 -7
- package/dist/memory/session-search.js +6 -22
- package/dist/memory/transcript.d.ts +10 -0
- package/dist/memory/transcript.js +39 -0
- package/dist/playbooks/agent-delegation.md +7 -5
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.d.ts +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/event-scheduling.md +2 -0
- package/dist/playbooks/memory-and-learning.md +11 -11
- package/dist/playbooks/runtime-orientation.md +3 -3
- package/dist/playbooks/task-driving.md +7 -7
- package/dist/playbooks/task-planning.md +5 -5
- package/dist/runtime/app-home.js +1 -1
- package/dist/runtime/bootstrap.js +10 -0
- package/dist/runtime/dingtalk.js +3 -2
- package/dist/runtime/durable-dispatch.d.ts +26 -1
- package/dist/runtime/durable-dispatch.js +51 -5
- package/dist/runtime/event-commands.js +7 -16
- package/dist/runtime/events.d.ts +4 -2
- package/dist/runtime/events.js +15 -20
- package/dist/runtime/subagent-commands.js +1 -1
- package/dist/runtime/task-commands.d.ts +1 -1
- package/dist/runtime/task-commands.js +17 -12
- package/dist/runtime/task-driver.js +2 -2
- package/dist/runtime/task-wake.d.ts +2 -2
- package/dist/runtime/task-wake.js +2 -2
- package/dist/security/block-message.d.ts +11 -0
- package/dist/security/block-message.js +12 -0
- package/dist/security/path-guard-check.d.ts +13 -0
- package/dist/security/path-guard-check.js +39 -0
- package/dist/security/path-guard.js +32 -14
- package/dist/settings.js +3 -2
- package/dist/shared/atomic-file.d.ts +17 -1
- package/dist/shared/atomic-file.js +50 -3
- package/dist/shared/duration.d.ts +2 -0
- package/dist/shared/duration.js +7 -0
- package/dist/shared/safe-id.d.ts +19 -0
- package/dist/shared/safe-id.js +24 -0
- package/dist/shared/text-utils.d.ts +1 -1
- package/dist/shared/text-utils.js +3 -8
- package/dist/shared/type-guards.d.ts +2 -0
- package/dist/shared/type-guards.js +4 -0
- package/dist/subagents/discovery.d.ts +44 -17
- package/dist/subagents/discovery.js +82 -111
- package/dist/subagents/external/claude-code.js +1 -3
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/run.d.ts +6 -0
- package/dist/subagents/external/run.js +122 -58
- package/dist/subagents/external/settlement.d.ts +3 -0
- package/dist/subagents/external/settlement.js +19 -5
- package/dist/subagents/format.d.ts +3 -2
- package/dist/subagents/format.js +3 -7
- package/dist/subagents/runs.d.ts +45 -9
- package/dist/subagents/runs.js +184 -64
- package/dist/subagents/tool.d.ts +35 -24
- package/dist/subagents/tool.js +631 -577
- package/dist/subagents/verification-outcome.js +1 -1
- package/dist/subagents/workspace-lease.js +1 -1
- package/dist/tasks/artifact-subject.d.ts +30 -4
- package/dist/tasks/artifact-subject.js +257 -25
- package/dist/tasks/control.js +7 -9
- package/dist/tasks/ledger.d.ts +2 -2
- package/dist/tasks/ledger.js +3 -7
- package/dist/tasks/transitions.d.ts +5 -1
- package/dist/tasks/transitions.js +2 -2
- package/dist/tasks/verification.d.ts +24 -2
- package/dist/tasks/verification.js +113 -21
- package/dist/tools/bash.d.ts +0 -1
- package/dist/tools/bash.js +45 -40
- package/dist/tools/config.d.ts +6 -1
- package/dist/tools/config.js +9 -0
- package/dist/tools/edit.d.ts +2 -3
- package/dist/tools/edit.js +274 -86
- package/dist/tools/event-manage.d.ts +13 -7
- package/dist/tools/event-manage.js +52 -14
- package/dist/tools/glob-match.d.ts +11 -0
- package/dist/tools/glob-match.js +75 -0
- package/dist/tools/glob.d.ts +15 -0
- package/dist/tools/glob.js +113 -0
- package/dist/tools/grep.d.ts +0 -1
- package/dist/tools/grep.js +57 -42
- package/dist/tools/ignore-dirs.d.ts +6 -0
- package/dist/tools/ignore-dirs.js +15 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.js +50 -40
- package/dist/tools/job.d.ts +0 -1
- package/dist/tools/job.js +1 -8
- package/dist/tools/line-index.d.ts +16 -0
- package/dist/tools/line-index.js +76 -0
- package/dist/tools/memory-manage.d.ts +20 -8
- package/dist/tools/memory-manage.js +65 -92
- package/dist/tools/presentation.d.ts +2 -0
- package/dist/tools/presentation.js +109 -0
- package/dist/tools/read.d.ts +2 -2
- package/dist/tools/read.js +97 -133
- package/dist/tools/registry.d.ts +4 -1
- package/dist/tools/registry.js +89 -22
- package/dist/tools/send-media.d.ts +6 -6
- package/dist/tools/send-media.js +16 -49
- package/dist/tools/session-search.d.ts +0 -1
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-security.d.ts +0 -2
- package/dist/tools/skill-security.js +0 -24
- package/dist/tools/skill.d.ts +31 -0
- package/dist/tools/skill.js +153 -0
- package/dist/tools/subagent-manage.d.ts +6 -5
- package/dist/tools/subagent-manage.js +60 -60
- package/dist/tools/task-manage/create.d.ts +2 -2
- package/dist/tools/task-manage/create.js +1 -3
- package/dist/tools/task-manage/lifecycle.d.ts +9 -6
- package/dist/tools/task-manage/lifecycle.js +56 -60
- package/dist/tools/task-manage/schema.d.ts +27 -15
- package/dist/tools/task-manage/schema.js +58 -74
- package/dist/tools/task-manage/shared.d.ts +11 -6
- package/dist/tools/task-manage/shared.js +30 -21
- package/dist/tools/task-manage/types.d.ts +14 -15
- package/dist/tools/task-manage/verification.d.ts +5 -5
- package/dist/tools/task-manage/verification.js +18 -15
- package/dist/tools/task-manage.d.ts +8 -11
- package/dist/tools/task-manage.js +63 -50
- package/dist/tools/tool-details.d.ts +17 -1
- package/dist/tools/tool-details.js +24 -0
- package/dist/tools/truncate.d.ts +5 -5
- package/dist/tools/truncate.js +5 -5
- package/dist/tools/web-fetch.d.ts +0 -1
- package/dist/tools/web-fetch.js +0 -1
- package/dist/tools/web-search.d.ts +0 -1
- package/dist/tools/web-search.js +0 -1
- package/dist/tools/write-content.d.ts +3 -3
- package/dist/tools/write-content.js +12 -51
- package/dist/tools/write.d.ts +2 -3
- package/dist/tools/write.js +3 -4
- package/dist/tui/pitui-frontend.js +3 -3
- package/dist/usage/ledger.js +7 -4
- package/examples/sub-agents/README.md +13 -13
- package/examples/sub-agents/documenter.md +2 -1
- package/examples/sub-agents/reviewer.md +2 -0
- package/examples/sub-agents/scout.md +2 -1
- package/examples/sub-agents/verifier.md +6 -4
- package/examples/sub-agents/worker.md +2 -1
- package/package.json +5 -5
- package/dist/tools/skill-manage.d.ts +0 -41
- package/dist/tools/skill-manage.js +0 -232
package/dist/tools/send-media.js
CHANGED
|
@@ -1,35 +1,25 @@
|
|
|
1
1
|
import { basename, extname } from "path";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
4
|
-
import {
|
|
5
|
-
import { guardPath } from "../security/path-guard.js";
|
|
4
|
+
import { checkPathGuard } from "../security/path-guard-check.js";
|
|
6
5
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
7
|
-
import { shellEscape } from "../shared/shell-escape.js";
|
|
8
6
|
import { formatSize, MAX_INLINE_BINARY_BYTES } from "./truncate.js";
|
|
9
7
|
/** Extensions delivered as inline images; everything else goes as a file attachment. */
|
|
10
8
|
const IMAGE_EXTENSIONS = new Set([".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp"]);
|
|
11
9
|
const sendMediaSchema = Type.Object({
|
|
12
|
-
label: Type.String({ description: "Brief description of what you're sending and why (shown to the user)" }),
|
|
13
10
|
path: Type.String({ description: "Path to the local file to send (relative to the workspace, or absolute)" }),
|
|
14
11
|
fileName: Type.Optional(Type.String({ description: "Display name for the recipient; defaults to the file's own name" })),
|
|
15
12
|
});
|
|
16
|
-
function formatPathBlockMessage(resolvedPath, category, reason) {
|
|
17
|
-
const lines = [`Path blocked${category ? ` [${category}]` : ""}`];
|
|
18
|
-
if (reason)
|
|
19
|
-
lines.push(`Reason: ${reason}`);
|
|
20
|
-
if (resolvedPath)
|
|
21
|
-
lines.push(`Resolved path: ${resolvedPath}`);
|
|
22
|
-
return lines.join("\n");
|
|
23
|
-
}
|
|
24
13
|
/**
|
|
25
14
|
* Send a workspace file to the current channel as a native attachment (inline
|
|
26
15
|
* image or downloadable file). Bound to its channel at build time — like `read`
|
|
27
16
|
* and `bash` — so the model never chooses the destination. The file is read
|
|
28
|
-
* through
|
|
29
|
-
*
|
|
30
|
-
* path-guard as the file tools before any bytes leave
|
|
17
|
+
* through `FileStore` (spec 044, D7) rather than shelling out to `base64`, so
|
|
18
|
+
* there is no 4/3 blow-up through a captured stdout string to size against, and
|
|
19
|
+
* every path passes the same path-guard as the file tools before any bytes leave
|
|
20
|
+
* the box.
|
|
31
21
|
*/
|
|
32
|
-
export function createSendMediaTool(
|
|
22
|
+
export function createSendMediaTool(fileStore, options) {
|
|
33
23
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
34
24
|
const securityContext = options.securityContext ?? { agentWorkspaceDir: process.cwd(), projectRoot: process.cwd() };
|
|
35
25
|
return {
|
|
@@ -40,45 +30,22 @@ export function createSendMediaTool(executor, options) {
|
|
|
40
30
|
"Use this to hand the user a generated report, screenshot, chart, or export — not for showing file contents to yourself (use `read` for that).",
|
|
41
31
|
parameters: sendMediaSchema,
|
|
42
32
|
execute: async (_toolCallId, { path, fileName }, signal) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
channelId: options.channelId,
|
|
50
|
-
rawPath: path,
|
|
51
|
-
operation: "read",
|
|
52
|
-
resolvedPath: guardResult.resolvedPath,
|
|
53
|
-
category: guardResult.category,
|
|
54
|
-
reason: guardResult.reason,
|
|
55
|
-
});
|
|
56
|
-
throw new Error(formatPathBlockMessage(guardResult.resolvedPath, guardResult.category, guardResult.reason));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
// Confirm the target is a readable regular file and get its size before base64-encoding
|
|
60
|
-
// it, in one exec. Size matters because base64 inflates to 4/3 and the executor caps
|
|
61
|
-
// captured stdout at 10MB -- above the inline limit, base64 would be silently truncated
|
|
62
|
-
// mid-encoding into a buffer that still decodes: a corrupt file "successfully" sent to
|
|
63
|
-
// the user with no error at all (fix plan §2.3).
|
|
64
|
-
const stat = await executor.exec(`if [ -f ${shellEscape(path)} ]; then wc -c < ${shellEscape(path)}; else echo NO; fi`, { signal });
|
|
65
|
-
const statOutput = stat.stdout.trim();
|
|
66
|
-
if (statOutput === "NO") {
|
|
33
|
+
const target = await checkPathGuard(path, "read", securityConfig, securityContext, {
|
|
34
|
+
tool: "send_media",
|
|
35
|
+
channelId: options.channelId,
|
|
36
|
+
});
|
|
37
|
+
const stat = await fileStore.stat(target);
|
|
38
|
+
if (!stat || !stat.isFile) {
|
|
67
39
|
throw new RecoverableToolError(`Cannot send ${path}: not a regular file (does it exist?).`);
|
|
68
40
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
throw new RecoverableToolError(`Cannot send ${path}: it is ${formatSize(sizeBytes)}, over the ${formatSize(MAX_INLINE_BINARY_BYTES)} send limit. ` +
|
|
41
|
+
if (stat.size > MAX_INLINE_BINARY_BYTES) {
|
|
42
|
+
throw new RecoverableToolError(`Cannot send ${path}: it is ${formatSize(stat.size)}, over the ${formatSize(MAX_INLINE_BINARY_BYTES)} send limit. ` +
|
|
72
43
|
"Compress it first, or provide the path so the user can be told where to find it.");
|
|
73
44
|
}
|
|
74
|
-
|
|
75
|
-
if (encoded.code !== 0) {
|
|
76
|
-
throw new Error(encoded.stderr || `Failed to read file: ${path}`);
|
|
77
|
-
}
|
|
78
|
-
const data = Buffer.from(encoded.stdout.replace(/\s/g, ""), "base64");
|
|
79
|
-
if (data.length === 0) {
|
|
45
|
+
if (stat.size === 0) {
|
|
80
46
|
throw new RecoverableToolError(`Cannot send ${path}: the file is empty.`);
|
|
81
47
|
}
|
|
48
|
+
const { data } = await fileStore.readBytes(target, { signal });
|
|
82
49
|
const name = fileName?.trim() || basename(path);
|
|
83
50
|
const kind = IMAGE_EXTENSIONS.has(extname(name).toLowerCase()) ? "image" : "file";
|
|
84
51
|
const result = await options.mediaSender.sendMedia(options.channelId, { data, fileName: name, kind });
|
|
@@ -3,7 +3,6 @@ import type { Api, Model } from "@earendil-works/pi-ai";
|
|
|
3
3
|
import { Type } from "typebox";
|
|
4
4
|
import type { PipiclawSessionSearchSettings } from "../settings.js";
|
|
5
5
|
declare const sessionSearchSchema: Type.TObject<{
|
|
6
|
-
label: Type.TString;
|
|
7
6
|
query: Type.TOptional<Type.TString>;
|
|
8
7
|
limit: Type.TOptional<Type.TInteger>;
|
|
9
8
|
roleFilter: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"system">, Type.TLiteral<"unknown">]>>>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { searchChannelSessions } from "../memory/session-search.js";
|
|
3
3
|
const sessionSearchSchema = Type.Object({
|
|
4
|
-
label: Type.String({ description: "Brief description of what you're searching for and why (shown to user)" }),
|
|
5
4
|
query: Type.Optional(Type.String({
|
|
6
5
|
description: "Search query for current-channel transcript cold storage. Empty query returns recent entries.",
|
|
7
6
|
})),
|
|
@@ -5,6 +5,4 @@ export interface SkillValidationResult {
|
|
|
5
5
|
export declare function validateSkillName(name: string): SkillValidationResult;
|
|
6
6
|
export declare function validateSkillFrontmatter(content: string, expectedName: string): SkillValidationResult;
|
|
7
7
|
export declare function resolveSkillPath(workspaceDir: string, name: string): string;
|
|
8
|
-
export declare function resolveSkillSupportingFile(skillDir: string, filePath: string): string;
|
|
9
8
|
export declare function scanSkillContent(content: string): SkillValidationResult;
|
|
10
|
-
export declare function validateSkillMarkdown(content: string, expectedName: string): SkillValidationResult;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
const SKILL_NAME_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
3
3
|
const FRONTMATTER_REGEX = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
|
|
4
|
-
const ALLOWED_SUPPORTING_DIRS = new Set(["references", "templates", "scripts", "assets"]);
|
|
5
4
|
const BLOCKED_CONTENT_PATTERNS = [
|
|
6
5
|
{ pattern: /ignore\s+(all\s+)?(previous|prior)\s+instructions/i, message: "contains prompt-injection wording" },
|
|
7
6
|
{
|
|
@@ -78,22 +77,6 @@ export function resolveSkillPath(workspaceDir, name) {
|
|
|
78
77
|
}
|
|
79
78
|
return skillDir;
|
|
80
79
|
}
|
|
81
|
-
export function resolveSkillSupportingFile(skillDir, filePath) {
|
|
82
|
-
const normalized = filePath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
83
|
-
if (!normalized || normalized.includes("..")) {
|
|
84
|
-
throw new Error("Supporting file path must not be empty or contain '..'.");
|
|
85
|
-
}
|
|
86
|
-
const [topLevel] = normalized.split("/");
|
|
87
|
-
if (!topLevel || !ALLOWED_SUPPORTING_DIRS.has(topLevel)) {
|
|
88
|
-
throw new Error("Supporting files must live under references/, templates/, scripts/, or assets/.");
|
|
89
|
-
}
|
|
90
|
-
const base = resolve(skillDir);
|
|
91
|
-
const resolved = resolve(base, normalized);
|
|
92
|
-
if (!resolved.startsWith(`${base}/`)) {
|
|
93
|
-
throw new Error("Supporting file path escaped the skill directory.");
|
|
94
|
-
}
|
|
95
|
-
return resolved;
|
|
96
|
-
}
|
|
97
80
|
export function scanSkillContent(content) {
|
|
98
81
|
for (const { pattern, message } of BLOCKED_CONTENT_PATTERNS) {
|
|
99
82
|
if (pattern.test(content)) {
|
|
@@ -102,10 +85,3 @@ export function scanSkillContent(content) {
|
|
|
102
85
|
}
|
|
103
86
|
return ok();
|
|
104
87
|
}
|
|
105
|
-
export function validateSkillMarkdown(content, expectedName) {
|
|
106
|
-
const frontmatter = validateSkillFrontmatter(content, expectedName);
|
|
107
|
-
if (!frontmatter.ok) {
|
|
108
|
-
return frontmatter;
|
|
109
|
-
}
|
|
110
|
-
return scanSkillContent(content);
|
|
111
|
-
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* `skill` is deliberately read-only. Authoring a workspace skill goes through the generic
|
|
6
|
+
* `write`/`edit` tools writing `workspace/skills/<name>/SKILL.md` directly — a low-frequency path
|
|
7
|
+
* that does not need a dedicated action surface, and one where every write already goes through
|
|
8
|
+
* the same path-guard every other file write does (unlike the old `skill_manage`, which wrote via
|
|
9
|
+
* a hand-rolled path resolver that never consulted the guard at all).
|
|
10
|
+
*/
|
|
11
|
+
declare const skillSchema: Type.TObject<{
|
|
12
|
+
action: Type.TUnion<[Type.TLiteral<"list">, Type.TLiteral<"read">]>;
|
|
13
|
+
name: Type.TOptional<Type.TString>;
|
|
14
|
+
}>;
|
|
15
|
+
export interface WorkspaceSkillSummary {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
path: string;
|
|
19
|
+
warning?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SkillToolOptions {
|
|
22
|
+
workspaceDir: string;
|
|
23
|
+
securityConfig?: SecurityConfig;
|
|
24
|
+
securityContext?: SecurityRuntimeContext;
|
|
25
|
+
channelId?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function listWorkspaceSkills(options: {
|
|
28
|
+
workspaceDir: string;
|
|
29
|
+
}): Promise<WorkspaceSkillSummary[]>;
|
|
30
|
+
export declare function createSkillTool(options: SkillToolOptions): AgentTool<typeof skillSchema>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { Type } from "typebox";
|
|
5
|
+
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
6
|
+
import { checkPathGuard } from "../security/path-guard-check.js";
|
|
7
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
8
|
+
import { resolveSkillPath, scanSkillContent, validateSkillFrontmatter, validateSkillName } from "./skill-security.js";
|
|
9
|
+
import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
|
|
10
|
+
/**
|
|
11
|
+
* `skill` is deliberately read-only. Authoring a workspace skill goes through the generic
|
|
12
|
+
* `write`/`edit` tools writing `workspace/skills/<name>/SKILL.md` directly — a low-frequency path
|
|
13
|
+
* that does not need a dedicated action surface, and one where every write already goes through
|
|
14
|
+
* the same path-guard every other file write does (unlike the old `skill_manage`, which wrote via
|
|
15
|
+
* a hand-rolled path resolver that never consulted the guard at all).
|
|
16
|
+
*/
|
|
17
|
+
const skillSchema = Type.Object({
|
|
18
|
+
action: Type.Union([Type.Literal("list"), Type.Literal("read")], {
|
|
19
|
+
description: '"list" workspace skills, or "read" one skill\'s full SKILL.md content.',
|
|
20
|
+
}),
|
|
21
|
+
name: Type.Optional(Type.String({ description: "Exact workspace skill name from the list (required for read)." })),
|
|
22
|
+
});
|
|
23
|
+
function isNodeError(error) {
|
|
24
|
+
return error instanceof Error && "code" in error;
|
|
25
|
+
}
|
|
26
|
+
function extractDescription(content) {
|
|
27
|
+
const match = content.replace(/\r\n/g, "\n").match(/^---\n([\s\S]*?)\n---/);
|
|
28
|
+
if (!match) {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
for (const line of (match[1] ?? "").split("\n")) {
|
|
32
|
+
const fieldMatch = line.match(/^description:\s*(.*)$/);
|
|
33
|
+
if (fieldMatch) {
|
|
34
|
+
return fieldMatch[1].replace(/^["']|["']$/g, "").trim();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
export async function listWorkspaceSkills(options) {
|
|
40
|
+
const skillsDir = join(options.workspaceDir, "skills");
|
|
41
|
+
let names;
|
|
42
|
+
try {
|
|
43
|
+
names = await readdir(skillsDir);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (isNodeError(error) && error.code === "ENOENT") {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
const summaries = [];
|
|
52
|
+
for (const name of names.sort()) {
|
|
53
|
+
const nameValidation = validateSkillName(name);
|
|
54
|
+
if (!nameValidation.ok) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const skillDir = join(skillsDir, name);
|
|
58
|
+
const skillStats = await stat(skillDir).catch(() => null);
|
|
59
|
+
if (!skillStats?.isDirectory()) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const skillPath = join(skillDir, "SKILL.md");
|
|
63
|
+
let content;
|
|
64
|
+
try {
|
|
65
|
+
const skillFileStats = await stat(skillPath);
|
|
66
|
+
if (!skillFileStats.isFile()) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
content = await readFile(skillPath, "utf-8");
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (isNodeError(error) && error.code === "ENOENT") {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
const validation = validateSkillFrontmatter(content, name);
|
|
78
|
+
const scan = validation.ok ? scanSkillContent(content) : validation;
|
|
79
|
+
summaries.push({
|
|
80
|
+
name,
|
|
81
|
+
description: extractDescription(content),
|
|
82
|
+
path: `${options.workspaceDir}/skills/${name}/SKILL.md`,
|
|
83
|
+
warning: scan.ok ? undefined : scan.error,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return summaries;
|
|
87
|
+
}
|
|
88
|
+
async function readWorkspaceSkill(options, name) {
|
|
89
|
+
const nameValidation = validateSkillName(name);
|
|
90
|
+
if (!nameValidation.ok) {
|
|
91
|
+
throw new RecoverableToolError(nameValidation.error ?? `Invalid skill name "${name}".`);
|
|
92
|
+
}
|
|
93
|
+
const skillDir = resolveSkillPath(options.workspaceDir, name);
|
|
94
|
+
const rawPath = join(skillDir, "SKILL.md");
|
|
95
|
+
if (!existsSync(rawPath)) {
|
|
96
|
+
throw new RecoverableToolError(`Workspace skill "${name}" does not exist. Use action "list" to see what's available.`);
|
|
97
|
+
}
|
|
98
|
+
// Runs the same path-guard every other read goes through: a `SKILL.md` that is itself a
|
|
99
|
+
// symlink pointing outside `workspace/skills/` (planted via `bash ln -s`, not via `name` --
|
|
100
|
+
// `resolveSkillPath` already confines that) is caught here instead of being read verbatim.
|
|
101
|
+
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
102
|
+
const securityContext = options.securityContext ?? {
|
|
103
|
+
agentWorkspaceDir: options.workspaceDir,
|
|
104
|
+
projectRoot: options.workspaceDir,
|
|
105
|
+
};
|
|
106
|
+
const target = await checkPathGuard(rawPath, "read", securityConfig, securityContext, {
|
|
107
|
+
tool: "skill",
|
|
108
|
+
channelId: options.channelId,
|
|
109
|
+
});
|
|
110
|
+
const content = await readFile(target, "utf-8");
|
|
111
|
+
const truncation = truncateHead(content);
|
|
112
|
+
let body = truncation.content;
|
|
113
|
+
if (truncation.truncated) {
|
|
114
|
+
body += `\n\n[Truncated at ${formatSize(DEFAULT_MAX_BYTES)}. Use the read tool on ${target} to page through the rest.]`;
|
|
115
|
+
}
|
|
116
|
+
// Mirrors the framing pi's own skill loader gives a model-invoked skill: the location and the
|
|
117
|
+
// relative-path rule are what let the model correctly `read` a skill's references/templates
|
|
118
|
+
// afterward, and are the whole reason `skill read` is worth more than a plain `read` call.
|
|
119
|
+
const envelope = `<skill name="${name}" location="${target}">\n` +
|
|
120
|
+
`References are relative to ${dirname(target)}.\n\n` +
|
|
121
|
+
`${body}\n` +
|
|
122
|
+
`</skill>`;
|
|
123
|
+
return {
|
|
124
|
+
content: [{ type: "text", text: envelope }],
|
|
125
|
+
details: { action: "read", name, path: target, truncated: truncation.truncated },
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export function createSkillTool(options) {
|
|
129
|
+
return {
|
|
130
|
+
name: "skill",
|
|
131
|
+
label: "skill",
|
|
132
|
+
description: "List or read workspace-level Pipiclaw skills (procedural memory) under workspace/skills/. Read-only: " +
|
|
133
|
+
"to author or update a skill, write workspace/skills/<name>/SKILL.md directly with the write/edit tools " +
|
|
134
|
+
'(frontmatter needs "name" and "description" fields).',
|
|
135
|
+
parameters: skillSchema,
|
|
136
|
+
execute: async (_toolCallId, args) => {
|
|
137
|
+
if (args.action === "list") {
|
|
138
|
+
const skills = await listWorkspaceSkills(options);
|
|
139
|
+
return {
|
|
140
|
+
content: [{ type: "text", text: JSON.stringify({ skills }) }],
|
|
141
|
+
details: { action: "list", count: skills.length },
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
if (args.action !== "read") {
|
|
145
|
+
throw new RecoverableToolError('Unsupported skill action. Use "list" or "read".');
|
|
146
|
+
}
|
|
147
|
+
if (!args.name) {
|
|
148
|
+
throw new RecoverableToolError('Action "read" requires a skill name.');
|
|
149
|
+
}
|
|
150
|
+
return readWorkspaceSkill(options, args.name);
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -5,10 +5,10 @@ import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
|
5
5
|
import type { SecurityConfig } from "../security/types.js";
|
|
6
6
|
import type { PipiclawMemoryRecallSettings } from "../settings.js";
|
|
7
7
|
import { type SubAgentDiscoveryResult } from "../subagents/discovery.js";
|
|
8
|
-
declare const
|
|
9
|
-
|
|
10
|
-
op: Type.TUnion<[Type.TLiteral<"
|
|
11
|
-
runId: Type.
|
|
8
|
+
declare const subagentListSchema: Type.TObject<{}>;
|
|
9
|
+
declare const subagentRunSchema: Type.TObject<{
|
|
10
|
+
op: Type.TUnion<[Type.TLiteral<"show">, Type.TLiteral<"cancel">, Type.TLiteral<"follow_up">]>;
|
|
11
|
+
runId: Type.TString;
|
|
12
12
|
task: Type.TOptional<Type.TString>;
|
|
13
13
|
}>;
|
|
14
14
|
export interface SubAgentManageToolOptions {
|
|
@@ -40,5 +40,6 @@ export interface SubAgentManageToolOptions {
|
|
|
40
40
|
getMemoryRecallSettings?: () => PipiclawMemoryRecallSettings;
|
|
41
41
|
memoryCandidateStore?: MemoryCandidateStore;
|
|
42
42
|
}
|
|
43
|
-
export declare function
|
|
43
|
+
export declare function createSubAgentListTool(options: SubAgentManageToolOptions): AgentTool<typeof subagentListSchema>;
|
|
44
|
+
export declare function createSubAgentRunTool(options: SubAgentManageToolOptions): AgentTool<typeof subagentRunSchema>;
|
|
44
45
|
export {};
|
|
@@ -9,15 +9,16 @@ import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format
|
|
|
9
9
|
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
10
10
|
import { assertVerifyAdmissible, assertWithinProjectBoundary, buildContextualBlocks, buildSubAgentTask, } from "../subagents/tool.js";
|
|
11
11
|
import { acquireWorkspaceLease, formatWorkspaceLeaseConflict, releaseWorkspaceLease, } from "../subagents/workspace-lease.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
// Spec 047, P3: `subagent_list` is zero-argument and shape-independent (like `task_list`); the
|
|
13
|
+
// other three ops all take `runId`, so they stay together in `subagent_run` rather than being
|
|
14
|
+
// split per-verb (`cancel` and `show` have identical parameter sets).
|
|
15
|
+
const subagentListSchema = Type.Object({});
|
|
16
|
+
const subagentRunSchema = Type.Object({
|
|
17
|
+
op: Type.Union([Type.Literal("show"), Type.Literal("cancel"), Type.Literal("follow_up")], {
|
|
18
|
+
description: '"show" full detail for self-diagnosis, "cancel" a running one, or "follow_up" a resumable run.',
|
|
18
19
|
}),
|
|
19
|
-
runId: Type.
|
|
20
|
-
task: Type.Optional(Type.String({ description: "
|
|
20
|
+
runId: Type.String({ description: "The run id to operate on." }),
|
|
21
|
+
task: Type.Optional(Type.String({ description: "New instruction. Required for op=follow_up." })),
|
|
21
22
|
});
|
|
22
23
|
/** Spec 042 D9: cap on `op=list`'s output — see the call site for why running runs are exempt. */
|
|
23
24
|
const LIST_CAP = 50;
|
|
@@ -72,7 +73,7 @@ async function formatRunShow(record) {
|
|
|
72
73
|
lines.push("dispatch warnings:", ...record.invocationWarnings.map((warning) => `- ${warning}`));
|
|
73
74
|
}
|
|
74
75
|
if (record.sessionId)
|
|
75
|
-
lines.push(`sessionId: ${record.sessionId} (usable with
|
|
76
|
+
lines.push(`sessionId: ${record.sessionId} (usable with subagent_run op=follow_up)`);
|
|
76
77
|
if (record.runtime === "external") {
|
|
77
78
|
const stderrTail = await readFile(join(record.artifactDir, "stderr.log"), "utf-8")
|
|
78
79
|
.then((text) => text.slice(-STDERR_TAIL_CHARS))
|
|
@@ -89,43 +90,45 @@ function resumableHarnessOf(record) {
|
|
|
89
90
|
return undefined;
|
|
90
91
|
return record.harness === "codex-cli" || record.harness === "claude-code" ? record.harness : undefined;
|
|
91
92
|
}
|
|
92
|
-
export function
|
|
93
|
+
export function createSubAgentListTool(options) {
|
|
93
94
|
const manager = () => getSubAgentRunManager(options.channelId);
|
|
94
95
|
return {
|
|
95
|
-
name: "
|
|
96
|
-
label: "
|
|
97
|
-
description: "
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
.sort((a, b) => (b.finishedAt ?? b.startedAt) - (a.finishedAt ?? a.startedAt));
|
|
115
|
-
const shownTerminal = terminal.slice(0, Math.max(0, LIST_CAP - running.length));
|
|
116
|
-
const runs = [...running, ...shownTerminal];
|
|
117
|
-
const lines = runs.length === 0 ? ["No delegation runs."] : runs.map(formatRunLine);
|
|
118
|
-
if (runs.length < allRuns.length) {
|
|
119
|
-
lines.push(`… showing ${runs.length} of ${allRuns.length} runs (all running + most recently finished). Ask about a specific runId if you need an older one not shown here.`);
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
content: [{ type: "text", text: lines.join("\n") }],
|
|
123
|
-
details: { op, runs },
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
if (!runId) {
|
|
127
|
-
throw new RecoverableToolError(`${op} requires runId.`);
|
|
96
|
+
name: "subagent_list",
|
|
97
|
+
label: "subagent_list",
|
|
98
|
+
description: "Snapshot of this channel's delegation runs. A finished run wakes this channel itself — never poll here, end the turn.",
|
|
99
|
+
parameters: subagentListSchema,
|
|
100
|
+
execute: async () => {
|
|
101
|
+
// Spec 042 D9: this used to return every run on the channel, unbounded, in both the
|
|
102
|
+
// text and `details.runs` — a long-lived channel could dump thousands of historical
|
|
103
|
+
// records into a single tool result. Running runs (the ones a decision might depend
|
|
104
|
+
// on) are never dropped; only the terminal tail is capped, newest first.
|
|
105
|
+
const allRuns = manager().list();
|
|
106
|
+
const running = allRuns.filter((record) => record.status === "running");
|
|
107
|
+
const terminal = allRuns
|
|
108
|
+
.filter((record) => record.status !== "running")
|
|
109
|
+
.sort((a, b) => (b.finishedAt ?? b.startedAt) - (a.finishedAt ?? a.startedAt));
|
|
110
|
+
const shownTerminal = terminal.slice(0, Math.max(0, LIST_CAP - running.length));
|
|
111
|
+
const runs = [...running, ...shownTerminal];
|
|
112
|
+
const lines = runs.length === 0 ? ["No delegation runs."] : runs.map(formatRunLine);
|
|
113
|
+
if (runs.length < allRuns.length) {
|
|
114
|
+
lines.push(`… showing ${runs.length} of ${allRuns.length} runs (all running + most recently finished). Ask about a specific runId if you need an older one not shown here.`);
|
|
128
115
|
}
|
|
116
|
+
return {
|
|
117
|
+
content: [{ type: "text", text: lines.join("\n") }],
|
|
118
|
+
details: { op: "list", runs },
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
export function createSubAgentRunTool(options) {
|
|
124
|
+
const manager = () => getSubAgentRunManager(options.channelId);
|
|
125
|
+
return {
|
|
126
|
+
name: "subagent_run",
|
|
127
|
+
label: "subagent_run",
|
|
128
|
+
description: "Operate on one delegation run by runId. show: full detail for self-diagnosis. cancel: stop a running one " +
|
|
129
|
+
"(no wake — your decision, not a failure). follow_up: continue a resumable run with a new instruction (new runId).",
|
|
130
|
+
parameters: subagentRunSchema,
|
|
131
|
+
execute: async (_toolCallId, { op, runId, task }) => {
|
|
129
132
|
const resolution = manager().resolveRef(runId);
|
|
130
133
|
if (resolution.kind === "ambiguous") {
|
|
131
134
|
throw new RecoverableToolError(`"${runId}" matches multiple runs on this channel: ${resolution.candidates.map((candidate) => candidate.runId).join(", ")}. Use the full runId.`);
|
|
@@ -195,9 +198,9 @@ export function createSubAgentManageTool(options) {
|
|
|
195
198
|
if (role.shell) {
|
|
196
199
|
throw new RecoverableToolError(`Role "${record.agent}" runs its command through a shell, which has no way to carry a resume session id. Delegate a new run instead, carrying forward whatever context it needs.`);
|
|
197
200
|
}
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
//
|
|
201
|
+
// Verify admission is re-checked against the *current* role config, shared with the initial
|
|
202
|
+
// dispatch. A write-capable verify follow-up takes the same exclusive lease as any writer;
|
|
203
|
+
// `exec` remains barred because it has no verification protocol terminal.
|
|
201
204
|
assertVerifyAdmissible(role, record.purpose, record.workingDirectory);
|
|
202
205
|
// Spec 042 D7: a role hot-edited since the original dispatch (different command, model,
|
|
203
206
|
// or shell mode) would resume the old session under a harness invocation it never wrote.
|
|
@@ -242,22 +245,19 @@ export function createSubAgentManageTool(options) {
|
|
|
242
245
|
// inside `buildContextualBlocks` — optional here so a caller that only ever exercises
|
|
243
246
|
// list/cancel is not forced to wire an LLM-backed dependency it will never use. Absent
|
|
244
247
|
// either, context blocks degrade to none rather than guessing at a model or key.
|
|
245
|
-
const contextualBlocks = options.getCurrentModel && options.resolveApiKey
|
|
246
|
-
? await buildContextualBlocks(task, role, {
|
|
247
|
-
channelDir: options.channelDir,
|
|
248
|
-
workspaceDir: options.workspaceDir,
|
|
249
|
-
runtimeContext: { workspaceDir: options.workspaceDir, channelId: options.channelId },
|
|
250
|
-
getMemoryRecallSettings: options.getMemoryRecallSettings,
|
|
251
|
-
resolveApiKey: options.resolveApiKey,
|
|
252
|
-
memoryCandidateStore: options.memoryCandidateStore,
|
|
253
|
-
}, options.getCurrentModel())
|
|
254
|
-
: [];
|
|
255
|
-
const envelopedTask = buildSubAgentTask(task, role, { workspaceDir: options.workspaceDir, channelId: options.channelId }, contextualBlocks, runContext,
|
|
256
|
-
// returns: "artifact" has no external equivalent (spec 042 D3) and follow_up never
|
|
257
|
-
// requests it — always "text", matching the initial external dispatch.
|
|
258
|
-
"text");
|
|
259
248
|
let launchResult;
|
|
260
249
|
try {
|
|
250
|
+
const contextualBlocks = options.getCurrentModel && options.resolveApiKey
|
|
251
|
+
? await buildContextualBlocks(task, role, {
|
|
252
|
+
channelDir: options.channelDir,
|
|
253
|
+
workspaceDir: options.workspaceDir,
|
|
254
|
+
runtimeContext: { workspaceDir: options.workspaceDir, channelId: options.channelId },
|
|
255
|
+
getMemoryRecallSettings: options.getMemoryRecallSettings,
|
|
256
|
+
resolveApiKey: options.resolveApiKey,
|
|
257
|
+
memoryCandidateStore: options.memoryCandidateStore,
|
|
258
|
+
}, options.getCurrentModel())
|
|
259
|
+
: [];
|
|
260
|
+
const envelopedTask = buildSubAgentTask(task, role, { workspaceDir: options.workspaceDir, channelId: options.channelId }, contextualBlocks, runContext);
|
|
261
261
|
launchResult = await launchExternalRun({
|
|
262
262
|
runId: newRunId,
|
|
263
263
|
channelId: options.channelId,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function createTask(options: TaskManageToolOptions, request:
|
|
1
|
+
import type { TaskCreateRequest, TaskManageResult, TaskManageToolOptions } from "./types.js";
|
|
2
|
+
export declare function createTask(options: TaskManageToolOptions, request: TaskCreateRequest): Promise<TaskManageResult>;
|
|
@@ -6,14 +6,12 @@ import { normalizeTaskId, uncheckedTaskAcceptanceItems } from "../../tasks/ledge
|
|
|
6
6
|
import { RecoverableToolError } from "../tool-details.js";
|
|
7
7
|
import { renderTaskFile, renderTaskSkeleton, tasksDir } from "./shared.js";
|
|
8
8
|
export async function createTask(options, request) {
|
|
9
|
-
if (!request.id)
|
|
10
|
-
throw new RecoverableToolError('action "create" requires an id.');
|
|
11
9
|
const id = normalizeTaskId(request.id);
|
|
12
10
|
const dir = tasksDir(options);
|
|
13
11
|
const taskPath = join(dir, `${id}.md`);
|
|
14
12
|
const archivePath = join(dir, "archive", `${id}.md`);
|
|
15
13
|
if (existsSync(taskPath)) {
|
|
16
|
-
throw new RecoverableToolError(`Task "${id}" already exists; use
|
|
14
|
+
throw new RecoverableToolError(`Task "${id}" already exists; use task_update or edit the body instead.`);
|
|
17
15
|
}
|
|
18
16
|
if (existsSync(archivePath)) {
|
|
19
17
|
throw new RecoverableToolError(`Archived task "${id}" already exists; choose a new id or restore it manually first.`);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { TaskCloseRequest, TaskManageResult, TaskManageToolOptions, TaskUpdateRequest } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* `task_update` merges the old `progress`/`set` actions into one, branching on whether `note` is
|
|
4
|
+
* present (spec 046, D3.2): a note means "checkpoint an open cycle" (active/waiting only, and
|
|
5
|
+
* never repairs a bad control line in the same call); no note means "metadata-only edit" (also
|
|
6
|
+
* allowed on sleeping, and the only path that can repair an unparsable control line).
|
|
7
|
+
*/
|
|
8
|
+
export declare function updateTask(options: TaskManageToolOptions, request: TaskUpdateRequest): Promise<TaskManageResult>;
|
|
9
|
+
export declare function closeTask(options: TaskManageToolOptions, request: TaskCloseRequest): Promise<TaskManageResult>;
|
|
7
10
|
export declare function listTasks(options: TaskManageToolOptions): Promise<TaskManageResult>;
|