@oyasmi/pipiclaw 0.8.11-beta.4 → 0.8.11

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.
@@ -0,0 +1,29 @@
1
+ /** A catalog entry is a single trigger, not a summary; longer descriptions are clipped in the prompt (spec 026 §10.5). */
2
+ export declare const MAX_PLAYBOOK_DESCRIPTION_CHARS = 100;
3
+ export interface RuntimePlaybookMetadata {
4
+ name: string;
5
+ description: string;
6
+ filename: string;
7
+ path: string;
8
+ /**
9
+ * Listed only when at least one of these tools is registered — any-of, not all-of:
10
+ * a guide spanning user-provided tools can leave this empty so it remains discoverable.
11
+ * (Prompt sections gate the other way: see `requiresAllTools` in agent/prompt/types.ts.)
12
+ */
13
+ requiresAnyTool: string[];
14
+ /** Ascending; ties break on filename. */
15
+ priority: number;
16
+ }
17
+ /** Load the small always-on catalog; playbook bodies remain on disk until the agent reads one. */
18
+ export declare function loadRuntimePlaybookCatalog(directory?: string): RuntimePlaybookMetadata[];
19
+ /**
20
+ * Drop playbooks whose mechanism is unreachable with the current tool set: the task
21
+ * playbooks are pure noise for a runtime with `task_manage` switched off.
22
+ */
23
+ export declare function selectRuntimePlaybooks(catalog: RuntimePlaybookMetadata[], toolNames: readonly string[]): RuntimePlaybookMetadata[];
24
+ /**
25
+ * The always-loaded catalog. It shows the real absolute PLAYBOOKS_DIR once at the
26
+ * top so the model can `read` a guide without guessing the install path (spec 026
27
+ * §3.3, §7.1); each entry is filename + one short trigger, never the body.
28
+ */
29
+ export declare function renderPlaybookCatalog(playbooks: RuntimePlaybookMetadata[]): string;
@@ -0,0 +1,91 @@
1
+ import { readdirSync, readFileSync } from "node:fs";
2
+ import { basename, join } from "node:path";
3
+ import { PLAYBOOKS_DIR } from "../paths.js";
4
+ import { TOOL_NAMES } from "../tools/registry.js";
5
+ const DEFAULT_PRIORITY = 100;
6
+ /** A catalog entry is a single trigger, not a summary; longer descriptions are clipped in the prompt (spec 026 §10.5). */
7
+ export const MAX_PLAYBOOK_DESCRIPTION_CHARS = 100;
8
+ function parseList(value) {
9
+ if (!value)
10
+ return [];
11
+ return value
12
+ .split(",")
13
+ .map((item) => item.trim())
14
+ .filter(Boolean);
15
+ }
16
+ function parseFrontmatter(content, filename) {
17
+ const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(content);
18
+ if (!match)
19
+ throw new Error(`Runtime playbook ${filename} has no YAML frontmatter.`);
20
+ const fields = new Map();
21
+ for (const line of match[1]?.split(/\r?\n/) ?? []) {
22
+ const separator = line.indexOf(":");
23
+ if (separator < 0)
24
+ continue;
25
+ const key = line.slice(0, separator).trim();
26
+ let value = line.slice(separator + 1).trim();
27
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
28
+ value = value.slice(1, -1);
29
+ }
30
+ fields.set(key, value);
31
+ }
32
+ const name = fields.get("name")?.trim();
33
+ const description = fields.get("description")?.trim();
34
+ if (!name || !description) {
35
+ throw new Error(`Runtime playbook ${filename} requires non-empty name and description metadata.`);
36
+ }
37
+ if (`${name}.md` !== filename) {
38
+ throw new Error(`Runtime playbook ${filename} metadata name must be "${basename(filename, ".md")}".`);
39
+ }
40
+ // Authored metadata is validated, never silently ignored: a typo in a tool name would
41
+ // otherwise drop the playbook from the catalog with no signal anywhere.
42
+ const requiresAnyTool = parseList(fields.get("requires-tools"));
43
+ for (const tool of requiresAnyTool) {
44
+ if (!TOOL_NAMES.has(tool)) {
45
+ throw new Error(`Runtime playbook ${filename} requires unknown tool "${tool}".`);
46
+ }
47
+ }
48
+ const priorityField = fields.get("priority");
49
+ const priority = priorityField ? Number(priorityField) : DEFAULT_PRIORITY;
50
+ if (!Number.isFinite(priority)) {
51
+ throw new Error(`Runtime playbook ${filename} has a non-numeric priority "${priorityField}".`);
52
+ }
53
+ return { name, description, requiresAnyTool, priority };
54
+ }
55
+ /** Load the small always-on catalog; playbook bodies remain on disk until the agent reads one. */
56
+ export function loadRuntimePlaybookCatalog(directory = PLAYBOOKS_DIR) {
57
+ return readdirSync(directory)
58
+ .filter((filename) => filename.endsWith(".md"))
59
+ .sort()
60
+ .map((filename) => {
61
+ const path = join(directory, filename);
62
+ return { ...parseFrontmatter(readFileSync(path, "utf-8"), filename), filename, path };
63
+ })
64
+ .sort((a, b) => a.priority - b.priority || a.filename.localeCompare(b.filename));
65
+ }
66
+ /**
67
+ * Drop playbooks whose mechanism is unreachable with the current tool set: the task
68
+ * playbooks are pure noise for a runtime with `task_manage` switched off.
69
+ */
70
+ export function selectRuntimePlaybooks(catalog, toolNames) {
71
+ const tools = new Set(toolNames);
72
+ return catalog.filter((playbook) => {
73
+ if (playbook.requiresAnyTool.length === 0)
74
+ return true;
75
+ return playbook.requiresAnyTool.some((tool) => tools.has(tool));
76
+ });
77
+ }
78
+ /**
79
+ * The always-loaded catalog. It shows the real absolute PLAYBOOKS_DIR once at the
80
+ * top so the model can `read` a guide without guessing the install path (spec 026
81
+ * §3.3, §7.1); each entry is filename + one short trigger, never the body.
82
+ */
83
+ export function renderPlaybookCatalog(playbooks) {
84
+ const entries = playbooks.map((playbook) => {
85
+ const description = playbook.description.length > MAX_PLAYBOOK_DESCRIPTION_CHARS
86
+ ? `${playbook.description.slice(0, MAX_PLAYBOOK_DESCRIPTION_CHARS - 1)}…`
87
+ : playbook.description;
88
+ return `- ${playbook.filename} — ${description}`;
89
+ });
90
+ return ["For Pipiclaw mechanisms, read the matching file with `read` under:", PLAYBOOKS_DIR, "", ...entries].join("\n");
91
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.8.11-beta.4",
3
+ "version": "0.8.11",
4
4
  "description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
5
5
  "type": "module",
6
6
  "bin": {