@claudebuddy/claudebuddy-agent-sdk 0.4.0 → 0.5.0
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.
- package/CHANGELOG.md +36 -0
- package/README.md +75 -3
- package/dist/agent.d.ts +12 -22
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +209 -224
- package/dist/agent.js.map +1 -1
- package/dist/engine.d.ts +7 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +234 -224
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp/client.d.ts +3 -0
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +13 -4
- package/dist/mcp/client.js.map +1 -1
- package/dist/providers/anthropic.d.ts +2 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +31 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/openai.d.ts +3 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +54 -3
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/sse.d.ts +3 -0
- package/dist/providers/sse.d.ts.map +1 -0
- package/dist/providers/sse.js +36 -0
- package/dist/providers/sse.js.map +1 -0
- package/dist/providers/types.d.ts +16 -0
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/session.d.ts +10 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +98 -4
- package/dist/session.js.map +1 -1
- package/dist/tools/agent-tool.d.ts.map +1 -1
- package/dist/tools/agent-tool.js +32 -9
- package/dist/tools/agent-tool.js.map +1 -1
- package/dist/tools/ask-user.d.ts +3 -2
- package/dist/tools/ask-user.d.ts.map +1 -1
- package/dist/tools/ask-user.js +16 -15
- package/dist/tools/ask-user.js.map +1 -1
- package/dist/tools/bash.d.ts +0 -3
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +79 -59
- package/dist/tools/bash.js.map +1 -1
- package/dist/tools/config-tool.d.ts +4 -3
- package/dist/tools/config-tool.d.ts.map +1 -1
- package/dist/tools/config-tool.js +20 -16
- package/dist/tools/config-tool.js.map +1 -1
- package/dist/tools/cron-tools.d.ts +3 -2
- package/dist/tools/cron-tools.d.ts.map +1 -1
- package/dist/tools/cron-tools.js +33 -29
- package/dist/tools/cron-tools.js.map +1 -1
- package/dist/tools/index.js +55 -53
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/lsp-tool.js +2 -2
- package/dist/tools/lsp-tool.js.map +1 -1
- package/dist/tools/mcp-resource-tools.d.ts +2 -1
- package/dist/tools/mcp-resource-tools.d.ts.map +1 -1
- package/dist/tools/mcp-resource-tools.js +44 -27
- package/dist/tools/mcp-resource-tools.js.map +1 -1
- package/dist/tools/plan-tools.d.ts +3 -2
- package/dist/tools/plan-tools.d.ts.map +1 -1
- package/dist/tools/plan-tools.js +24 -21
- package/dist/tools/plan-tools.js.map +1 -1
- package/dist/tools/send-message.d.ts +5 -4
- package/dist/tools/send-message.d.ts.map +1 -1
- package/dist/tools/send-message.js +24 -21
- package/dist/tools/send-message.js.map +1 -1
- package/dist/tools/session-state.d.ts +4 -0
- package/dist/tools/session-state.d.ts.map +1 -0
- package/dist/tools/session-state.js +9 -0
- package/dist/tools/session-state.js.map +1 -0
- package/dist/tools/task-tools.d.ts +19 -4
- package/dist/tools/task-tools.d.ts.map +1 -1
- package/dist/tools/task-tools.js +119 -31
- package/dist/tools/task-tools.js.map +1 -1
- package/dist/tools/team-tools.d.ts +7 -3
- package/dist/tools/team-tools.d.ts.map +1 -1
- package/dist/tools/team-tools.js +26 -22
- package/dist/tools/team-tools.js.map +1 -1
- package/dist/tools/todo-tool.d.ts +3 -2
- package/dist/tools/todo-tool.d.ts.map +1 -1
- package/dist/tools/todo-tool.js +24 -21
- package/dist/tools/todo-tool.js.map +1 -1
- package/dist/tools/tool-search.d.ts +2 -1
- package/dist/tools/tool-search.d.ts.map +1 -1
- package/dist/tools/tool-search.js +14 -13
- package/dist/tools/tool-search.js.map +1 -1
- package/dist/tools/update-goal.d.ts +9 -7
- package/dist/tools/update-goal.d.ts.map +1 -1
- package/dist/tools/update-goal.js +20 -21
- package/dist/tools/update-goal.js.map +1 -1
- package/dist/tools/worktree-tools.d.ts +0 -6
- package/dist/tools/worktree-tools.d.ts.map +1 -1
- package/dist/tools/worktree-tools.js +14 -6
- package/dist/tools/worktree-tools.js.map +1 -1
- package/dist/types.d.ts +31 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/compact.d.ts +5 -1
- package/dist/utils/compact.d.ts.map +1 -1
- package/dist/utils/compact.js +11 -1
- package/dist/utils/compact.js.map +1 -1
- package/dist/utils/permissions.d.ts +7 -0
- package/dist/utils/permissions.d.ts.map +1 -0
- package/dist/utils/permissions.js +39 -0
- package/dist/utils/permissions.js.map +1 -0
- package/dist/utils/retry.d.ts.map +1 -1
- package/dist/utils/retry.js +17 -2
- package/dist/utils/retry.js.map +1 -1
- package/docs/background-tasks.md +62 -0
- package/docs/runtime-progress.md +63 -0
- package/package.json +9 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.5.0 — 2026-09-10
|
|
4
|
+
|
|
5
|
+
- Apply tool permissions consistently to built-in, MCP, override and child tools;
|
|
6
|
+
isolate built-in mutable state by Agent session.
|
|
7
|
+
- Preserve terminal errors, cancellation and usage in prompt results; share budgets
|
|
8
|
+
across goal rounds, subagents and compaction.
|
|
9
|
+
- Forward cancellation to provider/MCP transports and retry waits. Preserve history
|
|
10
|
+
and clean up when consumers exit the query iterator early.
|
|
11
|
+
- Stream incremental text/tool arguments from Anthropic and OpenAI-compatible APIs;
|
|
12
|
+
execute tool calls only after complete responses. Preserve mutation barriers in
|
|
13
|
+
tool scheduling and parallelize only explicitly safe adjacent reads.
|
|
14
|
+
- Checkpoint conversation progress during execution and record replayable semantic
|
|
15
|
+
events. Resume unknown tool outcomes explicitly without automatically replaying
|
|
16
|
+
side effects.
|
|
17
|
+
- Implement query-scoped background Bash/subagent execution with task output,
|
|
18
|
+
waiting, cancellation, bounded output and completion notifications. Join work
|
|
19
|
+
before final accounting and cancel it on interrupted runs.
|
|
20
|
+
- Disable scheduler/remote-trigger placeholders in model tool schemas. Clarify that
|
|
21
|
+
the current LSP fallback performs lexical search, not semantic analysis.
|
|
22
|
+
- Add 69 offline regression tests, including local HTTP/MCP transport coverage.
|
|
23
|
+
|
|
24
|
+
### Migration notes
|
|
25
|
+
|
|
26
|
+
- An explicit empty allowedTools list exposes no tools. Query overrides cannot widen
|
|
27
|
+
constructor allow/deny bounds. Default bypassPermissions remains unchanged.
|
|
28
|
+
- Unsupported sandbox enforcement throws. Only one query/goal may own an Agent at
|
|
29
|
+
a time. Use separate Agents for concurrent conversations.
|
|
30
|
+
- Pass agent.getToolState() to session-specific built-in helper functions. Global
|
|
31
|
+
helper defaults no longer configure Agent instances.
|
|
32
|
+
- Check prompt().is_error and subtype before treating output as success.
|
|
33
|
+
- Persistence now occurs during execution; set persistSession:false for host-owned
|
|
34
|
+
storage. Session storage remains single-writer, without exactly-once side effects.
|
|
35
|
+
- Background work is scoped to its creating query; it is not a cross-query daemon.
|
|
36
|
+
See docs/background-tasks.md and docs/runtime-progress.md for limits.
|
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ClaudeBuddy Agent SDK (TypeScript)
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@claudebuddy/claudebuddy-agent-sdk)
|
|
4
4
|
[](https://nodejs.org)
|
|
5
5
|
[](./LICENSE)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
claudebuddy Agent SDK that runs the full agent loop **in-process** — no subprocess or CLI required. Supports both **Anthropic** and **OpenAI-compatible** APIs. Deploy anywhere: cloud, serverless, Docker, CI/CD.
|
|
8
8
|
|
|
9
|
-
Also available in **Go**: [open-agent-sdk-go](https://github.com/claudebuddy/claudebuddy-agent-sdk)
|
|
10
9
|
|
|
11
10
|
## Get started
|
|
12
11
|
|
|
@@ -486,6 +485,79 @@ Start the web UI:
|
|
|
486
485
|
npx tsx examples/web/server.ts
|
|
487
486
|
```
|
|
488
487
|
|
|
488
|
+
## Background tasks
|
|
489
|
+
|
|
490
|
+
`Bash` and `Agent` support `run_in_background: true`, returning a `task_id` for
|
|
491
|
+
`TaskOutput` and `TaskStop`. Tasks execute within the current query; the engine
|
|
492
|
+
joins them before its final result and cancels them on interruption. See
|
|
493
|
+
[background execution](docs/background-tasks.md) for output, cancellation and
|
|
494
|
+
lifecycle details. Scheduler placeholders are currently excluded from model tools.
|
|
495
|
+
|
|
496
|
+
## Streaming and recovery
|
|
497
|
+
|
|
498
|
+
Set `includePartialMessages: true` to receive real text/tool argument deltas from
|
|
499
|
+
Anthropic and OpenAI-compatible transports. The final `assistant` event contains the
|
|
500
|
+
complete response. Tool calls execute only after completion; adjacent explicitly
|
|
501
|
+
safe reads may run concurrently, preserving mutation barriers.
|
|
502
|
+
|
|
503
|
+
With persistence enabled, progress is checkpointed during execution and semantic
|
|
504
|
+
events can be replayed with `readSessionEvents(sessionId, afterId?)`. Unknown tool
|
|
505
|
+
outcomes are marked on resume and are not automatically replayed. See
|
|
506
|
+
[streaming, scheduling and recovery](docs/runtime-progress.md) for usage, failure
|
|
507
|
+
semantics and the single-writer storage requirement.
|
|
508
|
+
|
|
509
|
+
## Runtime reliability and compatibility
|
|
510
|
+
|
|
511
|
+
Each `Agent` owns its conversation and built-in tool state. Only one query or goal
|
|
512
|
+
may run on an Agent at a time; use separate Agents for concurrent conversations.
|
|
513
|
+
Children intentionally share the parent session state, cancellation signal and
|
|
514
|
+
execution budget, while inheriting its available tools and permission policy.
|
|
515
|
+
`clear()` clears conversation and tool state, retaining connected MCP servers.
|
|
516
|
+
Configure session-specific helpers with the Agent's state handle, for example
|
|
517
|
+
`setQuestionHandler(handler, agent.getToolState())`. Helpers called without a state
|
|
518
|
+
handle retain legacy standalone behavior and do not configure Agent instances.
|
|
519
|
+
|
|
520
|
+
Tool allow/deny lists apply to built-in, MCP and replacement tools. Query overrides
|
|
521
|
+
can narrow the constructor's lists; `allowedTools: []` exposes no tools. Denials win.
|
|
522
|
+
|
|
523
|
+
| Permission mode | Execution policy |
|
|
524
|
+
| --- | --- |
|
|
525
|
+
| `bypassPermissions` (default) | Available tools are permitted; a supplied `canUseTool` callback may still deny. |
|
|
526
|
+
| `plan` | Only tools declaring `isReadOnly() === true`; callbacks cannot permit mutations. |
|
|
527
|
+
| `default`, `auto` | Read-only or explicitly allowed tools are preapproved; other tools require an allowing callback. `auto` currently uses this deterministic policy. |
|
|
528
|
+
| `dontAsk` | Read-only or explicitly allowed tools only. |
|
|
529
|
+
| `acceptEdits` | Also preapproves the built-in file and notebook edit/write tools; other mutations require an allowing callback. |
|
|
530
|
+
|
|
531
|
+
A supplied callback is still consulted for preapproved tools. Tool metadata and
|
|
532
|
+
custom tool implementations are trusted host code. These policies do not provide
|
|
533
|
+
OS isolation: requesting sandbox enforcement throws an explicit unsupported error.
|
|
534
|
+
Goal runs additionally expose their internal goal-reporting tool.
|
|
535
|
+
|
|
536
|
+
`prompt()` returns `subtype`, `is_error`, `errors` and `total_cost_usd` alongside text
|
|
537
|
+
and usage. Check `is_error` before treating text as a completed answer. Provider
|
|
538
|
+
failures, cancellation, exhausted turns and budget limits remain observable.
|
|
539
|
+
Invalid configuration and overlapping runs throw. Goal execution emits one final
|
|
540
|
+
aggregate result and stops on provider failure, cancellation or a budget limit.
|
|
541
|
+
|
|
542
|
+
`maxBudgetUsd` covers one ordinary query, or all rounds of one goal, including child
|
|
543
|
+
agents and compaction summaries. Usage and costs accumulate in the same ledger.
|
|
544
|
+
The limit checks whether another request may start; an in-flight request can exceed
|
|
545
|
+
it. Cost is estimated from configured pricing and reported token usage.
|
|
546
|
+
|
|
547
|
+
Cancellation propagates to Anthropic/OpenAI transports, retry waits, compaction,
|
|
548
|
+
child agents and MCP requests. Custom tools/providers must cooperate with the
|
|
549
|
+
supplied abort signal; cancellation cannot undo completed side effects. Breaking
|
|
550
|
+
out of a query iterator preserves conversation history and releases its run lock.
|
|
551
|
+
|
|
552
|
+
Run offline regression tests and compile the SDK:
|
|
553
|
+
|
|
554
|
+
```bash
|
|
555
|
+
npm run test:all
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
`npm run test:examples` executes the examples separately; these may use live model
|
|
559
|
+
APIs and require credentials.
|
|
560
|
+
|
|
489
561
|
## Star History
|
|
490
562
|
|
|
491
563
|
<a href="https://www.star-history.com/?repos=claudebuddy%2Fclaudebuddy-agent-sdk&type=timeline&legend=top-left">
|
package/dist/agent.d.ts
CHANGED
|
@@ -34,6 +34,9 @@ export declare class Agent {
|
|
|
34
34
|
private abortCtrl;
|
|
35
35
|
private currentEngine;
|
|
36
36
|
private hookRegistry;
|
|
37
|
+
private sessionState;
|
|
38
|
+
private activeRun;
|
|
39
|
+
private closed;
|
|
37
40
|
constructor(options?: AgentOptions);
|
|
38
41
|
/**
|
|
39
42
|
* Resolve API type from options, env, or model name heuristic.
|
|
@@ -54,38 +57,25 @@ export declare class Agent {
|
|
|
54
57
|
* Async initialization: connect MCP servers, register agents, resume sessions.
|
|
55
58
|
*/
|
|
56
59
|
private setup;
|
|
57
|
-
/**
|
|
58
|
-
* Run a query with streaming events.
|
|
59
|
-
*/
|
|
60
|
+
/** Run one query, or an explicitly configured goal, with exclusive session ownership. */
|
|
60
61
|
query(prompt: string | any[], overrides?: Partial<AgentOptions>): AsyncGenerator<SDKMessage, void>;
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
/** A controller and ledger outlive every round/child in this run. */
|
|
63
|
+
private withRun;
|
|
64
|
+
private queryOnce;
|
|
65
|
+
/** Collect text and retain the final status instead of hiding engine failures. */
|
|
65
66
|
prompt(text: string, overrides?: Partial<AgentOptions>): Promise<QueryResult>;
|
|
66
|
-
/**
|
|
67
|
-
* Goal-driven autonomous loop.
|
|
68
|
-
*
|
|
69
|
-
* Runs the agent toward `goal` over up to `maxRounds` rounds. Unlike a single
|
|
70
|
-
* `query`, the agent keeps working ("give it a task and let it run until done")
|
|
71
|
-
* and only stops when:
|
|
72
|
-
* - it calls the injected `update_goal` tool with goal_status="complete", or
|
|
73
|
-
* - it reports goal_status="blocked", or
|
|
74
|
-
* - `maxRounds` is exhausted (returns with a helpful error event), or
|
|
75
|
-
* - it is aborted.
|
|
76
|
-
*
|
|
77
|
-
* The `update_goal` internal tool is injected into the tool pool and a
|
|
78
|
-
* goal-mode system prompt is appended, so the agent knows it should keep
|
|
79
|
-
* working autonomously and how to signal completion.
|
|
80
|
-
*/
|
|
67
|
+
/** Goal rounds share cancellation, accounting and a run-local goal report. */
|
|
81
68
|
runGoal(goal: string, overrides?: {
|
|
82
69
|
maxGoalRounds?: number;
|
|
83
70
|
turnsPerRound?: number;
|
|
84
71
|
}): AsyncGenerator<SDKMessage, void>;
|
|
72
|
+
private runGoalInternal;
|
|
85
73
|
/**
|
|
86
74
|
* Get conversation messages.
|
|
87
75
|
*/
|
|
88
76
|
getMessages(): Message[];
|
|
77
|
+
/** Pass this session handle to built-in state helpers such as setQuestionHandler. */
|
|
78
|
+
getToolState(): Map<string, unknown>;
|
|
89
79
|
/**
|
|
90
80
|
* Reset conversation history.
|
|
91
81
|
*/
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,UAAU,
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KA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