Skip to content

Commit a5f2010

Browse files
jbreiteclaude
andauthored
Refactor AskUser tool to deferred client-rendered model (#25)
Replace server-side onQuestion/onStructuredQuestions handlers with a deferred tool that emits structured questions for the client to render. Each question now has a stable `id` for deterministic answer mapping. Simplifies config from `askUser: { onQuestion }` to `askUser: true`. Bumps version to 0.6.0 (breaking change). Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4b1c04d commit a5f2010

File tree

9 files changed

+76
-259
lines changed

9 files changed

+76
-259
lines changed

AGENTS.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ See also `CLAUDE.md` for development workflow and conventions.
126126

127127
| Tool | Purpose | Config Key |
128128
|------|---------|------------|
129-
| `AskUser` | Ask user clarifying questions | `askUser: { onQuestion? }` |
129+
| `AskUser` | Ask user clarifying questions | `askUser: true` |
130130
| `EnterPlanMode` | Enter planning/exploration mode | `planMode: true` |
131131
| `ExitPlanMode` | Exit planning mode with a plan | `planMode: true` |
132132
| `Skill` | Execute skills | `skill: { skills }` |
@@ -656,4 +656,3 @@ const cachedTool = cached(myTool, "MyTool", {
656656
store: new LRUCacheStore(500), // Max 500 entries
657657
});
658658
```
659-

README.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ await sandbox.destroy();
133133

134134
| Tool | Purpose | Config Key |
135135
|------|---------|------------|
136-
| `AskUser` | Ask user clarifying questions | `askUser: { onQuestion? }` |
136+
| `AskUser` | Ask user clarifying questions | `askUser: true` |
137137
| `EnterPlanMode` | Enter planning/exploration mode | `planMode: true` |
138138
| `ExitPlanMode` | Exit planning mode with a plan | `planMode: true` |
139139
| `Skill` | Execute skills | `skill: { skills }` |
@@ -221,12 +221,7 @@ You can configure tools with security restrictions and limits, and enable option
221221
```typescript
222222
const { tools, planModeState } = createAgentTools(sandbox, {
223223
// Enable optional tools
224-
askUser: {
225-
onQuestion: async (question) => {
226-
// Return user's answer, or undefined to return awaiting_response
227-
return await promptUser(question);
228-
},
229-
},
224+
askUser: true,
230225
planMode: true, // Enables EnterPlanMode and ExitPlanMode
231226
skill: {
232227
skills: discoveredSkills, // From discoverSkills()
@@ -917,7 +912,7 @@ Creates a set of agent tools bound to a sandbox instance.
917912

918913
### Optional Tools (also available via config)
919914

920-
- `createAskUserTool(onQuestion?)` - Ask user for clarification
915+
- `createAskUserTool(config?)` - Emit a deferred AskUser tool call for the client
921916
- `createEnterPlanModeTool(state)` - Enter planning/exploration mode
922917
- `createExitPlanModeTool(state, onPlanSubmit?)` - Exit planning mode with a plan
923918
- `createSkillTool(skills)` - Execute loaded skills

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bashkit",
3-
"version": "0.5.3",
3+
"version": "0.6.0",
44
"description": "Agentic coding tools for the Vercel AI SDK",
55
"type": "module",
66
"main": "./dist/index.js",

src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ export type {
3838
// Result type from createAgentTools
3939
AgentToolsResult,
4040
// AskUser tool
41-
AskUserError,
41+
AskUserAnswers,
42+
AskUserInput,
4243
AskUserOutput,
43-
AskUserResponseHandler,
44-
QuestionOption,
45-
StructuredQuestion,
44+
AskUserQuestion,
45+
AskUserQuestionOption,
46+
AskUserToolConfig,
4647
// Sandbox tools
4748
BashError,
4849
BashOutput,

src/tools/AGENTS.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The tools module implements all 15 AI agent tools in BashKit. These tools bridge
1212
| `edit.ts` | String-based find/replace editing with uniqueness validation |
1313
| `glob.ts` | Pattern-based file discovery using find command |
1414
| `grep.ts` | Ripgrep-powered content search with context and filtering |
15-
| `ask-user.ts` | Interactive Q&A with simple and structured question formats |
15+
| `ask-user.ts` | Deferred structured user Q&A rendered by the client |
1616
| `enter-plan-mode.ts` | Enter planning mode for explore-then-execute workflows |
1717
| `exit-plan-mode.ts` | Exit planning mode and submit plan for approval |
1818
| `skill.ts` | Activate pre-loaded skills from SKILL.md files |
@@ -32,7 +32,7 @@ The tools module implements all 15 AI agent tools in BashKit. These tools bridge
3232
- `createEditTool(sandbox, config?)` -- String replacement editing
3333
- `createGlobTool(sandbox, config?)` -- File pattern matching
3434
- `createGrepTool(sandbox, config?)` -- Content search with ripgrep
35-
- `createAskUserTool(config?)` -- User interaction tool
35+
- `createAskUserTool(config?)` -- Deferred user interaction tool
3636
- `createEnterPlanModeTool(state, onEnter?)` -- Planning mode entry
3737
- `createExitPlanModeTool(onPlanSubmit?)` -- Planning mode exit
3838
- `createSkillTool(config)` -- Skill activation
@@ -44,14 +44,14 @@ The tools module implements all 15 AI agent tools in BashKit. These tools bridge
4444
### Output Types
4545
Each tool exports `<Name>Output` for success and `<Name>Error` for errors:
4646
- Sandbox tools: `BashOutput | BashError`, `ReadOutput | ReadError`, etc.
47-
- Interactive tools: `AskUserOutput | AskUserError`, etc.
47+
- Interactive tools: `AskUserOutput`, etc.
4848
- Workflow tools: `TaskOutput | TaskError`, `TodoWriteOutput | TodoWriteError`
4949
- Web tools: `WebSearchOutput | WebSearchError`, `WebFetchOutput | WebFetchError`
5050

5151
### Configuration Types
5252
- `AgentConfig` -- Top-level config for createAgentTools()
5353
- `ToolConfig` -- Per-tool config (timeout, allowedPaths, maxFileSize, etc.)
54-
- `AskUserConfig` -- Ask user handlers
54+
- `AskUserConfig` -- AskUser AI SDK tool options
5555
- `SkillConfig` -- Skill metadata and sandbox
5656
- `TaskToolConfig` -- Sub-agent configuration (includes optional `budget` for auto-wiring cost tracking)
5757
- `ModelRegistryConfig` -- Model registry config (provider, apiKey) for fetching model info
@@ -66,7 +66,7 @@ Each tool exports `<Name>Output` for success and `<Name>Error` for errors:
6666
- Bash, Read, Write, Edit, Glob, Grep -- Direct sandbox operations via Sandbox interface
6767

6868
**Interactive Tools** (opt-in via config):
69-
- AskUser -- User Q&A with simple and structured formats
69+
- AskUser -- Deferred structured user Q&A rendered by the client
7070
- EnterPlanMode, ExitPlanMode -- Plan-then-execute workflow
7171
- Skill -- Load specialized instructions from SKILL.md files
7272

@@ -81,7 +81,7 @@ Each tool exports `<Name>Output` for success and `<Name>Error` for errors:
8181
### Data Flow
8282

8383
1. **Tool Creation**: `createAgentTools()` → individual `create*Tool()` factories → `tool()` from AI SDK
84-
2. **Execution**: AI model calls tool → `execute()` function → sandbox operation or external API → return Output or Error
84+
2. **Execution**: AI model calls tool → `execute()` function or deferred client round-trip → sandbox operation or external API → return Output or Error
8585
3. **Caching** (optional): `resolveCache()` wraps cacheable tools with `cached()` from cache module
8686
4. **Model Registry** (optional): `createAgentTools()` fetches model info (pricing + context lengths) from a provider (e.g., OpenRouter). Data is shared with budget tracking and returned as `openRouterModels` in the result.
8787
5. **Budget** (optional): `createAgentTools()` creates a `BudgetTracker` from config, using pricing derived from model registry or manual overrides. Returns it for wiring into `onStepFinish`/`stopWhen`. Auto-wires into Task tool sub-agents.

0 commit comments

Comments
 (0)