Skip to content

refactor(agent-task-loop): share the JSON line scan and run the duplicates gate - #198

Merged
PerfectPan merged 1 commit into
mainfrom
refactor/share-json-line-scan
Nov 18, 2026
Merged

PerfectPan merged 1 commit into
mainfrom
refactor/share-json-line-scan

Conversation

@PerfectPan

@PerfectPan PerfectPan commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Share the last-line-first JSON scan that claudeResultEvents (adapters/claude-lines.ts) and the review verdict parser (services/review-service.ts) each wrote out: jsonLinesLastFirst in src/utils/json-lines.ts. The review output comes from any reviewer agent, so the helper does not live in the Claude adapter. This was the one clone pnpm duplicates reported on main. asReviewPayload now holds the verdict check that the whole-text parse and the line scan both use; a null line, which used to throw inside the try and get skipped, is now skipped by an explicit object check.
  • Run pnpm duplicates in CI after format:check. refactor: share the provider/service shapes and drop the knip export staging #195 added the script (jscpd with @perfectpan/lint-config's zero-threshold profile), but no workflow ran it, so new clones passed CI. It is listed with the CI gates in AGENTS.md and CONTRIBUTING.md, and in the PR and MR templates (kept in sync).
  • No changeset: behavior does not change, like the dedupe refactor in refactor: share the provider/service shapes and drop the knip export staging #195 (CONTRIBUTING.md:102).
  • fix: drop the premature duplicates gate #196 proposed removing this script; it will be closed in favor of this change.

Validation

  • pnpm duplicates on main: 1 clone (claude-lines.ts [36-43] / review-service.ts [36-42]), exit 1. On this branch: Found 0 clones., exit 0.
  • New tests: utils/json-lines.test.ts, adapters/claude-lines.test.ts (non-object lines dropped), and a review-service.test.ts case with trailing null and 42 lines. All three pass on main's source as well (the behavior is unchanged). Removing the object check in asReviewPayload fails the review case with TypeError: Cannot read properties of null (reading 'verdict'); removing the filter in claudeResultEvents fails the claude-lines case.
  • pnpm format:check, gh repo-checks repository, pnpm build, pnpm typecheck, pnpm lint: exit 0.
  • pnpm test: exit 0 (agent-task-loop 545/545, agent-room 70/70, agent-finder-cli 23/23, room-web 195/195). The first run under machine load failed execa-runner.test.ts > kills descendant processes when the cancel signal aborts; it passed three times on its own and in the full rerun.
  • pnpm changeset status: exit 1 only because there is no changeset (see above).

Risks

  • The gate does not scan .tsx: jscpd treats tsx as its own format, and the script passes --format 'typescript,javascript'. With tsx added there are 8 clones in room-web routes, TUI components, and one across agent-finder-cli's sessions-browse-command.tsx and agent-task-loop's commands/tui.tsx. Adding tsx waits until those are resolved, in a separate change.

…cates gate

claudeResultEvents and the review verdict parser each walked an agent's
output last line first and parsed every line as JSON; that loop was the
one clone the duplicates gate reported. Both now use jsonLinesLastFirst,
and the review parser checks for an object before reading the verdict.

CI now runs pnpm duplicates (jscpd with lint-config's zero-threshold
profile), which no workflow ran before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PerfectPan
PerfectPan merged commit fc87403 into main Nov 18, 2026
8 checks passed
@PerfectPan
PerfectPan deleted the refactor/share-json-line-scan branch November 18, 2026 13:37
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.

1 participant