Skip to content

Refactor orchestrator-v2 developer APIs#51

Merged
devzeebo merged 2 commits into
mainfrom
feat/interface-refactor
Jul 8, 2026
Merged

Refactor orchestrator-v2 developer APIs#51
devzeebo merged 2 commits into
mainfrom
feat/interface-refactor

Conversation

@devzeebo

@devzeebo devzeebo commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replace runOrchestrator with an Orchestrator class that registers work item sources and kind-based mappers before dispatch
  • Unify data registries to a single mutable DataRegistry/Registry model (no readonly split, no lazy ensure)
  • Add runner script agent baseline (registerScriptAgent) and task agent augment (registerTaskAgent(name, agent), registerEngine, loadAgent in agent-3-task)
  • Yield full RuneDetail from BifrostWorkItemSource metadata and wire the lvl3 example

Test plan

  • vp check passes
  • vp test — 112 tests pass
  • vp run -r build succeeds across all packages

… and runner augmentation.

Unify mutable data registries, replace runOrchestrator with Orchestrator + work-item mappers, add script/task agent registration via augment and loadAgent in agent-3-task, and wire the lvl3 example.
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@devzeebo, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 21 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 34dcd6b9-38b8-4a1e-8608-d26adb65ae12

📥 Commits

Reviewing files that changed from the base of the PR and between 1e3bdca and 5cf512f.

📒 Files selected for processing (5)
  • orchestrator-v2/docs/orchestrator.md
  • orchestrator-v2/examples/lvl3/runner.ts
  • orchestrator-v2/packages/orchestrator/src/orchestrator.ts
  • orchestrator-v2/packages/orchestrator/src/peer-registry.ts
  • orchestrator-v2/packages/runner/README.md
📝 Walkthrough

Walkthrough

This PR replaces runOrchestrator with a class-based Orchestrator supporting work-item mapping, unifies MutableDataRegistry/ReadonlyRegistry into a single Registry/DataRegistry contract, replaces enrollTaskAgent with dispatch-named registerTaskAgent/registerEngine/registerScriptAgent on Runner, adds agent-definition parsing/loading utilities, simplifies Bifrost work-item metadata mapping, and updates examples, docs, and workspace config accordingly.

Changes

Orchestration and registration API refactor

Layer / File(s) Summary
Unified data registry types
packages/interfaces-work/src/types.ts, packages/interfaces-work/src/index.ts
ReadonlyRegistry and MutableDataRegistry are removed; Registry<T> now directly declares get, has, and register, and DataRegistry.get returns Registry<T[K]>.
Registry implementation and Runner wiring
packages/runner/src/data-registry.ts, .../runner.ts, .../index.ts, .../types.ts, .../data-registry.spec.ts, README.md
createDataRegistry returns DataRegistry (get-only, throws on unknown type); asDataRegistry is removed; Runner.data is typed as DataRegistry.
Script agent support
packages/runner/src/script-agent.ts, .../runner.ts, .../index.ts
Adds ScriptFn type and createScriptAgent, and a new Runner.registerScriptAgent(name, fn) method.
Agent definition parsing and loading
packages/agent-3-task/src/agent-parser.ts, .../load-agent.ts, .../package.json, .../index.ts
Adds parseAgentDefinition (frontmatter/token/parameter validation via gray-matter) and loadAgent (file load + deep-merge override); exports updated accordingly.
Task agent registration by dispatch name
packages/agent-3-task/src/augment.ts, .../create-task-agent.ts, .../enroll-task-agent.ts (removed), .../augment.spec.ts, .../run-task-agent.spec.ts
enrollTaskAgent/TaskAgentRunner are removed; registerTaskAgent(name, agent) and registerEngine use data.get(...) directly; createTaskAgent takes an explicit name.
Orchestrator class
packages/orchestrator/src/orchestrator.ts, .../index.ts, .../test-helpers.ts, docs/orchestrator.md
runOrchestrator is replaced by an Orchestrator class with registerWorkItemSource, addWorkItemMapper, and start; adds WorkItemMapper and OrchestratorStartOptions types.
Bifrost work-item metadata mapping
packages/work-item-source-bifrost/src/bifrost-work-item-source.ts, .../index.ts, .../bifrost-work-item-source.spec.ts
mapToWorkItem now casts the full RuneDetail as metadata instead of hand-mapping individual fields; RuneDetail is exported; tests updated for the new dependency shape.
Examples, docs, and workspace config
README.md, docs/runner.md, examples/lvl3/*, pnpm-workspace.yaml
README/docs examples and the new examples/lvl3 package (orchestrator, runner, agents) demonstrate the new registration APIs; workspace globs include examples/*.

Sequence Diagram(s)

sequenceDiagram
    participant App as Example App
    participant Orchestrator
    participant WorkItemSource as BifrostWorkItemSource
    participant Mapper as WorkItemMapper
    participant Peer

    App->>Orchestrator: new Orchestrator()
    App->>Orchestrator: registerWorkItemSource(source)
    App->>Orchestrator: addWorkItemMapper("task", mapper)
    App->>Orchestrator: start({ identity, authorizedRunners, scheduler })
    Orchestrator->>Peer: create peer, subscribe connect/disconnect
    Orchestrator->>WorkItemSource: watchWorkItems()
    WorkItemSource-->>Orchestrator: raw work item
    Orchestrator->>Mapper: transform(rawWorkItem)
    Mapper-->>Orchestrator: mapped WorkItem
    Orchestrator->>Peer: dispatch(mapped WorkItem)
Loading
sequenceDiagram
    participant App as Example App
    participant Runner
    participant LoadAgent as loadAgent
    participant Parser as parseAgentDefinition
    participant DataRegistry

    App->>Runner: new Runner({ data })
    App->>Runner: registerEngine("cursor", engine)
    App->>LoadAgent: loadAgent("./agents/cowsay/AGENT.md")
    LoadAgent->>Parser: parseAgentDefinition(fileContent)
    Parser-->>LoadAgent: AgentDefinition | null
    LoadAgent-->>App: AgentDefinition
    App->>Runner: registerTaskAgent("cowsay", agentDefinition)
    Runner->>DataRegistry: get("agentDefinition").register("cowsay", agentDefinition)
    App->>Runner: registerScriptAgent("doSomething", fn)
Loading

Possibly related PRs

  • devzeebo/bifrost#46: Updates the same orchestrator-v2/README.md "Run a runner" example to use the new Runner registration APIs introduced here.
  • devzeebo/bifrost#49: Modifies the same bifrost-work-item-source.ts mapToWorkItem output and dependency-mapping tests touched in this PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: refactoring orchestrator-v2 developer APIs.
Description check ✅ Passed The description is on-topic and accurately reflects the changes in the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
orchestrator-v2/packages/runner/README.md (1)

39-40: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Document createScriptAgent and ScriptFn in the "Lower-level exports" section.

These new public exports from index.ts (line 4) are not listed in the README, while createDataRegistry and Registry — which are exported at the same level — are documented.

📖 Proposed addition
 - `createDataRegistry(guards)` — create a typed data registry up front
+- `createScriptAgent(fn, name)` — create a script agent work item handler
+- `ScriptFn` — script agent function type
 - `loadRunnerConfig(configPath)` — parse and validate YAML config
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@orchestrator-v2/packages/runner/README.md` around lines 39 - 40, The README’s
“Lower-level exports” section is missing the newly public exports, so add
entries for createScriptAgent and ScriptFn alongside the existing items. Update
the documentation in the same style as createDataRegistry and Registry, using
the symbols from index.ts so readers can find the new API exports easily.
orchestrator-v2/docs/orchestrator.md (1)

82-93: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Configuration docs don't reflect the new class-based API.

The Configuration section still shows OrchestratorOptions with workItemSource as a field, but start() now takes OrchestratorStartOptions which omits workItemSource (registered separately via registerWorkItemSource) and adds abortSignal. A user following these docs would pass workItemSource to start() and get a type error. The docs also don't mention the class-based API (new Orchestrator(), registerWorkItemSource, addWorkItemMapper, start) or abortSignal for graceful shutdown.

📝 Suggested doc update
 ### Configuration

 ```typescript
+// Step 1: Register the work item source
+const orchestrator = new Orchestrator();
+orchestrator.registerWorkItemSource(workItemSource);
+
+// Step 2: Optionally register per-kind mappers
+orchestrator.addWorkItemMapper("task", (workItem) => {
+  return { ...workItem, state: { ...workItem.metadata } };
+});
+
+// Step 3: Start with OrchestratorStartOptions (no workItemSource)
 type OrchestratorStartOptions = {
   identity: PeerIdentity;
   authorizedRunners: ReadonlyMap<string, KeyObject>;
   scheduler: Scheduler;
   host?: string;
   port?: number;
   heartbeatTimeoutMs?: number; // default 30000
   maxInFlightPerPeer?: number; // default 1
   abortSignal?: AbortSignal;
 };
+
+const handle = await orchestrator.start(options);
</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @orchestrator-v2/docs/orchestrator.md around lines 82 - 93, Update the
Configuration section to match the class-based Orchestrator API: replace the
outdated OrchestratorOptions example that includes workItemSource with the
current OrchestratorStartOptions shape, which uses abortSignal and omits
workItemSource. Add a concise usage example showing new Orchestrator(),
registerWorkItemSource(), addWorkItemMapper(), and start() so readers see the
correct flow and where each symbol belongs. Make sure the docs clearly
distinguish registration-time setup from the start() options to avoid type
errors from passing workItemSource into start().


</details>

<!-- cr-comment:v1:7b27e6c9349301e548c2326b -->

</blockquote></details>

</blockquote></details>
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@orchestrator-v2/examples/lvl3/runner.ts`:
- Line 11: The agent loading call in runner.ts is using a path relative to
process.cwd(), so it can break when the example is launched from another
directory. Update the registerTaskAgent invocation by resolving the AGENT.md
location from the module itself in runner.ts, using import.meta.url (and the
related path/file URL helpers) to build an absolute path before calling
loadAgent. Keep the fix localized to the runner setup so the cowsay agent is
loaded reliably regardless of the current working directory.

In `@orchestrator-v2/packages/orchestrator/src/orchestrator.ts`:
- Around line 102-119: `done` can hang in `orchestrator()` because `await
registry.waitForAvailablePeer()` is not cancelable when the abort signal fires.
Update the work-item loop to race `registry.waitForAvailablePeer()` against the
abort signal (or add a `PeerRegistry.cancelWaiters()` path invoked from
`cleanup()`), so the await unblocks immediately on abort and the loop can exit
cleanly before `dispatchWorkItem()` runs. Keep the fix centered around
`waitForAvailablePeer`, `cleanup`, and the `done` async block.

---

Outside diff comments:
In `@orchestrator-v2/docs/orchestrator.md`:
- Around line 82-93: Update the Configuration section to match the class-based
Orchestrator API: replace the outdated OrchestratorOptions example that includes
workItemSource with the current OrchestratorStartOptions shape, which uses
abortSignal and omits workItemSource. Add a concise usage example showing new
Orchestrator(), registerWorkItemSource(), addWorkItemMapper(), and start() so
readers see the correct flow and where each symbol belongs. Make sure the docs
clearly distinguish registration-time setup from the start() options to avoid
type errors from passing workItemSource into start().

In `@orchestrator-v2/packages/runner/README.md`:
- Around line 39-40: The README’s “Lower-level exports” section is missing the
newly public exports, so add entries for createScriptAgent and ScriptFn
alongside the existing items. Update the documentation in the same style as
createDataRegistry and Registry, using the symbols from index.ts so readers can
find the new API exports easily.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: aca116eb-e13f-46e8-b53e-cda5a59b8081

📥 Commits

Reviewing files that changed from the base of the PR and between efac957 and 1e3bdca.

⛔ Files ignored due to path filters (1)
  • orchestrator-v2/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (33)
  • orchestrator-v2/README.md
  • orchestrator-v2/docs/orchestrator.md
  • orchestrator-v2/docs/runner.md
  • orchestrator-v2/examples/lvl3/agents/cowsay/AGENT.md
  • orchestrator-v2/examples/lvl3/doSomething.ts
  • orchestrator-v2/examples/lvl3/orchestrator.ts
  • orchestrator-v2/examples/lvl3/package.json
  • orchestrator-v2/examples/lvl3/runner.ts
  • orchestrator-v2/packages/agent-3-task/package.json
  • orchestrator-v2/packages/agent-3-task/src/agent-parser.ts
  • orchestrator-v2/packages/agent-3-task/src/augment.spec.ts
  • orchestrator-v2/packages/agent-3-task/src/augment.ts
  • orchestrator-v2/packages/agent-3-task/src/create-task-agent.ts
  • orchestrator-v2/packages/agent-3-task/src/enroll-task-agent.ts
  • orchestrator-v2/packages/agent-3-task/src/index.ts
  • orchestrator-v2/packages/agent-3-task/src/load-agent.ts
  • orchestrator-v2/packages/agent-3-task/src/run-task-agent.spec.ts
  • orchestrator-v2/packages/interfaces-work/src/index.ts
  • orchestrator-v2/packages/interfaces-work/src/types.ts
  • orchestrator-v2/packages/orchestrator/src/index.ts
  • orchestrator-v2/packages/orchestrator/src/orchestrator.ts
  • orchestrator-v2/packages/orchestrator/src/test-helpers.ts
  • orchestrator-v2/packages/runner/README.md
  • orchestrator-v2/packages/runner/src/data-registry.spec.ts
  • orchestrator-v2/packages/runner/src/data-registry.ts
  • orchestrator-v2/packages/runner/src/index.ts
  • orchestrator-v2/packages/runner/src/runner.ts
  • orchestrator-v2/packages/runner/src/script-agent.ts
  • orchestrator-v2/packages/runner/src/types.ts
  • orchestrator-v2/packages/work-item-source-bifrost/src/bifrost-work-item-source.spec.ts
  • orchestrator-v2/packages/work-item-source-bifrost/src/bifrost-work-item-source.ts
  • orchestrator-v2/packages/work-item-source-bifrost/src/index.ts
  • orchestrator-v2/pnpm-workspace.yaml
💤 Files with no reviewable changes (2)
  • orchestrator-v2/packages/interfaces-work/src/index.ts
  • orchestrator-v2/packages/agent-3-task/src/enroll-task-agent.ts

Comment thread orchestrator-v2/examples/lvl3/runner.ts Outdated
Comment thread orchestrator-v2/packages/orchestrator/src/orchestrator.ts
@devzeebo devzeebo merged commit 898563c into main Jul 8, 2026
1 check passed
@devzeebo devzeebo deleted the feat/interface-refactor branch July 8, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant