Skip to content

feat(git): persistent-state allowlist primitive (S4, #383) - #394

Merged
vybe merged 1 commit into
Abilityai:mainfrom
AndriiPasternak31:feature/383-persistent-state-allowlist
Apr 18, 2026
Merged

vybe merged 1 commit into
Abilityai:mainfrom
AndriiPasternak31:feature/383-persistent-state-allowlist

Conversation

@AndriiPasternak31

Copy link
Copy Markdown
Contributor

Summary

Adds the persistent-state allowlist primitive from proposal §S4 so a
later reset-preserve-state operation can name which workspace files must
survive a template-level reset.

The default list (matching the verified s3_fix_verified.sh harness):

persistent_state:
  - workspace/**
  - .trinity/**
  - .mcp.json
  - .claude.json
  - .claude/.credentials.json

Why it works this way

template.yaml is read only at agent creation (template_service.py
caches it for 10 minutes), so sync/reset paths can't re-read it at
runtime. The list is therefore materialized into
.trinity/persistent-state.yaml at creation time and read from disk
thereafter — same split as .env / .env.example. Operators can edit
the on-disk file per-agent.

What this PR changes

  • src/backend/services/git_service.py
    — DEFAULT_PERSISTENT_STATE constant
    — materialize_persistent_state(agent_name, patterns) (heredoc writer
    executed inside the container, preserves glob characters)
    — _persistent_state_for(agent_name) (reader with default fallback)
  • docker/base-image/agent_server/routers/files.py
    — _read_persistent_state() for in-container consumers
  • src/backend/services/template_service.py
    — _build_template() now surfaces persistent_state (falls back to
    DEFAULT_PERSISTENT_STATE when the template omits the key)
  • src/backend/services/agent_service/crud.py
    — single non-fatal call site after container start and git-config
    registration
  • template.yaml (root) — documented default block

162 insertions across 5 modified files, plus two new unit-test files
(14 tests).

Deliberately out of scope

Named here so reviewers don't have to ask:

  • Reset-preserve-state subroutine / API endpoint → Reset-preserve-state operation (S3) #384 / S3
  • Snapshot / restore endpoints → S3
  • .trinity/last-remote-sha/<branch> storage → S7
  • PROTECTED_PATHS / EDIT_PROTECTED_PATHS semantics are unchanged in
    this PR. A snapshot test (`test_protected_paths_lists_unchanged`)
    pins both lists byte-exact so any future change to delete/edit
    protection has to land in its own PR.

Test plan

  • 14 new unit tests (`tests/unit/test_persistent_state_allowlist.py`
    and `tests/unit/test_persistent_state_reader.py`): default
    constant, template-override path, three reader fallback cases
    (missing file, invalid YAML, missing key), the five agent-server
    reader behaviours, the mirror-matches-source drift guard, and the
    PROTECTED_PATHS snapshot.
  • Adjacent git unit tests (`test_github_init_push.py`,
    `test_git_pull_branch.py`) still pass (13/13) — confirms the
    module changes don't regress existing git-service flows.
  • Tier-2 harness (after S0 / Self-hosted git URL support (S0) #387 lands): create agent → exec
    `cat /home/developer/.trinity/persistent-state.yaml` → expect
    default list; edit file in container → reader returns the edit.

Refs #381
Closes #383

🤖 Generated with Claude Code

Add the `persistent_state` allowlist primitive so a later
reset-preserve-state operation can name which workspace files must survive
a template-level reset. `template.yaml` is read only at agent creation
(cached 10 min), so runtime sync/reset paths can't re-read it — the list
is materialized into `.trinity/persistent-state.yaml` at creation time and
read from disk thereafter. Same split as `.env` / `.env.example`.

Scope:
- Reader + materializer in `services/git_service.py`
  (`DEFAULT_PERSISTENT_STATE`, `materialize_persistent_state`,
  `_persistent_state_for`).
- Matching reader in `agent_server/routers/files.py` for in-container use.
- Default defined once; template can override via
  `template_service._build_template`.
- Single non-fatal call site in `agent_service/crud.py` after container
  start and git-config registration.
- Documented default block in the root `template.yaml`.

Deliberately out of scope (owned by follow-up PRs):
- Reset-preserve-state subroutine / API endpoint (→ Abilityai#384 / S3).
- Snapshot / restore endpoints (→ S3).
- `.trinity/last-remote-sha/<branch>` storage (→ S7).
- `PROTECTED_PATHS` / `EDIT_PROTECTED_PATHS` semantics — a snapshot test
  (`test_protected_paths_lists_unchanged`) pins the two lists byte-exact
  so a future change to delete/edit protection has to be its own PR.

Tests: 14 new unit tests cover the default constant, template-override
path, three reader fallback cases (missing file, invalid YAML, missing
key), the five agent-server reader behaviours, and the mirror/source and
protected-paths invariants. All pass on Python 3.12, together with the
pre-existing 13 git unit tests.

Refs Abilityai#381
Closes Abilityai#383

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean infrastructure primitive with comprehensive test coverage (14 tests). Explicitly scoped to add reader/writer only without changing existing protection semantics.

@vybe
vybe merged commit 21f2de4 into Abilityai:main Apr 18, 2026
vybe pushed a commit that referenced this pull request Apr 22, 2026
…ents/index (follow-up to #394) (#404)

* docs(feature-flows): add persistent-state-allowlist flow (S4, #383)

New vertical-slice document covering the allowlist primitive:
- Why it materializes at agent creation (template.yaml cached 10 min)
- Flow 1: creation-time materialization (crud.py + git_service)
- Flow 2: runtime read (backend + agent-server helpers)
- Default list, fallback rules, test coverage
- Explicit out-of-scope list (reset subroutine → #384)

Index: added to Recent Updates and GitHub Integration sections (one row
each, descriptions kept to one line).

* docs: record persistent-state allowlist in architecture / requirements / index (S4, #383)

- architecture.md: note the primitive in the git_service.py one-liner and
  call out `.trinity/persistent-state.yaml` in the agent file-structure tree.
- requirements.md: add §11.3 under GitHub Integration with status,
  description, and scope boundary (reset consumer is #384).
- project_index.json: bump `last_updated` and add `persistent_state_allowlist`
  to `features.implemented`.

No new endpoints / schema / integrations; minimal touch per update-docs
principle.

---------

Co-authored-by: Andrii Pasternak <[email protected]>
@trinity-ability trinity-ability mentioned this pull request Aug 17, 2026
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.

Persistent state allowlist (S4)

2 participants