Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat!(agent/slop): ability to copy prompt and open in agent from task (#2815)
teo6516ed435a2f
diff --git a/js/app/packages/block-md/component/DispatchAgentMenu.tsx b/js/app/packages/block-md/component/DispatchAgentMenu.tsxnew file mode 100644index 0000000000..69f66ee448--- /dev/null+++ b/js/app/packages/block-md/component/DispatchAgentMenu.tsx@@ -0,0 +1,269 @@+import { useBlockId } from '@core/block';+import { toast } from '@core/component/Toast/Toast';+import { DropdownMenuContent, MenuItem } from '@core/component/Menu';+import { editorStateAsMarkdown } from '@core/component/LexicalMarkdown/utils';+import { isOk } from '@core/util/maybeResult';+import { useBlockDocumentName } from '@core/util/currentBlockDocumentName';+import { tryMacroId, macroIdToEmail } from '@core/user';+import { storageServiceClient } from '@service-storage/client';+import { mdStore } from '../signal/markdownBlockData';+import {+ discussionThreads,+ sortComments,+} from '../comments/discussionResource';+import { makePersisted } from '@solid-primitives/storage';+import { DropdownMenu } from '@kobalte/core/dropdown-menu';+import { Button } from '@ui/components/Button';+import { createSignal, For, type Component, type JSX } from 'solid-js';+import { Dynamic } from 'solid-js/web';+import CaretDown from '@icon/regular/caret-down.svg';+import CopyIcon from '@icon/regular/copy.svg';+import TerminalWindowIcon from '@icon/regular/terminal-window.svg';+import ClaudeIcon from '@macro-icons/wide/claude.svg';+import CursorIcon from '@macro-icons/wide/cursor-ide.svg';+import ZedIcon from '@macro-icons/wide/zed-ide.svg';+import CodexIcon from '@macro-icons/wide/codex-ide.svg';+import type { CommentThread } from '@service-storage/generated/schemas/commentThread';+import { createCallback } from '@solid-primitives/rootless';+import { openMacroMcpSetupModal } from '@app/component/macro-mcp-setup-modal/MacroMcpSetupModal';+import PlugIcon from '@icon/regular/plug.svg';++const MAX_BRANCH_LENGTH = 200;+const LAST_USED_KEY = 'dispatch-agent-last-used';++const slugify = (title: string): string =>+ title+ .toLowerCase()+ .replace(/[^a-z0-9\s-]/g, '')+ .replace(/\s+/g, '-')+ .replace(/-+/g, '-')+ .replace(/^-|-$/g, '');++async function buildBranchName(+ documentId: string,+ documentName: string+): Promise<{ shortId: string; branchName: string }> {+ const result = await storageServiceClient.getDocumentShortId({ documentId });+ const shortId = isOk(result) ? result[1] : documentId;+ const slug = slugify(documentName);+ const branchName = `macro-${shortId}${slug ? `-${slug}` : ''}`.slice(+ 0,+ MAX_BRANCH_LENGTH+ );+ return { shortId, branchName };+}++async function generateTaskPrompt(+ documentId: string,+ documentName: string,+ content: string,+ threads: CommentThread[]+): Promise<string> {+ const { shortId, branchName } = await buildBranchName(+ documentId,+ documentName+ );++ const lines: string[] = [];++ lines.push(`Work on Macro task ${documentName}:`);+ lines.push('');+ lines.push(`<task identifier="${shortId}">`);+ lines.push(`<title>${documentName}</title>`);+ lines.push(`<branch>${branchName}</branch>`);+ lines.push('</task>');++ if (content) {+ lines.push('');+ lines.push('<task-content>');+ lines.push(content);+ lines.push('</task-content>');+ }++ if (threads.length > 0) {+ lines.push('');+ for (const thread of threads) {+ const sorted = [...thread.comments].sort(sortComments);+ lines.push(`<comment-thread thread-id="${thread.thread.threadId}">`);+ for (const comment of sorted) {+ if (comment.text && !comment.deletedAt) {+ const userId = comment.sender ?? comment.owner;+ const macroId = tryMacroId(userId);+ const author = macroId ? macroIdToEmail(macroId) : userId;+ const createdAt = comment.createdAt+ ? ` created-at="${comment.createdAt}"`+ : '';+ lines.push(+ `<comment author="${author}"${createdAt}>${comment.text}</comment>`+ );+ }+ }+ lines.push('</comment-thread>');+ }+ }++ lines.push('');+ lines.push(`Please use the branch "${branchName}" for your work.`);+ lines.push('');+ lines.push(+ 'If you have the Macro MCP server enabled, use it to gather additional context about this task.'+ );++ return lines.join('\n');+}++type AgentAction = {+ key: string;+ name: string;+ icon: Component<JSX.SvgSVGAttributes<SVGSVGElement>>;+ buttonIcon?: Component<JSX.SvgSVGAttributes<SVGSVGElement>>;+ execute: (prompt: string) => void;+};++const COPY_ACTION: AgentAction = {+ key: 'copy',+ name: 'Copy as prompt',+ icon: CopyIcon,+ buttonIcon: TerminalWindowIcon,+ execute: (prompt) => {+ navigator.clipboard.writeText(prompt);+ toast.success('Task prompt copied to clipboard');+ },+};++const PLATFORM_ACTIONS: AgentAction[] = [+ {+ key: 'claude-code',+ name: 'Claude Code Web',+ icon: ClaudeIcon,+ execute: (prompt) =>+ window.open(+ `https://claude.ai/code?q=${encodeURIComponent(prompt)}`,+ '_blank'+ ),+ },+ {+ key: 'codex-desktop',+ name: 'Codex Desktop',+ icon: CodexIcon,+ execute: (prompt) =>+ window.open(`codex://new?prompt=${encodeURIComponent(prompt)}`, '_blank'),+ },+ {+ key: 'cursor',+ name: 'Cursor',+ icon: CursorIcon,+ execute: (prompt) =>+ window.open(+ `cursor://anysphere.cursor-deeplink/prompt?text=${encodeURIComponent(prompt)}`,+ '_blank'+ ),+ },+ {+ key: 'zed',+ name: 'Zed',+ icon: ZedIcon,+ execute: (prompt) =>+ window.open(`zed://agent?prompt=${encodeURIComponent(prompt)}`, '_blank'),+ },+];++const ALL_ACTIONS = [COPY_ACTION, ...PLATFORM_ACTIONS];++const [lastUsedKey, setLastUsedKey] = makePersisted(+ createSignal(COPY_ACTION.key),+ { name: LAST_USED_KEY }+);++export function DispatchAgentButton() {+ const blockId = useBlockId();+ const name = useBlockDocumentName();+ const [store] = mdStore;+ const [open, setOpen] = createSignal(false);++ const lastUsed = () =>+ ALL_ACTIONS.find((a) => a.key === lastUsedKey()) ?? COPY_ACTION;++ const buildPrompt = createCallback(() => {+ const docName = name();+ const content = store.editor+ ? editorStateAsMarkdown(store.editor, 'external')+ : '';+ const threads = discussionThreads() ?? [];+ return generateTaskPrompt(blockId, docName, content, threads);+ });++ const executeAction = async (action: AgentAction) => {+ try {+ const prompt = await buildPrompt();+ action.execute(prompt);+ setLastUsedKey(action.key);+ } catch (e) {+ console.error('Failed to generate task prompt', e);+ toast.failure('Failed to generate task prompt');+ }+ setOpen(false);+ };++ const handlePrimaryClick = () => {+ executeAction(lastUsed());+ };++ return (+ <DropdownMenu open={open()} onOpenChange={setOpen}>+ <div class="border-1 border-edge-muted flex ml-1 items-stretch rounded-xs">+ <Button+ onClick={handlePrimaryClick}+ tooltip={lastUsed().name}+ variant="ghost"+ size="icon-sm"+ class="p-1"+ >+ <Dynamic+ component={lastUsed().buttonIcon ?? lastUsed().icon}+ class="size-3.5"+ />+ </Button>+ <div class="w-[1px] bg-edge-muted" />+ <DropdownMenu.Trigger+ as={Button}+ variant="ghost"+ size="icon-sm"+ class="p-1"+ >+ <CaretDown class="w-3 h-3" />+ </DropdownMenu.Trigger>+ </div>+ <DropdownMenu.Portal>+ <DropdownMenuContent>+ <MenuItem+ text={COPY_ACTION.name}+ icon={COPY_ACTION.icon}+ onClick={() => executeAction(COPY_ACTION)}+ />+ <MenuItem+ text="MCP setup instructions"+ icon={PlugIcon}+ onClick={() => {+ openMacroMcpSetupModal();+ setOpen(false);+ }}+ />+ <div class="my-1 h-[1px] bg-edge-muted/50" />+ <div class="px-2 py-1 text-xs text-ink-extra-muted font-medium">+ Open in+ </div>+ <For each={PLATFORM_ACTIONS}>+ {(action) => (+ <MenuItem+ text={action.name}+ icon={action.icon}+ onClick={() => executeAction(action)}+ />+ )}+ </For>+ </DropdownMenuContent>+ </DropdownMenu.Portal>+ </DropdownMenu>+ );+}diff --git a/js/app/packages/block-md/component/TopBar.tsx b/js/app/packages/block-md/component/TopBar.tsxindex 2cf21d6a29..d9b5cfad8e 100644--- a/js/app/packages/block-md/component/TopBar.tsx+++ b/js/app/packages/block-md/component/TopBar.tsx@@ -51,6 +51,7 @@ import GitBranch from '@icon/regular/git-branch.svg';import Info from '@icon/regular/info.svg';import Bell from '@icon/regular/bell.svg';import Quotes from '@icon/regular/quotes.svg';+import TerminalWindowIcon from '@icon/regular/terminal-window.svg';import IconShared from '@macro-icons/wide/share.svg';import IconLink from '@icon/regular/link.svg';import ClockIcon from '@icon/regular/clock-counter-clockwise.svg';@@ -62,6 +63,7 @@ import { registerHotkey } from '@core/hotkey/hotkeys';import { blockHotkeyScopeSignal } from '@core/signal/blockElement';import { DETAILS_DRAWER_ID } from '@core/component/DetailsDrawer';import { createEffect, For, on, Show, type JSX } from 'solid-js';+import { DispatchAgentButton } from './DispatchAgentMenu';import { HISTORY_DRAWER_ID } from './History';import { DRAWER_ID as PROPERTIES_DRAWER_ID } from './MarkdownPropertiesModal';import { useAnalytics } from '@app/component/analytics-context';@@ -221,6 +223,13 @@ export function TopBar() {action: propertiesControl.toggle,isActive: propertiesControl.isOpen,},+ {+ label: 'Dispatch to Agent',+ icon: TerminalWindowIcon,+ action: () => {},+ condition: () => isTask && !isMobile(),+ buttonComponent: () => <DispatchAgentButton />,+ },{label: 'Share',icon: IconShared,diff --git a/js/app/packages/macro-icons/wide/claude.svg b/js/app/packages/macro-icons/wide/claude.svgnew file mode 100644index 0000000000..f6340092d0--- /dev/null+++ b/js/app/packages/macro-icons/wide/claude.svg@@ -0,0 +1,3 @@+<svg width="100%" height="100%" viewBox="0 0 24 24" fill="currentColor" stroke="none" xmlns="http://www.w3.org/2000/svg">+<path d="m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z"/>+</svg>diff --git a/js/app/packages/macro-icons/wide/codex-ide.svg b/js/app/packages/macro-icons/wide/codex-ide.svgnew file mode 100644index 0000000000..10f0bc3517--- /dev/null+++ b/js/app/packages/macro-icons/wide/codex-ide.svg@@ -0,0 +1,3 @@+<svg width="100%" height="100%" viewBox="0 0 24 24" fill="currentColor" stroke="none" xmlns="http://www.w3.org/2000/svg">+<path d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"/>+</svg>diff --git a/js/app/packages/macro-icons/wide/cursor-ide.svg b/js/app/packages/macro-icons/wide/cursor-ide.svgnew file mode 100644index 0000000000..3bf22f3e15--- /dev/null+++ b/js/app/packages/macro-icons/wide/cursor-ide.svg@@ -0,0 +1,3 @@+<svg width="100%" height="100%" viewBox="0 0 24 24" fill="currentColor" stroke="none" xmlns="http://www.w3.org/2000/svg">+<path d="M11.503.131 1.891 5.678a.84.84 0 0 0-.42.726v11.188c0 .3.162.575.42.724l9.609 5.55a1 1 0 0 0 .998 0l9.61-5.55a.84.84 0 0 0 .42-.724V6.404a.84.84 0 0 0-.42-.726L12.497.131a1.01 1.01 0 0 0-.996 0M2.657 6.338h18.55c.263 0 .43.287.297.515L12.23 22.918c-.062.107-.229.064-.229-.06V12.335a.59.59 0 0 0-.295-.51l-9.11-5.257c-.109-.063-.064-.23.061-.23"/>+</svg>diff --git a/js/app/packages/macro-icons/wide/zed-ide.svg b/js/app/packages/macro-icons/wide/zed-ide.svgnew file mode 100644index 0000000000..2dcb61c179--- /dev/null+++ b/js/app/packages/macro-icons/wide/zed-ide.svg@@ -0,0 +1,3 @@+<svg width="100%" height="100%" viewBox="0 0 24 24" fill="currentColor" stroke="none" xmlns="http://www.w3.org/2000/svg">+<path d="M2.25 1.5a.75.75 0 0 0-.75.75v16.5H0V2.25A2.25 2.25 0 0 1 2.25 0h20.095c1.002 0 1.504 1.212.795 1.92L10.764 14.298h3.486V12.75h1.5v1.922a1.125 1.125 0 0 1-1.125 1.125H9.264l-2.578 2.578h11.689V9h1.5v9.375a1.5 1.5 0 0 1-1.5 1.5H5.185L2.562 22.5H21.75a.75.75 0 0 0 .75-.75V5.25H24v16.5A2.25 2.25 0 0 1 21.75 24H1.655C.653 24 .151 22.788.86 22.08L13.19 9.75H9.75v1.5h-1.5V9.375A1.125 1.125 0 0 1 9.375 8.25h5.314l2.625-2.625H5.625V15h-1.5V5.625a1.5 1.5 0 0 1 1.5-1.5h13.19L21.438 1.5z"/>+</svg>