Skip to content

chore: prepare codebase for new harness contributions - #13

Merged
srbouffard merged 5 commits into
mainfrom
chore/refactorize-for-new-harnesses
Jun 18, 2026
Merged

chore: prepare codebase for new harness contributions#13
srbouffard merged 5 commits into
mainfrom
chore/refactorize-for-new-harnesses

Conversation

@srbouffard

Copy link
Copy Markdown
Owner

What

Split the monolithic app.go into per-harness files and add the tests and documentation needed to make contributing a new harness (e.g. Hermes, OpenCode) straightforward.

Changes

Code organisation

  • Extract copilot capture/reconcile/install logic → internal/cli/app_copilot.go
  • Extract VS Code capture logic → internal/cli/app_vscode.go
  • app.go is now generic dispatch only; the switch in runCapture() is the single extension point for new harnesses

Tests (23 total, all green)

  • app_copilot_test.go: integration tests for the full App.Run() path — final session, provisional session, missing sessionId, unknown harness, install --print-config, reconcile provisional→final, reconcile best_effort
  • Complements the existing app_vscode_test.go integration tests
  • internal/copilot/testdata/: session_final.jsonl and session_provisional.jsonl fixture files

Docs

  • docs/adding-a-harness.md: step-by-step guide covering file structure, working code examples, SessionSummary field reference, reconcile guidance, test patterns, and a checklist

Adding a harness after this PR

Three things:

  1. Create internal/<name>/ with a Summarize() function
  2. Create internal/cli/app_<name>.go with a runCapture<Name>() method
  3. Add one case to the switch in runCapture() in app.go

srbouffard and others added 2 commits June 18, 2026 14:58
- Extract copilot capture/reconcile/install logic from app.go into
  app_copilot.go; VS Code logic into app_vscode.go. app.go is now
  generic dispatch only — the switch in runCapture() is the natural
  extension point for new harnesses.
- Add app_copilot_test.go with integration tests covering the final,
  provisional, missing-sessionId, and unknown-harness cases.
- Add internal/copilot/testdata/ fixtures (session_final.jsonl and
  session_provisional.jsonl) as canonical examples of both states.
- Add docs/adding-a-harness.md: step-by-step guide for contributors
  including file structure, SessionSummary field reference, reconcile
  guidance, test patterns, and a checklist.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add TestRunReconcileUpgradesProvisionalToFinal: verifies the full
  provisional→final upgrade path through App.Run(reconcile).
- Add TestRunReconcileMarksBestEffortWhenExhausted: verifies that
  a reconcile that exhausts without finding shutdown metrics marks
  the session as best_effort and returns an error.
- Add TestRunInstallCopilotPrintConfig: verifies --print-config
  emits valid JSON containing the sessionEnd hook and binary path.
- Fix missing imports (encoding/json, fmt, time) in the
  app_myharness.go code example in docs/adding-a-harness.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread internal/cli/app_copilot.go Fixed
srbouffard and others added 3 commits June 18, 2026 16:21
defer logFile.Close() on a writable fd without checking the error is a
CodeQL-flagged pattern. The child process writes directly to the kernel
fd so there is no Go-side buffering to lose, but make the intentional
discard explicit with defer func() { _ = logFile.Close() }() to satisfy
static analysis and document the reasoning.

Pre-existing issue surfaced by CodeQL on this PR's diff.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove boilerplate code examples in favour of directing contributors to
the existing harness implementations as the canonical reference. Add
explanations of the two key challenges a harness author will encounter:

- Hook payloads are thin; the real data lives in a separate log or API
  that must be located via session ID and CWD.
- Final metrics may arrive after the hook exits; use provisional capture
  + async reconcile rather than blocking the hook runner.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Agents tackling a new harness integration will now be directed to the
guide and the copilot harness as the canonical reference before writing
any code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@srbouffard
srbouffard merged commit e514d5b into main Jun 18, 2026
5 checks passed
@srbouffard
srbouffard deleted the chore/refactorize-for-new-harnesses branch June 18, 2026 14:31
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