Skip to content

🌱 refactor(schema): seed default policy keys at DB init, not by bro#129

Merged
ZaxShen merged 1 commit into
devfrom
refactor/schema-seeded-defaults
Apr 26, 2026
Merged

🌱 refactor(schema): seed default policy keys at DB init, not by bro#129
ZaxShen merged 1 commit into
devfrom
refactor/schema-seeded-defaults

Conversation

@ZaxShen
Copy link
Copy Markdown
Contributor

@ZaxShen ZaxShen commented Apr 26, 2026

Summary

User feedback: 'Why don't make insert the default values by sql itself when setup DB? It can be part of the DB setup process?' and 'Why we waste so many lines on First-action chain?'

Both addressed.

Schema seeds defaults at DB creation

`mcp/trajectory-server/src/schema.sql` β€” `INSERT OR IGNORE` for the 3 default policy keys right after the `plugin_config` CREATE. Idempotent, safe to re-run on existing DBs (no overwrite of user choices).

CLAUDE.md first-action chain: 12 lines β†’ 4 lines

Before:

  • 'State check' with conditional default-write block (5 nested MCP calls)
  • 'Cache human_name' bullet
  • 'Resume' bullet

After:

  • Two parallel reads: `identity_get` + `issue_resume`
  • Welcome banner
  • Continue with ask

`config_get` removed from the always-call set β€” bro fetches lazily when a specific key matters.

Welcome banner: 3 variants β†’ 2

Dropped the 'first contact' variant. Pending-work-or-idle is enough; the user knows bro is active because of the 'Entering bro mode.' announcement and the banner that follows.

`tmb_defaults_applied` ledger event removed entirely

Schema seeding is a system action, not a bro decision. The ledger is for events bro emits; it shouldn't be polluted with init-state markers.

Test fixes (all caught locally)

  • `config_list with 0 entries returns empty object` β†’ `config_list returns schema-seeded defaults on a fresh DB`
  • `plugin_config has zero rows on init` β†’ `plugin_config has the 3 schema-seeded default policy keys on init`
  • The +1 / +3 entry tests now assert seeded keys appear alongside user-set entries
  • `tests/hooks/git-guards.test.sh` β€” drop redundant `INSERT INTO plugin_config` (now collides with schema seed)
  • `tests/mcp-integration/agent-bro-workflow.test.mjs` β€” DELETED (tested the removed onboarding sequence)

Fixture updates

  • `onboarding-anonymous.sql` β€” drops redundant config inserts + the `tmb_defaults_applied` row. Now seeds only the deliberately-blank identity row.
  • `onboarding-named.sql` β€” drops redundant config inserts; renames ledger event `tmb_defaults_applied` β†’ `tmb_user_named` (which is what the fixture actually represents).

Doc updates

  • `docs/architecture/FLOWS.md` Flow 1 sequence diagram redrawn (no bro-side default writes).
  • `docs/contributing/ENUMS.md` β€” drops `tmb_defaults_applied` from the event-type table.
  • `tests/manual/setup.md` β€” expected-state description updated.

Local verification

`bash tests/run-all.sh` β†’ `All test layers passed (L1 + L2 + L3).`

User feedback: 'Why don't make insert the default values by sql itself
when setup DB? It can be part of the DB setup process?' β€” and 'Why we
waste so many lines on First-action chain?'

Both addressed.

## Schema changes

`mcp/trajectory-server/src/schema.sql` β€” INSERT OR IGNORE for the 3
default policy keys (branching_model=github-flow, pr_target=main,
protected_branches=["main"]) right after the plugin_config CREATE.
Idempotent, safe to re-run on existing DBs (no overwrite of user
choices).

## CLAUDE.md compression

First-action chain shrinks from 12 lines to 4:

  ## Activation routine (every triggered message, no shortcuts)

  Two parallel MCP reads, then welcome banner, then the actual ask:
  - identity_get(agent='bro') β€” name (or null = user hasn't reonboarded yet)
  - issue_resume(agent='bro') β€” pending work, if any

  Policy keys are seeded at DB init; fetch via config_get only when needed.

Welcome banner shrinks from 3 variants to 2 (no 'first contact' variant
needed β€” pending-work or idle is enough).

`tmb_defaults_applied` ledger event removed entirely. Schema seeding is
silent; bro only logs ledger events for decisions it actually makes.

## Test updates

- `tests/hooks/git-guards.test.sh` β€” drop the redundant INSERT INTO
  plugin_config (now schema-seeded; INSERT was hitting UNIQUE constraint).
- `mcp/trajectory-server/src/test/config.test.ts` β€” three tests updated:
  'config_list with 0 entries' β†’ 'config_list returns schema-seeded defaults
  on a fresh DB'; the +1 and +3 entry tests now assert the seeded keys
  appear alongside user-set entries.
- `mcp/trajectory-server/src/test/schema.test.ts` β€” 'plugin_config has zero
  rows on init' β†’ 'plugin_config has the 3 schema-seeded default policy
  keys on init' (with concrete value assertions).
- `tests/mcp-integration/agent-bro-workflow.test.mjs` β€” DELETED. It tested
  the removed first-run onboarding sequence.

## Fixture updates

- `onboarding-anonymous.sql` β€” drop the redundant INSERT INTO plugin_config
  + the tmb_defaults_applied ledger row. Fixture now only seeds the
  deliberately-blank identity row.
- `onboarding-named.sql` β€” drop the redundant config inserts; rename the
  ledger event from `tmb_defaults_applied` to `tmb_user_named` (which is
  what the fixture actually represents β€” user explicitly set their name
  via tmb_reonboard).

## Doc updates

- FLOWS.md Flow 1 redrawn β€” sequence diagram now shows just the two
  parallel reads + welcome banner. No bro-side default writes.
- ENUMS.md β€” drop `tmb_defaults_applied` (no longer fired anywhere).
- tests/manual/setup.md β€” expected-state description updated.

## Local verification

bash tests/run-all.sh β†’ All test layers passed (L1 + L2 + L3).
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