[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-82037":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":8,"htmlUrl":8,"language":9,"languages":8,"totalLinesOfCode":8,"stars":10,"forks":11,"watchers":12,"openIssues":13,"contributorsCount":14,"subscribersCount":14,"size":14,"stars1d":15,"stars7d":16,"stars30d":17,"stars90d":14,"forks30d":14,"starsTrendScore":18,"compositeScore":19,"rankGlobal":8,"rankLanguage":8,"license":8,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":8,"pushedAt":8,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":14,"starSnapshotCount":14,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},82037,"pi-dynamic-workflows","Michaelliv\u002Fpi-dynamic-workflows","Michaelliv",null,"TypeScript",914,45,3,12,0,8,131,547,53,8.99,false,"main",true,[],"2026-06-12 02:04:22","# pi-dynamic-workflows\n\n> Claude-Code-style dynamic workflows for [Pi](https:\u002F\u002Fgithub.com\u002Fearendil-works\u002Fpi).\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:\u002F\u002Fclaude.com\u002Fblog\u002Fintroducing-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 \u002Fpath\u002Fto\u002Fpi-dynamic-workflows\n```\n\nThen in Pi:\n\n```text\n\u002Freload\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\u002F3 done)\n  ✓ Scan 1\u002F1\n    #1 ✓ repo inventory\n  ✓ Analyze 2\u002F2\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:\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\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\u002Fworkflow.ts` | AST-validated parser and sandboxed workflow runtime. |\n| `src\u002Fworkflow-tool.ts` | The Pi `workflow` tool, prompt guidelines, rendering, abort handling. |\n| `src\u002Fagent.ts` | `WorkflowAgent`, an in-memory Pi subagent runner. |\n| `src\u002Fstructured-output.ts` | Terminating structured-output tool backed by TypeBox\u002FJSON Schema. |\n| `src\u002Fdisplay.ts` | Workflow snapshots and compact text renderers. |\n| `extensions\u002Fworkflow.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\u002Fworkflow-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\u002Fpipeline, phases, abort, structured output) but does not yet implement persisted or resumable runs, or a `\u002Fworkflows` manager.\n\n## License\n\nMIT\n","pi-dynamic-workflows 是一个用于 Pi 的扩展工具，它引入了动态工作流功能，允许模型编写小型 JavaScript 脅本来分发任务给多个独立的子代理，并最终汇总结果。该工具的核心功能包括通过自然语言请求执行复杂的工作流，如代码库审计、多角度审查和大规模重构等。技术上，它支持并行处理、管道操作以及阶段标记等功能，且运行在受限制的 Node.js 沙箱环境中以保证安全性与确定性。适用于需要对项目进行深入分析或组织复杂的自动化任务场景中，特别适合开发者及团队提高工作效率。",2,"2026-06-11 04:07:33","CREATED_QUERY"]