Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,64 @@ All notable changes to this project are documented here. Format: [Keep a Changel

### Added

- **Two indicator views, one button** (31 Oct). The operator picked both mock-ups and kept both, with Quick as the
default.
- **Quick** (`picker.js`) is a dropdown under the Indicators button:
- type straight away, and search covers LuxAlgo scripts and built-ins together; initials count, so "rsi" finds
Relative Strength Index first;
- categories on the left, yours first (Recent, Favourites, On chart), then the library's families, then the
built-ins;
- results in the middle, and a preview with the picture and the write-up's first lines on the right;
- keyboard: ↑ ↓ move, ↵ runs, → opens Details, Esc closes;
- in a narrow Hermes pane the categories become chips and the preview stays, as a strip above the list.
- **Panel** (`drawer.js`) is the slide-in panel, reorganised:
- "On chart" first, then "Recently used", then all scripts;
- two-line names, family as a coloured tag, a ☆ that shows only when it means something;
- search matches highlighted, and the same keys as Quick.
- **The switch.** Each view has a Quick | Panel switch, and the choice is remembered per browser. The narrow
pane's Scripts button follows it too.
- **Wording.** A LuxAlgo script says **Run**: one at a time, it replaces the last one. A built-in says **Add**:
it stacks.
- **Shared logic.** The dropdown owns no data and no actions: it reads the drawer's rows and acts through the
drawer, so a run is the same run from either view, and the agent's `indicators` door still drives the panel.
- **Every built-in has a real preview.** Vela ships no picture for its 77 built-ins, so each preview is the study
itself: its own descriptor's `compute()` with default settings, on the open chart's last bars. Overlays (moving
averages, Bollinger Bands, SuperTrend, ZigZag…) are drawn over the candles; oscillators (RSI, MACD, Stochastic,
Aroon…) get a pane under them; Volume and the volume profile come from the candles. The previews show in
Quick's preview pane and as each built-in's tile in the Panel. Nothing is fetched. LuxAlgo scripts keep the
picture from LuxAlgo's catalogue.
- **The preview is the focus, and says what the study is for.** The dropdown is larger (up to 880 × 540), the
preview column is 300–360 px wide and its picture 236 px tall. Under the name, one plain sentence under
"What it's for": each of the 77 built-ins has its own (`PURPOSE` in `picker.js`, e.g. RSI "Measures momentum
on a 0–100 scale; above 70 is often read as overbought and below 30 as oversold."), and a LuxAlgo script
shows the first sentence of its own write-up. The same lines feed search in both views, so "overbought" finds
RSI, Stochastic, Williams %R and Money Flow Index.
- Pinned by `test_indicator_views.py`. Verified in Chromium at 1280 and 620 px, dark and light: open, search,
keyboard run, Recent and On chart filling in, a built-in added, Esc and click-away, and the switch both ways
surviving a reload.

### Fixed

- **The scripts list behind Indicators** (31 Oct). Six faults from a screenshot review:
- **A row whose preview picture failed collapsed.** The `<img>` was deleted, the row's grid shifted one
column left, and the name landed in the 52 px picture slot ("Indic…"). That is every row without a
catalogue picture, and every row offline. The picture is now swapped for a tile with the name's
first letter, and each part of a row owns its grid column.
- **Built-in rows** had the ƒ in the corner of its tile, and their Run button sat 12 px left of every
other Run. Both are aligned now.
- **The detail view said only "Failed / No live MCP session".** It now says the LuxAlgo Library isn't
connected, what that means, and offers Try again. The server's message stays, smaller.
- **The search box always said "Search 800 scripts".** The number is gone.
- **The family chips were cut at the edge** with no sign there were more. A fade marks the side that
scrolls, and the mouse wheel scrolls them.
- **The footer's theme switch** was a tiny dim ◐ that read as a broken glyph. It is now the sun/moon
icon the Edge Stats sheet uses, on a 28 px target.

Pinned by `test_lib_drawer_polish.py`. Verified in Chromium with a third of the previews failing: every
name gets the same width and every Run lines up, in dark and light.

### Added

- **`AGENTS.md`: give an agent the repo link and it installs the plugin** (30 Oct). A file written for AI agents
and signposted at the top of the README ("If you are an AI agent ..."). It covers:
- telling the user what will happen, before running anything;
Expand Down
188 changes: 188 additions & 0 deletions console/backend/tests/test_indicator_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
"""Two views of the indicators, one door (31 Oct).

The operator picked both mock-ups and kept both: the quick-add dropdown ("Quick", picker.js) is what
the Indicators button opens by default, and the slide-in panel ("Panel", drawer.js) is the other view.
Each carries a switch to the other, and the choice is remembered. Neither owns data or actions: the
dropdown reads the drawer's rows and acts through the drawer, so a run is the same run from either.
"""

import re
import unittest
from pathlib import Path

FRONT = Path(__file__).resolve().parents[2] / "frontend"
PICKER = (FRONT / "picker.js").read_text(encoding="utf-8")
DRAWER = (FRONT / "drawer.js").read_text(encoding="utf-8")
WS = (FRONT / "workspace.js").read_text(encoding="utf-8")
APP = (FRONT / "app.js").read_text(encoding="utf-8")
HTML = (FRONT / "index.html").read_text(encoding="utf-8")
CSS = (FRONT / "styles.css").read_text(encoding="utf-8")


class OneDoorTwoViews(unittest.TestCase):
def test_the_picker_loads_after_the_drawer(self):
self.assertLess(HTML.index('src="./drawer.js"'), HTML.index('src="./picker.js"'))

def test_the_indicators_button_opens_the_chosen_view(self):
self.assertIn("window.taIndicators.toggle()", WS)
self.assertIn("window.libDrawer.toggle()", WS, "without picker.js the panel is still the door")

def test_quick_is_the_default(self):
self.assertIn("read(VIEW_KEY, 'quick') === 'panel' ? 'panel' : 'quick'", PICKER)

def test_the_choice_is_remembered(self):
self.assertIn("const VIEW_KEY = 'ta-indicators-view'", PICKER)
self.assertIn("write(VIEW_KEY", PICKER)

def test_each_view_switches_to_the_other(self):
self.assertIn('data-view="panel"', PICKER)
self.assertIn("switchToPanel", PICKER)
self.assertIn('data-view="quick"', HTML)
self.assertIn("window.taIndicators.setView('quick')", DRAWER)

def test_the_narrow_panes_scripts_button_follows_the_choice_too(self):
block = DRAWER[DRAWER.index("if (fallback) fallback.addEventListener('click'"):][:300]
self.assertIn("window.taIndicators.toggle()", block)


class TheDropdownOwnsNothing(unittest.TestCase):
def test_rows_and_actions_come_from_the_drawer(self):
self.assertIn("window.libDrawer.items()", PICKER)
self.assertIn("window.libDrawer.act(", PICKER)
self.assertNotIn("api('/api/source'", PICKER, "a run must go through the drawer's one run path")
self.assertIn("items, act,", DRAWER)

def test_the_drawer_still_writes_no_storage(self):
# favourites have one store (app.js); recents and the view live in picker.js
self.assertNotIn("localStorage.setItem", DRAWER)


class WhatItShows(unittest.TestCase):
def test_yours_first(self):
for cat in ("'recent'", "'fav'", "'on'", "'all'", "'builtin'"):
self.assertIn(cat, PICKER)
self.assertIn("st.cat = recent().length ? 'recent' : 'all'", PICKER)

def test_a_run_is_remembered_for_recent(self):
self.assertIn("ti().noteRecent(slug)", DRAWER)
self.assertIn("noteRecent('builtin:' + nat.type)", DRAWER)

def test_the_panel_groups_on_chart_and_recent_first(self):
for label in ("'On chart · '", "'Recently used'", "'All scripts'"):
self.assertIn(label, DRAWER)

def test_initials_find_the_classic(self):
# "rsi" is Relative Strength Index before Connors RSI
self.assertIn("initials(x.name) === q.replace", PICKER)

def test_matches_are_highlighted_safely(self):
self.assertIn("'<mark>' + esc(", PICKER)

def test_luxalgo_scripts_say_run_and_built_ins_say_add(self):
# one LuxAlgo script at a time replaces the last; a built-in stacks — the words must not blur that
self.assertIn("ICON.run + 'Run'", PICKER)
self.assertIn("ICON.plus + 'Add'", PICKER)
self.assertIn("r.__native ? 'Add' : 'Run'", DRAWER)


class ItBehaves(unittest.TestCase):
def test_keyboard(self):
for key in ("'ArrowDown'", "'ArrowUp'", "'Enter'", "'ArrowRight'", "'Escape'"):
self.assertIn(key, PICKER)
for key in ("'ArrowDown'", "'ArrowUp'", "'ArrowRight'"):
self.assertIn(key, DRAWER)

def test_escape_reaches_it_from_anywhere(self):
self.assertIn("window.closePickerIfOpen", PICKER)
self.assertLess(APP.index("window.closePickerIfOpen()"), APP.index("window.closeDrawerIfOpen()"))

def test_it_is_a_listbox_for_screen_readers(self):
self.assertIn('role="listbox"', PICKER)
self.assertIn('role="option"', PICKER)
self.assertIn("aria-activedescendant", PICKER)

def test_the_global_search_style_does_not_draw_inside_it(self):
self.assertIn('.qp__search input[type="search"]:focus', CSS)

def test_motion_is_opacity_and_transform(self):
rule = re.search(r"\.qp \{([^}]*)\}", CSS).group(1)
self.assertIn("transition: opacity", rule)
self.assertNotRegex(rule, r"transition:[^;]*\b(width|height|top|left)\b")
self.assertIn(".qp { transition: none; }", CSS)

def test_a_narrow_pane_gets_chips_and_keeps_the_preview(self):
# 31 Oct, the operator: "make the preview pane larger a bit. That's the focus". The Hermes
# pane is narrow, so there the preview stays, as a strip above the list, instead of folding away.
self.assertIn("el.classList.toggle('is-narrow', narrow)", PICKER)
rule = re.search(r"\.qp\.is-narrow \.qp__prev \{([^}]*)\}", CSS).group(1)
self.assertIn("display: grid", rule)
self.assertNotRegex(CSS, r"\.qp\.is-narrow \.qp__prev[^{]*\{[^}]*display: none")


class EveryBuiltInHasARealPreview(unittest.TestCase):
"""31 Oct, the operator: "there must be preview of each indicator". Vela ships no picture for its
built-ins, so each preview is the study itself — its own descriptor's compute(), default inputs, on
the open chart's last bars. Nothing is fetched and nothing is drawn by hand."""

def test_the_preview_runs_the_studys_own_maths(self):
self.assertIn("v.getNativeIndicator(type)", PICKER)
self.assertIn("d.create().spec.compute(bars, d.defaultInputs ? d.defaultInputs() : {})", PICKER)
self.assertIn("window.chartBars()", PICKER)

def test_overlays_and_oscillators_are_drawn_differently(self):
self.assertIn("const sub = !r.overlay", PICKER)
for part in ("out.bands", "out.levels", "out.polylines", "'columns'"):
self.assertIn(part, PICKER)

def test_volume_and_the_profile_come_from_the_candles(self):
self.assertIn("r.type === 'vpvr'", PICKER)
self.assertIn("r.type === 'volume'", PICKER)

def test_both_views_draw_them(self):
self.assertIn('data-native-preview="${esc(x.slug)}"', PICKER)
self.assertIn('data-native-preview="${esc(r.slug)}"', DRAWER)
self.assertIn("ti().drawNativeTiles(list)", DRAWER)

def test_a_long_list_is_drawn_a_few_at_a_time(self):
self.assertIn("tiles.splice(0, 6)", PICKER)
self.assertIn("requestAnimationFrame(step)", PICKER)


class ThePreviewIsTheFocus(unittest.TestCase):
"""31 Oct, the operator: "make the preview pane larger a bit. That's the focus... and then just a
simple, minor explanation of what the indicator is for"."""

PURPOSE = re.search(r"const PURPOSE = \{(.*?)\n \};", PICKER, re.S).group(1)
KEYS = re.findall(r"^ '([a-z0-9-]+)': '", PURPOSE, re.M)

def test_the_pane_and_the_picture_are_larger(self):
self.assertIn("const width = Math.min(880, W - 16);", PICKER)
self.assertIn("Math.min(540, H - top - 12)", PICKER)
self.assertIn("minmax(300px, 360px)", CSS)
self.assertIn(".qp__shot { width: 100%; height: 236px;", CSS)

def test_every_built_in_says_what_it_is_for(self):
# Vela 0.8.3 ships 77 built-ins; each one gets its own sentence, and each key is a real type id.
self.assertEqual(len(self.KEYS), 77)
self.assertEqual(len(set(self.KEYS)), 77)
vela = "".join(p.read_text(encoding="utf-8", errors="replace")
for p in (FRONT / "vendor" / "vela" / "dist").glob("chunk-*.js"))
missing = [k for k in self.KEYS if f'"{k}"' not in vela and f"'{k}'" not in vela]
self.assertEqual(missing, [], "PURPOSE keys that are not Vela built-in types")

def test_one_plain_sentence_each(self):
for line in re.findall(r"^ '[a-z0-9-]+': '(.*)',$", self.PURPOSE, re.M):
self.assertLess(len(line), 140, line)
self.assertNotIn("<", line)

def test_a_luxalgo_script_uses_its_own_write_up(self):
self.assertIn("return firstSentence(x.description);", PICKER)
self.assertIn("What it’s for", PICKER)
self.assertIn("${esc(why)}", PICKER)

def test_the_panel_finds_built_ins_by_what_they_do(self):
self.assertIn("ti().purpose({ native: true, slug: n.type })", DRAWER)


if __name__ == "__main__":
unittest.main()
83 changes: 83 additions & 0 deletions console/backend/tests/test_lib_drawer_polish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""The scripts list behind Indicators: six faults found in a screenshot review (31 Oct).

1. a row whose preview picture failed collapsed: the <img> was deleted, the row's grid shifted one
column left, the name landed in the 52 px picture slot ("Indic…") and the ☆ got the name's room;
2. built-in rows: the ƒ sat in the corner of its tile, and Run sat 12 px left of every other Run
(no ☆ in those rows, so Run took the ☆'s column);
3. the detail view said only "Failed / No live MCP session" — no reason in words, no way to retry;
4. the search box always said "Search 800 scripts" (the header said 120, or 77);
5. the family chips were cut at the edge ("Mom") with nothing saying they scroll;
6. the theme switch in the footer was a tiny dim ◐ that read as a broken glyph.
"""

import re
import unittest
from pathlib import Path

FRONT = Path(__file__).resolve().parents[2] / "frontend"
CSS = (FRONT / "styles.css").read_text(encoding="utf-8")
JS = (FRONT / "drawer.js").read_text(encoding="utf-8")
APP = (FRONT / "app.js").read_text(encoding="utf-8")
HTML = (FRONT / "index.html").read_text(encoding="utf-8")


def rule(selector: str) -> str:
m = re.search(re.escape(selector) + r"\s*\{([^}]*)\}", CSS)
assert m, f"no CSS rule for {selector}"
return m.group(1)


class ARowKeepsItsShape(unittest.TestCase):
def test_each_part_owns_its_column(self):
# a missing tile or a missing ☆ can no longer move what comes after it
for sel, col in ((".drow > .drow__main", "2"), (".drow > .drow__star", "3"), (".drow > .drow__run", "4")):
self.assertRegex(rule(sel), rf"grid-column:\s*{col}\b", sel)

def test_a_failed_picture_becomes_a_tile_not_a_hole(self):
self.assertIn("img.replaceWith(", JS)
self.assertIn("drow__shot--none", JS)
self.assertNotIn("img.remove()", JS)

def test_placeholder_tiles_centre_their_glyph(self):
r = rule(".drow__shot--native,\n.drow__shot--none")
self.assertIn("place-items: center", r)


class TheDetailSaysWhatWentWrong(unittest.TestCase):
def test_api_errors_carry_their_code(self):
self.assertIn("err.code = payload.code", APP)

def test_an_offline_library_is_said_in_words_with_a_retry(self):
self.assertIn("mcp_unavailable", APP)
self.assertIn("The LuxAlgo Library isn't connected", APP)
self.assertIn("data-detail-retry", APP)
self.assertNotIn('<h2 class="detail__title">Failed</h2>', APP)


class TheSearchDoesNotMakeUpACount(unittest.TestCase):
def test_no_fixed_number_in_the_placeholder(self):
self.assertNotRegex(HTML, r'placeholder="Search \d+ scripts')


class TheChipsSayTheyScroll(unittest.TestCase):
def test_overflow_is_marked_and_faded(self):
self.assertIn("dataset.more", JS)
self.assertIn('.drawer__fams[data-more', CSS)
self.assertIn("mask-image", CSS.split(".drawer__fams[data-more", 1)[1][:400])


class TheThemeSwitchIsAnIcon(unittest.TestCase):
def test_sun_and_moon_not_a_glyph(self):
btn = HTML[HTML.index('id="theme-toggle"') - 80: HTML.index('id="theme-toggle"') + 900]
self.assertIn("i-sun", btn)
self.assertIn("i-moon", btn)
self.assertNotIn(">◐<", btn)

def test_it_is_a_real_target(self):
r = rule(".drawer__theme")
self.assertRegex(r, r"width:\s*28px")
self.assertRegex(r, r"height:\s*28px")


if __name__ == "__main__":
unittest.main()
4 changes: 3 additions & 1 deletion console/backend/tests/test_preview_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ def test_a_row_without_a_picture_loses_its_img_not_its_tile(self):
drawer = read(DRAWER)
self.assertIn("list.addEventListener('error'", drawer,
"a 404 preview must not leave the browser's broken-image glyph behind")
self.assertIn("if (img && img.tagName === 'IMG') img.remove();", drawer)
# 31 Oct: the <img> is swapped for a placeholder tile, not deleted — deleting it shifted the
# row's grid one column left and squeezed the name into the 52 px picture slot ("Indic…")
self.assertIn("img.replaceWith(", drawer)


if __name__ == "__main__":
Expand Down
Loading
Loading