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
routine_program
What it is
Routines: the typed program a routine runs. A stored task is either
{"steps": [...], "mcp_servers": [...]} or the single agent task routines used
before steps (AgentTask), which loads as one agent step. Pure data and rules;
no I/O.
Start here
src/model.rs: steps (code and agent, a flat list run in order), the program's recordedsdk,AgentTask, andRoutineProgram::from_task.src/contract.rs: what a code step receives and returns.CODE_STEPS(src/code_steps.md, how to write a code step: the one description CreateRoutine and the scheduler's drafter both read),STEP_CONTEXT(the type ofmain's argument:run,routine,trigger,steps,knobs),code_version(the SDK fingerprint plus a hash ofSTEP_CONTEXT, recorded assdk),assign_step_ids(ids from titles, on save) andcheck_files(each code step's file, withstepstyped from the code steps before it).src/knob.rs:Knobs, a code step's values its owner changes without new code (text, number, boolean, choice, or a question for AI), whichmainreads asknobs.<name>, typed from the knob but not its value; andsentence_slots, the{name}/{?name}slots of a step'ssentence.src/plan.rs:StepRecord, what each step of a run did.src/starters.rs+src/starters/*.ts: starter routines whose step is code, offered by the new-routine flow and shown to the drafter as worked examples. The harness's real-Deno test type-checks each one.src/validate.rs: save-time rules andlimits, including that every knob fits its type and is read by the code, and every sentence slot names one of the step's knobs.
Scope
- Owns: the program's shape, its validation, and the code-step contract.
- Not here: running it →
crates/scheduled_action(program_runner.rs); running and type-checking code →services/agent_harness_service(routine_code.rs, overcrates/code_execution); trigger conditions →scheduled_action'sevent_runs/condition.rs.
Boundaries
- Depends on:
bots(AgentMcpServer). - Used by:
scheduled_action,routines(agent tools), the web app's routines editor, which mirrors the wire shape incore/routine-steps.ts.
Recipes
- Add a limit:
limitsinsrc/validate.rs→ itsProgramError. - Change what
mainreceives:STEP_CONTEXTandcode_steps.md→run_contextinscheduled_action'sprogram_runner.rs. The version changes with it, so every routine's code is checked again before its next run, and rewritten only if that fails.
Checks
cargo test -p routine_program- If the task types changed: regenerate the scheduler spec and SDK (the
schemafeature registersAgentTask,AgentTaskAgentandRoutineModelId).
Gotchas
- There are no branches: code decides inside itself (
macro.ai.decide) and can branch on anything it has read. sdkis bookkeeping the scheduler writes after type-checking; never trust a client's value (scheduled_action::domain::code_check).- Code steps are checked together:
check_filesappends a module-scopedtype StepContextto each file, after its source so diagnostics keep their lines, and a step reads earlier steps' return types by importing their files. A change to one step's return can fail a later step. - A program with
mcp_serversneeds an agent step (AppsWithoutAgent). RoutineModelIdrejects blank models while parsing, so a single agent task with a blank model failsfrom_taskrather than validation.- A single agent task keeps the rules it was saved under:
validate()skips the blank and length limits on its instructions, so stored routines keep running. Adding steps makes it a program, which gets every limit.