Skip to content

feat(miner-hands): Agent-SDK CodingAgentDriver (query() loop) - #4548

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
reyanthony062001-ops:feat/agent-sdk-driver-4267
Jul 10, 2026
Merged

feat(miner-hands): Agent-SDK CodingAgentDriver (query() loop)#4548
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
reyanthony062001-ops:feat/agent-sdk-driver-4267

Conversation

@reyanthony062001-ops

Copy link
Copy Markdown
Contributor

Closes #4267

What

The Agent-SDK CodingAgentDriver implementation of #4262's seam: createAgentSdkCodingAgentDriver drives the coding agent in-process via @anthropic-ai/claude-agent-sdk's query() async-iterable loop, complementing the CLI-subprocess driver that just landed for #4266. Rebased onto current main, so it composes cleanly with the CLI driver's and repo-map's engine exports. New dependency @anthropic-ai/claude-agent-sdk@^0.3.205 on packages/gittensory-engine — no @anthropic-ai/* package existed in the repo before this, peer deps satisfied by existing root versions, npm audit --audit-level=moderate clean. Supply-chain note: the package publishes no SLSA/sigstore attestation yet; caret-pinned and lockfile-resolved.

How it maps to the issue's deliverables

  • query() loop → shared result shape: streamed SDK frames fold in the driver — assistant text into the transcript, tool_use frames for Edit/Write/NotebookEdit into changedFiles (deduped; Bash et al. are not file changes), the terminal result frame into ok/error/turnsUsed/summary. No SDK event type leaks into CodingAgentDriver — the exported AgentSdkQueryFn consumes plain records.
  • Interchangeability with the CLI-subprocess driver: same scoped inputs (cwd = task.workingDirectory, maxTurns budget, instructions verbatim as the prompt, acceptance criteria materialized in the worktree per feat(miner-hands): immutable acceptance-criteria file written before the coding agent starts #4271), structured failures that never throw, changedFiles reported only on success, and the same edit-permission scope (permissionMode: "acceptEdits" here vs --permission-mode acceptEdits there — documented at the call site) so test(miner-hands): parity/contract test suite for CodingAgentDriver implementations #4296's parity suite can hold both to one contract.
  • maintainer: PreToolUse-hook-enforced house rules (deny even under bypassPermissions) #2343 hook attachment point: the driver takes hooks and forwards them verbatim onto the query() session options (PreToolUse etc.) — the SDK's hook surface stays reachable from outside the module.
  • No real model calls in CI: tests inject a fake AgentSdkQueryFn (the injected-SpawnFn convention); the real-SDK path is a lazy dynamic import behind the default.

Failure mapping: non-success result subtype → agent_sdk_<subtype>; success + is_erroragent_sdk_errored; stream ending without a result frame → agent_sdk_no_result; a mid-stream throw → agent_sdk_thrown: <redacted detail>. Text that can carry model output (summary, transcript, error detail) passes through the engine's shared redactSecrets (#4284), bounded by one named MAX_REDACTED_TEXT_LENGTH ceiling. Test fixtures build secret-shaped strings at runtime, so no token-shaped literal appears in the diff.

Testing

  • 10 vitest cases in test/unit/agent-sdk-driver.test.ts (the codecov-measured path) and a parity-matched node:test suite in packages/gittensory-engine/test/ — success path (session options, hooks pass-through, changed-file tracking/dedupe, turn count), error_max_turns, is_error on a success subtype, unknown-subtype fallback, missing result frame, Error and non-Error mid-stream throws (redacted), secret redaction in summary/transcript, malformed-frame tolerance, and the no-options constructor.
  • Green on the final rebased commit: engine workspace suite (334/334), root typecheck, git diff --check, npm audit --audit-level=moderate, and 100% line+branch coverage on the new module.

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.07%. Comparing base (c6a5504) to head (4984760).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4548   +/-   ##
=======================================
  Coverage   94.06%   94.07%           
=======================================
  Files         425      426    +1     
  Lines       37774    37815   +41     
  Branches    13794    13813   +19     
=======================================
+ Hits        35533    35574   +41     
  Misses       1586     1586           
  Partials      655      655           
Files with missing lines Coverage Δ
...es/gittensory-engine/src/miner/agent-sdk-driver.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. gittensor:priority Maintainer-selected Gittensor priority — scores a 1.5x multiplier. labels Jul 10, 2026
@loopover-orb

loopover-orb Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Tip

🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩

✅ Gittensory review result - approve/merge recommended

Review updated: 2026-07-10 01:12:56 UTC

6 files · 1 AI reviewer · no blockers · readiness 100/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
Adds createAgentSdkCodingAgentDriver, an in-process Agent-SDK query() loop driver that mirrors the CLI-subprocess driver's contract: structured failures (thrown errors, missing result frame, non-success/is_error result) never throw, changedFiles are deduped from Edit/Write/NotebookEdit tool_use blocks and only reported on success, and hooks are forwarded verbatim to the SDK session per the #2343 attachment point. Every failure branch and the fold logic are exercised by tests against a fake injected AgentSdkQueryFn (a vitest suite against src/ and a node:test suite against dist/, matching the existing CLI-driver test convention), CI including patch/project coverage is green, and the PR closes its linked issue (#4267) with work scoped tightly to the stated seam rather than speculative feature surface.

Nits — 5 non-blocking
  • packages/gittensory-engine/src/miner/agent-sdk-driver.ts: run()'s try/stream-loop/subtype-branch nesting is fairly deep (around line 90-140) — consider extracting the post-loop result classification (no-result / non-success / success) into a small helper for readability.
  • packages/gittensory-engine/src/miner/agent-sdk-driver.ts: transcript is redacted but never length-capped (only summary/error are sliced to MAX_REDACTED_TEXT_LENGTH), so a very chatty session could produce an unbounded transcript string if this is ever persisted or logged wholesale.
  • packages/gittensory-engine/test/agent-sdk-driver.test.ts omits the 'tool_use with missing name' malformed-frame case that test/unit/agent-sdk-driver.test.ts covers — minor asymmetry between the two mirrored suites, not a real coverage gap since patch coverage is measured against src/**.
  • No SLSA/sigstore attestation for the new @​anthropic-ai/claude-agent-sdk dependency, but this is already called out explicitly in the PR description as an accepted, documented risk rather than an oversight.
  • Extract a small classifyResult(resultMessage, transcript, turnsUsed) helper in agent-sdk-driver.ts to flatten the nesting and make the three failure/success branches easier to scan at a glance.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #4267
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 19 registered-repo PR(s), 10 merged, 1 issue(s).
Contributor context ✅ Confirmed Gittensor contributor reyanthony062001-ops; Gittensor profile; 19 PR(s), 1 issue(s).
Gate result ✅ Passing No configured blocker found.
Linked issue satisfaction

Addressed
The PR adds @​anthropic-ai/claude-agent-sdk as a dependency of packages/gittensory-engine, implements createAgentSdkCodingAgentDriver driving query() in an async loop, folds streamed assistant/tool_use/result frames into the shared CodingAgentDriverResult shape (changedFiles, transcript, ok/error, turnsUsed) without leaking SDK types, forwards scoped cwd/maxTurns/hooks (including the #2343 PreToolU

Review context
  • Author: reyanthony062001-ops
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 19 PR(s), 1 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Gittensory approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 8f492f2 into JSONbored:main Jul 10, 2026
10 checks passed
@loopover-orb loopover-orb Bot added gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. and removed gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. gittensor:priority Maintainer-selected Gittensor priority — scores a 1.5x multiplier. labels Jul 10, 2026
@JSONbored JSONbored added gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. gittensor:priority Maintainer-selected Gittensor priority — scores a 1.5x multiplier. and removed gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. labels Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. gittensor:priority Maintainer-selected Gittensor priority — scores a 1.5x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(miner-hands): Agent-SDK CodingAgentDriver (query() loop)

2 participants