Skip to content
GitHub

DevelopOther

@holtkeeper/write-task

Write tasks are agent work that changes code: a change, a fix, a port of a patch, tests. Each task runs as a job of the write-task analyzer on one repository, in a fresh checkout, and ends with a branch and a merge request. Nothing is ever merged.

policy ─► checkout ─► branch ─┬─ patch? ─► git apply -3 ─┬─ applies ─► checks ─┬─ pass ──────────────► commit ─► MR
│ └─ conflict ─┐ └─ fail ─► agent ─► checks ─┘
└─ no patch ─────────────────────────────┴──────────────────► agent ─► checks ─┘
  1. Policy (WriteTaskPolicy, read when the task starts): refused with WriteTaskRefusedError while write tasks are off (the tasks.write setting’s enabled, off by default, switched in Ops › Tasks), when the repository is read-only (repo.freeze: the most specific entry in force freezes it rather than lifting a broader freeze), when commands would run on the worker host unsandboxed (unsandboxed: jobs.execution.mode host; repository scripts the agent may edit run as checks), or when the task has neither prompt nor patch. Once this week’s write task spend reached the weekly cap (weeklyCapReached) the task stops as a budget stop, so the job ends blocked. dryRun does everything but push and open the merge request. noTests ({ reason? }, from repo.tests) marks a repository with no tests by design: detected checks leave out tests and the prompt says not to add tests or test tooling.
  2. Checkout: context.checkout(repo, { ref: targetBranch, writable: true }) gives a private working tree of the target branch (default: the repository’s default branch) and its command runner (mise or container mode). Git credentials never reach the tree: they go to the git processes that talk to the remote only.
  3. Branch: holtkeeper/<task-id>-<slug> (taskBranch), the slug being the title’s first 40 characters in kebab case, made (or reset, git switch -C) from the target branch. Tasks of one group share the task id, so every repository gets the same branch name.
  4. Fast path: a task with a patch tries git apply -3 first. When it applies and the checks pass, no agent runs and the task costs nothing. When it conflicts, the tree is reset and the agent gets the patch to make the same change by hand; when it applies and checks fail, the agent gets the failing output.
  5. Checks (detectChecks): install (bun install --frozen-lockfile, pnpm install --frozen-lockfile, yarn install --immutable or npm ci, from the lockfile), then the typecheck / type-check / tsc, lint, format:check / fmt:check / check:format and test scripts of the root package.json, then the Go checks (below); detectChecks(dir, configured, { tests: false }) (policy noTests) leaves out the test script and go test. options.checks replaces the detection. Checks run with CI=1 and their own env through the checkout’s runner; a failing install stops the rest.
    • Go (detectGoChecks, when the repository has a Go module: the use directories of a root go.work, else every go.mod up to four levels deep, skipping vendor/ and testdata/): gofmt -l over the changed .go files (outside vendor/ and testdata/; passes when none changed, fails when it lists any), go vet and go test. Over a go.work they run once with every module’s pattern (go vet ./a/... ./b/...) and GOTOOLCHAIN=local; otherwise per module (go -C <dir> vet ./... for nested ones) with GOTOOLCHAIN=local and GOFLAGS=-mod=mod, which Go refuses in workspace mode, so a requirement the change needs lands in go.mod / go.sum. When any module has vendor/modules.txt, -mod=mod is left out and Go builds from vendor/ as the repository does, so a new import that is not vendored fails the check instead of committing a go.mod that no longer matches vendor/. Then the linter: the Makefile’s lint target (make lint), or golangci-lint run when a .golangci.yml / .yaml / .toml / .json exists and mise.toml, .mise.toml or .tool-versions provides golangci-lint (the checkout’s toolchain installs it). A lint target whose recipe, direct prerequisites or the variables they use start docker / podman / nerdctl, and a golangci-lint config nothing provides, are skipped with a line in the job log. No go mod tidy check: it needs the module graph from the network and would rarely tell more than go vet.
    • Before every check run of the task (after the patch and after the agent) formatGoFiles runs gofmt -w over the changed .go files, so formatting alone never sends a patch to the agent; the agent may run gofmt -w itself (fixCommands).
  6. Agent (tier main, task kind write-task): read, search, edit and run, where run is limited to the check commands and gofmt -w when the checks run gofmt (also as mise exec -- <command>) plus git status, git diff and git log (AgentTask.commands; shell operators, substitutions and quotes are refused). It gets env (the egress proxy) plus the checks’ own variables (the Go ones above) and nothing secret, maxTurns, maxCostUsd = budgetUsd and the task’s abort signal. It mounts the repos toolset (reposToolset): list_related_repos (the group’s other targets, the family and repositories sharing a config group, through links.related), request_repository (asks people to add a repository to the task’s group through links.requestRepository; nothing happens there in this run), run_checks (the detected checks, optionally by name, with the end of failing output) and open_merge_request (title, description and draft flag for the merge request this workspace opens when the agent is done; it cannot target another repository or branch). It answers { summary, changes, remainingProblems, commitMessage? }. A budget stop (BudgetExceededError) is rethrown, nothing is published and the job ends blocked.
  7. Commit message (chooseCommitMessage): the first of options.commitMessage, the title the agent gave open_merge_request, the agent’s commitMessage and the task title that the repository’s commit conventions accept (@holtkeeper/commit-conventions: setting, push rules, commitlint, history; only error problems count). Else, when titles must be Conventional Commits, the first candidate with a type added (fix for fix tasks, test for tests, else chore). Else the first candidate, with its problems listed in the merge request.
  8. Publish (publishChange): with a signing publisher (a forge SSH key with signing) the checkout commits and pushes over git, signed; otherwise one commit goes through GitForge.commit with the forge credential the worker holds, starting the branch from the target; a branch an earlier run left without an open merge request is deleted first, and with an open one the commit’s actions follow what the branch holds. Only regular files inside the checkout are sent: a symlink or anything else is refused, so a link to a worker file never publishes that file. Then GitForge.createMergeRequest opens a draft (draft, default true; failing checks always make it a draft), or the open merge request of the branch is updated. A draft the agent asked for stays a draft. The description has the task, how the change was made, the agent’s own description (open_merge_request), its summary and remaining problems, a check table and failing output.

The whole task is aborted after timeoutMinutes (default 20, at most 60), besides the worker’s job timeout. The checkout is removed afterwards in every case.

  • createWriteTaskAnalyzer({ policy?, conventions?, env?, links?, onStart? }) → the write-task analyzer: scope repo, pool: 'write' (WRITE_POOL), not exclusive (it works in its own checkout, so a queued task never holds up other jobs of its repository), needs the forge and optionally an agent, no refresh (never automatic). policy(repo) defaults to “off”; conventions(repo) gives the repository’s CommitConventions (failures are ignored); env() is read per task; links (WriteTaskLinks) answers the agent’s list_related_repos and request_repository; onStart(repo, options, jobId) runs first on the worker and stops the task when it throws (the server checks that an approved task queued this very job and marks it running). writeTaskAnalyzer is the copy without server state, which refuses every task.
  • writeTaskAnalysis — analysis kind write-task (WriteTaskData): taskId, title, kind, status (opened, no-changes, dry-run), branch, targetBranch, path (patch, agent, patch+agent), patch? (applied, conflict), files, checks, commit?, mergeRequest? { id, url, draft }, agent? { summary, changes, remainingProblems, turns, costUsd?, transcriptRef? }, group?.
  • writeTaskOptionsSchema (WriteTaskOptions): taskId (lowercase, 4–40 characters), title, prompt?, kind (change, fix, port, tests), patch?, commitMessage?, checks?, budgetUsd (default DEFAULT_TASK_BUDGET_USD = 1.5, at most MAX_TASK_BUDGET_USD = 5), maxTurns (40), timeoutMinutes (20), draft (true), targetBranch?, group?, task? (the stored agent task the job carries out).
  • runWriteTask({ repo, options, policy, forge, checkout, agent?, conventions?, env?, links?, signal?, log?, step? }) — the flow above, for callers outside the job engine and tests.
  • reposToolset({ repo, options, checks, runChecks, links?, branch, targetBranch, onMergeRequest }) — the agent’s repos toolset (RelatedRepo, WriteTaskLinks, MergeRequestRequest).
  • WriteTaskRefusedError, chooseCommitMessage(candidates, conventions, kind), taskBranch(taskId, title), taskSlug(title), WRITE_TASK_KIND, WRITE_POOL.

Only workers that serve the write pool claim write tasks (serve --pool write, see @holtkeeper/jobs); every other worker leaves them in the queue. The Helm chart’s writeWorker deployment is such a pool, with stricter resources and network access only through the egress proxy (deployment). The server queues tasks when a person approves a task group (see @holtkeeper/server), checks the requester’s tasks:run grants and the spend caps, and replaces the registry copy with one that reads tasks.write, repo.freeze, the config’s dryRun, the commit conventions and the egress proxy. Agent runs go through the server’s agent wrapper, so the weekly budget, transcripts and usage records apply as for every other agent run.