Skip to content

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

Open
mkayander wants to merge 9 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 9 commits into
mainfrom
cursor/infer-ds-variable-labels-3270

Conversation

@mkayander

@mkayander mkayander commented Apr 14, 2026

Copy link
Copy Markdown
Owner

Summary

Infers display labels for runtime-built arrays/maps (from variable names in user code) and for test-case arguments (optional rename + arg-N defaults). Fixes the getLevels / const array = [] case where plain literals were invisible to the visualizer.

Problem

[] creates a plain JS array even when Array is aliased to ArrayProxy. Without the AST transform there are no addArray frames and no captions.

Solution

Layer Behavior
JS AST []__dstructArrayLiteralWithName("array") when bound; unnamed otherwise. new Array(1,2,3) gets trailing { displayLabel }.
Worker Always runs transformed code when parse succeeds (array rewrite is independent of line probes).
Fallback If no return function … template, still rewrite literals in all functions.
Runtime displayLabel on addArray options → Redux → StructureDisplayLabel above array/matrix/map views.
Args Optional label on arguments; UI popover with debounced save; uuid store keys for new projects.
Python attach_ast_parents + inferred list literal names → displayLabel in addArray frames.

Regression coverage

  • getLevelsArrayTracking.test.ts — instrumented binary-tree solution emits addArray with displayLabel: "array".
  • Transform / instrumentation unit tests for ??=, new Array, fallback template.

Review notes (post-rebase on main)

  • Rebased cleanly; resolved exec.py import conflict (collection tracker + attach_ast_parents).
  • DRY pass: shared buildTrackedArrayFromLiteralElements, collapsed program traversal visitor, private runtime label helper.
  • Known limits (YAGNI): nested array[depth] ??= [] rows stay unnamed; Array.from / push-built arrays not instrumented; Python dict/set literals still use legacy name option in collection tracker.
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, Comment Jul 4, 2026 4:19pm

@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
cursoragent and others added 8 commits July 4, 2026 16:10
- 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>
@cursor cursor Bot force-pushed the cursor/infer-ds-variable-labels-3270 branch from 7f11e9f to b9e3d56 Compare July 4, 2026 16:14
- 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>
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