Skip to content

feat(prompt): "Your environment" block in the platform prompt (trinity-enterprise#945) - #3800

Merged
vybe merged 6 commits into
devfrom
feature/ent945-environment-block
Oct 19, 2026
Merged

vybe merged 6 commits into
devfrom
feature/ent945-environment-block

Conversation

@vybe

@vybe vybe commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes abilityai/trinity-enterprise#945 (platform prompt "Your environment" block).

What

Adds a facts-only ### Your environment block to the platform prompt (platform_prompt_service.py), rendered at every prompt tier. It tells the agent where it lives:

  • durable home vs /tmp (a small RAM-backed noexec tmpfs) and $TMPDIR (~/.tmp, on the volume)
  • the directories the platform reserves (data/ is gitignored once data_paths is declared), and that .trinity/ is written by the agent but people cannot edit it from the Files tab
  • when template.yaml edits take effect
  • what a reset to the template's main keeps: the files listed in .trinity/persistent-state.yaml, or a default set without that file (workspace/, .trinity/, .mcp.json, .claude.json, .claude/.credentials.json). It never touches untracked files. A force-replace pull (offered on a pull conflict, and through git_pull) is the exception: it resets to the remote and deletes untracked files that are not gitignored.
  • protected paths, which come from guardrails-baseline.json path_deny. On Claude Code (runtime label claude-code, claude or empty), Write/Edit refuse them and shell commands do not. On Codex/Gemini nothing in the runtime blocks them.

"Remembering Things About Users" now calls auto-memory "Claude Code's auto-memory (under ~/.claude/projects/)" instead of a path that does not exist (~/.claude/projects/memory/). It also says the repo's memory/ directory is shared across all users. write_user_memory's MCP description uses the same wording. The stale "100 MB" /tmp comment in capabilities.py is corrected.

Commits: c4f2f7e07 block · 3016feae2 tests · d9d2e2f20 architecture note · bef530b53 review fixes (reset default, write_user_memory wording) · af6f25854 feature flows · 8fd08e2b5 validation round 1 fixes (force-replace pull, data/ ignore condition, claude runtime alias).

Rulings carried

Review + security

  • Reading review on an independent model returned MERGEABLE AFTER FIXES: no criticals, three items (F1 write_user_memory description and doc hits, F2 reset default, F3 feature-flow bullet), all fixed in bef530b53 / af6f25854.
  • /cso --diff found nothing. .claude and src/backend/enterprise are untouched in the range.
  • /validate-pr round 1 (review 5567799045): REQUEST CHANGES on C1 (force-replace pull) and W1 (claude alias); both fixed in 8fd08e2b5.
  • Block length: 2,338 chars on Claude Code / claude / empty, 2,290 on Gemini, 2,276 on Codex (cap 2,600). write_user_memory description: 1,238 chars (cap 2,048).

Tests

  • New file tests/unit/test_ent945_environment_block.py: 72 passed on 8fd08e2b5. The F2 owner-match test and the three round-2 tests (force-replace sentence, conditional data/ ignore, claude alias) were shown red before the prompt changed.
  • Targeted: test_ent243_prompt_tier.py 39, test_platform_prompt_unit.py 41, test_platform_prompt_runtime.py 7, all passing.
  • Review sweep: 17 prompt-pinning files gave 603 passed on d9d2e2f20. Five mutations turned 7 tests red.
  • Order check: the new file ran in one process after the three files that stub services / services.platform_prompt_service: 170 passed.
  • The full shuffled run is CI's.

Before merge

Handoffs

  • Debt (defer to trinity-enterprise#140), for .claude/DEBT_INBOX.md: a reverse drift guard for the ### Your environment block. Today tests/unit/test_ent945_environment_block.py only checks that every folder the block names still matches its owning constant. Nothing fails when a new folder is reserved (a new startup.sh mkdir or .trinity/ file) and the block does not mention it. When the injection registry lands, add a scan of startup.sh mkdirs and .trinity/ literals against a shrink-only exempt list. This chain does not stage the .claude submodule, so the entry is recorded here for the debt-inbox owner.

Built by trinity-pm's build-chain run chain-agent-env (plan → rulings → implement → review → fix) through the fleet engineer.

🤖 Generated with Claude Code

Trinity Agent (trinity) and others added 5 commits October 19, 2026 00:59
…trinity-enterprise#945)

States the container facts an agent cannot infer from tool signatures:
the user and durable workspace volume, the noexec RAM /tmp and $TMPDIR,
UTC, what a reset to main keeps, the folders the platform creates or
reads, the memory/ convention, when template.yaml is re-read, and the
agent image's guardrail path_deny list.

- The block renders at every prompt tier (always class).
- The protected-paths sentence depends on the runtime: Claude Code is
  told its Write/Edit tools refuse these paths and shell commands do
  not; Codex, Gemini and any other runtime are told nothing blocks them.
- _GUARDRAIL_PATH_DENY is a backend copy of guardrails-baseline.json
  path_deny (the backend image does not ship the hooks).
- The Codex orientation now names refresh_metric_definitions.
- The user-memory warning now names Claude Code's auto-memory
  (under ~/.claude/projects/) instead of a path that does not exist.
- capabilities.py: a stale "100 MB cap" comment now says the tmpfs
  size cap (the default is 512m and AGENT_TMP_SIZE changes it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-enterprise#945)

test_ent945_environment_block.py (T1-T10): the block renders at every
tier through get_platform_system_prompt, directly before Package
Persistence; no marker ships unfilled on any runtime; the backend
path_deny copy equals guardrails-baseline.json exactly; each reserved
folder matches its owning constant (read by AST, never skipped); the
protected-paths sentence never claims a hook a runtime lacks; budget
2600 chars; no /tmp size number; the Codex orientation names
refresh_metric_definitions.

Written first and seen red (53 failed: section missing) before the
service change.

test_ent243_prompt_tier.py: test_minimal_keeps_the_user_memory_leak_warning
re-pinned from the old ~/.claude/projects/memory/ literal to the new
"Claude Code's auto-memory (under ~/.claude/projects/)" wording.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing (trinity-enterprise#945)

- The reset sentence now names the default keep-set that applies when
  `.trinity/persistent-state.yaml` is absent (the agent server's
  `_DEFAULT_PERSISTENT_STATE`). New owner-match test
  `test_reset_default_set_matches_the_agent_server` parses that constant
  out of files.py; it was red before the sentence changed.
- `write_user_memory` description no longer names
  `~/.claude/projects/memory/`, which does not exist: it names Claude
  Code's auto-memory under `~/.claude/projects/` and the repo's
  `memory/` directory, matching the prompt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…#945)

- system-wide-trinity-prompt.md: bullet for the always-tier
  "Your environment" section and what pins it.
- write-user-memory.md: drop the nonexistent `~/.claude/projects/memory/`
  literal for Claude Code's auto-memory under `~/.claude/projects/`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vybe

vybe commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Companion docs PR: #3801 (#3797) states the same environment facts in the compatible-agent guide. Merge the two together.

@trinity-ability trinity-ability 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.

PR Validation Report — #3800 (/validate-pr, Lane B, tip af6f25854)

Recommendation: REQUEST CHANGES — one factual error in the new always-on block. It is a one-clause fix. Everything else passes.

Summary

Category Status Notes
Commit messages ✅ 5 conventional commits
Base branch ✅ dev
PR size ✅ 8 files, +368/−10
Status auto-promotion ⚠️ "Implements trinity-enterprise#945" has no closing keyword. It is cross-tracker, so the private issue needs a manual status-in-dev bump after merge either way
Architecture / feature flows ✅ agent-runtime.md, system-wide-trinity-prompt.md, write-user-memory.md updated
Security (§4.1–4.10) ✅ No keys, emails, IPs, mode flips or env files. /home/developer/ appears only as the in-container path. Enterprise-docs guard pattern: 0 hits
Infra / build / config packaging ➖ No Dockerfile, compose or new env var
Structural review ✅ The independent reading review and /cso --diff are cited in the body
Merge gate (Tier 1) ✅ All checks on af6f25854 are green. regression diff, pytest (head) and journey-smoke pass. dev-ci is success and no dev-ci red issue is open
Test adequacy ✅ Each fact is pinned to its owning constant, not to the block's own text
Code quality ✅ / ⚠️ See W1

Execution coverage (§5.4)

changed symbol / test executed by live consumer verdict
### Your environment + __PATH_DENY_SENTENCE__ fill TestPresence::test_live_prompt_carries_the_block through get_platform_system_prompt(runtime=…) routers/chat.py, task_execution_service.py → get_platform_system_prompt ✅
_adapt_instructions_for_runtime hooked/unhooked swap TestRuntimeHonesty same composition root ✅ Mutation: replacing the runtime_key not in _GUARDRAIL_HOOK_RUNTIMES guard with False turns 3 tests red. Restored afterwards
_GUARDRAIL_PATH_DENY TestPathDeny (exact list equality with guardrails-baseline.json) the rendered prompt ✅ guard
Reset default keep-set test_reset_default_set_matches_the_agent_server (AST read of _DEFAULT_PERSISTENT_STATE) the rendered prompt ✅ guard

Local runs on af6f25854: test_ent945_environment_block.py 64 passed, test_ent243_prompt_tier.py 39 passed, test_platform_prompt_unit.py 41 passed.

Critical (block merge)

C1. src/backend/services/platform_prompt_service.py:242: "a reset to the template's main … never touches untracked ones" is false for one of the two reset paths.

  • The statement holds for reset_to_main_preserve_state_impl (docker/base-image/agent_server/routers/git.py:2731), which runs git reset --hard origin/main and overlays the snapshot, with no clean step.
  • The force_reset pull strategy (docker/base-image/agent_server/routers/git.py:2553-2573) is also a reset to the template's main. On a trinity/* working branch, _get_pull_branch (git.py:1549) resolves to main, so it runs git reset --hard origin/main and then git clean -fd. It also ignores .trinity/persistent-state.yaml entirely.
  • People reach force_reset through the UI ("Force Replace Local" in GitConflictModal.vue:56) and through the MCP git_pull tool (src/mcp-server/src/tools/git.ts:264).

An agent that trusts the always-on sentence and keeps work untracked but not gitignored loses it on that path. Gitignored files such as data/ do survive, because clean -fd has no -x.

Suggested fix, one clause: scope the existing sentence to the preserve-state reset, and add that a force-reset pull ("Force Replace Local" / git_pull force_reset) discards local changes and deletes untracked, non-gitignored files, with no keep-set. The test file has no owner pin for this fact. Consider pinning it to git.py, for example by asserting that reset_to_main_preserve_state_impl contains no clean.

Companion #3801 carries the same claim. It appears in the submodule paragraph, in "(An ordinary pull merges and does not reset.)", and in the FAQ and agent-data lines ("neither wipes untracked files"). The two PRs do not contradict each other, but both contradict the code. Correct them together so the two surfaces stay identical.

Warnings

  • W1. platform_prompt_service.py:512: _GUARDRAIL_HOOK_RUNTIMES = {"claude-code", ""} leaves out "claude". Both CLAUDE_RUNTIME_NAMES (agent_service/helpers.py:41) and the agent-side _CLAUDE_RUNTIMES (runtime_adapter.py:195) treat claude as Claude Code, which runs the hook. An agent labelled claude would be told "Nothing in your runtime blocks these writes". That fails in the safe direction but is still untrue. Add "claude", or mirror the set in a pinned test.
  • W2. PR body inaccuracies.
    • It calls #3797 the "sibling guide PR", but #3797 is the issue and the PR is #3801.
    • It says the block covers "$TMPDIR … never cleared wholesale" and "An ordinary pull merges". Neither sentence is in the block.
    • #3801 says "merges or rebases". This is body-only, but it is the one place where the two descriptions differ.

Suggestions

  • platform_prompt_service.py:252: "Your own memory directory is memory/ …" is a convention rather than a platform fact, and it has no owner pin. The wording is fine per the #3797 ruling; it is noted only because the rest of the block is owner-pinned.

Report-only validation: no commits or pushes were made to this branch.

🤖 Generated with Claude Code

@trinity-ability trinity-ability added the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Oct 19, 2026
…me alias (trinity-enterprise#945)

Validation round 1 follow-ups on the `### Your environment` block:

- Name the force-replace pull (pull-conflict "Force Replace Local" and
  `git_pull`) as the exception to "never touches untracked ones": it resets
  to the remote and runs `git clean -fd`, deleting untracked files that are
  not gitignored.
- `data/` is gitignored only once the agent declares `data_paths`; it is not
  in the base gitignore patterns, so the block no longer says it always is.
- `_GUARDRAIL_HOOK_RUNTIMES` gains `claude`, which the agent server treats
  as Claude Code (runtime_adapter, execution_env), so that alias is no longer
  told nothing blocks the protected paths.

Red first: test_force_replace_pull_is_named_as_the_exception,
test_data_folder_ignore_is_conditional and
test_claude_alias_gets_the_hooked_sentence all failed before the change.
The feature-flow summary is updated to match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
trinity-ability pushed a commit that referenced this pull request Oct 19, 2026
#3797)

A force-replace pull (strategy=force_reset) runs git reset --hard then
git clean -fd, so it deletes untracked files that are not gitignored;
the default pull is git pull --rebase; data/ is gitignored only once
data_paths is declared. Wording matches the companion PR #3800.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@trinity-ability trinity-ability 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.

PR Validation Report — round 2 (head 8fd08e2b5)

Lane B (prompt service, MCP tool description, tests, docs; no schema). Round 1 was review 5567799045 on af6f25854.

Round-1 items

Item Status Evidence
C1: force-replace pull vs "never touches untracked" ✅ fixed Block now says a force-replace pull "resets to the remote and deletes untracked files that are not gitignored". That matches agent_server/routers/git.py force_reset (git reset --hard origin/<branch> then git clean -fd, no -x, so ignored files survive). "Offered when a pull conflicts" matches GitConflictModal.vue:56. "Through git_pull" matches src/mcp-server/src/tools/git.ts (strategy: force_reset).
W1: _GUARDRAIL_HOOK_RUNTIMES lacked "claude" ✅ fixed Now {"claude-code", "claude", ""}, the same set as runtime_adapter.py:195 and execution_env.py:138.
W2: PR-body errors ✅ fixed Body names sibling #3801. The cross-tracker / no-closing-keyword note is under Before merge. Claims match the block text. Test counts reproduce (72 in the new file).
R3: data/ ignore condition ✅ "gitignored once you declare data_paths" is accurate: data/ is not in _GITIGNORE_PATTERNS; it is added by trinity_files._data_paths_gitignore_entries (DP-002).

Execution coverage (§5.4)

changed symbol executed by live consumer verdict
_GUARDRAIL_HOOK_RUNTIMES += claude T13 + TestRuntimeHonesty[claude] platform_prompt_service runtime adapter ✅
force-replace sentence T11 (rendered block) the platform prompt render ✅
data/ conditional T12 (rendered block) the platform prompt render ✅

Mutations (run in an isolated worktree):

  • Removing "claude" from the set turns 2 tests red (T13 and test_claude_code_names_its_hook_and_its_gap[claude]).
  • Reverting both sentences turns 2 tests red (T11, T12).

Local runs: test_ent945_environment_block.py, test_ent243_prompt_tier.py and test_platform_prompt_runtime.py give 118 passed.

Agreement with #3801 (a178c5efc)

The two PRs agree on all five points:

  • Reset keep-set: the default set is named identically.
  • Force-replace pull sentence: same wording. #3801 says "the MCP git_pull tool".
  • data/ ignore condition: the same in both.
  • memory/: committed at the repo root in both.
  • .trinity/: both say people cannot edit it from the Files tab and the agent can.

Other checks

  • Security greps: no keys, real emails, symlinks or mode changes. The only /home/ hit is the in-container /home/developer/ path, which is documented and not a host path.
  • CI: terminal and green: 20 pass, 6 skipped, 0 failing.
  • dev-ci: success, and there is no open dev-ci red issue.

Not blocking

  • Cross-tracker issue: no closing keyword reaches trinity-enterprise#945, so after merge set status-in-dev on it by hand. The body already says this.
  • Merge order: merge together with #3801.

Recommendation: APPROVE. No new findings.

@trinity-ability trinity-ability removed the status-needs-fix PR has an unaddressed review/validation finding; cleared by the author's next push (#2815) label Oct 19, 2026
@vybe
vybe marked this pull request as ready for review October 19, 2026 07:30
vybe added a commit that referenced this pull request Oct 19, 2026
…ts (#3797) (#3801)

* docs(guide): recommended workspace layout in Directory Structure (#3797)

Restates ## Directory Structure as three zones (platform-owned, committed,
volume-only) with three rules, project_files/<slug>/, $TMPDIR scratch,
gitignored side clones vs submodules (#2366), the .gitignore read as a
consequence of the zones, and source links. Drops the stale
.claude/skills-library/ mount line. Wording kept consistent with the
platform prompt's environment block (trinity-enterprise#945).

Refs #3797

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(guide): FAQ pointer to the recommended workspace layout (#3797)

Refs #3797

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(guide): consistent committed folder, reset default, pull vs reset (#3797)

- Content Folder Convention, Best Practices and the commit_paths example
  name reports/<kind>/ as the committed work folder, matching the new
  Directory Structure tree; outputs/ is kept as a legacy name that still works.
- The reset-to-main sentence states the default persistent set used when
  .trinity/persistent-state.yaml is absent, and that untracked files are
  never touched.
- The FAQ, agent-data.md, the guide's data_paths section and the
  agent-data-volumes flow no longer call an ordinary template pull a reset.
- Memory Management points at the repo-level memory/ and keeps per-person
  facts out of it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* docs(agents): force-replace pull, pull rebases, data/ ignore condition (#3797)

A force-replace pull (strategy=force_reset) runs git reset --hard then
git clean -fd, so it deletes untracked files that are not gitignored;
the default pull is git pull --rebase; data/ is gitignored only once
data_paths is declared. Wording matches the companion PR #3800.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Trinity Agent (trinity) <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@vybe
vybe merged commit eaba15a into dev Oct 19, 2026
28 checks passed
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.

2 participants