@saltpub/agent-autoloop 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.en.md +9 -9
- package/README.md +9 -9
- package/SECURITY.md +1 -1
- package/dist/cli/dashboard/favicon.svg +8 -0
- package/dist/cli/dashboard/index.html +1 -0
- package/dist/cli/dashboard.js +1 -0
- package/dist/cli/main.js +9 -13
- package/dist/cli/runs.js +17 -3
- package/dist/cli/status.js +19 -8
- package/dist/host/runtime.js +13 -3
- package/dist/host/server.js +7 -1
- package/dist/host/service.js +8 -2
- package/dist/host/settle.js +10 -0
- package/dist/host/state.js +36 -20
- package/dist/kernel/decide.js +82 -4
- package/dist/kernel/due.js +2 -0
- package/dist/kernel/evolve.js +3 -0
- package/dist/kernel/http.js +11 -0
- package/dist/kernel/query.js +9 -3
- package/dist/plugins/claude/agent.js +14 -1
- package/dist/plugins/codex/agent.js +14 -1
- package/dist/plugins/delivery/delivery.js +3 -1
- package/dist/plugins/delivery/review-ledger.js +37 -22
- package/dist/plugins/delivery/review-policy.js +2 -12
- package/dist/plugins/delivery/review.js +124 -51
- package/dist/plugins/xiaojiu/channel.js +59 -9
- package/dist/protocol/client.js +6 -0
- package/dist/protocol/rules.js +1 -1
- package/dist/protocol/schema.json +6 -1
- package/dist/protocol/validate.js +19 -2
- package/dist/worker/agents.js +51 -18
- package/dist/worker/worker.js +6 -3
- package/docs/plugins.md +4 -2
- package/docs/protocol.md +12 -7
- package/docs/state-machines.md +2 -2
- package/examples/recipes/feishu-messages/README.md +60 -0
- package/examples/recipes/feishu-messages/SKILL.md +16 -0
- package/examples/recipes/feishu-messages/rules.json +21 -0
- package/examples/recipes/feishu-messages/watch.ts +157 -0
- package/examples/recipes/github-issues/rules.json +6 -1
- package/examples/recipes/github-issues/watch.ts +39 -0
- package/examples/recipes/ops-alerts/README.md +2 -2
- package/examples/recipes/ops-alerts/restart.ts +3 -0
- package/examples/recipes/ops-alerts/rules.json +1 -1
- package/examples/watch-github-issues.sh +3 -22
- package/package.json +1 -1
- package/plugins/claude/agent.ts +15 -1
- package/plugins/codex/agent.ts +14 -1
- package/plugins/delivery/delivery.ts +5 -1
- package/plugins/delivery/review-ledger.ts +46 -24
- package/plugins/delivery/review-policy.ts +2 -14
- package/plugins/delivery/review.ts +158 -56
- package/plugins/xiaojiu/channel.ts +59 -11
- package/skills/agent-autoloop/SKILL.md +23 -9
- package/examples/recipes/ops-alerts/restart.sh +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @saltpub/agent-autoloop
|
|
2
2
|
|
|
3
|
+
## 0.1.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 08c2757: `doctor` 不再把用 API Key 的 Codex 说成「用不了」:`codex login status` 只看存在本机的登录,靠 `OPENAI_API_KEY` 或第三方网关的 `env_key`(如 `CRS_API_KEY`)供密钥时它会说没登录,现在再问一次 `codex doctor`,环境变量给了密钥就算可用。
|
|
8
|
+
- f537233: 中台看板使用「闭环中枢」SVG 图标:深靛蓝回环绕过墨色内核,琥珀色节点标记事件入口,与看板现有配色一致。
|
|
9
|
+
- c2f46a0: 新增 recipe `examples/recipes/feishu-messages/`:常驻脚本用 lark-cli 长连接收飞书私聊消息,只收白名单发送人的文字消息,转成事件发给中台,断线自动重连、投递失败有限重试;附带示例规则、Agent 技能与启用说明(Windows 计划任务与 systemd 都写了)。
|
|
10
|
+
- 3dc6c2a: 合并上游 15 个提交:Claude Code 到用量上限时识别恢复时间、到点前不再派活;规则改组后已在跑的轮次和卡片跟着进新组;改时区后定时按新时区走;重装不再动自建系统级 systemd unit;轮次历史按规则分页读取;worker 能找到登录 shell 才加进 PATH 的程序;失败原因不再从字符中间截断;rules 提前拒绝无效来源插件名;示例轮询脚本改走 Node,Windows 可用
|
|
11
|
+
- c2b3661: 回执里 `notice` 的 `text` 上限从 4000 字放宽到 50000 字:整篇报告可以放进一条通知,不用再拆成多条。`ask` 和其余字段的上限不变。老版本中台收到超过 4000 字的 notice 仍会拒收整份回执:中台和接单程序分开部署时先升中台。
|
|
12
|
+
- 03e7747: rules.json 分多步写入时(编辑器分步保存、工具截断重写),目录监听可能在两次写入之间读到写了一半的内容,误报「rules.json 写错了,还在用旧规则」。现在连续的文件变化会合并在 200 毫秒的窗口内,只按最终内容重载;真正写错的文件照常说。
|
|
13
|
+
- b8d2450: 小九通道发消息先走 `/open/im/v1/messages`,v1 报错时才改用 `/open/im/v2/messages`;两边都失败时失败原因里写明各自的报错。卡片更新仍走 v1。
|
|
14
|
+
- b883940: 小九通道的 `webhook` 新增可选 `forward`:不是本通道所画按钮的回调(`message_receive`、外来卡片的点击)原样转发到该地址,转发失败回 500 让平台重试。一个 bot 只有一个回调地址,同一个 bot 同时给聊天桥(如 xiaojiu-agent-bridge)用时,平台回调指向本通道即可,bridge 侧不用改;不配 `forward` 行为不变。
|
|
15
|
+
|
|
16
|
+
## 0.1.4
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 93378f6: 交付审查把发现分成两级:挡上线(会算错钱、丢数据、越权、发错消息或让发布出事故)要写「处理:」、计入未处理并退回改动,建议只记录;同一类问题合成一条。有挡上线发现的轮次之后,下一轮只核对那几条修好没有、修法有没有带出新的挡上线问题,不再找新的边角,和修法无关的新改动照常审;换审查器或分支改写后整份重审时也核对这几条,上一轮的记录作为资料交给审查器。连续两轮都有挡上线时不再自动审第三轮,交给负责人:放行只认可信账号在第二轮记录写好之后写的 `delivery-owner/<PR 编号>` 成功状态,写在那一轮之前的不算。上一轮挡上线的那个提交不审第二次;之后只改文档或只同步 main 的,下一轮拿整份改动核对那几条,光写「处理:」不算。定时器唤起的轮次里,回答现在指回来源事件而不是 `timer:N`,`why` 里的来龙去脉对得上。
|
|
21
|
+
|
|
3
22
|
## 0.1.3
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/README.en.md
CHANGED
|
@@ -122,7 +122,7 @@ Order checked. We have enough stock in the warehouse.
|
|
|
122
122
|
```
|
|
123
123
|
````
|
|
124
124
|
|
|
125
|
-
Besides `ask`, receipts can send notifications (`notice`), resolve open cards (`resolve`), schedule follow-up checks (`later`), and emit new events (`events`). A notice asks for nothing, but you can add a line of your own when you settle one, and it stays on the card; one marked `fyi` is only there to tell you, and has no button. If the JSON is invalid, the hub has the agent rewrite just that final message in the same session, without repeating completed work. If rewriting also fails, it keeps the original conclusion and tells you the receipt was not applied (a plain command has no session, so it goes straight to this). Going on in an old session works the same way: a new session starts only when the old one can't be continued. If it was continued and then broke partway, the run counts as failed and is retried in that session a few minutes later, not redone in a new one. A new event on the same thread starts a new session by default; with `"resume": true` in the rule it goes on in the last round's session.
|
|
125
|
+
Besides `ask`, receipts can send notifications (`notice`), resolve open cards (`resolve`), schedule follow-up checks (`later`), and emit new events (`events`). A notice asks for nothing, but you can add a line of your own when you settle one, and it stays on the card; one marked `fyi` is only there to tell you, and has no button. If the JSON is invalid, the hub has the agent rewrite just that final message in the same session, without repeating completed work. If rewriting also fails, it keeps the original conclusion and tells you the receipt was not applied (a plain command has no session, so it goes straight to this). Going on in an old session works the same way: a new session starts only when the old one can't be continued. If it was continued and then broke partway, the run counts as failed and is retried in that session a few minutes later, not redone in a new one. A new event on the same thread starts a new session by default; with `"resume": true` in the rule it goes on in the last round's session. When Claude Code hits its subscription usage limit, the hub stops handing it work until the reset time it reported, keeps queued and new events waiting, picks them up again at that time by itself, and tells you once when that will be.
|
|
126
126
|
|
|
127
127
|
## Ready-to-use recipes
|
|
128
128
|
|
|
@@ -149,14 +149,14 @@ More: [Claude-to-Codex browser handoff](examples/recipes/browser-handoff/README.
|
|
|
149
149
|
|
|
150
150
|
Built-in plugins ship with the program and are enabled through configuration. Use `agent-autoloop add <git URL>` for third-party plugins.
|
|
151
151
|
|
|
152
|
-
| Side | Built in
|
|
153
|
-
| --------------------------------- |
|
|
154
|
-
| **Events**: how work is found | [GitHub Webhook](plugins/github/source.ts), [GitLab Webhook](plugins/gitlab/source.ts), [HTTP API](docs/protocol.md#来源把世界变成事件), [cron rules](skills/agent-autoloop/SKILL.md#改规则), [issue polling script](examples/
|
|
155
|
-
| **Agents**: who does the work | [Claude Code](plugins/claude/agent.ts), [Codex](plugins/codex/agent.ts), [OpenCode](plugins/opencode/agent.ts), [pi](plugins/pi/agent.ts), [OMP](plugins/omp/agent.ts), [ACP](plugins/acp/agent.ts), [DeepSeek Harness](plugins/dsh/agent.ts), [ZCode](plugins/zcode/agent.ts), [generic command](plugins/command/agent.ts)
|
|
156
|
-
| **Channels**: how cards reach you | [Desktop notifications](plugins/desktop/channel.ts) (on by default), [Feishu](plugins/feishu/channel.ts), [DingTalk / WeCom / Slack / Discord](plugins/webhook/templates.ts)
|
|
157
|
-
| **Delivery**: CI/CD as a plugin | [`delivery`](plugins/delivery/delivery.ts)
|
|
152
|
+
| Side | Built in | Setup |
|
|
153
|
+
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------ |
|
|
154
|
+
| **Events**: how work is found | [GitHub Webhook](plugins/github/source.ts), [GitLab Webhook](plugins/gitlab/source.ts), [HTTP API](docs/protocol.md#来源把世界变成事件), [cron rules](skills/agent-autoloop/SKILL.md#改规则), [issue polling script](examples/recipes/github-issues/watch.ts) | [Guide](skills/agent-autoloop/SKILL.md#接一个事件插件) |
|
|
155
|
+
| **Agents**: who does the work | [Claude Code](plugins/claude/agent.ts), [Codex](plugins/codex/agent.ts), [OpenCode](plugins/opencode/agent.ts), [pi](plugins/pi/agent.ts), [OMP](plugins/omp/agent.ts), [ACP](plugins/acp/agent.ts), [DeepSeek Harness](plugins/dsh/agent.ts), [ZCode](plugins/zcode/agent.ts), [generic command](plugins/command/agent.ts) | [Guide](skills/agent-autoloop/SKILL.md#接一个-agent) |
|
|
156
|
+
| **Channels**: how cards reach you | [Desktop notifications](plugins/desktop/channel.ts) (on by default), [Feishu](plugins/feishu/channel.ts), [DingTalk / WeCom / Slack / Discord](plugins/webhook/templates.ts) | [Guide](skills/agent-autoloop/SKILL.md#接一个通道) |
|
|
157
|
+
| **Delivery**: CI/CD as a plugin | [`delivery`](plugins/delivery/delivery.ts) | [Guide](skills/agent-autoloop/SKILL.md#交付流水线) |
|
|
158
158
|
|
|
159
|
-
**What has been tested:** Claude Code, Codex, and ACP (with the official Codex ACP adapter) have run multi-turn Q&A and session resumption across processes. OpenCode (2.2.7), pi, and OMP have run multi-turn Q&A, session resumption, and usage reporting. ZCode has run a question, an answer, and the resumed session. Feishu has run real delivery, button callbacks, and card updates. The four webhook templates have only been checked against local mock servers, and the GitLab webhook against the payloads in its docs, not a real GitLab. These text channels answer through a link, so `hub.publicUrl` must be reachable from your phone or computer.
|
|
159
|
+
**What has been tested:** Claude Code, Codex, and ACP (with the official Codex ACP adapter) have run multi-turn Q&A and session resumption across processes. OpenCode (2.2.7), pi, and OMP have run multi-turn Q&A, session resumption, and usage reporting. ZCode has run a question, an answer, and the resumed session. [Agentica](https://github.com/shibing624/agentica) 1.6.1 has run multi-turn Q&A and cross-process session resumption over `use: "acp"`. Feishu has run real delivery, button callbacks, and card updates. The four webhook templates have only been checked against local mock servers, and the GitLab webhook against the payloads in its docs, not a real GitLab. These text channels answer through a link, so `hub.publicUrl` must be reachable from your phone or computer.
|
|
160
160
|
|
|
161
161
|
**Built-in agents through another service.** To send Claude Code or Codex to a third-party model service, or to set environment variables before it starts, write a small script that sets them and starts the program, then put `"program": "/path/to/script"` on the agent. Session resumption and usage reporting still work. See the [guide](skills/agent-autoloop/SKILL.md#接一个-agent).
|
|
162
162
|
|
|
@@ -173,7 +173,7 @@ Built-in plugins ship with the program and are enabled through configuration. Us
|
|
|
173
173
|
|
|
174
174
|
OpenClaw's `agent exec` stops each run after 600 seconds by default, and that counts as a failure; for longer work add `--timeout <seconds>` to the command (`0` means no limit).
|
|
175
175
|
|
|
176
|
-
Agents that speak ACP connect with `use: "acp"` and can go on in the same session: [Gemini CLI](https://geminicli.com/docs/cli/acp-mode/) is `"command": ["gemini", "--acp"]`, [OpenCode](https://opencode.ai/docs/acp) is `"command": ["opencode", "acp"]`, and Antigravity is `"command": ["agy", "acp"]`. Gemini CLI 0.67.0 and OpenCode 1.1.2 answered the ACP handshake; multi-turn Q&A and session resumption have not been run yet. Antigravity (agy 1.5.5) has run both on Windows. OpenCode also has a built-in plugin (`use: "opencode"`, `run --format json`) with session resumption and usage reporting.
|
|
176
|
+
Agents that speak ACP connect with `use: "acp"` and can go on in the same session: [Agentica](https://github.com/shibing624/agentica) 1.6.1 is `"command": ["agentica", "acp"]`, [Gemini CLI](https://geminicli.com/docs/cli/acp-mode/) is `"command": ["gemini", "--acp"]`, [OpenCode](https://opencode.ai/docs/acp) is `"command": ["opencode", "acp"]`, and Antigravity is `"command": ["agy", "acp"]`. Agentica has run multi-turn Q&A and cross-process session resumption (the same `sessionId` via `session/load`); it stores ACP sessions in `~/.agentica/acp/sessions`, overridable with `AGENTICA_ACP_SESSION_DIR`. For a single turn without resumption, `use: "command"` with `["agentica", "--query", "{prompt}", "--print"]` also ran successfully, but reports no usage and keeps no session. Gemini CLI 0.67.0 and OpenCode 1.1.2 answered the ACP handshake; multi-turn Q&A and session resumption have not been run yet. Antigravity (agy 1.5.5) has run both on Windows. OpenCode also has a built-in plugin (`use: "opencode"`, `run --format json`) with session resumption and usage reporting.
|
|
177
177
|
|
|
178
178
|
**Delivery pipeline.** Once delivery rules are configured, the `deliver` label takes a GitHub PR through review, CI, merge, deployment, and live-version verification. Projects can choose reviewers per authoring agent or share a policy. Delivery reads trusted settings from main and reviews a read-only snapshot on the worker.
|
|
179
179
|
|
package/README.md
CHANGED
|
@@ -120,7 +120,7 @@ Agent 结束了这一轮,问了你一个问题。它现在不占进程、不
|
|
|
120
120
|
```
|
|
121
121
|
````
|
|
122
122
|
|
|
123
|
-
除了提问(`ask`),还能发通知(`notice`)、关闭已解决的卡片(`resolve`)、预约复查(`later`)和触发新事件(`events`)。通告不需要回答,但结案时可以顺手写一句处理说明,这句话会留在卡片上;只是告诉一声的通告标成 `fyi`,不带按钮。万一 JSON 写错了,中台只让它在原会话里重写最后这段回复,不会把已经干完的业务重做一遍;重写也失败时,保留原结论并通知你回执没有生效(通用命令没有会话,直接走这一步)。接着旧会话跑也一样:会话接不上才开新的;接上了、干到一半断了,就算没跑成,过几分钟回到原会话重试,不开新会话重做。同一事项的新事件默认开新会话;规则写 `"resume": true` 就接着上一轮的会话。
|
|
123
|
+
除了提问(`ask`),还能发通知(`notice`)、关闭已解决的卡片(`resolve`)、预约复查(`later`)和触发新事件(`events`)。通告不需要回答,但结案时可以顺手写一句处理说明,这句话会留在卡片上;只是告诉一声的通告标成 `fyi`,不带按钮。万一 JSON 写错了,中台只让它在原会话里重写最后这段回复,不会把已经干完的业务重做一遍;重写也失败时,保留原结论并通知你回执没有生效(通用命令没有会话,直接走这一步)。接着旧会话跑也一样:会话接不上才开新的;接上了、干到一半断了,就算没跑成,过几分钟回到原会话重试,不开新会话重做。同一事项的新事件默认开新会话;规则写 `"resume": true` 就接着上一轮的会话。Claude Code 的订阅用量到了上限,中台按它报的恢复时间停止给它派活,排着的和新来的事件都留着,到点自动接着派,并通知你一次几点恢复。
|
|
124
124
|
|
|
125
125
|
## 拿来即用的场景模板
|
|
126
126
|
|
|
@@ -147,14 +147,14 @@ Agent 结束了这一轮,问了你一个问题。它现在不占进程、不
|
|
|
147
147
|
|
|
148
148
|
内置插件随程序安装,填好配置即可启用;第三方插件用 `agent-autoloop add <git 地址>` 安装。
|
|
149
149
|
|
|
150
|
-
| 方向 | 内置
|
|
151
|
-
| ----------------------------- |
|
|
152
|
-
| **事件**:怎么发现新活 | [GitHub Webhook](plugins/github/source.ts)、[GitLab Webhook](plugins/gitlab/source.ts)、[HTTP 接口](docs/protocol.md#来源把世界变成事件)、[定时规则](skills/agent-autoloop/SKILL.md#改规则)、[Issue 轮询脚本](examples/
|
|
153
|
-
| **Agent**:谁来干活 | [Claude Code](plugins/claude/agent.ts)、[Codex](plugins/codex/agent.ts)、[OpenCode](plugins/opencode/agent.ts)、[pi](plugins/pi/agent.ts)、[OMP](plugins/omp/agent.ts)、[ACP](plugins/acp/agent.ts)、[DeepSeek Harness](plugins/dsh/agent.ts)、[ZCode](plugins/zcode/agent.ts)、[通用命令](plugins/command/agent.ts)
|
|
154
|
-
| **通道**:去哪找你拍板 | [桌面通知](plugins/desktop/channel.ts)(默认开启)、[飞书](plugins/feishu/channel.ts)、[钉钉 / 企微 / Slack / Discord](plugins/webhook/templates.ts)
|
|
155
|
-
| **交付**:把 CI/CD 也做成插件 | [`delivery`](plugins/delivery/delivery.ts)
|
|
150
|
+
| 方向 | 内置 | 配置 |
|
|
151
|
+
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
|
|
152
|
+
| **事件**:怎么发现新活 | [GitHub Webhook](plugins/github/source.ts)、[GitLab Webhook](plugins/gitlab/source.ts)、[HTTP 接口](docs/protocol.md#来源把世界变成事件)、[定时规则](skills/agent-autoloop/SKILL.md#改规则)、[Issue 轮询脚本](examples/recipes/github-issues/watch.ts) | [说明](skills/agent-autoloop/SKILL.md#接一个事件插件) |
|
|
153
|
+
| **Agent**:谁来干活 | [Claude Code](plugins/claude/agent.ts)、[Codex](plugins/codex/agent.ts)、[OpenCode](plugins/opencode/agent.ts)、[pi](plugins/pi/agent.ts)、[OMP](plugins/omp/agent.ts)、[ACP](plugins/acp/agent.ts)、[DeepSeek Harness](plugins/dsh/agent.ts)、[ZCode](plugins/zcode/agent.ts)、[通用命令](plugins/command/agent.ts) | [说明](skills/agent-autoloop/SKILL.md#接一个-agent) |
|
|
154
|
+
| **通道**:去哪找你拍板 | [桌面通知](plugins/desktop/channel.ts)(默认开启)、[飞书](plugins/feishu/channel.ts)、[钉钉 / 企微 / Slack / Discord](plugins/webhook/templates.ts) | [说明](skills/agent-autoloop/SKILL.md#接一个通道) |
|
|
155
|
+
| **交付**:把 CI/CD 也做成插件 | [`delivery`](plugins/delivery/delivery.ts) | [说明](skills/agent-autoloop/SKILL.md#交付流水线) |
|
|
156
156
|
|
|
157
|
-
**实测情况:** Claude Code、Codex 和 ACP(官方 Codex ACP 适配器)跑通了多轮问答和跨进程会话续接;OpenCode(2.2.7)、pi 和 OMP 跑通了多轮问答、会话续接和用量统计;ZCode
|
|
157
|
+
**实测情况:** Claude Code、Codex 和 ACP(官方 Codex ACP 适配器)跑通了多轮问答和跨进程会话续接;OpenCode(2.2.7)、pi 和 OMP 跑通了多轮问答、会话续接和用量统计;ZCode 跑通了提问、回答后接回原会话;[Agentica](https://github.com/shibing624/agentica) 1.6.1 用 `use: "acp"` 跑通了多轮问答和跨进程会话续接;飞书跑通了发送、按钮回调和卡片更新;四种 Webhook 模板只在本地模拟服务上验证过,GitLab Webhook 按官方文档的格式测试,没连过真实 GitLab。这些文字通道靠回答链接拍板,要把 `hub.publicUrl` 配成手机或电脑能打开的地址。
|
|
158
158
|
|
|
159
159
|
**内置 Agent 走第三方网关。** Claude Code、Codex 要接第三方模型服务,或者启动前要先设好环境变量,写一个设好变量再启动它的小脚本,在 Agent 里写 `"program": "脚本路径"`,会话续接和用量统计照旧,见[说明](skills/agent-autoloop/SKILL.md#接一个-agent)。
|
|
160
160
|
|
|
@@ -170,7 +170,7 @@ Agent 结束了这一轮,问了你一个问题。它现在不占进程、不
|
|
|
170
170
|
|
|
171
171
|
OpenClaw 的 `agent exec` 每次默认最多跑 600 秒,到点就算失败;要跑更久的,在命令里加 `--timeout <秒>`(`0` 不限时)。
|
|
172
172
|
|
|
173
|
-
会说 ACP 的 Agent 用 `use: "acp"` 接,还能接着原来的会话做:[Gemini CLI](https://geminicli.com/docs/cli/acp-mode/) 写 `"command": ["gemini", "--acp"]`,[OpenCode](https://opencode.ai/docs/acp) 写 `"command": ["opencode", "acp"]`,Antigravity 写 `"command": ["agy", "acp"]`。Gemini CLI 0.67.0 和 OpenCode 1.1.2 已经跑通 ACP
|
|
173
|
+
会说 ACP 的 Agent 用 `use: "acp"` 接,还能接着原来的会话做:[Agentica](https://github.com/shibing624/agentica) 1.6.1 写 `"command": ["agentica", "acp"]`,[Gemini CLI](https://geminicli.com/docs/cli/acp-mode/) 写 `"command": ["gemini", "--acp"]`,[OpenCode](https://opencode.ai/docs/acp) 写 `"command": ["opencode", "acp"]`,Antigravity 写 `"command": ["agy", "acp"]`。Agentica 已跑通多轮问答和跨进程会话续接(同一个 `sessionId` 走 `session/load`);它的 ACP 会话默认放在 `~/.agentica/acp/sessions`,可用 `AGENTICA_ACP_SESSION_DIR` 换目录。只要单轮、不需要会话续接,也可以 `use: "command"` + `["agentica", "--query", "{prompt}", "--print"]`,实测跑通一轮,但没有用量统计和会话续接。Gemini CLI 0.67.0 和 OpenCode 1.1.2 已经跑通 ACP 握手,多轮问答和会话续接还没跑过。Antigravity(agy 1.5.5)在 Windows 上跑通了多轮问答和会话续接。OpenCode 另有内置插件,走 `run --format json`,会话续接和用量统计都有。
|
|
174
174
|
|
|
175
175
|
**交付流水线。** 配好交付规则后,给 GitHub PR 打上 `deliver` 标签后,它会自己跟进到上线:**审代码 → 等 CI → 合并 PR → 等部署 → 核对线上版本**。审查可以按写代码的 Agent 指定,也可以让多个项目共用一份策略。审查和交付配置只从 `main` 读取,绝不在接单电脑上检出或运行 PR 里的代码;排队、并发和重试直接复用内核。
|
|
176
176
|
|
package/SECURITY.md
CHANGED
|
@@ -26,7 +26,7 @@ ACP 的授权依赖 Agent 遵守协议,规范允许它不询问就执行,`ac
|
|
|
26
26
|
|
|
27
27
|
交付只接受规则指定仓库内的分支到 main。项目设置、审查要求、替换审查命令均读 main;PR 只下载 Git 对象,生成文字差异,不检出、不运行 PR 的代码、测试、配置或 hooks;审查看不到内容的章鱼合并直接报问题,不放行。默认 Codex 禁用用户配置与记忆,只读隔离的快照。自定义审查命令由项目管理者负责提供同等权限约束。
|
|
28
28
|
|
|
29
|
-
按写代码的 Agent 定审查器时,来源只认 可信 main 配置(项目的 `review.trusted` 或共用策略的 `trusted_submitters`)列出的 GitHub 账号在该提交上写的 `delivery-agent/<PR 编号>` 状态;PR 说明、标签、分支名,以及其他账号(包括 PR 自己的工作流)写的状态都不算,列了 `agents` 却没有 `trusted`
|
|
29
|
+
按写代码的 Agent 定审查器时,来源只认 可信 main 配置(项目的 `review.trusted` 或共用策略的 `trusted_submitters`)列出的 GitHub 账号在该提交上写的 `delivery-agent/<PR 编号>` 状态;PR 说明、标签、分支名,以及其他账号(包括 PR 自己的工作流)写的状态都不算,列了 `agents` 却没有 `trusted` 的设置不接受。连续两轮审查仍有挡上线问题时,放行同样只认这些账号写的 `delivery-owner/<PR 编号>` 状态。声明是可信账号自己报的,插件不核对改动实际由谁写:能用这个账号写状态的程序都能报任何一个名字。免审的改动只在碰到 `review.xhigh` 的路径或要求只审查时才会被审,所以发信、钱、权限、发布这类路径要写进 `review.xhigh`。
|
|
30
30
|
|
|
31
31
|
审查成功状态只在同一提交的完整检查通过后写入;PR 正文只承载可见的审查记录,实际认可的轮次需要本机 GitHub 登录账号在提交上写入的凭据;处理说明可以编辑;合并前再次核对提交、目标分支、标签和 main,等待检查期间新增 `deliver-review` 也会阻止合并,清标签只成功一部分时重试也不会合并只审查的 PR。项目仍需在 GitHub 配好自身合并规则,插件不能代替平台权限。带 `deliver` 标签的已合并 PR 只继续核实 Ship 与健康版本,不重复合并。健康 URL 默认要求 HTTPS,只有显式测试开关允许 HTTP 127.0.0.1;跳转和不合格的版本不能证明上线。
|
|
32
32
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-labelledby="title">
|
|
2
|
+
<title id="title">中台看板:闭环中枢</title>
|
|
3
|
+
<rect x="1" y="1" width="62" height="62" rx="13" fill="#edeff1" stroke="#c7cdd3"/>
|
|
4
|
+
<path d="M44 15H22a10 10 0 0 0-10 10v14a10 10 0 0 0 10 10h20a10 10 0 0 0 10-10V28" fill="none" stroke="#1d4e89" stroke-width="6" stroke-linecap="round"/>
|
|
5
|
+
<path d="M43 27l9-9 9 9" fill="none" stroke="#1d4e89" stroke-width="6" stroke-linecap="round" stroke-linejoin="round"/>
|
|
6
|
+
<rect x="24" y="24" width="16" height="16" rx="3" fill="#171b1f"/>
|
|
7
|
+
<circle cx="44" cy="15" r="4.5" fill="#a86c15" stroke="#edeff1" stroke-width="2"/>
|
|
8
|
+
</svg>
|
package/dist/cli/dashboard.js
CHANGED
|
@@ -10,6 +10,7 @@ const PAGES = [
|
|
|
10
10
|
["/", "index.html", "text/html; charset=utf-8"],
|
|
11
11
|
["/app.js", "app.js", "text/javascript; charset=utf-8"],
|
|
12
12
|
["/style.css", "style.css", "text/css; charset=utf-8"],
|
|
13
|
+
["/favicon.svg", "favicon.svg", "image/svg+xml; charset=utf-8"],
|
|
13
14
|
];
|
|
14
15
|
/** Starts the page on this machine, pointed at one hub with one owner's key. Port 0 lets the system pick one. */
|
|
15
16
|
export async function startDashboard({ url, key, port, folder = path.join(import.meta.dirname, "dashboard"), }) {
|
package/dist/cli/main.js
CHANGED
|
@@ -11,7 +11,7 @@ import { CONFIG_FILE, readConfig, writeConfig } from "../host/config.js";
|
|
|
11
11
|
import { HOME, RULES_FILE } from "../host/home.js";
|
|
12
12
|
import { findOnPath, psQuote } from "../host/command.js";
|
|
13
13
|
import { privateDirectory } from "../host/files.js";
|
|
14
|
-
import { aboveDesktop, installService, removeService, restartService, runningUp, serviceLogs, serviceRunning, startupInstead, systemUnit, untilAnswering, } from "../host/service.js";
|
|
14
|
+
import { aboveDesktop, installService, leftToSystem, removeService, restartService, runningUp, serviceLogs, serviceRunning, startupInstead, systemUnit, untilAnswering, } from "../host/service.js";
|
|
15
15
|
import { versionLine } from "../host/version.js";
|
|
16
16
|
import { ENTRY as PROGRAM, ROOT } from "../host/program.js";
|
|
17
17
|
import { pointSkill } from "../host/update.js";
|
|
@@ -315,7 +315,7 @@ function commandWords(line) {
|
|
|
315
315
|
/** What was asked for on the command line, or whichever of the usual Agents is installed. */
|
|
316
316
|
async function agentsToUse(named, worker) {
|
|
317
317
|
const agents = {};
|
|
318
|
-
const { adapterFor,
|
|
318
|
+
const { adapterFor, onPath } = await import("../worker/agents.js");
|
|
319
319
|
const command = text(named.command);
|
|
320
320
|
if (command) {
|
|
321
321
|
const words = commandWords(command);
|
|
@@ -325,15 +325,8 @@ async function agentsToUse(named, worker) {
|
|
|
325
325
|
const [first] = words;
|
|
326
326
|
const there = /[\\/]/.test(first)
|
|
327
327
|
? existsSync(path.resolve(first))
|
|
328
|
-
:
|
|
329
|
-
(
|
|
330
|
-
try {
|
|
331
|
-
return Boolean(findProgram(first));
|
|
332
|
-
}
|
|
333
|
-
catch {
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
})();
|
|
328
|
+
: // Where the rule will look, not where a built-in Agent may also look: a rule's command runs in a login shell.
|
|
329
|
+
/^[\w.+@-]+$/.test(first) && Boolean(onPath(first));
|
|
337
330
|
if (!there)
|
|
338
331
|
return fail(`找不到 ${first}:先装好它,或者在 --command 里写它的完整路径。`);
|
|
339
332
|
agents.agent = { name: "Agent", worker, use: "command", command: words };
|
|
@@ -592,8 +585,8 @@ async function runs(args) {
|
|
|
592
585
|
return fail(RUNS_USAGE);
|
|
593
586
|
const before = named.before === undefined ? undefined : runOf(named.before, RUNS_USAGE);
|
|
594
587
|
const owner = ownerClient();
|
|
595
|
-
const {
|
|
596
|
-
const found = await
|
|
588
|
+
const { readRuns, runsText } = await import("./runs.js");
|
|
589
|
+
const found = await readRuns(owner, rest[0], before);
|
|
597
590
|
if (named.json !== undefined)
|
|
598
591
|
return console.log(JSON.stringify({ runs: found.runs, before: found.more }, null, 2));
|
|
599
592
|
const color = colorFor(process.stdout, process.env);
|
|
@@ -994,6 +987,9 @@ async function service(args) {
|
|
|
994
987
|
// Installing over kept data comes here and not to init, and uninstalling took the links away.
|
|
995
988
|
await prepareManagedInstall();
|
|
996
989
|
linkSkill();
|
|
990
|
+
const told = leftToSystem();
|
|
991
|
+
if (told)
|
|
992
|
+
return console.log(told);
|
|
997
993
|
installService();
|
|
998
994
|
return waitForHub();
|
|
999
995
|
}
|
package/dist/cli/runs.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// `agent-autoloop runs`: the finished runs before the few `status` shows, so `why` can be given a number. It pages through
|
|
2
|
-
// /v1/state
|
|
3
|
-
import {
|
|
2
|
+
// /v1/state on older hubs; newer ones can return one rule's finished runs in one request.
|
|
3
|
+
import { HubError } from "../protocol/client.js";
|
|
4
|
+
import { finished, runRows, shellWord } from "./status.js";
|
|
4
5
|
/**
|
|
5
6
|
* Up to `want` finished runs, newest first, older than `before` and of `rule` when given. `more` is where the next list
|
|
6
7
|
* starts, or null when there's nothing older.
|
|
@@ -27,13 +28,26 @@ export async function findRuns(page, { rule, before, want = 20 }) {
|
|
|
27
28
|
cursor = state.nextBefore;
|
|
28
29
|
}
|
|
29
30
|
}
|
|
31
|
+
export async function readRuns(owner, rule, before) {
|
|
32
|
+
if (rule) {
|
|
33
|
+
try {
|
|
34
|
+
const page = await owner.ruleRuns(rule, before);
|
|
35
|
+
return { state: page, runs: page.runs, more: page.nextBefore };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (!(error instanceof HubError && error.status === 404))
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return findRuns(owner.state, { rule, before });
|
|
43
|
+
}
|
|
30
44
|
export function runsText(found, { rule, color, columns }) {
|
|
31
45
|
if (!found.runs.length)
|
|
32
46
|
return rule === undefined ? "还没有做完的轮次。" : `规则「${rule}」没有做完的轮次。`;
|
|
33
47
|
const lines = runRows(found.state, found.runs, { color, columns });
|
|
34
48
|
lines.push("", "细节:agent-autoloop why <第几轮>");
|
|
35
49
|
if (found.more !== null) {
|
|
36
|
-
const named = rule === undefined ? "" : ` ${
|
|
50
|
+
const named = rule === undefined ? "" : ` ${shellWord(rule)}`;
|
|
37
51
|
lines.push(`更早的:agent-autoloop runs${named} --before ${found.more}`);
|
|
38
52
|
}
|
|
39
53
|
return lines.join("\n");
|
package/dist/cli/status.js
CHANGED
|
@@ -10,15 +10,25 @@ const WEEK = ["周日", "周一", "周二", "周三", "周四", "周五", "周
|
|
|
10
10
|
export function clockFor(state) {
|
|
11
11
|
const zone = state.timezone;
|
|
12
12
|
const now = Date.parse(state.now);
|
|
13
|
+
const calendar = new Intl.DateTimeFormat("en-CA", { timeZone: zone });
|
|
14
|
+
const hour = new Intl.DateTimeFormat("zh-CN", {
|
|
15
|
+
timeZone: zone,
|
|
16
|
+
hour: "2-digit",
|
|
17
|
+
minute: "2-digit",
|
|
18
|
+
hourCycle: "h23",
|
|
19
|
+
});
|
|
20
|
+
const short = new Intl.DateTimeFormat("zh-CN", { timeZone: zone, month: "numeric", day: "numeric" });
|
|
13
21
|
const dayOf = (at) => {
|
|
14
|
-
const [y, m, d] =
|
|
22
|
+
const [y, m, d] = calendar.format(at).split("-").map(Number);
|
|
15
23
|
return Date.UTC(y, m - 1, d) / 86_400_000;
|
|
16
24
|
};
|
|
17
|
-
const clock = (at) =>
|
|
25
|
+
const clock = (at) => hour.format(at);
|
|
18
26
|
/** Today's is just the time; yesterday, tomorrow and the coming week by name; further off by date. */
|
|
27
|
+
const today = dayOf(now);
|
|
19
28
|
const when = (iso) => {
|
|
20
29
|
const at = Date.parse(iso);
|
|
21
|
-
const
|
|
30
|
+
const day = dayOf(at);
|
|
31
|
+
const days = day - today;
|
|
22
32
|
if (days === 0)
|
|
23
33
|
return clock(at);
|
|
24
34
|
if (days === -1)
|
|
@@ -26,8 +36,8 @@ export function clockFor(state) {
|
|
|
26
36
|
if (days === 1)
|
|
27
37
|
return `明天 ${clock(at)}`;
|
|
28
38
|
if (days > 1 && days < 7)
|
|
29
|
-
return `${WEEK[new Date(
|
|
30
|
-
const date =
|
|
39
|
+
return `${WEEK[new Date(day * 86_400_000).getUTCDay()]} ${clock(at)}`;
|
|
40
|
+
const date = short.format(at);
|
|
31
41
|
return `${date} ${clock(at)}`;
|
|
32
42
|
};
|
|
33
43
|
const lasted = (iso) => {
|
|
@@ -40,7 +50,7 @@ export function clockFor(state) {
|
|
|
40
50
|
const PLAIN = /^[\p{L}\p{N}_./][\p{L}\p{N}_.#@:/-]*$/u;
|
|
41
51
|
/** A word the user's shell reads back unchanged: single quotes, which neither expands inside, as each shell escapes them.
|
|
42
52
|
* PowerShell also takes the curly single quotes (common in Chinese text) as quotes, so each of those is doubled too. */
|
|
43
|
-
const shellWord = (word, windows) => PLAIN.test(word)
|
|
53
|
+
export const shellWord = (word, windows = process.platform === "win32") => PLAIN.test(word)
|
|
44
54
|
? word
|
|
45
55
|
: windows
|
|
46
56
|
? `'${word.replace(/['\u2018\u2019\u201a\u201b]/g, "$&$&")}'`
|
|
@@ -120,10 +130,11 @@ export function render(state, { color, columns }) {
|
|
|
120
130
|
const whereRoom = Math.max(0, ...presence.map((one) => width(one.where)));
|
|
121
131
|
for (const one of presence) {
|
|
122
132
|
const head = ` ${one.online ? green("●") : red("○")} ${pad(one.name, nameRoom)} `;
|
|
133
|
+
const limited = one.limited ? ` ${yellow(`用量到上限,${when(one.limited.until)} 自动恢复`)}` : "";
|
|
123
134
|
if (one.online)
|
|
124
|
-
say(head + dim(one.where));
|
|
135
|
+
say(head + dim(one.where) + limited);
|
|
125
136
|
else
|
|
126
|
-
say(`${head}${dim(pad(one.where, whereRoom))} ${red(`离线,最后在线 ${one.seenAt ? when(one.seenAt) : "没见过"}`)}`);
|
|
137
|
+
say(`${head}${dim(pad(one.where, whereRoom))} ${red(`离线,最后在线 ${one.seenAt ? when(one.seenAt) : "没见过"}`)}${limited}`);
|
|
127
138
|
}
|
|
128
139
|
const sourceName = (id) => state.sources.find((one) => one.id === id)?.name ?? id;
|
|
129
140
|
const paused = state.lines.filter((line) => line.paused);
|
package/dist/host/runtime.js
CHANGED
|
@@ -7,7 +7,7 @@ import { DatabaseSync } from "node:sqlite";
|
|
|
7
7
|
import { HOME, RULES_FILE } from "./home.js";
|
|
8
8
|
import { privateDirectory } from "./files.js";
|
|
9
9
|
import { COMPILED } from "./program.js";
|
|
10
|
-
import { skippedOf, stateOf as state, viewStatements } from "./state.js";
|
|
10
|
+
import { ruleHistory, skippedOf, stateOf as state, viewStatements } from "./state.js";
|
|
11
11
|
import { cardHash, digest, whose as keyHolder } from "../kernel/credentials.js";
|
|
12
12
|
import { decide } from "../kernel/decide.js";
|
|
13
13
|
import { NotFound } from "../kernel/errors.js";
|
|
@@ -48,6 +48,10 @@ const format = digest([`../kernel/evolve${COMPILED ? ".js" : ".ts"}`, `../kernel
|
|
|
48
48
|
digest(environment.secret));
|
|
49
49
|
let current = openView(db, format);
|
|
50
50
|
db.exec(CARD_HASH_INDEX);
|
|
51
|
+
// Only the history reader needs this index. Adding it to an existing projection doesn't require replaying the log.
|
|
52
|
+
db.exec(`CREATE INDEX IF NOT EXISTS projection_run_history
|
|
53
|
+
ON projections(collection, json_extract(data,'$.rule'), json_extract(data,'$.id'))
|
|
54
|
+
WHERE collection='runs'`);
|
|
51
55
|
export const all = (sql, params = []) => db
|
|
52
56
|
.prepare(sql)
|
|
53
57
|
.all(...params)
|
|
@@ -130,12 +134,18 @@ export const view = (card, ref = null, links = false) => query.cardView(card, en
|
|
|
130
134
|
export const activeRuns = () => Number(one("SELECT count(*) AS n FROM runs WHERE state IN ('queued', 'claimed', 'unknown')")?.n ?? 0);
|
|
131
135
|
export const unrouted = (limit = 20) => query.unrouted(getView(), limit);
|
|
132
136
|
export const skipped = (rule, since, everything = false) => skippedOf(all, rule, since, everything);
|
|
137
|
+
export const runsOfRule = (rule, before) => snapshot(() => ruleHistory(all, rule, before));
|
|
133
138
|
/** Read in one snapshot: its seq is where the log stood for all of it, for a client to go on in /v1/stream from. */
|
|
134
139
|
export function stateOf(now = Date.now(), before) {
|
|
135
|
-
|
|
136
|
-
try {
|
|
140
|
+
return snapshot(() => {
|
|
137
141
|
const latest = getView();
|
|
138
142
|
return { seq: latest.seq, ...state(now, before, query.configuration(latest), { all, view, unrouted }) };
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function snapshot(read) {
|
|
146
|
+
db.exec("BEGIN");
|
|
147
|
+
try {
|
|
148
|
+
return read();
|
|
139
149
|
}
|
|
140
150
|
finally {
|
|
141
151
|
db.exec("COMMIT");
|
package/dist/host/server.js
CHANGED
|
@@ -5,11 +5,14 @@ import { basename, dirname } from "node:path";
|
|
|
5
5
|
import { RULES_FILE } from "./home.js";
|
|
6
6
|
import { loadPlugin } from "./plugins.js";
|
|
7
7
|
import * as hub from "./runtime.js";
|
|
8
|
+
import { settled } from "./settle.js";
|
|
8
9
|
import { AuthError, NotFound } from "../kernel/errors.js";
|
|
9
10
|
import { createHandler } from "../kernel/http.js";
|
|
10
11
|
/** Past this setTimeout fires at once. */
|
|
11
12
|
const LONGEST_TIMER = 2147483647;
|
|
12
13
|
const TICK_RETRY = 5_000;
|
|
14
|
+
// Writers save in steps; the window lets a half-written file become the final one before it is read.
|
|
15
|
+
const WATCH_SETTLE = 200;
|
|
13
16
|
function logStream(after, signal, key) {
|
|
14
17
|
let position = after;
|
|
15
18
|
let unsubscribe = () => { };
|
|
@@ -111,9 +114,10 @@ export function makeHandler(commit = "dev") {
|
|
|
111
114
|
arm();
|
|
112
115
|
});
|
|
113
116
|
// libuv 1.52 (Node 24.16+) on Windows asserts and exits on the first change in a folder named through an 8.3 short name.
|
|
117
|
+
const settle = settled(fire, WATCH_SETTLE);
|
|
114
118
|
const watcher = watch(realpathSync.native(dirname(RULES_FILE)), (_event, file) => {
|
|
115
119
|
if (file === basename(RULES_FILE))
|
|
116
|
-
|
|
120
|
+
settle();
|
|
117
121
|
});
|
|
118
122
|
const handle = createHandler({
|
|
119
123
|
commit,
|
|
@@ -122,6 +126,7 @@ export function makeHandler(commit = "dev") {
|
|
|
122
126
|
environment: hub.environment,
|
|
123
127
|
dispatch: hub.execute,
|
|
124
128
|
state: hub.stateOf,
|
|
129
|
+
ruleRuns: hub.runsOfRule,
|
|
125
130
|
skipped: hub.skipped,
|
|
126
131
|
why: hub.why,
|
|
127
132
|
card: hub.cardByToken,
|
|
@@ -151,6 +156,7 @@ export function makeHandler(commit = "dev") {
|
|
|
151
156
|
close() {
|
|
152
157
|
closed = true;
|
|
153
158
|
clearTimeout(timer);
|
|
159
|
+
settle.cancel();
|
|
154
160
|
watcher.close();
|
|
155
161
|
unlisten();
|
|
156
162
|
wake();
|
package/dist/host/service.js
CHANGED
|
@@ -316,10 +316,16 @@ export function systemUnit() {
|
|
|
316
316
|
return null;
|
|
317
317
|
return spawnSync("systemctl", ["is-active", "--quiet", label()], { stdio: "ignore" }).status === 0 ? label() : null;
|
|
318
318
|
}
|
|
319
|
+
/** A system-level unit running this, and no service of ours: installing one beside it would start a second hub. */
|
|
320
|
+
export function leftToSystem() {
|
|
321
|
+
const name = systemUnit();
|
|
322
|
+
return name && !serviceRunning()
|
|
323
|
+
? `这台电脑用的是系统级服务,运行 systemctl restart ${name} 才会用上新版。`
|
|
324
|
+
: undefined;
|
|
325
|
+
}
|
|
319
326
|
/** New code counts once what's running starts again. What can't be restarted from here is said back, for the owner. */
|
|
320
327
|
export function restartService() {
|
|
321
328
|
if (serviceRunning())
|
|
322
329
|
return void installService();
|
|
323
|
-
|
|
324
|
-
return name ? `这台电脑用的是系统级服务,运行 systemctl restart ${name} 才会用上新版。` : undefined;
|
|
330
|
+
return leftToSystem();
|
|
325
331
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Runs once after calls stop for `window` ms: a file written in steps is read whole, not half-written. */
|
|
2
|
+
export function settled(run, window) {
|
|
3
|
+
let timer;
|
|
4
|
+
const schedule = () => {
|
|
5
|
+
clearTimeout(timer);
|
|
6
|
+
timer = setTimeout(run, window);
|
|
7
|
+
};
|
|
8
|
+
schedule.cancel = () => clearTimeout(timer);
|
|
9
|
+
return schedule;
|
|
10
|
+
}
|
package/dist/host/state.js
CHANGED
|
@@ -16,6 +16,7 @@ const VIEWS = {
|
|
|
16
16
|
seen: "kind name seen_at",
|
|
17
17
|
keys: "kind name hash created_at",
|
|
18
18
|
pauses: "name by reason since until",
|
|
19
|
+
limits: "agent until reason since",
|
|
19
20
|
};
|
|
20
21
|
/** Made anew at every start, so changing them takes no rebuild and no migration. */
|
|
21
22
|
export const viewStatements = Object.entries(VIEWS).map(([table, columns]) => {
|
|
@@ -90,6 +91,36 @@ export function skippedOf(all, rule, since, everything = false) {
|
|
|
90
91
|
const events = all(`${columns} ${SKIPPED_BY} ${order}`, [since, rule, rule]);
|
|
91
92
|
return { count, events: events.map(skippedView) };
|
|
92
93
|
}
|
|
94
|
+
function runView(run, all) {
|
|
95
|
+
return {
|
|
96
|
+
id: run.id,
|
|
97
|
+
rule: run.rule,
|
|
98
|
+
agent: run.agent,
|
|
99
|
+
state: run.state,
|
|
100
|
+
attempts: run.attempts,
|
|
101
|
+
createdAt: run.created_at,
|
|
102
|
+
claimedAt: run.claimed_at,
|
|
103
|
+
finishedAt: run.finished_at,
|
|
104
|
+
notBefore: run.not_before,
|
|
105
|
+
summary: run.summary ?? "",
|
|
106
|
+
error: run.error ?? "",
|
|
107
|
+
link: run.link ?? "",
|
|
108
|
+
session: run.session,
|
|
109
|
+
usage: run.usage ? JSON.parse(run.usage) : null,
|
|
110
|
+
stopping: run.cancel_at !== null,
|
|
111
|
+
manual: Boolean(run.manual),
|
|
112
|
+
events: all(EVENTS_OF_RUN, [run.id]),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export function ruleHistory(all, rule, before) {
|
|
116
|
+
const limit = 20;
|
|
117
|
+
const rows = all(`SELECT * FROM runs WHERE rule = ? AND state NOT IN ('queued', 'claimed') ${before === undefined ? "" : "AND id < ?"}
|
|
118
|
+
ORDER BY id DESC LIMIT ?`, before === undefined ? [rule, limit + 1] : [rule, before, limit + 1]);
|
|
119
|
+
return {
|
|
120
|
+
runs: rows.slice(0, limit).map((run) => runView(run, all)),
|
|
121
|
+
nextBefore: rows.length > limit ? rows[limit - 1].id : null,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
93
124
|
export function stateOf(now, before, rules, { all, view, unrouted }) {
|
|
94
125
|
const seen = new Map(all("SELECT kind, name, seen_at FROM seen").map((row) => [`${row.kind}:${row.name}`, row.seen_at]));
|
|
95
126
|
const presence = (who) => {
|
|
@@ -162,7 +193,10 @@ export function stateOf(now, before, rules, { all, view, unrouted }) {
|
|
|
162
193
|
}),
|
|
163
194
|
agents: Object.entries(rules.agents).map(([id, { name, use, worker, program }]) => {
|
|
164
195
|
const totals = tally(counts.filter((row) => row.agent === id));
|
|
165
|
-
|
|
196
|
+
// Like a pause, one past its end is lifted at the next tick and already holds nothing.
|
|
197
|
+
const limit = all("SELECT until, reason, since FROM limits WHERE agent = ?", [id])[0];
|
|
198
|
+
const limited = limit && Date.parse(limit.until) > now ? limit : null;
|
|
199
|
+
return { id, name, use, worker, ...(program && { program }), ...presence(`worker:${worker}`), totals, limited };
|
|
166
200
|
}),
|
|
167
201
|
channels: Object.entries(rules.channels).map(([id, { name }]) => {
|
|
168
202
|
// Coming back says the channel's program runs, not that a card got through: the last one it was given says that.
|
|
@@ -177,25 +211,7 @@ export function stateOf(now, before, rules, { all, view, unrouted }) {
|
|
|
177
211
|
: undefined;
|
|
178
212
|
return { id, name, ...presence(`channel:${id}`), ...(lastFailure && { lastFailure }) };
|
|
179
213
|
}),
|
|
180
|
-
runs: visible.map((run) => (
|
|
181
|
-
id: run.id,
|
|
182
|
-
rule: run.rule,
|
|
183
|
-
agent: run.agent,
|
|
184
|
-
state: run.state,
|
|
185
|
-
attempts: run.attempts,
|
|
186
|
-
createdAt: run.created_at,
|
|
187
|
-
claimedAt: run.claimed_at,
|
|
188
|
-
finishedAt: run.finished_at,
|
|
189
|
-
notBefore: run.not_before,
|
|
190
|
-
summary: run.summary ?? "",
|
|
191
|
-
error: run.error ?? "",
|
|
192
|
-
link: run.link ?? "",
|
|
193
|
-
session: run.session,
|
|
194
|
-
usage: run.usage ? JSON.parse(run.usage) : null,
|
|
195
|
-
stopping: run.cancel_at !== null,
|
|
196
|
-
manual: Boolean(run.manual),
|
|
197
|
-
events: all(EVENTS_OF_RUN, [run.id]),
|
|
198
|
-
})),
|
|
214
|
+
runs: visible.map((run) => runView(run, all)),
|
|
199
215
|
hasMore,
|
|
200
216
|
nextBefore: hasMore ? page[PAGE - 1].id : null,
|
|
201
217
|
unrouted: unrouted(),
|