BrewSession API Extension
Core Workflow
- Inspect existing patterns before editing:
Sources/BrewKit/BrewSession/*Sources/BrewKit/BrewModels/*Tests/BrewKitTests/*
- Read
TodoLists/BrewSession-TODO.mdto identify the current coverage state and the exact built-in command forms being added or changed. - Confirm command behavior from the most local reliable source first:
- Run
brew commandsfor the built-in command list when Homebrew is available. - Use
brew help <command>and the Homebrew manpage for flags and output details.
- Run
- Choose the API shape:
- Add a strong typed
BrewSessionmethod for common, user-facing workflows. - Use or extend
BrewBuiltinCommandfor generic built-in command coverage. - Prefer structured return types when the command has stable
--jsonor--json=v2output.
- Add a strong typed
- Add or update models in
Sources/BrewKit/BrewModelsonly when the API returns structured data. - Add or update command APIs in
Sources/BrewKit/BrewSession/BrewSession+Command+<Name>.swift. - Add focused tests in
Tests/BrewKitTests, reusingMockCommandRunnerfor command execution behavior. - Update
TodoLists/BrewSession-TODO.mdin the same change:- Mark newly supported command forms as
[x]. - Add newly discovered built-in command forms as
[ ]. - Keep descriptions short and aligned with the implemented API behavior.
- Update the
更新时间value when the TODO file changes.
- Mark newly supported command forms as
API Rules
- Use
asyncmethods for every API that launches a brew process. - Use synchronous helpers only for pure local work such as argument construction, parsing, and lightweight getters.
- Expose typed errors with
throws(BrewSessionError)on public APIs that can fail. - Reuse
runCommand(args:)andstreamCommand(args:)as execution primitives. - Return structured model types instead of raw strings when output shape is stable.
- Keep raw
BrewCommandResultreturns for commands whose output is primarily human-readable or pass-through. - Preserve existing naming style, overload shape, access control, and test style.
Documentation Rules
- Document public APIs with bilingual comments.
- Put English first and Chinese second.
- Keep comments factual: describe command behavior, parameters, return value, and notable error conditions.
- Avoid broad Homebrew explanations that can drift from the actual implementation.
Test Rules
- Cover argument construction and command mapping.
- Cover JSON parsing and model decoding when structured output is introduced.
- Cover error mapping with
BrewSessionErrorwhen behavior changes. - Confirm
TodoLists/BrewSession-TODO.mdreflects every supported command form added or changed. - Use targeted tests first:
swift test --filter <TargetedTests>
- Run
swift buildafter implementation. - Run full
swift testwhen changes touch shared parsing, command execution, or public model contracts.
Commit Guidance
Only create commits when the user asks for git work. If committing, keep commits scoped:
feat(models): add <ModelName> for <purpose>feat(session): add <apiName> for brew <command>test(session): cover <apiName> behavior and mapping