Skip to content

P0: share gap-risk detection with the preview path; user-entered AI feedback - #43

Merged
Ocean82 merged 1 commit into
mainfrom
p0-usefulness-first
Sep 27, 2026
Merged

Ocean82 merged 1 commit into
mainfrom
p0-usefulness-first

Conversation

@Ocean82

@Ocean82 Ocean82 commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

Completes the remaining P0 (Useful First) items from docs/strategy/2026-09-24-usefulness-first-strategy.md. P0.1, P0.2 and P0.4 already landed on main via #41; this covers the rest.

8 files, +175 / −120.

P0.3 — act-path safety

The range-gap detector ("SUM skips an adjacent numeric cell") moves out of columnOps.ts into src/lib/formulaGapRisk.ts, so the Apply/Reject preview path can share it rather than only the execute path. The preview now reports the risk as a warnings[] entry alongside the proposed changes, and Apply confirms those warnings through the existing confirmGaps override. columnOps.ts shrinks by ~110 lines as a side effect.

P0.5 — AI quality loop

Thumbs-down now opens an optional "what went wrong?" field. The rating is recorded immediately on click; submitting the note re-records it with the user's own words instead of the auto-derived fingerprint — which is what makes failover analysis actionable rather than aggregate-only. Cmd/Ctrl+Enter submits, Escape skips.

Parser question-veto

format_as_table joins DESTRUCTIVE_TOOLS, so "should I format this as a table?" no longer fires a bulk restyle. Targeted tools stay deliberately excluded — the polite-framing path treats "can you highlight X" as a real command, and there is a test pinning that.

Verification

Gate Result
npm run lint:ci pass
npm run typecheck pass
npm run test 1791 / 1791
npm run test --prefix server 344 / 344
npm run test:realengine 12 / 12

Follow-up

The P1 formatting sandbox is stacked on this branch — see #44. Merge this first.

🤖 Generated with Claude Code

Summary by Sourcery

Improve spreadsheet action safety and AI feedback quality by surfacing formula risks before application and capturing actionable user explanations for negative responses.

New Features:

  • Add inline, optional user explanations for negative AI response feedback, with immediate rating capture and keyboard shortcuts for submitting or skipping.
  • Expose formula range-gap risks in action previews so users can review them before applying changes.

Bug Fixes:

  • Prevent bulk table-formatting actions from being triggered by question-form requests.
  • Ensure formula applications continue to block suspected range gaps unless explicitly confirmed.

Enhancements:

  • Share formula gap-risk detection between preview and execution paths.
  • Update strategy tracking to mark the remaining usefulness-first and formatting milestones as complete.

Tests:

  • Update formula gap-risk coverage to exercise the shared detector.

…eedback

Completes the remaining P0 (Useful First) items. P0.1, P0.2 and P0.4 already
landed on main via #41; this covers the rest.

P0.3 — act-path safety
  The range-gap detector ("SUM skips an adjacent numeric cell") moves out of
  columnOps.ts into src/lib/formulaGapRisk.ts so the Apply/Reject *preview*
  path can share it, not just the execute path. The preview now surfaces the
  risk as a warning alongside the proposed changes, and Apply confirms those
  warnings via the existing confirmGaps override. columnOps.ts shrinks by
  ~110 lines as a result.

P0.5 — AI quality loop
  Thumbs-down now opens an optional "what went wrong?" field. The rating is
  recorded immediately on click; submitting the note re-records it with the
  user's own words instead of the auto-derived fingerprint, which is what
  makes failover analysis actionable. Cmd/Ctrl+Enter submits, Escape skips.

Parser question-veto
  format_as_table joins DESTRUCTIVE_TOOLS so "should I format this as a
  table?" no longer fires a bulk restyle. Targeted tools stay excluded — the
  polite-framing path deliberately treats "can you highlight X" as a command.

Verified: lint:ci, typecheck, 1791 unit tests, 344 server tests,
12 realengine golden-set tests.
Copilot AI lite review requested due to automatic review settings September 27, 2026 18:00
@sourcery-ai

sourcery-ai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR completes the remaining usefulness-first P0 work by making formula gap-risk detection available to both execution and preview paths, surfacing risks before Apply, collecting actionable user-entered thumbs-down feedback, and vetoing question-framed bulk table formatting.

Sequence diagram for formula gap-risk preview and apply

sequenceDiagram
    participant User
    participant Preview as buildActionPreview
    participant Risk as detectFormulaRangeGapRisk
    participant Apply as handleApplyFormula
    participant Sheet

    User->>Preview: Preview apply_formula
    Preview->>Risk: detectFormulaRangeGapRisk
    Risk->>Sheet: Inspect adjacent numeric cells
    Sheet-->>Risk: Gap risk or null
    Risk-->>Preview: warnings[] when risk exists
    Preview-->>User: Proposed changes and warnings
    User->>Apply: Apply with confirmGaps
    Apply->>Risk: detectFormulaRangeGapRisk
    Risk-->>Apply: Gap risk or null
    Apply->>Sheet: Write formula when confirmed
Loading

Sequence diagram for user-entered thumbs-down feedback

sequenceDiagram
    actor User
    participant Toolbar as MessageToolbar
    participant Panel as ChatPanel
    participant Feedback as recordChatFeedback

    User->>Toolbar: Click thumbs-down
    Toolbar->>Panel: onFeedback(messageId, down)
    Panel->>Feedback: recordChatFeedback with fingerprint
    Toolbar-->>User: Show optional detail field
    User->>Toolbar: Enter explanation
    User->>Toolbar: Send feedback or Cmd/Ctrl+Enter
    Toolbar->>Panel: onFeedback(messageId, down, userDetail)
    Panel->>Feedback: recordChatFeedback with user words
    Feedback-->>Panel: Deduplicate by messageId
Loading

Flow diagram for question-vetoed table formatting

flowchart TD
    A[User asks whether to format as a table] --> B{Parser resolves format_as_table}
    B --> C{Question phrasing detected}
    C -->|Yes| D[Veto destructive tool parse]
    D --> E[Hand request to LLM]
    C -->|No| F[Continue normal command handling]
Loading

File-Level Changes

Change Details Files
Shared formula range-gap detection across execution and preview flows, with warnings carried into the Apply/Reject UI and confirmed through the existing override.
  • Extracted aggregate range-gap detection into a reusable library module.
  • Reused detection during formula execution while preserving confirmGaps/force bypass behavior.
  • Added preview warnings for risky apply_formula actions and extended the action preview type.
src/lib/formulaGapRisk.ts
src/agent/toolHandlers/columnOps.ts
src/agent/toolHandlers/columnOps.test.ts
src/lib/previewBuilders.ts
src/types/api.ts
Added an actionable thumbs-down feedback loop that captures optional user explanations while preserving immediate rating submission.
  • Opened an inline explanation field on thumbs-down with a 200-character limit.
  • Supported Cmd/Ctrl+Enter to submit and Escape or Skip to dismiss.
  • Re-recorded feedback using trimmed user text instead of the automatic message fingerprint.
src/components/ChatPanel.tsx
Prevented question-framed bulk table formatting requests from being executed directly by the parser.
  • Added format_as_table to the destructive/question-veto tool set.
  • Documented and preserved the distinction between bulk formatting and targeted formatting commands.
src/agent/parser.ts
Updated strategy documentation to reflect completion of the AI feedback milestone and previously completed P1 implementation items.
  • Described thumbs-down comments as inline user-entered detail.
  • Marked formatting, layout, and parser phrase work as complete.
docs/strategy/2026-09-24-usefulness-first-strategy.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a4b89cf9-fdd1-4efb-a90f-14af9d910c82


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

@sourcery-ai sourcery-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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. If the shared gap detector is wrong, it could either block valid formula applications or allow a formula with an omitted adjacent value to be written into the sheet. A bad formula persists in stored workbook data, but it is bounded and can be corrected or recomputed; reverting the change does not automatically repair formulas already written.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@Ocean82
Ocean82 merged commit 67dfe4a into main Sep 27, 2026
5 checks passed
@Ocean82
Ocean82 deleted the p0-usefulness-first branch September 27, 2026 18:24
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.

2 participants