@saltpub/agent-autoloop 0.1.4 → 0.1.7
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 +33 -0
- package/README.en.md +10 -10
- package/README.md +10 -10
- 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 +44 -2
- package/dist/cli/explain.js +2 -0
- package/dist/cli/main.js +36 -21
- 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 +51 -22
- package/dist/kernel/decide.js +79 -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 +7 -1
- package/dist/plugins/claude/agent.js +14 -1
- package/dist/plugins/codex/agent.js +56 -6
- package/dist/plugins/delivery/project.js +3 -1
- package/dist/plugins/delivery/review.js +7 -4
- package/dist/plugins/feishu/channel.js +44 -6
- package/dist/plugins/xiaojiu/channel.js +59 -9
- package/dist/protocol/client.js +6 -0
- package/dist/protocol/rules.js +2 -1
- package/dist/protocol/schema.json +12 -1
- package/dist/protocol/validate.js +19 -2
- package/dist/worker/agents.js +55 -18
- package/dist/worker/contract.js +1 -0
- package/dist/worker/worker.js +112 -34
- package/docs/plugins.md +4 -2
- package/docs/protocol.md +18 -7
- package/examples/plugins/hello-source/source.ts +4 -3
- 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 +53 -6
- package/plugins/delivery/project.ts +2 -1
- package/plugins/delivery/review.ts +7 -4
- package/plugins/feishu/channel.ts +50 -6
- package/plugins/xiaojiu/channel.ts +59 -11
- package/skills/agent-autoloop/SKILL.md +24 -7
- package/examples/recipes/ops-alerts/restart.sh +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @saltpub/agent-autoloop
|
|
2
2
|
|
|
3
|
+
## 0.1.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a99d4d2: `agent-autoloop dashboard` 在已有看板占着端口时不再报端口占用:再敲一次会认出是本程序的看板,打印地址并打开它(别的程序占着端口仍然报错)。新增 `dashboard --stop` 关掉在跑的看板,不用再找进程杀;看板相应多了 `POST /stop`,只关看板自己,碰不到中台。
|
|
8
|
+
|
|
9
|
+
## 0.1.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- bdc9242: 合并上游修复与规则标签:
|
|
14
|
+
|
|
15
|
+
- 规则可以写可选的 `tags`(文字的列表),中台不解释,原样带进 `/v1/state` 的 `lines`、`runs`、`cards`、`recentCards`、`/v1/runs` 和这条规则每一轮的资料文件。老中台不认识这个字段会拒收规则文件,先升中台再写。
|
|
16
|
+
- worker 轮询只检查还在跑的任务,不再扫历史目录,目录多了也不拖住中台。
|
|
17
|
+
- worker 自身的失败文字按字符截断,不再把半个字留成替换符。
|
|
18
|
+
- Windows 上 Codex 桌面版更新换了安装目录也能找到 `codex`,不再轮轮报找不到。
|
|
19
|
+
- 交付:路径模式末尾整段 `**` 才覆盖它下面的所有文件;审查器提前退出不再把整轮结束掉。
|
|
20
|
+
- 共享用量限制的卡片不再误报已恢复,并说明该试哪条规则。
|
|
21
|
+
- 飞书卡片发不出去时说清原因和下一步(bot 缺权限指向开发者后台),不再贴 lark-cli 的原始 JSON。
|
|
22
|
+
|
|
23
|
+
## 0.1.5
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 08c2757: `doctor` 不再把用 API Key 的 Codex 说成「用不了」:`codex login status` 只看存在本机的登录,靠 `OPENAI_API_KEY` 或第三方网关的 `env_key`(如 `CRS_API_KEY`)供密钥时它会说没登录,现在再问一次 `codex doctor`,环境变量给了密钥就算可用。
|
|
28
|
+
- f537233: 中台看板使用「闭环中枢」SVG 图标:深靛蓝回环绕过墨色内核,琥珀色节点标记事件入口,与看板现有配色一致。
|
|
29
|
+
- c2f46a0: 新增 recipe `examples/recipes/feishu-messages/`:常驻脚本用 lark-cli 长连接收飞书私聊消息,只收白名单发送人的文字消息,转成事件发给中台,断线自动重连、投递失败有限重试;附带示例规则、Agent 技能与启用说明(Windows 计划任务与 systemd 都写了)。
|
|
30
|
+
- 3dc6c2a: 合并上游 15 个提交:Claude Code 到用量上限时识别恢复时间、到点前不再派活;规则改组后已在跑的轮次和卡片跟着进新组;改时区后定时按新时区走;重装不再动自建系统级 systemd unit;轮次历史按规则分页读取;worker 能找到登录 shell 才加进 PATH 的程序;失败原因不再从字符中间截断;rules 提前拒绝无效来源插件名;示例轮询脚本改走 Node,Windows 可用
|
|
31
|
+
- c2b3661: 回执里 `notice` 的 `text` 上限从 4000 字放宽到 50000 字:整篇报告可以放进一条通知,不用再拆成多条。`ask` 和其余字段的上限不变。老版本中台收到超过 4000 字的 notice 仍会拒收整份回执:中台和接单程序分开部署时先升中台。
|
|
32
|
+
- 03e7747: rules.json 分多步写入时(编辑器分步保存、工具截断重写),目录监听可能在两次写入之间读到写了一半的内容,误报「rules.json 写错了,还在用旧规则」。现在连续的文件变化会合并在 200 毫秒的窗口内,只按最终内容重载;真正写错的文件照常说。
|
|
33
|
+
- b8d2450: 小九通道发消息先走 `/open/im/v1/messages`,v1 报错时才改用 `/open/im/v2/messages`;两边都失败时失败原因里写明各自的报错。卡片更新仍走 v1。
|
|
34
|
+
- b883940: 小九通道的 `webhook` 新增可选 `forward`:不是本通道所画按钮的回调(`message_receive`、外来卡片的点击)原样转发到该地址,转发失败回 500 让平台重试。一个 bot 只有一个回调地址,同一个 bot 同时给聊天桥(如 xiaojiu-agent-bridge)用时,平台回调指向本通道即可,bridge 侧不用改;不配 `forward` 行为不变。
|
|
35
|
+
|
|
3
36
|
## 0.1.4
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
package/README.en.md
CHANGED
|
@@ -101,7 +101,7 @@ Changes take effect within seconds of saving. Run `agent-autoloop check` to vali
|
|
|
101
101
|
|
|
102
102
|
### See what's going on
|
|
103
103
|
|
|
104
|
-
`agent-autoloop dashboard` serves a read-only board on this machine (`http://127.0.0.1:3351` by default; `--port` to move it, `--no-open` to keep the browser shut): rules and the last 24 hours on the left, what's coming and what just finished on the right. The four counts on top — running, queued, waiting on you, finished today — open a detail list, and any round opens its full story. It sends only `GET /v1/state`, `GET /v1/stream`, and `GET /v1/runs/<id>/why`, follows the log live, and the hub keeps running if you close it.
|
|
104
|
+
`agent-autoloop dashboard` serves a read-only board on this machine (`http://127.0.0.1:3351` by default; `--port` to move it, `--no-open` to keep the browser shut; run it again while one is up to print the address and open it, `--stop` to close it): rules and the last 24 hours on the left, what's coming and what just finished on the right. The four counts on top — running, queued, waiting on you, finished today — open a detail list, and any round opens its full story. It sends only `GET /v1/state`, `GET /v1/stream`, and `GET /v1/runs/<id>/why`, follows the log live, and the hub keeps running if you close it.
|
|
105
105
|
|
|
106
106
|
### How agents talk back to the hub
|
|
107
107
|
|
|
@@ -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
|
@@ -99,7 +99,7 @@ Agent 结束了这一轮,问了你一个问题。它现在不占进程、不
|
|
|
99
99
|
|
|
100
100
|
### 看现在的情况
|
|
101
101
|
|
|
102
|
-
`agent-autoloop dashboard` 在这台电脑上开一个只读看板(默认 `http://127.0.0.1:3351`,`--port` 换端口,`--no-open`
|
|
102
|
+
`agent-autoloop dashboard` 在这台电脑上开一个只读看板(默认 `http://127.0.0.1:3351`,`--port` 换端口,`--no-open` 不打开浏览器;已经在跑时再敲一次会打印地址并打开它,`--stop` 关掉它):左边是规则和最近 24 小时的时间轴,右边是接下去要跑的、最近跑完的;顶上四个数是“在跑”“排队”“待你”“今天跑完”,点开是明细,点任意一轮能看它的来龙去脉。它只发 `GET /v1/state`、`GET /v1/stream`、`GET /v1/runs/<id>/why` 三个请求,靠日志实时更新,关掉它不影响中台。
|
|
103
103
|
|
|
104
104
|
### Agent 怎么跟中台配合?
|
|
105
105
|
|
|
@@ -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
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
- `access` 由专用 Agent 插件映射到 CLI 权限;`command` 不替任意程序限制权限。普通 Agent 的 `read` 不等于读不到这台电脑上的密钥。要隔离密钥,用单独的系统账号或容器。
|
|
15
15
|
- 普通访问密钥只存 SHA-256,另有本机 `master.key` 推导轮次和卡片链接的 token。`master.key` 为空或不完整时中台拒绝启动,不会拿它签链接,也不会自己换一把新的。接单程序不通过提示词、资料或环境变量传递中台凭据;同一系统账号下能读哪些文件仍由 Agent 沙箱决定。回执能影响的范围见 `docs/protocol.md`。
|
|
16
16
|
- 卡片链接谁拿到谁就能回答这一张卡片,从卡片创建起 7 天内有效,过期后也不再显示卡片内容,只发给配了 `"links": true` 的通道。
|
|
17
|
-
- `agent-autoloop dashboard` 只听 127.0.0.1,只把 `/v1/state`、`/v1/stream`、`/v1/runs/<id>/why` 连同本人密钥转给中台,密钥不进页面;只认发给 `127.0.0.1:<端口>` 和 `localhost:<端口>`
|
|
17
|
+
- `agent-autoloop dashboard` 只听 127.0.0.1,只把 `/v1/state`、`/v1/stream`、`/v1/runs/<id>/why` 连同本人密钥转给中台,密钥不进页面;只认发给 `127.0.0.1:<端口>` 和 `localhost:<端口>` 的请求,别的主机名(包括被解析到本机的域名)一律拒绝;除 `POST /stop`(只关掉看板自己,碰不到中台和本机别的任何东西)外别的方法一律拒绝。它只读,不写日志、不回答问题。
|
|
18
18
|
- 本项目只启动你自己安装、自己登录的官方命令行工具,不接触、不保存、不中转它们的登录凭据。
|
|
19
19
|
- 浏览器能力由 Agent 自己的工具配置提供;专用入口只从可信规则或 Skill 取得,不从事件正文取命令。中台不自动授予浏览器权限或接管桌面会话。需本人恢复的连接或验证用 `ask` 交回,保留未验收项。
|
|
20
20
|
|
|
@@ -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"), }) {
|
|
@@ -17,6 +18,7 @@ export async function startDashboard({ url, key, port, folder = path.join(import
|
|
|
17
18
|
const pages = new Map(PAGES.map(([route, file, type]) => [route, { body: readFileSync(path.join(folder, file)), type }]));
|
|
18
19
|
const owner = { authorization: `Bearer ${key}` };
|
|
19
20
|
let allowed = new Set();
|
|
21
|
+
const stopping = Promise.withResolvers();
|
|
20
22
|
async function forward(answer, address) {
|
|
21
23
|
const upstream = await fetch(address, { headers: owner });
|
|
22
24
|
if (!upstream.ok)
|
|
@@ -49,9 +51,14 @@ export async function startDashboard({ url, key, port, folder = path.join(import
|
|
|
49
51
|
async function serve(request, answer) {
|
|
50
52
|
if (!allowed.has(request.headers.host ?? ""))
|
|
51
53
|
return send(answer, 403, { error: "这个地址不是本机的看板" });
|
|
54
|
+
const here = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
55
|
+
// The one thing past read-only: it stops the board itself, and nothing behind it.
|
|
56
|
+
if (here.pathname === "/stop" && request.method === "POST") {
|
|
57
|
+
send(answer, 200, { stopped: true });
|
|
58
|
+
return stopping.resolve();
|
|
59
|
+
}
|
|
52
60
|
if (request.method !== "GET" && request.method !== "HEAD")
|
|
53
61
|
return send(answer, 405, { error: "看板只读" });
|
|
54
|
-
const here = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
55
62
|
const page = pages.get(here.pathname);
|
|
56
63
|
if (page) {
|
|
57
64
|
answer.writeHead(200, { "content-type": page.type, "cache-control": "no-store" });
|
|
@@ -71,6 +78,8 @@ export async function startDashboard({ url, key, port, folder = path.join(import
|
|
|
71
78
|
return send(answer, 404, { error: "看板没有这个地址" });
|
|
72
79
|
}
|
|
73
80
|
const server = createServer((request, answer) => {
|
|
81
|
+
// Every answer carries the board's name, so a rerun of the command can tell it from a stranger on the same port.
|
|
82
|
+
answer.setHeader("x-agent-autoloop", "dashboard");
|
|
74
83
|
serve(request, answer).catch((error) => send(answer, 502, { error: error.message }));
|
|
75
84
|
});
|
|
76
85
|
const listening = Promise.withResolvers();
|
|
@@ -78,10 +87,43 @@ export async function startDashboard({ url, key, port, folder = path.join(import
|
|
|
78
87
|
server.listen(port, "127.0.0.1", () => {
|
|
79
88
|
const bound = server.address().port;
|
|
80
89
|
allowed = new Set([`127.0.0.1:${bound}`, `localhost:${bound}`]);
|
|
81
|
-
listening.resolve({
|
|
90
|
+
listening.resolve({
|
|
91
|
+
url: `http://127.0.0.1:${bound}/`,
|
|
92
|
+
// The page holds a live stream open; without cutting those sockets close() would wait on them forever.
|
|
93
|
+
close: () => {
|
|
94
|
+
server.closeAllConnections();
|
|
95
|
+
server.close();
|
|
96
|
+
},
|
|
97
|
+
stopped: stopping.promise,
|
|
98
|
+
});
|
|
82
99
|
});
|
|
83
100
|
return listening.promise;
|
|
84
101
|
}
|
|
102
|
+
/** The address of the board already on this port, or null when the port is free or belongs to something else. */
|
|
103
|
+
export async function probeDashboard(port) {
|
|
104
|
+
try {
|
|
105
|
+
const answer = await fetch(`http://127.0.0.1:${port}/`, { signal: AbortSignal.timeout(2000) });
|
|
106
|
+
await answer.body?.cancel();
|
|
107
|
+
return answer.headers.get("x-agent-autoloop") === "dashboard" ? `http://127.0.0.1:${port}/` : null;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** Asks the board on this port to close. True only when a board said yes; a stranger's server is left alone. */
|
|
114
|
+
export async function stopDashboard(port) {
|
|
115
|
+
try {
|
|
116
|
+
const answer = await fetch(`http://127.0.0.1:${port}/stop`, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
signal: AbortSignal.timeout(2000),
|
|
119
|
+
});
|
|
120
|
+
await answer.body?.cancel();
|
|
121
|
+
return answer.headers.get("x-agent-autoloop") === "dashboard" && answer.ok;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
85
127
|
function send(answer, status, body) {
|
|
86
128
|
if (answer.headersSent)
|
|
87
129
|
return answer.end();
|
package/dist/cli/explain.js
CHANGED
|
@@ -20,6 +20,8 @@ function details(rule, rules, now) {
|
|
|
20
20
|
parts.push("接着上一轮的会话");
|
|
21
21
|
if (rule.title)
|
|
22
22
|
parts.push(`会话标题 ${rule.title}`);
|
|
23
|
+
if (rule.tags?.length)
|
|
24
|
+
parts.push(`标签 ${rule.tags.join("、")}`);
|
|
23
25
|
if (rule.group !== rule.name)
|
|
24
26
|
parts.push(`组 ${rule.group}`);
|
|
25
27
|
if (rule.tell !== "needed")
|
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";
|
|
@@ -118,12 +118,13 @@ const STATUS_USAGE = `用法:agent-autoloop status [--json]
|
|
|
118
118
|
|
|
119
119
|
现在什么情况:谁在线、等你什么、在做什么、做过什么、花了多少。
|
|
120
120
|
--json 输出 /v1/state 的原始结构,给脚本和看板用`;
|
|
121
|
-
const DASHBOARD_USAGE = `用法:agent-autoloop dashboard [--port 3351] [--no-open]
|
|
121
|
+
const DASHBOARD_USAGE = `用法:agent-autoloop dashboard [--port 3351] [--no-open] [--stop]
|
|
122
122
|
|
|
123
123
|
在这台电脑上打开看板:最近 24 小时的轨道、每条规则、在跑和排着的活、等你决定的卡片。
|
|
124
|
-
只读;回答卡片仍然走通道或 agent-autoloop answer
|
|
124
|
+
只读;回答卡片仍然走通道或 agent-autoloop answer。已经在跑时再敲一次会打印地址并打开它。
|
|
125
125
|
--port 看板占用的端口,默认 3351
|
|
126
|
-
--no-open
|
|
126
|
+
--no-open 不发开浏览器,只打印地址
|
|
127
|
+
--stop 关掉这个端口上在跑的看板`;
|
|
127
128
|
const RUNS_USAGE = `用法:agent-autoloop runs [规则] [--before <第几轮>] [--json]
|
|
128
129
|
|
|
129
130
|
列出做完的轮次,新的在前,一次 20 轮:编号、结束时间、怎么样了、规则和结果。
|
|
@@ -186,7 +187,7 @@ rules.json 里这个定时任务要写 cwd;你答了,中台叫醒它的 Agen
|
|
|
186
187
|
runs: { flags: ["before", "json"], usage: RUNS_USAGE },
|
|
187
188
|
run: { flags: ["subject", "reason"], usage: "用法:agent-autoloop run <规则> [--subject 对象] [--reason 说明]" },
|
|
188
189
|
service: { flags: [], usage: "用法:agent-autoloop service install|remove" },
|
|
189
|
-
dashboard: { flags: ["port", "no-open"], usage: DASHBOARD_USAGE },
|
|
190
|
+
dashboard: { flags: ["port", "no-open", "stop"], usage: DASHBOARD_USAGE },
|
|
190
191
|
status: { flags: ["json"], usage: STATUS_USAGE },
|
|
191
192
|
stop: { flags: [], usage: "用法:agent-autoloop stop <第几轮>" },
|
|
192
193
|
tell: { flags: ["task"], usage: "用法:agent-autoloop tell <编号> [--task 定时任务名],内容从标准输入读" },
|
|
@@ -315,7 +316,7 @@ function commandWords(line) {
|
|
|
315
316
|
/** What was asked for on the command line, or whichever of the usual Agents is installed. */
|
|
316
317
|
async function agentsToUse(named, worker) {
|
|
317
318
|
const agents = {};
|
|
318
|
-
const { adapterFor,
|
|
319
|
+
const { adapterFor, onPath } = await import("../worker/agents.js");
|
|
319
320
|
const command = text(named.command);
|
|
320
321
|
if (command) {
|
|
321
322
|
const words = commandWords(command);
|
|
@@ -325,15 +326,8 @@ async function agentsToUse(named, worker) {
|
|
|
325
326
|
const [first] = words;
|
|
326
327
|
const there = /[\\/]/.test(first)
|
|
327
328
|
? existsSync(path.resolve(first))
|
|
328
|
-
:
|
|
329
|
-
(
|
|
330
|
-
try {
|
|
331
|
-
return Boolean(findProgram(first));
|
|
332
|
-
}
|
|
333
|
-
catch {
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
})();
|
|
329
|
+
: // Where the rule will look, not where a built-in Agent may also look: a rule's command runs in a login shell.
|
|
330
|
+
/^[\w.+@-]+$/.test(first) && Boolean(onPath(first));
|
|
337
331
|
if (!there)
|
|
338
332
|
return fail(`找不到 ${first}:先装好它,或者在 --command 里写它的完整路径。`);
|
|
339
333
|
agents.agent = { name: "Agent", worker, use: "command", command: words };
|
|
@@ -564,20 +558,38 @@ async function dashboard(args) {
|
|
|
564
558
|
const port = given === undefined ? 3351 : Number(given);
|
|
565
559
|
if (!Number.isInteger(port) || port < 1 || port > 65535)
|
|
566
560
|
return fail(`端口要写 1 到 65535 之间的数字:${given}`);
|
|
561
|
+
const { probeDashboard, startDashboard, stopDashboard } = await import("./dashboard.js");
|
|
562
|
+
if (named.stop !== undefined) {
|
|
563
|
+
const stopped = await stopDashboard(port);
|
|
564
|
+
return console.log(stopped ? "看板关了。" : `127.0.0.1:${port} 没有在跑的看板。`);
|
|
565
|
+
}
|
|
567
566
|
const config = readConfig();
|
|
568
|
-
const { startDashboard } = await import("./dashboard.js");
|
|
569
567
|
const board = await startDashboard({
|
|
570
568
|
url: config.url,
|
|
571
569
|
key: config.owner ?? fail("这台电脑上没有本人的密钥(只接活的电脑看不了)"),
|
|
572
570
|
port,
|
|
573
|
-
}).catch((error) =>
|
|
574
|
-
|
|
571
|
+
}).catch(async (error) => {
|
|
572
|
+
// A rerun while one is up: point at it instead of dying on the busy port. A stranger's port still fails.
|
|
573
|
+
if (error.code === "EADDRINUSE") {
|
|
574
|
+
const running = await probeDashboard(port);
|
|
575
|
+
if (running) {
|
|
576
|
+
console.log(`看板已经在 ${running} 跑着`);
|
|
577
|
+
if (named["no-open"] === undefined)
|
|
578
|
+
openPage(running);
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return fail(`看板起不来:${error.message}`);
|
|
583
|
+
});
|
|
584
|
+
if (!board)
|
|
585
|
+
return;
|
|
586
|
+
console.log(`看板在 ${board.url} · 按 Ctrl-C 或 agent-autoloop dashboard --stop 结束`);
|
|
575
587
|
if (named["no-open"] === undefined)
|
|
576
588
|
openPage(board.url);
|
|
577
589
|
const stop = Promise.withResolvers();
|
|
578
590
|
process.once("SIGINT", stop.resolve);
|
|
579
591
|
process.once("SIGTERM", stop.resolve);
|
|
580
|
-
await stop.promise;
|
|
592
|
+
await Promise.race([stop.promise, board.stopped]);
|
|
581
593
|
board.close();
|
|
582
594
|
}
|
|
583
595
|
async function status(named) {
|
|
@@ -592,8 +604,8 @@ async function runs(args) {
|
|
|
592
604
|
return fail(RUNS_USAGE);
|
|
593
605
|
const before = named.before === undefined ? undefined : runOf(named.before, RUNS_USAGE);
|
|
594
606
|
const owner = ownerClient();
|
|
595
|
-
const {
|
|
596
|
-
const found = await
|
|
607
|
+
const { readRuns, runsText } = await import("./runs.js");
|
|
608
|
+
const found = await readRuns(owner, rest[0], before);
|
|
597
609
|
if (named.json !== undefined)
|
|
598
610
|
return console.log(JSON.stringify({ runs: found.runs, before: found.more }, null, 2));
|
|
599
611
|
const color = colorFor(process.stdout, process.env);
|
|
@@ -994,6 +1006,9 @@ async function service(args) {
|
|
|
994
1006
|
// Installing over kept data comes here and not to init, and uninstalling took the links away.
|
|
995
1007
|
await prepareManagedInstall();
|
|
996
1008
|
linkSkill();
|
|
1009
|
+
const told = leftToSystem();
|
|
1010
|
+
if (told)
|
|
1011
|
+
return console.log(told);
|
|
997
1012
|
installService();
|
|
998
1013
|
return waitForHub();
|
|
999
1014
|
}
|
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, rules, 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();
|