Skip to content

feat/14 append file tool#15

Merged
four-bytes-robby merged 6 commits into
mainfrom
feat/14-append-file-tool
Jun 14, 2026
Merged

feat/14 append file tool#15
four-bytes-robby merged 6 commits into
mainfrom
feat/14-append-file-tool

Conversation

@four-bytes-robby

@four-bytes-robby four-bytes-robby commented Jun 14, 2026

Copy link
Copy Markdown
Member

Closes #14


Summary by cubic

Adds append_file for fast append/prepend-only edits and gh_pr_review for structured GitHub PR review data. Cuts token use, bumps @four-bytes/four-opencode-supertools to 0.4.1, fixes CI fetch-depth for git-diff tests, and cleans up ESLint.

  • New Features

    • append_file: append or prepend; optional after_line; ensures trailing newline. ~95% fewer tokens vs patch_file. Implements feat: add append_file tool for simple file appending #14.
    • gh_pr_review: fetches review states and comments via gh; returns concise structured output with truncation.
    • Both tools registered; tests cover append, prepend, empty files, and missing-file errors.
  • Bug Fixes

    • CI: set fetch-depth: 0 in PR workflow to support git-diff tests using HEAD~1.
    • GitLab: cast response data to any for clearer error messages.
    • Add missing lint script.
    • Lint cleanup: define Bun/fetch/Response globals, use @typescript-eslint/no-unused-vars, and underscore unused params (no functional changes).

Written for commit 157f604. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

Release Notes v0.4.1

  • New Features

    • Added file append/prepend tool for inserting content into files.
    • Added PR review fetching tool to display review comments and submissions.
  • Bug Fixes

    • Fixed GitLab API request payload handling.
  • Tests

    • Added test suite for file append functionality.
  • Chores

    • Improved linting rules and code quality checks.
    • Enhanced CI/CD workflow for better repository history access.

@four-bytes-robby four-bytes-robby self-assigned this Jun 14, 2026
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

Recent review info
Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0415842c-9c7f-404a-b745-e9f89d103c6a

Commits

Reviewing files that changed from the base of the PR and between bf66afd and 157f604.

Files selected for processing (19)
  • .github/workflows/pr.yml
  • eslint.config.js
  • package.json
  • src/four-opencode-supertools.ts
  • src/lib/gh-utils.ts
  • src/lib/git-utils.ts
  • src/lib/gitlab-utils.ts
  • src/tools/append-file.ts
  • src/tools/apply-patch.ts
  • src/tools/curse-score.ts
  • src/tools/gh-pr-comment.ts
  • src/tools/gh-pr-create.ts
  • src/tools/gh-pr-review.ts
  • src/tools/gitlab-mr-comment.ts
  • src/tools/gitlab-mr-create.ts
  • src/tools/gitlab-mr-status.ts
  • src/tools/implicit-coupling.ts
  • src/tools/pr-risk.ts
  • tests/append-file.test.ts

Walkthrough

Walkthrough

Two new tools are added: appendFileTool for appending or prepending text to files, and ghPrReviewTool for fetching GitHub PR review comments and formatting them as a structured report. Both are registered in the plugin tool map. ESLint flat config gains new globals and unused-variable rules, triggering underscore-prefix renames on unused parameters across existing tools. Minor GitLab utility fixes and code formatting cleanups are also applied.

Changes

New tools, linting setup, and minor fixes

Layer / File(s) Summary
appendFileTool implementation and tests
src/tools/append-file.ts, tests/append-file.test.ts
Adds appendFileTool with schema for file_path, content, optional mode, and optional after_line. Execute logic reads the file, branches between append and prepend modes with newline normalization, writes the result, and returns a success or error string. Bun test suite covers append, prepend at top, prepend after a specific line, empty-file cases, and the ENOENT error path.
ghPrReviewTool implementation
src/tools/gh-pr-review.ts
Adds ghPrReviewTool with schema { pr: number, repo?: string }. Execute calls gh pr view --json comments,reviews, filters out empty-body reviews, and returns a structured Reviews and Comments report with author metadata and truncated bodies, or a "No review comments" message.
Plugin registration and package metadata
src/four-opencode-supertools.ts, package.json
Imports and registers ghPrReviewTool and appendFileTool under gh_pr_review and append_file in the tool map. Bumps the version to 0.4.1 and adds a lint script running eslint src/.
ESLint configuration and CI setup
.github/workflows/pr.yml, eslint.config.js
Extends ESLint flat config with browser/Fetch-related globals and @typescript-eslint/no-unused-vars rule with underscore-prefix ignoring. Sets fetch-depth: 0 in CI checkout step for full git history.
Unused parameter renames across existing tools
src/lib/gh-utils.ts, src/lib/git-utils.ts, src/tools/apply-patch.ts, src/tools/curse-score.ts, src/tools/pr-risk.ts, src/tools/implicit-coupling.ts
Renames unused timeout to _timeout in runGh and runGit, ctx to _ctx in apply-patch, and top to _top in curse-score to comply with lint rules. Removes unused Commit type import in pr-risk and unused truncated state in implicit-coupling.
GitHub PR tool schema and formatting updates
src/tools/gh-pr-comment.ts, src/tools/gh-pr-create.ts
Reformats optional repo argument schema from single-line to multi-line chained builder calls in gh-pr-comment and gh-pr-create. Reformats gh-pr-comment's runGh invocation to multi-line layout while preserving command arguments.
GitLab utilities regex, type, and formatting fixes
src/lib/gitlab-utils.ts, src/tools/gitlab-mr-comment.ts, src/tools/gitlab-mr-create.ts, src/tools/gitlab-mr-status.ts
Fixes URL-parsing regex in getGitLabProjectId for proper group/project capture. Changes gitlabApi error message extraction to use (data as any)?.message type assertion. Reformats parameter lists and gitlabApi call sites across GitLab tools without altering runtime behavior.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant ghPrReviewTool
  participant ghCLI
  Caller->>ghPrReviewTool: execute(args, ctx)
  ghPrReviewTool->>ghPrReviewTool: resolve repo from args.repo or ctx
  ghPrReviewTool->>ghCLI: gh pr view pr --json comments,reviews
  ghCLI-->>ghPrReviewTool: raw JSON output
  ghPrReviewTool->>ghPrReviewTool: parse JSON, filter empty-body reviews
  ghPrReviewTool->>ghPrReviewTool: format Reviews and Comments sections
  ghPrReviewTool-->>Caller: formatted report text or error string
Loading

Estimated code review effort

3 (Moderate) | 25 minutes

Possibly related issues

  • feat: add append_file tool for simple file appending #14: This PR directly implements appendFileTool in src/tools/append-file.ts with the specified arg schema (file_path, content, mode, after_line), registers it under append_file, and adds the specified test suite in tests/append-file.test.ts.
  • [FEAT] add gh_pr_review tool to fetch PR review comments #12: This PR adds ghPrReviewTool in src/tools/gh-pr-review.ts with the { pr: number, repo?: string } schema, registers it under gh_pr_review, and implements the review/comment parsing, empty-body filtering, and debug logging described in the issue.
Finishing Touches
Generate docstrings
  • Create stacked PR
  • Commit on current branch
Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/14-append-file-tool
Resolve merge conflicts
  • Resolve merge conflict in branch feat/14-append-file-tool
Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/14-append-file-tool

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Comment @coderabbitai help to get the list of available commands and usage tips.

@four-bytes-robby four-bytes-robby force-pushed the feat/14-append-file-tool branch from 17f23d3 to cf2579b Compare June 14, 2026 21:27

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/tools/gh-pr-review.ts">

<violation number="1" location="src/tools/gh-pr-review.ts:55">
P2: Review-state data is lost by filtering out bodyless reviews. Tool can report “No review comments” even when formal review decisions exist.</violation>
</file>

<file name="src/tools/append-file.ts">

<violation number="1" location="src/tools/append-file.ts:48">
P1: `after_line: -1` is placed at the wrong position in prepend mode. It can insert at the beginning (or after the last content line) instead of before the last line.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/tools/append-file.ts
}
// after_line=0 means position 0 (before first line).
// after_line=N (N>0) means after line at index N, so position N+1.
const insertPos = insertAt === 0 ? 0 : insertAt + 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: after_line: -1 is placed at the wrong position in prepend mode. It can insert at the beginning (or after the last content line) instead of before the last line.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/tools/append-file.ts, line 48:

<comment>`after_line: -1` is placed at the wrong position in prepend mode. It can insert at the beginning (or after the last content line) instead of before the last line.</comment>

<file context>
@@ -0,0 +1,73 @@
+        }
+        // after_line=0 means position 0 (before first line).
+        // after_line=N (N>0) means after line at index N, so position N+1.
+        const insertPos = insertAt === 0 ? 0 : insertAt + 1;
+        const before = lines.slice(0, insertPos);
+        const after = lines.slice(insertPos);
</file context>

Comment thread src/tools/gh-pr-review.ts
const reviews = data.reviews ?? [];

// Filter out empty-body reviews (e.g. bare APPROVED clicks)
const substantiveReviews = reviews.filter((r) => r.body && r.body.trim().length > 0);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Review-state data is lost by filtering out bodyless reviews. Tool can report “No review comments” even when formal review decisions exist.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/tools/gh-pr-review.ts, line 55:

<comment>Review-state data is lost by filtering out bodyless reviews. Tool can report “No review comments” even when formal review decisions exist.</comment>

<file context>
@@ -0,0 +1,107 @@
+      const reviews = data.reviews ?? [];
+
+      // Filter out empty-body reviews (e.g. bare APPROVED clicks)
+      const substantiveReviews = reviews.filter((r) => r.body && r.body.trim().length > 0);
+
+      if (comments.length === 0 && substantiveReviews.length === 0) {
</file context>

@four-bytes-robby four-bytes-robby merged commit 993107a into main Jun 14, 2026
4 of 5 checks passed
@four-bytes-robby four-bytes-robby deleted the feat/14-append-file-tool branch June 14, 2026 21:35
@four-bytes-robby

Copy link
Copy Markdown
Member Author

@cubic-dev-ai Thanks for the review!

  • P1 (append-file.ts:48 — after_line: -1 prepend bug): Confirmed, this is a real bug. The -1 shortcut should insert before the last line, not after. Will fix in a follow-up PR.
  • P2 (gh-pr-review.ts:55 — bodyless review filtering): Valid observation — filtering out bodyless reviews loses formal review decisions (APPROVED/CHANGES_REQUESTED). Will address in a follow-up PR.

Both fixes tracked as follow-up issues from this merged PR.

@cubic-dev-ai

cubic-dev-ai Bot commented Jun 14, 2026

Copy link
Copy Markdown

@cubic-dev-ai Thanks for the review!

  • P1 (append-file.ts:48 — after_line: -1 prepend bug): Confirmed, this is a real bug. The -1 shortcut should insert before the last line, not after. Will fix in a follow-up PR.
  • P2 (gh-pr-review.ts:55 — bodyless review filtering): Valid observation — filtering out bodyless reviews loses formal review decisions (APPROVED/CHANGES_REQUESTED). Will address in a follow-up PR.

...

@four-bytes-robby Sounds good, those both make sense as follow-up work.

On P1 (after_line: -1): your diagnosis is correct — the intent was "before the last line" but Math.max(0, lines.length - 2) and the insertPos logic together land in the wrong spot. A follow-up PR sounds right since this is edge-case behavior on a new tool.

On P2 (bodyless reviews): yep, a bare APPROVED with no body is exactly the kind of signal you'd want to return. Worth either including those reviews with an empty/missing body indicator, or separating review state reporting from inline comment display. Either approach works — the v1 filter was overly aggressive.

Nothing urgent here — both are minor and contained. Ship it.

Tip: get faster answers by chatting with cubic’s review copilot in the review UI

@four-bytes-robby

Copy link
Copy Markdown
Member Author

@cubic-dev-ai Both fixes now in PRs:

Both PRs ready for review. Thanks for the catch!

@cubic-dev-ai

cubic-dev-ai Bot commented Jun 14, 2026

Copy link
Copy Markdown

@cubic-dev-ai Both fixes now in PRs:

Both PRs ready for review. Thanks for the catch!

@four-bytes-robby I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 19 files

Re-trigger cubic

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.

feat: add append_file tool for simple file appending

1 participant