Skip to content

feat(desktop): dynamic nest AGENTS.md regeneration#583

Closed
wpfleger96 wants to merge 5 commits into
mainfrom
wpfleger/dynamic-nest-agents
Closed

feat(desktop): dynamic nest AGENTS.md regeneration#583
wpfleger96 wants to merge 5 commits into
mainfrom
wpfleger/dynamic-nest-agents

Conversation

@wpfleger96
Copy link
Copy Markdown
Collaborator

@wpfleger96 wpfleger96 commented May 14, 2026

Summary

  • Adds a <!-- BEGIN SPROUT MANAGED --> / <!-- END SPROUT MANAGED --> demarcated section to ~/.sprout/AGENTS.md that the desktop app regenerates whenever relevant state changes
  • New regenerate_nest_context() function in nest.rs renders active agents, workspace config, and CLI reference into the managed section while preserving user edits outside the markers
  • Hooks wired into all mutation paths: persona CRUD (create/update/delete/activate/install pack/uninstall pack), agent CRUD (create/delete/update), workspace switch, and app startup
  • Atomic writes via tempfile::NamedTempFile + persist() prevent partial writes on crash or concurrent triggers
  • Robust marker parsing: line-start anchoring, ordered search, orphan cleanup, Markdown cell escaping
  • 19 unit tests including 7 adversarial cases (marker ordering, duplicates, code-block false positives, pipe/newline escaping, idempotency)

Context

Agents operating in ~/.sprout/ had no reliable way to discover who else is in the workspace. The static AGENTS.md template told agents about directory layout and MCP tools but said nothing about the workspace's current inhabitants. This makes cross-agent coordination brittle — agents can't @mention teammates they don't know exist.

The dynamic section is eventually consistent: agents read AGENTS.md at session/new time, so updates become visible on the next session rotation.

Merge order: This PR should merge after #585 (CLI grouped command format) — the CLI Quick Reference section uses the grouped syntax.

@wpfleger96 wpfleger96 requested a review from wesbillman as a code owner May 14, 2026 18:51
@wpfleger96 wpfleger96 force-pushed the wpfleger/dynamic-nest-agents branch from c8fb76c to 6220ec5 Compare May 14, 2026 23:35
AGENTS.md in ~/.sprout is now dynamically regenerated whenever personas,
agents, or workspace config changes. Agents discover their teammates on
every fresh session via a managed section demarcated by HTML comment
markers. User edits outside the markers are preserved across
regenerations.
BackendKind and RespondTo are only used in test helper constructors.
Fixes identified by crossfire review (Codex + Gemini) and plan author:

- Use tempfile::NamedTempFile for atomic writes instead of deterministic
  .tmp path that races under concurrent regeneration triggers
- Enforce ordered BEGIN/END marker search with line-start anchoring to
  prevent inverted slicing when markers are out of order or mid-line
- Strip orphan BEGIN markers before appending new managed section
- Escape pipe and newline characters in agent/persona names to prevent
  Markdown table corruption
- Rename "Role" column to "Persona" (display_name is a name, not a role)
- Move regenerate_nest_context calls outside lock scope in all mutation
  hooks to reduce lock hold time and eliminate future deadlock risk
- Add 7 adversarial unit tests: marker ordering, orphan cleanup,
  duplicates, code-block false positives, pipe/newline escaping,
  idempotency
nest.rs grew to 770 lines with regenerate_nest_context, marker
helpers, and 19 unit tests. The 500-line default is too tight for
this file — override to 800 following the established pattern.
@wpfleger96 wpfleger96 force-pushed the wpfleger/dynamic-nest-agents branch from 6220ec5 to 74a2c1a Compare May 15, 2026 19:51
wpfleger96 added a commit that referenced this pull request May 15, 2026
…uplication

base_prompt.md (injected every turn via [Base]) already has a comprehensive
CLI reference table covering all 11 command groups. The CLI_QUICK_REFERENCE
constant in nest.rs was a less complete duplicate (4 commands). AGENTS.md's
dynamic section now focuses on what's unique to it: active agents and
workspace info.

Also bumps personas.rs file size override from 900 to 950 to accommodate
the merge_personas inequality checks added in the review-fix commit.
@wpfleger96
Copy link
Copy Markdown
Collaborator Author

Consolidated into #584 — both PRs modify agent context (base prompt + AGENTS.md dynamic section) and are better reviewed/tested together. All commits preserved. Also removed the CLI_QUICK_REFERENCE duplication since base_prompt.md's CLI table makes it redundant.

@wpfleger96 wpfleger96 closed this May 15, 2026
wpfleger96 added a commit that referenced this pull request May 18, 2026
…uplication

base_prompt.md (injected every turn via [Base]) already has a comprehensive
CLI reference table covering all 11 command groups. The CLI_QUICK_REFERENCE
constant in nest.rs was a less complete duplicate (4 commands). AGENTS.md's
dynamic section now focuses on what's unique to it: active agents and
workspace info.

Also bumps personas.rs file size override from 900 to 950 to accommodate
the merge_personas inequality checks added in the review-fix commit.
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