-
Notifications
You must be signed in to change notification settings - Fork 24
feat(orchestrator): markdown-backed agent loader + full integration flow #619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gewenyu99
merged 1 commit into
experiment/orchestrator-01-bootstrap-gating
from
experiment/orchestrator-06-agent-loader
Jun 18, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
205 changes: 205 additions & 0 deletions
205
src/lib/programs/orchestrator/__tests__/agent-prompt-loader.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,205 @@ | ||
| import * as fs from 'fs'; | ||
| import * as os from 'os'; | ||
| import * as path from 'path'; | ||
| import { | ||
| agentRunTools, | ||
| buildRegistry, | ||
| parseAgentPrompt, | ||
| resolveTask, | ||
| type AgentPrompt, | ||
| type AgentRegistry, | ||
| } from '../agent-prompt-loader'; | ||
| import { QueueStore } from '../queue'; | ||
|
|
||
| function tmpDir(): string { | ||
| return fs.mkdtempSync(path.join(os.tmpdir(), 'agent-loader-test-')); | ||
| } | ||
|
|
||
| function registryOf(prompts: AgentPrompt[]): AgentRegistry { | ||
| return buildRegistry( | ||
| prompts.map((p) => ({ ...p, flow: 'test-flow' })), | ||
| 'test-flow', | ||
| ); | ||
| } | ||
|
|
||
| describe('parseAgentPrompt', () => { | ||
| const sample = `--- | ||
| type: instrument-events | ||
| model: claude-sonnet-4-6 # cheapest model that succeeds | ||
| skills: [instrument-events] | ||
| allowedTools: [Read, Edit, Grep, Glob, Bash] | ||
| disallowedTools: [enqueue_task] | ||
| dependsOn: [init] | ||
| --- | ||
|
|
||
| ## Goal | ||
| Add at least one capture call. | ||
| `; | ||
|
|
||
| it('parses frontmatter scalars and inline arrays', () => { | ||
| const p = parseAgentPrompt(sample, 'fallback'); | ||
| expect(p.type).toBe('instrument-events'); | ||
| expect(p.model).toBe('claude-sonnet-4-6'); | ||
| expect(p.skills).toEqual(['instrument-events']); | ||
| expect(p.allowedTools).toEqual(['Read', 'Edit', 'Grep', 'Glob', 'Bash']); | ||
| expect(p.disallowedTools).toEqual(['enqueue_task']); | ||
| expect(p.dependsOn).toEqual(['init']); | ||
| }); | ||
|
|
||
| it('strips inline comments and keeps the body', () => { | ||
| const p = parseAgentPrompt(sample, 'fallback'); | ||
| expect(p.model).not.toContain('#'); | ||
| expect(p.body).toContain('## Goal'); | ||
| expect(p.body).not.toContain('---'); | ||
| }); | ||
|
|
||
| it('falls back to the menu id when type is omitted', () => { | ||
| const p = parseAgentPrompt('---\nmodel: x\n---\nbody', 'install'); | ||
| expect(p.type).toBe('install'); | ||
| }); | ||
|
|
||
| it('parses the flow from frontmatter', () => { | ||
| const p = parseAgentPrompt('---\nflow: audit\n---\nx', 'fix-events'); | ||
| expect(p.flow).toBe('audit'); | ||
| }); | ||
|
|
||
| it('marks the seed from frontmatter; everything else is a task', () => { | ||
| expect(parseAgentPrompt('---\nseed: true\n---\nplan', 'planner').seed).toBe( | ||
| true, | ||
| ); | ||
| expect(parseAgentPrompt('---\nmodel: x\n---\nbody', 'install').seed).toBe( | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| it('defaults missing array fields to empty and model to undefined', () => { | ||
| const p = parseAgentPrompt('no frontmatter at all', 'stub'); | ||
| expect(p.model).toBeUndefined(); | ||
| expect(p.skills).toEqual([]); | ||
| expect(p.dependsOn).toEqual([]); | ||
| expect(p.body).toBe('no frontmatter at all'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('agentRunTools', () => { | ||
| it('MCP-qualifies orchestrator tools and passes native tools through', () => { | ||
| const p = parseAgentPrompt( | ||
| '---\nallowedTools: [Read, read_handoffs]\ndisallowedTools: [enqueue_task, complete_task, Bash]\n---\nx', | ||
| 't', | ||
| ); | ||
| const { allowedTools, disallowedTools } = agentRunTools(p); | ||
| expect(allowedTools).toEqual([ | ||
| 'Read', | ||
| 'mcp__posthog-wizard__read_handoffs', | ||
| ]); | ||
| expect(disallowedTools).toEqual([ | ||
| 'mcp__posthog-wizard__enqueue_task', | ||
| 'mcp__posthog-wizard__complete_task', | ||
| 'Bash', | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('buildRegistry', () => { | ||
| const prompt = (over: Partial<AgentPrompt>): AgentPrompt => ({ | ||
| type: 'x', | ||
| seed: false, | ||
| skills: [], | ||
| allowedTools: [], | ||
| disallowedTools: [], | ||
| dependsOn: [], | ||
| body: 'b', | ||
| ...over, | ||
| }); | ||
|
|
||
| it('scopes to one flow and keeps the seed out of the task types', () => { | ||
| const registry = buildRegistry( | ||
| [ | ||
| prompt({ type: 'plan-audit', flow: 'audit', seed: true }), | ||
| prompt({ type: 'fix-events', flow: 'audit' }), | ||
| prompt({ type: 'install', flow: 'posthog-integration' }), | ||
| prompt({ type: 'example' }), | ||
| ], | ||
| 'audit', | ||
| ); | ||
| expect(registry.types).toEqual(['fix-events']); | ||
| expect(registry.seed?.type).toBe('plan-audit'); | ||
| expect(registry.get('install')).toBeUndefined(); | ||
| // A flowless prompt (e.g. the documentation example) joins no registry. | ||
| expect(registry.get('example')).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('resolveTask', () => { | ||
| let dir: string; | ||
| let store: QueueStore; | ||
|
|
||
| beforeEach(() => { | ||
| dir = tmpDir(); | ||
| store = new QueueStore(dir, 'run-1'); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| const prompt: AgentPrompt = { | ||
| type: 'capture', | ||
| seed: false, | ||
| model: 'claude-haiku-4-5-20251001', | ||
| skills: ['instrument-events'], | ||
| allowedTools: ['Read', 'Edit'], | ||
| disallowedTools: ['enqueue_task'], | ||
| dependsOn: ['plan-capture'], | ||
| body: '## Goal\nInstrument the planned events.', | ||
| }; | ||
|
|
||
| it('throws when no prompt is registered for the type', () => { | ||
| const registry = registryOf([]); | ||
| const task = { type: 'capture', dependsOn: [] } as never; | ||
| expect(() => resolveTask(registry, task, store)).toThrow(/capture/); | ||
| }); | ||
|
|
||
| it('resolves model, tools, and skills from the prompt', () => { | ||
| const registry = registryOf([prompt]); | ||
| const task = store.enqueue({ type: 'capture' }); | ||
| const resolved = resolveTask(registry, task, store); | ||
| expect(resolved.model).toBe('claude-haiku-4-5-20251001'); | ||
| expect(resolved.skills).toEqual(['instrument-events']); | ||
| expect(resolved.disallowedTools).toEqual([ | ||
| 'mcp__posthog-wizard__enqueue_task', | ||
| ]); | ||
| }); | ||
|
|
||
| it('prefers the enqueue model override over the prompt model', () => { | ||
| const registry = registryOf([prompt]); | ||
| const task = store.enqueue({ type: 'capture', model: 'override-x' }); | ||
| expect(resolveTask(registry, task, store).model).toBe('override-x'); | ||
| }); | ||
|
|
||
| it("appends upstream dependencies' handoffs as context", () => { | ||
| const registry = registryOf([prompt]); | ||
| const dep = store.enqueue({ type: 'plan-capture' }); | ||
| store.complete(dep.id, { | ||
| goals: 'decide events', | ||
| did: 'picked signup and purchase', | ||
| forNextAgent: 'instrument those two', | ||
| }); | ||
| const task = store.enqueue({ | ||
| type: 'capture', | ||
| dependsOn: [dep.id], | ||
| }); | ||
| const resolved = resolveTask(registry, task, store); | ||
| expect(resolved.prompt).toContain('Context from previous steps'); | ||
| expect(resolved.prompt).toContain('picked signup and purchase'); | ||
| expect(resolved.prompt).toContain('instrument those two'); | ||
| }); | ||
|
|
||
| it('omits the context section when there are no handoffs', () => { | ||
| const registry = registryOf([prompt]); | ||
| const task = store.enqueue({ type: 'capture' }); | ||
| expect(resolveTask(registry, task, store).prompt).not.toContain( | ||
| 'Context from previous steps', | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.