@oyasmi/pipiclaw 0.9.2-beta.2 → 0.9.2-beta.4
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 +3 -0
- package/dist/agent/channel-runner.d.ts +13 -18
- package/dist/agent/channel-runner.js +44 -90
- package/dist/agent/command-extension.js +1 -1
- package/dist/agent/context-budget.d.ts +8 -0
- package/dist/agent/context-budget.js +10 -2
- package/dist/agent/job-manager.d.ts +1 -1
- package/dist/agent/job-manager.js +9 -1
- package/dist/agent/prompt/builder.d.ts +0 -1
- package/dist/agent/prompt/builder.js +1 -14
- package/dist/agent/prompt/manifest.js +2 -1
- package/dist/agent/prompt/sections.js +1 -1
- package/dist/agent/runner-factory.d.ts +19 -1
- package/dist/agent/runner-factory.js +8 -1
- package/dist/agent/session-events.d.ts +2 -2
- package/dist/agent/turn-prompt.d.ts +35 -0
- package/dist/agent/turn-prompt.js +37 -0
- package/dist/agent/turn-recovery.js +1 -1
- package/dist/agent/turn-state.d.ts +60 -0
- package/dist/agent/turn-state.js +95 -0
- package/dist/agent/types.d.ts +3 -3
- package/dist/{runtime → channel}/channel-context.d.ts +6 -2
- package/dist/{runtime → channel}/channel-context.js +6 -2
- package/dist/{runtime → channel}/channel-event.d.ts +8 -0
- package/dist/channel/channel-paths.d.ts +16 -0
- package/dist/{runtime → channel}/channel-paths.js +20 -0
- package/dist/{agent/commands.d.ts → commands/catalog.d.ts} +16 -1
- package/dist/{agent/commands.js → commands/catalog.js} +30 -0
- package/dist/index.d.ts +1 -1
- package/dist/log.js +14 -5
- package/dist/main.js +29 -0
- package/dist/memory/commands.js +2 -2
- package/dist/memory/maintenance-state.d.ts +8 -0
- package/dist/memory/maintenance-state.js +47 -4
- package/dist/memory/scheduler.d.ts +6 -0
- package/dist/memory/scheduler.js +19 -16
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/runtime/bootstrap.d.ts +2 -2
- package/dist/runtime/bootstrap.js +43 -13
- package/dist/runtime/delivery.d.ts +3 -3
- package/dist/runtime/dingtalk.d.ts +4 -4
- package/dist/runtime/dingtalk.js +2 -2
- package/dist/runtime/durable-dispatch.d.ts +7 -1
- package/dist/runtime/durable-dispatch.js +12 -2
- package/dist/runtime/event-commands.js +2 -2
- package/dist/runtime/events.d.ts +8 -1
- package/dist/runtime/events.js +15 -3
- package/dist/runtime/project-commands.js +2 -2
- package/dist/runtime/skill-commands.d.ts +27 -0
- package/dist/runtime/skill-commands.js +72 -0
- package/dist/runtime/subagent-commands.d.ts +8 -0
- package/dist/runtime/subagent-commands.js +29 -5
- package/dist/runtime/task-commands.js +2 -2
- package/dist/runtime/task-driver.d.ts +5 -1
- package/dist/runtime/task-driver.js +13 -12
- package/dist/runtime/task-migration.js +3 -2
- package/dist/runtime/task-wake.d.ts +6 -1
- package/dist/runtime/task-wake.js +21 -2
- package/dist/settings.d.ts +13 -0
- package/dist/settings.js +78 -0
- package/dist/shared/token-estimate.d.ts +1 -0
- package/dist/shared/token-estimate.js +19 -0
- package/dist/subagents/external/claude-code.js +20 -0
- package/dist/subagents/external/codex-cli.js +33 -0
- package/dist/subagents/external/harness.d.ts +8 -0
- package/dist/subagents/external/progress-tail.d.ts +14 -0
- package/dist/subagents/external/progress-tail.js +84 -0
- package/dist/subagents/external/run.js +1 -0
- package/dist/subagents/external/settlement.d.ts +4 -1
- package/dist/subagents/external/settlement.js +9 -2
- package/dist/subagents/runs.d.ts +45 -4
- package/dist/subagents/runs.js +187 -14
- package/dist/subagents/tool.js +4 -3
- package/dist/tasks/artifact-subject.d.ts +8 -0
- package/dist/tasks/artifact-subject.js +25 -0
- package/dist/tools/glob-match.d.ts +25 -4
- package/dist/tools/glob-match.js +175 -53
- package/dist/tools/glob.js +5 -2
- package/dist/tools/grep.js +4 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/registry.d.ts +1 -1
- package/dist/tools/send-media.d.ts +1 -1
- package/dist/tools/skill.d.ts +15 -0
- package/dist/tools/skill.js +16 -8
- package/dist/tui/app.js +5 -3
- package/dist/tui/commands.d.ts +1 -0
- package/dist/tui/commands.js +3 -1
- package/dist/tui/terminal-context.d.ts +2 -2
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +2 -1
- package/dist/tui/turn-controller.js +2 -1
- package/examples/sub-agents/README.md +3 -2
- package/examples/sub-agents/builder-hard.md +17 -16
- package/examples/sub-agents/builder.md +16 -12
- package/examples/sub-agents/documenter.md +15 -16
- package/examples/sub-agents/explorer.md +16 -17
- package/examples/sub-agents/git-committer.md +18 -28
- package/examples/sub-agents/log-sifter.md +15 -14
- package/examples/sub-agents/planner.md +11 -11
- package/examples/sub-agents/reviewer.md +20 -13
- package/examples/sub-agents/scout.md +14 -11
- package/examples/sub-agents/verifier.md +17 -14
- package/examples/sub-agents/worker.md +18 -12
- package/package.json +1 -1
- package/dist/runtime/channel-paths.d.ts +0 -4
- /package/dist/{runtime → channel}/active-session-store.d.ts +0 -0
- /package/dist/{runtime → channel}/active-session-store.js +0 -0
- /package/dist/{runtime → channel}/channel-event.js +0 -0
- /package/dist/{runtime → channel}/channel-index.d.ts +0 -0
- /package/dist/{runtime → channel}/channel-index.js +0 -0
- /package/dist/{runtime → channel}/project-scope-store.d.ts +0 -0
- /package/dist/{runtime → channel}/project-scope-store.js +0 -0
- /package/dist/{runtime → channel}/store.d.ts +0 -0
- /package/dist/{runtime → channel}/store.js +0 -0
- /package/dist/{agent → commands}/reply-limits.d.ts +0 -0
- /package/dist/{agent → commands}/reply-limits.js +0 -0
package/dist/tools/glob-match.js
CHANGED
|
@@ -1,75 +1,197 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Compile a shell-style glob pattern into a
|
|
2
|
+
* Compile a shell-style glob pattern into a matcher for POSIX-relative file paths.
|
|
3
3
|
*
|
|
4
4
|
* Semantics follow the convention the model already knows from `find`/`fd`/Claude Code's own glob
|
|
5
5
|
* tool: a pattern with no `/` matches the *basename* at any depth (so `*.ts` searches the whole
|
|
6
6
|
* tree, not just its top level); `**` matches any number of path segments, including zero, when it
|
|
7
|
-
* sits between (or at the start/end of) path separators; `{a,b}` is brace-expanded into
|
|
8
|
-
*
|
|
7
|
+
* sits between (or at the start/end of) path separators; `{a,b}` is brace-expanded into
|
|
8
|
+
* alternatives. Matching is always case-sensitive and always against `/`-joined relative paths —
|
|
9
9
|
* callers never see platform separators.
|
|
10
|
+
*
|
|
11
|
+
* ## Why this is not a regular expression
|
|
12
|
+
*
|
|
13
|
+
* The obvious implementation compiles the whole pattern into one `RegExp` — and that regex is a
|
|
14
|
+
* denial-of-service primitive, because the pattern is a model-supplied argument and the matcher
|
|
15
|
+
* runs once per walked file on the event loop. Nested unbounded quantifiers backtrack
|
|
16
|
+
* exponentially on a *near* miss: `**/` repeated ten times took ~2s per path, `{*,*}` repeated
|
|
17
|
+
* five times ~145ms and rising by ~17x per group, and `*a*a*a*a*a*a*a*azzz` — nineteen
|
|
18
|
+
* characters, no `**`, no braces — took **32 seconds** against a sixty-character name. Folding
|
|
19
|
+
* `**/` or capping the pattern length only removes particular spellings; the blow-up belongs to
|
|
20
|
+
* the whole class of "several stars separated by literals", which no length bound can exclude.
|
|
21
|
+
*
|
|
22
|
+
* So the pattern is matched structurally instead: braces expand to a bounded set of variants,
|
|
23
|
+
* each variant is split into path segments, and both the segment sequence and each segment's
|
|
24
|
+
* characters are matched by the classic single-backtrack-point wildcard algorithm. That is
|
|
25
|
+
* O(n·m) in the worst case with no nested quantifiers, so every shape above matches in
|
|
26
|
+
* microseconds and no pattern can stall the walk.
|
|
10
27
|
*/
|
|
28
|
+
/** A pattern longer than this is a mistake or an attack; neither deserves a match attempt. */
|
|
29
|
+
const MAX_PATTERN_LENGTH = 512;
|
|
30
|
+
/** Brace expansion multiplies: `{a,b}` ten times over is 1024 variants of the same walk. */
|
|
31
|
+
const MAX_BRACE_VARIANTS = 64;
|
|
32
|
+
/** A path segment that is exactly `**`: any number of segments, including none. */
|
|
33
|
+
const GLOBSTAR = Symbol("globstar");
|
|
34
|
+
/** `*` inside a segment: any run of characters, not crossing a separator. */
|
|
35
|
+
const STAR = Symbol("star");
|
|
36
|
+
/** `?` inside a segment: exactly one character. */
|
|
37
|
+
const ANY = Symbol("any");
|
|
11
38
|
export function compileGlobPattern(pattern) {
|
|
12
|
-
|
|
13
|
-
|
|
39
|
+
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
40
|
+
throw new Error(`pattern is longer than ${MAX_PATTERN_LENGTH} characters`);
|
|
41
|
+
}
|
|
42
|
+
// The anchoring decision is made on the pattern as written, before expansion: `{src/a,b}`
|
|
43
|
+
// carries a separator and is therefore path-anchored for *both* of its alternatives.
|
|
44
|
+
const matchBasenameOnly = !pattern.includes("/");
|
|
45
|
+
const variants = expandBraces(pattern).map(compileVariant);
|
|
46
|
+
return {
|
|
47
|
+
test(path) {
|
|
48
|
+
const segments = matchBasenameOnly ? [path.slice(path.lastIndexOf("/") + 1)] : path.split("/");
|
|
49
|
+
return variants.some((variant) => matchVariant(variant, segments));
|
|
50
|
+
},
|
|
51
|
+
};
|
|
14
52
|
}
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Expand `{a,b}` alternations into concrete patterns, innermost group last so nesting works.
|
|
55
|
+
*
|
|
56
|
+
* Braces are located by depth-counted scanning rather than the first `}` found, so `{a,{b,c}}`
|
|
57
|
+
* and a comma inside a nested group are read the way the writer meant. An unmatched `{` stays a
|
|
58
|
+
* literal character, as it did before.
|
|
59
|
+
*/
|
|
60
|
+
function expandBraces(pattern) {
|
|
61
|
+
const open = findBraceGroup(pattern);
|
|
62
|
+
if (!open)
|
|
63
|
+
return [pattern];
|
|
64
|
+
const results = [];
|
|
65
|
+
for (const alternative of open.alternatives) {
|
|
66
|
+
for (const expanded of expandBraces(`${open.prefix}${alternative}${open.suffix}`)) {
|
|
67
|
+
results.push(expanded);
|
|
68
|
+
if (results.length > MAX_BRACE_VARIANTS) {
|
|
69
|
+
throw new Error(`brace expansion produces more than ${MAX_BRACE_VARIANTS} patterns`);
|
|
31
70
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return results;
|
|
74
|
+
}
|
|
75
|
+
function findBraceGroup(pattern) {
|
|
76
|
+
const start = pattern.indexOf("{");
|
|
77
|
+
if (start === -1)
|
|
78
|
+
return undefined;
|
|
79
|
+
let depth = 0;
|
|
80
|
+
const alternatives = [];
|
|
81
|
+
let current = "";
|
|
82
|
+
for (let i = start; i < pattern.length; i++) {
|
|
83
|
+
const char = pattern[i];
|
|
84
|
+
if (char === "{") {
|
|
85
|
+
depth++;
|
|
86
|
+
if (depth === 1)
|
|
87
|
+
continue; // the group's own opening brace is not content
|
|
88
|
+
}
|
|
89
|
+
else if (char === "}") {
|
|
90
|
+
depth--;
|
|
91
|
+
if (depth === 0) {
|
|
92
|
+
alternatives.push(current);
|
|
93
|
+
return { prefix: pattern.slice(0, start), alternatives, suffix: pattern.slice(i + 1) };
|
|
37
94
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
95
|
+
}
|
|
96
|
+
else if (char === "," && depth === 1) {
|
|
97
|
+
alternatives.push(current);
|
|
98
|
+
current = "";
|
|
41
99
|
continue;
|
|
42
100
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
101
|
+
current += char;
|
|
102
|
+
}
|
|
103
|
+
return undefined; // unbalanced `{` — leave it as a literal
|
|
104
|
+
}
|
|
105
|
+
function compileVariant(pattern) {
|
|
106
|
+
const rawSegments = pattern.split("/");
|
|
107
|
+
const segments = rawSegments.map((segment) => segment === "**" ? GLOBSTAR : compileSegment(segment));
|
|
108
|
+
const trailingGlobstar = segments.length > 1 && segments[segments.length - 1] === GLOBSTAR;
|
|
109
|
+
return { segments, trailingGlobstar };
|
|
110
|
+
}
|
|
111
|
+
function compileSegment(segment) {
|
|
112
|
+
const tokens = [];
|
|
113
|
+
for (const char of segment) {
|
|
114
|
+
if (char === "*") {
|
|
115
|
+
// Adjacent stars are the same star. A `**` that is not a whole segment (`a**b`) has
|
|
116
|
+
// always meant single-segment `*`, and collapsing keeps that without a second token.
|
|
117
|
+
if (tokens[tokens.length - 1] !== STAR)
|
|
118
|
+
tokens.push(STAR);
|
|
46
119
|
continue;
|
|
47
120
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
121
|
+
tokens.push(char === "?" ? ANY : char);
|
|
122
|
+
}
|
|
123
|
+
return tokens;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Match a segment sequence, with `**` as the only construct that can span segments.
|
|
127
|
+
*
|
|
128
|
+
* The single backtrack point (`starIndex`/`starSegment`) is what keeps this linear-ish: on a
|
|
129
|
+
* mismatch the matcher advances the most recent globstar by one segment instead of exploring
|
|
130
|
+
* every combination of every globstar, which is the search space a regex engine would walk.
|
|
131
|
+
*/
|
|
132
|
+
function matchVariant(variant, path) {
|
|
133
|
+
const { segments, trailingGlobstar } = variant;
|
|
134
|
+
// The trailing `**` is handled after the loop, so drop it here and require a remainder there.
|
|
135
|
+
const patternLength = trailingGlobstar ? segments.length - 1 : segments.length;
|
|
136
|
+
let patternIndex = 0;
|
|
137
|
+
let pathIndex = 0;
|
|
138
|
+
let starIndex = -1;
|
|
139
|
+
let starPathIndex = 0;
|
|
140
|
+
while (pathIndex < path.length) {
|
|
141
|
+
const segment = patternIndex < patternLength ? segments[patternIndex] : undefined;
|
|
142
|
+
// Pattern spent with path left over: a trailing `**` takes the whole remainder.
|
|
143
|
+
if (segment === undefined && trailingGlobstar)
|
|
144
|
+
break;
|
|
145
|
+
if (segment === GLOBSTAR) {
|
|
146
|
+
starIndex = patternIndex;
|
|
147
|
+
starPathIndex = pathIndex;
|
|
148
|
+
patternIndex++;
|
|
51
149
|
continue;
|
|
52
150
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
out += escapeRegExpChar(ch);
|
|
57
|
-
i += 1;
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
const alternatives = pattern
|
|
61
|
-
.slice(i + 1, close)
|
|
62
|
-
.split(",")
|
|
63
|
-
.map((alt) => globToRegExpSource(alt));
|
|
64
|
-
out += `(?:${alternatives.join("|")})`;
|
|
65
|
-
i = close + 1;
|
|
151
|
+
if (segment !== undefined && matchSegment(segment, path[pathIndex])) {
|
|
152
|
+
patternIndex++;
|
|
153
|
+
pathIndex++;
|
|
66
154
|
continue;
|
|
67
155
|
}
|
|
68
|
-
|
|
69
|
-
|
|
156
|
+
if (starIndex === -1)
|
|
157
|
+
return false;
|
|
158
|
+
// Let the last globstar swallow one more segment and retry from just after it.
|
|
159
|
+
starPathIndex++;
|
|
160
|
+
pathIndex = starPathIndex;
|
|
161
|
+
patternIndex = starIndex + 1;
|
|
70
162
|
}
|
|
71
|
-
|
|
163
|
+
while (patternIndex < patternLength && segments[patternIndex] === GLOBSTAR)
|
|
164
|
+
patternIndex++;
|
|
165
|
+
if (patternIndex !== patternLength)
|
|
166
|
+
return false;
|
|
167
|
+
return trailingGlobstar ? pathIndex < path.length : pathIndex === path.length;
|
|
72
168
|
}
|
|
73
|
-
|
|
74
|
-
|
|
169
|
+
/** The same algorithm one level down: `*` is the backtrack point, `?` and literals advance. */
|
|
170
|
+
function matchSegment(tokens, text) {
|
|
171
|
+
let tokenIndex = 0;
|
|
172
|
+
let textIndex = 0;
|
|
173
|
+
let starIndex = -1;
|
|
174
|
+
let starTextIndex = 0;
|
|
175
|
+
while (textIndex < text.length) {
|
|
176
|
+
const token = tokenIndex < tokens.length ? tokens[tokenIndex] : undefined;
|
|
177
|
+
if (token === STAR) {
|
|
178
|
+
starIndex = tokenIndex;
|
|
179
|
+
starTextIndex = textIndex;
|
|
180
|
+
tokenIndex++;
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (token === ANY || (typeof token === "string" && token === text[textIndex])) {
|
|
184
|
+
tokenIndex++;
|
|
185
|
+
textIndex++;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (starIndex === -1)
|
|
189
|
+
return false;
|
|
190
|
+
starTextIndex++;
|
|
191
|
+
textIndex = starTextIndex;
|
|
192
|
+
tokenIndex = starIndex + 1;
|
|
193
|
+
}
|
|
194
|
+
while (tokenIndex < tokens.length && tokens[tokenIndex] === STAR)
|
|
195
|
+
tokenIndex++;
|
|
196
|
+
return tokenIndex === tokens.length;
|
|
75
197
|
}
|
package/dist/tools/glob.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Type } from "typebox";
|
|
|
3
3
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
4
4
|
import { checkPathGuard } from "../security/path-guard-check.js";
|
|
5
5
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
6
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
6
7
|
import { compileGlobPattern } from "./glob-match.js";
|
|
7
8
|
import { IGNORED_DIR_SEGMENTS } from "./ignore-dirs.js";
|
|
8
9
|
import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
|
|
@@ -52,8 +53,10 @@ export function createGlobTool(fileStore, options = {}) {
|
|
|
52
53
|
try {
|
|
53
54
|
matcher = compileGlobPattern(pattern);
|
|
54
55
|
}
|
|
55
|
-
catch {
|
|
56
|
-
|
|
56
|
+
catch (error) {
|
|
57
|
+
// The reason is part of the message: a pattern rejected for complexity is fixed by
|
|
58
|
+
// simplifying it, which "invalid pattern" alone does not tell the model.
|
|
59
|
+
throw new RecoverableToolError(`Invalid glob pattern: ${pattern} (${errorMessage(error)})`);
|
|
57
60
|
}
|
|
58
61
|
const walk = await fileStore.walkFiles(target, {
|
|
59
62
|
maxEntries: MAX_SCAN_ENTRIES,
|
package/dist/tools/grep.js
CHANGED
|
@@ -166,7 +166,10 @@ export function createGrepTool(executor, options = {}) {
|
|
|
166
166
|
flags.push(`--exclude-dir=${segment}`);
|
|
167
167
|
}
|
|
168
168
|
if (glob) {
|
|
169
|
-
|
|
169
|
+
// Model-controlled, so it must be shell-escaped like the pattern and path below -- the
|
|
170
|
+
// executor runs the command via `sh -c`, and an unescaped glob such as `*.ts; rm -rf x`
|
|
171
|
+
// would otherwise run as an extra command instead of matching nothing.
|
|
172
|
+
flags.push(`--include=${shellEscape(glob)}`);
|
|
170
173
|
}
|
|
171
174
|
// `--` terminates flags so a pattern beginning with `-` is not read as one. Bounded via
|
|
172
175
|
// `maxCaptureBytes` (D5.2) rather than a `| head -n` pipe: piping through `head` would
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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 { MediaSender } from "../channel/channel-context.js";
|
|
3
4
|
import type { Executor } from "../executor.js";
|
|
4
5
|
import type { FileStore } from "../file-store.js";
|
|
5
6
|
import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
6
|
-
import type { MediaSender } from "../runtime/channel-context.js";
|
|
7
7
|
import type { ProjectScope } from "../security/project-scope.js";
|
|
8
8
|
import type { SecurityConfig } from "../security/types.js";
|
|
9
9
|
import type { PipiclawMemoryRecallSettings, PipiclawSessionSearchSettings } from "../settings.js";
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { ChannelJobManager } from "../agent/job-manager.js";
|
|
4
|
+
import type { MediaSender } from "../channel/channel-context.js";
|
|
4
5
|
import type { Executor } from "../executor.js";
|
|
5
6
|
import type { FileStore } from "../file-store.js";
|
|
6
7
|
import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
7
|
-
import type { MediaSender } from "../runtime/channel-context.js";
|
|
8
8
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
9
9
|
import type { PipiclawSessionSearchSettings } from "../settings.js";
|
|
10
10
|
import type { PipiclawToolsConfig, PipiclawWebToolsConfig } from "./config.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
+
import type { MediaSender } from "../channel/channel-context.js";
|
|
3
4
|
import type { FileStore } from "../file-store.js";
|
|
4
|
-
import type { MediaSender } from "../runtime/channel-context.js";
|
|
5
5
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
6
6
|
declare const sendMediaSchema: Type.TObject<{
|
|
7
7
|
path: Type.TString;
|
package/dist/tools/skill.d.ts
CHANGED
|
@@ -27,5 +27,20 @@ export interface SkillToolOptions {
|
|
|
27
27
|
export declare function listWorkspaceSkills(options: {
|
|
28
28
|
workspaceDir: string;
|
|
29
29
|
}): Promise<WorkspaceSkillSummary[]>;
|
|
30
|
+
export interface WorkspaceSkillFile {
|
|
31
|
+
name: string;
|
|
32
|
+
/** The guard-resolved path actually opened — never the raw pre-guard path. */
|
|
33
|
+
path: string;
|
|
34
|
+
content: string;
|
|
35
|
+
truncated: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Load one skill's `SKILL.md` bytes through the same path-guard every other file read goes
|
|
39
|
+
* through. Shared by the `skill` tool's `read` action and the `/skills show` runtime command
|
|
40
|
+
* (`src/runtime/skill-commands.ts`) — a `SKILL.md` that is itself a symlink pointing outside
|
|
41
|
+
* `workspace/skills/` (planted via `bash ln -s`, not via `name` -- `resolveSkillPath` already
|
|
42
|
+
* confines that) is caught here in both callers instead of being read verbatim.
|
|
43
|
+
*/
|
|
44
|
+
export declare function loadWorkspaceSkillFile(options: SkillToolOptions, name: string): Promise<WorkspaceSkillFile>;
|
|
30
45
|
export declare function createSkillTool(options: SkillToolOptions): AgentTool<typeof skillSchema>;
|
|
31
46
|
export {};
|
package/dist/tools/skill.js
CHANGED
|
@@ -85,7 +85,14 @@ export async function listWorkspaceSkills(options) {
|
|
|
85
85
|
}
|
|
86
86
|
return summaries;
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Load one skill's `SKILL.md` bytes through the same path-guard every other file read goes
|
|
90
|
+
* through. Shared by the `skill` tool's `read` action and the `/skills show` runtime command
|
|
91
|
+
* (`src/runtime/skill-commands.ts`) — a `SKILL.md` that is itself a symlink pointing outside
|
|
92
|
+
* `workspace/skills/` (planted via `bash ln -s`, not via `name` -- `resolveSkillPath` already
|
|
93
|
+
* confines that) is caught here in both callers instead of being read verbatim.
|
|
94
|
+
*/
|
|
95
|
+
export async function loadWorkspaceSkillFile(options, name) {
|
|
89
96
|
const nameValidation = validateSkillName(name);
|
|
90
97
|
if (!nameValidation.ok) {
|
|
91
98
|
throw new RecoverableToolError(nameValidation.error ?? `Invalid skill name "${name}".`);
|
|
@@ -95,9 +102,6 @@ async function readWorkspaceSkill(options, name) {
|
|
|
95
102
|
if (!existsSync(rawPath)) {
|
|
96
103
|
throw new RecoverableToolError(`Workspace skill "${name}" does not exist. Use action "list" to see what's available.`);
|
|
97
104
|
}
|
|
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
105
|
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
102
106
|
const securityContext = options.securityContext ?? {
|
|
103
107
|
agentWorkspaceDir: options.workspaceDir,
|
|
@@ -113,16 +117,20 @@ async function readWorkspaceSkill(options, name) {
|
|
|
113
117
|
if (truncation.truncated) {
|
|
114
118
|
body += `\n\n[Truncated at ${formatSize(DEFAULT_MAX_BYTES)}. Use the read tool on ${target} to page through the rest.]`;
|
|
115
119
|
}
|
|
120
|
+
return { name, path: target, content: body, truncated: truncation.truncated };
|
|
121
|
+
}
|
|
122
|
+
async function readWorkspaceSkill(options, name) {
|
|
123
|
+
const file = await loadWorkspaceSkillFile(options, name);
|
|
116
124
|
// Mirrors the framing pi's own skill loader gives a model-invoked skill: the location and the
|
|
117
125
|
// relative-path rule are what let the model correctly `read` a skill's references/templates
|
|
118
126
|
// afterward, and are the whole reason `skill read` is worth more than a plain `read` call.
|
|
119
|
-
const envelope = `<skill name="${name}" location="${
|
|
120
|
-
`References are relative to ${dirname(
|
|
121
|
-
`${
|
|
127
|
+
const envelope = `<skill name="${file.name}" location="${file.path}">\n` +
|
|
128
|
+
`References are relative to ${dirname(file.path)}.\n\n` +
|
|
129
|
+
`${file.content}\n` +
|
|
122
130
|
`</skill>`;
|
|
123
131
|
return {
|
|
124
132
|
content: [{ type: "text", text: envelope }],
|
|
125
|
-
details: { action: "read", name, path:
|
|
133
|
+
details: { action: "read", name: file.name, path: file.path, truncated: file.truncated },
|
|
126
134
|
};
|
|
127
135
|
}
|
|
128
136
|
export function createSkillTool(options) {
|
package/dist/tui/app.js
CHANGED
|
@@ -7,18 +7,19 @@
|
|
|
7
7
|
* preparation shares `prepareAppServices` with the DingTalk path.
|
|
8
8
|
*/
|
|
9
9
|
import { userInfo } from "node:os";
|
|
10
|
-
import { renderBuiltInHelp } from "../agent/commands.js";
|
|
11
10
|
import { createRunner } from "../agent/index.js";
|
|
12
11
|
import { channelRunningJobLines } from "../agent/job-manager.js";
|
|
12
|
+
import { ensureChannelDir } from "../channel/channel-paths.js";
|
|
13
|
+
import { ChannelStore } from "../channel/store.js";
|
|
14
|
+
import { renderBuiltInHelp } from "../commands/catalog.js";
|
|
13
15
|
import * as log from "../log.js";
|
|
14
16
|
import { ensureChannelMemoryFilesSync } from "../memory/files.js";
|
|
15
17
|
import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, printBootstrapSummary, readCliVersion, } from "../runtime/app-home.js";
|
|
16
18
|
import { prepareAppServices } from "../runtime/bootstrap.js";
|
|
17
|
-
import { ensureChannelDir } from "../runtime/channel-paths.js";
|
|
18
19
|
import { finalDeliveryOf, progressStyleOf } from "../runtime/dingtalk.js";
|
|
19
20
|
import { handleEventsCommand } from "../runtime/event-commands.js";
|
|
20
21
|
import { handleProjectCommand } from "../runtime/project-commands.js";
|
|
21
|
-
import {
|
|
22
|
+
import { handleSkillsCommand } from "../runtime/skill-commands.js";
|
|
22
23
|
import { handleSubagentsCommand } from "../runtime/subagent-commands.js";
|
|
23
24
|
import { handleTasksCommand } from "../runtime/task-commands.js";
|
|
24
25
|
import { flushSecurityLogs } from "../security/logger.js";
|
|
@@ -141,6 +142,7 @@ export async function runTuiApp(options) {
|
|
|
141
142
|
channelId,
|
|
142
143
|
}),
|
|
143
144
|
runSubagents: (args) => handleSubagentsCommand({ args, channelId, discovery: runner.getSubAgentDiscoverySnapshot() }),
|
|
145
|
+
runSkills: (args) => handleSkillsCommand({ args, workspaceDir: paths.workspaceDir, appHomeDir: paths.appHomeDir, channelId }),
|
|
144
146
|
runProject: (args) => handleProjectCommand({
|
|
145
147
|
args,
|
|
146
148
|
channelId,
|
package/dist/tui/commands.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export interface DispatchDeps {
|
|
|
41
41
|
runTasks(args: string): Promise<string>;
|
|
42
42
|
runSubagents(args: string): Promise<string>;
|
|
43
43
|
runProject(args: string): Promise<string>;
|
|
44
|
+
runSkills(args: string): Promise<string>;
|
|
44
45
|
}
|
|
45
46
|
export declare function dispatch(input: string, deps: DispatchDeps): Promise<DispatchOutcome>;
|
|
46
47
|
/**
|
package/dist/tui/commands.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* depend on whether a turn is running, which only the app knows — so those come
|
|
14
14
|
* back as intents rather than being applied here.
|
|
15
15
|
*/
|
|
16
|
-
import { BUILT_IN_COMMANDS, parseBuiltInCommand, SESSION_COMMANDS } from "../
|
|
16
|
+
import { BUILT_IN_COMMANDS, parseBuiltInCommand, SESSION_COMMANDS } from "../commands/catalog.js";
|
|
17
17
|
export async function dispatch(input, deps) {
|
|
18
18
|
const trimmed = input.trim();
|
|
19
19
|
if (!trimmed)
|
|
@@ -43,6 +43,8 @@ export async function dispatch(input, deps) {
|
|
|
43
43
|
return { kind: "reply", text: await deps.runSubagents(command.args) };
|
|
44
44
|
case "project":
|
|
45
45
|
return { kind: "reply", text: await deps.runProject(command.args) };
|
|
46
|
+
case "skills":
|
|
47
|
+
return { kind: "reply", text: await deps.runSkills(command.args) };
|
|
46
48
|
case "stop":
|
|
47
49
|
return { kind: "stop" };
|
|
48
50
|
case "steer":
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* - `respond` / `respondPlain` archive when `shouldLog` is set;
|
|
10
10
|
* - `replaceMessage` / `deleteMessage` do not archive (they only re-render).
|
|
11
11
|
*/
|
|
12
|
-
import type { ChannelContext, FinalDelivery, ProgressStyle } from "../
|
|
13
|
-
import type { ChannelStore } from "../
|
|
12
|
+
import type { ChannelContext, FinalDelivery, ProgressStyle } from "../channel/channel-context.js";
|
|
13
|
+
import type { ChannelStore } from "../channel/store.js";
|
|
14
14
|
import type { TranscriptRenderer } from "./renderer.js";
|
|
15
15
|
/** The minimal per-turn input the terminal context needs (no DingTalk types). */
|
|
16
16
|
export interface TurnInput {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { MediaSender } from "../channel/channel-context.js";
|
|
1
2
|
import type { BootstrapIO } from "../runtime/app-home.js";
|
|
2
|
-
import type { MediaSender } from "../runtime/channel-context.js";
|
|
3
3
|
/**
|
|
4
4
|
* Terminal implementation of the `MediaSender` port. There is no chat surface to
|
|
5
5
|
* push a file to, and the bytes already came from a local file, so "sending" here
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* unit-tested with fakes and a fake clock. `app.ts` builds the real ones.
|
|
8
8
|
*/
|
|
9
9
|
import type { AgentRunner } from "../agent/types.js";
|
|
10
|
-
import type { ChannelStore } from "../
|
|
10
|
+
import type { ChannelStore } from "../channel/store.js";
|
|
11
11
|
import type { Frontend } from "./renderer.js";
|
|
12
12
|
import { type DeliveryTraits } from "./terminal-context.js";
|
|
13
13
|
export interface TurnControllerDeps {
|
|
@@ -24,6 +24,7 @@ export interface TurnControllerDeps {
|
|
|
24
24
|
runTasks: (args: string) => Promise<string>;
|
|
25
25
|
runSubagents: (args: string) => Promise<string>;
|
|
26
26
|
runProject: (args: string) => Promise<string>;
|
|
27
|
+
runSkills: (args: string) => Promise<string>;
|
|
27
28
|
/** Static bits the status renderer needs alongside the live run state. */
|
|
28
29
|
statusInfo: {
|
|
29
30
|
version: string;
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* Collaborators (runner, frontend, store) are injected so the machine can be
|
|
7
7
|
* unit-tested with fakes and a fake clock. `app.ts` builds the real ones.
|
|
8
8
|
*/
|
|
9
|
-
import { formatBusyCommandList, formatUnknownCommandMessage, isSessionCommandName, slashCommandName, } from "../agent/commands.js";
|
|
10
9
|
import { renderStatus } from "../agent/status-render.js";
|
|
10
|
+
import { formatBusyCommandList, formatUnknownCommandMessage, isSessionCommandName, slashCommandName, } from "../commands/catalog.js";
|
|
11
11
|
import * as log from "../log.js";
|
|
12
12
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
13
13
|
import { errorMessage } from "../shared/text-utils.js";
|
|
@@ -37,6 +37,7 @@ export class TurnController {
|
|
|
37
37
|
runTasks: deps.runTasks,
|
|
38
38
|
runSubagents: deps.runSubagents,
|
|
39
39
|
runProject: deps.runProject,
|
|
40
|
+
runSkills: deps.runSkills,
|
|
40
41
|
renderContext: (args) => this.deps.runner.renderContextReport(args),
|
|
41
42
|
renderStatus: () => renderStatus({
|
|
42
43
|
runner: this.deps.runner,
|
|
@@ -51,9 +51,9 @@ reviewer 发现的问题回流给产出角色;verifier 失败回流给 builder
|
|
|
51
51
|
| `builder` | claude-code | `sonnet` | `write` | medium | 边界清晰、验收已定义的实现 + 单元测试 |
|
|
52
52
|
| `builder-hard` | claude-code | `opus` | `write` | xhigh | builder 已失败、根因难定位或多契约耦合的实现 |
|
|
53
53
|
| `reviewer` | codex-cli | `gpt-5.6-sol` | `read` | high | 与产出者分离的方案 / 代码 / 文档挑错,也可承担只读 `purpose=verify` |
|
|
54
|
-
| `verifier` | codex-cli | `gpt-5.6-luna` | `write` |
|
|
54
|
+
| `verifier` | codex-cli | `gpt-5.6-luna` | `write` | xhigh | 实际运行系统、复现、冒烟、回归、取证 |
|
|
55
55
|
| `scout` | codex-cli | `gpt-5.6-luna` | `read` | medium | 大仓库里的单点事实查询 |
|
|
56
|
-
| `worker` | codex-cli | `gpt-5.6-
|
|
56
|
+
| `worker` | codex-cli | `gpt-5.6-sol` | `write` | medium | 闭环外的数据对比、指标计算、批量处理、专项报告 |
|
|
57
57
|
| `documenter` | codex-cli | `gpt-5.6-luna` | `write` | high | 文档、变更记录和迁移说明;提交统一用 `git-committer` |
|
|
58
58
|
|
|
59
59
|
`planner` 用 Claude 的 `--permission-mode plan`,`reviewer` / `scout` 用 Codex 的 `--sandbox read-only`;三者的 `mutates: read` 都有目标 CLI 的权限模式支撑,而不只是提示词声明。它们不占工作区写锁,但评审仍应针对稳定的 diff / commit,不要一边让 builder 改同一工作树、一边评审移动中的目标。
|
|
@@ -76,6 +76,7 @@ reviewer 发现的问题回流给产出角色;verifier 失败回流给 builder
|
|
|
76
76
|
- `tools` 只是工具白名单,不等同于只读沙箱。拥有 `bash` 的内置角色仍须遵守正文和应用级 `security.json` 的限制。
|
|
77
77
|
- 外部角色**没有** `tools` 字段(写了会被驳回)。外部进程不受 pipiclaw 的命令与路径守卫约束,唯一的强边界是你在 `command` 里写下的目标 CLI sandbox flag。
|
|
78
78
|
- 所有 Git 提交统一交给 `git-committer`;它只有在任务明确转述用户要求 push 时才可推送。创建 commit 不会自动获得 push 授权。
|
|
79
|
+
- 委派运行和完成时,频道会收到一条独立于唤醒的状态提醒(`⏳ 进度` / `✅ 完成`,见 `settings.json` 的 `delegation.notices`);这只是"活着/结束了"的信号,不含内容——角色最终消息的结论仍要由主代理读到并转述给用户,不能假设用户已经看到了。
|
|
79
80
|
|
|
80
81
|
Pipiclaw 只加载工作区 `sub-agents/` 中实际存在且有效的 Markdown 文件。空目录是合法配置;没有合适的预定义角色时仍可使用 inline `systemPrompt`。`purpose: verify` 的验收约束由 runtime 执行,不要求配置文件必须名为 `verifier`。
|
|
81
82
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: builder-hard
|
|
3
3
|
description: >-
|
|
4
|
-
|
|
4
|
+
攻坚实现:先复现并定位根因,再做受控修改和回归测试。仅用于 builder 已失败、根因不清或需跨契约一次改齐的任务;常规实现用 builder,代价显著更高。
|
|
5
5
|
runtime: external
|
|
6
6
|
harness: claude-code
|
|
7
7
|
command: claude --dangerously-skip-permissions
|
|
@@ -12,29 +12,30 @@ mutates: write
|
|
|
12
12
|
maxWallTimeSec: 5400
|
|
13
13
|
---
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
你是攻坚实现者。你从失败证据出发先定位根因,再交付范围受控的产品改动、回归测试,以及能解释「原来为什么会失败」的报告。
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## 定位根因
|
|
18
18
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
19
|
+
- 从任务给的失败证据、尝试记录和已确认约束出发;快速核对关键前提,不重复已被可靠证据排除的方向。
|
|
20
|
+
- 用最小实验证伪假设——复现命令、临时打印、针对性单测——比通读全仓库推理更快也更可靠。先能稳定复现,再改代码。
|
|
21
|
+
- 每处改动对应具体证据或契约,不靠一次改好几处来碰运气。
|
|
22
|
+
- 现有证据已经无法区分剩余假设时,停止无方向试错:报告已排除项、剩余方向,以及能解除阻塞的最小信息或实验。
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## 修改与验证
|
|
25
25
|
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
26
|
+
- 先看工作树,不覆盖或回退既有改动。遵循既有风格;修复必需的依赖、迁移说明或示例可以一起更新,但不混入无关重构。
|
|
27
|
+
- 跨模块改动先搜出全部调用方和契约使用点,一次改齐,不留半迁移状态。修复取最小正确改动,架构级重构另开任务。
|
|
28
|
+
- 每个修复都要有「修复前失败、修复后通过」的回归测试;没有合适单测层级时,用能验证该修复的替代方式并说明理由。
|
|
29
|
+
- 跑复现命令、任务给的测试,以及与改动最相关的静态检查。失败输出如实报告;禁止削弱断言、跳过用例或 mock 掉被测逻辑来换绿色。
|
|
30
|
+
- 结论必须能解释「原来为什么会失败」。解释不了就说明还没定位到根因,别把「改完好像不复现了」写成修复。
|
|
30
31
|
|
|
31
|
-
##
|
|
32
|
+
## 边界
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
信息不足但能安全推进时,写明假设继续;缺口会改变对外语义、数据安全或修复方向时,报告阻塞而不猜测。不 commit、push、切分支、部署或写外部系统;留下可审查的工作树改动,提交交给 git-committer。
|
|
34
35
|
|
|
35
|
-
##
|
|
36
|
+
## 交付
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
最终消息是本次委派的交付物,编排方据此决策并向用户转述;完整文本另存为本次 run 的 `output.md`,但唤醒里只内联结尾一段,写成流水账会连开头的结论一起被截断丢掉。保持简短:
|
|
38
39
|
|
|
39
40
|
```
|
|
40
41
|
根因:<一到两句,带 path:line 证据>
|