@anureo/workflow 0.3.4 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +0,0 @@
1
- import { expect, test } from 'bun:test'
2
- import { createClient, type StructuredOutputToolDefinition } from '@anureo/sdk'
3
- import { createPiAdapter } from '@anureo/adapter-pi'
4
- import { fakeFactory } from '../../adapter/pi/tests/fake-host'
5
- import { z } from 'zod'
6
- import { agent } from './agent'
7
-
8
- test('workflow schema uses direct Pi tools and retains Zod refinement validation', async () => {
9
- const fake = fakeFactory(host => {
10
- let output: StructuredOutputToolDefinition | undefined
11
- Object.assign(host, { async setOutputTool(tool?: StructuredOutputToolDefinition) { output = tool } })
12
- host.script = async host => { await output!.execute({ sum: 42 }); await host.assistant('submitted') }
13
- })
14
- const client = await createClient({ adapter: createPiAdapter({ version: '1.5.2', createHost: fake.factory }), identity: { adapterId: 'pi', runtimeConfigId: 'workflow-direct-tool' } })
15
- try {
16
- const schema = z.object({ sum: z.number().int() })
17
- expect(await agent('17 + 25', { client, cwd: process.cwd(), schema })).toEqual({ sum: 42 })
18
- await expect(agent('17 + 25', { client, cwd: process.cwd(), schema: schema.refine(value => value.sum < 0) })).rejects.toMatchObject({ code: 'AGENT_STRUCTURED_OUTPUT_INVALID', outcomeUnknown: false })
19
- expect(fake.opens.every(open => !Object.hasOwn(open, 'mcpServers'))).toBe(true)
20
- } finally { await client.dispose() }
21
- })
@@ -1,71 +0,0 @@
1
- import { expect, test } from 'bun:test'
2
- import { mkdtemp, readFile, rm } from 'node:fs/promises'
3
- import { tmpdir } from 'node:os'
4
- import { join } from 'node:path'
5
- import { fileURLToPath } from 'node:url'
6
- import { z } from 'zod'
7
- import { createClient } from '@anureo/sdk'
8
- import { createClaudeAdapter } from '@anureo/adapter-claude'
9
- import { createCodexAdapter } from '@anureo/adapter-codex'
10
- import { agent, parallel } from './index'
11
-
12
- test('Zod agent crosses the official Claude SDK and a real JSONL process in fresh native sessions', async () => {
13
- const cwd = await mkdtemp(join(tmpdir(), 'anureo-workflow-native-'))
14
- const log = join(cwd, 'initialize.jsonl')
15
- const client = await createClient({ adapter: createClaudeAdapter({
16
- command: fileURLToPath(new URL('../../adapter/claude/tests/fixtures/fake-claude.mjs', import.meta.url)),
17
- executableRuntime: 'node', stateDir: join(cwd, 'state'), env: { FAKE_SCHEMA_PROBE: '1', FAKE_SCHEMA_LOG: log },
18
- }), identity: { adapterId: 'claude', runtimeConfigId: 'workflow' } })
19
- try {
20
- const schema = z.object({ answer: z.literal(42) })
21
- expect(await parallel([
22
- () => agent('first', { client, cwd, schema }),
23
- () => agent('second', { client, cwd, schema }),
24
- ])).toEqual([{ answer: 42 }, { answer: 42 }])
25
- const records = (await readFile(log, 'utf8')).trim().split('\n').map(line => JSON.parse(line))
26
- const structured = records.filter(record => record.schema)
27
- expect(structured).toHaveLength(2)
28
- expect(new Set(structured.map(record => record.sessionId)).size).toBe(2)
29
- expect(structured[0].schema).toMatchObject({ type: 'object', properties: { answer: { const: 42 } } })
30
- } finally {
31
- await client.dispose()
32
- await rm(cwd, { recursive: true, force: true, maxRetries: 20, retryDelay: 100 })
33
- }
34
- }, 15_000)
35
-
36
- test('Claude nominal success without native structured_output never falls back to prose', async () => {
37
- const cwd = await mkdtemp(join(tmpdir(), 'anureo-workflow-missing-'))
38
- const client = await createClient({ adapter: createClaudeAdapter({
39
- command: fileURLToPath(new URL('../../adapter/claude/tests/fixtures/fake-claude.mjs', import.meta.url)), executableRuntime: 'node', stateDir: cwd,
40
- }), identity: { adapterId: 'claude', runtimeConfigId: 'missing' } })
41
- try {
42
- await expect(agent('missing', { client, cwd, schema: z.object({ answer: z.number() }) })).rejects.toMatchObject({ code: 'CLAUDE_STRUCTURED_OUTPUT_MISSING' })
43
- } finally {
44
- await client.dispose()
45
- await rm(cwd, { recursive: true, force: true, maxRetries: 20, retryDelay: 100 })
46
- }
47
- }, 15_000)
48
-
49
- const codexCases = [
50
- { scenario: 'workflow-schema', expected: { answer: 42 }, description: 'returns a successful structured result' },
51
- { scenario: 'auth-expired', expected: null, description: 'returns null when authentication expires' },
52
- ] as const
53
-
54
- for (const { scenario, expected, description } of codexCases) test(`Zod agent crosses Codex native process: ${description}`, async () => {
55
- const cwd = await mkdtemp(join(tmpdir(), 'anureo-workflow-codex-'))
56
- const log = join(cwd, 'requests.jsonl')
57
- const client = await createClient({ adapter: createCodexAdapter({ command: process.execPath,
58
- args: [fileURLToPath(new URL('../../adapter/codex/tests/fake-app-server.mjs', import.meta.url))],
59
- version: '0.164.0', env: { FAKE_SCENARIO: scenario, FAKE_LOG_FILE: log },
60
- }), identity: { adapterId: 'codex', runtimeConfigId: scenario } })
61
- try {
62
- const value = await agent('answer', { client, cwd, schema: z.object({ answer: z.literal(42) }) })
63
- expect(value).toEqual(expected)
64
- const starts = (await readFile(log, 'utf8')).trim().split('\n').map(line => JSON.parse(line)).filter(frame => frame.method === 'turn/start')
65
- expect(starts).toHaveLength(1)
66
- expect(starts[0].params.outputSchema).toMatchObject({ type: 'object', properties: { answer: { const: 42 } } })
67
- } finally {
68
- await client.dispose()
69
- await rm(cwd, { recursive: true, force: true, maxRetries: 20, retryDelay: 100 })
70
- }
71
- }, 15_000)
@@ -1,32 +0,0 @@
1
- import { randomUUID } from 'node:crypto'
2
- import { open, rename, unlink } from 'node:fs/promises'
3
- import { dirname } from 'node:path'
4
- import { canonicalJson } from './json'
5
-
6
- /** Windows supports file flushes, but Node does not provide directory fsync there. */
7
- export async function syncDirectory(path: string): Promise<void> {
8
- if (process.platform === 'win32') return
9
- const directory = await open(path, 'r')
10
- try { await directory.sync() } finally { await directory.close() }
11
- }
12
-
13
- export async function atomicPublish(path: string, value: unknown): Promise<void> {
14
- const text = `${canonicalJson(value)}\n`
15
- const temporary = `${path}.${randomUUID()}.tmp`
16
- let temporaryExists = false
17
- try {
18
- const file = await open(temporary, 'wx', 0o600)
19
- temporaryExists = true
20
- try { await file.writeFile(text, 'utf8'); await file.sync() }
21
- finally { await file.close() }
22
- await rename(temporary, path)
23
- temporaryExists = false
24
- await syncDirectory(dirname(path))
25
- } catch (cause) {
26
- if (temporaryExists) {
27
- try { await unlink(temporary) }
28
- catch (cleanup) { throw new AggregateError([cause, cleanup], 'Atomic publish failed') }
29
- }
30
- throw cause
31
- }
32
- }
@@ -1,19 +0,0 @@
1
- import { AsyncLocalStorage } from 'node:async_hooks'
2
- import type { AgentJournal } from './persistence/journal'
3
- import type { RunState } from './workflow-state'
4
-
5
- /** Ambient context linking agent() calls inside a workflow body to its journal. */
6
- export interface RunContext {
7
- readonly journal: AgentJournal
8
- readonly state: RunState
9
- }
10
-
11
- const storage = new AsyncLocalStorage<RunContext>()
12
-
13
- export function runWith<T>(context: RunContext, body: () => Promise<T>): Promise<T> {
14
- return storage.run(context, body)
15
- }
16
-
17
- export function currentRun(): RunContext | undefined {
18
- return storage.getStore()
19
- }