@parcha/agentrun-harness-claude 0.1.0-beta.57 → 0.1.0-beta.59

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.
@@ -387,6 +387,71 @@ export function fakeSdk(fake = {}) {
387
387
  await mirror([{ type: 'last-prompt' }]);
388
388
  continue;
389
389
  }
390
+ const batching = /^batch (.*)$/s.exec(command);
391
+ if (batching) {
392
+ const spec = JSON.parse(batching[1]);
393
+ const sleep = fake.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
394
+ const event = (ev) => ({ type: 'stream_event', parent_tool_use_id: null, event: ev });
395
+ const tool = (await tools).get(spec.tool);
396
+ const lines = [];
397
+ const running = [];
398
+ yield event({ type: 'message_start', message: { id: `msg_${uuid().slice(0, 8)}`, role: 'assistant', content: [] } });
399
+ for (let index = 1; index <= spec.n; index++) {
400
+ const id = `toolu_${randomUUID().slice(0, 8)}_${++calls}`;
401
+ const block = { type: 'tool_use', id, name: `mcp__hands__${spec.tool}`, input: spec.args };
402
+ yield event({ type: 'content_block_start', index: index - 1, content_block: { ...block, input: {} } });
403
+ await sleep(spec.gapMs);
404
+ yield event({ type: 'content_block_delta', index: index - 1, delta: { type: 'input_json_delta', partial_json: JSON.stringify(spec.args) } });
405
+ yield event({ type: 'content_block_stop', index: index - 1 });
406
+ const a = entry('assistant', { message: { role: 'assistant', content: [block] } });
407
+ if (!spec.lost?.includes(index))
408
+ lines.push(a);
409
+ yield { type: 'assistant', parent_tool_use_id: null, uuid: a.uuid, session_id: sessionId, message: a.message };
410
+ if (spec.refused?.includes(index)) {
411
+ const r = entry('user', { message: { role: 'user', content: [{ type: 'tool_result', tool_use_id: id, is_error: true, content: `<tool_use_error>Error: No such tool available: ${block.name}</tool_use_error>` }] } });
412
+ if (!spec.lost?.includes(index))
413
+ lines.push(r);
414
+ yield { type: 'user', parent_tool_use_id: null, message: r.message };
415
+ continue;
416
+ }
417
+ running.push((async () => {
418
+ const result = tool ? await tool.handler(spec.args, { _meta: { 'claudecode/toolUseId': id } }) : { content: [{ type: 'text', text: `no tool ${spec.tool}` }], isError: true };
419
+ fake.onCallEnd?.({ id, index, isError: !!result.isError, text: String(result.content[0]?.text ?? '') });
420
+ return { id, result };
421
+ })());
422
+ }
423
+ yield event({ type: 'message_delta', delta: { stop_reason: 'tool_use', stop_sequence: null }, usage: { output_tokens: 12 } });
424
+ yield event({ type: 'message_stop' });
425
+ fake.onMessageEnd?.();
426
+ await mirror(lines);
427
+ const results = await Promise.all(running);
428
+ if (signal?.aborted)
429
+ return;
430
+ for (const { id, result } of results) {
431
+ const r = entry('user', { message: { role: 'user', content: [{ type: 'tool_result', tool_use_id: id, is_error: !!result.isError, content: result.content[0]?.text }] } });
432
+ await mirror([r]);
433
+ yield { type: 'user', parent_tool_use_id: null, message: r.message };
434
+ }
435
+ const reply = `${spec.tool} ran ${results.filter(({ result }) => !result.isError).length} of ${spec.n}`;
436
+ if (spec.then) {
437
+ // The answer is a message of its own, in the same stream, streamed as the model writes it.
438
+ yield event({ type: 'message_start', message: { id: `msg_${uuid().slice(0, 8)}`, role: 'assistant', content: [] } });
439
+ yield event({ type: 'content_block_start', index: 0, content_block: { type: 'text', text: '' } });
440
+ for (let at = 0; at < spec.then.n; at++) {
441
+ await sleep(spec.then.gapMs);
442
+ yield event({ type: 'content_block_delta', index: 0, delta: { type: 'text_delta', text: at ? ' .' : reply } });
443
+ }
444
+ yield event({ type: 'content_block_stop', index: 0 });
445
+ yield event({ type: 'message_delta', delta: { stop_reason: 'end_turn', stop_sequence: null }, usage: { output_tokens: 12 } });
446
+ yield event({ type: 'message_stop' });
447
+ }
448
+ const b = entry('assistant', { message: { role: 'assistant', content: [{ type: 'text', text: reply }] } });
449
+ await mirror([b]);
450
+ yield { type: 'assistant', parent_tool_use_id: null, uuid: b.uuid, session_id: sessionId, message: b.message };
451
+ yield { type: 'result', subtype: 'success', is_error: false, result: 'ok', session_id: sessionId, user_message_uuids: consumed, queued_turn_count: 0 };
452
+ await mirror([{ type: 'last-prompt' }]);
453
+ continue;
454
+ }
390
455
  const call = /^call (\S+) (.*)$/s.exec(command);
391
456
  if (call) {
392
457
  const id = `toolu_${randomUUID().slice(0, 8)}_${++calls}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-harness-claude",
3
- "version": "0.1.0-beta.57",
3
+ "version": "0.1.0-beta.59",
4
4
  "description": "The Claude Agent SDK as an AgentRun harness: the host's tools as its only tools, its model behind a loopback proxy, durable in AgentRun's own store.",
5
5
  "keywords": [
6
6
  "agentrun",
@@ -48,7 +48,7 @@
48
48
  "test": "node --test --test-concurrency=8 'test/*.test.mjs'"
49
49
  },
50
50
  "dependencies": {
51
- "@parcha/agentrun-kernel": "0.1.0-beta.57"
51
+ "@parcha/agentrun-kernel": "0.1.0-beta.59"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@anthropic-ai/claude-agent-sdk": "0.3.286",
@@ -77,6 +77,6 @@
77
77
  },
78
78
  "devDependencies": {
79
79
  "@anthropic-ai/claude-agent-sdk": "0.3.286",
80
- "@parcha/agentrun-dsl": "0.1.0-beta.57"
80
+ "@parcha/agentrun-dsl": "0.1.0-beta.59"
81
81
  }
82
82
  }