md2ui 0.1.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- md2ui/__init__.py +0 -0
- md2ui/advice.py +468 -0
- md2ui/advice_forms.py +273 -0
- md2ui/advice_patterns.py +249 -0
- md2ui/app.py +1049 -0
- md2ui/app_capture.py +193 -0
- md2ui/app_chrome.py +134 -0
- md2ui/app_icon.py +88 -0
- md2ui/app_native_field.py +217 -0
- md2ui/app_prompt.py +468 -0
- md2ui/app_surface.py +49 -0
- md2ui/check.py +873 -0
- md2ui/check_charts.py +383 -0
- md2ui/check_choices.py +205 -0
- md2ui/check_feeds.py +206 -0
- md2ui/check_placeholders.py +127 -0
- md2ui/digest.py +402 -0
- md2ui/includes.py +527 -0
- md2ui/main.py +216 -0
- md2ui/mcp_demo.py +1033 -0
- md2ui/mcp_demo_activity.py +155 -0
- md2ui/mcp_demo_records.py +157 -0
- md2ui/mcp_demo_told.py +115 -0
- md2ui/mcp_server.py +563 -0
- md2ui/meanings.py +592 -0
- md2ui/notes.py +61 -0
- md2ui/pattern_respell.py +128 -0
- md2ui/pipeline/__init__.py +0 -0
- md2ui/pipeline/data_point_detector.py +1165 -0
- md2ui/pipeline/data_point_types.py +45 -0
- md2ui/pipeline/detector_guards.py +124 -0
- md2ui/pipeline/detector_parsers.py +1645 -0
- md2ui/pipeline/detector_scope.py +97 -0
- md2ui/pipeline/detector_signs.py +73 -0
- md2ui/pipeline/detector_vocabulary.py +190 -0
- md2ui/pipeline/generator_column_cuts.py +91 -0
- md2ui/pipeline/generator_displays.py +361 -0
- md2ui/pipeline/generator_fit_votes.py +276 -0
- md2ui/pipeline/generator_markers.py +149 -0
- md2ui/pipeline/generator_spacers.py +389 -0
- md2ui/pipeline/generator_spring_wrap.py +62 -0
- md2ui/pipeline/generator_units.py +798 -0
- md2ui/pipeline/grouper_annotate.py +567 -0
- md2ui/pipeline/grouper_block_splits.py +758 -0
- md2ui/pipeline/grouper_charts.py +547 -0
- md2ui/pipeline/grouper_choices.py +36 -0
- md2ui/pipeline/grouper_code_blocks.py +208 -0
- md2ui/pipeline/grouper_column_rows.py +552 -0
- md2ui/pipeline/grouper_content_edits.py +104 -0
- md2ui/pipeline/grouper_display_vocab.py +82 -0
- md2ui/pipeline/grouper_displays.py +339 -0
- md2ui/pipeline/grouper_drawing_elements.py +403 -0
- md2ui/pipeline/grouper_element_splits.py +389 -0
- md2ui/pipeline/grouper_escapes.py +234 -0
- md2ui/pipeline/grouper_feed_slots.py +298 -0
- md2ui/pipeline/grouper_glue.py +516 -0
- md2ui/pipeline/grouper_ids.py +105 -0
- md2ui/pipeline/grouper_inline_marks.py +682 -0
- md2ui/pipeline/grouper_kinds.py +718 -0
- md2ui/pipeline/grouper_line_flow.py +245 -0
- md2ui/pipeline/grouper_memo.py +124 -0
- md2ui/pipeline/grouper_node_reads.py +317 -0
- md2ui/pipeline/grouper_pairs.py +133 -0
- md2ui/pipeline/grouper_ranges.py +272 -0
- md2ui/pipeline/grouper_separate.py +453 -0
- md2ui/pipeline/grouper_separator_splits.py +332 -0
- md2ui/pipeline/grouper_sliders.py +343 -0
- md2ui/pipeline/grouper_spacers.py +451 -0
- md2ui/pipeline/grouper_split_apply.py +386 -0
- md2ui/pipeline/grouper_split_criteria.py +320 -0
- md2ui/pipeline/grouper_text_lengths.py +41 -0
- md2ui/pipeline/grouper_types.py +1059 -0
- md2ui/pipeline/grouper_value_splits.py +229 -0
- md2ui/pipeline/layout_auto.py +108 -0
- md2ui/pipeline/layout_generator.py +4042 -0
- md2ui/pipeline/layout_render.py +2920 -0
- md2ui/pipeline/layout_script_parser.py +443 -0
- md2ui/pipeline/markdown_grouper.py +2638 -0
- md2ui/pipeline/render_actions.py +592 -0
- md2ui/pipeline/render_backgrounds.py +569 -0
- md2ui/pipeline/render_bars.py +201 -0
- md2ui/pipeline/render_card_label.py +55 -0
- md2ui/pipeline/render_chart.py +748 -0
- md2ui/pipeline/render_choices.py +117 -0
- md2ui/pipeline/render_code_blocks.py +422 -0
- md2ui/pipeline/render_colors.py +545 -0
- md2ui/pipeline/render_counts.py +195 -0
- md2ui/pipeline/render_drawing_elements.py +516 -0
- md2ui/pipeline/render_element_paint.py +103 -0
- md2ui/pipeline/render_fills.py +204 -0
- md2ui/pipeline/render_glyph_faces.py +261 -0
- md2ui/pipeline/render_hints.py +278 -0
- md2ui/pipeline/render_image_placeholder.py +149 -0
- md2ui/pipeline/render_line_chart.py +304 -0
- md2ui/pipeline/render_list_surfaces.py +183 -0
- md2ui/pipeline/render_measure.py +2629 -0
- md2ui/pipeline/render_metrics.py +565 -0
- md2ui/pipeline/render_picture.py +192 -0
- md2ui/pipeline/render_pill_paint.py +81 -0
- md2ui/pipeline/render_place.py +1220 -0
- md2ui/pipeline/render_placeholders.py +161 -0
- md2ui/pipeline/render_ring_text.py +189 -0
- md2ui/pipeline/render_scroll_overlay.py +140 -0
- md2ui/pipeline/render_segmented.py +159 -0
- md2ui/pipeline/render_settings.py +105 -0
- md2ui/pipeline/render_shadows.py +327 -0
- md2ui/pipeline/render_shaping.py +130 -0
- md2ui/pipeline/render_slots.py +118 -0
- md2ui/pipeline/render_spacing.py +488 -0
- md2ui/pipeline/render_style.py +763 -0
- md2ui/pipeline/render_text.py +553 -0
- md2ui/pipeline/render_text_paint.py +220 -0
- md2ui/pipeline/render_text_scopes.py +446 -0
- md2ui/pipeline/theme.py +2642 -0
- md2ui/pipeline/theme_assets.py +98 -0
- md2ui/pipeline/theme_model.py +1697 -0
- md2ui/pipeline/theme_placeholders.py +154 -0
- md2ui/pipeline/value_format.py +50 -0
- md2ui/session.py +623 -0
- md2ui/shipped/MEANINGS.md +99 -0
- md2ui/shipped/THEME.md +1030 -0
- md2ui/shipped/assets/app/icon.png +0 -0
- md2ui/shipped/assets/demo/working.webp +0 -0
- md2ui/shipped/assets/fonts.lock +537 -0
- md2ui/shipped/assets/icons/LICENSE +202 -0
- md2ui/shipped/assets/icons/NOTICE +13 -0
- md2ui/shipped/assets/icons/material-design-icons-md2ui.ttf +0 -0
- md2ui/shipped/data/images/image-broken-placeholder.png +0 -0
- md2ui/shipped/data/images/image-placeholder.png +0 -0
- md2ui/shipped/data/vectors/image-placeholder.svg +1 -0
- md2ui/shipped/patterns/bank-card.md +23 -0
- md2ui/shipped/patterns/framed-picture.md +20 -0
- md2ui/shipped/patterns/live-card.md +27 -0
- md2ui/shipped/patterns/month-calendar.md +40 -0
- md2ui/shipped/patterns/music-player.md +26 -0
- md2ui/shipped/skills/README.md +204 -0
- md2ui/shipped/skills/banking-example.md +72 -0
- md2ui/shipped/skills/code-blocks.md +80 -0
- md2ui/shipped/skills/colour.md +41 -0
- md2ui/shipped/skills/dashboards.md +437 -0
- md2ui/shipped/skills/elements.md +450 -0
- md2ui/shipped/skills/images.md +592 -0
- md2ui/shipped/skills/includes.md +39 -0
- md2ui/shipped/skills/lookup.md +90 -0
- md2ui/shipped/skills/opened.md +43 -0
- md2ui/shipped/skills/pages/api-reference.md +287 -0
- md2ui/shipped/skills/pages/artist-page.md +110 -0
- md2ui/shipped/skills/pages/current-conditions.md +89 -0
- md2ui/shipped/skills/pages/dish-grid.md +61 -0
- md2ui/shipped/skills/pages/garment-detail.md +122 -0
- md2ui/shipped/skills/pages/home-board.md +140 -0
- md2ui/shipped/skills/pages/hours-ahead.md +46 -0
- md2ui/shipped/skills/pages/money-dashboard.md +93 -0
- md2ui/shipped/skills/pages/places.md +33 -0
- md2ui/shipped/skills/pages/publisher-console.md +186 -0
- md2ui/shipped/skills/pages/shelves.md +73 -0
- md2ui/shipped/skills/pages/stay-detail.md +284 -0
- md2ui/shipped/skills/pages/wallet-overview.md +49 -0
- md2ui/shipped/skills/pages/watchlist.md +32 -0
- md2ui/shipped/skills/pages/widget-board.md +144 -0
- md2ui/shipped/skills/pages/workspace-landing.md +299 -0
- md2ui/shipped/skills/pages.md +71 -0
- md2ui/shipped/skills/patterns/agenda.md +28 -0
- md2ui/shipped/skills/patterns/article.md +32 -0
- md2ui/shipped/skills/patterns/buy-box.md +32 -0
- md2ui/shipped/skills/patterns/call-to-action.md +21 -0
- md2ui/shipped/skills/patterns/chart-card.md +24 -0
- md2ui/shipped/skills/patterns/choices.md +37 -0
- md2ui/shipped/skills/patterns/code-sample.md +30 -0
- md2ui/shipped/skills/patterns/comparison.md +28 -0
- md2ui/shipped/skills/patterns/confirm.md +23 -0
- md2ui/shipped/skills/patterns/connect-account.md +23 -0
- md2ui/shipped/skills/patterns/directory.md +35 -0
- md2ui/shipped/skills/patterns/empty-state.md +32 -0
- md2ui/shipped/skills/patterns/features.md +30 -0
- md2ui/shipped/skills/patterns/feed.md +33 -0
- md2ui/shipped/skills/patterns/figure-tiles.md +35 -0
- md2ui/shipped/skills/patterns/gallery.md +23 -0
- md2ui/shipped/skills/patterns/goodbye.md +27 -0
- md2ui/shipped/skills/patterns/guide.md +30 -0
- md2ui/shipped/skills/patterns/hero-figure.md +23 -0
- md2ui/shipped/skills/patterns/hero.md +24 -0
- md2ui/shipped/skills/patterns/inbox.md +24 -0
- md2ui/shipped/skills/patterns/itinerary.md +24 -0
- md2ui/shipped/skills/patterns/kpis.md +27 -0
- md2ui/shipped/skills/patterns/listing.md +39 -0
- md2ui/shipped/skills/patterns/month-calendar.md +38 -0
- md2ui/shipped/skills/patterns/now-playing.md +25 -0
- md2ui/shipped/skills/patterns/offer.md +20 -0
- md2ui/shipped/skills/patterns/people.md +23 -0
- md2ui/shipped/skills/patterns/photo-card.md +25 -0
- md2ui/shipped/skills/patterns/picture-rows.md +32 -0
- md2ui/shipped/skills/patterns/profile.md +21 -0
- md2ui/shipped/skills/patterns/progress.md +21 -0
- md2ui/shipped/skills/patterns/quick-actions.md +23 -0
- md2ui/shipped/skills/patterns/reference-list.md +35 -0
- md2ui/shipped/skills/patterns/result.md +25 -0
- md2ui/shipped/skills/patterns/reviews.md +34 -0
- md2ui/shipped/skills/patterns/services.md +27 -0
- md2ui/shipped/skills/patterns/shelf.md +40 -0
- md2ui/shipped/skills/patterns/shortcuts.md +36 -0
- md2ui/shipped/skills/patterns/specs.md +33 -0
- md2ui/shipped/skills/patterns/split.md +27 -0
- md2ui/shipped/skills/patterns/status-list.md +25 -0
- md2ui/shipped/skills/patterns/steps.md +24 -0
- md2ui/shipped/skills/patterns/suggestions.md +19 -0
- md2ui/shipped/skills/patterns/task-list.md +25 -0
- md2ui/shipped/skills/patterns/testimonials.md +30 -0
- md2ui/shipped/skills/patterns/ticker-rows.md +22 -0
- md2ui/shipped/skills/repetition.md +296 -0
- md2ui/shipped/skills/structure.md +827 -0
- md2ui/shipped/skills/text.md +195 -0
- md2ui/shipped/skills/verifying.md +82 -0
- md2ui/stale_code.py +80 -0
- md2ui/theme_lint.py +521 -0
- md2ui/utils/__init__.py +0 -0
- md2ui/utils/fetch_policy.py +43 -0
- md2ui/utils/font_loader.py +426 -0
- md2ui/utils/font_lock.py +128 -0
- md2ui/utils/image_cache.py +641 -0
- md2ui/utils/image_params.py +163 -0
- md2ui/utils/photo_decoder.py +236 -0
- md2ui/utils/png.py +115 -0
- md2ui/utils/scroll_state.py +168 -0
- md2ui/wire.py +561 -0
- md2ui/wire_bars.py +268 -0
- md2ui/wire_client.py +408 -0
- md2ui/wire_edits.py +244 -0
- md2ui/wire_feed_posts.py +149 -0
- md2ui/wire_feeds.py +555 -0
- md2ui/wire_frames.py +268 -0
- md2ui/wire_includes.py +232 -0
- md2ui/wire_patch.py +437 -0
- md2ui/wire_records.py +144 -0
- md2ui/wire_sections.py +218 -0
- md2ui/wire_server.py +810 -0
- md2ui/wire_texts.py +255 -0
- md2ui-0.1.0a1.dist-info/METADATA +395 -0
- md2ui-0.1.0a1.dist-info/RECORD +244 -0
- md2ui-0.1.0a1.dist-info/WHEEL +4 -0
- md2ui-0.1.0a1.dist-info/entry_points.txt +7 -0
- md2ui-0.1.0a1.dist-info/licenses/LICENSE +21 -0
- md2ui-0.1.0a1.dist-info/licenses/assets/icons/LICENSE +202 -0
- md2ui-0.1.0a1.dist-info/licenses/assets/icons/NOTICE +13 -0
md2ui/__init__.py
ADDED
|
File without changes
|
md2ui/advice.py
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
"""Advice from what an answer used: the section that teaches it, while unread.
|
|
2
|
+
|
|
3
|
+
Agents read the core note and stop (ADR-502).
|
|
4
|
+
Directed, they find the right note and use it; unprompted, nothing tells them
|
|
5
|
+
their answer needs one. The one surface every agent reads at the moment it
|
|
6
|
+
decides is a tool's result, and it is the only one that knows what the agent
|
|
7
|
+
wrote. So ``check``, ``preview`` and the demo's ``show`` add a line naming the
|
|
8
|
+
section that teaches a construct the answer used, when this session has not
|
|
9
|
+
read that section (ADR-502).
|
|
10
|
+
|
|
11
|
+
Each trigger reads the grouped tree, never the source text, and is kept only
|
|
12
|
+
while an eval shows it helps: an answer it fires on is better after the re-send
|
|
13
|
+
than before. A line says what to write first, so a small fix needs no read, and
|
|
14
|
+
then the section, with its cost, for the cases the hint does not cover.
|
|
15
|
+
|
|
16
|
+
Once per section per session, and nothing when nothing fires, so an answer that
|
|
17
|
+
needs no advice pays nothing. A hint that only points is not enough for card
|
|
18
|
+
actions, so the card hint names the theme's own card spellings.
|
|
19
|
+
|
|
20
|
+
A pattern in ``skills/patterns/`` is advised the same way, from the shape of a
|
|
21
|
+
section (``advice_patterns``). Reading the patterns index is not reading a
|
|
22
|
+
pattern, so only ``patterns/<name>`` silences one.
|
|
23
|
+
|
|
24
|
+
A form written a turn at a time (a stepper of buttons, options without a name,
|
|
25
|
+
values no press carries) is advised from ``advice_forms``, skipping what an
|
|
26
|
+
include drew and the steppers a registered handler answers (ADR-612): a
|
|
27
|
+
backend's handler answers those with no turn.
|
|
28
|
+
|
|
29
|
+
A shell module beside ``check`` and ``digest``; the pipeline never imports it.
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
from __future__ import annotations
|
|
33
|
+
|
|
34
|
+
import re
|
|
35
|
+
from collections.abc import Collection, Iterator
|
|
36
|
+
from dataclasses import dataclass, field
|
|
37
|
+
|
|
38
|
+
from md2ui import session, wire_sections
|
|
39
|
+
from md2ui.advice_forms import form_hints
|
|
40
|
+
from md2ui.advice_patterns import pattern_hints
|
|
41
|
+
from md2ui.check import check_grouped
|
|
42
|
+
from md2ui.includes import Includes, Region, failures, unexpanded
|
|
43
|
+
from md2ui.meanings import Contract, Row, _node_spelling
|
|
44
|
+
from md2ui.pipeline.grouper_types import MarkdownGroupNode
|
|
45
|
+
from md2ui.notes import sections
|
|
46
|
+
|
|
47
|
+
SKILLS = session.resource_root() / "skills"
|
|
48
|
+
|
|
49
|
+
ICON_ROLES = "elements/what-the-icon-does-decides-how-you-write-it"
|
|
50
|
+
THEME = "theme"
|
|
51
|
+
CHIPS = "text/inline-code-has-two-forms"
|
|
52
|
+
CHARTS = "dashboards/which-figure-each-spelling-draws"
|
|
53
|
+
FORMS = "elements/what-a-click-does"
|
|
54
|
+
|
|
55
|
+
# Two values and what joins them, written as a line of its own: `SFO → JFK`,
|
|
56
|
+
# `San Francisco SFO → New York JFK`. Up to three words a side, so a sentence
|
|
57
|
+
# never matches.
|
|
58
|
+
_SIDE = r"(\S+(?:\s\S+){0,2})"
|
|
59
|
+
_JOINED = re.compile(rf"^\s*{_SIDE}\s+(\S{{1,3}})\s+{_SIDE}\s*$")
|
|
60
|
+
_ARROWS = frozenset("→ ⟶ ➔ ➜ ⇒ ->".split())
|
|
61
|
+
_DIGIT = re.compile(r"\d")
|
|
62
|
+
# A label that names a way in to the item rather than what the card is for:
|
|
63
|
+
# `Open Copywriting`, `View on Expedia`, `Read more`.
|
|
64
|
+
_WAY_IN = re.compile(r"^(?:open|view|see|details|read|visit|go to)\b", re.IGNORECASE)
|
|
65
|
+
# A note whose bare name serves an index of its parts, not the parts themselves.
|
|
66
|
+
_INDEXES = frozenset({"patterns"})
|
|
67
|
+
# The contract's slots for an action inside a card, and for a way in that repeats
|
|
68
|
+
# on every card (``meanings.SLOTS``).
|
|
69
|
+
_CARD_SLOTS = frozenset({"card-main", "card-quieter"})
|
|
70
|
+
_WAY_IN_SLOT = "card-way-in"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@dataclass
|
|
74
|
+
class Reading:
|
|
75
|
+
"""What one session has read through ``guide``, and what it was advised to
|
|
76
|
+
read: advice is never repeated, whether or not it was followed."""
|
|
77
|
+
|
|
78
|
+
read: set[str] = field(default_factory=set)
|
|
79
|
+
advised: set[str] = field(default_factory=set)
|
|
80
|
+
|
|
81
|
+
def covers(self, topic: str) -> bool:
|
|
82
|
+
"""Read or advised already: the topic itself, or the whole note it is a
|
|
83
|
+
section of. ``patterns`` is the index, so a pattern counts only when it
|
|
84
|
+
was read by its own name."""
|
|
85
|
+
seen = self.read | self.advised
|
|
86
|
+
note = topic.split("/")[0]
|
|
87
|
+
return topic in seen or (note in seen and note not in _INDEXES)
|
|
88
|
+
|
|
89
|
+
def advise(
|
|
90
|
+
self,
|
|
91
|
+
tree: dict | None,
|
|
92
|
+
contract: Contract | None,
|
|
93
|
+
drawn: Collection[str] = (),
|
|
94
|
+
handled: Collection[str] = (),
|
|
95
|
+
) -> list[dict]:
|
|
96
|
+
"""Advice for the grouped *tree*, as ``check`` notes, each with the topic
|
|
97
|
+
it points to under ``read``. *drawn* is the lines includes drew, and
|
|
98
|
+
*handled* the ``agent:`` slugs the server's handlers answer."""
|
|
99
|
+
out: list[dict] = []
|
|
100
|
+
for topic, message in _found(tree, contract, drawn, handled) if tree else ():
|
|
101
|
+
if self.covers(topic) or any(o["read"] == topic for o in out):
|
|
102
|
+
continue
|
|
103
|
+
out.append(
|
|
104
|
+
{"level": "note", "code": "advice", "message": message, "read": topic}
|
|
105
|
+
)
|
|
106
|
+
self.advised |= {o["read"] for o in out}
|
|
107
|
+
return out
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def reply_issues(
|
|
111
|
+
markdown: str,
|
|
112
|
+
ast: MarkdownGroupNode | None,
|
|
113
|
+
contract: Contract | None,
|
|
114
|
+
reading: Reading,
|
|
115
|
+
includes: Includes | None = None,
|
|
116
|
+
regions: tuple[Region, ...] = (),
|
|
117
|
+
handled: Collection[str] = (),
|
|
118
|
+
) -> list[dict]:
|
|
119
|
+
"""What a reply's sender returns to its agent: the authoring issues, then the
|
|
120
|
+
advice for this session. The demo's ``show`` and the ``check`` tool return it,
|
|
121
|
+
and so does a backend's own send tool after ``Conversation.send``
|
|
122
|
+
(protocol/backend.md): advice helps only on the path every reply takes.
|
|
123
|
+
*markdown* is the page with its includes expanded; an include line left in it
|
|
124
|
+
is an issue, said for *includes* (``includes.unexpanded``, ADR-612), and
|
|
125
|
+
*regions* are the lines they drew, which no advice is about; one that drew
|
|
126
|
+
its failure line is an issue too (``includes.failures``). *handled* is
|
|
127
|
+
the ``agent:`` slugs the server's handlers answer (``Conversation.handlers``):
|
|
128
|
+
a stepper they answer costs no turn and is not advised a count."""
|
|
129
|
+
tree = ast.to_dict() if ast is not None else None
|
|
130
|
+
issues = unexpanded(markdown, includes) + failures(regions)
|
|
131
|
+
issues += check_grouped(markdown, ast, contract)
|
|
132
|
+
issues += _unread_limits(markdown)
|
|
133
|
+
lines = markdown.split("\n")
|
|
134
|
+
drawn = [line for r in regions for line in lines[r.start : r.end]]
|
|
135
|
+
return issues + reading.advise(tree, contract, drawn, handled)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _unread_limits(markdown: str) -> list[dict]:
|
|
139
|
+
"""A note for each ``fresh:`` that names no duration: without one, the section
|
|
140
|
+
is never reported stale, and nothing else would say so."""
|
|
141
|
+
return [
|
|
142
|
+
{
|
|
143
|
+
"level": "note",
|
|
144
|
+
"code": "fresh-unread",
|
|
145
|
+
"message": f"`fresh: {s.fresh}` under `{s.name}` is not a duration, so "
|
|
146
|
+
"the section is never reported stale. Write a number and a unit: "
|
|
147
|
+
"`30s`, `5m`, `2h`, `1d`.",
|
|
148
|
+
}
|
|
149
|
+
for s in wire_sections.unread_limits(markdown)
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _found(
|
|
154
|
+
tree: dict,
|
|
155
|
+
contract: Contract | None,
|
|
156
|
+
drawn: Collection[str] = (),
|
|
157
|
+
handled: Collection[str] = (),
|
|
158
|
+
) -> Iterator[tuple[str, str]]:
|
|
159
|
+
"""``(topic, message)`` for each trigger the tree sets off, in document order."""
|
|
160
|
+
for node in _walk(tree):
|
|
161
|
+
kids = node.get("children", [])
|
|
162
|
+
for glyph, number in zip(kids, kids[1:]):
|
|
163
|
+
if (
|
|
164
|
+
glyph.get("type") == "emoji"
|
|
165
|
+
and number.get("text_style") == "display"
|
|
166
|
+
and _DIGIT.search(str(number.get("content", "")))
|
|
167
|
+
):
|
|
168
|
+
yield (
|
|
169
|
+
ICON_ROLES,
|
|
170
|
+
(
|
|
171
|
+
f"`{glyph['content']}` stands as a badge beside the number "
|
|
172
|
+
f"`{number['content']}`. An icon that belongs to the number is "
|
|
173
|
+
f"written inside its tier, `___{glyph['content']} "
|
|
174
|
+
f"{number['content']}___`, and grows with it. {_read(ICON_ROLES)}"
|
|
175
|
+
),
|
|
176
|
+
)
|
|
177
|
+
for amount in _lone_amounts(node):
|
|
178
|
+
yield (
|
|
179
|
+
CHIPS,
|
|
180
|
+
(
|
|
181
|
+
f"`{amount}` is one amount on a chip, and a chip is for a word the "
|
|
182
|
+
f"reader scans for: a status, a tag. Write the amount without the "
|
|
183
|
+
f"backticks, {amount}, or `__{amount}__` when it leads its card; a set of "
|
|
184
|
+
f"prices, or a change such as `▲ +2%`, stays chips. {_read(CHIPS)}"
|
|
185
|
+
),
|
|
186
|
+
)
|
|
187
|
+
lines = [] if str(node.get("type")).startswith("heading") else kids
|
|
188
|
+
for line in lines:
|
|
189
|
+
if line.get("type") != "text" or not (joined := _joined(line)):
|
|
190
|
+
continue
|
|
191
|
+
yield (
|
|
192
|
+
ICON_ROLES,
|
|
193
|
+
(
|
|
194
|
+
f"`{line['content']}` writes how two values relate as one line of "
|
|
195
|
+
f"text. An icon between two values stands between them, "
|
|
196
|
+
f"`__{_bare(joined[0])}__ ... {joined[1]} ... "
|
|
197
|
+
f"__{_bare(joined[2])}__`. "
|
|
198
|
+
f"{_read(ICON_ROLES)}"
|
|
199
|
+
),
|
|
200
|
+
)
|
|
201
|
+
runs: dict[object, list[str]] = {}
|
|
202
|
+
for card in kids:
|
|
203
|
+
if card.get("heading_group") and not _asks(card):
|
|
204
|
+
if action := _full_size_action(card):
|
|
205
|
+
runs.setdefault(card.get("fingerprint_hash"), []).append(action)
|
|
206
|
+
actions = max(runs.values(), key=len, default=[])
|
|
207
|
+
if len(actions) >= 2 and contract and (spelled := _card_spellings(contract)):
|
|
208
|
+
yield (
|
|
209
|
+
THEME,
|
|
210
|
+
f"These {len(actions)} cards each hold a full-size action, "
|
|
211
|
+
f"`{actions[0]}`. With this theme an action inside a card is "
|
|
212
|
+
f'{spelled}: `guide("theme")` lists which size goes where.',
|
|
213
|
+
)
|
|
214
|
+
if contract and (way_in := _repeated_way_in(kids, contract)):
|
|
215
|
+
count, written, spelled = way_in
|
|
216
|
+
yield (
|
|
217
|
+
THEME,
|
|
218
|
+
f"These {count} cards each hold `{written}`, a way in to the item. "
|
|
219
|
+
f"With this theme a way in that repeats on every card is {spelled}: "
|
|
220
|
+
f'`guide("theme")` lists which spelling goes where.',
|
|
221
|
+
)
|
|
222
|
+
yield from _tabulated_series(tree)
|
|
223
|
+
for message in form_hints(tree, drawn, handled):
|
|
224
|
+
yield FORMS, f"{message} {_read(FORMS)}"
|
|
225
|
+
yield from pattern_hints(tree)
|
|
226
|
+
if contract is not None and (own := _declared_and_used(tree, contract)):
|
|
227
|
+
yield (
|
|
228
|
+
THEME,
|
|
229
|
+
(
|
|
230
|
+
f"This theme declares spellings of its own for {own}: "
|
|
231
|
+
f'`guide("theme")` lists them and what each means.'
|
|
232
|
+
),
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def _walk(node: dict) -> Iterator[dict]:
|
|
237
|
+
yield node
|
|
238
|
+
for kid in node.get("children", []):
|
|
239
|
+
yield from _walk(kid)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def _joined(node: dict) -> tuple[str, str, str] | None:
|
|
243
|
+
"""``(from, glyph, to)`` when a text line is two short values joined by an
|
|
244
|
+
arrow or a lone glyph."""
|
|
245
|
+
found = _JOINED.match(str(node.get("content", "")))
|
|
246
|
+
if found is None:
|
|
247
|
+
return None
|
|
248
|
+
glyphs = {
|
|
249
|
+
dp["matched"] for dp in node.get("data_points", []) if dp["label"] == "dp_emoji"
|
|
250
|
+
}
|
|
251
|
+
if found.group(2) not in _ARROWS and found.group(2) not in glyphs:
|
|
252
|
+
return None
|
|
253
|
+
return found.group(1), found.group(2), found.group(3)
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def _lone_amounts(node: dict) -> list[str]:
|
|
257
|
+
"""The chips among *node*'s children that are one amount and nothing else,
|
|
258
|
+
each the only amount chip on its line. A line of several prices is a set,
|
|
259
|
+
and a table cell is a cell of one; a signed or arrowed change is detected as
|
|
260
|
+
a change, not an amount, so it never counts."""
|
|
261
|
+
amounts = [
|
|
262
|
+
str(kid["content"])
|
|
263
|
+
for kid in node.get("children", [])
|
|
264
|
+
if kid.get("type") == "inline_code"
|
|
265
|
+
and not kid.get("table_role")
|
|
266
|
+
and [dp["matched"] for dp in kid.get("data_points", [])]
|
|
267
|
+
== [str(kid["content"]).strip()]
|
|
268
|
+
and kid["data_points"][0]["label"] == "dp_currency"
|
|
269
|
+
]
|
|
270
|
+
# Children of a line group share one line; any other node's chips each
|
|
271
|
+
# stand on a line of their own.
|
|
272
|
+
return amounts if len(amounts) == 1 or not node.get("line_split_group") else []
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _bare(value: str) -> str:
|
|
276
|
+
"""A value without the emphasis it was written with, to rewrap in a hint."""
|
|
277
|
+
return value.strip("*_")
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _asks(card: dict) -> bool:
|
|
281
|
+
"""A card that asks the user something: its buttons are the answers, a choice
|
|
282
|
+
set, which takes the full size (``skills/README.md``, *choice set*)."""
|
|
283
|
+
return any(
|
|
284
|
+
str(kid.get("content", "")).rstrip().endswith("?")
|
|
285
|
+
for kid in card.get("children", [])
|
|
286
|
+
if kid.get("type") == "text"
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _full_size_action(card: dict) -> str | None:
|
|
291
|
+
"""The first button a card holds at the standard size: the bare main action
|
|
292
|
+
or the quieter one, worded or an icon."""
|
|
293
|
+
link = _card_link(card, ("primary", "secondary"))
|
|
294
|
+
return str(link["content"]).strip() if link else None
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _card_link(card: dict, variants: tuple[str, ...]) -> dict | None:
|
|
298
|
+
"""The first link of one of *variants* a card holds, as its own child or in a
|
|
299
|
+
row of its own (never in a card nested inside it)."""
|
|
300
|
+
for kid in card.get("children", []):
|
|
301
|
+
row = [] if kid.get("heading_group") else kid.get("children", [])
|
|
302
|
+
for node in [kid, *row]:
|
|
303
|
+
if node.get("type") == "link" and node.get("link_variant") in variants:
|
|
304
|
+
return node
|
|
305
|
+
return None
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def _repeated_way_in(
|
|
309
|
+
kids: list[dict], contract: Contract
|
|
310
|
+
) -> tuple[int, str, str] | None:
|
|
311
|
+
"""``(cards, as written, the way-in spelling)`` when every card of a run holds
|
|
312
|
+
the same kind of card action worded as the same way in to the item (`Open`,
|
|
313
|
+
`View`, `Read more`): a link that repeats on every card, which the theme
|
|
314
|
+
spells apart from the action the card is for.
|
|
315
|
+
|
|
316
|
+
A way in is told by its label, not its target: `Open Copywriting` as an
|
|
317
|
+
``agent:`` action and `View on Expedia` as an ``https:`` link are both one.
|
|
318
|
+
The spellings are the contract's rows chosen by their slot, as
|
|
319
|
+
``_card_spellings`` chooses them: the card actions are the rows with a
|
|
320
|
+
``_CARD_SLOTS`` slot, and the way in is the row with ``_WAY_IN_SLOT``. A
|
|
321
|
+
way in already written in that spelling is not a card action, so it never
|
|
322
|
+
fires."""
|
|
323
|
+
rows = _button_rows(contract)
|
|
324
|
+
way_in = [row.write for row in rows if _WAY_IN_SLOT in row.slots]
|
|
325
|
+
in_card = tuple(
|
|
326
|
+
row.selects.variant
|
|
327
|
+
for row in rows
|
|
328
|
+
if row.selects is not None and _CARD_SLOTS.intersection(row.slots)
|
|
329
|
+
)
|
|
330
|
+
if not way_in or not in_card:
|
|
331
|
+
return None
|
|
332
|
+
runs: dict[object, list[dict | None]] = {}
|
|
333
|
+
for card in kids:
|
|
334
|
+
if card.get("heading_group"):
|
|
335
|
+
link = _card_link(card, in_card)
|
|
336
|
+
runs.setdefault(card.get("fingerprint_hash"), []).append(link)
|
|
337
|
+
for links in runs.values():
|
|
338
|
+
found = [link for link in links if link is not None]
|
|
339
|
+
if len(links) < 2 or len(found) < len(links):
|
|
340
|
+
continue
|
|
341
|
+
verbs = {_way_in_verb(str(link.get("link_label", ""))) for link in found}
|
|
342
|
+
kinds = {link.get("link_variant") for link in found}
|
|
343
|
+
if len(kinds) == 1 and len(verbs) == 1 and None not in verbs:
|
|
344
|
+
return len(found), str(found[0]["content"]).strip(), way_in[0]
|
|
345
|
+
return None
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def _way_in_verb(label: str) -> str | None:
|
|
349
|
+
"""The word a label opens with when it names a way in to the item."""
|
|
350
|
+
found = _WAY_IN.match(label)
|
|
351
|
+
return found[0].lower() if found else None
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def _card_spellings(contract: Contract) -> str:
|
|
355
|
+
"""The theme's spellings for an action inside a card, from the rows whose
|
|
356
|
+
slot places them there, each with its meaning: ``**[Label](/x)**`` (the main
|
|
357
|
+
action inside a card), ``***[Label](/x)***`` (a quieter action inside a card)."""
|
|
358
|
+
rows = [
|
|
359
|
+
row for row in _button_rows(contract) if _CARD_SLOTS.intersection(row.slots)
|
|
360
|
+
]
|
|
361
|
+
return ", ".join(f"{row.write} ({row.means})" for row in rows)
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def _button_rows(contract: Contract) -> list[Row]:
|
|
365
|
+
"""The contract's rows for a worded or an icon button."""
|
|
366
|
+
return [
|
|
367
|
+
row
|
|
368
|
+
for section in contract.sections
|
|
369
|
+
if section.heading.lower() in ("buttons", "icon buttons")
|
|
370
|
+
for row in section.rows
|
|
371
|
+
]
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def _declared_and_used(tree: dict, contract: Contract) -> str:
|
|
375
|
+
"""The elements the answer uses that the theme gives spellings of its own,
|
|
376
|
+
named as ``MEANINGS.md``'s sections are: ``icons and chips``."""
|
|
377
|
+
own = {
|
|
378
|
+
row.selects.element
|
|
379
|
+
for section in contract.sections
|
|
380
|
+
for row in section.rows
|
|
381
|
+
if row.own and row.selects is not None
|
|
382
|
+
}
|
|
383
|
+
used = {
|
|
384
|
+
spelled[0].element
|
|
385
|
+
for node in _walk(tree)
|
|
386
|
+
if (spelled := _node_spelling(node)) is not None
|
|
387
|
+
}
|
|
388
|
+
names = sorted(f"{element}s" for element in own & used)
|
|
389
|
+
return " and ".join(names)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def _read(topic: str) -> str:
|
|
393
|
+
note, _, name = topic.partition("/")
|
|
394
|
+
path = SKILLS / f"{note}.md"
|
|
395
|
+
text = (
|
|
396
|
+
sections(path.read_text(encoding="utf-8")).get(name, "")
|
|
397
|
+
if path.is_file()
|
|
398
|
+
else ""
|
|
399
|
+
)
|
|
400
|
+
return f'`guide("{topic}")`, ≈{len(text.split())} words.'
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
# The grouper's datapoint displays that draw a figure: bars, rings, ratio bars and a
|
|
404
|
+
# line (a date chip is a chip).
|
|
405
|
+
_FIGURES = frozenset({"kv_percent_bar", "unit_ratio", "ratio_bar", "line_chart"})
|
|
406
|
+
|
|
407
|
+
# One number in a cell, with what it is measured in: a currency before it, or a
|
|
408
|
+
# unit after it.
|
|
409
|
+
_CELL_VALUE = re.compile(
|
|
410
|
+
r"^\D*?([$€£¥]?)\s*[-−+]?\d[\d.,]*\s*(%|°[CF]?|[A-Za-z/]+)?\s*$"
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def _text(node: dict) -> str:
|
|
415
|
+
return " ".join(
|
|
416
|
+
[str(node.get("content") or "")] + [_text(k) for k in node.get("children", [])]
|
|
417
|
+
).strip()
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def _tabulated_series(tree: dict) -> Iterator[tuple[str, str]]:
|
|
421
|
+
"""A table column of three or more numbers in one unit, on a page that draws
|
|
422
|
+
no figure: the series is there, only written as cells."""
|
|
423
|
+
if any(
|
|
424
|
+
n.get("chart_group")
|
|
425
|
+
or n.get("line_group")
|
|
426
|
+
or n.get("datapoint_display") in _FIGURES
|
|
427
|
+
for n in _walk(tree)
|
|
428
|
+
):
|
|
429
|
+
return
|
|
430
|
+
for node in _walk(tree):
|
|
431
|
+
kids = node.get("children", [])
|
|
432
|
+
header = next((k for k in kids if k.get("type") == "table_header"), None)
|
|
433
|
+
rows = [k for k in kids if k.get("type") == "table_row"]
|
|
434
|
+
if not header or len(rows) < 3:
|
|
435
|
+
continue
|
|
436
|
+
heads = [_text(c) for c in header.get("children", [])]
|
|
437
|
+
names = [re.sub(r"\s*\(.*?\)", "", h) for h in heads]
|
|
438
|
+
series: dict[str, list[str]] = {}
|
|
439
|
+
for col, name in enumerate(names):
|
|
440
|
+
# Bare numbers take the unit their header declares in parentheses,
|
|
441
|
+
# `Wind (km/h)`; with none declared they are not a series in one unit.
|
|
442
|
+
declared = re.search(r"\(([^()]+)\)", heads[col])
|
|
443
|
+
units = set()
|
|
444
|
+
for row in rows:
|
|
445
|
+
cells = row.get("children", [])
|
|
446
|
+
text = _text(cells[col]) if col < len(cells) else ""
|
|
447
|
+
found = _CELL_VALUE.match(text)
|
|
448
|
+
if not found or len(re.findall(r"\d+(?:[.,]\d+)*", text)) != 1:
|
|
449
|
+
break
|
|
450
|
+
unit = found.group(1) + (found.group(2) or "")
|
|
451
|
+
units.add(unit or (declared.group(1).strip() if declared else ""))
|
|
452
|
+
else:
|
|
453
|
+
if len(units) == 1 and (unit := units.pop()):
|
|
454
|
+
series.setdefault(unit, []).append(name)
|
|
455
|
+
if not series:
|
|
456
|
+
continue
|
|
457
|
+
unit, named = max(series.items(), key=lambda s: len(s[1]))
|
|
458
|
+
cols = ", ".join(f"`{n}`" for n in named)
|
|
459
|
+
yield (
|
|
460
|
+
CHARTS,
|
|
461
|
+
f"{'The ' + cols + ' columns hold' if len(named) > 1 else 'The ' + cols + ' column holds'} "
|
|
462
|
+
f"{len(rows)} values each in `{unit}`, and the page draws no figure. A "
|
|
463
|
+
f"series the reader follows draws as a chart: rows under a "
|
|
464
|
+
f"`Name ({unit}):` line, each value alone, or two series compared under "
|
|
465
|
+
f"`A, B ({unit}):`, one value per series. The table can stay. "
|
|
466
|
+
f"{_read(CHARTS)}",
|
|
467
|
+
)
|
|
468
|
+
return
|