feat(github): route lifecycle writes through App connection

Merged
KH
4mo ago
+1036-78

Advances #221

Outcome

  • Adds an AppGithubWriteback adapter from the connected GithubConnectionWrite to the orchestrator GithubWriteback lifecycle port.
  • Extends the Relayfile connection writer with confirmed GitHub issue comments and issue label/state updates.
  • Requires confirmWrite to acknowledge every App mutation; pending, failed, or timed-out writes reject.
  • Extends the guarded cloud-mount allowlist only for canonical issue patches and Factory deterministic comment drafts.

Selection and attribution

  • Exact github.identity: "app" selects the App lifecycle adapter at FactoryLoop construction and refuses local-gh fallback when the capability is absent.
  • auto and user retain the current local-gh issue lifecycle behavior. Existing auto PR publication remains App-preferred.
  • App mode sends PR publication, issue comments, lifecycle labels, and issue close through the workspace connection. Factory holds no GitHub credential; the server-side repo-capable App connection performs the provider mutation.

Deliberate scope

  • getIssueAuthor, getIssueStatus, and hasCommentMarker remain absent because provider-authoritative App reads are tracked separately in relayfile-cloud#159; existing callers keep their conservative optional-read behavior.
  • mergePolicy: "never" short-circuits real-issue merge-gate check/merge calls, so gh pr merge is not ported.
  • Notion intake owns a separate GhCliIssuePublisher surface and is unchanged.

Verification

  • npm run build
  • Changed-file suite: 685 passed across mount writer, writeback, orchestrator, and fleet CLI tests.
  • Final selection regression run: 3 passed (App/no-token must-fire, default-gh must-not-fire, missing capability fail-loud).
  • Guarded mount regression: 1 passed.
  • git diff --check and targeted credential-pattern scan passed.

Summary by cubic

Routes GitHub issue lifecycle writes (comments, status labels, close) through the connected App when github.identity is "app", preserving non-Factory labels and clearing all Factory lifecycle labels on "ready". The default "auto" keeps the local gh path for issues; "user" always uses gh.

  • Exact "app" selects AppGithubWriteback and refuses local-gh fallback if the mount lacks postIssueComment, ensureRepositoryLabel, mutateIssueLabel, or updateIssue. Provider-authoritative reads stay optional on the adapter.
  • Adds App-authored issue writes to GithubConnectionWrite via confirmed Relayfile drafts:
    • Deterministic comment drafts at /issues/{n}/comments/factory-{sha256-24}.json bound to the comment body.
    • Canonical partial issue updates at /issues/{n}.json (state-only for close).
    • Unique lifecycle label operations via /labels/factory-{uuid}.json and /issues/{n}/labels/factory-{uuid}.json.
    • confirmWrite must return acked; pending, failed, or timeouts reject.
  • Mount guard scopes App lifecycle drafts:
    • Always allow Factory-authored PR/ref/close artifacts.
    • Allow issue comment/update/label drafts only for configured repositories with an in-scope open issue; validate filenames, bind comment names to body content, and require exact repository label name/color/description. Installed for both ordinary CLI cloud mounts and direct library mounts.
  • Identity behavior: "user" always uses local gh; "auto" prefers App for PRs while keeping gh for issue lifecycle. Notion intake’s GitHub publisher is unchanged.