@oyasmi/pipiclaw 0.9.1 → 0.9.2-beta.1

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 (149) hide show
  1. package/dist/agent/channel-runner.d.ts +2 -1
  2. package/dist/agent/channel-runner.js +9 -5
  3. package/dist/agent/effect-ledger.js +9 -2
  4. package/dist/agent/job-manager.d.ts +4 -0
  5. package/dist/agent/job-manager.js +17 -2
  6. package/dist/agent/prompt/manifest.d.ts +1 -1
  7. package/dist/agent/prompt/manifest.js +1 -1
  8. package/dist/agent/prompt/sections.js +8 -5
  9. package/dist/agent/session-events.d.ts +2 -0
  10. package/dist/agent/session-events.js +29 -14
  11. package/dist/agent/turn-recovery.js +2 -2
  12. package/dist/agent/type-guards.js +5 -1
  13. package/dist/agent/workspace-resources.d.ts +2 -2
  14. package/dist/agent/workspace-resources.js +41 -3
  15. package/dist/executor.d.ts +14 -0
  16. package/dist/executor.js +96 -24
  17. package/dist/file-store.d.ts +96 -0
  18. package/dist/file-store.js +189 -0
  19. package/dist/memory/consolidation.js +2 -26
  20. package/dist/memory/files.js +7 -7
  21. package/dist/memory/maintenance-jobs.js +2 -34
  22. package/dist/memory/maintenance-state.js +2 -1
  23. package/dist/memory/recall.d.ts +10 -0
  24. package/dist/memory/recall.js +15 -7
  25. package/dist/memory/session-search.js +6 -22
  26. package/dist/memory/transcript.d.ts +10 -0
  27. package/dist/memory/transcript.js +39 -0
  28. package/dist/playbooks/agent-delegation.md +6 -4
  29. package/dist/playbooks/background-jobs.md +1 -1
  30. package/dist/playbooks/catalog.d.ts +1 -1
  31. package/dist/playbooks/catalog.js +1 -1
  32. package/dist/playbooks/event-scheduling.md +2 -0
  33. package/dist/playbooks/memory-and-learning.md +11 -11
  34. package/dist/playbooks/runtime-orientation.md +3 -3
  35. package/dist/playbooks/task-driving.md +5 -5
  36. package/dist/playbooks/task-planning.md +5 -5
  37. package/dist/runtime/app-home.js +1 -1
  38. package/dist/runtime/bootstrap.js +10 -0
  39. package/dist/runtime/dingtalk.js +3 -2
  40. package/dist/runtime/durable-dispatch.d.ts +26 -1
  41. package/dist/runtime/durable-dispatch.js +51 -5
  42. package/dist/runtime/event-commands.js +7 -16
  43. package/dist/runtime/events.d.ts +4 -2
  44. package/dist/runtime/events.js +15 -20
  45. package/dist/runtime/subagent-commands.js +1 -1
  46. package/dist/runtime/task-commands.d.ts +1 -1
  47. package/dist/runtime/task-commands.js +10 -10
  48. package/dist/runtime/task-driver.js +2 -2
  49. package/dist/security/block-message.d.ts +11 -0
  50. package/dist/security/block-message.js +12 -0
  51. package/dist/security/path-guard-check.d.ts +13 -0
  52. package/dist/security/path-guard-check.js +39 -0
  53. package/dist/security/path-guard.js +32 -14
  54. package/dist/settings.js +3 -2
  55. package/dist/shared/atomic-file.d.ts +17 -1
  56. package/dist/shared/atomic-file.js +50 -3
  57. package/dist/shared/duration.d.ts +2 -0
  58. package/dist/shared/duration.js +7 -0
  59. package/dist/shared/safe-id.d.ts +19 -0
  60. package/dist/shared/safe-id.js +24 -0
  61. package/dist/shared/text-utils.d.ts +1 -1
  62. package/dist/shared/text-utils.js +3 -8
  63. package/dist/shared/type-guards.d.ts +2 -0
  64. package/dist/shared/type-guards.js +4 -0
  65. package/dist/subagents/discovery.d.ts +44 -17
  66. package/dist/subagents/discovery.js +82 -111
  67. package/dist/subagents/external/claude-code.js +1 -3
  68. package/dist/subagents/external/harness.d.ts +1 -1
  69. package/dist/subagents/format.d.ts +3 -2
  70. package/dist/subagents/format.js +3 -7
  71. package/dist/subagents/runs.d.ts +1 -1
  72. package/dist/subagents/runs.js +4 -9
  73. package/dist/subagents/tool.d.ts +31 -19
  74. package/dist/subagents/tool.js +582 -561
  75. package/dist/subagents/workspace-lease.js +1 -1
  76. package/dist/tasks/control.js +7 -9
  77. package/dist/tasks/ledger.d.ts +2 -2
  78. package/dist/tasks/ledger.js +3 -7
  79. package/dist/tasks/transitions.d.ts +5 -1
  80. package/dist/tasks/transitions.js +2 -2
  81. package/dist/tools/bash.d.ts +0 -1
  82. package/dist/tools/bash.js +45 -40
  83. package/dist/tools/config.d.ts +6 -1
  84. package/dist/tools/config.js +9 -0
  85. package/dist/tools/edit.d.ts +2 -3
  86. package/dist/tools/edit.js +274 -86
  87. package/dist/tools/event-manage.d.ts +13 -7
  88. package/dist/tools/event-manage.js +52 -14
  89. package/dist/tools/glob-match.d.ts +11 -0
  90. package/dist/tools/glob-match.js +75 -0
  91. package/dist/tools/glob.d.ts +15 -0
  92. package/dist/tools/glob.js +113 -0
  93. package/dist/tools/grep.d.ts +0 -1
  94. package/dist/tools/grep.js +57 -42
  95. package/dist/tools/ignore-dirs.d.ts +6 -0
  96. package/dist/tools/ignore-dirs.js +15 -0
  97. package/dist/tools/index.d.ts +3 -0
  98. package/dist/tools/index.js +50 -40
  99. package/dist/tools/job.d.ts +0 -1
  100. package/dist/tools/job.js +1 -8
  101. package/dist/tools/line-index.d.ts +16 -0
  102. package/dist/tools/line-index.js +76 -0
  103. package/dist/tools/memory-manage.d.ts +20 -8
  104. package/dist/tools/memory-manage.js +65 -92
  105. package/dist/tools/presentation.d.ts +2 -0
  106. package/dist/tools/presentation.js +109 -0
  107. package/dist/tools/read.d.ts +2 -2
  108. package/dist/tools/read.js +97 -133
  109. package/dist/tools/registry.d.ts +4 -1
  110. package/dist/tools/registry.js +89 -22
  111. package/dist/tools/send-media.d.ts +6 -6
  112. package/dist/tools/send-media.js +16 -49
  113. package/dist/tools/session-search.d.ts +0 -1
  114. package/dist/tools/session-search.js +0 -1
  115. package/dist/tools/skill-security.d.ts +0 -2
  116. package/dist/tools/skill-security.js +0 -24
  117. package/dist/tools/skill.d.ts +31 -0
  118. package/dist/tools/skill.js +153 -0
  119. package/dist/tools/subagent-manage.d.ts +6 -5
  120. package/dist/tools/subagent-manage.js +47 -47
  121. package/dist/tools/task-manage/create.d.ts +2 -2
  122. package/dist/tools/task-manage/create.js +1 -3
  123. package/dist/tools/task-manage/lifecycle.d.ts +9 -6
  124. package/dist/tools/task-manage/lifecycle.js +49 -56
  125. package/dist/tools/task-manage/schema.d.ts +27 -15
  126. package/dist/tools/task-manage/schema.js +58 -74
  127. package/dist/tools/task-manage/shared.d.ts +11 -6
  128. package/dist/tools/task-manage/shared.js +30 -21
  129. package/dist/tools/task-manage/types.d.ts +14 -15
  130. package/dist/tools/task-manage/verification.d.ts +4 -4
  131. package/dist/tools/task-manage/verification.js +6 -8
  132. package/dist/tools/task-manage.d.ts +8 -11
  133. package/dist/tools/task-manage.js +63 -50
  134. package/dist/tools/tool-details.d.ts +17 -1
  135. package/dist/tools/tool-details.js +24 -0
  136. package/dist/tools/truncate.d.ts +5 -5
  137. package/dist/tools/truncate.js +5 -5
  138. package/dist/tools/web-fetch.d.ts +0 -1
  139. package/dist/tools/web-fetch.js +0 -1
  140. package/dist/tools/web-search.d.ts +0 -1
  141. package/dist/tools/web-search.js +0 -1
  142. package/dist/tools/write-content.d.ts +3 -3
  143. package/dist/tools/write-content.js +12 -51
  144. package/dist/tools/write.d.ts +2 -3
  145. package/dist/tools/write.js +3 -4
  146. package/dist/usage/ledger.js +7 -4
  147. package/package.json +1 -1
  148. package/dist/tools/skill-manage.d.ts +0 -41
  149. package/dist/tools/skill-manage.js +0 -232
@@ -1,232 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { readdir, readFile, stat } from "node:fs/promises";
3
- import { join } from "node:path";
4
- import { Type } from "typebox";
5
- import { createAtomicTempPath, writeFileAtomically } from "../shared/atomic-file.js";
6
- import { RecoverableToolError } from "../shared/recoverable-error.js";
7
- import { resolveSkillPath, resolveSkillSupportingFile, scanSkillContent, validateSkillFrontmatter, validateSkillMarkdown, validateSkillName, } from "./skill-security.js";
8
- import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
9
- const skillManageSchema = Type.Object({
10
- label: Type.String({ description: "Brief description of the skill action (shown to user)" }),
11
- action: Type.Union([
12
- Type.Literal("list"),
13
- Type.Literal("view"),
14
- Type.Literal("create"),
15
- Type.Literal("patch"),
16
- Type.Literal("write_file"),
17
- ], {
18
- description: '"list" workspace skills, "view" one skill\'s contents, or "create"/"patch"/"write_file" to author them.',
19
- }),
20
- name: Type.Optional(Type.String({ description: "Workspace skill name (required for all actions except list)." })),
21
- content: Type.Optional(Type.String({ description: "Full content for create/write_file." })),
22
- filePath: Type.Optional(Type.String({
23
- description: "Supporting file path inside the skill for view/patch/write_file. Defaults to SKILL.md. Supporting files must be under references/, templates/, scripts/, or assets/.",
24
- })),
25
- find: Type.Optional(Type.String({ description: "Exact text to replace when action is patch." })),
26
- replace: Type.Optional(Type.String({ description: "Replacement text when action is patch." })),
27
- });
28
- function isNodeError(error) {
29
- return error instanceof Error && "code" in error;
30
- }
31
- function extractDescription(content) {
32
- const match = content.replace(/\r\n/g, "\n").match(/^---\n([\s\S]*?)\n---/);
33
- if (!match) {
34
- return "";
35
- }
36
- for (const line of (match[1] ?? "").split("\n")) {
37
- const fieldMatch = line.match(/^description:\s*(.*)$/);
38
- if (fieldMatch) {
39
- return fieldMatch[1].replace(/^["']|["']$/g, "").trim();
40
- }
41
- }
42
- return "";
43
- }
44
- export async function listWorkspaceSkills(options) {
45
- const skillsDir = join(options.workspaceDir, "skills");
46
- let names;
47
- try {
48
- names = await readdir(skillsDir);
49
- }
50
- catch (error) {
51
- if (isNodeError(error) && error.code === "ENOENT") {
52
- return [];
53
- }
54
- throw error;
55
- }
56
- const summaries = [];
57
- for (const name of names.sort()) {
58
- const nameValidation = validateSkillName(name);
59
- if (!nameValidation.ok) {
60
- continue;
61
- }
62
- const skillDir = join(skillsDir, name);
63
- const skillStats = await stat(skillDir).catch(() => null);
64
- if (!skillStats?.isDirectory()) {
65
- continue;
66
- }
67
- const skillPath = join(skillDir, "SKILL.md");
68
- let content;
69
- try {
70
- const skillFileStats = await stat(skillPath);
71
- if (!skillFileStats.isFile()) {
72
- continue;
73
- }
74
- content = await readFile(skillPath, "utf-8");
75
- }
76
- catch (error) {
77
- if (isNodeError(error) && error.code === "ENOENT") {
78
- continue;
79
- }
80
- throw error;
81
- }
82
- const validation = validateSkillFrontmatter(content, name);
83
- summaries.push({
84
- name,
85
- description: extractDescription(content),
86
- path: `${options.workspaceDir}/skills/${name}/SKILL.md`,
87
- warning: validation.ok ? undefined : validation.error,
88
- });
89
- }
90
- return summaries;
91
- }
92
- function parseWriteAction(action) {
93
- if (action === "create" || action === "patch" || action === "write_file") {
94
- return action;
95
- }
96
- throw new RecoverableToolError('Unsupported skill action. Use "list", "view", "create", "patch", or "write_file".');
97
- }
98
- function ensureSkillMarkdownSafe(content, name) {
99
- const validation = validateSkillMarkdown(content, name);
100
- if (!validation.ok) {
101
- throw new RecoverableToolError(validation.error ?? "Skill content failed validation.");
102
- }
103
- }
104
- function ensureSupportingFileSafe(content) {
105
- const validation = scanSkillContent(content);
106
- if (!validation.ok) {
107
- throw new RecoverableToolError(validation.error ?? "Skill content failed validation.");
108
- }
109
- }
110
- function applyUniquePatch(content, find, replace) {
111
- if (!find) {
112
- throw new RecoverableToolError("Patch requires a non-empty find string.");
113
- }
114
- const first = content.indexOf(find);
115
- if (first < 0) {
116
- throw new RecoverableToolError("Patch find string was not found.");
117
- }
118
- if (content.indexOf(find, first + find.length) >= 0) {
119
- throw new RecoverableToolError("Patch find string matched multiple locations.");
120
- }
121
- return `${content.slice(0, first)}${replace}${content.slice(first + find.length)}`;
122
- }
123
- export async function manageWorkspaceSkill(options, request) {
124
- const skillDir = resolveSkillPath(options.workspaceDir, request.name);
125
- const skillPath = join(skillDir, "SKILL.md");
126
- if (request.action === "create") {
127
- if (existsSync(skillPath)) {
128
- throw new RecoverableToolError(`Workspace skill "${request.name}" already exists.`);
129
- }
130
- const content = request.content ?? "";
131
- ensureSkillMarkdownSafe(content, request.name);
132
- await writeFileAtomically(skillPath, content);
133
- return {
134
- action: "create",
135
- name: request.name,
136
- path: skillPath,
137
- bytesWritten: Buffer.byteLength(content, "utf-8"),
138
- requiresResourceRefresh: true,
139
- notice: `已沉淀:创建 workspace skill \`${request.name}\`。`,
140
- };
141
- }
142
- if (!existsSync(skillPath)) {
143
- throw new RecoverableToolError(`Workspace skill "${request.name}" does not exist.`);
144
- }
145
- if (request.action === "write_file") {
146
- if (!request.filePath) {
147
- throw new RecoverableToolError("write_file requires filePath.");
148
- }
149
- const content = request.content ?? "";
150
- const targetPath = resolveSkillSupportingFile(skillDir, request.filePath);
151
- ensureSupportingFileSafe(content);
152
- await writeFileAtomically(targetPath, content);
153
- return {
154
- action: "write_file",
155
- name: request.name,
156
- path: targetPath,
157
- bytesWritten: Buffer.byteLength(content, "utf-8"),
158
- requiresResourceRefresh: true,
159
- notice: `已沉淀:更新 workspace skill \`${request.name}\` 的支持文件。`,
160
- };
161
- }
162
- const targetPath = request.filePath ? resolveSkillSupportingFile(skillDir, request.filePath) : skillPath;
163
- const original = await readFile(targetPath, "utf-8");
164
- const nextContent = applyUniquePatch(original, request.find ?? "", request.replace ?? "");
165
- if (targetPath === skillPath) {
166
- ensureSkillMarkdownSafe(nextContent, request.name);
167
- }
168
- else {
169
- ensureSupportingFileSafe(nextContent);
170
- }
171
- const tempPath = createAtomicTempPath(targetPath);
172
- await writeFileAtomically(targetPath, nextContent, tempPath);
173
- return {
174
- action: "patch",
175
- name: request.name,
176
- path: targetPath,
177
- bytesWritten: Buffer.byteLength(nextContent, "utf-8"),
178
- requiresResourceRefresh: true,
179
- notice: `已沉淀:更新 workspace skill \`${request.name}\`。`,
180
- };
181
- }
182
- async function viewWorkspaceSkill(options, name, filePath) {
183
- const skillDir = resolveSkillPath(options.workspaceDir, name);
184
- const targetPath = filePath ? resolveSkillSupportingFile(skillDir, filePath) : join(skillDir, "SKILL.md");
185
- const content = await readFile(targetPath, "utf-8");
186
- // Cap with the shared truncation limits so a large supporting file cannot flood context.
187
- const truncation = truncateHead(content);
188
- let body = truncation.content;
189
- if (truncation.truncated) {
190
- body += `\n\n[Truncated at ${formatSize(DEFAULT_MAX_BYTES)}. Use the read tool on ${targetPath} to page through the rest.]`;
191
- }
192
- return {
193
- content: [{ type: "text", text: `Skill: ${name}\nPath: ${targetPath}\n\n${body}` }],
194
- details: { action: "view", name, path: targetPath, truncated: truncation.truncated },
195
- };
196
- }
197
- export function createSkillManageTool(options) {
198
- return {
199
- name: "skill_manage",
200
- label: "skill_manage",
201
- description: "Manage workspace-level Pipiclaw skills (procedural memory): list them, view one's contents, or author them " +
202
- "with create/patch/write_file. No channel-scoped skills.",
203
- parameters: skillManageSchema,
204
- execute: async (_toolCallId, args) => {
205
- if (args.action === "list") {
206
- const skills = await listWorkspaceSkills(options);
207
- return {
208
- content: [{ type: "text", text: JSON.stringify({ skills }) }],
209
- details: { action: "list", count: skills.length },
210
- };
211
- }
212
- if (!args.name) {
213
- throw new RecoverableToolError(`Action "${args.action}" requires a skill name.`);
214
- }
215
- if (args.action === "view") {
216
- return viewWorkspaceSkill(options, args.name, args.filePath);
217
- }
218
- const result = await manageWorkspaceSkill(options, {
219
- action: parseWriteAction(args.action),
220
- name: args.name,
221
- content: args.content,
222
- filePath: args.filePath,
223
- find: args.find,
224
- replace: args.replace,
225
- });
226
- return {
227
- content: [{ type: "text", text: JSON.stringify(result) }],
228
- details: { ...result },
229
- };
230
- },
231
- };
232
- }