{"id":50886133,"url":"https://github.com/tychenjiajun/pi-tool-guard","last_synced_at":"2026-06-15T17:02:49.636Z","repository":{"id":364967139,"uuid":"1267158976","full_name":"tychenjiajun/pi-tool-guard","owner":"tychenjiajun","description":"Pi extension that corrects LLM tool calls: normalizes argument aliases for edit/write/read and strips trailing pipeline extractors from bash commands","archived":false,"fork":false,"pushed_at":"2026-06-15T08:43:25.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-15T11:32:37.413Z","etag":null,"topics":["argument-normalization","bash","llm","pi-coding-agent","pi-extension","pipeline-optimization","tool-correction","typescript"],"latest_commit_sha":null,"homepage":"https://github.com/tychenjiajun/pi-tool-guard","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tychenjiajun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-06-12T09:22:42.000Z","updated_at":"2026-06-15T08:43:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/tychenjiajun/pi-tool-guard","commit_stats":null,"previous_names":["tychenjiajun/pi-tool-guard"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tychenjiajun/pi-tool-guard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tychenjiajun%2Fpi-tool-guard","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tychenjiajun%2Fpi-tool-guard/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tychenjiajun%2Fpi-tool-guard/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tychenjiajun%2Fpi-tool-guard/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tychenjiajun","download_url":"https://codeload.github.com/tychenjiajun/pi-tool-guard/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tychenjiajun%2Fpi-tool-guard/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34372130,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["argument-normalization","bash","llm","pi-coding-agent","pi-extension","pipeline-optimization","tool-correction","typescript"],"created_at":"2026-06-15T17:02:48.757Z","updated_at":"2026-06-15T17:02:49.631Z","avatar_url":"https://github.com/tychenjiajun.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pi-tool-guard\n\nA pi extension that corrects common LLM tool call mistakes: normalizes argument aliases for `edit`/`write`/`read` and strips trailing pipeline extractors from `bash` commands.\n\n## Install\n\n```bash\npi install npm:pi-tool-guard\n```\n\n---\n\n## Features\n\n### 1. Argument alias normalization (`edit` / `write` / `read`)\n\nWhen the LLM calls a tool with wrong field names, the extension normalizes them before schema validation. No error, no re-execution.\n\n| Tool | Canonical | Accepted aliases |\n|---|---|---|\n| edit | `path` | `file`, `filePath`, `file_path`, `target`, `filename`, `file_name` |\n| edit | `edits[].oldText` | `old_str`, `old_string`, `oldContent`, `old`, `original`, `search` |\n| edit | `edits[].newText` | `new_str`, `new_string`, `newContent`, `new`, `replacement`, `replace` |\n| write | `path` | `file`, `filePath`, `file_path`, `target`, `filename`, `file_name` |\n| write | `content` | `text`, `body`, `code`, `data`, `fileContent`, `contents` |\n| read | `path` | `file`, `filePath`, `file_path`, `target`, `filename`, `file_name` |\n| read | `offset` | `start`, `startLine`, `start_line`, `from`, `line` |\n| read | `limit` | `lines`, `maxLines`, `max_lines`, `count`, `numLines`, `num_lines` |\n\n\u003e **Edit tool shorthand**: top-level `oldText`/`newText` (or aliases) are automatically wrapped into an `edits` array.\n\u003e\n\u003e **Read tool type coercion**: string values for `offset` and `limit` are coerced to numbers.\n\n### 2. Bash pipeline extractor stripping\n\nWhen the LLM appends truncation commands (`tail`, `head`, `grep`, etc.) to bash commands, the extension strips them and applies the extractor intelligently.\n\n**Three-case strategy:**\n\n| Scenario | UI Notification | LLM Response |\n|---|---|---|\n| Fast command (\u003c 10s), truncated | `Filtered via \\`head -5\\`` | Filtered result only |\n| Fast command (\u003c 10s), not truncated | `Filtered via \\`head -5\\`` | Filtered result only |\n| Slow command (truncated or not) | `The full output is above...` | Result + `This is a slow command. Avoid re-running...` |\n\n\u003e **Notification format**: The UI notification shows both the full original command and the extracted pipeline. Example: `Removed trailing pipeline commands: \\`grep FAIL | head -5\\` from \\`npm test | grep FAIL | head -5\\`.`\n\n**Example:** `vitest run | tail -n 10`\n- If vitest finishes in \u003c 10s → run `tail` on result (or full output file if truncated), notify UI\n- If vitest is slow → return result as-is, notify UI, append slow-command hint to LLM\n\n**Detected extractors:** `head`, `tail`, `grep`, `egrep`, `fgrep`, `rg`, `sed`, `awk`, `cut`, `sort`, `uniq`, `wc`, `less`, `more`, `column`, `jq`, `yq`, `tr`\n\nAll trailing extractors are stripped: `npm test | grep FAIL | head -5` → strips `grep FAIL | head -5`\n\n---\n\n## Architecture\n\nBoth features use `prepareArguments` on overridden built-in tools — the cleanest pi extension pattern for argument correction:\n\n- **edit/write/read**: `createXxxToolDefinition(cwd)` + `prepareArguments` normalizes aliases before schema validation\n- **bash**: `createBashToolDefinition(cwd)` + custom `execute` override:\n  1. `prepareArguments` parses the command with [unbash](https://github.com/nicolo-ribaudo/unbash), strips trailing extractors\n  2. `execute` runs the stripped command via the original built-in execute\n  3. If fast (\u003c 10s) + truncated → runs extractor on the full output file via `pi.exec`\n  4. If fast (\u003c 10s) + not truncated → pipes result through extractor via `pi.exec`\n  5. If slow (truncated or not) → returns result as-is with notice\n\nNo error recovery, no session scanning.\n\n## Development\n\n```bash\npnpm install\npnpm test        # Run all tests\npnpm typecheck   # Type check\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftychenjiajun%2Fpi-tool-guard","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftychenjiajun%2Fpi-tool-guard","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftychenjiajun%2Fpi-tool-guard/lists"}