Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

18.6 KB
Raw Blame

editor API

All edits go through the editor object. id is a node id from the XML. Methods that create a node return a handle you can pass to later calls. Pass plain text only. scope is optional: { kind: 'all' } for every match, { kind: 'nth', n: N } for the 1-based Nth match, or omitted (defaults to { kind: 'all' }).

Inline Formatting By Match

  • bold(id, match, scope?) · italic(id, match, scope?) · underline(id, match, scope?) · strike(id, match, scope?) · inlineCode(id, match, scope?)
  • unbold(id, match, scope?) · unitalic(id, match, scope?) · ununderline(id, match, scope?) · unstrike(id, match, scope?) · uninlineCode(id, match, scope?)
  • format(id, match, format, on?, scope?) where format is bold, italic, underline, strike, or code
  • clearFormat(id, match?, scope?) · clearAllFormat(id)
  • highlight(id, match, scope?) · unhighlight(id, match, scope?)
  • link(id, match, url, scope?) · unlink(id, match, scope?)
editor.bold('b1', 'quick');
editor.italic('b1', 'brown');
editor.highlight('b1', 'the');
editor.link('b1', 'fox', 'https://x');

Before:

<doc>
  <p id="b1">
    <t id="t1">the quick brown fox</t>
  </p>
</doc>

After:

<doc>
  <p id="b1">
    <mark id="b2" direction="null" format="" indent="0" version="1" ids="[]">
      <t id="t1">the</t>
    </mark>
    <t id="t2"> </t>
    <t id="t3" bold="true">quick</t>
    <t id="t4"> </t>
    <t id="t5" italic="true">brown</t>
    <t id="t6"> </t>
    <a id="b3" href="https://x">
      <t id="t7">fox</t>
    </a>
  </p>
</doc>

Inline Formatting By Text Node

  • boldNode(textId) · italicNode(textId) · underlineNode(textId) · strikeNode(textId) · codeNode(textId)
  • formatNode(textId, format, on?) · clearNodeFormat(textId)
editor.boldNode('t1');
editor.underlineNode('t1');

Before:

<doc>
  <p id="b1">
    <t id="t1">Hello world</t>
  </p>
</doc>

After:

<doc>
  <p id="b1">
    <t id="t1" bold="true" underline="true">Hello world</t>
  </p>
</doc>

Text Content

  • setText(id, text) — replaces the block's whole contents with one plain run, deleting any bold/code spans, links, mentions and line breaks it contained. Use it to rewrite a block from scratch.
  • replace(id, find, to, scope?) — rewrites matching text in place, leaving the rest of the block intact. Use it to edit existing prose. find must sit within a single text run.
  • appendText(id, text) · prependText(id, text)
  • setEquation(id, tex)
editor.setText('b1', 'replaced');
editor.appendText('b2', '!!!');
editor.prependText('b3', '> ');
editor.replace('b3', 'third', 'THIRD');
editor.setEquation('eq1', 'y^2');

Before:

<doc>
  <p id="b1"><t id="t1">first</t></p>
  <p id="b2"><t id="t2">second</t></p>
  <p id="b3"><t id="t3">third</t></p>
  <equation id="eq1" version="1" equation="x^2" inline="false"/>
</doc>

After:

<doc>
  <p id="b1"><t id="t1">replaced</t></p>
  <p id="b2"><t id="t2">second!!!</t></p>
  <p id="b3"><t id="t3">&gt; THIRD</t></p>
  <equation id="eq1" version="1" equation="y^2" inline="false"/>
</doc>

Block Type Conversion

  • convertToParagraph(id) · convertToHeading(id, level) · convertToQuote(id) · convertToCodeBlock(id, language) · setLanguage(id, language)
editor.convertToHeading('b1', 2);
editor.convertToQuote('b2');
editor.convertToCodeBlock('b3', 'ts');
editor.convertToParagraph('b4');
editor.setLanguage('b3', 'python');

Before:

<doc>
  <p id="b1"><t id="t1">Title</t></p>
  <p id="b2"><t id="t2">A quote</t></p>
  <p id="b3"><t id="t3">code here</t></p>
  <h3 id="b4"><t id="t4">Back to paragraph</t></h3>
</doc>

After:

<doc>
  <h2 id="b1~v1"><t id="t1">Title</t></h2>
  <blockquote id="b2~v1"><t id="t2">A quote</t></blockquote>
  <custom-code id="b3~v1" direction="null" format="" indent="0" version="1" language="python"><t id="t3">code here</t></custom-code>
  <p id="b4~v1"><t id="t4">Back to paragraph</t></p>
</doc>

Converting a block's type gives it a fresh id: the old id with a ~vN suffix (b1 → b1~v1, again → b1~v2). It's the SAME block — the suffix just marks the retype, and the stem tells you which block it was. Both the suffixed id and the original resolve later in the same code, but going forward use the id shown in the latest XML.

Lists

  • bulletList(idOrIds) · numberedList(idOrIds) · checklist(idOrIds) · setListType(id, kind)
  • check(id) · uncheck(id) · setChecked(id, bool)
  • indent(id, by?) · outdent(id, by?) · setIndent(id, level)
  • insertListItemAfter(liId, text, list?) · insertListItemBefore(liId, text, list?) · removeListItem(liId)
  • appendListItem(listId, text) · prependListItem(listId, text)

To add an item relative to an existing sibling, use insertListItemAfter/Before with that <li>'s id. list ('bullet'|'number'|'check', default 'bullet') sets the new item's kind; when it differs from the surrounding list, the item is wrapped in a nested sublist of that kind.

To add an item to a list as a whole -- including a list that is currently empty (no <li> to anchor on) -- use appendListItem/prependListItem with the <ul>/<ol> id; the item inherits the list's kind. All four methods return a handle to the new <li> you can use in later calls.

editor.checklist(['b1', 'b2']);
editor.check('b1');
editor.indent('b2');
editor.outdent('b2');
editor.setChecked('b2', false);
const li = editor.insertListItemAfter('li1', 'second item');
editor.insertListItemAfter(li, 'nested', 'number');
editor.removeListItem('li2');
const first = editor.appendListItem('ol3', 'first step'); // populate an empty list
editor.appendListItem('ol3', 'second step');

Before:

<doc>
  <ul id="list1"><li id="li1"><t id="t1">first item</t></li><li id="li2" value="2"><t id="t2">old item</t></li></ul>
</doc>

After:

<doc>
  <ul id="list1">
    <li id="li1"><t id="t1">first item</t></li>
    <li id="b1" value="2"><t id="t3">second item</t></li>
    <li id="b2" value="3">
      <ol id="b3"><li id="b4"><t id="t4">nested</t></li></ol>
    </li>
  </ul>
</doc>

Before:

<doc>
  <p id="b1"><t id="t1">task b</t></p>
  <p id="b2"><t id="t2">task a</t></p>
  <ul id="list1"><li id="li1"><t id="t3">z</t></li><li id="li2" value="2"><t id="t4">a</t></li></ul>
</doc>

After:

<doc>
  <ul id="b3" listType="check">
    <li id="b4" checked="true"><t id="t1">task b</t></li>
    <li id="b5" value="2" checked="false"><t id="t2">task a</t></li>
  </ul>
  <ul id="list1"><li id="li2"><t id="t4">a</t></li><li id="li1" value="2"><t id="t3">z</t></li></ul>
</doc>

Structure

  • insertParagraphAfter(id, text?) · insertParagraphBefore(id, text?)
  • insertHeadingAfter(id, level, text?) · insertHeadingBefore(id, level, text?)
  • insertQuoteAfter(id, text?) · insertCodeBlockAfter(id, language, text?)
  • insertBlockAfter(id, spec) · insertBlockBefore(id, spec)
  • appendParagraph(text?) · prependParagraph(text?) · appendBlock(spec) · prependBlock(spec)
  • move(id, position) where position is { after: id }, { before: id }, { appendToRoot: true }, or { prependToRoot: true }
  • remove(id) · removeMany(ids) · merge(ids, separator?)
editor.insertHeadingBefore('b1', 1, 'Title');
const c = editor.insertParagraphAfter('b2', 'Conclusion');
editor.appendText(c, '!');
editor.appendParagraph('Footer');
editor.move('b2', { after: c });
editor.remove('b4');

Before:

<doc>
  <p id="b1"><t id="t1">Intro</t></p>
  <p id="b2"><t id="t2">Body</t></p>
  <p id="b4"><t id="t3">Remove me</t></p>
</doc>

After:

<doc>
  <h1 id="b3"><t id="t4">Title</t></h1>
  <p id="b1"><t id="t1">Intro</t></p>
  <p id="b5"><t id="t5">Conclusion!</t></p>
  <p id="b2"><t id="t2">Body</t></p>
  <p id="b6"><t id="t6">Footer</t></p>
</doc>

Tables

  • insertTableAfter(id, rows) · insertTableBefore(id, rows) · appendTable(rows) where rows is string[][] and row 0 is the header
  • setCell(tableId, row, col, text)
  • addRow(tableId, at?) · addColumn(tableId, at?) · removeRow(tableId, row) · removeColumn(tableId, col)
const t = editor.appendTable([['Item', 'Done']]);
editor.addRow(t);
editor.setCell(t, 1, 1, 'yes');

Before:

<doc>
  <p id="b1"><t id="t1">Tasks</t></p>
</doc>

After:

<doc>
  <p id="b1"><t id="t1">Tasks</t></p>
  <table id="b2">
    <tr id="b3"><td id="b4" headerState="1"><p id="b5"><t id="t2">Item</t></p></td><td id="b6" headerState="1"><p id="b7"><t id="t3">Done</t></p></td></tr>
    <tr id="b8"><td id="b9"><p id="b10"/></td><td id="b11"><p id="b12"><t id="t4">yes</t></p></td></tr>
  </table>
</doc>

Media, Math, And Inline Objects

  • insertDivider(afterId)
  • insertImage(afterId, { srcType, url, alt?, width?, height? })
  • insertVideo(afterId, { srcType, url, controls?, width?, height? })
  • insertEquation(afterId, tex) · insertInlineEquation(blockId, at, tex)
  • insertLineBreak(blockId, at) — inserts a soft line break (Shift+Enter) within a block. Use only when multiple lines must live in a single semantic block (poetry, addresses, signature blocks). For ordinary multi-line content, insert separate paragraph nodes instead.
  • insertDate(blockId, at, isoDate, displayFormat?) / mentionDate(...) — inserts a date/time mention chip (the same chip @ inserts). Prefer this over typing a date as plain text.
  • insertTextAfterInline(inlineRef, text) — inserts a plain text node immediately after an inline object. Use this (not appendText) when you need text to follow an inline equation, date, line break, or other inline node.

The at in insertInlineEquation/insertLineBreak/insertDate is a character offset into the block's plain text — inline objects don't count toward it. Compute it (text.length, text.indexOf('word')) rather than guessing. When you do use insertLineBreak for soft-break content, set the first line then add each break at the running text length and insertTextAfterInline the next line:

editor.setText('b1', 'Lily pad hoppers');
const br1 = editor.insertLineBreak('b1', 'Lily pad hoppers'.length);
editor.insertTextAfterInline(br1, 'Croaking through the night');
const br2 = editor.insertLineBreak('b1', 'Lily pad hoppers'.length + 'Croaking through the night'.length);
editor.insertTextAfterInline(br2, 'Splash, then silence');
editor.insertDivider('b1');
editor.insertImage('b1', { srcType: 'url', url: 'https://x/cat.png', alt: 'cat' });
editor.insertVideo('b1', { srcType: 'url', url: 'https://x/movie.mp4', controls: true });
editor.insertEquation('b1', 'E=mc^2');
const eq = editor.insertInlineEquation('b2', 0, 'x^2');
editor.insertTextAfterInline(eq, ' is x squared');
editor.insertLineBreak('b2', 3);
editor.insertDate('b2', 4, '2026-06-23', 'MMM d, yyyy');

Before:

<doc>
  <p id="b1"><t id="t1">Above</t></p>
  <p id="b2"><t id="t2">Below</t></p>
</doc>

After:

<doc>
  <p id="b1"><t id="t1">Above</t></p>
  <equation id="b3" version="1" equation="E=mc^2" inline="false"/>
  <video id="b4" version="1" srcType="url" _id="" url="https://x/movie.mp4" width="0" height="0" scale="1" constrainedWidth="null" constrainedHeight="null" controls="true"/>
  <image id="b5" version="1" srcType="url" _id="" url="https://x/cat.png" width="0" height="0" scale="1" constrainedWidth="null" constrainedHeight="null" alt="cat"/>
  <hr id="b6"/>
  <p id="b2"><equation id="b7" version="1" equation="x^2" inline="true"/><t id="t2">Bel</t><br id="b8"/><date-mention id="b9" date="2026-06-23" displayFormat="MMM d, yyyy"/><t id="t3">ow</t></p>
</doc>

Update Existing Media And Dates

  • setImageAlt(id, alt) · setImageUrl(id, url)
  • setVideoUrl(id, url) · setVideoControls(id, controls)
  • setDate(id, isoDate, displayFormat?)
editor.setImageAlt('img1', 'dog');
editor.setImageUrl('img1', 'https://x/dog.png');
editor.setVideoUrl('vid1', 'https://x/new.mp4');
editor.setVideoControls('vid1', false);
editor.setDate('date1', '2026-07-01', 'yyyy-MM-dd');

Before:

<doc>
  <image id="img1" version="1" srcType="url" _id="" url="https://x/cat.png" alt="cat"/>
  <video id="vid1" version="1" srcType="url" _id="" url="https://x/old.mp4" controls="true"/>
  <p id="b1"><date-mention id="date1" date="2026-06-23" displayFormat="MMM d"/></p>
</doc>

After:

<doc>
  <image id="img1" version="1" srcType="url" _id="" url="https://x/dog.png" alt="dog"/>
  <video id="vid1" version="1" srcType="url" _id="" url="https://x/new.mp4" controls="false"/>
  <p id="b1"><date-mention id="date1" date="2026-07-01" displayFormat="yyyy-MM-dd"/></p>
</doc>

Mentions

These insert the same @-mention chips the user inserts from the @ menu. Use the ids and details supplied in the task -- do not invent entity ids. Date/time chips do not need a looked-up id.

Existing chips in the document XML look like <user-mention>, <date-mention>, <document-mention>, <agent-session-mention>, <contact-mention>, <group-mention>, <pr-mention>, <booking-link-mention>, <tag-mention>. Leave them intact unless the task asks to change them.

  • insertDate(blockId, at, isoDate, displayFormat?) · mentionDate(...) — time chip. isoDate is ISO 8601; displayFormat is the label on the chip (e.g. 'Mon, Dec 1, 2025', 'Today', '3:00 PM').
  • insertMention(blockId, at, mention)
  • mentionUser(blockId, at, { userId, email })
  • mentionContact(blockId, at, { contactId, name, emailOrDomain, isCompany })
  • mentionGroup(blockId, at, { groupAlias })
  • mentionDocument(blockId, at, { documentId, documentName, blockName, blockParams? }) — documents, channels, chats, folders, projects, tasks, emails, calendar events, skills, calls, automations (blockName is md/channel/chat/project/initiative/task/email/calendar/skill/call/automation/…). A project (initiative) is blockName: 'initiative' with the initiative id as documentId; project is a folder. blockParams is for channel messages (channel_message_id) and calendar occurrences (occurrenceKey).
  • mentionAgentSession(blockId, at, { id, label?, expanded? }) — existing agent session. expanded: true inserts the card that follows the session's latest turn.
  • mentionPullRequest(blockId, at, { id, label? })
  • mentionBookingLink(blockId, at, { profileId, url, slug?, label? }) — Macro booking page (/app/book/{profileId}/{slug?}). Prefer the shareable URL from a booking-link tool.
  • mentionTag(blockId, at, { optionId, propertyDefinitionId, scope, name, color? })
// `at` is a plain-text offset; chips do not increase it. 6 appends after "Email ".
editor.mentionUser('b1', 6, { userId: 'u1', email: '[email protected]' });
editor.mentionContact('b1', 6, { contactId: 'c1', name: 'Acme', emailOrDomain: 'acme.com', isCompany: true });
editor.mentionDate('b1', 6, '2026-07-08T00:00:00.000Z', 'Today');
editor.mentionAgentSession('b1', 6, { id: 'sess-1', label: 'Fix login' });
editor.mentionDocument('b1', 6, { documentId: 'd1', documentName: 'Spec', blockName: 'md' });

Before:

<doc>
  <p id="b1"><t id="t1">Email </t></p>
</doc>

After:

<doc>
  <p id="b1"><t id="t1">Email </t><document-mention id="m5" documentId="d1" name="Spec" blockName="md"/><agent-session-mention id="m4" sessionId="sess-1" label="Fix login"/><date-mention id="m3" date="2026-07-08T00:00:00.000Z" displayFormat="Today"/><contact-mention id="m2" contactId="c1" name="Acme" email="acme.com" isCompany="true"/><user-mention id="m1" userId="u1" email="[email protected]"/></p>
</doc>

Node Specs

  • { block: 'paragraph', text? }
  • { block: 'heading', level, text? }
  • { block: 'quote', text? }
  • { block: 'code', language, text? }
  • { block: 'list', list: 'bullet'|'number'|'check', items: string[] }
  • { block: 'table', rows }
  • { block: 'divider' }
  • { block: 'document-card', documentId, documentName, blockName, blockParams? } where blockParams is Record<string, string>. Use the ids supplied in the task -- do not invent them.
  • { block: 'database-query', query } -- see Databases.
  • { block: 'html-render', html }
  • { block: 'image', srcType, url, alt?, width?, height? }
  • { block: 'video', srcType, url, controls?, width?, height? }
  • { block: 'equation', tex, inline? }
editor.appendBlock({ block: 'heading', level: 2, text: 'Section' });
editor.appendBlock({ block: 'list', list: 'check', items: ['todo a', 'todo b'] });
editor.appendBlock({ block: 'code', language: 'ts', text: 'const x = 1' });

Before:

<doc>
  <p id="b1"><t id="t1">Doc</t></p>
</doc>

After:

<doc>
  <p id="b1"><t id="t1">Doc</t></p>
  <h2 id="b2"><t id="t2">Section</t></h2>
  <ul id="b3" listType="check"><li id="b4"><t id="t3">todo a</t></li><li id="b5" value="2"><t id="t4">todo b</t></li></ul>
  <custom-code id="b6" direction="null" format="" indent="0" version="1" language="ts"><t id="t5">const x = 1</t></custom-code>
</doc>

Databases

The XML shows a saved database question as <database-query queryId displayMode title? prompt chart? height?/>: a live number (displayMode="scalar", inside a paragraph), table, or bar/line/area/scatter/pie chart that re-runs for each viewer. An embedded database is <document-card blockName="database" blockParams='{"tableId":…,"viewId":…}'/>.

  • insertDatabaseQueryAfter(id, query) · insertDatabaseQueryBefore(id, query) · appendDatabaseQuery(query) -- query is the <m-db-query>…</m-db-query> block from the task, passed verbatim as a string. Never write or alter one yourself; without a block in the task, report that one is needed.
  • insertInlineDatabaseQuery(blockId, at, query) -- a scalar block inside a sentence.
  • setDatabaseQueryView(id, { displayMode?, title?, chart?, height? }) -- change how an existing answer is shown; null removes title, chart, or height. The question itself never changes. Chart modes need chart: { x, y: string[], color?, stack?, title? } naming result columns: keep the existing chart's columns unless the task names others. A scalar cannot become a table or chart in place.
  • setDatabaseLocation(cardId, { tableId, viewId? }) -- show another table or view of an embedded database. Use ids from the task or the card's blockParams; an omitted viewId shows the table's default view.
  • Embed a database: { block: 'document-card', documentId: databaseId, documentName, blockName: 'database', blockParams: { tableId, viewId } }.
const chart = editor.insertDatabaseQueryAfter('h1', '<m-db-query>{"queryId":"q1","databaseId":"db1","title":"Deals by stage","prompt":"Deals by stage","displayMode":"bar","chart":{"x":"stage","y":["deals"]}}</m-db-query>');
editor.setDatabaseQueryView(chart, { displayMode: 'pie' });
editor.setDatabaseLocation('card1', { tableId: 'tbl2' });