docs/moonbit-ai-tasks-implementation.md
This document captures the task-centric MoonBit implementation added in Flow, where .ai/tasks/*.mbt is the primary extension mechanism.
The implementation adds:
.ai/tasks/tasks the primary interfacerecipe command demoted to compatibility modeCore runtime and wiring:
src/ai_tasks.rssrc/ai_taskd.rssrc/tasks.rssrc/bin/ai_taskd_client.rssrc/palette.rssrc/cli.rssrc/lib.rsLegacy compatibility updates:
src/recipe.rsDocs updates:
docs/commands/tasks.mddocs/commands/recipe.mddocs/commands/readme.mddocs/index.mdxdocs/moonbit-ai-tasks-implementation.mdWorkspace 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:
.mooncakes, _build)// title: ...// description: ...// tags: [a, b]Task resolution accepts:
ai:flow/dev-checkFlow executes AI tasks through a cache-first runtime.
Important execution details:
moon.mod.json / moon.mod)moon build --target native --release)~/Library/Caches/flow/ai-tasks/<hash>/task-binmoon run for tasks without Moon workspace metadataFLOW_AI_TASK_MODE (dev, release, js, etc.)FLOW_AI_TASK_NO_FROZEN is setFLOW_AI_TASK_RUNTIME=moon-runFlow now includes a lightweight Unix-socket daemon for repeated AI task runs:
~/.flow/run/ai-taskd.sockf tasks daemon start|status|stopf tasks run-ai --daemon <selector>./target/release/ai-taskd-client <selector>Recent runtime optimizations:
FLOW_AI_TASKD_DISCOVERY_TTL_MS)FLOW_AI_TASKD_ARTIFACT_TTL_MS).ai/tasks scan for ai:scope/task)fai with auto-preference from f for latency-tagged AI tasks in daemon modeFlow-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.mbtEach task has its own Moon package/workspace files:
.ai/tasks/flow/<task>/moon.mod.json.ai/tasks/flow/<task>/moon.pkg.jsonai: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 pointsFrom ~/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-cli
Optional benchmark controls:
FLOW_BENCH_ITERATIONS=30 FLOW_BENCH_WARMUP=5 f ai:flow/bench-cli
Runtime-path benchmark harness:
f bench-ai-runtime --iterations 80 --warmup 10 --json-out /tmp/flow_ai_runtime_bench.json
You can automate the exact flow:
~/code/myflow).f commit --sync ...).Flow task:
f myflow-commit-session-smoke --help
Common run for ~/code/myflow:
f myflow-commit-session-smoke --repo-path ~/code/myflow --require-sessions
What it checks:
GET /api/commits?repo=<owner>/<repo> contains the target commitsessionWindow metadata--require-sessions is set, commit has sessions.length > 0GET /api/sessions/:id (unless --skip-session-fetch)Auth:
MYFLOW_TOKEN if set~/.config/flow/auth.toml tokencargo 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-sessions
To 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"