# pi-onedev-toolkit

Lightweight [OneDev](https://onedev.io/) integration for [Pi](https://pi.dev/), built on the official [TOD CLI](https://code.onedev.io/onedev/tod): repo-aware issue, pull request, build, and one-shot watch tools plus issue-to-PR and PR-review skills.

The agent never sees tokens. The extension invokes `tod` with structured arguments, resolves the OneDev project from the repository's git remotes, and keeps unavailable domain schemas out of the default prompt. Model-facing multiword parameters use strict `snake_case`; unknown parameters are rejected instead of being silently ignored.

## Requirements

- OneDev 15.1+
- The `tod` CLI installed and configured:

```bash
curl -fsSL https://code.onedev.io/onedev/tod/~raw/main/install.sh | bash
tod config set   # server-url + access-token (or set ONEDEV_SERVER_URL / ONEDEV_ACCESS_TOKEN)
```

## Install

```bash
pi install npm:pi-onedev-toolkit
# or from source
pi install git:github.com/alpertarhan/pi-onedev-toolkit
```

When the current directory is a OneDev repository, the status line shows the active project. `onedev_context` action `setup` explains missing TOD configuration, credentials, or project remotes; `/od-health` performs an authenticated re-check. Use `/od-settings` to enable or disable the footer for the current session branch.

## Tools

| Tool | Domains | Covers |
| --- | --- | --- |
| `onedev_context` (always active) | — | Readiness, authenticated health, login, setup guidance, and accessible project discovery |
| `onedev_tools` (always active) | — | Activate only the issue, pull, build, and watch domains needed now |
| `onedev_issue` | issue | Query/get/comment issues, change fields/labels/state, log work, issue branches |
| `onedev_pull` | pull | PR metadata/comments/code comments/labels/builds/patch, create/edit, reply/resolve review comments, approve, request changes, merge/discard |
| `onedev_build` | build | Build queries, logs, code-problem and unit-test reports, changes since success, jobs, build-spec validation/upgrades |
| `onedev_watch` | watch | One-shot build-result and pull-attention notifications; list/stop active session watches |

Lazy by design: domain tools activate only through `onedev_tools`, keeping the default tool list and system prompt light. Activation performs the first authenticated check and returns the server, project, and login context in the same response.

Model-visible issue, PR, and build output defaults to 16 KB. PR patches, build logs, and build-spec schemas default to 32 KB. Use `max_bytes` to raise or lower a call's budget up to 128 KB; truncation keeps the payload head/tail and is reported explicitly. List actions instead return one-line-per-item digests by default (pass `full` for the raw payload), so bulk queries stay small without losing items; payloads beyond the 512 KB internal fetch fall back to the normal bounded raw output. Internal watch polling remains separately bounded and is never copied into the model context.

Remote and local mutations use Pi's real interactive approval UI. An approval can apply once, for the session, or persist for the exact server/project/operation in `~/.pi/agent/onedev-toolkit.json`; remove that file to revoke all saved approvals. Non-interactive sessions reject unapproved mutations. `build run` in local mode uses an isolated temporary Git index so TOD cannot leave the user's index staged; `check_spec` is treated as a mutation because TOD may upgrade `.onedev-buildspec.yml`.

Watches are session-scoped and one-shot. They use one timer, bounded polling, expiration and backoff, and wake the agent with metadata only. The agent retrieves logs, comments, or build details with the corresponding read tool. At most ten watches may be active; session changes and shutdown clear them.

Attachment download is intentionally not exposed: current TOD releases may send the OneDev bearer token to an absolute external Markdown URL and do not provide a safe download-size/overwrite boundary.

## Commands

- `/od-context` — active server, inferred project, login
- `/od-health` — re-check tod configuration and server reachability
- `/od-settings` — enable or disable the OneDev footer status in the TUI

## Compatibility notes

- Update TOD regularly from its upstream install script. `get_unit_test_report` reports an actionable upgrade error when the installed TOD predates that command.
- Plain references require the current repository to have a OneDev remote from which TOD can infer the project. The toolkit reports `no_project` rather than pretending a qualified reference can bypass TOD's resolver.
- `issue`, `pull`, and `build` `list` calls with an explicit `project` work from any repository: the toolkit binds TOD to a throwaway Git remote for the query and removes it afterwards.
- Tool calls use `snake_case`, for example `for_code_review`, `target_branch`, `report_name`, and `interval_seconds`.

## Skills

- `onedev-issue-to-pr` — gather issue context, branch, implement, present for review, then push and open the PR
- `onedev-pr-review` — full-context PR review with line-anchored findings; submits only on explicit request

If you use only tools and slash commands, omit both workflow entries from every prompt while keeping the extension and tools:

```json
{ "source": "npm:pi-onedev-toolkit", "skills": [] }
```

## Development

```bash
bun install
bun run check   # typecheck + vitest
bun run scripts/smoke.ts  # optional read-only live smoke; see CONTRIBUTING.md
```

## License

MIT
