Skip to content

refactor: eliminate duplicated logic in inspect, data-inspector, and simple-schema - #331

Closed
antfubot wants to merge 1 commit into
mainfrom
little-baths-obey
Closed

refactor: eliminate duplicated logic in inspect, data-inspector, and simple-schema#331
antfubot wants to merge 1 commit into
mainfrom
little-baths-obey

Conversation

@antfubot

@antfubot antfubot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

What

Removes copy-pasted logic surfaced by jscpd across a few source files, extracting a named helper at each seam. Net −72 lines, no behaviour change.

  • inspect RPC functions — the identical timing + error-envelope block (Date.now() / try / normalize thrown error into InvokeResult) was duplicated across execute-command, invoke, invoke-agent-tool, and read-agent-resource. Extracted toInvokeResult(run) into _invoke-result.ts; all four delegate to it.
  • data-inspector query-enginerunQuery and runQueryAtPath were identical except for a navigate step. Extracted a private executeQuery(target, query, options, select) with a node-selector callback; both are now one-line wrappers.
  • devframe simple-schemarecord, array, and object each repeated the "run schema, prefix issue paths" loop. Extracted pushFieldIssues(issues, key, schema, value).
  • AgentSmart.vueonInvoke/onRead differed only in the RPC call. Extracted runAction(id, call) holding the guard/pending/try-catch-finally.

Deliberately left as-is

  • normalize.ts ~ skeleton.ts — two parallel-but-distinct traversals (different recursion arity, getter-error shapes, truncation markers); a shared helper would obscure each self-contained walker for a marginal gain.
  • CommandsView.vue ~ FunctionsView.vue — only toolbar/empty-state/list markup overlaps; types, row components, and domain logic differ.
  • Cross-plugin rpc.ts/main.ts composables — AGENTS.md wants these ported per-plugin to keep plugins independent.

Verification

  • Targeted tests pass: inspect (23), data-inspector (79), simple-schema (7), no type errors.
  • eslint clean on all changed files.
  • Re-ran jscpd: the four targeted clones are gone.

This PR was created with the help of an agent.

…simple-schema

Extract shared helpers for copy-pasted logic surfaced by jscpd:
- inspect RPC functions share one toInvokeResult() envelope helper
- data-inspector runQuery/runQueryAtPath share executeQuery()
- simple-schema record/array/object share pushFieldIssues()
- AgentSmart onInvoke/onRead share runAction()
@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 2, 2026

Copy link
Copy Markdown

◈ PR Lens

🟢 +0 new · 🟠 ~3 changed · 🔴 -0 removed · 1 flow · 8 files · commit 558e28c


Architecture

Architecture diagram for devframes/devframe at 558e28c

3 components touched across 2 lanes.

Open full size


Data flow

Data flow diagram for devframes/devframe at 558e28c

Executing Inspect action with normalized result envelope

Open full size


Drill down
Devframe Core Engine — 1 component
🟡 CHANGED Simple Schema validator

Lightweight Standard Schema validation utilities for objects, arrays, and records.

Built-in Devframes — 2 components
🟡 CHANGED Inspect Devframe

Devframe inspection plugin providing RPC introspection, command execution, agent inspection, and UI views.

🟡 CHANGED Data Inspector Devframe

Plugin for live Jora query evaluation, AST navigation, and payload size tracking.


View

  • Architecture lens
  • Data flow lens
  • Expand every detail
  • Show unchanged neighbours

Tip

Push a new commit and the whole comment re-renders for the new head. An older run never overwrites a newer one, so a slow render cannot put a stale diagram back.

🪧 More tips
  • Run PR Lens on your own machine: npx skills add coldteadotai/pr-lens installs the agent skill. Then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Draw a diff before it is even a pull request: npx @coldtea/pr-lens-cli analyze --base origin/main reads the diff with your own model key, and npx @coldtea/pr-lens-cli render .pr-lens/graph.json draws the same lenses on your machine.
  • The boxes under View are live. Tick Architecture lens or Data flow lens to choose which diagrams appear, or Expand every detail to open every drill-down at once. The comment redraws in place a few seconds later.
  • Show unchanged neighbours lists the components this change did not touch alongside the ones it did, so the drill-down shows what the changed code sits next to.
  • GitHub will not let you zoom an image in a comment. The link under each diagram opens it full size on a page of its own, where you can.
  • The CLI's render picks up .github/pr-lens.yml automatically and applies your corrections (renames, exclusions, lane pins) at draw time.
  • Would you rather run it from CI on a key of your own? Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and a model key in your repository secrets, say GEMINI_API_KEY. The Action asks Gemini by default, or OpenAI and any endpoint speaking /chat/completions through its provider input.
  • PR Lens is free for open source. A star on the repository is what keeps it going.
  • The diagrams follow your GitHub theme, so dark mode gets the dark render and light mode the light one, and the moving dots show this pull request's data in motion.

◈ Rendered by PR Lens · crafted with ❤️ by the Coldtea team · Something drawn wrong?

@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
devframe Skipped Skipped Sep 2, 2026 4:46am UTC

@antfu antfu closed this Sep 2, 2026
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