diff --git a/src/content/posts/kiln-automation-flow.md b/src/content/posts/kiln-automation-flow.md index 773446e..3d7ab63 100644 --- a/src/content/posts/kiln-automation-flow.md +++ b/src/content/posts/kiln-automation-flow.md @@ -44,6 +44,26 @@ tags: .html-embed .fo .ok{border-style:solid;border-color:var(--accent);color:var(--foreground)} .html-embed .fg{display:grid;grid-template-columns:repeat(auto-fit,minmax(112px,1fr));gap:8px;width:100%} .html-embed .fg .fn{flex:none} +.html-embed .fc .fa.v{position:relative;justify-content:center} +.html-embed .fc .fa.v span{position:absolute;left:calc(50% + 12px);top:50%;transform:translateY(-50%);width:12em} +.html-embed .sg{display:grid;grid-template-columns:minmax(0,1fr) 112px minmax(0,1fr) 112px minmax(0,1fr);align-items:stretch;width:100%} +.html-embed .sg .fn{display:flex;flex-direction:column;justify-content:center} +.html-embed .sg .fa{align-self:center;max-width:none;width:100%;min-width:0;padding:0 8px} +.html-embed .sg .fa.lt i::after{right:auto;left:-2px;border-left:0;border-right:8px solid currentColor} +.html-embed .sg .fa.v{position:relative;justify-self:center;width:auto;padding:6px 0} +.html-embed .sg .fa.v span{position:absolute;right:calc(100% + 10px);top:50%;transform:translateY(-50%);width:8.5em;text-align:right} +.html-embed .sg .fa.up i::after{bottom:auto;top:-2px;border-top:0;border-bottom:8px solid currentColor} +.html-embed .sg .c1{grid-column:1}.html-embed .sg .c2{grid-column:2}.html-embed .sg .c3{grid-column:3}.html-embed .sg .c4{grid-column:4}.html-embed .sg .c5{grid-column:5} +.html-embed .sg .r1{grid-row:1}.html-embed .sg .r2{grid-row:2}.html-embed .sg .r3{grid-row:3} +@media (max-width:640px){ +.html-embed .sg{display:flex;flex-direction:column;align-items:center} +.html-embed .sg .fn{flex:none;width:min(100%,300px)} +.html-embed .sg .fa,.html-embed .sg .fa.v{flex:none;position:relative;width:100%;flex-direction:row;justify-content:center;padding:6px 0} +.html-embed .sg .fa i,.html-embed .sg .fa.v i{width:2px;height:28px} +.html-embed .sg .fa i::after,.html-embed .sg .fa.lt i::after,.html-embed .sg .fa.v i::after{right:auto;top:auto;left:-4px;bottom:-2px;border-top:8px solid currentColor;border-left:5px solid transparent;border-right:5px solid transparent;border-bottom:0} +.html-embed .sg .fa span,.html-embed .sg .fa.v span{position:absolute;left:calc(50% + 12px);right:auto;top:50%;transform:translateY(-50%);width:12em;text-align:left} +.html-embed .sg .fa.up{display:none} +} @media (max-width:640px){ .html-embed .fr{flex-direction:column} .html-embed .fr .fn{flex:none;width:min(100%,300px)} @@ -72,7 +92,7 @@ tags:
一句话:GitHub 只管发事件和收结果;判断、调度、合并、打 tag、发布全在 Kiln 的 Server 里,靠「状态变更和外发消息同一个事务提交」把这些步骤串成一条不会丢步的链。
Server 里 CI 和 AI 是两个分开的领域:表、调度器、通信协议(runner.v1 和 airunner.v2)都不同。它们只在组装文件 server.go 里通过窄接口接线,或者经由共用的 outbox 表传事件。internal/archtest 会在一个领域直接 import 另一个领域、或查询别人的表时让测试失败,这条边界是机器检查的,不只是写在文档里。
PR #10 也是一轮返修(11:41 合并,v1.0.4);PR #11 一次通过审计(12:32 合并,v1.0.5)。从第一个 commit 到公开发布,三个分别用了 36、45 和 13 分钟。
GitHub 把事件 POST 到 /webhook。处理函数用常数时间比较校验 HMAC-SHA256 签名,按 delivery id 去重存进 events 表,然后返回 202,请求里不做别的事。
一个后台循环再逐条处理存下的事件:不在 KILN_ALLOWED_ACCOUNTS 里的账号的安装会被拒绝并卸载;来自 fork 的 PR 一律丢弃,没有开关;同一个 ref 已经有更新事件的旧事件直接跳过。
outbox/worker.go:86 · ci/cicheck/checkrun.go:40 · server.go:390
Kiln 不用 GitHub 的 merge queue,也不需要分支保护。PR 有人加上 kiln:merge 就入队;默认分支上的 .kiln/merge.yml 写了 auto: true 时,required 里的每一项都通过后自动入队。这个配置只从默认分支读,PR 改不了自己的合并门槛。
每个仓库只有一个执行者,持有 Postgres 的 advisory lock。每一轮都重新从 GitHub 读 PR,从头判断:等、更新分支、合并,或者带着原因移出队列。合并请求带上它验证过的 head SHA,head 变了 GitHub 会拒绝。
@@ -137,7 +157,7 @@ tags:审计说明要求做变异验证:在临时副本里把改动的关键逻辑改坏,确认测试会失败。上面表格里两次审计不通过,都是这一类问题。
ai/review/plan.go:135,568 · ai/review/tasktype.go:104,178 · ai/review/publish.go:124
kiln:ready 的 Issue 经 Issues webhook 同步进 dev_pool。In one sentence: GitHub only sends events and receives results; deciding, scheduling, merging, tagging and publishing all happen in Kiln's server, chained together by one habit: every state change commits in the same transaction as the message it causes.
Inside the server, CI and AI are separate domains with different tables, schedulers and wire protocols (runner.v1 and airunner.v2). They meet only in the assembly file server.go, through narrow interfaces, or through events in a shared outbox table. internal/archtest fails the tests if one domain imports another or queries its tables, so the boundary is checked by a machine, not just described in a doc.
PR #10 also took one repair round (merged 11:41, v1.0.4); PR #11 passed review first time (merged 12:32, v1.0.5). From first commit to public release: 36, 45 and 13 minutes.
GitHub posts the event to /webhook. The handler checks the HMAC-SHA256 signature with a constant-time comparison, stores the event in events keyed by delivery id, and returns 202. Nothing else happens in the request.
A background loop then processes stored events one by one. Installations from accounts outside KILN_ALLOWED_ACCOUNTS are rejected and uninstalled; pull requests from forks are always dropped, with no switch to allow them; an event already superseded by a newer one for the same ref is skipped.
outbox/worker.go:86 · ci/cicheck/checkrun.go:40 · server.go:390
Kiln uses neither GitHub's merge queue nor branch protection. A PR enters the queue when someone adds kiln:merge, or automatically once every entry under required has passed, if .kiln/merge.yml on the default branch sets auto: true. That config is read only from the default branch, so a PR cannot lower its own bar.
Each repository has one executor, holding a Postgres advisory lock. Every pass re-reads the PR from GitHub and decides from scratch: wait, update the branch, merge, or remove it with a reason. The merge request carries the head SHA it verified, and GitHub refuses if the head has moved.
@@ -253,7 +273,7 @@ tags:The review brief requires mutation checks: break the changed logic in a scratch copy and confirm a test fails. Both failed reviews in the table above were of that kind.
ai/review/plan.go:135,568 · ai/review/tasktype.go:104,178 · ai/review/publish.go:124
kiln:ready are mirrored into dev_pool from Issues webhooks.一句话:kiln-orca 是一个常驻的用户服务,夹在 Kiln Server 和 Orca 之间。它从 Server 领任务、在 Orca 里开一个一次性的工作区启动 Agent、把每一步写进本地 journal 以便崩溃后接着做;Agent 能做的事只有通过 kiln-orca task 命令问它,git 凭据也是它按每一次传输向 Server 要来、用完就还。
Orca 是一个桌面应用,管 Agent 的工作区(git worktree)、终端和编排(run、dispatch、worker)。Orca 内部怎么分工、要不要拆子 Agent,是它自己的事,Kiln 不管。
kiln-orca 以 macOS LaunchAgent 或 Linux systemd --user 服务运行,一个数据目录就是一个节点。节点注册时用的令牌决定它是审计节点还是开发节点;一台装了 Codex 和 Claude Code 的机器可以同时注册两个节点,各用一个数据目录。
服务启动时,连接器读注册信息和私钥,拿单实例锁,在数据目录的 run/kiln-orca.sock 上开 socket,然后逐项检查:Orca 是否打开、版本是否不低于 1.4.258,Docker 和 Compose 能不能用,随包的 kiln-runner 能不能准备工具链,journal 能不能写,每个 Agent 的 --version,以及 kiln-task skill 是否已同步进 Agent 的 skill 目录。
host/socket.ts:295 · core/attempt.ts:1412-1649 · core/done.ts:138
task exec:每一次 git 传输一枚 tokentask exec -- <命令> 把工具链放到 PATH 最前面,再用 GIT_EXEC_PATH 指向一个镜像目录,其中 git-remote-http(s) 换成了连接器的包装程序,并给任务仓库的主机配上连接器的 credential helper。
每次 git 走 HTTP(S) 时,包装程序先检查这次传输会不会带上别的凭据:地址里有用户名或密码、对这个地址生效的 http.extraHeader、netrc 里出现这个主机或 default,或者这些查不了。有任何一项就拒绝这次传输。都没有时,它经 socket 向连接器开一个只读操作,连接器只在地址正好是任务仓库或声明过的依赖仓库时才向 Server 要 token;连接一断,token 立即吊销。
写权限只在交付时用:连接器自己推 attempt 分支时单独申请一枚写 token,推完就还。Agent 拿不到写凭据。
@@ -163,12 +183,12 @@ tags:In one sentence: kiln-orca is a resident user service between the Kiln server and Orca. It takes tasks from the server, starts an agent in a one-shot Orca worktree, and writes each step to a local journal so it can carry on after a crash; the agent can only act by asking it through the kiln-orca task command, and git credentials are fetched from the server per transfer and handed back when done.
Orca is a desktop app that manages agents' worktrees, terminals and orchestration (runs, dispatches, workers). How Orca divides work inside, and whether it spawns sub-agents, is its own business; Kiln does not care.
kiln-orca runs as a macOS LaunchAgent or a Linux systemd --user service, and one data directory is one node. The token a node enrols with decides whether it is a review node or a development node; a machine with both Codex and Claude Code installed can enrol one of each, each with its own data directory.
On start, the connector reads its enrolment and private key, takes a single-instance lock, opens a socket at run/kiln-orca.sock in the data directory, then checks each dependency: Orca is open and at least version 1.4.258; Docker and Compose work; the bundled kiln-runner can prepare toolchains; the journal is writable; each agent answers --version; and the kiln-task skill is synced into each agent's skills directory.
host/socket.ts:295 · core/attempt.ts:1412-1649 · core/done.ts:138
task exec: one token per git transfertask exec -- <command> puts the toolchain first on PATH, points GIT_EXEC_PATH at a mirror directory where git-remote-http(s) is replaced by the connector's wrapper, and configures the connector's credential helper for the task repository's host.
Each time git goes over HTTP(S), the wrapper first checks whether the transfer would carry some other credential: a user or password in the URL, an http.extraHeader effective for that URL, netrc mentioning the host or default, or any of these being unreadable. Any one of them refuses the transfer. Otherwise it opens a read operation with the connector over the socket, and the connector asks the server for a token only if the URL is exactly the task repository or a declared dependency; when the connection closes, the token is revoked.
Write access is used only for delivery: the connector requests a separate write token for its own push of the attempt branch and returns it right after. The agent never gets a write credential.