Skip to content

feat(agent): clickable layer mention pills in AI chat composer and thread#172

Open
Zen0-99 wants to merge 5 commits into
CoreBunch:mainfrom
Zen0-99:feature/agent-layer-mentions
Open

feat(agent): clickable layer mention pills in AI chat composer and thread#172
Zen0-99 wants to merge 5 commits into
CoreBunch:mainfrom
Zen0-99:feature/agent-layer-mentions

Conversation

@Zen0-99

@Zen0-99 Zen0-99 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds interactive @-style layer mention pills to the AI chat composer and message thread. Users can click a sparkles icon in the canvas selection toolbar or right-click a layer in the DOM panel to queue layer IDs as styled pills in the composer. Pills are clickable and select the corresponding layer on the canvas. Sent messages retain their pill rendering in the thread, and the assistant's replies are also scanned for layer references so those render as pills too.

Why

Previously users had to describe elements to the AI because there was no way to reference the internal layer numbering system. This change lets users point the AI directly at specific layers via visual, clickable references.

Testing

  • All 54 existing tests pass (bun test)
  • TypeScript compiles cleanly (bun tsc --noEmit)
  • Verified multi-selection support: Ctrl+click multiple layers, click sparkles icon, all layers appear as separate pills
  • Verified mention click: clicking a pill selects the corresponding layer on the canvas
image image

Adds a Windows-specific retry loop using cmd /c timeout when the port
probing helper cannot identify the holding process. This avoids false
positives when a previous dev server is still shutting down.
@Zen0-99 Zen0-99 changed the title feat: clickable layer mention pills in AI chat feat(agent): clickable layer mention pills in AI chat composer and thread Jul 2, 2026
@DavidBabinec

Copy link
Copy Markdown
Contributor

Can you refine the design so the badge style doesn't push the text out of alignment?

Btw. agent was already aware of your selected element, but there was no UI for it yet, so I agree that this is useful too.

@Zen0-99 Zen0-99 closed this Jul 3, 2026
@Zen0-99 Zen0-99 reopened this Jul 3, 2026
@Zen0-99

Zen0-99 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Accidentally pressed to close, but will get right on it!

- New mentionLabel.ts helper resolves .classSelector, <tag>, or
  displayName from a nodeId, plus a tag-derived colorKey.
- Mention pills are now bold colored inline text (no badge box) so
  they don't push line height out of alignment.
- Underline uses currentColor so hover matches the pill color.
- AgentComposer uses getMentionLabelForNode for inserted pills.
- LayerNodeContextMenu generates human labels when staging mentions.
- RichTextBubble scanner now matches Layer/Module/Element/Node/Section/
  Component prefixes with optional brackets or backticks.
- Preserves the original prefix word in rendered output.
- Falls back to agentMentionLabels registry for deleted nodes.
- sendAgentMessage replaces human mention labels with 'Layer nodeId'
  in the AI prompt, and appends a concise instruction telling the AI
  to use the same format in its responses.
- AgentToolCall gains displayLabel (resolved at creation time via
  getMentionLabelForNode) so tool rows show human names after deletion.
- ToolCallRow and toolCallDisplay.ts thread displayLabel through
  all node-detail helpers.
- AgentSlice gains agentMentionLabels: Record<string, string> to
  accumulate nodeId→label mappings across the conversation.
- Labels are registered when drafting mentions, sending user messages,
  and creating tool calls — surviving node deletion for AI response
  scanning.
- streamEvents.ts resolves and caches displayLabel on toolCall creation.
@Zen0-99

Zen0-99 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@DavidBabinec So I polished up the PR (see new image above)

  • Instead of those chunky badge-style pills with borders and backgrounds that were pushing text around, mentions now render as bold colored inline text — they sit right in the flow of the sentence without messing up line height.
  • Colors now pull from the node's actual tag or class selector, so a div gets its familiar blue, a header its green, etc. — no more random purple. For readability we show human labels like .icon or h3 in the UI while still shipping Layer nodeId to the AI under the hood so it knows exactly what we're talking about.
  • I also added a little registry that remembers node labels across the conversation, so if you ask the AI to delete something and it later references that layer in its reply, the pill still shows .icon instead of a raw ID — even though the node is long gone.

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.

3 participants