Skip to content

feat(create): fork-to-own agent creation + brain-orb git-sync exemptions (trinity-enterprise#93, #76) - #1490

Merged
AndriiPasternak31 merged 3 commits into
devfrom
feature/93-fork-to-own
Jul 6, 2026
Merged

AndriiPasternak31 merged 3 commits into
devfrom
feature/93-fork-to-own

Conversation

@vybe

@vybe vybe commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Consolidated PR carrying two tasks (supersedes #1479, closed unmerged — its commits are the base of this branch):

Task 1 — Git-sync exemptions for Brain-Orb template files (trinity-enterprise#76)

  • Brain-Orb-capable templates COMMIT their convention files — the .trinity/brain-orb/{scopes,scope,search,action} hooks and .trinity/setup.sh. The fleet gitignore migration (_migrate_workspace_gitignore, run on every operator Push) used to untrack them and push their deletion, so a re-clone/recreate booted hookless.
  • _build_rm_cached_ignored_command now pathspec-exempts .trinity/brain-orb and .trinity/setup.sh from both the emptiness probe and the removal pipe; sibling .trinity/ runtime files are still swept.
  • Compatibility check S-005 additionally accepts the .trinity/* star form (the only shape a template can commit re-included hooks under) so the compat panel doesn't flag Brain-Orb templates.
  • Tests: test_github_init_gitignore.py (real-git regression), test_compatibility_checks.py (S-005 star form). Live-validated in the Configurable MCP Server URL in Admin Settings #76 e2e (cornelius-e2e).

Task 2 — Fork-to-own agent creation (trinity-enterprise#93)

  • Templates declaring fork_to_own: required in template.yaml get a featured card in Create Agent and are copied at creation into a repo the user owns — private by default, created + pushed with the user's PAT, which then persists as the per-agent PAT (feat: Per-agent GitHub PAT configuration #347) so recreates never fall back to the platform PAT.
  • Origin points at the user's repo: captures, operator Push, and the 15-min auto-sync (enabled for fork agents even in source mode) write there, never the shared upstream template. GIT_UPSTREAM_REPO + a credential-less upstream remote keep template updates one git pull upstream main away.
  • Mechanism: Trinity-side copy (create private repo + push full history) over the GitHub fork API (public-only forks — fails the privacy AC) and the generate API (unrelated histories — breaks clean upstream pulls). Template-generic; Cornelius is the first user.

Hardening (from /autoplan reviews + /review + /cso --diff)

  • SecretStr PAT unwrapped exactly once; container env carries the plain token (regression test — a masked token = silent empty agent, bug: GitHub-template agent deploy — race intermittently leaves a silent empty agent (clone into non-empty /home/developer, exit 128, not surfaced) #1439 class)
  • Push auth via GIT_CONFIG_* env (http.extraHeader) — token never on argv or in URLs; all git output scrubbed (plain + b64)
  • Destination semantics: empty or template-tip SHA-match → retry-safe reuse; holding data → 409; bound to a live agent → 409 (name disclosed only if caller can access it, SEC: User and Agent Enumeration via differential API responses #186); binding re-checked post-reservation (source-mode rows bypass the UNIQUE index) with a deterministic race loser
  • Fork orchestration runs before the docker try-block (structured FORK_* errors reach the UI); PAT persist runs inside it (rollback deletes the reserved row + MCP key)
  • Staging under /data/agent-fork-tmp (backend /tmp is a 100 MB tmpfs)
  • /review: 2 criticals found & fixed (missing DatabaseManager facade delegation — learning captured; binding-guard TOCTOU). /cso --diff: clean; 1 Low accepted-risk (account-scoped PAT blast radius) remediated in UI guidance — report at docs/security-reports/cso-2026-07-06.md

Deliberate scope decisions

  • MCP create_agent does not accept fork_to_own — MCP tool args are audit-logged; a PAT arg would persist in plaintext.
  • fork_to_own: required enforcement is fail-open on a template.yaml metadata-fetch failure (advisory gate; documented).
  • PAT expiry/rotation UX deferred — sync-health S1 alerts cover detection today.

Release step (cross-repo)

The featured Cornelius card appears once Abilityai/cornelius template.yaml adds fork_to_own: required + tagline (canonical internal repo → /sync-to-public). Until then Cornelius creation behaves as today.

Test Plan

  • pytest tests/unit/test_fork_to_own.py — 40 passed (model validation, orchestrator collision/scrub/timeout, crud gates, deep-slice env + PAT persistence + rollback, destination race, facade delegation, startup.sh static)
  • pytest tests/unit/test_github_init_gitignore.py tests/unit/test_compatibility_checks.py — task-1 suites green
  • Neighboring suites unaffected — 115 passed, 1 pre-existing skip
  • Live e2e on localhost (2026-07-06): featured card rendered → invalid-PAT structured error in modal → real create from a private fork_to_own: required template → destination repo created private → agent booted, origin=user repo / upstream=template → per-agent PAT source: "agent" → capture synced → commit landed in the user's repo, template untouched
  • Optional: repeat e2e with a fine-grained PAT

Part of abilityai/trinity-enterprise#93 and abilityai/trinity-enterprise#76 (closed manually at release — cross-repo keywords don't auto-close)

🤖 Generated with Claude Code

@vybe
vybe changed the base branch from feature/76-brain-orb-template to dev July 6, 2026 16:02
@vybe vybe changed the title feat(create): fork-to-own agent creation — featured template flow copies into the user's own repo (trinity-enterprise#93) feat(create): fork-to-own agent creation + brain-orb git-sync exemptions (trinity-enterprise#93, #76) Jul 6, 2026
@AndriiPasternak31
AndriiPasternak31 self-requested a review July 6, 2026 16:23
Eugene Vyborov and others added 3 commits July 6, 2026 17:28
…rack sweep (trinity-enterprise#76)

Brain-Orb-capable templates COMMIT their convention hooks under
.trinity/brain-orb/ (scopes/scope/search/action). The fleet gitignore
migration appends `.trinity/` on every push and then `git rm --cached`s
ignored-but-tracked files — which untracked the hooks and pushed their
deletion, so any later re-clone/recreate booted hookless.

- _build_rm_cached_ignored_command: pathspec-exempt `.trinity/brain-orb`
  from both the emptiness probe and the removal pipe; sibling .trinity/
  files are still swept.
- compatibility S-005: accept the `.trinity/*` star form (the only shape
  a template can commit re-included hooks under — git cannot re-include
  beneath a dir-form exclusion) as satisfying the ignore intent, so the
  compat panel doesn't flag Brain-Orb templates and its auto-fix doesn't
  churn.
- Regression tests for both (real git repo + snapshot check).

Co-Authored-By: Claude Fable 5 <[email protected]>
…trinity-enterprise#76)

Caught by the live e2e Push: the fleet .trinity/ append made the template's
committed setup.sh ignored-but-tracked and the sweep untracked it — a re-clone
of the synced agent repo would never run its startup setup (Brain Orb seed
copy + hook chmod). Same class as the brain-orb hook deletion; same fix.

Co-Authored-By: Claude Fable 5 <[email protected]>
… user's own repo (trinity-enterprise#93)

Templates declaring `fork_to_own: required` in template.yaml are copied at
creation into a repo the USER owns (private by default): the user's PAT
creates the destination, pushes the template's default branch with full
history, and persists as the per-agent PAT (#347) so recreates never fall
back to the platform PAT. Origin points at the user's repo — captures,
operator Push, and the 15-min auto-sync (enabled for fork agents even in
source mode) all land there, never in the shared upstream template.
`GIT_UPSTREAM_REPO` + a credential-less `upstream` remote keep template
updates one `git pull upstream` away. Cornelius is the first user; the
mechanism is template-generic.

- models: ForkToOwnRequest (SecretStr PAT, anchored destination regex,
  private-by-default) on AgentConfig
- fork_to_own.py orchestrator: create/reuse/refuse destination semantics
  (empty or template-tip SHA-match → reuse; else 409), REST + git-plane
  readiness polls, auth via GIT_CONFIG_* env (token never on argv/URL),
  scrub_secret on all output, staging under /data (backend /tmp is tmpfs)
- crud: fork block before the docker try (structured FORK_* errors survive);
  PAT persist inside it (rollback covers); destination-binding guard
  re-checked post-reservation (source-mode rows bypass the UNIQUE index) —
  concurrent losers roll back deterministically; 409 names the bound agent
  only when the caller can access it (#186)
- frontend: featured cards for fork_to_own templates, destination/PAT/
  visibility fields, loud public-repo warning, fine-grained-token guidance
- tests: 40 new (model, orchestrator, crud gates, deep-slice env/PAT
  persistence/rollback, race, facade delegation, startup.sh)

/review: 2 critical findings fixed (missing DatabaseManager delegation;
binding-guard TOCTOU). /cso --diff: clean, 1 Low accepted-risk remediated
in UI copy (docs/security-reports/cso-2026-07-06.md).

Part of abilityai/trinity-enterprise#93

Co-Authored-By: Claude Fable 5 <[email protected]>
@vybe
vybe force-pushed the feature/93-fork-to-own branch from 1e2ca7a to fc0e904 Compare July 6, 2026 16:30
)
if rc != 0:
logger.error("fork-to-own: template clone failed for %s: %s",
template_repo, scrub_secret(out, read_pat))
timeout=PUSH_TIMEOUT_S, auth_pat=user_pat,
)
if rc != 0:
logger.error("fork-to-own: push to %s failed: %s", destination_repo, out)
@AndriiPasternak31
AndriiPasternak31 merged commit f119ad3 into dev Jul 6, 2026
19 of 21 checks passed
AndriiPasternak31 added a commit that referenced this pull request Jul 6, 2026
…#1490)

PR #1490 (fork-to-own) merged test_fork_to_own.py with three bare
`del sys.modules['services.*']` and no baseline entry, reddening the
`sys.modules pollution` lint on dev's tip — every open PR inherits it via the
merge-ref. This PR rebased onto that tip, so fold in the fix rather than block
on it.

Add the linter's blessed snapshot/restore exemption pair (top-level
`_STUBBED_MODULE_NAMES` + autouse `_restore_sys_modules`, precedent
tests/unit/test_telegram_webhook_backfill.py): snapshot the services.*/database
sys.modules subtrees before each test and restore after, so the dynamic
per-test purges can't leak across the session. Behavior-preserving — the file's
40 tests still pass; the lint now treats the file as exempt (0 findings).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
AndriiPasternak31 added a commit that referenced this pull request Jul 6, 2026
…wn (#1490)

PR #1490 (fork-to-own) merged tests/unit/test_fork_to_own.py with three raw
`del sys.modules['services.*']` and no baseline entry, reddening the sys.modules
pollution lint on dev's tip — every open PR inherits it via the merge-ref. This
PR rebased onto that tip, so record the three pre-existing violations in the lint
baseline to restore green.

Deliberately a baseline entry, NOT a code change: an autouse snapshot/restore
fixture (the lint's other sanctioned remedy) was tried first but re-adds modules a
test deliberately deletes, which broke test_owner_mismatch_forbidden under
full-suite ordering (regression-diff flagged it as a new HEAD failure). Baselining
touches zero test behavior and is the lint's explicit escape hatch for accepted
pre-existing debt. Properly draining these three to monkeypatch.delitem is a
#1490-owned follow-up for that file's author.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
vybe pushed a commit that referenced this pull request Jul 7, 2026
… as prod build args (#1489) (#1492)

* fix(frontend): plumb VITE_BUG_REPORTING_ENABLED / VITE_BUG_INTAKE_URL as prod build args

HelpChatWidget (#1116) reads two build-time knobs to disable in-app bug
reporting or repoint it off the hosted intake, but the prod build path never
passed them. Vite inlines import.meta.env.* at build time, so an operator
setting VITE_BUG_REPORTING_ENABLED=false in .env had no effect — every prod
build shipped with reporting on, pointed at intake.abilityai.dev, with no
supported off switch.

Copy the existing VITE_API_URL plumbing verbatim: two ARG+ENV in
Dockerfile.prod (before npm run build), two build.args in
docker-compose.prod.yml, keeping compose default == ARG default == code
default so an unset .env byte-reproduces today. Document both in .env.example
with prod-only, no-secrets, and CSP-caveat warnings.

Repoint path is CSP-blocked (connect-src hard-codes the intake host in both
security-headers.conf and vite.config.js); disable path works end-to-end. CSP
parameterization for a working self-host repoint is an umbrella #1485 follow-up.

Fixes #1489
Refs #1485

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

* test(#1489): static guards for VITE_BUG_* prod build-arg plumbing

Pure static tests (no Docker, no backend — mirroring
test_858_dockerfile_unbuffered.py) over the prod frontend build path:
Dockerfile.prod declares both ARG + ENV ${VAR} pass-throughs before
`RUN npm run build`, docker-compose.prod.yml forwards both via
${VAR:-default} build.args, and the three defaulting layers agree
(Dockerfile ARG == compose default == HelpChatWidget code default) so an
unset .env byte-reproduces today's behavior. Scoped to #1489; the general
VITE_* parity guard is a deferred #1485 follow-up.

Refs #1489, #1485

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

* docs(feature-flows): note prod build-arg plumbing for VITE_BUG_* knobs (#1489)

Update the in-app-bug-reporting flow's Config-knobs bullet to record that the
#1116 build-time knobs are Vite build args (not runtime env) and are now plumbed
through docker/frontend/Dockerfile.prod + docker-compose.prod.yml with
three-layer default agreement; expand the CSP bullet with the repoint caveat.
Add a Recent Updates index row.

Refs #1489, #1485

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

* fix(test): sync dependencies + models stubs in test_login_rate_limit_split with auth.py

Pre-existing dev-baseline failure (8 fixture errors, deterministic in isolation),
surfaced here because #1492's lint fix unmasks it in CI ordering. routers/auth.py
grew its imports over time but the fake-module stubs in this test drifted:

  - `from dependencies import (...)` gained get_current_user / is_token_revoked /
    oauth2_scheme / revoke_token_jti via the #187 JWT-revocation/logout work; the
    stub defined only authenticate_user + create_access_token.
  - `from models import User` (a Depends(get_current_user) param annotation on the
    #187 logout endpoint) was added; the models stub defined only Token.

`from dependencies import (...)` / `from models import (...)` resolve every name at
import time, so a missing stub attr errors the whole file at fixture setup. Add the
four dependencies stubs + the User stub (bare lambdas / a bare class — none are
exercised by the rate-limit paths under test). 8 errors -> 8 passed.

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

* chore(lint): baseline pre-existing sys.modules debt in test_fork_to_own (#1490)

PR #1490 (fork-to-own) merged tests/unit/test_fork_to_own.py with three raw
`del sys.modules['services.*']` and no baseline entry, reddening the sys.modules
pollution lint on dev's tip — every open PR inherits it via the merge-ref. This
PR rebased onto that tip, so record the three pre-existing violations in the lint
baseline to restore green.

Deliberately a baseline entry, NOT a code change: an autouse snapshot/restore
fixture (the lint's other sanctioned remedy) was tried first but re-adds modules a
test deliberately deletes, which broke test_owner_mismatch_forbidden under
full-suite ordering (regression-diff flagged it as a new HEAD failure). Baselining
touches zero test behavior and is the lint's explicit escape hatch for accepted
pre-existing debt. Properly draining these three to monkeypatch.delitem is a
#1490-owned follow-up for that file's author.

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

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
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.

3 participants