{"_id":"@baryonlabs/pi-dynamic-workflows","name":"@baryonlabs/pi-dynamic-workflows","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.2":{"name":"@baryonlabs/pi-dynamic-workflows","version":"1.0.2","description":"Claude-Code-style dynamic workflow orchestration for Pi (Baryon fork: crash-safe script errors + guarded sandbox).","type":"module","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"},"./workflow":{"types":"./types/workflow.d.ts"}},"scripts":{"test":"npm run check && npm run build && npm run test:unit","test:unit":"tsx --test tests/**/*.test.ts","check":"biome check .","format":"biome format --write .","lint":"biome lint .","build":"tsc","dev":"tsx src/index.ts"},"keywords":["pi-package","pi","workflow","agents"],"pi":{"extensions":["extensions/workflow.ts"]},"repository":{"type":"git","url":"git+https://github.com/baryonlabs/pi-dynamic-workflows.git"},"author":{"name":"michaelliv"},"license":"MIT","dependencies":{"acorn":"^8.16.0"},"peerDependencies":{"@earendil-works/pi-ai":"^0.78.0","@earendil-works/pi-coding-agent":"^0.78.0","@earendil-works/pi-tui":"^0.78.0","typebox":"*"},"devDependencies":{"@biomejs/biome":"2.4.16","@earendil-works/pi-ai":"0.78.0","@earendil-works/pi-coding-agent":"0.78.0","@earendil-works/pi-tui":"0.78.0","tsx":"latest","typebox":"latest","typescript":"latest"},"publishConfig":{"access":"public"},"_id":"@baryonlabs/pi-dynamic-workflows@1.0.2","gitHead":"a09b8a1e2538ef5a82d0d3df402ec39392393581","bugs":{"url":"https://github.com/baryonlabs/pi-dynamic-workflows/issues"},"homepage":"https://github.com/baryonlabs/pi-dynamic-workflows#readme","_nodeVersion":"24.4.0","_npmVersion":"11.4.2","dist":{"integrity":"sha512-cVI/Jaq7EsJT9rLHa+QcnIlw+RSKYTE/RfNZ8jIOlD80Eoj3k4FQJ3TT5ChQ4fz4Aty+5cIlQJ7I78dngAOGvg==","shasum":"341b817f8d482269d705ddc79da782c2d5677040","tarball":"https://registry.npmjs.org/@baryonlabs/pi-dynamic-workflows/-/pi-dynamic-workflows-1.0.2.tgz","fileCount":23,"unpackedSize":104769,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICX6lwwAiArggKupJcDRQZnjQADbMl52cBRWQGmWR68LAiEAxGLEk+Wsh82rT8HQgu4+3kcYInda7ChhIuwf0X0heN8="}]},"_npmUser":{"name":"martinhong","email":"hongbuzz@gmail.com"},"directories":{},"maintainers":[{"name":"chan3785","email":"chanho3785@gmail.com"},{"name":"martinhong","email":"hongbuzz@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/pi-dynamic-workflows_1.0.2_1783436940722_0.1558868767136341"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-07T15:09:00.544Z","1.0.2":"2026-07-07T15:09:00.901Z","modified":"2026-07-07T15:09:01.163Z"},"maintainers":[{"name":"chan3785","email":"chanho3785@gmail.com"},{"name":"martinhong","email":"hongbuzz@gmail.com"}],"description":"Claude-Code-style dynamic workflow orchestration for Pi (Baryon fork: crash-safe script errors + guarded sandbox).","homepage":"https://github.com/baryonlabs/pi-dynamic-workflows#readme","keywords":["pi-package","pi","workflow","agents"],"repository":{"type":"git","url":"git+https://github.com/baryonlabs/pi-dynamic-workflows.git"},"author":{"name":"michaelliv"},"bugs":{"url":"https://github.com/baryonlabs/pi-dynamic-workflows/issues"},"license":"MIT","readme":"# @baryonlabs/pi-dynamic-workflows\n\n> Claude-Code-style dynamic workflows for [Pi](https://github.com/earendil-works/pi).\n\n**Baryon fork** of [Michaelliv/pi-dynamic-workflows](https://github.com/Michaelliv/pi-dynamic-workflows) (MIT). This fork fixes a crash: a workflow script that calls a non-existent host API (`bash`, `fetch`, `require`, ...) inside an un-awaited async function used to escape as an unhandled promise rejection and kill the whole `pi` process, not just the workflow call. See [CHANGELOG.md](./CHANGELOG.md).\n\nA Pi extension that adds a `workflow` tool. Instead of one assistant doing everything sequentially, the model writes a small JavaScript script that fans out the work across many isolated subagents, then synthesizes the results.\n\nGreat for codebase audits, multi-perspective review, large refactors, and fan-out research.\n\nInspired by Anthropic's [dynamic workflows in Claude Code](https://claude.com/blog/introducing-dynamic-workflows-in-claude-code).\n\n## Install\n\n```bash\npi install npm:pi-dynamic-workflows\n# or from a local checkout\npi install /path/to/pi-dynamic-workflows\n```\n\nThen in Pi:\n\n```text\n/reload\n```\n\nThat's it. The extension registers a `workflow` tool and activates it on session start.\n\n## Usage\n\nJust ask Pi for a workflow in plain language:\n\n```text\nRun a workflow to inspect this repository and summarize the main modules.\n```\n\nThe model will write a workflow script and call the `workflow` tool. Live progress shows up inline:\n\n```text\n◆ Workflow: inspect_project (3/3 done)\n  ✓ Scan 1/1\n    #1 ✓ repo inventory\n  ✓ Analyze 2/2\n    #2 ✓ source modules\n    #3 ✓ final summary\n```\n\nPress `Esc` to cancel a running workflow. Active subagents are aborted and surfaced as skipped.\n\n## Workflow script shape\n\nA workflow is plain JavaScript. The first statement must export literal metadata. `name` and `description` are required; `phases` is optional documentation for an expected outline. The live progress view is driven by `phase(...)` calls at runtime:\n\n```js\nexport const meta = {\n  name: 'inspect_project',\n  description: 'Inspect a repository and summarize the main modules',\n  phases: [\n    { title: 'Scan' },\n    { title: 'Analyze' },\n  ],\n}\n\nphase('Scan')\nconst inventory = await agent('Inspect the repository structure.', {\n  label: 'repo inventory',\n})\n\nphase('Analyze')\nconst summary = await agent(\n  'Summarize the main modules from this inventory:\\n' + inventory,\n  { label: 'module summary' },\n)\n\nreturn { inventory, summary }\n```\n\nPhases are discovered as the script runs, so conditional and loop-created phases work naturally. If a branch is skipped, its phase does not show up as an empty progress row.\n\n### Editor IntelliSense\n\nReusable workflow files can opt into editor hints for workflow globals:\n\n```js\n/// <reference types=\"pi-dynamic-workflows/workflow\" />\n```\n\nThis declares `agent`, `parallel`, `pipeline`, `phase`, `log`, `args`, `cwd`, and `budget` for TypeScript-aware editors.\n\n### Available globals\n\n| Global | Description |\n| --- | --- |\n| `agent(prompt, opts)` | Spawn an isolated subagent. Returns its final text or, with `opts.schema`, a validated object. |\n| `parallel(thunks)` | Run an array of `() => agent(...)` thunks concurrently. Results are returned in input order. |\n| `pipeline(items, ...stages)` | Run each item through sequential stages while items fan out. Each stage receives `(prev, original, index)`. |\n| `phase(title)` | Mark the current phase. Used for grouping in the live progress view. |\n| `log(message)` | Append a workflow-level log line. |\n| `args` | Optional JSON value passed in via the tool's `args` parameter. |\n| `cwd`, `process.cwd()` | Current working directory for subagents. |\n| `budget` | `{ total, spent(), remaining() }` token budget tracker. |\n\n### Determinism rules\n\nWorkflow scripts are evaluated inside a Node `vm` sandbox. The following are intentionally unavailable:\n\n- `Date.now()`, `new Date()`\n- `Math.random()`\n- `require`, `import`, `fs`, network APIs\n- spreads, computed keys, template interpolation, function calls inside `meta`\n\nThis keeps `meta` parseable, runs reproducible, and the surface area small.\n\n### Structured subagent output\n\nPass a JSON Schema via `opts.schema` and the subagent will return a validated object:\n\n```js\nconst finding = await agent('Find security-sensitive files.', {\n  label: 'security scan',\n  schema: {\n    type: 'object',\n    properties: {\n      paths: { type: 'array', items: { type: 'string' } },\n      reason: { type: 'string' },\n    },\n    required: ['paths', 'reason'],\n  },\n})\n```\n\nUnder the hood this is a Pi `structured_output` tool with `terminate: true`, so the subagent ends on that call without an extra assistant turn.\n\n## How it works\n\n```text\nuser prompt\n  → Pi model writes a workflow script\n  → workflow tool parses + runs script in a vm sandbox\n  → script calls agent(), parallel(), pipeline()\n  → each agent() spawns an in-memory Pi subagent session\n  → snapshots stream back as compact progress\n  → final structured result returned to the parent assistant\n```\n\nSubagents run in fresh in-memory Pi sessions with the standard coding tools, so they can read files, run shell commands, and call structured output exactly like a normal Pi turn.\n\n## Library modules\n\n| File | Purpose |\n| --- | --- |\n| `src/workflow.ts` | AST-validated parser and sandboxed workflow runtime. |\n| `src/workflow-tool.ts` | The Pi `workflow` tool, prompt guidelines, rendering, abort handling. |\n| `src/agent.ts` | `WorkflowAgent`, an in-memory Pi subagent runner. |\n| `src/structured-output.ts` | Terminating structured-output tool backed by TypeBox/JSON Schema. |\n| `src/display.ts` | Workflow snapshots and compact text renderers. |\n| `extensions/workflow.ts` | The Pi extension entrypoint. |\n\n## Development\n\n```bash\nnpm install\nnpm test     # biome check + tsc + unit tests\nnpm run dev\n```\n\nParser unit tests live in `tests/workflow-parser.test.ts` and cover both accepted and rejected script shapes.\n\n## Status\n\nThis is a prototype. It implements the core workflow primitive (script, subagents, parallel/pipeline, phases, abort, structured output) but does not yet implement persisted or resumable runs, or a `/workflows` manager.\n\n## License\n\nMIT\n","readmeFilename":"README.md","_rev":"1-b100b183242c847d9775b83059cef309"}