Repository navigation
feat(studio): add the @/ alias and port the prototype's foundation primitives and utilities - #2225
Conversation
…tives Resolve `@/` to `apps/web/src` in tsconfig.json (inherited by tsconfig.browser.json) and in vite.config.ts, which also drives Vitest, so prototype files drop in without rewriting their imports. Existing relative imports are left as they are. Port scroll-area, separator, chevron-indicator, and error-boundary from the prototype verbatim apart from Biome formatting, each with a happy-dom test. Add @radix-ui/react-scroll-area 1.3.0 and @radix-ui/react-separator 1.1.16, exact-pinned; both resolve onto the Radix internals already in the lockfile. Refs #2204 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Port use-is-truncated, clipboard, line-diff, error-message, and formatters from the prototype into apps/web/src/hooks and apps/web/src/lib, with tests, and move the existing call sites onto them: - clipboard: every ad-hoc navigator.clipboard call. Session ID, selection, and thread copies now go through copyToClipboard, so they confirm with a toast and report a missing or blocked clipboard instead of failing silently. The support-summary copy keeps its inline status line through writeClipboardText. - line-diff: replaces the LCS copy inlined in chat/edit-diff.tsx; knowledge/skill-diff.tsx now diffs through it directly instead of reaching into the chat feature. - error-message: replaces the seven identical errorMessage copies (chat-state, knowledge/format, learning-review, memory-consolidation, memory-settings, schedules-workspace, schedule-detail). Storage settings and the schedule form keep their own reader because their fallback sentences differ. - formatters: replaces the six formatDate copies, moves describeCron and ordinal out of cron-builder.ts, and backs turn-stats' formatDurationMs and formatTokens. The prototype's duplicate errorMessage is left out in favour of lib/error-message. use-is-truncated has no consumer yet; it backs tooltip onlyWhenTruncated in the next slice. use-confirm, use-prompt, use-beforeunload-guard, document-title, file-meta, and useIsCompact are deferred to the feature ports that need them. Refs #2204 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Rebasing onto #2222 brought the new features/memory pages, which still imported errorMessage from knowledge/format and kept an identical local copy in memory-fact-detail. Both now use lib/error-message. facts-about-you keeps its own reader because its fallback sentence differs. Also restore the two describeCron expectations that did not move into lib/formatters.test.ts, and word the clipboard-unavailable toast for any copied text rather than only an ID. Refs #2204 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
b668f24 to
720ea8d
Compare
…hange Two global-search tests switch the signed-in account and then click the Search trigger. React Query notifies subscribers of the new account on a timer that act() does not flush, so under load the test sometimes queried the trigger before the palette re-keyed to the new account. It clicked the old account's trigger, which correctly does nothing because its scope no longer matches, and the inventory request the test waits for never came. "checks fresh identity before reopening cached private results" failed about 1 run in 3 on a loaded machine, on origin/main too. The tests now wait for the new trigger before clicking. No timeout changes; the behaviour under test is unchanged. 15/15 runs pass. Refs #2204 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
kantord
left a comment
There was a problem hiding this comment.
unless there is a blocker, lets take the approach of merge-and-address-in-later-step, otherwise the churn will be a lot
so I will start looking at them and sending agents at them, and just noting all issues that I think need discussion or addressing, but aren't blockers/regressions
first one is, I don't think we should write and bundle our own line diff algo in this product, if there are any reasonable way to avoid it: https://github.com/stacklok/mecatl/pull/2225/changes#diff-ccbb159cd46134e20e9bff8579a59293abfe3f2df046686dfcc5d02260155685 I would replace it with a dependency in FE, or push it to BE somehow
this is doubly true of describeCron, we already found a dependency for thsi, and I believe that an unmerged pr already adds it
and in general, for all of these things I think we should evaluate whether they can be first copied over from SEP. Plus we can talk about it on the sync meeting but I think we cannot copy-paste these things anymore, we just need to publish these in a public repo right now
#2225 moved describeCron out of cron-builder into lib/formatters, so the schedule detail and inventory imports no longer resolved. Import both helpers from the shared module and drop the duplicate local formatDate. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
#2225 moved describeCron out of cron-builder into lib/formatters, so the schedule detail and inventory imports no longer resolved. Import both helpers from the shared module and drop the duplicate local formatDate. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
Post-merge review follow-ups for this PR. No blockers or regressions found. Items worth tracking were filed here:
Other candidate findings were checked and dropped as not worth tracking. Fully or partially written by an AI agent. |
Summary
This is the first slice of the Studio alignment foundation (#2204, part of #2210). It adds the prototype's
@/import alias and ports the four primitives that #2211 didn't cover. It also ports the shared hooks and lib modules that Studio already has duplicated code for, and moves the existing call sites onto them. After this, a feature port from the prototype only needs formatting changes, not import rewrites.What changed
@/import aliasapps/web/tsconfig.jsonmaps@/*to./src/*.tsconfig.browser.jsoninherits the mapping.apps/web/vite.config.tsresolves@tosrc/. Vite and Vitest share this config.@/, so typecheck, the Vite build, Vitest, and Playwright all resolve the alias.Primitives ported from the prototype
Each one is verbatim apart from Biome formatting, and each has a happy-dom test:
scroll-areaseparatorchevron-indicatorerror-boundaryDependencies, exact-pinned:
@radix-ui/react-scroll-area1.3.0@radix-ui/react-separator1.1.16Both come from the same release wave as
@radix-ui/react-popover1.2.0. They resolve onto Radix internals already in the lockfile, so the lockfile only gains these two packages.Hooks and lib modules ported from the prototype, with their call sites migrated
hooks/use-is-truncatedonlyWhenTruncatedin PR b.lib/clipboardnavigator.clipboard.writeTextcalls in chat and settings.lib/line-diffchat/edit-diff.tsx.knowledge/skill-diff.tsxnow diffs throughlib/line-diffdirectly instead of importing from the chat feature.lib/error-messageerrorMessagecopies in chat-state, knowledge/format, learning-review, schedules-workspace, schedule-detail, and memory-fact-detail, plus the import in consolidate-memory-card.lib/formattersformatDatecopies,describeCron/ordinalfromcron-builder.ts, and turn-stats'formatDurationMs/formatTokens. turn-stats keeps a string-to-number bridge, as the prototype does.Storage settings and the schedule form keep their own
errorMessage, because their fallback sentences differ.Differences from the prototype
lib/error-message.ts: the doc comment describes Studio's consolidation instead of the prototype's file paths.lib/formatters.ts: the duplicateerrorMessageis dropped (Studio has a single reader inlib/error-message), and theformatDatecomment no longer names prototype files.lib/clipboard.test.ts: Studio's no-isolate rules forbidvi.mock, so the test stubstoast.success/toast.errorwithvi.spyOnand swaps in a fake Clipboard API withvi.stubGlobal("navigator", …).Visible change
The Copy session ID button (inspection dialog and header menu), the
chat.copyIdshortcut, the selection Copy button, and the side-thread copy now show a toast: "Session ID copied", "Selection copied", or "Thread copied". If the clipboard is missing or blocked, the toast says so. Before, these copies failed silently, as an unhandled promise rejection in some cases. This is the prototype's copy policy.The support-summary copy in Settings still reports through its inline status line and does not toast.
Deferred
card(CardAction,data-slot,@containerheader),table(sortable head, nested rows withChevronIndicator, retiringsortable-head.tsx), andtooltip(onlyWhenTruncated) API changes. Also theinputstates and thestyles.csscherry-picks (badgealready landed in fix(studio): make Badge identical to the prototype #2212).use-confirmanduse-prompt: the only candidate is chat-workspace's inline confirm/prompt state, which is coupled to shortcut suppression and to Studio-specific labels.use-beforeunload-guard: Studio has nobeforeunloadhandler.document-title: Studio never assignsdocument.title.file-meta: Studio has no file-kind classification.useIsCompact: Studio has no consumer for the compact breakpoint.lib/use-mobile.tsstays where it is.Test evidence
task studio:check(current head, after the rebase): passed. Biome checked 408 files; typecheck clean; server 24 files / 187 tests; web 123 files / 769 tests; generated-artifact check clean.task studio:browser: 54 passed (desktop and mobile Chromium). The chat-approval journey needsbin/mecated, sotask buildran first.use-is-truncated,clipboard,line-diff,error-message, andformatters. There is also a regression test forskill-diffabove the line-diff bound, and asession-inspectiontest showing that Copy session ID writes the ID and toasts.No regression
This compares the original PR head (
b668f24fa) with its merge-base (a4771a787). The "After the rebase onto #2222" section at the end covers the current head. The merge-base was checked out as a throwaway worktree with the samebin/mecated. I found no behaviour difference other than the intended copy toasts.Equivalence of the consolidated helpers
A throwaway Vitest harness ran each old implementation from the merge-base against its replacement on the same inputs. It compared return values and thrown errors, and recorded every mismatch. It ran 19 times: UTC/en-US, plus Los Angeles, St John's, Rome, Kolkata, Chatham and Lord Howe, each in en-US, de-DE and ja-JP. A seeded mutant (one changed output each in
errorMessage,ordinalandskillDiffRows) produced 17 mismatches, so the harness does catch differences.errorMessage(chat-state, knowledge/format, learning-review, memory-consolidation, memory-settings, schedules-workspace, schedule-detail) →lib/error-messageundefined,null, strings, numbers,NaN, bigint, symbol,Errorand its subclasses,Errorwithdetail,DOMExceptionabort,detailof every type ("",null,undefined, number, object, array), a getter, a null-prototype object, a function,Map,PromiseformatDate→lib/formattersz, non-ISO,"", invalid (both throw the sameRangeError), 200 random instantsdescribeCron(cron-builder) →lib/formatterscron-builder.test.ts, plus a 12×11×15×3×9 grid of field values (steps, ranges, lists, out-of-range,MON, leading zeros), whitespace and tab variants,@daily,""ordinal→lib/formattersNaN,Infinity,-0, fractions, 1e21formatTokens(string)(old inline) → the bridge tolib-5,""," 12 ","0x10","1.5","abc"(sameSyntaxError), 500 random valuesformatDurationMs→lib/formatters-0, 0.4/0.5/999.5 rounding,NaN, ±Infinity,MAX_VALUE,MIN_VALUE, 500 random valuesformatTurnStatandusageMenuLines(old vs new module)computeLineDiff(old vs new edit-diff), rawlib/line-diffops vs the old ops,editSizeNote""/"", one side empty, trailing newlines, CRLF, unicode, swapped-/+bullets, 1,500 random edits with heavy ties, 20 pairs of about 1,000 lines, the bound itself (1,000+1,000 aligns, 1,000+1,001 coarse), 2,001-line one-sided, 5,000 vs 4,999skillDiffRowsandhasSkillDiffChanges(old knowledge/skill-diff throughcomputeLineDiff, new throughlib/line-diffand its own coarse fallback){}, body only), above-bound bodies (large-diff fallback), and non-daemon unified diffsTotal: 68,896 comparisons per run × 19 runs, with 0 mismatches.
Test delta (merge-base → HEAD)
chat/chat-state.test.tslib/error-message.test.tstests the same three branches (detail,Error#message, fallback string). The literals differ, and the new tests add a numericdetailandundefined. Not weakened.chat/turn-stats.test.tsformatDurationMs: 480 →480ms, 4100 →4.1s, 4000 →4s)lib/formatters.test.ts: 840 →840ms, 4100 →4.1s, 2000 →2s, 61500 →61.5s, plus a clamp test (−5,NaN). Same cases with different literals, plus more.formatTokens(string)tests stay in turn-stats.schedules/cron-builder.test.tsordinal×9;describeCronshapes ×8; fallback ×2)ordinal: identical 9 expects. Fallback: both literals kept, and 4 more added. Shapes: 6 of 8 kept verbatim. Not carried over:"59 23 28 * *"→"Monthly on the 28th at 11:59 PM"and"*/15 * * * *"→"Every 15 minutes". They are replaced by analogous cases (5 7 22,0 9 13,0 12 1,*/5), and the harness above shows identical output for both. Both literal expectations were restored inlib/formatters.test.tsin720ea8d5b.chat/edit-diff.test.tsLINE_DIFF_MAX_LINESmoved tolib/line-diffchat/session-inspection.test.tsxknowledge/skill-diff.test.tsLINE_DIFF_MAX_LINES).use-is-truncated,clipboard,error-message,formatters,line-diff)Net change in web tests: −5 + 2 + 48 = +45.
Gates, before and after
task studio:check: Biometask studio:check: typecheck, generated-checktask studio:check: server Vitesttask studio:check: web Vitesttask studio:browser(desktop + mobile Chromium)Both web runs print the same
Error: socket hang upline, so it predates this PR.Findings
describeCronexpectations that did not move were restored (720ea8d5b).720ea8d5b). It only appears when a copy fails.After the rebase onto #2222
#2222 (the memory restyle) deleted
knowledge/memory-consolidation.tsxandsettings/memory-settings.tsx. This PR used to migrate those two files. The rebase takes the deletions. The newfeatures/memory/pages now use the shared helpers:consolidate-memory-card.tsximportserrorMessagefromlib/error-message. It used to import it fromknowledge/format, which this PR emptied of helpers.memory-fact-detail.tsxhad a local copy identical tolib/error-message; that copy is removed.facts-about-you.tsxkeeps its own reader, because its fallback sentence ("Memory could not be loaded.") differs.Gates at the current head (
720ea8d5b, onorigin/mainaa1979c1d):task studio:checktask studio:browsersearch/global-search.test.tsx› "checks fresh identity before reopening cached private results" was flaky onorigin/maintoo, failing about 1 run in 3 on a loaded machine. The cause was a race in the test, not in the app. After an account change, React Query notifies subscribers on a timer thatact()does not flush, so the test sometimes clicked the previous account's Search trigger before the palette re-keyed. That click is correctly a no-op, because the scope no longer matches.db98c3768makes this test, and the sibling test with the same pattern, wait for the re-keyed trigger. No timeouts changed. 15/15 runs pass.Screenshots
Captured with a throwaway Playwright journey (Chromium, not committed) that reuses
e2e/fixtures.ts: offline BFF routes, a fixed clock (2026-09-25 12:30 UTC),Europe/Rome, en-US, and clipboard permissions. Each surface was shot at desktop 1280×800 and mobile 390×844, in light and dark. Before is the merge base withmain(aa1979c1d), after is this PR's head (db98c3768). Every pair was pixel-compared; red boxes mark the regions that differ. Desktop composites are downscaled to 1600px wide. The copy journeys also assert that the clipboard received the text, on both trees.Clipboard copies
Copy session ID (session details dialog)
Intended change: the "Session ID copied" toast appears (bottom right on desktop, bottom on mobile). The dialog is otherwise identical.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Side thread → Copy thread
Intended change: the "Thread copied" toast. Before, the copy succeeded without feedback. The thread is otherwise identical.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Selection → Copy
Intended change: the "Selection copied" toast. Everything else is identical.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Settings → About → Copy support summary
Identical: the inline "Support summary copied." line, and no toast, on both trees. (Desktop light differs by 10 px of card-corner anti-aliasing, at most 1/255 per channel.)
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Schedules (
formatDate,describeCron)Schedules list
Identical: "Next …" and "Once …" dates.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Schedule detail
Identical: the date facts and run history.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Create form, cron description
Identical: "every weekday at 9am" reads "Weekdays at 9:00 AM" on both trees. (On light, 7 to 28 px of a nav icon's anti-aliasing differ; the same pixels also differ between two runs of the merge-base tree.)
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Diffs (
lib/line-diff)Learned skill diff (v1 → v2)
Identical.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Chat Edit diff (approval card)
Identical.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Error state (
errorMessage)Scheduled, 503 problem+json
Identical: the problem
detailis shown on both trees.Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Turn stats (
formatTokens)Turn stats line
Identical:
↑12.3k ↓1.8k · 34% cached. (Mobile light: the transcript's scroll offset varies from run to run on both trees, so its before image comes from a second merge-base run with the same offset; 6 px of nav-icon anti-aliasing remain.)Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Chat ··· menu token usage
Identical. (Mobile light uses a second merge-base run for the same scroll-offset reason.)
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Settings → Memory (
errorMessagein the consolidate card)Memory stores and Facts about you
Identical.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Consolidate memory card
Identical.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Consolidate memory, generated suggestion
Identical. (Desktop light differs by 8 px of card-corner anti-aliasing, at most 1/255 per channel.)
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Consolidate memory, error state
Identical: the 503 problem
detail("The memory store is busy. Try again in a minute.") is shown on both trees. (Desktop dark differs by 21 px of card-corner anti-aliasing, at most 1/255 per channel.)Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Memory fact detail (
errorMessage)Fact detail
Identical.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Fact detail, "Value unavailable" state
Identical: "Value unavailable: The memory store is offline." on both trees.
Dark and mobile
Desktop, dark:
Mobile, light:
Mobile, dark:
Re-verification (2026-10-11)
Re-verified at this head: no change needed.
Refs #2204
🤖 Generated with Claude Code