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
# Publishing `container/` in whatever form a sandbox provider wants, then
# booting an agent in it with a prompt - so what runs is our image, not a stock
# one. `.env` next to this justfile (or any parent) can supply
# DAYTONA_API_KEY.
#
# Override the prompt with `just boot-daytona "your prompt"`.
#
# `build-local` builds the same `container/` as a local Docker tag so
# `just run_local` (which sets DEV_DANGEROUS_LOCAL_CONTAINERS) can spawn
# sandboxes without a Daytona account. `run_local` / `stack up` already
# `docker build` the tag with no `--platform` (BuildKit cache no-ops when
# `container/` is unchanged); this recipe is the same unpinned build, so
# Apple Silicon / ARM Linux bake native `aarch64-linux`.
#
# All recipes skip the image build when the image already exists, which is
# wrong whenever `container/` has changed - a stale image is reused silently and
# the failure shows up much later, inside the sandbox. Use `just rebuild-daytona`
# / `build-local --force` after touching the Dockerfile or the sidecar.
set dotenv-load := true
# What the image is called: a Daytona snapshot, and a local Docker tag.
image_name := env_var_or_default("AGENT_HARNESS_IMAGE", "macro-agent-harness")
# Snapshot bake size from sandbox_sizes.json. Override with DAYTONA_SNAPSHOT_*.
snapshot_cpu := env_var_or_default("DAYTONA_SNAPSHOT_CPU", `jq -r .snapshot.cpu sandbox_sizes.json`)
snapshot_memory := env_var_or_default("DAYTONA_SNAPSHOT_MEMORY", `jq -r .snapshot.memoryGib sandbox_sizes.json`)
snapshot_disk := env_var_or_default("DAYTONA_SNAPSHOT_DISK", `jq -r .snapshot.diskGib sandbox_sizes.json`)
# Cheap for the agent to answer, and it proves the repo actually cloned.
default_prompt := "list the files in the repo root, then stop"
# List recipes; first so a bare `just` cannot start an image build
default:
@just --list
# Build the Daytona snapshot if missing. If it exists at the wrong size,
# fail without deleting it (a recreate that 400s on per-sandbox limits
# would leave @coder unable to spawn).
ensure-daytona:
#!/usr/bin/env bash
set -euo pipefail
# Daytona has no "build from a local Dockerfile at create time" mode, so
# the image becomes a snapshot once, out of band, and sandboxes boot from
# that.
name={{image_name}}
cpu={{snapshot_cpu}}
memory={{snapshot_memory}}
disk={{snapshot_disk}}
echo "desired snapshot $name at --cpu $cpu --memory $memory --disk $disk"
snapshot="$(daytona snapshot list --format json | jq -c --arg name "$name" 'first(.[] | select(.name == $name)) // empty')"
if [[ -z "$snapshot" ]]; then
echo "building snapshot $name (slow: the image bakes two nix dev shells)"
# `--context .` keeps paths intact instead of flattening container/.
( cd container && daytona snapshot create "$name" \
--dockerfile Dockerfile \
--context . \
--cpu "$cpu" --memory "$memory" --disk "$disk" )
exit
fi
IFS=$'\t' read -r current_cpu current_memory current_disk < <(
jq -r '[.cpu // 0, .mem // .memory // 0, .disk // 0] | @tsv' <<<"$snapshot"
)
if [[ "$current_cpu/$current_memory/$current_disk" == "$cpu/$memory/$disk" ]]; then
echo "snapshot $name already exists at the desired size, skipping build"
exit
fi
echo "snapshot $name has --cpu $current_cpu --memory $current_memory --disk $current_disk" >&2
echo "expected --cpu $cpu --memory $memory --disk $disk" >&2
echo "not deleting it: recreate with 'just rebuild-daytona' after Daytona raises per-sandbox limits ([email protected])" >&2
exit 1
# Build the Daytona snapshot if missing, then boot an agent in a sandbox
boot-daytona prompt=default_prompt: ensure-daytona
#!/usr/bin/env bash
set -euo pipefail
DAYTONA_SNAPSHOT={{image_name}} cargo run -p agent_harness --bin boot_agent -- daytona {{ quote(prompt) }}
# Delete the Daytona snapshot so the next boot rebuilds it
rebuild-daytona prompt=default_prompt:
#!/usr/bin/env bash
set -euo pipefail
# Deleting is how a rebuild happens: `snapshot create` will not replace an
# existing name.
daytona snapshot delete {{image_name}} || echo "no snapshot {{image_name}} to delete"
# Deletion is asynchronous - the snapshot is still listed for a few seconds
# after the delete returns, and `boot-daytona` would take that as "already
# exists" and reuse the image we just tried to replace.
echo "waiting for the snapshot to disappear"
for _ in $(seq 1 60); do
if ! daytona snapshot list | grep -qw {{image_name}}; then
break
fi
sleep 2
done
if daytona snapshot list | grep -qw {{image_name}}; then
echo "snapshot {{image_name}} is still listed after 120s; not rebuilding" >&2
exit 1
fi
just boot-daytona {{ quote(prompt) }}
# Build the image for the local Docker provider if missing
build-local force="":
#!/usr/bin/env bash
set -euo pipefail
# The same `container/` the Daytona snapshot is built from, so a local
# stack exercises the deployed image rather than an approximation of it.
# Slow on a cold build: the image bakes two nix dev shells.
tag={{image_name}}:latest
if [ -z "{{force}}" ] && docker image inspect "$tag" >/dev/null 2>&1; then
echo "image $tag already exists, skipping build (pass --force to rebuild)"
exit 0
fi
echo "building $tag (native platform; flake has x86_64-linux and aarch64-linux)"
docker build --tag "$tag" container