Skip to content

fix(agent): supplied patch/summary sources no longer require a git repository - #2052

Merged
gfargo-horizon-agent[bot] merged 5 commits into
mainfrom
agent/coco-1219-coco-1836-fix-agent-supplied-patch-summa
Aug 4, 2026
Merged

fix(agent): supplied patch/summary sources no longer require a git repository#2052
gfargo-horizon-agent[bot] merged 5 commits into
mainfrom
agent/coco-1219-coco-1836-fix-agent-supplied-patch-summa

Conversation

@gfargo-horizon-agent

@gfargo-horizon-agent gfargo-horizon-agent Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What

When a calling agent supplies its own change context via a patch, summary, or files source, review, changelog, and recap operations can now run from a directory that is not a git repository — over both the agent CLI and the MCP server. Previously, both transports resolved a git repository root unconditionally before inspecting the request source, causing an unhelpful INVALID_REPOSITORY error even when the repository was never needed.

Why

Closes #1836
Plane: OSS-1219

How

  • operations/agent/context.ts: Added requiresRepository(operation, source) predicate (true for commit-draft and kind: 'repository', false for all other supplied sources). Widened AgentOperationContext.git to SimpleGit | undefined and added requireRepository flag to createAgentOperationContext. Added warnings: string[] to ResolvedChangeContext; resolveChangeSource now emits a warning when headRevision is supplied but no git repo is available (stays provided-unverified) and throws INVALID_REPOSITORY for kind: 'repository' sources with no git context.
  • commands/agent/handler.ts: Compute needsRepo from the predicate before resolving the root. For supplied sources, fall back to resolveAgentDirectoryRoot + requireRepository: false on INVALID_REPOSITORY; re-throw REPOSITORY_OUTSIDE_ROOT and CANCELLED. Emit a descriptive error message for commit-draft with no repo.
  • mcp/server.ts: Same conditional branching in registerGenerationTool; skip resolveEffectiveRepoRoot/assertClientAllowsRoot for supplied sources when no repository is available; re-throw REPOSITORY_MISMATCH/REPOSITORY_OUTSIDE_ROOT.
  • operations/agent/generate.ts: Guard generateAgentCommitDraft with an explicit !context.git check for a clear diagnostic; thread resolved.warnings through all four operation envelopes.
  • commands/watch/handler.ts: Non-null assertion on context.git (watch always operates on a repository source).
  • Tests: New requiresRepository and createAgentOperationContext with requireRepository: false describe blocks in context.test.ts; new handler and MCP server test cases covering the no-repo fallback and commit-draft failure path; mock ResolvedChangeContext values updated to include the new warnings field.

Out of scope (noted in the issue): condense-diff has the same unconditional resolution shape for its patch source (dispatched separately via runCondenseDiff) — left repository-bound as a follow-up.

Testing

  • build passes (npx tsc --noEmit)
  • all directly-modified test files pass (115 tests across 6 suites)
  • lint clean (0 errors)
  • CI: pending

🤖 Generated by the harbor agent loop. Reviewed by a human before merge.

Closes #1836

…pository

review, changelog, and recap operations with a caller-supplied patch, summary,
or files source can now run from a non-git directory — over both the agent CLI
and MCP — without failing with INVALID_REPOSITORY.

Changes:
- Add requiresRepository(operation, source) predicate in context.ts: returns
  true for commit-draft (always needs a repo for branch/history context) and
  kind: 'repository' sources; false for all other supplied-source operations.
- Widen AgentOperationContext.git to SimpleGit | undefined and add
  requireRepository flag to createAgentOperationContext. When false, the
  context is created from the resolved directory without a git client.
- Add warnings: string[] to ResolvedChangeContext. resolveChangeSource now
  emits a warning when headRevision was supplied but no git repo is available
  to verify it (stays provided-unverified), and throws INVALID_REPOSITORY for
  kind: 'repository' sources when no git is present.
- handler.ts: compute needsRepo before resolving the repo; on INVALID_REPOSITORY
  for supplied sources fall back to resolveAgentDirectoryRoot + requireRepository:
  false; re-throw REPOSITORY_OUTSIDE_ROOT and CANCELLED; emit a descriptive
  INVALID_REPOSITORY message for commit-draft.
- mcp/server.ts: same branching in registerGenerationTool; skip
  resolveEffectiveRepoRoot / assertClientAllowsRoot for supplied sources when
  no repository is declared; re-throw REPOSITORY_MISMATCH / REPOSITORY_OUTSIDE_ROOT.
- generate.ts: guard generateAgentCommitDraft with !context.git check for a
  clear error message; thread resolved.warnings through all operation envelopes.
- watch/handler.ts: add non-null assertion on context.git (watch always operates
  on a repository source).
- Tests: new describe blocks for requiresRepository and
  createAgentOperationContext with requireRepository: false in context.test.ts;
  new handler.test.ts cases for review-from-non-git and commit-draft failure;
  new mcp/server.test.ts case for supplied source with no repo declared; fix
  ResolvedChangeContext mock values in generate/watch/additionalContext tests
  to include the new warnings field.

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Agent review (kiro · sonnet→opus) — CONCERNS

REVIEW: CONCERNS
RESOLVES: full

The PR correctly makes repository resolution conditional across both transports for supplied sources, keeps commit-draft and repository sources bound, and adds solid unit/transport coverage. Two parity gaps remain between the CLI and MCP transports (commit-draft error message and CANCELLED handling), both mergeable judgment calls rather than functional bugs.

2 concerns · 1 nit — 3 inline on the diff

Comment thread src/mcp/server.ts Outdated
Comment thread src/mcp/server.ts
Comment thread src/commands/agent/handler.ts Outdated

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Agent re-review (sonnet, delta) — BLOCK

REVIEW: BLOCK
RESOLVES: no

The PR on GitHub (pull/2052) has only one commit, 104125e, identical to what was already reviewed — no new commit was pushed. All three previously flagged fixes exist only as uncommitted changes in the local worktree, so the live PR still has the generic commit-draft error message, the CANCELLED-swallowing bug, and the duplicated-repository-phrasing wording.

  • Revise fixes were never committed or pushed — git diff origin/main...HEAD and gh pr diff 2052 both show only commit 104125e, the same commit already reviewed. The fixes for the three previously flagged issues (generic MCP commit-draft error, unswallowed CANCELLED re-throw, duplicated 'repository' wording) exist only as uncommitted changes in src/mcp/server.ts, src/commands/agent/handler.ts, and src/operations/agent/context.ts in the worktree — they were never committed, so PR #2052 on GitHub still has all three original defects. Since this review must not commit/push, the PR remains unresolved until those local edits are actually committed and pushed.

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Agent re-review (sonnet, delta) — CONCERNS

Tests look proportionate and correctly updated. Let me run the actual test suites to confirm they pass with the current committed state.

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Agent re-review (kiro · sonnet, delta) — LGTM

REVIEW: LGTM
RESOLVES: full

The revise correctly addresses both prior concerns: commit-draft now emits a context-specific INVALID_REPOSITORY message at both transports (handler.ts and server.ts), and CANCELLED is re-thrown before the no-repo fallback in both the CLI and MCP supplied-source paths. No new regressions, scope creep, or missing coverage introduced.

…1836-fix-agent-supplied-patch-summa

# Conflicts:
#	src/commands/agent/handler.ts
#	src/mcp/server.ts

@gfargo-horizon-agent gfargo-horizon-agent Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔎 Agent re-review (kiro · sonnet, delta) — LGTM

REVIEW: LGTM
RESOLVES: full

Both parity gaps from the prior review are resolved: the commit-draft-specific INVALID_REPOSITORY message is now emitted consistently in both transports, and CANCELLED is re-thrown (not swallowed) in the no-repo fallback path of both handler.ts and server.ts. No new issues introduced.

@gfargo-horizon-agent
gfargo-horizon-agent Bot merged commit 4226c03 into main Aug 4, 2026
11 checks passed
@gfargo-horizon-agent
gfargo-horizon-agent Bot deleted the agent/coco-1219-coco-1836-fix-agent-supplied-patch-summa branch August 4, 2026 18:16
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.

fix(agent): supplied patch/summary sources still require an unrelated git repository

0 participants