Skip to content

Infer DS labels from code + argument display names (arg-N) - #128

Open
mkayander wants to merge 18 commits into
mainfrom
cursor/infer-ds-variable-labels-3270
Open

Infer DS labels from code + argument display names (arg-N)#128
mkayander wants to merge 18 commits into
mainfrom
cursor/infer-ds-variable-labels-3270

Conversation

@mkayander

@mkayander mkayander commented Apr 14, 2026

Copy link
Copy Markdown
Owner

Summary

Infers data-structure display labels from user code (JS + Python) and adds user-facing argument display names with rename UI.

Runtime structure labels

  • JS AST rewrites [] / new Array() to tracked helpers with optional displayLabel
  • Python TrackedList passes displayLabel in addArray frames
  • Redux stores displayLabel; array/map/matrix views show StructureDisplayLabel

Argument display names

  • Priority: custom arg.label → solution parameter name → arg-{order+1}
  • Rename popover with 300ms debounce
  • New projects use uuid argument ids

Solution parameter inference (JS + Python)

  • JS: Babel parse of return function solve(a, b) { … }
  • Python: regex on def solve / def run, strips annotations/defaults
  • Live editor sync via editorCodeSlice; falls back to saved solution (mobile)

Production fixes included

  • Always apply array literal transform when parse succeeds
  • new Array() / ArrayProxy hardening (addStrings crash)
  • Skip destructuring RHS literals (phantom matrix from swap)

CI fix (latest)

  • Extract getMatrixChildArrayArgs out of useArgumentsParsing so the worker bundle no longer pulls tRPC/Next.js via useSolutionParameterNames

Test plan

  • 431 Vitest + 27 Python tests pass locally
  • codeExec.worker.spec.ts esbuild bundle succeeds
  • Manual: Add Strings — num1/num2 on args, nums on runtime array after const nums = new Array()
  • Manual: swap [num1, num2] = [num2, num1] — no phantom matrix
Open in Web Open in Cursor 

@vercel

vercel Bot commented Apr 14, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
dstruct Ready Ready Preview Aug 3, 2026 8:52am

@cursor
cursor Bot force-pushed the cursor/infer-ds-variable-labels-3270 branch from 54babea to 7956594 Compare April 23, 2026 19:22
@mkayander
mkayander marked this pull request as ready for review April 23, 2026 19:32
@cursor cursor Bot changed the title Infer data structure display labels from variable names (JS/Python) Infer DS labels from code + argument display names (arg-N) Apr 23, 2026
@cursor
cursor Bot force-pushed the cursor/infer-ds-variable-labels-3270 branch from 7956594 to 55d0d43 Compare April 23, 2026 19:53
@cursor
cursor Bot force-pushed the cursor/infer-ds-variable-labels-3270 branch from 55d0d43 to 5bcccdd Compare April 23, 2026 22:02
@cursor
cursor Bot force-pushed the cursor/infer-ds-variable-labels-3270 branch from 5bcccdd to cf6dc58 Compare May 20, 2026 20:26
@cursor
cursor Bot force-pushed the cursor/infer-ds-variable-labels-3270 branch from 7f11e9f to b9e3d56 Compare July 4, 2026 16:14
@cursor
cursor Bot force-pushed the cursor/infer-ds-variable-labels-3270 branch from 757725c to a92c658 Compare August 1, 2026 18:56
cursoragent and others added 10 commits August 1, 2026 21:20
- JS: extend array literal transform to call __dstructArrayLiteralWithName
  for const/assign/assignment-pattern RHS; keep unnamed helper for
  single-string literals and return-position literals
- Runtime: build labeled literals via ControlledArray with displayLabel in addArray options
- Redux: store displayLabel on ArrayData; show caption in array/map/matrix views
- Python: attach AST parents and infer list names from assign/ann/aug assign;
  pass displayLabel in TrackedList addArray options; seed case arg labels from arg name

Co-authored-by: Max Kayander <mkayander@users.noreply.github.com>
- Add optional ArgumentObject.label (non-unique); getArgumentDisplayLabel falls back to arg-{order+1}
- caseSlice.updateArgumentLabel + include label in args content signature
- ArgInput: composite field labels; suffix rename opens Popover with debounced 300ms save + flush on close
- JsonInput: suffixSlot + timeout passthrough; string/json inputs use 300ms debounce
- New projects/cases: short-uuid argument ids instead of head/array keys; addCase binary tree uses uuid
- useArgumentsParsing: structure displayLabel uses display name, not store id
- i18n: rename tooltip strings (en + generated types)

Co-authored-by: Max Kayander <mkayander@users.noreply.github.com>
- Extend array literal transform: append { displayLabel } to new Array/ArrayProxy
  when RHS is inferable; skip ambiguous new Array(singleNumber) length form
- Require array literal parent to be actual RHS (init/right) for named literals
- ArrayProxy constructor accepts optional trailing options object for displayLabel

Co-authored-by: Max Kayander <mkayander@users.noreply.github.com>
Plain array literals do not use ArrayProxy, so DS labels and addArray frames
only appear after the AST transform. Apply array literal rewriting whenever
parse succeeds, not only when line probes are injected; fall back to
transforming all functions if the return-function template is missing.

Also recognize ??=/||=/&&= bindings for named literals, inherit displayLabel
through Array.map, and always run transformed code in the worker.
- Share buildTrackedArrayFromLiteralElements for named/unnamed literals
- Collapse program-wide function traversal into one Babel visitor
- Keep runtime display label helper module-private
- Align Python ListOptions TypedDict with displayLabel field

Co-authored-by: Max Kayander <mkayander@users.noreply.github.com>
- Runtime tests: literal helper, map inheritance, plain [] gap, getLevels path
- Redux: arraySlice.create and caseSlice.updateArgumentLabel
- Args: getArgumentDisplayLabel fallbacks and duplicate labels
- AST: transformArrayLiteralsInProgram fallback
- Python: inline list literal emits displayLabel in addArray frame
- Remove duplicate getLevels file and instrument tests that only checked ok:true

Co-authored-by: Max Kayander <mkayander@users.noreply.github.com>
Co-authored-by: Max Kayander <mkayander@users.noreply.github.com>
Transform const nums = new Array() to __dstructArrayLiteralWithName instead
of new Array({ displayLabel }), which ArrayProxy rejected as a sole argument.

Also strip displayLabel-only options when it is the only constructor arg so
legacy transformed code (e.g. addStrings) keeps working.
Route element-style new Array(...) to __dstructArrayLiteralWithName instead
of appending displayLabel (avoids constructor edge cases). Keep displayLabel
append only for dynamic length forms like new Array(n).

Validate all ArrayProxy constructor elements, not just the first.
Tuple literals on the RHS of destructuring (e.g. [a, b] = [b, a]) must
stay plain arrays. Tracking them links tracked argument structures as
nested children and renders a phantom matrix in the viewer.
Parse JS return-function and Python def signatures to map case arguments
to parameter names (num1, num2) by position. Sync editor code to Redux
so labels update as the user edits. Explicit arg.label still wins.
- Prefer def solve/run entry points; strip type annotations and defaults
- Fall back to saved solution code when editor slice is empty (mobile results)
- Add tests for def run, annotations, and language dispatch
Extract getMatrixChildArrayArgs into entities/argument/lib so
createRuntimeMatrix no longer imports useArgumentsParsing (which pulls
tRPC/Next.js via useSolutionParameterNames). Import stringifySolutionResult
from its module path in the worker.
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