Provide one deterministic view over many Git branches so a human can decide:
The system recommends a disposition but does not silently merge, close, delete, force-push or rebase a branch. A source-code conflict, an intent conflict and a failed hosted check remain distinct facts.
The incident-derived diagnostic contract, operator command and division of
responsibility between todo2code, Goal, Giton, Validator Agent, Koru and
wellmanifest are specified in
GOVERNANCE_DIAGNOSTICS.md. That document is a
follow-up architecture boundary, not an expansion of ticket 036’s two-file
core implementation scope.
The exchange format is one discriminated contract, t2c.branch/v1. It uses a
kind field for snapshot, comparison, portfolio and validation
projections instead of creating unrelated formats in each repository.
{
"schemaVersion": "t2c.branch/v1",
"kind": "portfolio",
"repository": "semcod/example",
"base": {
"ref": "refs/remotes/origin/main",
"sha": "<40-hex>"
},
"snapshotFingerprint": "<sha256>",
"branches": [
{
"ref": "refs/remotes/origin/ticket-123-example",
"headSha": "<40-hex>",
"mergeBaseSha": "<40-hex>",
"ahead": 3,
"behind": 1,
"graphFingerprint": "<sha256>",
"truthMapFingerprint": "<sha256>",
"ticket": "ticket-123",
"pullRequests": [
{
"number": 42,
"state": "OPEN",
"headSha": "<40-hex>",
"baseRef": "main",
"mergeCommitSha": null
}
]
}
],
"interactions": [
{
"leftHeadSha": "<40-hex>",
"rightHeadSha": "<40-hex>",
"classification": "semantic_conflict",
"pathEvidence": ["src/example.ts"],
"recordIds": ["INT-NL-...", "INT-AST-..."],
"relationIds": ["REL-..."],
"mergeTreeFingerprint": "<sha256>"
}
],
"recommendations": [
{
"headSha": "<40-hex>",
"disposition": "rebase_required",
"advisory": true,
"reasonCodes": ["BASE_BEHIND", "SEMANTIC_OVERLAP"],
"evidenceIds": ["INT-NL-...", "REL-..."]
}
],
"provenance": {
"todo2codeVersion": "<semver>",
"goalVersion": "<semver-or-null>",
"koruVersion": "<semver-or-null>",
"generatedAt": "<display-only timestamp>"
},
"fingerprint": "<sha256>"
}
The fingerprint covers repository identity, exact base/head/merge-base SHAs, normalized records, relations, merge-tree evidence and tool versions. It does not cover the display timestamp. A moving branch name is never evidence by itself.
pullRequests is a history, not a scalar. GitHub permits the same branch name
to be reused for more than one PR. A PR describes the current ref only when its
recorded headSha equals the resolved branch head; branch-name equality alone
must never transfer review, merge or ticket evidence.
todo2code already provides most of the primitives:
t2c.graph/v1 comparison through t2c.diff/v1;The planned t2c.truth-map/v1 projector from ticket-036 supplies a stable way
to group these records into declared intent, observed facts and claims. Branch
Intelligence adds repository topology and cross-branch interaction evidence;
it does not replace the graph.
| Evidence | Deterministic producer | Meaning |
|---|---|---|
| ref topology | Goal Git adapter | exact refs, SHAs, merge base, ahead/behind |
| textual collision | Git merge-tree plus todo2code diff |
the same lines/files cannot merge cleanly |
| semantic overlap | todo2code graph/truth-map comparison | branches affect the same mapped intent or target |
| duplicate patch | stable patch identity / cherry equivalence | equivalent change already exists elsewhere |
| ticket conflict | todo2code communication/governance records | scopes or accepted intents disagree |
| checks/review | GitHub protected boundary | exact-head execution and review state |
| recommendation | deterministic rules | advisory branch disposition with cited evidence |
| optional LLM review | Validator GLM 5.2 | explanatory advice only, never trust root |
Scanning every pair with a full todo2code pipeline would be unnecessarily quadratic. The implementation should:
merge-base for every
branch against the selected base.git merge-tree and the deeper semantic comparison only for candidates.manual_review, never an invented order.t2c.branch/v1 portfolio and reverse indexes from every Git,
DSL and PR identifier to the affected recommendation.Suggested disposition values are:
merge_ready;merge_after;rebase_required;retarget_required;duplicate;superseded;stale;conflict;manual_review;keep.close and delete are commands in Goal, not analyzer dispositions. They need
an approved plan hash and external authority.
flowchart LR
Human[Human operator] --> GoalCLI[Goal branch portfolio CLI]
GoalCLI --> GoalCQRS[Goal BranchPortfolio CQRS]
GoalCQRS --> GitAdapter[Goal Git query adapter]
GoalCQRS --> KoruURI[Koru URI process orchestrator]
KoruURI --> T2C[todo2code deterministic analysis]
T2C --> Graph[t2c.graph/v1]
Graph --> Truth[t2c.truth-map/v1]
Truth --> Portfolio[t2c.branch/v1 portfolio]
GitAdapter --> Portfolio
Portfolio --> GoalStore[(Goal append-only event store)]
GoalStore --> ReadModel[Branch decision read model]
ReadModel --> Human
Portfolio --> TargetCI[Target repository protected CI]
TargetCI --> Attestation[SHA-bound artifact / attestation]
Attestation --> Validator[validator-agent]
Validator --> GitHub[Exact-head PR review]
LLM[OpenRouter GLM 5.2] -. advisory explanation .-> Validator
Owns semantic analysis and the canonical t2c.branch/v1 schema/projector. It
does not fetch credentials, approve a PR or mutate refs. Planned deliveries:
t2c branches analyze, MCP/A2A and optional Protobuf
projection;Owns the local Git portfolio process and approved mutations. It must not import Koru. It consumes the versioned todo2code contract through CLI/JSON first and can add Protobuf after the JSON contract is stable.
Commands:
CaptureBranchSnapshot;RequestBranchAnalysis;ProposeBranchDispositionPlan;ApproveBranchDispositionPlan;RevalidateBranchPlan;ExecuteBranchAction.Queries:
GetBranchPortfolio;GetBranchComparison;GetBranchDispositionPlan;ListStaleBranches;GetBranchEventStream.Events:
BranchSnapshotCaptured;BranchAnalysisCompleted / BranchAnalysisRejected;BranchDispositionProposed;BranchDispositionApproved / BranchDispositionRejected;BranchPlanInvalidated;BranchActionAttempted / BranchActionSucceeded /
BranchActionFailed.Every apply command binds repository, baseSha, all affected headSha
values, the portfolio fingerprint, an approval hash and an idempotency key.
Merge, close and deletion are separate effects and receipts. Goal’s existing
URI/DSL/CQRS+ES blueprint remains the architectural prerequisite; its dirty
local governance work must be completed without mixing this feature into it.
goal -a compatibility auditGoal 2.1.284 was inspected and exercised with
goal -a --dry-run --no-publish against a temporary checkout containing one
staged documentation change. The current command:
-a as the full test/commit/push/publish workflow;todo2code/t2c anywhere in the Goal runtime;t2c.graph/v1 / t2c.branch/v1;git pull --rebase on the current branch and retrying once.The observed dry-run reported one changed file, a proposed version bump and a commit summary, but no branch, PR, todo2code or semantic-conflict evidence. Focused Goal tests for the current push/retry and dry-run paths passed 41/41.
Therefore current goal -a cannot consume Branch Intelligence. Calling it
after analysis would also be too late: its automatic rebase retry can change
the exact snapshot on which a portfolio decision was based.
The safe Goal integration is a preflight state machine:
stateDiagram-v2
[*] --> NoPortfolio
NoPortfolio --> Analyzed: goal branches analyze
Analyzed --> Approved: approve exact plan hash
Analyzed --> Invalid: base/head changed
Approved --> Invalid: base/head changed
Approved --> ReleaseReady: disposition=merge_ready
Approved --> Blocked: conflict/rebase/manual_review
ReleaseReady --> GoalAll: goal -a --branch-plan PLAN
GoalAll --> Invalid: pre-push ref recheck failed
GoalAll --> Completed: tests + push + read-back pass
Invalid --> Analyzed: recompute
Blocked --> [*]
Completed --> [*]
Proposed compatibility rollout:
goal branches analyze and
goal branches show; do not alter goal -a yet.t2c.branch/v1 JSON from a pinned
todo2code CLI or Koru adapter. Goal must not import todo2code internals.branch_intelligence.mode = disabled|warn|require, defaulting to
disabled during dual-read rollout.warn, render cited recommendations but preserve existing behavior.require, make goal -a demand an approved portfolio fingerprint bound
to the current repository/base/head before tests, versioning, commit, rebase,
push or publish.BRANCH_PLAN_STALE; recomputation is required.--branch-plan <path> as the explicit compatibility input. Never locate
a plan implicitly from an untrusted branch checkout.BranchPlanValidated or BranchPlanRejected before the first
external effect and include the portfolio fingerprint in later receipts.Required Goal validation:
goal -a characterization tests;warn never authorizes a merge or deletion;require blocks conflict, manual_review, rebase_required and stale
plans;Owns local orchestration and operator experience:
Proposed URI bindings:
git://repository/query/branches
git://repository/query/merge-base
t2c://repository/query/branch-portfolio
goal://branch-portfolio/command/propose
goal://branch-portfolio/command/approve
goal://branch-portfolio/command/apply
validator://pull-request/command/validate-portfolio
URI bindings point to governed processes, not shell fragments. The local Koru adapter must use an isolated worktree and must preserve the user’s current dirty Koru checkout.
Extends direct-pr rather than creating an unrelated approval path. The
request must additionally bind:
expected_base_sha and expected_head_sha;merge_base_sha;branch_portfolio_fingerprint;The deterministic validator:
conflict, unresolved cycles, unsafe scope or missing evidence;openrouter/z-ai/glm-5.2 for an advisory explanation;Useful domain events in the existing Validator SQLite event store are
BranchPortfolioReceived, BranchPortfolioVerified,
BranchPortfolioRejected, PullRequestSnapshotInvalidated and
ExactSnapshotReviewSubmitted.
sequenceDiagram
actor H as Human
participant K as Koru
participant G as Goal
participant T as todo2code
participant CI as Protected CI
participant V as validator-agent
participant GH as GitHub
H->>K: analyze branches against origin/main
K->>G: CaptureBranchSnapshot
G->>GH: query refs/PR metadata
GH-->>G: exact base/head SHAs
G-->>K: snapshot fingerprint
K->>T: analyze immutable branch trees
T-->>K: t2c.branch/v1 portfolio
K->>G: ProposeBranchDispositionPlan(portfolio hash)
G-->>H: matrix, order, conflicts, evidence
H->>G: Approve plan hash
G-->>K: approved immutable plan
K->>GH: open/update PR only when requested
CI->>T: recompute exact base/head analysis
T-->>CI: portfolio slice + fingerprint
CI-->>V: protected artifact/attestation
V->>GH: re-read PR + hosted checks
V->>V: verify repo/base/head/ticket/hash
V->>GH: exact-snapshot review
Note over G,V: Any base/head change invalidates the plan and review
| Branch | Behind/ahead | Text | Intent | Duplicate | Recommendation |
|---|---|---|---|---|---|
ticket/A |
0/3 | clean | aligned | no | merge_ready |
ticket/B |
4/2 | clean | overlaps A | no | merge_after A then revalidate |
ticket/C |
1/5 | conflict | conflict | no | conflict |
ticket/D |
0/1 | clean | same assertion as A | yes | duplicate |
experiment/E |
40/0 | clean | no unique evidence | no | stale |
This table is a read model. It does not authorize branch deletion or merge.
OPENROUTER_API_KEY stays in the subactor/validator-agent Actions secret
for Validator advisory review, or in a local untracked environment for a
local opt-in explanation. It never enters DSL, artifacts, logs, URLs, PR
bodies or commits.Use an offline fixture repository with at least five branches:
Prove:
Each repository receives its own ticket and non-overlapping branch/worktree. Cross-repository correlation uses one stable ID, but one ticket never transfers path ownership into another repository.
The first read-only audit against the real wellmanifest/new-project remote is
recorded in
LIVE_AUDIT_WELLMANIFEST_2026-08-04.md.
It demonstrated contained merged branches, one divergent but semantically
superseded branch, same-name multi-PR history and the need to bind both base and
head SHAs.
The same audit verified that Goal 2.1.284 does not yet consume todo2code
branch evidence and documented the required fail-closed goal -a preflight
integration above.