This document captures the task-centric MoonBit implementation added in Flow, where .ai/tasks/*.mbt is the primary extension mechanism.
The implementation adds:
- discovery and execution of AI MoonBit tasks under
.ai/tasks/ - CLI/docs updates to make
tasksthe primary interface - legacy
recipecommand demoted to compatibility mode - a concrete task pack for Flow self-development
Core runtime and wiring:
src/ai_tasks.rssrc/ai_taskd.rssrc/tasks.rssrc/bin/ai_taskd_client.rssrc/palette.rssrc/cli.rssrc/lib.rs
Legacy compatibility updates:
src/recipe.rs
Docs updates:
docs/commands/tasks.mddocs/commands/recipe.mddocs/commands/readme.mddocs/index.mdxdocs/moonbit-ai-tasks-implementation.md
Workspace hygiene:
.gitignore(ignore Moon generated dirs under.ai/tasks/**)
Flow scans .ai/tasks/ recursively for .mbt files and exposes selectors as ai:<path>.
Key behavior in src/ai_tasks.rs:
- ignores generated Moon artifacts during discovery (
.mooncakes,_build) - parses metadata from top comments:
// title: ...// description: ...// tags: [a, b]
- resolves stable task IDs and selectors from path layout
Task resolution accepts:
- full selector:
ai:flow/dev-check - scoped selector forms
- name-based matching with ambiguity detection
Flow executes AI tasks through a cache-first runtime.
Important execution details:
- auto-resolves nearest Moon workspace root (
moon.mod.json/moon.mod) - computes content hash (task source + Moon config + moon version)
- builds native artifact once (
moon build --target native --release) - reuses cached binary from
~/Library/Caches/flow/ai-tasks/<hash>/task-bin - falls back to
moon runfor tasks without Moon workspace metadata - optional mode control via
FLOW_AI_TASK_MODE(dev,release,js, etc.) - default frozen dependency behavior unless
FLOW_AI_TASK_NO_FROZENis set - runtime override via
FLOW_AI_TASK_RUNTIME=moon-run
Flow now includes a lightweight Unix-socket daemon for repeated AI task runs:
- socket:
~/.flow/run/ai-taskd.sock - lifecycle:
f tasks daemon start|status|stop - daemon execution:
f tasks run-ai --daemon <selector> - low-overhead client execution:
./target/release/ai-taskd-client <selector>
Recent runtime optimizations:
- daemon-side task discovery cache with TTL (
FLOW_AI_TASKD_DISCOVERY_TTL_MS) - daemon-side hot artifact reuse cache with TTL (
FLOW_AI_TASKD_ARTIFACT_TTL_MS) - fast exact selector resolution (skip full
.ai/tasksscan forai:scope/task) - cache key generation optimized to use file metadata fingerprints + cached Moon version
- optional low-latency dispatch via
faiwith auto-preference fromffor latency-tagged AI tasks in daemon mode
Flow-local task pack under .ai/tasks/flow/:
.ai/tasks/flow/dev-check/main.mbt.ai/tasks/flow/pr-ready/main.mbt.ai/tasks/flow/regression-smoke/main.mbt.ai/tasks/flow/release-preflight/main.mbt.ai/tasks/flow/bench-cli/main.mbt.ai/tasks/flow/noop/main.mbt
Each task has its own Moon package/workspace files:
.ai/tasks/flow/<task>/moon.mod.json.ai/tasks/flow/<task>/moon.pkg.json
ai:flow/dev-check: fast quality gate (cargo check, targeted tests, CLI help smoke)ai:flow/pr-ready: pre-PR gate (dev-check + docs parity + gitignore hygiene)ai:flow/regression-smoke: temporary project smoke for task discovery/executionai:flow/release-preflight: build release binary and run release-path smoke checksai:flow/bench-cli: quick latency benchmark for high-frequency Flow CLI entry points
From ~/code/flow:
f tasks list
f tasks build-ai ai:flow/dev-check
f tasks run-ai ai:flow/dev-check
f tasks run-ai --daemon ai:flow/dev-check
f tasks daemon start
f tasks daemon status
f tasks daemon stop
f ai:flow/dev-check
f ai:flow/pr-ready
f ai:flow/regression-smoke
f ai:flow/release-preflight
f ai:flow/bench-cliOptional benchmark controls:
FLOW_BENCH_ITERATIONS=30 FLOW_BENCH_WARMUP=5 f ai:flow/bench-cliRuntime-path benchmark harness:
f bench-ai-runtime --iterations 80 --warmup 10 --json-out /tmp/flow_ai_runtime_bench.jsonYou can automate the exact flow:
- Do real Claude/Codex work in a repo (for example
~/code/myflow). - Commit with sync (
f commit --sync ...). - Verify that commit is visible in myflow and has attached sessions.
Flow task:
f myflow-commit-session-smoke --helpCommon run for ~/code/myflow:
f myflow-commit-session-smoke --repo-path ~/code/myflow --require-sessionsWhat it checks:
GET /api/commits?repo=<owner>/<repo>contains the target commit- commit has
sessionWindowmetadata - if
--require-sessionsis set, commit hassessions.length > 0 - first session id is fetchable via
GET /api/sessions/:id(unless--skip-session-fetch)
Auth:
- uses
MYFLOW_TOKENif set - otherwise falls back to
~/.config/flow/auth.tomltoken
cargo check --all-targets
cargo build --release --bin f
f tasks list | rg '^ai:flow/'
f ai:flow/regression-smoke
f myflow-commit-session-smoke --repo-path ~/code/myflow --require-sessionsTo prevent accidental commit noise from Moon caches/build output, Flow ignores:
.ai/tasks/**/.mooncakes/.ai/tasks/**/_build/
When committing this work, scope to the relevant code + docs only:
f commit --path src/ai_tasks.rs \
--path src/tasks.rs \
--path src/palette.rs \
--path src/cli.rs \
--path src/lib.rs \
--path src/recipe.rs \
--path docs/commands/tasks.md \
--path docs/commands/recipe.md \
--path docs/commands/readme.md \
--path docs/moonbit-ai-tasks-implementation.md \
"add task-centric moonbit ai task runtime and flow task pack"