Modules
A module is a shareable, swappable package of workflows, scripts, and prompts. A workflow step names a slot (workflow_name = "claim-task"), and a bind decides which workflow fills it. The task tracker is the main use today: beads-tasks and github-tasks are two modules that fill the same slots, so switching trackers is a one-file edit.
Module layout
.cloche/modules/github-tasks/
├── module.toml
├── README.md # required
├── tasks.cloche # workflows, including the exported ones
├── scripts/
└── prompts/
module.toml
name = "github-tasks"
description = "Task tracker backed by GitHub Issues (gh)"
exports = ["list-tasks", "claim-task", "close-task", "release-task", "create-task", "update-task"]
requires = ["gh", "jq"] # host binaries; `cloche validate` and `cloche doctor` check them
credentials = ["GH_TOKEN"] # secrets expected in the environment (warning if unset)
uses = [] # slots the module calls but does not provide
Workflows not listed in exports are private. Module workflows are reachable only through a bind; they never collide with project workflow names.
Every module has a README.md with Provides, Inputs and configuration, Prerequisites, and Credentials sections. cloche module add prints the Prerequisites section. Cloche never installs a module’s prerequisites.
Paths
file("prompts/x.md") in a module’s .cloche file resolves against the module root. Every run command of a module workflow gets CLOCHE_MODULE_DIR (the host path on the host, the /workspace/... path in a container), so scripts are called as "$CLOCHE_MODULE_DIR/scripts/x.sh".
Contracts
A workflow can declare what it needs and what it produces:
workflow close-task {
contract {
kv: task_id # required KV key
env: GH_TOKEN # required env var
out: some_key # KV key written when the workflow ends in done
}
...
}
contract is optional. A called workflow’s results are always success (reached done) and fail (reached abort). Inputs are checked before the child starts and out: keys when it ends in done; cloche validate checks compatibility statically.
with
A workflow_name step can remap inputs and outputs:
step review {
workflow_name = "code-review"
with {
task_id from ticket_id // child kv task_id <- caller kv ticket_id
env.MODEL = "opus" // literal into an env var
feedback_path from out.review_path // caller kv <- child's output
}
results = [success, fail]
}
Binds
bind code-review = ruby-review // one bind
bind { // several
list-tasks = beads-tasks
}
bind! lint = standardrb-lint // forced: beats every bind beneath it
The right-hand side is a module name (its export named after the slot), module:workflow, or a project workflow. Scope depends on where the bind sits:
| Position | Covers |
|---|---|
Top level of .cloche/project.cloche |
The project root — the only scope the daemon’s orchestration phases use. project.cloche holds only binds; it is not parsed as a workflow file. |
Top level of another .cloche file |
That file’s workflows |
Inside workflow { } |
That workflow |
Inside step { } |
That call |
Binds are dynamic: the innermost bind wins across nested calls, except bind!. An unbound slot falls back to a project workflow of that name, then a built-in.
Task trackers
The orchestration loop resolves these phases through the root binds in project.cloche:
| Workflow | kv: |
out: |
Notes |
|---|---|---|---|
list-tasks |
— | tasks_path |
A file of task JSONL. Each task may carry repos (the repositories its containers need), priority (0 = most urgent), and labels. |
claim-task |
task_id |
task_title, task_body_path |
Runs before main. A lost claim ends in fail with claim_status = unavailable; the daemon skips the task for the dedup window rather than treating it as an error. |
close-task |
task_id |
— | Also the console’s Close in tracker action. |
release-task |
task_id |
— | Also the console’s Release claim action. |
create-task |
title |
new_task_id |
Optional inputs: body, priority (0–4), labels (comma-separated; priority 0 adds the urgent label), signal_source, signal_key. |
update-task |
action |
task_found |
action = update (needs target_task_id; optional comment, priority, add_labels, remove_labels), find (needs signal_source and signal_key; writes found_task_id), or get (needs target_task_id; writes task_labels and task_status). |
create-task and update-task serve callers outside the loop — signal handling and DRAs — and can be run by hand with cloche tasks create | update | find.
main stays project-owned and reads task_title / task_body_path. Switching trackers is a project.cloche edit:
bind {
list-tasks = github-tasks // was beads-tasks
claim-task = github-tasks
close-task = github-tasks
release-task = github-tasks
create-task = github-tasks
update-task = github-tasks
}
The beads-tasks and github-tasks modules live in the Cloche repository under .cloche/modules/; add one to your project with cloche module add <path-to-module>.
A project with no project.cloche works as before: list-tasks output printed to stdout is still parsed as JSONL, and without a resolvable claim-task phase, main claims the task itself. Both fallbacks are slated for removal in a future minor release.
CLI
cloche module add <git-url>[@ref] | <path> # vendor into .cloche/modules/<name>/, record in modules.lock
cloche module list
cloche module update <name> [<ref>] # shows the diff, asks first
cloche module remove <name>
cloche validate # parse, bind, contract, requires and lockfile-hash checks
Git modules are pinned to a commit in .cloche/modules.lock; local-path modules are used in place. Vendored files are not committed automatically — review and commit them along with modules.lock. Nothing in a module runs at install or update time; review the diff before merging, as for any agent output. See the CLI reference for details.