Repository navigation
Render interactive components from Markdown - #338
HamptonMakes wants to merge 48 commits into
Conversation
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
… networking Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
| selection = comment.component_selection.except("image") | ||
| selection["png_url"] = api_v1_plan_comment_snapshot_path(@plan, comment) if comment.component_selection["image"] | ||
| { component_selection: selection } | ||
| end |
There was a problem hiding this comment.
what is this and why is it in the base controller?
| end | ||
| end | ||
| safe_join(content) | ||
| end |
There was a problem hiding this comment.
curious if these would be faster in erb or something else, or is this actually the most efficient and bug free way to do these types of view builds?
| module Comments | ||
| class ComponentAnnotation | ||
| PNG_HEADER = "\x89PNG\r\n\x1a\n".b.freeze | ||
| PNG_END = "\x00\x00\x00\x00IEND\xaeB\x60\x82".b.freeze |
There was a problem hiding this comment.
uhhh... is this secure?
| thread = @comment.comment_thread | ||
| raise ActiveRecord::RecordInvalid, thread unless thread.valid? | ||
| invalid! unless thread.anchor_kind == "component" && @selection.is_a?(String) && @selection.bytesize <= 2048 | ||
| data = JSON.parse(@selection) |
There was a problem hiding this comment.
are we using the most efficient and safe JSON parser?
| Rails.error.report(error, handled: true) | ||
| raise UploadError, "Could not save the component image. Your draft is still here. Try again." | ||
| end | ||
| @comment.component_snapshot.attach(@blob) |
There was a problem hiding this comment.
why is this so complex?
| | `GET /api/v1/plans/:id/comments` | List the threads. Each comment includes its `reactions`. | comments | | ||
| | `POST /api/v1/plans/:id/comments` | Start a thread: `body_markdown`, optional `anchor_text` and `anchor_occurrence`. | comments | | ||
| | `GET /api/v1/plans/:id/comments/:thread_id` | Get one thread. | comments | | ||
| | `GET /api/v1/plans/:id/comments/:comment_id/snapshot` | Read the PNG attached to a component comment using the same Bearer token. | comments | |
There was a problem hiding this comment.
do we indicate that a comment HAD an attachment?
I'm also wondering if this should be more attachment with a type, then specifically doing 'snapshot'
| @@ -0,0 +1,57 @@ | |||
| # Interactive components | |||
|
|
|||
| Write a top-level component between standalone region markers. Leave a blank line before and after each marker. The body is JavaScript. Use DOM APIs on the supplied `root` to build controls, HTML, SVG, canvas, and animation. Each reader starts with fresh state. A region ID such as `#retry-path` is optional and supplies a deep link. The optional title names the frame for assistive technology. Comment and Expand slide out below the bottom-right edge when the pointer approaches the component or its tab. Keyboard focus reveals the controls. On touch screens, tap the small grip beneath the corner. Expand preserves the current state. In Comment mode, click a point or drag a box. The reader previews a PNG of the live view with the selection marked. Enter selects the whole view. Reopening Comment resumes an unfinished annotation and its image. Discard annotation starts over. If capture is unavailable, for example after scrolling a nested panel, the selection and its dimensions still accompany the comment. No capture code is required from the author. | |||
There was a problem hiding this comment.
this doesn't seem as useful for a remote agent that's authoring the components... they don't care AS Much about how the user interacts with them, but should really focus on like- how they work, what they are, what they can/can't do...
| Write a top-level component between standalone region markers. Leave a blank line before and after each marker. The body is JavaScript. Use DOM APIs on the supplied `root` to build controls, HTML, SVG, canvas, and animation. Each reader starts with fresh state. A region ID such as `#retry-path` is optional and supplies a deep link. The optional title names the frame for assistive technology. Comment and Expand slide out below the bottom-right edge when the pointer approaches the component or its tab. Keyboard focus reveals the controls. On touch screens, tap the small grip beneath the corner. Expand preserves the current state. In Comment mode, click a point or drag a box. The reader previews a PNG of the live view with the selection marked. Enter selects the whole view. Reopening Comment resumes an unfinished annotation and its image. Discard annotation starts over. If capture is unavailable, for example after scrolling a nested panel, the selection and its dimensions still accompany the comment. No capture code is required from the author. | ||
|
|
||
| ````markdown | ||
| ::: {.component type="diagram"} |
There was a problem hiding this comment.
start with generic JS component, before diagram... and we should probably have instructions and a table for all supported component types...?
|
|
||
| The reader's browser runs the script inside an opaque sandbox. Bundle dependencies locally. The sandbox blocks fetch, remote scripts and images, form submissions, and parent navigation. Components have no access to the surrounding plan or its session storage. Browser support for blocking every outbound connection varies. Use components for document data intended for their readers. Its source stays available if execution is disabled or a dependency cannot be resolved. Source revisions retain their selected libraries and wrappers. | ||
|
|
||
| Component execution on this host is <%= Coplan.configuration.components_enabled ? "enabled" : "disabled" %>. |
There was a problem hiding this comment.
if its disabled, then this shouldn't be linked to at all!!! like, just don't let it know about it.
|
|
||
| ## Host catalog | ||
|
|
||
| <% catalog = Coplan.configuration.component_catalog %> |
There was a problem hiding this comment.
ah, here is the catalog!
|
|
||
| ## Host catalog | ||
|
|
||
| <% catalog = Coplan.configuration.component_catalog %> |
There was a problem hiding this comment.
ummm... I don't see any descriptoin of the difference between 'libraries' and 'types'... and libraries means something specific in coplan!
|
|
||
| Component execution on this host is <%= Coplan.configuration.components_enabled ? "enabled" : "disabled" %>. | ||
|
|
||
| ## Host catalog |
There was a problem hiding this comment.
don't use the word 'host' like this--- that's an internal term, not something the external agent shoudl know about.
"Available Component Types" or something.
| | Connecting a computer without a credential | <<%= @base %>/agent-instructions/connecting> | | ||
| | Diagrams, tables, code blocks, footnotes, section links, task lists, images | <<%= @base %>/agent-instructions/markdown> | | ||
| | Slide decks inside a plan (`::: {.presentation}` regions) | <<%= @base %>/agent-instructions/presentations> | | ||
| - Interactive JavaScript components, types, and bundled libraries: <<%= @base %>/agent-instructions/components> |
There was a problem hiding this comment.
THIS is what should be optionally shown
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e0970cfde
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| markers[pos[:start_line]] = line if line == CLOSE || line.match?(OPEN) | ||
| reset_marker_scan(0) | ||
| regions = [] | ||
| canonical = @lines.dup |
There was a problem hiding this comment.
Preserve CRLF offsets in the canonical source
For CRLF documents containing a component or presentation marker, initializing canonical from @lines removes every carriage return. MarkdownTextExtractor uses this canonical source to build position maps, but CommentThread#resolve_anchor_position stores those positions against the original content. Browser-created prose comments therefore receive incorrect anchor ranges, shifted by one character per preceding CRLF, which also breaks subsequent anchor tracking. Preserve the original line endings in canonical_source, including on masked lines, as component_mask already does.
Useful? React with 👍 / 👎.
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
…actions Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
* origin/main: Reset browser test sessions on Chrome 158 Make notification budgets configurable and safe Preserve responses before deferred agent wakes Isolate deferred agent wake failures Wake agent sessions after their inbox events commit Budget notification fan-out per person Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
Signed-off-by: Hampton Lintorn-Catlin <hampton@squareup.com>
What changed and why
Authors can put an interactive diagram or demo directly in a plan’s Markdown. A
::: {.component}region holds JavaScript and starts with a DOM element namedroot. Base is the only built-in starter. The checkout flow and stress-lab map both draw SVG in Base. Hosts can register additional types and versioned libraries. Each plan revision retains the bundles it uses.The engine defaults to showing component source. This demo host explicitly enables execution. Other hosts can follow the host setup guide to check their deployed frame policy and browser support before turning it on.
The reader runs each component in a sandboxed iframe on the existing host. The shell has an opaque origin, enforces its own Content Security Policy, and receives the program through a private message port. Comment and Expand slide out beneath the bottom-right corner as the pointer approaches. Keyboard focus or a tap on the touch grip also reveals the controls. A reader can select rendered HTML or SVG text and use the same Comment button or C shortcut as document prose. The discussion retains the selected words and bounds. A reader can also mark a point or drag a box, preview the marked PNG, and attach it to a discussion. The comment API exposes the original dimensions, selection and revision, plus a typed attachments list with authenticated download links. When capture is unavailable, the preview shows that the comment will carry the selection alone.
How to try it
Install the engine migrations and seed the shared demo library. Open Interactive components: checkout retries. Move the slider from three failed attempts to four. The total delay changes from seven seconds to fifteen. Choose Comment below the simulator and drag across the result. Post the preview and reopen its discussion to see the same fifteen-second result. Open the document editor and choose Edit on the diagram. The JavaScript editor highlights the source as you type. Change an SVG label and choose Preview to run it. Choose + → Component → Base to start a plain JavaScript component. New blocks open with the code field focused. Quick guide explains the selected type and shows its starter without leaving the editor. The same examples appear in the agent reference. The header offers optional imports when the host provides modules. Raw shows the complete Markdown region.
In the reader, select Failed attempts and press C to comment on the selected words. Start typing immediately. The marked image loads in the preview while you write. If you post early, the composer waits up to 3.5 seconds for the image. For a heavier workload, open Component stress lab. Set the map to 48 replicas per stage for 384 services and 1,344 routes, or run the canvas simulation at 32,768 time steps for 8,388,608 updates.
Base quick guide
Testing
Request and browser specs cover revision pinning, source fallback, module loading, iframe isolation, comments, and rich-editor round trips. In Chromium and WebKit, the retry diagram and changed simulator produced marked PNGs. The tab and transparent drag outline were checked in both color modes. Touch tests covered revealing and dismissing the controls.
Generated with Codex