Skip to content

fix: resolve readline conflict, implement /reset, update model defaults in ch08#6

Open
octo-patch wants to merge 1 commit intojiji262:mainfrom
octo-patch:fix/ch08-readline-conflict-reset-model
Open

fix: resolve readline conflict, implement /reset, update model defaults in ch08#6
octo-patch wants to merge 1 commit intojiji262:mainfrom
octo-patch:fix/ch08-readline-conflict-reset-model

Conversation

@octo-patch
Copy link
Copy Markdown

Problem

Chapter 08 (08-build-your-own.md) contains several bugs in the tutorial code that readers encounter when following along:

  1. Readline conflictindex.ts creates a readline.Interface and passes it to PermissionChecker, but CLI's constructor also creates its own readline.Interface. Two competing readline instances both attached to stdin causes garbled input handling in interactive mode.

  2. /reset command does nothing — The /reset case in CLI.ts only logs [会话已重置] but never calls any actual reset. The comment even acknowledges this as a TODO (// 这里通过事件或直接调用实现).

  3. Retired model in mermaid diagram — The final architecture diagram references claude-3-7-sonnet, which was retired on February 19, 2026.

  4. Outdated default model — Default model is claude-opus-4-5 (legacy); claude-sonnet-4-6 is the current recommended model.

  5. Unusual max_tokens value8096 should be 8192 (standard power-of-two).

Solution

  • CLI constructor now accepts an optional readline.Interface parameter; when provided, it reuses the shared instance instead of creating a new one. index.ts passes the same rl to both PermissionChecker and CLI.
  • AgentLoop.reset() method added, delegating to ContextManager.reset(). The /reset case in CLI now calls this.agent.reset().
  • Default model updated from claude-opus-4-5 to claude-sonnet-4-6 in both AgentLoop.ts and index.ts code blocks.
  • Mermaid diagram updated from retired claude-3-7-sonnet to claude-sonnet-4-6.
  • max_tokens corrected from 8096 to 8192.

Testing

All changes are in the tutorial markdown file. The code snippets were manually verified for correctness against the Anthropic TypeScript SDK API surface.

…ults in ch08

- CLI constructor now accepts optional readline.Interface to share with
  PermissionChecker, eliminating two competing readline instances on stdin
- Add AgentLoop.reset() method that delegates to ContextManager.reset()
  so the /reset command actually clears conversation history
- Update default model from retired claude-opus-4-5 to claude-sonnet-4-6
- Fix max_tokens from 8096 to 8192 (standard power-of-two value)
- Fix mermaid diagram referencing retired claude-3-7-sonnet model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant