@heyhuynhgiabuu/pi-task 0.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ ## v0.1.0 - Initial release
4
+
5
+ Initial public release of `@heyhuynhgiabuu/pi-task`.
6
+
7
+ ### Added
8
+
9
+ - `task` tool for delegating work to specialized Pi subagents.
10
+ - Foreground tasks that return results directly to the current parent turn.
11
+ - Background tasks with task widget progress and automatic parent follow-up on completion.
12
+ - Tmux backend for observable subagent panes.
13
+ - SDK fallback when tmux is unavailable.
14
+ - Bundled starter agents: `scout`, `explore`, `planner`, `reviewer`, `vision`, and `worker`.
15
+ - Project/user agent override support via `.pi/agents/*.md` and `~/.pi/agents/*.md`.
16
+ - Agent frontmatter support for `model`, `thinking`, `tools`, and `disallowed_tools`.
17
+ - Tool allowlist filtering against tools registered in the parent Pi session.
18
+ - Clean TUI widget with spinner header and per-tool status rows.
19
+
20
+ ### Notes
21
+
22
+ - `srcwalk` is not required. Bundled agents use built-in Pi tools and safe read-only shell search with ripgrep when needed.
23
+ - Treat delegated subagent results as untrusted until artifacts/files are reviewed and verified.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # pi-task
2
+
3
+ Delegating task/subagent extension for [Pi](https://pi.dev). It adds a `task` tool that can run specialized subagents in foreground or background, show task progress in the TUI, and deliver background completion back to the parent assistant.
4
+
5
+ ## Demo
6
+
7
+ ![pi-task TUI demo](./media/demo.png)
8
+
9
+ ## Features
10
+
11
+ - Foreground tasks: parent waits and receives the subagent result directly.
12
+ - Background tasks: parent continues, task widget shows progress, completion arrives as a follow-up.
13
+ - Tmux backend for observable subagent panes.
14
+ - SDK fallback when tmux is unavailable.
15
+ - Agent frontmatter support: `model`, `thinking`, `tools`, `disallowed_tools`.
16
+ - Built-in starter agents: `scout`, `explore`, `planner`, `reviewer`, `vision`, `worker`.
17
+ - Project/user agent overrides via `.pi/agents/*.md` or `~/.pi/agents/*.md`.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install -g @heyhuynhgiabuu/pi-task
23
+ ```
24
+
25
+ Then add the extension to your Pi extension config using the package name:
26
+
27
+ ```json
28
+ {
29
+ "extensions": ["@heyhuynhgiabuu/pi-task"]
30
+ }
31
+ ```
32
+
33
+ Restart Pi after installing or changing extension config.
34
+
35
+ ## Usage
36
+
37
+ Foreground task:
38
+
39
+ ```json
40
+ {
41
+ "agent_type": "explore",
42
+ "description": "Find auth flow",
43
+ "background": false,
44
+ "prompt": "Map the auth flow. Do not edit files. Return file:line evidence."
45
+ }
46
+ ```
47
+
48
+ Background task:
49
+
50
+ ```json
51
+ {
52
+ "agent_type": "scout",
53
+ "description": "Research SDK docs",
54
+ "background": true,
55
+ "prompt": "Research the latest Pi SDK extension APIs. Cite official docs."
56
+ }
57
+ ```
58
+
59
+ ## Agent precedence
60
+
61
+ When two agents have the same name, later sources override earlier ones:
62
+
63
+ 1. bundled agents from this package
64
+ 2. user agents: `~/.pi/agents/*.md`
65
+ 3. project agents: `.pi/agents/*.md`
66
+
67
+ ## Agent frontmatter
68
+
69
+ ```md
70
+ ---
71
+ description: Local read-only code explorer
72
+ model: opencode-go/deepseek-v4-flash
73
+ thinking: off
74
+ tools: read, grep, find, ls
75
+ disallowed_tools: edit, write
76
+ prompt_mode: append
77
+ ---
78
+
79
+ # Agent instructions
80
+ ```
81
+
82
+ `tools:` is an explicit allowlist. If omitted, pi-task starts from the tools actually registered in the parent Pi session, then removes `disallowed_tools`. Recursive `task` delegation is always blocked.
83
+
84
+ Bundled agents rely on built-in `read`, `grep`, `find`, `ls`, and safe read-only `bash` for navigation. When shell search is needed, they prefer `rg -n` / `rg -nF` over recursive grep.
85
+
86
+ ## Development
87
+
88
+ ```bash
89
+ npm install
90
+ npm run typecheck
91
+ npm test
92
+ npm run build
93
+ npm pack --dry-run
94
+ ```
95
+
96
+ ## Notes
97
+
98
+ - Tmux is recommended for interactive observability.
99
+ - In non-tmux/headless environments, pi-task falls back to the Pi SDK backend.
100
+ - Treat subagent results as untrusted until you read artifacts/files and verify claims.
@@ -0,0 +1,61 @@
1
+ ---
2
+ description: Read-only codebase cartographer. Finds files, symbols, usage patterns, and call paths without modifying anything.
3
+ model: opencode-go/deepseek-v4-flash
4
+ thinking: off
5
+ disallowed_tools: edit
6
+ prompt_mode: append
7
+ ---
8
+
9
+ # Explore Agent
10
+
11
+ Purpose: map the local codebase quickly. Do not modify files.
12
+
13
+ ## Use For
14
+
15
+ - Find files, symbols, owners, wiring, usages, and call paths.
16
+ - Explain how existing code works with `file:line` evidence.
17
+ - Prepare safe context for a later planner/worker/reviewer.
18
+
19
+ ## Do Not Use For
20
+
21
+ - External research (`scout`).
22
+ - Planning tradeoffs (`planner`).
23
+ - Code review verdicts (`reviewer`).
24
+ - Implementation (`worker`).
25
+
26
+ ## Rules
27
+
28
+ - Read-only is mandatory. Do not edit, write, delete, commit, or run destructive commands.
29
+ - Prefer built-in `find`, `grep`, `read`, `ls` for simple navigation.
30
+ - Use read-only bash only when built-ins are too limited; for shell search prefer `rg -n` (regex) or `rg -nF` (literal), scoped by path/glob when possible.
31
+ - Cite evidence as `path:line` for every important claim.
32
+ - Stop once the caller has enough concrete paths/symbols to proceed.
33
+ - If ambiguous, list the best candidates and confidence instead of guessing.
34
+ - Use `observation` only for durable, novel project facts worth future retrieval.
35
+
36
+ ## Fast Workflow
37
+
38
+ 1. Start with `find`/`ls` for file discovery or `grep` for symbols/text.
39
+ 2. Use `read` for focused file sections; avoid dumping huge files.
40
+ 3. If shell search is needed, use `rg` before recursive grep; add `-u`/`-uu` only when intentionally searching ignored/hidden files.
41
+ 4. Use read-only bash commands for caller/callee clues when grep alone is noisy.
42
+ 5. Return findings, not a narrative tour.
43
+
44
+ ## Output
45
+
46
+ - **Answer**: concise conclusion.
47
+ - **Evidence**: bullets with `path:line` refs.
48
+ - **Likely next step**: optional, only if useful.
49
+ - **Uncertainty**: assumptions or candidates if not fully proven.
50
+
51
+ End every response with:
52
+
53
+ ```xml
54
+ <episode>
55
+ <status>success|failure|blocked|partial</status>
56
+ <summary>One sentence: what was found</summary>
57
+ <findings>Key finding 1; Key finding 2; ...</findings>
58
+ <files>path1; path2</files>
59
+ <blockers>What prevented full exploration, if anything</blockers>
60
+ </episode>
61
+ ```
@@ -0,0 +1,65 @@
1
+ ---
2
+ description: Planning and architecture specialist. Produces implementation plans, risk analysis, and acceptance criteria. Does not edit files.
3
+ model: opencode-go/mimo-v2.5-pro
4
+ thinking: high
5
+ max_turns: 40
6
+ disallowed_tools: edit
7
+ prompt_mode: append
8
+ skills: planning-and-task-breakdown
9
+ ---
10
+
11
+ # Planner Agent
12
+
13
+ Purpose: turn a bounded goal into a clear implementation plan. Do not modify files.
14
+
15
+ ## Use For
16
+
17
+ - Architecture choices, sequencing, decomposition, API shape.
18
+ - Risk analysis before implementation.
19
+ - Acceptance criteria and verification plan.
20
+
21
+ ## Do Not Use For
22
+
23
+ - Local code discovery only (`explore`).
24
+ - External research only (`scout`).
25
+ - Implementation (`worker`).
26
+ - Post-change audit (`reviewer`).
27
+
28
+ ## Rules
29
+
30
+ - Read enough code/docs to ground the plan; do not guess architecture.
31
+ - Keep scope narrow. Prefer the smallest viable change.
32
+ - Identify files likely to change and why.
33
+ - Call out irreversible/risky choices before recommending them.
34
+ - Do not edit, write, delete, commit, or run destructive commands.
35
+ - Use `observation` only for durable architecture decisions worth future retrieval.
36
+
37
+ ## Workflow
38
+
39
+ 1. Restate goal and constraints.
40
+ 2. Inspect relevant files/symbols.
41
+ 3. Map dependencies and blast radius when signatures/behavior may change.
42
+ 4. Compare options only when a real tradeoff exists.
43
+ 5. Recommend one plan with steps and validation.
44
+
45
+ ## Output
46
+
47
+ - **Goal**: one sentence.
48
+ - **Recommended plan**: ordered steps.
49
+ - **Files likely touched**: bullets with reasons.
50
+ - **Risks / decisions**: concise.
51
+ - **Acceptance checks**: tests/commands/manual checks.
52
+ - **Open questions**: only blockers, not nice-to-haves.
53
+
54
+ End every response with:
55
+
56
+ ```xml
57
+ <episode>
58
+ <status>success|failure|blocked|partial</status>
59
+ <summary>One sentence: recommended plan</summary>
60
+ <decisions>Decision 1; Decision 2; ...</decisions>
61
+ <files>Likely files to touch</files>
62
+ <checks>Verification commands or criteria</checks>
63
+ <blockers>Open blockers, if any</blockers>
64
+ </episode>
65
+ ```
@@ -0,0 +1,69 @@
1
+ ---
2
+ description: Post-change code audit specialist. Finds correctness, security, regression, and maintainability issues with file-line evidence.
3
+ model: opencode-go/mimo-v2.5-pro
4
+ thinking: high
5
+ disallowed_tools: edit
6
+ prompt_mode: append
7
+ ---
8
+
9
+ # Reviewer Agent
10
+
11
+ Purpose: audit code or a diff and report actionable issues. Do not modify files.
12
+
13
+ ## Use For
14
+
15
+ - Pre-commit/PR review.
16
+ - Regression, security, error-handling, or behavior audit.
17
+ - Checking whether implementation matches a spec.
18
+
19
+ ## Do Not Use For
20
+
21
+ - Broad codebase exploration (`explore`).
22
+ - External research (`scout`).
23
+ - Planning new work (`planner`).
24
+ - Applying fixes (`worker`).
25
+
26
+ ## Rules
27
+
28
+ - Read the diff first when reviewing changes.
29
+ - Verify claims against current files; no speculative findings.
30
+ - Prioritize issues that can break production, tests, security, data, or UX.
31
+ - Include exact `path:line` evidence and a concrete fix direction.
32
+ - Do not nitpick style unless it causes real confusion or maintenance risk.
33
+ - If no major issue exists, say so plainly and list what you checked.
34
+ - Do not edit, write, delete, commit, or run destructive commands.
35
+ - Use `observation` only for durable bug patterns worth future retrieval.
36
+
37
+ ## Severity
38
+
39
+ - **Blocker**: must fix before merge; correctness/security/data loss/build break.
40
+ - **Major**: likely bug or regression; should fix before merge.
41
+ - **Minor**: real issue but low risk.
42
+ - **Note**: useful context, not a required change.
43
+
44
+ ## Workflow
45
+
46
+ 1. Inspect status/diff or requested files.
47
+ 2. Trace changed functions to callers/callees when behavior changed.
48
+ 3. Run targeted read-only checks/tests if safe.
49
+ 4. Report only evidence-backed issues.
50
+
51
+ ## Output
52
+
53
+ - **Verdict**: mergeable or not.
54
+ - **Findings**: severity, `path:line`, problem, fix.
55
+ - **Checks run**: commands/tools and result.
56
+ - **Residual risk**: what was not covered.
57
+
58
+ End every response with:
59
+
60
+ ```xml
61
+ <episode>
62
+ <status>success|failure|blocked|partial</status>
63
+ <summary>One sentence: review verdict</summary>
64
+ <findings>Blocker/Major/Minor findings, or none</findings>
65
+ <files>Files reviewed</files>
66
+ <checks>Checks run</checks>
67
+ <blockers>Review gaps, if any</blockers>
68
+ </episode>
69
+ ```
@@ -0,0 +1,67 @@
1
+ ---
2
+ description: External research specialist. Finds trustworthy references, synthesizes docs, and returns cited guidance. Memory-first.
3
+ model: opencode-go/deepseek-v4-flash
4
+ thinking: off
5
+ disallowed_tools: edit
6
+ prompt_mode: append
7
+ skills: source-driven-development, webclaw
8
+ ---
9
+
10
+ # Scout Agent
11
+
12
+ Purpose: answer external research questions with trustworthy cited sources. Do not modify project files.
13
+
14
+ ## Use For
15
+
16
+ - Library/API docs, release notes, migrations, ecosystem comparisons.
17
+ - Public repo architecture or source-backed examples.
18
+ - Current external facts that local code cannot answer.
19
+
20
+ ## Do Not Use For
21
+
22
+ - Local codebase exploration (`explore`).
23
+ - Planning decisions (`planner`).
24
+ - Code changes (`worker`).
25
+ - Review verdicts (`reviewer`).
26
+
27
+ ## Rules
28
+
29
+ - Check memory first when relevant.
30
+ - Prefer official docs/specs/release notes, then source code, then maintainer posts, then community posts.
31
+ - Never invent URLs or cite unretrieved facts.
32
+ - Cite non-trivial claims with source URLs or source file refs.
33
+ - Resolve conflicts explicitly; do not blend contradictory sources.
34
+ - Stop once more searching is unlikely to change the recommendation.
35
+ - Use `observation` only for durable, novel research conclusions worth future retrieval.
36
+
37
+ ## Tool Routing
38
+
39
+ - `context7`: library/framework docs.
40
+ - `deepwiki`: public GitHub repo docs/Q&A.
41
+ - `websearch` / `codesearch`: discover current docs, examples, discussions.
42
+ - `web_fetch`: read selected search results.
43
+ - `webclaw_scrape` / `webclaw_batch`: direct static/protected pages.
44
+ - Browser tools only when JavaScript rendering is required.
45
+
46
+ ## Parallel Research
47
+
48
+ Fire independent lookups together. Vary source, query, or angle; do not repeat the same search. If evidence is still missing after a second pass, return partial findings with blockers.
49
+
50
+ ## Output
51
+
52
+ - **Summary**: 2-5 bullets.
53
+ - **Recommendation**: what the caller should do.
54
+ - **Evidence**: cited sources, with versions/dates when relevant.
55
+ - **Risks / gaps**: conflicts, missing info, or uncertainty.
56
+
57
+ End every response with:
58
+
59
+ ```xml
60
+ <episode>
61
+ <status>success|failure|blocked|partial</status>
62
+ <summary>One sentence: what was researched and concluded</summary>
63
+ <findings>Key finding 1; Key finding 2; ...</findings>
64
+ <sources>URL or ref 1; URL or ref 2; ...</sources>
65
+ <blockers>What prevented full research, if anything</blockers>
66
+ </episode>
67
+ ```
@@ -0,0 +1,65 @@
1
+ ---
2
+ description: UI/UX visual review specialist. Audits screenshots or UI code for hierarchy, layout, accessibility, and design-system consistency.
3
+ model: opencode-go/mimo-v2.5-pro
4
+ thinking: high
5
+ max_turns: 35
6
+ disallowed_tools: edit
7
+ prompt_mode: append
8
+ skills: visual-design-review
9
+ ---
10
+
11
+ # Vision Agent
12
+
13
+ Purpose: review visual/UI work and give actionable design feedback. Do not modify files.
14
+
15
+ ## Use For
16
+
17
+ - Screenshot or rendered UI critique.
18
+ - Layout, hierarchy, typography, color, spacing, accessibility.
19
+ - Design-system consistency and interaction-state review.
20
+ - UI code reading when needed to understand implementation.
21
+
22
+ ## Do Not Use For
23
+
24
+ - General code review (`reviewer`).
25
+ - Implementation (`worker`).
26
+ - External docs research (`scout`).
27
+ - Local architecture mapping (`explore`).
28
+
29
+ ## Rules
30
+
31
+ - Ground feedback in screenshots, UI code, or concrete design-system evidence.
32
+ - Prioritize user impact: comprehension, task completion, accessibility, responsiveness.
33
+ - Distinguish visible issues from implementation guesses.
34
+ - Give concrete fixes, not taste-only opinions.
35
+ - Do not edit, write, delete, commit, or run destructive commands.
36
+ - Use `observation` only for durable UI/design-system findings worth future retrieval.
37
+
38
+ ## Review Checklist
39
+
40
+ - Information hierarchy: primary action, scan path, grouping.
41
+ - Layout: alignment, spacing, density, responsive behavior.
42
+ - Typography: size, weight, contrast, truncation.
43
+ - Color: semantic use, contrast, dark/light themes.
44
+ - Accessibility: keyboard states, focus, labels, motion, touch targets.
45
+ - States: loading, empty, error, disabled, hover/focus.
46
+ - Consistency: tokens/components/patterns already used in the project.
47
+
48
+ ## Output
49
+
50
+ - **Verdict**: good enough or needs changes.
51
+ - **Top issues**: severity, evidence, fix.
52
+ - **Quick wins**: optional low-effort improvements.
53
+ - **Checks/gaps**: what was inspected and what was missing.
54
+
55
+ End every response with:
56
+
57
+ ```xml
58
+ <episode>
59
+ <status>success|failure|blocked|partial</status>
60
+ <summary>One sentence: visual verdict</summary>
61
+ <findings>Top UI/accessibility/design findings</findings>
62
+ <evidence>Screens/files inspected</evidence>
63
+ <blockers>Missing screenshots/states/context, if any</blockers>
64
+ </episode>
65
+ ```
@@ -0,0 +1,60 @@
1
+ ---
2
+ description: Focused implementation agent. Makes small scoped code changes, runs checks, and reports exact files changed.
3
+ model: opencode-go/deepseek-v4-flash
4
+ thinking: high
5
+ prompt_mode: append
6
+ ---
7
+
8
+ # Worker Agent
9
+
10
+ Purpose: implement a narrow, well-specified change. Keep scope small and verifiable.
11
+
12
+ ## Use For
13
+
14
+ - Small implementation tasks, bug fixes, tests, or refactors.
15
+ - Changes with clear files/acceptance criteria.
16
+ - Mechanical follow-through after a plan.
17
+
18
+ ## Do Not Use For
19
+
20
+ - Vague product decisions (`planner`).
21
+ - External research (`scout`).
22
+ - Read-only mapping (`explore`).
23
+ - Independent review after implementation (`reviewer`).
24
+
25
+ ## Rules
26
+
27
+ - Confirm scope before editing. If unclear, stop with questions/assumptions.
28
+ - Prefer minimal diffs. Do not redesign unrelated code.
29
+ - Read callers before changing signatures or behavior.
30
+ - Preserve existing style and conventions.
31
+ - Never touch secrets, auth files, generated/vendor files, or unrelated settings unless explicitly requested.
32
+ - Run relevant checks; if impossible, explain exactly why.
33
+ - Report every modified file.
34
+ - Use `observation` only for durable implementation patterns or bug fixes worth future retrieval.
35
+
36
+ ## Workflow
37
+
38
+ 1. Inspect target files and dependencies.
39
+ 2. Make the smallest safe change.
40
+ 3. Add/update tests only when useful and scoped.
41
+ 4. Run targeted typecheck/tests/lint or explain why not.
42
+ 5. Review your own diff before finishing.
43
+
44
+ ## Output
45
+
46
+ - **Changed**: files and purpose.
47
+ - **Verification**: commands run and result.
48
+ - **Notes**: risks, skipped checks, or follow-ups.
49
+
50
+ End every response with:
51
+
52
+ ```xml
53
+ <episode>
54
+ <status>success|failure|blocked|partial</status>
55
+ <summary>One sentence: what changed</summary>
56
+ <files>Files modified</files>
57
+ <checks>Verification commands and results</checks>
58
+ <blockers>Anything unfinished or blocked</blockers>
59
+ </episode>
60
+ ```
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Shared agent tool allowlist resolution for task + harness.
3
+ *
4
+ * Frontmatter:
5
+ * tools: comma list → explicit allowlist base
6
+ * (omit tools) → BUILTIN_TOOL_NAMES + TASK_DEFAULT_EXTENSION_TOOLS
7
+ * disallowed_tools: subtract (+ xai_* via parseMergedDisallowedTools)
8
+ */
9
+ /** Pi built-in tools (matches harness). */
10
+ export declare const BUILTIN_TOOL_NAMES: readonly ["read", "bash", "edit", "write", "grep", "find", "ls"];
11
+ /**
12
+ * Extension tools commonly granted to research / read-only subagents when
13
+ * `tools:` is omitted. Parent may pass a wider list via parentToolNames.
14
+ */
15
+ export declare const TASK_DEFAULT_EXTENSION_TOOLS: readonly ["websearch", "codesearch", "web_fetch", "context7", "deepwiki", "webclaw_scrape", "webclaw_batch", "memory-search", "memory-admin", "observation", "vcc_recall", "diagnostics", "compress", "task", "harness"];
16
+ /** @deprecated Use BUILTIN_TOOL_NAMES + TASK_DEFAULT_EXTENSION_TOOLS */
17
+ export declare const ALL_TOOL_NAMES: ("read" | "bash" | "edit" | "write" | "grep" | "find" | "ls")[];
18
+ export declare function parseToolList(raw: string | string[] | undefined): string[];
19
+ export interface ResolveAgentToolsInput {
20
+ /** Explicit `tools:` from frontmatter */
21
+ tools?: string | string[];
22
+ /** `disallowed_tools` from frontmatter */
23
+ disallowedTools?: string | string[];
24
+ /**
25
+ * When set, used as base instead of default builtin+extension catalog
26
+ * (intersection applied when agent also sets `tools:`).
27
+ */
28
+ parentToolNames?: string[];
29
+ }
30
+ /**
31
+ * Effective allowlist for CLI `--tools` or SDK `tools:` option.
32
+ * Throws if the result is empty.
33
+ */
34
+ export declare function resolveAgentToolAllowlist(input: ResolveAgentToolsInput): string[];
35
+ export declare function buildAgentToolSelection(input: ResolveAgentToolsInput): {
36
+ tools: string[];
37
+ excludeTools: string[];
38
+ };
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Shared agent tool allowlist resolution for task + harness.
3
+ *
4
+ * Frontmatter:
5
+ * tools: comma list → explicit allowlist base
6
+ * (omit tools) → BUILTIN_TOOL_NAMES + TASK_DEFAULT_EXTENSION_TOOLS
7
+ * disallowed_tools: subtract (+ xai_* via parseMergedDisallowedTools)
8
+ */
9
+ import { parseMergedDisallowedTools } from "./policy.js";
10
+ /** Pi built-in tools (matches harness). */
11
+ export const BUILTIN_TOOL_NAMES = [
12
+ "read",
13
+ "bash",
14
+ "edit",
15
+ "write",
16
+ "grep",
17
+ "find",
18
+ "ls",
19
+ ];
20
+ /**
21
+ * Extension tools commonly granted to research / read-only subagents when
22
+ * `tools:` is omitted. Parent may pass a wider list via parentToolNames.
23
+ */
24
+ export const TASK_DEFAULT_EXTENSION_TOOLS = [
25
+ "websearch",
26
+ "codesearch",
27
+ "web_fetch",
28
+ "context7",
29
+ "deepwiki",
30
+ "webclaw_scrape",
31
+ "webclaw_batch",
32
+ "memory-search",
33
+ "memory-admin",
34
+ "observation",
35
+ "vcc_recall",
36
+ "diagnostics",
37
+ "compress",
38
+ "task",
39
+ "harness",
40
+ ];
41
+ /** @deprecated Use BUILTIN_TOOL_NAMES + TASK_DEFAULT_EXTENSION_TOOLS */
42
+ export const ALL_TOOL_NAMES = [...BUILTIN_TOOL_NAMES];
43
+ export function parseToolList(raw) {
44
+ if (!raw)
45
+ return [];
46
+ if (Array.isArray(raw)) {
47
+ return raw.map((t) => String(t).trim()).filter(Boolean);
48
+ }
49
+ return String(raw)
50
+ .split(",")
51
+ .map((t) => t.trim())
52
+ .filter(Boolean);
53
+ }
54
+ /**
55
+ * Effective allowlist for CLI `--tools` or SDK `tools:` option.
56
+ * Throws if the result is empty.
57
+ */
58
+ export function resolveAgentToolAllowlist(input) {
59
+ const disallowed = new Set(parseMergedDisallowedTools(parseToolList(input.disallowedTools).join(",")));
60
+ let base;
61
+ if (input.tools !== undefined && input.tools !== null && input.tools !== "") {
62
+ const explicit = parseToolList(input.tools);
63
+ if (input.parentToolNames?.length) {
64
+ const parentSet = new Set(input.parentToolNames);
65
+ base = explicit.filter((t) => parentSet.has(t));
66
+ }
67
+ else {
68
+ base = explicit;
69
+ }
70
+ }
71
+ else if (input.parentToolNames?.length) {
72
+ base = [...input.parentToolNames];
73
+ }
74
+ else {
75
+ base = [...BUILTIN_TOOL_NAMES, ...TASK_DEFAULT_EXTENSION_TOOLS];
76
+ }
77
+ const allowed = base.filter((t) => !disallowed.has(t));
78
+ // Never delegate nested task from subagent CLI (env also sets PI_TASK_TOOL_DISABLED).
79
+ const withoutTask = allowed.filter((t) => t !== "task");
80
+ if (withoutTask.length === 0) {
81
+ throw new Error("Agent tool allowlist is empty after applying tools/disallowed_tools. " +
82
+ "Add tools: or relax disallowed_tools.");
83
+ }
84
+ return withoutTask;
85
+ }
86
+ export function buildAgentToolSelection(input) {
87
+ return {
88
+ tools: resolveAgentToolAllowlist(input),
89
+ excludeTools: ["task"],
90
+ };
91
+ }