SPB Git

Repository Public License

09-claude-and-builder-agent.md 3.3 KB

# 9. Claude integration and the builder agent

Adapter. A dedicated Anthropic API client: streaming, tool use and structured outputs as currently documented, retry with backoff, timeouts, rate-limit handling, cancellation, token accounting, request IDs in logs. Check whether an official SDK exists for Swift; otherwise write a thin, well-tested client. Use prompt caching for stable context such as the catalog summary if the current API supports it.

First-run setup and settings. API key add/test/remove (Keychain); model list taken from what the account actually returns; separate planning and implementation models if available; maximum budget per build; maximum tool calls; per-project token usage with estimated and actual cost; privacy disclosure; a preview of exactly which project context will be sent, with opt-in. Offline, catalog apps keep working and Claude features show an explicit "unavailable" state.

Agent responsibilities (one agent, sections of one instruction set): intent analysis, component planning, UX layout, data architecture, logic wiring, minimal code generation, QA by running real tools, permission review, publishing only after verification and approval.

Tool contract. Every tool has a JSON schema, explicit scope, authorization check, structured errors, an audit entry, dry-run support, and idempotency where possible. Minimum set:

  • catalog.search, catalog.inspect, catalog.examples
  • project.create, project.read, project.patch, project.snapshot, project.rollback
  • ui.createPage, ui.addComponent, ui.setProperties, ui.connectAction, ui.preview
  • data.createSchema, data.import, data.query, data.migrate
  • logic.createWorkflow, logic.bind, logic.validate
  • code.read, code.proposePatch, code.runTests, code.lint
  • runtime.start, runtime.stop, runtime.logs
  • publisher.prepare, publisher.validate, publisher.publishLocal
  • security.requestPermission, security.inspectCapabilities

No raw shell tool by default. File, network, and process actions need scoped capabilities, and sensitive or irreversible ones need user confirmation.

Generation pipeline.

  1. Parse the request into a typed AppIntent with acceptance criteria.
  2. Resolve essential ambiguity: a few focused questions at most, otherwise reversible defaults.
  3. Draft the AppBlueprint.
  4. Query catalog and recipes; compute component coverage.
  5. Assemble UI and standard logic from catalog components.
  6. Generate only the missing logic, in isolation (ADR 0003).
  7. Validate schemas, types, bindings, data flow, accessibility, permissions.
  8. Start the preview and exercise the critical journeys.
  9. Repair failures with bounded retries and real diagnostics.
  10. Present the result, what was not implemented, real test status, and publish options.

Progress shown to the user (intent parsed, components selected, layout generated, data model created, preview running, tests complete) is driven by real tool events, which are all persisted. Budgets and loop limits stop runaway runs; the user can inspect the plan and cancel at any time. Do not promise a number of seconds.

Agent evaluation. Maintain a fixed set of 10–20 prompts with expected blueprint properties. Track valid-blueprint rate, component coverage, tool calls, and tokens per build, so changes to the agent's instructions are measured rather than guessed.

Files main
Menu

Theme