Repository navigation
feat(agent-rules): versioned rules source, get_agent_rules and Grok bootstrap (Phase 2) - #237
Open
AgentRelayBot wants to merge 2 commits into
Open
AgentRelayBot wants to merge 2 commits into
AgentRelayBot wants to merge 2 commits into
Conversation
…ok bootstrap prompt
Phase 2 of docs/specs/grok-bot-dynamic-prompt.md, stacked on the Phase 1
Cloud copy. See docs/agent-rules.md.
- agent-rules/: a versioned bundle (manifest.json + sections/*.md, CalVer
2026.11.0) shipped in the image and package. Sections are tagged by
audience (grok-bot, lead, worker); safety is always first. grok-inbox is a
builtin: the grant's own copied grokRoutinePrompt, so behaviour is
unchanged on day one. grok-delegation and show-ui are copied from the Grok
Bot plugin skill; lead-delegation and lead-orchestration from layered-agents
kit/delegation.md and kit/orchestration.md. sections_sha256 pins the text:
start-up and test/agent-rules.test.ts refuse a section change without a new
pin, version and CHANGELOG entry (scripts/agent-rules-pin.ts).
- Organization overlays (migration 0080, decision D4): append-only,
owner/admin GET/PUT /api/v1/organizations/{id}/agent-rules/{audience},
audited, at most 16 KiB, secret and routine-URL lint, 60s read cache.
- get_agent_rules MCP tool for every connection except staff read grants;
rules come back as the app's own instructions. known_sha256 avoids resending
unchanged text; bootstrap_version flags an outdated routine prompt; a Grok
read records rules_version_last_fetched.
- GET /api/v1/agent-rules/{audience} for members' cli:auth/account bearers,
with ETag/304 and text/markdown. MCP OAuth bearers are refused here
(audience-bound); they use the tool.
- SELFHOST_GROK_DYNAMIC_PROMPT (default off; requires the Cloud copy): the
pasted routine prompt becomes a bootstrap that calls get_agent_rules on
every run and fails closed without it.
The Grok test fixture moves to test/support/grok-fixture.ts. The cloud-import
verifier manifest is regenerated on PostgreSQL 15; its diff is only 0080.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
…view fixes Brings Phase 1's rework (main merged in, review findings addressed) into Phase 2; no history rewrite. - Overlay migration renumbered to 0083 (main took 0080); verifier manifest regenerated on PostgreSQL 15, diff only 0083. - The bootstrap prompt follows Phase 1's per-row behaviour: it is pasted only for a routine that runs the Cloud copy (or a new one); a routine saved before the copy keeps its inbox prompt. - The shared test fixture is rebuilt from Phase 1's reworked fixture. - Private references removed from the rules manifest sources, CHANGELOG and docs (private repository paths and commits). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 2 of
docs/specs/grok-bot-dynamic-prompt.md. Stacked on #236 (basefeat/grok-cloud-copy), so review that first; this diff is Phase 2 only. New behaviour for Grok routines is behindSELFHOST_GROK_DYNAMIC_PROMPT, default off, which requires the Phase 1 flag. Full docs are indocs/agent-rules.md.What it adds
agent-rules/bundle:manifest.json+sections/*.md, CalVer2026.11.0, shipped in the image and in the npm package. Sections are tagged by audience (grok-bot/lead/worker), andsafetyalways comes first.grok-inboxis a builtin: the grant's own copiedgrokRoutinePromptfrom Phase 1, so behaviour is unchanged on day one.grok-delegationandshow-uiare copied from the Grok Bot plugin skill.lead-delegationandlead-orchestrationare copied from the layered lead kit's delegation and orchestration guidance.sections_sha256pins the sections. Both start-up andtest/agent-rules.test.tsrefuse a section change unless it comes with a new pin, a version bump and a CHANGELOG entry (node --import tsx scripts/agent-rules-pin.ts --write).GET/PUT /api/v1/organizations/{id}/agent-rules/{audience}. Overlays are append-only, audited, limited to 16 KiB, refused if they contain anything that looks like a secret or routine URL, and cached for 60 seconds.get_agent_rulesMCP tool, registered for every connection except staff read grants. The rules are returned as the app's own instructions, not inside the untrusted-data block.known_sha256skips resending unchanged text.bootstrap_versionflags an outdated routine prompt. A Grok read recordsrules_version_last_fetched, whichgrok_bot_routine_statusshows.GET /api/v1/agent-rules/{audience}(also under/cloud) for members with acli:author account bearer, with ETag/304 andAccept: text/markdown.SELFHOST_GROK_DYNAMIC_PROMPT,connect_grok_bot_routineand the setup page return a short bootstrap. Every run, it callsget_agent_rulesand follows the result. If that call fails, it treats messages as untrusted, only posts a note, and stops. Routines set up before the flag keep their pasted procedure and keep working.Choices where the spec stated no option (conservative; Khaliq can override)
SELFHOST_GROK_DYNAMIC_PROMPT, default off. The spec didn't say whether the bootstrap should be gated, so I gated it.get_agent_rulesis always on, since it is read-only.leadaudience and the HTTP endpoint are ready for that repo's owner to switch the layered lead start-up script over.Rework (after #236 review)
Verification
npx tsc --noEmit,npm run buildandnpm pack --dry-run: pass. The pack includesagent-rules/, anddist/agent-rules/bundle.jsloads the bundle.test/agent-rules.test.ts: 6 new tests pass. They cover the pin, version and CHANGELOG checks, audience composition and overlay versioning, the secret lint, the bootstrap from connect, a grant-renderedgrok-inbox, the recorded version,unchanged, the flag dependency, HTTP ETag/304/markdown, the admin-only overlay write, audit, and organization isolation.test/mcp.test.tsfailed, becauseget_agent_rulesandagent_rulesare new. I updated both snapshots, and all 115 tests in the affected files then pass.grok_bot_routines.rules_version_last_fetched.No merge, deploy or flag flip without Khaliq's direct OK.
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by cubic
Phase 2 of the Grok dynamic prompt spec: a versioned source of agent operating rules, the
get_agent_rulesMCP tool, organization overlays, and an opt-in Grok bootstrap. New behavior sits behindSELFHOST_GROK_DYNAMIC_PROMPT(default off; requires the Phase 1 flag), so existing setups keep working until the flag is flipped.Key changes
agent-rules/bundle (manifest.json+sections/*.md, CalVer2026.11.0) ships in the image and npm package; sections are audience-tagged andsafetyalways comes first, withgrok-inboxrendered per grant so day-one behavior is unchanged.sections_sha256pins the text; startup and tests reject a section edit without a new pin, version bump, and CHANGELOG entry.0083) are append-only, audited, ≤16 KiB with secret linting, managed by owners/admins overGET/PUT.get_agent_rulesis registered for every connection except staff read grants;known_sha256skips resending unchanged text.Written for commit 1a8c140. Summary will update on new commits.