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.

4.1 KB
Raw Blame

Code steps: a code step runs TypeScript against Macro's SDK, the same SDK code mode uses. Use code for everything a routine does or decides: labeling or archiving email, setting properties, creating tasks, posting messages, reading many items, loops, and judgments with macro.ai.decide. Usually one code step does all of it. It takes:

  • title: what it does, in a few words. Saving names the step's output after it: "Find open invoices" becomes find_open_invoices. An id you give is kept.
  • summary: one sentence on how, for the routine's owner.
  • knobs: the values its owner may want to change without new code, which the code reads as knobs.<name>: label, channel or people's names, priorities, thresholds, time windows, and the yes/no questions it asks AI. Make a knob for every such constant instead of writing it into the code, never for logic; at most 12, and the code must read every one. Each is { "type", "name", "label", "value" }:
    • name is camelCase (dueWithinDays); label says what it is, in up to 60 characters ("Label for money email").
    • type is text, number (optional min and max), boolean, choice (with options: 2 to 12 strings, value one of them), or question: a yes/no question for macro.ai.decide, its value the question and its label the condition as a short clause that reads inside a sentence ("it's about money").
    • The owner can change any value later, so don't rely on today's.
  • sentence: what the step does, as one plain sentence for its owner (up to 300 characters), with {name} where a knob's value shows and {?name} where a question knob's clause shows: "Label it {moneyLabel} when {?aboutMoney}, and {marketingLabel} when {?aboutMarketing}." Every {…} names one of the step's knobs; question knobs use {?…}. It must say what the code does, no more.
  • source: a module exporting async function main({ macro, run, routine, trigger, steps, knobs }: StepContext). Take only what you use.
    • run.at is when the run counts as happening (ISO 8601) and run.timezone the zone to read it in. Use them for "today", "this week" or a cutoff; never new Date() or Date.now(), so a dry run that replays an earlier trigger gives the same answer.
    • run.lastSucceededAt (null on the first run) and run.previous ({ at, outcome }) say when the routine last ran. Work on what is new since then instead of everything each time.
    • trigger says what started the run: { kind: 'schedule', schedule, timezone }, { kind: 'event', event, item } with the item as JSON (item.entity_id, item.email?.subject, …), or { kind: 'manual', by }. Check trigger.kind before reading item.
    • run.dryRun is true when writes change nothing; routine is { id, name }.
    • steps.<id> is the output of a code step before this one, typed from that step's code. Changing what a step returns can break the steps that read it; every code step is checked with the others.
    • knobs.<name> is a knob's value, typed from the knob: a choice is the union of its options.
  • What main returns is the step's output: JSON (dates become strings) of at most 64 KB. Return only what later steps need, such as ids and counts, not whole items; a larger output fails the step. An Ask AI step after it sees it too.
  • Call SDK methods as their declarations show, with await. Don't import anything.
  • Judge with macro.ai.decide({ input, questions }): questions maps keys to yes/no questions, and probabilities[key] in the answer is from 0 to 1 (treat 0.5 and above as yes). Ask every question about one item in one call. Pass question knobs as the questions: questions: { aboutMoney: knobs.aboutMoney }. Build questions in code only when they come from data, such as one per label the owner has. To pick one of several options (a label, a priority, a person), ask one question per option and take the most likely one that reaches 0.5.
  • Resolve names to ids in code, from the SDK (labels, properties, people, channels), rather than hard-coding ids.
  • The code is type-checked against the SDK; the checker's errors come back, and the step isn't saved until they are fixed. It runs as the owner, within 30 seconds.