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 ─┘- Policy (
WriteTaskPolicy, read when the task starts): refused withWriteTaskRefusedErrorwhile write tasks are off (thetasks.writesetting’senabled, 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.modehost; repository scripts the agent may edit run as checks), or when the task has neitherpromptnorpatch. Once this week’s write task spend reached the weekly cap (weeklyCapReached) the task stops as a budget stop, so the job endsblocked.dryRundoes everything but push and open the merge request.noTests({ reason? }, fromrepo.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. - 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 (miseorcontainermode). Git credentials never reach the tree: they go to the git processes that talk to the remote only. - 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. - Fast path: a task with a
patchtriesgit apply -3first. 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. - Checks (
detectChecks):install(bun install --frozen-lockfile,pnpm install --frozen-lockfile,yarn install --immutableornpm ci, from the lockfile), then thetypecheck/type-check/tsc,lint,format:check/fmt:check/check:formatandtestscripts of the rootpackage.json, then the Go checks (below);detectChecks(dir, configured, { tests: false })(policynoTests) leaves out thetestscript andgo test.options.checksreplaces the detection. Checks run withCI=1and their ownenvthrough the checkout’s runner; a failinginstallstops the rest.- Go (
detectGoChecks, when the repository has a Go module: theusedirectories of a rootgo.work, else everygo.modup to four levels deep, skippingvendor/andtestdata/):gofmt -lover the changed.gofiles (outsidevendor/andtestdata/; passes when none changed, fails when it lists any),go vetandgo test. Over ago.workthey run once with every module’s pattern (go vet ./a/... ./b/...) andGOTOOLCHAIN=local; otherwise per module (go -C <dir> vet ./...for nested ones) withGOTOOLCHAIN=localandGOFLAGS=-mod=mod, which Go refuses in workspace mode, so a requirement the change needs lands ingo.mod/go.sum. When any module hasvendor/modules.txt,-mod=modis left out and Go builds fromvendor/as the repository does, so a new import that is not vendored fails the check instead of committing ago.modthat no longer matchesvendor/. Then the linter: the Makefile’slinttarget (make lint), orgolangci-lint runwhen a.golangci.yml/.yaml/.toml/.jsonexists andmise.toml,.mise.tomlor.tool-versionsprovidesgolangci-lint(the checkout’s toolchain installs it). Alinttarget whose recipe, direct prerequisites or the variables they use startdocker/podman/nerdctl, and a golangci-lint config nothing provides, are skipped with a line in the job log. Nogo mod tidycheck: it needs the module graph from the network and would rarely tell more thango vet. - Before every check run of the task (after the patch and after the agent)
formatGoFilesrunsgofmt -wover the changed.gofiles, so formatting alone never sends a patch to the agent; the agent may rungofmt -witself (fixCommands).
- Go (
- Agent (tier
main, task kindwrite-task):read,search,editandrun, whererunis limited to the check commands andgofmt -wwhen the checks rungofmt(also asmise exec -- <command>) plusgit status,git diffandgit log(AgentTask.commands; shell operators, substitutions and quotes are refused). It getsenv(the egress proxy) plus the checks’ own variables (the Go ones above) and nothing secret,maxTurns,maxCostUsd=budgetUsdand the task’s abort signal. It mounts therepostoolset (reposToolset):list_related_repos(the group’s other targets, the family and repositories sharing a config group, throughlinks.related),request_repository(asks people to add a repository to the task’s group throughlinks.requestRepository; nothing happens there in this run),run_checks(the detected checks, optionally by name, with the end of failing output) andopen_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 endsblocked. - Commit message (
chooseCommitMessage): the first ofoptions.commitMessage, the title the agent gaveopen_merge_request, the agent’scommitMessageand the task title that the repository’s commit conventions accept (@holtkeeper/commit-conventions: setting, push rules, commitlint, history; onlyerrorproblems count). Else, when titles must be Conventional Commits, the first candidate with a type added (fixforfixtasks,testfortests, elsechore). Else the first candidate, with its problems listed in the merge request. - Publish (
publishChange): with a signing publisher (a forge SSH key with signing) the checkout commits and pushes over git, signed; otherwise one commit goes throughGitForge.commitwith 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. ThenGitForge.createMergeRequestopens a draft (draft, defaulttrue; 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.
Public API
Section titled “Public API”createWriteTaskAnalyzer({ policy?, conventions?, env?, links?, onStart? })→ thewrite-taskanalyzer: scoperepo,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, norefresh(never automatic).policy(repo)defaults to “off”;conventions(repo)gives the repository’sCommitConventions(failures are ignored);env()is read per task;links(WriteTaskLinks) answers the agent’slist_related_reposandrequest_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 itrunning).writeTaskAnalyzeris the copy without server state, which refuses every task.writeTaskAnalysis— analysis kindwrite-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(defaultDEFAULT_TASK_BUDGET_USD= 1.5, at mostMAX_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’srepostoolset (RelatedRepo,WriteTaskLinks,MergeRequestRequest).WriteTaskRefusedError,chooseCommitMessage(candidates, conventions, kind),taskBranch(taskId, title),taskSlug(title),WRITE_TASK_KIND,WRITE_POOL.
Where it runs
Section titled “Where it runs”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.