--- name: tasks-execute description: Use when someone wants an agent to work through an ArchDev Tasks epic — pick ready tasks, lease each one, keep a lease heartbeat running the whole time, implement and verify, commit, push and open a pull request, close, and continue to the next task. Triggers include "work the epic", "execute these tasks", "pick up the next task", "run the plan", or /tasks-execute . --- # Execute an epic Work an ArchDev Tasks epic one task at a time. Each task follows the same loop: ``` pick ready task → claim lease → start heartbeat → work → verify ↑ ↓ next ready task ← close ← stop heartbeat ← comment ← push + PR ← commit ``` Two rules matter more than anything else in this skill: 1. **Never work on a task you have not leased.** The claim is the only ownership gate. A `ready` listing is a snapshot, not ownership. 2. **Never hold a lease without a running heartbeat.** Leases expire (60s to 1h). Without renewal another session can claim the task while you are still editing it, and your commit then lands on work someone else owns. Use the `archdev` CLI for every Tasks operation. Prefer `--json` for output you parse. The CLI is the authority when it disagrees with this file: read `"$archdev" tasks guide` once per session. ## Activity and risk ownership Follow the `archdev` skill for activity reporting. Plan/task lifecycle events retain their `risk.plan` / `risk.task` assessments. Server automation owns hosted PR and code-region grading: report PR events without fetching, waiting for, reusing, or attaching a server grade. No local assessment, annotation or stop hold is required. ## 0. Connect Resolve the absolute directory containing this `SKILL.md` and run its bootstrap. It installs or updates ArchDev when the binary is missing or lacks `tasks heartbeat`; get approval before installing or upgrading software. Capture stdout, which is the executable's absolute path. ```sh archdev="$(bash /absolute/path/to/tasks-execute/scripts/bootstrap.sh)" # Bash/Zsh set archdev (bash /absolute/path/to/tasks-execute/scripts/bootstrap.sh) # Fish $archdev = & powershell -NoProfile -File 'C:\path\to\tasks-execute\scripts\bootstrap.ps1' ``` Then: 1. `"$archdev" auth status`. If signed out, run `"$archdev" auth login` and let the human finish browser sign-in. 2. `"$archdev" tasks guide`. Read it in full. 3. If the `archdev` skill is installed, load it too. It covers lifecycle posts, presence and PR bookkeeping that this skill refers to. ## 1. Pin down the epic and the scope The user names an Epic ID, a display name, or a plan. Resolve its stable `epc_` identity and published members before claiming anything; a Task's `epic` label alone is not first-class membership proof. 1. Confirm the current draft was reviewed and published, and execution is separately authorized. In a Workbench thread, require canonical approval through `task_review_publish` and the current revision's `saved` receipt read with `task_review_save` (a read-only tool, not approval or save). CLI imports, project logs, kickoff metadata, and chat consent do not replace that approval; changed drafts need approval again. If the tools are unavailable, return draft briefs to the thread assistant, not a CLI import. Follow the thread's separate claim or Factory-handoff approval rules; review approval alone is not permission to lease work. 2. Find the owner scope: `--team `, `--user `, or `--org `. Without one, the CLI uses the authenticated organization. If the user did not say and more than one fits, ask. Never guess an ID. 3. Retain the Epic ID and Task IDs from the approved publication receipt or existing plan state. `tasks show ` exposes membership as `task_epic`; `epic` is the visible name or a legacy grouping label. If membership is unavailable or disagrees with the intended Epic, resolve visibility or identity before claiming. Do not infer membership from a matching label or publish another graph to discover an ID. 4. List candidate Tasks, including done work, using the Epic's display name: ```sh "$archdev" --json tasks list --epic "" [--team ] --limit 100 "$archdev" --json tasks ready --explain --epic "" [--team ] ``` These are label filters, not Epic-ID lookups. Page with `--after-cursor` when a page is full. Match candidates to the retained published Task IDs and confirm `task_epic` before choosing work. Reconcile renamed Epics from known member IDs rather than treating an empty name-filtered list as done. Epic editing commands accept the `epc_` ID or an exact unique name; ambiguous names require the ID. Check `archdev epics --help` for supported commands; do not invent an Epic list or show command. 5. Preserve Project membership separately: each Task's `project_id` is stored as `metadata.archdev_project_id`, not on the Epic. Do not move Tasks or rewrite metadata to make an execution list match. For new work, follow the `tasks` skill's existing project lookup and review process. 6. Note which tasks are tagged `human` or `post_deploy`. Do not claim those: a person or a production observation closes them. Report them at the end. 7. Read the repository's agent instructions (`AGENTS.md`, `CLAUDE.md`) before editing. They decide branch, commit, push and test rules. Where they are stricter than this skill, they win. Write a small state file outside the checkout, for example `~/.archdev/task-execute/.json` (`mkdir -p ~/.archdev/task-execute` first), holding the Epic ID, current display name, approved publication revision and Task IDs, scope, and for each claimed task its `task_id`, `lease_id`, `session_id`, `session_name`, and heartbeat log path. Rewrite it on every claim, release and close. It is how you resume after a crash or context reset (§8). It contains no secrets; still keep it out of the repository. ## 2. Pick the next task 1. Re-read readiness every time. Never reuse an old listing: `"$archdev" --json tasks ready --epic "" [scope]`. Recheck published membership and execution authorization from §1; a ready result does not authorize publication, claiming, or scope expansion. 2. Choose the highest-priority ready task (lowest `priority` number), then the oldest. Work one task at a time unless the user asked for parallel workers. 3. Read it fully before claiming: ```sh "$archdev" --json tasks show "$archdev" --json tasks comments --all "$archdev" --json tasks deps list ``` Comments carry pause reasons, human answers and earlier attempts. The description carries the objective, acceptance, verification and the `## Implementation plan`. 4. If the task cannot be done as written (contradiction, missing access, a decision only a human can make), do not claim it. Comment the exact question on the task, tell the user, and pick another ready task. ## 3. Claim the lease ```sh "$archdev" --json tasks claim \ --session-name ":::" \ --harness \ --lease-duration-seconds 300 ``` - The random suffix makes the session name unique, so you can recognise your own lease in `tasks show` later. - Keep `lease.lease_id`, `lease.session_id` and `lease.expires_at` from the response. Write them to the state file before doing anything else. - A conflict error means another session holds the task. Do not retry in a loop and never try to take it over. Pick another ready task. - Go straight to §4. Mark the task in progress and set presence only after the heartbeat is running. ## 4. Start the heartbeat (before any other work) Start the heartbeat immediately after the claim succeeds. Do not read code, plan, or edit anything first. ```sh "$archdev" --json tasks heartbeat \ --lease-id --session-id \ --interval-seconds 60 --lease-duration-seconds 300 ``` It renews the lease every 60s for 300s. It needs native ArchDev Tasks leases and refuses other task backends. It writes one JSON line per event to stdout; errors also go to stderr as plain text: | `event` | Meaning | What you do | |---|---|---| | `renewed` | Lease extended to `expires_at` | Nothing | | `renew_failed` | Transient failure (network, timeout, 5xx, rate limit); still retrying | Watch. Do not commit or close until a `renewed` follows | | `lease_lost` | `reason: "lost"`: the backend refused the lease (expired, held by someone else, or the task is gone). `reason: "expired"`: no renewal succeeded for a full lease duration, so the lease is presumed lost. Exits with **code 3** | **Stop work on this task now** (see below) | | `heartbeat_error` | A request the backend will never accept (signed out, invalid parameters). Exits with **code 1** | Stop work, fix the cause (for example `auth login`), then confirm with `tasks renew` | | `stopped` | You stopped it | Expected before close or release | Then, with the heartbeat running: ```sh "$archdev" --json tasks update --status in_progress \ --lease-id --session-id ``` Set presence only for an accessible **team-owned** task, and only if `"$archdev" presence --help` lists `update`: `"$archdev" presence update --task `. Personal tasks stay private: never publish their IDs through presence. ### Run it so the harness tells you when it dies The heartbeat must keep running in the background for as long as you hold the task, and you must find out when it exits. - **Claude Code:** run it with the Bash tool, `run_in_background: true` and the maximum `timeout` (7200000 ms). Record the background task ID it returns in the state file. The harness re-invokes you when it exits. - Read its output from the output file path the tool returns (for example `tail -n 1 `). Do not read the whole file into context. - Stop it with the harness's stop tool for background tasks (for example `TaskStop` with the recorded ID). - Background runs have a time limit. When the notification says it stopped because of the limit and you still hold the task, restart it straight away with the **same** lease and session IDs. - If a Monitor tool is available, use it as well to watch the output for `lease_lost`, `heartbeat_error` and `renew_failed` lines. - **Codex, Grok and other harnesses:** use the harness's persistent or background process facility if it has one. Otherwise start it detached, with stdout and stderr in separate files so the event log stays JSONL: ```sh mkdir -p "$HOME/.archdev/task-execute" nohup "$archdev" --json tasks heartbeat --lease-id \ --session-id \ >"$HOME/.archdev/task-execute/.heartbeat.jsonl" \ 2>"$HOME/.archdev/task-execute/.heartbeat.err" & echo $! # record this PID in the state file ``` Stop it with `kill ` (SIGTERM). Check `kill -0 ` to see whether it is still alive. ### Check the heartbeat at every gate Before each of these steps, read the newest heartbeat line and confirm the process is alive, the line is `renewed`, and its `at` is within about two intervals (two minutes at the defaults): 1. before the first edit 2. before running long verification 3. before `git commit` 4. before `git push` or opening a PR 5. before `tasks close` If the line is older, the process is gone, or the line is anything other than `renewed`, run the lease-lost steps below. ### When the lease is lost or the heartbeat is dead 1. Stop editing. Do not commit, push or close. 2. Probe ownership with your stored IDs: ```sh "$archdev" --json tasks renew --lease-id --session-id ``` - **It succeeds:** you still hold the task. Restart the heartbeat with the same IDs and continue. - **It fails with a conflict** ("Task lease has expired" or "Task lease does not match the current holder"): your lease is gone. The second message also appears when nobody holds the task, so check: `"$archdev" --json tasks show ` and look at `current_lease`. - **Empty:** claim again with **new** IDs (§3), start a new heartbeat, and check the working tree still matches what you expect before going on. - **Another `session_name`:** someone else owns the task now, and your work on it is no longer authoritative. Comment where your partial work is (branch name, stash tag, or WIP commit SHA), tell the user, and move to another ready task. Never push over the other session's work. - **It fails with an authentication or other error:** fix that first (for example `auth login`), then probe again. ### Rules - One heartbeat per held lease, never zero. - Do not request a long lease (up to 3600s) to avoid running a heartbeat. Use 300s with a 60s interval unless the user says otherwise. Allowed durations are 60 to 3600 seconds. - `--interval-seconds` must be shorter than `--lease-duration-seconds`. Keep it at a third of the duration or less. - Stop the heartbeat only as part of closing (§6) or giving the task back (§7), right before that command, never earlier. ## 5. Do the work 1. Report the start if the `archdev` skill's lifecycle posts are in use: `"$archdev" log post --project --kind start ""`. 2. Before designing anything, search for the closest existing implementation of the behavior and a sibling to copy, even when the task names them. Comment both paths on the task and extend that code. Build nothing for callers that do not exist yet. Before adding a new mechanism (migration, database trigger, lock, OAuth or auth flow, module, service, protocol), write a one-line reason the existing one is insufficient. 3. Follow the task's implementation plan, acceptance and verification. They are the contract. If they turn out to be wrong, comment what you found and why, and adjust within the objective. 4. Decide scope changes yourself, on evidence. Widening means more paths than the brief names, a stronger guarantee than its acceptance states, or a mechanism much larger than its `Size:`. First find the smallest change that stops the problem where it starts. Widen only when you can name the concrete caller, writer, or stored data the smaller change misses, and the cost the larger one adds (hot-path work, triggers, locks, deadlock risk). An invariant worded "every path" is not that evidence. Comment the decision, the evidence, and the cost on the task. 5. Choose the simplest mechanism that meets the acceptance, then prove it. Scale the integration matrix to that mechanism. Never pick a heavier one (triggers, advisory locks, extra connections) to make the proof easier. 6. Record durable progress on the task at real milestones, not every step: `"$archdev" tasks comment ""`. 7. Run the verification the task names: its canonical end-to-end test, focused tests, and the repository's pre-commit gates. A task is not done until they pass, or until the gap is written down on the task with the reason. 8. Two failed attempts on the same failure means change approach, not try a third time. If you are still stuck, use §7. ## 6. Commit, push, open a PR, then close This skill carries each task through to a pull request. Invoking it on an epic is the user's explicit request to **commit, push and open a PR** for each finished task. Skip pushing only when the user said so for this run ("commit only", "don't push"), or when the repository instructions forbid agent pushes; then stop at the commit and say so in the report. Repository instructions still decide the branch, commit format, PR format and whether PRs open ready or as drafts. If they forbid agent commits outright, stop at verified, uncommitted work and ask. 1. Gate check: the heartbeat's newest line is `renewed` (§4). 2. Commit only that task's files, on the branch the repository rules require, using the task title and ID in the message: ``` (): Task: ``` Never bypass hooks (`--no-verify`). If a hook fails, fix the cause. 3. Pick the PR base before pushing: - **The task's prerequisites are merged** (or it has none): branch from the remote default branch (`git fetch origin `, then rebase onto `origin/`) and open the PR against it. - **A prerequisite's PR is still open** and this task builds on its code: stack. Base this branch and the PR on the prerequisite's branch, and put `Merge order: after #` at the top of the PR body. - **A base PR merged while you worked** (its branch is gone, or `gh pr create` says the base is not a branch): rebase only your own commits onto the default branch (`git rebase --onto origin/ `), run a compile/lint check, push with `--force-with-lease`, and open the PR against the default branch. 4. Gate check, then push the branch and open one PR per task. Use the repository's PR template and rules (title, required first line, problem, what changed, testing with the canonical end-to-end proof, risk). Name the task and link it. Never push over someone else's branch. 5. Link the PR to the task and record the result: ```sh "$archdev" tasks links add --type pull_request "$archdev" tasks comment "PR : on . Verified by ." ``` Then run the PR bookkeeping the `archdev` skill requires for any PR head you moved. 6. Do not wait for CI before moving on: CI runs the full suites while you work the next task. Locally, run the focused tests and gates the task names (§5), not every suite. Check the PR's CI when you finish the epic (§9), or sooner if the next task stacks on it, and fix failures on the same branch. When fixing review or risk findings, replacing a mechanism with a smaller one that closes the same defect is a valid fix. Answer a design-level finding by simplifying the design, not by adding another guard layer. 7. Gate check again, then stop the heartbeat and close, fenced with your lease. The last renewal leaves minutes on the lease, which is plenty for the close. Stopping first means the heartbeat never reports your own close as a lost lease. ```sh "$archdev" --json tasks close --lease-id --session-id ``` If the close fails, restart the heartbeat with the same IDs before you retry or investigate. 8. Run `"$archdev" presence clear` if you set presence. Update the state file with the task's PR URL. 9. Go back to §2. Closing a task can make its dependents ready; a dependent that builds on this task's code stacks on its PR (step 3). ## 7. Give a task back When you cannot finish (blocked, needs a human, out of scope, or the user redirects you): 1. Comment the state: what is done, where it lives (branch or SHA), what remains, and the exact question if one exists. 2. Reopen it while still fenced: ```sh "$archdev" --json tasks update --status open --lease-id --session-id ``` 3. Stop the heartbeat, then release: ```sh "$archdev" --json tasks release --lease-id --session-id ``` 4. Run `presence clear` if you set presence, and update the state file. ## 8. Resume after a crash or context reset 1. Read the state file. 2. For each task it lists as held, probe with the stored IDs: `"$archdev" --json tasks renew --lease-id --session-id `. - **Success:** the lease is still yours. Start a heartbeat with the same IDs straight away (§4), then continue. - **Failure:** follow the lease-lost steps in §4. They cover an expired lease, a new owner, and auth errors. 3. Clean up anything the crash left running: a heartbeat PID or background task for a task you no longer hold. 4. Read the task's newest comments before editing, in case someone changed the plan while you were away. ## 9. Finish Stop when the epic has no ready tasks left, when the user stops you, or when a blocker needs them. Before you report, check that no heartbeat is still running for a task you closed or released. Epic completion is derived from its member Tasks; do not manually close an Epic. No ready Tasks may mean blocked, paused, leased, or unpublished work, not completion. Reconcile the published members by retained IDs and report remaining drafts or missing visibility honestly. Required proof Tasks must belong to the Epic and gate rollout through `depends_on`; do not omit them from the completion report because implementation Tasks are done. Report back in this form: 1. **Done:** task, commit SHA, PR link and its CI state, and the verification that proved it. 2. **Given back:** task, why, and the question it needs answered. 3. **Blocked or not started:** task and its blockers, from `tasks ready --explain --epic ""`. 4. **For a human:** tasks tagged `human` or `post_deploy`. 5. **PRs:** every PR opened, its base (stacked or default branch), its merge order, and CI status. Check CI on each before reporting and fix failures on the same branch. If pushing was skipped, say so and list the unpushed branches.