Skip to content

refactor: consolidate Track A RunContract formatting#132

Merged
devkade merged 3 commits into
devfrom
refactor/issue-128-runcontract-format-cleanup
May 15, 2026
Merged

refactor: consolidate Track A RunContract formatting#132
devkade merged 3 commits into
devfrom
refactor/issue-128-runcontract-format-cleanup

Conversation

@devkade
Copy link
Copy Markdown
Owner

@devkade devkade commented May 15, 2026

Summary

  • Extracted RunContract presentation formatting from src/presentation/messages.ts into src/presentation/run-contract-format.ts.
  • Refactored renderRunContractPrompt into small formatting helpers while preserving prompt wording and adapter-neutral semantics.
  • Expanded prompt-renderer tests and added direct RunContract formatter regression coverage.

Refactor target evidence

  • src/presentation/messages.ts: inline formatRunContractSection, formatRunContractInline, missingExpectationCount, and runContractForState were presentation helpers embedded in the larger UI formatter module.
  • src/domain/run-contract-prompt-renderer.ts: long template-literal sections for runtime context, artifact cadence, shared lifecycle, and Kapi rules were drift-prone after refactor: unify RunContract prompt rendering across service and CLI runtime #115's shared renderer consolidation.
  • test/run-contract-prompt-renderer.test.ts: setup duplicated long option objects; split fixtures make the shared renderer contract easier to extend without hiding wording changes.

Boundaries preserved

  • RunContract core remains adapter-neutral; no GitHub/PR/kapi-agent/Ragna/Discord semantics were added to domain projection.
  • workflow-validation remains the completion authority; formatter changes only project and display the existing advisory RunContract view.
  • Runtime readiness probe remains separate from RunContract advisory quality.
  • Public CLI/Pi wording is preserved except internal formatting helpers now own the same text.

Verification

  • npm test -- test/run-contract-format.test.ts test/run-contract-prompt-renderer.test.ts test/presentation-ui.test.ts
  • npm run verify
  • git diff --check

Closes #133

Part of #128

Revision explanation for current head d4e6d4b4b6eb5530f3e503f0a031d40826096fd0

What changed:

Why this closes the prior feedback:

  • Prior feedback on fae23f... identified a review harness invocation failure caused by the branch being behind dev.
  • Current head d4e6d4b4b6eb5530f3e503f0a031d40826096fd0 includes current dev, so that harness contract is present.
  • Size gate remains below 200 changed lines.

Verification for this head:

  • git diff --check origin/dev...HEAD passed.
  • npm run verify passed after alignment.

Copy link
Copy Markdown

@kapi-agent kapi-agent Bot left a comment

Choose a reason for hiding this comment

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

kapi-agent review

Verdict: REQUEST_CHANGES

Blocking issues

  • Size gate failed: this PR has 232 changed lines, which exceeds the 200-line hard limit. Please split this into multiple PRs, each under 200 changed lines and scoped to one semantic unit.
  • Because the verifier gate failed, I cannot approve this revision even if the refactor appears mechanically reasonable.

Suggested split:

  • PR 1: extract src/presentation/run-contract-format.ts from src/presentation/messages.ts with focused tests.
  • PR 2: refactor src/domain/run-contract-prompt-renderer.ts helper formatting and its prompt-renderer tests.

Warnings / risks

  • The touched area is artifact/workflow-contract presentation logic, where small formatting changes can affect downstream prompt/workflow expectations. Please keep each split PR narrow enough that wording-preservation can be reviewed independently.

Suggestions

  • In the follow-up PR descriptions, explicitly state which output strings are intended to remain byte-for-byte stable and which are intentionally reformatted.
  • Include targeted test commands for each split PR, not only the full verifier.

Looks good

  • The extracted run-contract-format.ts appears to preserve the prior compact RunContract summary behavior.
  • Added direct tests for RunContract formatter behavior are the right kind of regression coverage for this refactor.

Verification notes

  • Verifier gate status: FAIL — size gate failed: 232 changed lines >= 200.
  • Size gate status: FAIL — must be below 200 changed lines.
  • Revision-explanation status: not required for this opened PR; found true.
  • Reported author verification: npm test -- test/run-contract-format.test.ts test/run-contract-prompt-renderer.test.ts test/presentation-ui.test.ts, npm run verify, and git diff --check, but approval is blocked by the size gate.

Engine: pi

@devkade
Copy link
Copy Markdown
Owner Author

devkade commented May 15, 2026

@kapi-agent review

Revision explanation for current head fae23f29e106d4f62c2f145ad1c0ca5d81489848:

What changed:

  • Compactly rewrote the two new RunContract formatter/prompt-renderer test fixtures without changing production behavior.
  • Reduced the PR diff from 232 changed lines to 190 changed lines, below the kapi-agent hard size gate.

Why this closes the prior feedback:

Verification:

  • git diff --check passed.
  • npm test -- test/run-contract-format.test.ts test/run-contract-prompt-renderer.test.ts test/presentation-ui.test.ts passed.
  • npm run verify passed.

@devkade
Copy link
Copy Markdown
Owner Author

devkade commented May 15, 2026

@kapi-agent review

Revision explanation for current head fae23f282a09848bc77d235d7f71e5bf600573d9:

What changed:

  • Compactly rewrote the two new RunContract formatter/prompt-renderer test fixtures without changing production behavior.
  • Reduced the PR diff from 232 changed lines to 190 changed lines, below the kapi-agent hard size gate.

Why this closes the prior feedback:

Verification:

  • git diff --check passed.
  • npm test -- test/run-contract-format.test.ts test/run-contract-prompt-renderer.test.ts test/presentation-ui.test.ts passed.
  • npm run verify passed.

Copy link
Copy Markdown

@kapi-agent kapi-agent Bot left a comment

Choose a reason for hiding this comment

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

kapi-agent review

Verdict: REQUEST_CHANGES

Blocking issues

  • Revision explanation gate failed. This PR was updated after a prior kapi-agent changes-requested review, but there is no author comment or PR-body update explaining what changed and why. Please add a review response summarizing:

    • what changed since the previous kapi-agent review,
    • why those changes address the prior size/verifier feedback,
    • any remaining intentional scope.

    After that, request re-review.

Warnings / risks

  • The touched code is RunContract/workflow prompt presentation logic (src/domain/run-contract-prompt-renderer.ts, src/presentation/messages.ts, src/presentation/run-contract-format.ts). Even formatting-only refactors can affect downstream prompt expectations, so preserving exact wording and section spacing remains important.
  • formatKapiRules() now builds the same runtime guidance through line arrays. The current tests appear to cover this, but any future edits should keep byte-for-byte prompt output regression tests close to this code.

Suggestions

  • Add the missing revision response as a PR comment rather than relying only on commit messages, so the review history clearly shows how the prior feedback was addressed.
  • In the revision response, explicitly call out that the PR is now under the 200-line limit and that npm run verify passes.

Looks good

  • Size is now within the hard gate: 190 changed lines.
  • The extraction from src/presentation/messages.ts to src/presentation/run-contract-format.ts appears mechanically scoped and preserves the existing compact RunContract summary wording.
  • The helper extraction in src/domain/run-contract-prompt-renderer.ts improves maintainability without obvious adapter/runtime coupling.
  • Added regression coverage in test/run-contract-format.test.ts directly protects the newly extracted presentation formatter behavior.

Verification notes

  • Verifier gate status: FAIL, because the revision explanation gate failed.
  • Size gate status: PASS — 190 changed lines, under the 200-line limit.
  • Revision-explanation status: FAIL — prior kapi-agent review exists, this is a revised PR, and no explanation of what changed and why was found.
  • CI/local evidence provided: npm ci && npm run verify exited 0, including test, check, unused check, and quality budget commands.

Engine: pi

@devkade
Copy link
Copy Markdown
Owner Author

devkade commented May 15, 2026

@kapi-agent review

Revision explanation for current head fae23f282a09848bc77d235d7f71e5bf600573d9:

What changed:

  • Reduced the current PR diff to 190 changed lines by compacting only the newly-added formatter/prompt-renderer test fixtures.
  • Left production refactor semantics unchanged: messages.ts still delegates RunContract compact formatting, and renderRunContractPrompt still uses shared helper-rendered sections.

Why this closes the prior feedback:

  • The prior blocking feedback was the hard size gate (232 changed lines >= 200).
  • Current GitHub PR size is now 190 changed lines, so the size gate is satisfied.
  • Remaining scope is intentional for issue refactor: bound Track A RunContract formatter cleanup #133: presentation RunContract formatter extraction plus shared prompt-renderer helper cleanup, with no GitHub/PR/Discord/Ragna semantics introduced into RunContract core.

Verification:

  • git diff --check passed.
  • npm test -- test/run-contract-format.test.ts test/run-contract-prompt-renderer.test.ts test/presentation-ui.test.ts passed.
  • npm run verify passed.

@kapi-agent
Copy link
Copy Markdown

kapi-agent Bot commented May 15, 2026

kapi-agent review

Verdict: REQUEST_CHANGES

Blocking issues

  • Verification gate failed: the Ilchul review harness gate failed with a merge-blocking finding:
    • Ilchul review CLI failed
    • Evidence: Unexpected kapi-review arguments: --input-file .../review-input.json
  • Per gate policy, I cannot approve while any configured gate is FAIL, even though the size gate and normal verifier passed.

Warnings / risks

  • The changed code is workflow-contract and RunContract presentation logic:
    • src/domain/run-contract-prompt-renderer.ts
    • src/presentation/messages.ts
    • src/presentation/run-contract-format.ts
  • Formatting refactors in this area can create regressions in prompt/workflow contract expectations even when behavior looks mechanically equivalent. The new focused tests reduce this risk, but byte-for-byte prompt stability remains important.

Suggestions

  • Fix the Ilchul review harness invocation/configuration so it accepts the current review input contract or update the caller to use the expected CLI arguments.
  • After the harness is fixed, request re-review without expanding this PR’s semantic scope.
  • Consider adding a small regression test around the Ilchul/kapi-review CLI argument contract if this failure came from project code rather than external review infrastructure.

Looks good

  • Size gate now passes: 190 changed lines, under the 200-line hard limit.
  • The revision explanation is present and directly addresses the prior kapi-agent feedback.
  • The extraction from src/presentation/messages.ts to src/presentation/run-contract-format.ts appears mechanically scoped and preserves the existing compact RunContract wording.
  • The prompt-renderer helper refactor keeps the same section ordering and readable construction while improving maintainability.
  • Added tests cover the new RunContract formatter surface and unknown workflow behavior.

Verification notes

  • Verifier gate status: FAIL due to Ilchul review harness failure.
  • Size gate status: PASS, 190 changed lines < 200.
  • Revision-explanation status: PASS, explanation found.
  • Standard verifier evidence: PASS, npm ci && npm run verify exited 0.
  • Reviewed evidence includes the changed files and tests listed in the PR context, especially:
    • src/domain/run-contract-prompt-renderer.ts
    • src/presentation/messages.ts
    • src/presentation/run-contract-format.ts
    • test/run-contract-format.test.ts

Engine: pi


kapi-agent request lifecycle:

  • Status: COMPLETED
  • Head: fae23f282a09
  • Formal review event: REQUEST_CHANGES
  • Review API status: 200
  • Required check API status: 201

Copy link
Copy Markdown

@kapi-agent kapi-agent Bot left a comment

Choose a reason for hiding this comment

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

kapi-agent review

Verdict: REQUEST_CHANGES

Blocking issues

  • Verification gate failed: the Ilchul review harness gate failed with a merge-blocking finding:
    • Ilchul review CLI failed
    • Evidence: Unexpected kapi-review arguments: --input-file .../review-input.json
  • Per gate policy, I cannot approve while any configured gate is FAIL, even though the size gate and normal verifier passed.

Warnings / risks

  • The changed code is workflow-contract and RunContract presentation logic:
    • src/domain/run-contract-prompt-renderer.ts
    • src/presentation/messages.ts
    • src/presentation/run-contract-format.ts
  • Formatting refactors in this area can create regressions in prompt/workflow contract expectations even when behavior looks mechanically equivalent. The new focused tests reduce this risk, but byte-for-byte prompt stability remains important.

Suggestions

  • Fix the Ilchul review harness invocation/configuration so it accepts the current review input contract or update the caller to use the expected CLI arguments.
  • After the harness is fixed, request re-review without expanding this PR’s semantic scope.
  • Consider adding a small regression test around the Ilchul/kapi-review CLI argument contract if this failure came from project code rather than external review infrastructure.

Looks good

  • Size gate now passes: 190 changed lines, under the 200-line hard limit.
  • The revision explanation is present and directly addresses the prior kapi-agent feedback.
  • The extraction from src/presentation/messages.ts to src/presentation/run-contract-format.ts appears mechanically scoped and preserves the existing compact RunContract wording.
  • The prompt-renderer helper refactor keeps the same section ordering and readable construction while improving maintainability.
  • Added tests cover the new RunContract formatter surface and unknown workflow behavior.

Verification notes

  • Verifier gate status: FAIL due to Ilchul review harness failure.
  • Size gate status: PASS, 190 changed lines < 200.
  • Revision-explanation status: PASS, explanation found.
  • Standard verifier evidence: PASS, npm ci && npm run verify exited 0.
  • Reviewed evidence includes the changed files and tests listed in the PR context, especially:
    • src/domain/run-contract-prompt-renderer.ts
    • src/presentation/messages.ts
    • src/presentation/run-contract-format.ts
    • test/run-contract-format.test.ts

Engine: pi

@devkade
Copy link
Copy Markdown
Owner Author

devkade commented May 15, 2026

@kapi-agent review

Revision explanation for current head d4e6d4b4b6eb5530f3e503f0a031d40826096fd0:

What changed:

Why this closes the prior feedback:

  • The latest blocker was the review harness invocation failing because this PR head lacked the current kapi-review --input-file contract from dev.
  • The current head now includes origin/dev, so the review harness should run against the current CLI contract while the PR's semantic diff remains unchanged.
  • Size gate remains satisfied at 190 changed lines.

Verification:

  • git diff --check origin/dev...HEAD passed.
  • npm run verify passed after merging current origin/dev.

Copy link
Copy Markdown

@kapi-agent kapi-agent Bot left a comment

Choose a reason for hiding this comment

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

kapi-agent review

Verdict: REQUEST_CHANGES

Blocking issues

  • Revision explanation gate failed. This PR was updated after prior kapi-agent reviews, but no revision explanation was found for the current head d4e6d4b4b6eb5530f3e503f0a031d40826096fd0. The existing author comments explain earlier fae23f... heads, not the current revision.
    • Please add a PR comment or PR body update explaining:
      • what changed since the last kapi-agent review,
      • why the current head closes the prior feedback,
      • whether the semantic scope changed,
      • what verification was run for this exact revision.
    • After that, request re-review.

Warnings / risks

  • The changed area remains workflow-contract and RunContract presentation logic:
    • src/domain/run-contract-prompt-renderer.ts
    • src/presentation/messages.ts
    • src/presentation/run-contract-format.ts
  • Formatting-only refactors in this area can still affect downstream prompt/workflow expectations. The added regression tests reduce that risk, but byte-for-byte wording and spacing should remain explicitly protected.

Suggestions

  • In the revision response, explicitly call out whether the current d4e6d4... revision only preserves the prior 190-line scoped refactor or includes any additional changes.
  • Consider keeping future prompt-formatting changes in similarly focused PRs with direct output regression tests.

Looks good

  • Size gate now passes: 190 changed lines is under the 200-line hard limit.
  • Standard verification passed: npm ci && npm run verify exited 0.
  • The extracted src/presentation/run-contract-format.ts appears mechanically equivalent to the previous inline formatter in messages.ts.
  • The new formatter tests cover compact RunContract summary wording and unknown workflow handling.
  • The prompt-renderer refactor is organized into smaller helpers without obvious adapter/runtime boundary leakage.

Verification notes

  • Verifier gate status: FAIL overall, because the revision explanation gate failed.
  • Size gate status: PASS, 190 changed lines < 200.
  • Revision-explanation status: FAIL for current head d4e6d4b4b6eb5530f3e503f0a031d40826096fd0.
  • Normal verifier status: PASS, npm ci && npm run verify exited 0.
  • Ilchul review harness status: PASS/neutral, no blocking findings.

Engine: pi

@devkade
Copy link
Copy Markdown
Owner Author

devkade commented May 15, 2026

@kapi-agent review

@kapi-agent
Copy link
Copy Markdown

kapi-agent Bot commented May 15, 2026

kapi-agent review

Verdict: APPROVE

Final approval summary

Review journey

The original goal was to consolidate Track A RunContract formatting while preserving workflow/prompt behavior. The semantic scope is limited to extracting compact RunContract presentation helpers from src/presentation/messages.ts and simplifying renderRunContractPrompt formatting helpers in src/domain/run-contract-prompt-renderer.ts. Prior kapi-agent feedback blocked on PR size, then missing/current revision explanation, then a review harness contract failure; the current revision includes an author explanation for the current head and aligns with origin/dev to restore the harness.

What changed

  • Added src/presentation/run-contract-format.ts for RunContract presentation formatting.
  • Updated src/presentation/messages.ts to delegate to the extracted formatter.
  • Refactored src/domain/run-contract-prompt-renderer.ts into small section-formatting helpers.
  • Added/updated tests in:
    • test/run-contract-format.test.ts
    • test/run-contract-prompt-renderer.test.ts

Why this is correct

The extraction preserves the same compact RunContract wording and keeps presentation-specific formatting outside the larger messages module. The prompt renderer refactor is mechanical: it builds the same sections through helper functions while preserving workflow/runtime layout boundaries and avoiding adapter-specific semantics.

Evidence

  • Verifier gate: PASS.
  • Size gate: PASS, 190 changed lines under the 200-line hard limit.
  • Revision-explanation status: PASS, explanation found for current head d4e6d4b4b6eb5530f3e503f0a031d40826096fd0.
  • Ilchul review harness gate: PASS, neutral/comment result with 0 blocking findings.
  • npm ci && npm run verify exited 0.
  • Local inspection included git diff --stat origin/dev...HEAD, git diff --check origin/dev...HEAD, and the changed RunContract prompt/formatter tests.

Remaining risks and approval rationale

Remaining risk is low and limited to prompt wording regressions in workflow contract output. The focused regression tests cover the extracted formatter and prompt-renderer boundaries, all configured gates pass, and no blocking issue remains, so approval is justified.

Blocking issues

  • none.

Warnings / risks

  • Prompt/workflow contract formatting remains a sensitive area. Future edits to src/domain/run-contract-prompt-renderer.ts or src/presentation/run-contract-format.ts should keep byte-for-byte wording tests close to the changed text.

Suggestions

  • Consider snapshot-style or exact-string tests for full workflow/runtime prompt outputs if this formatting continues to evolve.

Looks good

  • The extracted run-contract-format.ts keeps RunContract UI formatting cohesive and testable.
  • messages.ts is simpler after delegating RunContract-specific formatting.
  • The helper split in run-contract-prompt-renderer.ts improves maintainability without adding adapter-specific concepts.
  • Tests cover the compact formatter output, unknown workflow behavior, shared renderer path, and runtime adapter-neutrality.

Verification notes

  • Verifier gate: PASS — npm ci && npm run verify exited 0.
  • Size gate: PASS — 190 changed lines, below the 200-line limit.
  • Revision-explanation status: PASS — current-head explanation found.
  • Ilchul review harness gate: PASS — no blocking findings.
  • Local evidence: git diff --check origin/dev...HEAD passed.

Engine: pi


kapi-agent request lifecycle:

  • Status: COMPLETED
  • Head: d4e6d4b4b6eb
  • Formal review event: APPROVE
  • Review API status: 200
  • Required check API status: 201

Copy link
Copy Markdown

@kapi-agent kapi-agent Bot left a comment

Choose a reason for hiding this comment

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

kapi-agent review

Verdict: APPROVE

Final approval summary

Review journey

The original goal was to consolidate Track A RunContract formatting while preserving workflow/prompt behavior. The semantic scope is limited to extracting compact RunContract presentation helpers from src/presentation/messages.ts and simplifying renderRunContractPrompt formatting helpers in src/domain/run-contract-prompt-renderer.ts. Prior kapi-agent feedback blocked on PR size, then missing/current revision explanation, then a review harness contract failure; the current revision includes an author explanation for the current head and aligns with origin/dev to restore the harness.

What changed

  • Added src/presentation/run-contract-format.ts for RunContract presentation formatting.
  • Updated src/presentation/messages.ts to delegate to the extracted formatter.
  • Refactored src/domain/run-contract-prompt-renderer.ts into small section-formatting helpers.
  • Added/updated tests in:
    • test/run-contract-format.test.ts
    • test/run-contract-prompt-renderer.test.ts

Why this is correct

The extraction preserves the same compact RunContract wording and keeps presentation-specific formatting outside the larger messages module. The prompt renderer refactor is mechanical: it builds the same sections through helper functions while preserving workflow/runtime layout boundaries and avoiding adapter-specific semantics.

Evidence

  • Verifier gate: PASS.
  • Size gate: PASS, 190 changed lines under the 200-line hard limit.
  • Revision-explanation status: PASS, explanation found for current head d4e6d4b4b6eb5530f3e503f0a031d40826096fd0.
  • Ilchul review harness gate: PASS, neutral/comment result with 0 blocking findings.
  • npm ci && npm run verify exited 0.
  • Local inspection included git diff --stat origin/dev...HEAD, git diff --check origin/dev...HEAD, and the changed RunContract prompt/formatter tests.

Remaining risks and approval rationale

Remaining risk is low and limited to prompt wording regressions in workflow contract output. The focused regression tests cover the extracted formatter and prompt-renderer boundaries, all configured gates pass, and no blocking issue remains, so approval is justified.

Blocking issues

  • none.

Warnings / risks

  • Prompt/workflow contract formatting remains a sensitive area. Future edits to src/domain/run-contract-prompt-renderer.ts or src/presentation/run-contract-format.ts should keep byte-for-byte wording tests close to the changed text.

Suggestions

  • Consider snapshot-style or exact-string tests for full workflow/runtime prompt outputs if this formatting continues to evolve.

Looks good

  • The extracted run-contract-format.ts keeps RunContract UI formatting cohesive and testable.
  • messages.ts is simpler after delegating RunContract-specific formatting.
  • The helper split in run-contract-prompt-renderer.ts improves maintainability without adding adapter-specific concepts.
  • Tests cover the compact formatter output, unknown workflow behavior, shared renderer path, and runtime adapter-neutrality.

Verification notes

  • Verifier gate: PASS — npm ci && npm run verify exited 0.
  • Size gate: PASS — 190 changed lines, below the 200-line limit.
  • Revision-explanation status: PASS — current-head explanation found.
  • Ilchul review harness gate: PASS — no blocking findings.
  • Local evidence: git diff --check origin/dev...HEAD passed.

Engine: pi

@devkade devkade merged commit ab2448c into dev May 15, 2026
4 of 6 checks passed
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.

refactor: bound Track A RunContract formatter cleanup

1 participant