Skip to content
This repository was archived by the owner on Jun 12, 2026. It is now read-only.

Commit 9b81026

Browse files
committed
fix: enforce task delegation policy
Adds code-defined agent registration, nested task ancestry, default max-depth enforcement, allowedSubagents overrides, and frontmatter task permission checks before task runner startup. QA: npm test; npm run check; npm run qa:import; npm run qa:process-kill; npm run qa:senpi-install; npm pack --dry-run
1 parent 9cb55b0 commit 9b81026

26 files changed

Lines changed: 407 additions & 12 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.1.1
4+
5+
- Enforce nested task depth, allowed subagent overrides, and frontmatter task permissions.
6+
- Add code-defined agent registration helpers.
7+
38
## 0.1.0
49

510
- Initial task subagent extension package.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Task subagent extension for the pi coding agent.
1212
- Session resume reconciliation through `~/.senpi/task/tasks/*.json`.
1313
- JSONL task logs under `~/.senpi/task/logs/*.jsonl` with secret-like fields redacted.
1414
- Agent frontmatter loading from `.pi`, `.senpi`, `~/.pi/agent`, `~/.senpi/agent`, and `~/.senpi/agents`.
15+
- Code-defined agents through `defineAgent()` and `registerAgent()`.
16+
- Nested task policy with default max depth `1`; `allowedSubagents` and task permissions can explicitly allow deeper calls.
1517
- Model fallback for `models: [provider/a, provider/b]`.
1618
- TUI footer/widget status plus `/tasks`, `/task-kill`, and a keyboard shortcut.
1719

@@ -30,8 +32,11 @@ models:
3032
allowedSubagents:
3133
- github-librarian
3234
- web-librarian
35+
maxDepth: 1
3336
tools:
3437
read: allow
38+
task:
39+
"web-librarian": allow
3540
bash:
3641
"rg *": allow
3742
---

docs/architecture.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Core rule: background task errors, abrupt process exits, resume state, and final
99
## Components
1010

1111
- `agents`: markdown agent registry with pi/senpi-compatible search paths.
12-
- `permissions`: senpi-compatible last-match-wins rule evaluation.
12+
- `permissions`: senpi-compatible last-match-wins rule evaluation for task policy.
1313
- `runtime`: task state, result store, runners, resume reconciliation, and model fallback.
1414
- `tools`: `task`, `task_status`, `task_cancel`.
1515
- `ui`: compact status and widget rendering.
@@ -22,6 +22,18 @@ Process mode uses `ProcessTaskRunner` and `ProcessRunner`. It launches a separat
2222

2323
`CompositeTaskRunner` routes by `task.executionMode`, so both modes share persistence, logging, cancellation, status UI, and fallback handling.
2424

25+
## Agent Definition And Task Policy
26+
27+
Markdown agents are loaded from project and user `.pi` / `.senpi` locations, including `~/.senpi/agents/agents`. Code can also define agents by importing `defineAgent()` or `registerAgent()` from `pi-task`.
28+
29+
Nested tasks are enforced before a task record is created:
30+
31+
- Top-level parent sessions may create depth-1 tasks.
32+
- Default `maxDepth` is `1`.
33+
- A parent agent's `allowedSubagents` permits the named target even beyond depth.
34+
- Frontmatter task permissions can allow or deny `task:<agent>` or `task` patterns.
35+
- Denied delegations return a `denied` status and do not start a runner.
36+
2537
## Persistence And Resume
2638

2739
Task records are atomically written to `~/.senpi/task/tasks/<task-id>.json`. Final responses and errors remain available through `task_status` after the task finishes.

docs/planning-summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Primary implementation choices:
2222

2323
- In-process is the default runner.
2424
- Process mode is explicit through agent frontmatter or tool params.
25+
- Nested task depth is enforced before starting a task; `allowedSubagents` overrides the default max depth.
26+
- Agents can be markdown-loaded or code-registered.
2527
- Background state is first-class and retrievable by `task_status`.
2628
- Final responses and errors are persisted before the manager reports completion.
2729
- Abrupt process termination is represented as `killed`; unobservable resumed process tasks become `lost`.

docs/qa-results.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ Status: PASSED
44

55
Command-backed evidence from May 16, 2026:
66

7-
- `npm test`: passed, 17 files / 30 tests.
7+
- `npm test`: passed, 19 files / 37 tests.
88
- `npm run check`: passed, `tsgo --noEmit` and `biome check .`.
99
- `npm run qa:import`: passed, `import ok`.
1010
- `npm run qa:process-kill`: passed, child pid was reported and direct `SIGTERM` produced `killed`.
1111
- `npm run qa:senpi-install`: passed dry-run for `~/.senpi/agent/extensions/pi-task`.
12-
- `npm pack --dry-run`: passed, `pi-task-0.1.0.tgz`, 36 files.
12+
- `npm pack --dry-run`: passed, `pi-task-0.1.1.tgz`, 40 files.
1313

1414
Manual QA scenario note:
1515

docs/release.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ gh repo edit code-yeongyu/pi-task --description "Task subagent extension for pi"
1212
Release setup:
1313

1414
```bash
15-
git tag v0.1.0
16-
git push origin v0.1.0
17-
gh release create v0.1.0 --generate-notes
15+
git tag v0.1.1
16+
git push origin v0.1.1
17+
gh release create v0.1.1 --generate-notes
1818
```

docs/verifier.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Approval requires:
1313
- Pi lifecycle/tool events are mapped in code and task logs redact sensitive fields.
1414
- Process mode records pid and external kill evidence.
1515
- In-process is the default.
16-
- Permissions, agent schema, and model fallback match `docs/spec.md`.
16+
- Permissions, default depth, allowed-subagent override, agent schema, code-defined agents, and model fallback match `docs/spec.md`.

evidence/manual-qa.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Verified manually:
1313
- `npm run qa:import` loads the extension default export.
1414
- `npm run qa:process-kill` records pid and reports `killed` after direct external `SIGTERM`.
1515
- `npm run qa:senpi-install` resolves the local install symlink target.
16+
- `npm test` now covers 19 files / 37 tests, including nested task policy and code-defined agents.
1617
- `senpi --help` confirms `senpi install <source>` and `--extension/-e` host support.
1718
- `command -v pi` returned no binary on this machine, so local host checks use `senpi`.
1819

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pi-task",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "Task subagent extension for the pi coding agent with background lifecycle visibility, resume, process supervision, and final-result retrieval.",
55
"type": "module",
66
"license": "MIT",

0 commit comments

Comments
 (0)