@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.
Files changed (116) hide show
  1. package/README.md +3 -0
  2. package/dist/agent/channel-runner.d.ts +13 -18
  3. package/dist/agent/channel-runner.js +44 -90
  4. package/dist/agent/command-extension.js +1 -1
  5. package/dist/agent/context-budget.d.ts +8 -0
  6. package/dist/agent/context-budget.js +10 -2
  7. package/dist/agent/job-manager.d.ts +1 -1
  8. package/dist/agent/job-manager.js +9 -1
  9. package/dist/agent/prompt/builder.d.ts +0 -1
  10. package/dist/agent/prompt/builder.js +1 -14
  11. package/dist/agent/prompt/manifest.js +2 -1
  12. package/dist/agent/prompt/sections.js +1 -1
  13. package/dist/agent/runner-factory.d.ts +19 -1
  14. package/dist/agent/runner-factory.js +8 -1
  15. package/dist/agent/session-events.d.ts +2 -2
  16. package/dist/agent/turn-prompt.d.ts +35 -0
  17. package/dist/agent/turn-prompt.js +37 -0
  18. package/dist/agent/turn-recovery.js +1 -1
  19. package/dist/agent/turn-state.d.ts +60 -0
  20. package/dist/agent/turn-state.js +95 -0
  21. package/dist/agent/types.d.ts +3 -3
  22. package/dist/{runtime → channel}/channel-context.d.ts +6 -2
  23. package/dist/{runtime → channel}/channel-context.js +6 -2
  24. package/dist/{runtime → channel}/channel-event.d.ts +8 -0
  25. package/dist/channel/channel-paths.d.ts +16 -0
  26. package/dist/{runtime → channel}/channel-paths.js +20 -0
  27. package/dist/{agent/commands.d.ts → commands/catalog.d.ts} +16 -1
  28. package/dist/{agent/commands.js → commands/catalog.js} +30 -0
  29. package/dist/index.d.ts +1 -1
  30. package/dist/log.js +14 -5
  31. package/dist/main.js +29 -0
  32. package/dist/memory/commands.js +2 -2
  33. package/dist/memory/maintenance-state.d.ts +8 -0
  34. package/dist/memory/maintenance-state.js +47 -4
  35. package/dist/memory/scheduler.d.ts +6 -0
  36. package/dist/memory/scheduler.js +19 -16
  37. package/dist/playbooks/agent-delegation.md +2 -2
  38. package/dist/runtime/bootstrap.d.ts +2 -2
  39. package/dist/runtime/bootstrap.js +43 -13
  40. package/dist/runtime/delivery.d.ts +3 -3
  41. package/dist/runtime/dingtalk.d.ts +4 -4
  42. package/dist/runtime/dingtalk.js +2 -2
  43. package/dist/runtime/durable-dispatch.d.ts +7 -1
  44. package/dist/runtime/durable-dispatch.js +12 -2
  45. package/dist/runtime/event-commands.js +2 -2
  46. package/dist/runtime/events.d.ts +8 -1
  47. package/dist/runtime/events.js +15 -3
  48. package/dist/runtime/project-commands.js +2 -2
  49. package/dist/runtime/skill-commands.d.ts +27 -0
  50. package/dist/runtime/skill-commands.js +72 -0
  51. package/dist/runtime/subagent-commands.d.ts +8 -0
  52. package/dist/runtime/subagent-commands.js +29 -5
  53. package/dist/runtime/task-commands.js +2 -2
  54. package/dist/runtime/task-driver.d.ts +5 -1
  55. package/dist/runtime/task-driver.js +13 -12
  56. package/dist/runtime/task-migration.js +3 -2
  57. package/dist/runtime/task-wake.d.ts +6 -1
  58. package/dist/runtime/task-wake.js +21 -2
  59. package/dist/settings.d.ts +13 -0
  60. package/dist/settings.js +78 -0
  61. package/dist/shared/token-estimate.d.ts +1 -0
  62. package/dist/shared/token-estimate.js +19 -0
  63. package/dist/subagents/external/claude-code.js +20 -0
  64. package/dist/subagents/external/codex-cli.js +33 -0
  65. package/dist/subagents/external/harness.d.ts +8 -0
  66. package/dist/subagents/external/progress-tail.d.ts +14 -0
  67. package/dist/subagents/external/progress-tail.js +84 -0
  68. package/dist/subagents/external/run.js +1 -0
  69. package/dist/subagents/external/settlement.d.ts +4 -1
  70. package/dist/subagents/external/settlement.js +9 -2
  71. package/dist/subagents/runs.d.ts +45 -4
  72. package/dist/subagents/runs.js +187 -14
  73. package/dist/subagents/tool.js +4 -3
  74. package/dist/tasks/artifact-subject.d.ts +8 -0
  75. package/dist/tasks/artifact-subject.js +25 -0
  76. package/dist/tools/glob-match.d.ts +25 -4
  77. package/dist/tools/glob-match.js +175 -53
  78. package/dist/tools/glob.js +5 -2
  79. package/dist/tools/grep.js +4 -1
  80. package/dist/tools/index.d.ts +1 -1
  81. package/dist/tools/registry.d.ts +1 -1
  82. package/dist/tools/send-media.d.ts +1 -1
  83. package/dist/tools/skill.d.ts +15 -0
  84. package/dist/tools/skill.js +16 -8
  85. package/dist/tui/app.js +5 -3
  86. package/dist/tui/commands.d.ts +1 -0
  87. package/dist/tui/commands.js +3 -1
  88. package/dist/tui/terminal-context.d.ts +2 -2
  89. package/dist/tui/terminal-media-sender.d.ts +1 -1
  90. package/dist/tui/turn-controller.d.ts +2 -1
  91. package/dist/tui/turn-controller.js +2 -1
  92. package/examples/sub-agents/README.md +3 -2
  93. package/examples/sub-agents/builder-hard.md +17 -16
  94. package/examples/sub-agents/builder.md +16 -12
  95. package/examples/sub-agents/documenter.md +15 -16
  96. package/examples/sub-agents/explorer.md +16 -17
  97. package/examples/sub-agents/git-committer.md +18 -28
  98. package/examples/sub-agents/log-sifter.md +15 -14
  99. package/examples/sub-agents/planner.md +11 -11
  100. package/examples/sub-agents/reviewer.md +20 -13
  101. package/examples/sub-agents/scout.md +14 -11
  102. package/examples/sub-agents/verifier.md +17 -14
  103. package/examples/sub-agents/worker.md +18 -12
  104. package/package.json +1 -1
  105. package/dist/runtime/channel-paths.d.ts +0 -4
  106. /package/dist/{runtime → channel}/active-session-store.d.ts +0 -0
  107. /package/dist/{runtime → channel}/active-session-store.js +0 -0
  108. /package/dist/{runtime → channel}/channel-event.js +0 -0
  109. /package/dist/{runtime → channel}/channel-index.d.ts +0 -0
  110. /package/dist/{runtime → channel}/channel-index.js +0 -0
  111. /package/dist/{runtime → channel}/project-scope-store.d.ts +0 -0
  112. /package/dist/{runtime → channel}/project-scope-store.js +0 -0
  113. /package/dist/{runtime → channel}/store.d.ts +0 -0
  114. /package/dist/{runtime → channel}/store.js +0 -0
  115. /package/dist/{agent → commands}/reply-limits.d.ts +0 -0
  116. /package/dist/{agent → commands}/reply-limits.js +0 -0
@@ -1,75 +1,197 @@
1
1
  /**
2
- * Compile a shell-style glob pattern into a `RegExp` matched against a POSIX-relative file path.
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 an
8
- * alternation. Matching is always case-sensitive and always against `/`-joined relative paths —
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
- const body = globToRegExpSource(pattern);
13
- return pattern.includes("/") ? new RegExp(`^${body}$`) : new RegExp(`(?:^|/)${body}$`);
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
- /** Single-pass translation so `**` can see the literal `/` characters on either side of it. */
16
- function globToRegExpSource(pattern) {
17
- let out = "";
18
- let i = 0;
19
- const n = pattern.length;
20
- while (i < n) {
21
- const ch = pattern[i];
22
- if (ch === "*" && pattern[i + 1] === "*") {
23
- const precededByBoundary = i === 0 || pattern[i - 1] === "/";
24
- const followedBySlash = pattern[i + 2] === "/";
25
- const followedByEnd = i + 2 === n;
26
- if (precededByBoundary && followedBySlash) {
27
- // `**/`: zero or more complete path segments.
28
- out += "(?:.*/)?";
29
- i += 3;
30
- continue;
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
- if (precededByBoundary && followedByEnd) {
33
- // trailing `**`: everything under this point.
34
- out += ".*";
35
- i += 2;
36
- continue;
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
- // `**` not cleanly bounded by separators — fall back to single-segment `*` semantics.
39
- out += "[^/]*";
40
- i += 2;
95
+ }
96
+ else if (char === "," && depth === 1) {
97
+ alternatives.push(current);
98
+ current = "";
41
99
  continue;
42
100
  }
43
- if (ch === "*") {
44
- out += "[^/]*";
45
- i += 1;
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
- if (ch === "?") {
49
- out += "[^/]";
50
- i += 1;
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 (ch === "{") {
54
- const close = pattern.indexOf("}", i);
55
- if (close === -1) {
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
- out += escapeRegExpChar(ch);
69
- i += 1;
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
- return out;
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
- function escapeRegExpChar(ch) {
74
- return /[.+^${}()|[\]\\]/.test(ch) ? `\\${ch}` : ch;
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
  }
@@ -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
- throw new RecoverableToolError(`Invalid glob pattern: ${pattern}`);
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,
@@ -166,7 +166,10 @@ export function createGrepTool(executor, options = {}) {
166
166
  flags.push(`--exclude-dir=${segment}`);
167
167
  }
168
168
  if (glob) {
169
- flags.push(`--include=${glob}`);
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
@@ -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";
@@ -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;
@@ -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 {};
@@ -85,7 +85,14 @@ export async function listWorkspaceSkills(options) {
85
85
  }
86
86
  return summaries;
87
87
  }
88
- async function readWorkspaceSkill(options, name) {
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="${target}">\n` +
120
- `References are relative to ${dirname(target)}.\n\n` +
121
- `${body}\n` +
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: target, truncated: truncation.truncated },
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 { ChannelStore } from "../runtime/store.js";
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,
@@ -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
  /**
@@ -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 "../agent/commands.js";
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 "../runtime/channel-context.js";
13
- import type { ChannelStore } from "../runtime/store.js";
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 "../runtime/store.js";
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` | high | 实际运行系统、复现、冒烟、回归、取证 |
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-luna` | `write` | max | 闭环外的数据对比、指标计算、批量处理、专项报告 |
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
- 高强度疑难实现(外部 Claude)。仅用于已有失败证据、根因难定位或需要跨契约迁移的任务;常规编码用 builder。会先建立根因证据再修改工作区,成本高且异步返回。
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
- - 不 commit、push、切分支、部署或写外部系统;保留可审查的工作树改动,提交交给 git-committer。
29
- - 信息不足但可以安全推进时,写明假设并继续;缺口会改变对外语义、数据安全或修复方向时,报告阻塞而不猜测。
26
+ - 先看工作树,不覆盖或回退既有改动。遵循既有风格;修复必需的依赖、迁移说明或示例可以一起更新,但不混入无关重构。
27
+ - 跨模块改动先搜出全部调用方和契约使用点,一次改齐,不留半迁移状态。修复取最小正确改动,架构级重构另开任务。
28
+ - 每个修复都要有「修复前失败、修复后通过」的回归测试;没有合适单测层级时,用能验证该修复的替代方式并说明理由。
29
+ - 跑复现命令、任务给的测试,以及与改动最相关的静态检查。失败输出如实报告;禁止削弱断言、跳过用例或 mock 掉被测逻辑来换绿色。
30
+ - 结论必须能解释「原来为什么会失败」。解释不了就说明还没定位到根因,别把「改完好像不复现了」写成修复。
30
31
 
31
- ## 单元验证
32
+ ## 边界
32
33
 
33
- 跑复现命令、任务给出的单元测试,以及与改动最相关的静态检查。没有合适单元测试层级时使用能验证该修复的替代方式并说明理由。命令失败如实报告输出;禁止为了变绿而削弱断言、跳过用例或 mock 掉被测逻辑。修复必须能解释为什么原来会失败。
34
+ 信息不足但能安全推进时,写明假设继续;缺口会改变对外语义、数据安全或修复方向时,报告阻塞而不猜测。不 commit、push、切分支、部署或写外部系统;留下可审查的工作树改动,提交交给 git-committer。
34
35
 
35
- ## 最终消息
36
+ ## 交付
36
37
 
37
- 最终消息是调用方唯一能读到的内容,保持简短:
38
+ 最终消息是本次委派的交付物,编排方据此决策并向用户转述;完整文本另存为本次 run 的 `output.md`,但唤醒里只内联结尾一段,写成流水账会连开头的结论一起被截断丢掉。保持简短:
38
39
 
39
40
  ```
40
41
  根因:<一到两句,带 path:line 证据>