@saltpub/agent-autoloop 0.0.0-stage → 0.1.2
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/INSTALL.md +118 -0
- package/LICENSE +21 -0
- package/README.en.md +264 -0
- package/README.md +260 -2
- package/SECURITY.md +48 -0
- package/dist/bin/agent-autoloop.js +2 -0
- package/dist/cli/backup.js +144 -0
- package/dist/cli/explain.js +84 -0
- package/dist/cli/main.js +1016 -0
- package/dist/cli/mcp.js +151 -0
- package/dist/cli/runs.js +40 -0
- package/dist/cli/spend.js +21 -0
- package/dist/cli/status.js +304 -0
- package/dist/cli/try.js +6 -0
- package/dist/cli/uninstall.js +84 -0
- package/dist/cli/update.js +65 -0
- package/dist/cli/why.js +115 -0
- package/dist/host/background-launcher.js +12 -0
- package/dist/host/background.js +24 -0
- package/dist/host/channels.js +4 -0
- package/dist/host/command.js +98 -0
- package/dist/host/config.js +37 -0
- package/dist/host/files.js +22 -0
- package/dist/host/home.js +5 -0
- package/dist/host/http.js +43 -0
- package/dist/host/launcher.js +188 -0
- package/dist/host/lines.js +15 -0
- package/dist/host/node-path.js +33 -0
- package/dist/host/npm.js +28 -0
- package/dist/host/plugins.js +26 -0
- package/dist/host/program.js +14 -0
- package/dist/host/runtime.js +179 -0
- package/dist/host/server.js +159 -0
- package/dist/host/service.js +325 -0
- package/dist/host/state.js +203 -0
- package/dist/host/up.js +162 -0
- package/dist/host/update.js +286 -0
- package/dist/host/version.js +81 -0
- package/dist/kernel/card-page.js +54 -0
- package/dist/kernel/credentials.js +16 -0
- package/dist/kernel/cron.js +135 -0
- package/dist/kernel/decide.js +826 -0
- package/dist/kernel/due.js +73 -0
- package/dist/kernel/errors.js +9 -0
- package/dist/kernel/evolve.js +264 -0
- package/dist/kernel/http.js +357 -0
- package/dist/kernel/query.js +202 -0
- package/dist/kernel/rules.js +20 -0
- package/dist/kernel/store.js +52 -0
- package/dist/plugins/acp/agent.js +32 -0
- package/dist/plugins/acp/bridge.js +204 -0
- package/dist/plugins/claude/agent.js +113 -0
- package/dist/plugins/codex/agent.js +105 -0
- package/dist/plugins/command/agent.js +25 -0
- package/dist/plugins/delivery/action.js +25 -0
- package/dist/plugins/delivery/agent.js +13 -0
- package/dist/plugins/delivery/delivery.js +388 -0
- package/dist/plugins/delivery/github.js +201 -0
- package/dist/plugins/delivery/handoff.js +50 -0
- package/dist/plugins/delivery/input.js +47 -0
- package/dist/plugins/delivery/poll.js +72 -0
- package/dist/plugins/delivery/project.js +144 -0
- package/dist/plugins/delivery/review-ledger.js +82 -0
- package/dist/plugins/delivery/review-policy.js +99 -0
- package/dist/plugins/delivery/review.js +280 -0
- package/dist/plugins/delivery/run.js +204 -0
- package/dist/plugins/desktop/channel.js +94 -0
- package/dist/plugins/dsh/agent.js +116 -0
- package/dist/plugins/feishu/channel.js +245 -0
- package/dist/plugins/github/source.js +30 -0
- package/dist/plugins/gitlab/source.js +30 -0
- package/dist/plugins/omp/agent.js +3 -0
- package/dist/plugins/opencode/agent.js +88 -0
- package/dist/plugins/pi/agent.js +92 -0
- package/dist/plugins/webhook/channel.js +70 -0
- package/dist/plugins/webhook/templates.js +34 -0
- package/dist/plugins/xiaojiu/channel.js +410 -0
- package/dist/plugins/zcode/agent.js +102 -0
- package/dist/protocol/client.js +56 -0
- package/dist/protocol/conformance.js +184 -0
- package/dist/protocol/job.js +1 -0
- package/dist/protocol/rules.js +230 -0
- package/dist/protocol/schema.js +70 -0
- package/dist/protocol/schema.json +985 -0
- package/dist/protocol/validate.js +150 -0
- package/dist/worker/agents.js +47 -0
- package/dist/worker/contract.js +178 -0
- package/dist/worker/run.js +52 -0
- package/dist/worker/usage.js +45 -0
- package/dist/worker/windows.ps1 +48 -0
- package/dist/worker/worker.js +595 -0
- package/docs/architecture.en.svg +178 -0
- package/docs/architecture.svg +178 -0
- package/docs/auto-update.md +53 -0
- package/docs/plugins.md +139 -0
- package/docs/protocol.md +582 -0
- package/docs/state-machines.md +77 -0
- package/examples/channel.sh +15 -0
- package/examples/plugins/hello-agent/agent.ts +40 -0
- package/examples/plugins/hello-channel/channel.ts +54 -0
- package/examples/plugins/hello-source/source.ts +19 -0
- package/examples/recipes/browser-handoff/README.md +44 -0
- package/examples/recipes/browser-handoff/SKILL.md +22 -0
- package/examples/recipes/browser-handoff/browser.json +10 -0
- package/examples/recipes/browser-handoff/handoff.ts +44 -0
- package/examples/recipes/browser-handoff/rules.json +19 -0
- package/examples/recipes/feedback/README.md +34 -0
- package/examples/recipes/feedback/SKILL.md +22 -0
- package/examples/recipes/feedback/event.json +8 -0
- package/examples/recipes/feedback/rules.json +37 -0
- package/examples/recipes/feishu-brief/README.md +28 -0
- package/examples/recipes/feishu-brief/SKILL.md +16 -0
- package/examples/recipes/feishu-brief/collect.ts +164 -0
- package/examples/recipes/feishu-brief/rules.json +57 -0
- package/examples/recipes/feishu-brief/sources.json +13 -0
- package/examples/recipes/github-issues/README.md +17 -0
- package/examples/recipes/github-issues/SKILL.md +18 -0
- package/examples/recipes/github-issues/rules.json +30 -0
- package/examples/recipes/inbox-triage/README.md +36 -0
- package/examples/recipes/inbox-triage/SKILL.md +19 -0
- package/examples/recipes/inbox-triage/collect.ts +191 -0
- package/examples/recipes/inbox-triage/rules.json +57 -0
- package/examples/recipes/inbox-triage/sources.json +8 -0
- package/examples/recipes/morning-brief/README.md +17 -0
- package/examples/recipes/morning-brief/SKILL.md +17 -0
- package/examples/recipes/morning-brief/rules.json +16 -0
- package/examples/recipes/ops-alerts/README.md +18 -0
- package/examples/recipes/ops-alerts/SKILL.md +34 -0
- package/examples/recipes/ops-alerts/restart.sh +5 -0
- package/examples/recipes/ops-alerts/rules.json +29 -0
- package/examples/recipes/website-watch/README.md +26 -0
- package/examples/recipes/website-watch/SKILL.md +19 -0
- package/examples/recipes/website-watch/check.ts +86 -0
- package/examples/recipes/website-watch/rules.json +56 -0
- package/examples/recipes/website-watch/site.json +6 -0
- package/examples/skills/weekly-sweep/SKILL.md +17 -0
- package/examples/watch-github-issues.sh +23 -0
- package/examples/worker.sh +18 -0
- package/package.json +55 -4
- package/plugins/acp/agent.ts +31 -0
- package/plugins/acp/bridge.ts +190 -0
- package/plugins/claude/agent.ts +121 -0
- package/plugins/codex/agent.ts +103 -0
- package/plugins/command/agent.ts +25 -0
- package/plugins/delivery/action.ts +29 -0
- package/plugins/delivery/action.yml +28 -0
- package/plugins/delivery/agent.ts +15 -0
- package/plugins/delivery/delivery.ts +408 -0
- package/plugins/delivery/github.ts +207 -0
- package/plugins/delivery/handoff.ts +72 -0
- package/plugins/delivery/input.ts +55 -0
- package/plugins/delivery/poll.ts +65 -0
- package/plugins/delivery/project.ts +161 -0
- package/plugins/delivery/review-ledger.ts +90 -0
- package/plugins/delivery/review-policy.ts +126 -0
- package/plugins/delivery/review.ts +324 -0
- package/plugins/delivery/run.ts +219 -0
- package/plugins/desktop/channel.ts +100 -0
- package/plugins/dsh/agent.ts +100 -0
- package/plugins/feishu/channel.ts +243 -0
- package/plugins/github/source.ts +33 -0
- package/plugins/gitlab/source.ts +32 -0
- package/plugins/omp/agent.ts +4 -0
- package/plugins/opencode/agent.ts +78 -0
- package/plugins/pi/agent.ts +80 -0
- package/plugins/webhook/channel.ts +74 -0
- package/plugins/webhook/templates.ts +32 -0
- package/plugins/xiaojiu/channel.ts +426 -0
- package/plugins/zcode/agent.ts +96 -0
- package/skills/agent-autoloop/SKILL.md +260 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 680" role="img" aria-labelledby="t">
|
|
2
|
+
<title id="t">Agent Autoloop architecture: a kernel in the middle, everything else a plugin</title>
|
|
3
|
+
<defs>
|
|
4
|
+
<style>
|
|
5
|
+
svg{--bg:#faf9f5;--ink:#1d1c19;--muted:#6e6b64;--line:#d6d3cb;--card:#fff;--item:#f4f2ec;--accent:#c2491d;--core:#1d1c19;--core-ink:#faf9f5;--core-duty:#33302a;--core-chip:#282621;--core-line:#423f38;--core-sub:#b9b5ab;--core-accent:#ef8a62;--tag-bg:#3d261c;--tag-ink:#ffb08e;--you-bg:#fff4ee}
|
|
6
|
+
@media (prefers-color-scheme:dark){svg{--bg:#151412;--ink:#f1efe9;--muted:#a29e95;--line:#45433d;--card:#1e1d1a;--item:#262420;--accent:#ef8a62;--core:#f1efe9;--core-ink:#1d1c19;--core-duty:#dedad0;--core-chip:#e6e3da;--core-line:#cac5b9;--core-sub:#57544d;--core-accent:#c2491d;--tag-bg:#f8dfd3;--tag-ink:#a83810;--you-bg:#2a1f1a}}
|
|
7
|
+
text{font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Noto Sans CJK SC","Microsoft YaHei",sans-serif;font-size:14px;fill:var(--ink)}
|
|
8
|
+
.h2{font-size:16.5px;font-weight:600}
|
|
9
|
+
.s{font-size:12px;fill:var(--muted)}
|
|
10
|
+
.r{font-size:13.5px}
|
|
11
|
+
.l{font-size:12px;font-weight:600;fill:var(--accent)}
|
|
12
|
+
.bg{fill:var(--bg)}
|
|
13
|
+
.plug{fill:var(--card);stroke:var(--muted);stroke-width:1.3;stroke-dasharray:6 5}
|
|
14
|
+
.item{fill:var(--item);stroke:var(--line)}
|
|
15
|
+
.loop-pill{fill:var(--you-bg);stroke:var(--accent);stroke-width:1.4}
|
|
16
|
+
.loop-text{font-size:13px;font-weight:600;fill:var(--accent)}
|
|
17
|
+
.more{fill:none;stroke:var(--line);stroke-dasharray:4 4}
|
|
18
|
+
.dot{fill:var(--muted)}
|
|
19
|
+
.core{fill:var(--core);stroke:var(--core-accent);stroke-width:2}
|
|
20
|
+
.duty{fill:var(--core-duty);stroke:var(--core-line)}
|
|
21
|
+
.chip{fill:var(--core-chip)}
|
|
22
|
+
.tag{fill:var(--tag-bg);stroke:var(--core-accent);stroke-width:1}
|
|
23
|
+
.cte{font-size:19.5px;font-weight:700;fill:var(--core-ink)}
|
|
24
|
+
.cs{font-size:11.5px;fill:var(--core-sub)}
|
|
25
|
+
.cn{font-size:14.5px;font-weight:600;fill:var(--core-ink)}
|
|
26
|
+
.cd{font-size:12px;fill:var(--core-sub)}
|
|
27
|
+
.tn{font-size:11.2px;font-weight:700;fill:var(--tag-ink)}
|
|
28
|
+
.td{font-size:10.6px;fill:var(--core-ink)}
|
|
29
|
+
.you{fill:var(--you-bg);stroke:var(--accent);stroke-width:2.4}
|
|
30
|
+
.you-t{font-size:20px;font-weight:700;fill:var(--accent)}
|
|
31
|
+
.you-s{font-size:13px;font-weight:600;fill:var(--ink)}
|
|
32
|
+
.badge{fill:var(--accent)}
|
|
33
|
+
.n{font-size:12.5px;font-weight:700;fill:var(--bg)}
|
|
34
|
+
.conn{fill:none;stroke:var(--accent);stroke-width:2.1;marker-end:url(#a)}
|
|
35
|
+
.back{fill:none;stroke:var(--accent);stroke-width:1.8;stroke-dasharray:6 4;marker-end:url(#a)}
|
|
36
|
+
.flow{fill:none;stroke:var(--muted);stroke-width:1.4;marker-end:url(#b)}
|
|
37
|
+
.both{fill:none;stroke:var(--accent);stroke-width:1.8;marker-start:url(#a);marker-end:url(#a)}
|
|
38
|
+
</style>
|
|
39
|
+
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" style="fill:var(--accent)"/></marker>
|
|
40
|
+
<marker id="b" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" style="fill:var(--muted)"/></marker>
|
|
41
|
+
</defs>
|
|
42
|
+
<rect class="bg" x="0" y="0" width="960" height="680" rx="18"/>
|
|
43
|
+
|
|
44
|
+
<!-- Top auto-loop arc: finish directly / scheduled follow-up -> back to kernel -->
|
|
45
|
+
<path class="back" d="M851 66V28H480V63"/>
|
|
46
|
+
<rect class="loop-pill" x="480" y="13" width="368" height="30" rx="15"/>
|
|
47
|
+
<text x="664" y="33" class="loop-text" text-anchor="middle">Auto-loop: finishes on its own · checks back later</text>
|
|
48
|
+
|
|
49
|
+
<!-- Left: Event plugins -->
|
|
50
|
+
<rect class="plug" x="22" y="68" width="174" height="316" rx="14"/>
|
|
51
|
+
<text x="38" y="100" class="h2">Event plugins</text>
|
|
52
|
+
<text x="38" y="121" class="s">Spot new work to do</text>
|
|
53
|
+
<rect class="item" x="36" y="142" width="146" height="36" rx="8"/>
|
|
54
|
+
<text x="109" y="165" class="r" text-anchor="middle">Schedules</text>
|
|
55
|
+
<rect class="item" x="36" y="188" width="146" height="36" rx="8"/>
|
|
56
|
+
<text x="109" y="211" class="r" text-anchor="middle">GitHub</text>
|
|
57
|
+
<rect class="item" x="36" y="234" width="146" height="36" rx="8"/>
|
|
58
|
+
<text x="109" y="257" class="r" text-anchor="middle">Your systems</text>
|
|
59
|
+
<rect class="item" x="36" y="280" width="146" height="36" rx="8"/>
|
|
60
|
+
<text x="109" y="303" class="r" text-anchor="middle">Polling script</text>
|
|
61
|
+
<rect class="more" x="36" y="326" width="146" height="32" rx="8"/>
|
|
62
|
+
<circle class="dot" cx="97" cy="342" r="2.4"/>
|
|
63
|
+
<circle class="dot" cx="109" cy="342" r="2.4"/>
|
|
64
|
+
<circle class="dot" cx="121" cy="342" r="2.4"/>
|
|
65
|
+
|
|
66
|
+
<!-- 1: new event -->
|
|
67
|
+
<path class="conn" d="M198 226H246"/>
|
|
68
|
+
<circle class="badge" cx="222" cy="203" r="12"/>
|
|
69
|
+
<text x="222" y="207.5" class="n" text-anchor="middle">1</text>
|
|
70
|
+
<text x="222" y="246" class="l" text-anchor="middle">event</text>
|
|
71
|
+
|
|
72
|
+
<!-- Center: Autoloop kernel -->
|
|
73
|
+
<rect class="core" x="250" y="68" width="460" height="316" rx="22"/>
|
|
74
|
+
<text x="272" y="102" class="cte">Autoloop kernel</text>
|
|
75
|
+
<text x="688" y="101" class="cs" text-anchor="end">No runtime dependencies · Deterministic</text>
|
|
76
|
+
|
|
77
|
+
<!-- Core responsibility -->
|
|
78
|
+
<rect class="duty" x="268" y="116" width="424" height="52" rx="10"/>
|
|
79
|
+
<text x="480" y="139" class="cn" text-anchor="middle">Dispatches work by your rules</text>
|
|
80
|
+
<text x="480" y="158" class="cd" text-anchor="middle">Picks which agent & folder · merges duplicate events</text>
|
|
81
|
+
|
|
82
|
+
<!-- 4 kernel mechanism tags -->
|
|
83
|
+
<rect class="chip" x="268" y="180" width="424" height="40" rx="9"/>
|
|
84
|
+
<rect class="tag" x="276" y="187" width="100" height="26" rx="6"/>
|
|
85
|
+
<text x="326" y="204" class="tn" text-anchor="middle">Zero-cost wait</text>
|
|
86
|
+
<text x="386" y="204" class="td">Exits while waiting for you; 0 tokens, resumes chat</text>
|
|
87
|
+
|
|
88
|
+
<rect class="chip" x="268" y="228" width="424" height="40" rx="9"/>
|
|
89
|
+
<rect class="tag" x="276" y="235" width="100" height="26" rx="6"/>
|
|
90
|
+
<text x="326" y="252" class="tn" text-anchor="middle">Event sourcing</text>
|
|
91
|
+
<text x="386" y="252" class="td">Crash-safe & traceable; rebuilds from log, 0 migrations</text>
|
|
92
|
+
|
|
93
|
+
<rect class="chip" x="268" y="276" width="424" height="40" rx="9"/>
|
|
94
|
+
<rect class="tag" x="276" y="283" width="100" height="26" rx="6"/>
|
|
95
|
+
<text x="326" y="300" class="tn" text-anchor="middle">Code/data split</text>
|
|
96
|
+
<text x="386" y="300" class="td">Issue text never enters prompts or alters dir & access</text>
|
|
97
|
+
|
|
98
|
+
<rect class="chip" x="268" y="324" width="424" height="40" rx="9"/>
|
|
99
|
+
<rect class="tag" x="276" y="331" width="100" height="26" rx="6"/>
|
|
100
|
+
<text x="326" y="348" class="tn" text-anchor="middle">Hop breaker</text>
|
|
101
|
+
<text x="386" y="348" class="td">Stops agent chains past 8 hops before burning quota</text>
|
|
102
|
+
|
|
103
|
+
<!-- 2 & 3: dispatch & result -->
|
|
104
|
+
<path class="conn" d="M712 190H760"/>
|
|
105
|
+
<circle class="badge" cx="736" cy="167" r="12"/>
|
|
106
|
+
<text x="736" y="171.5" class="n" text-anchor="middle">2</text>
|
|
107
|
+
<text x="736" y="210" class="l" text-anchor="middle">assign</text>
|
|
108
|
+
|
|
109
|
+
<path class="conn" d="M760 266H712"/>
|
|
110
|
+
<circle class="badge" cx="736" cy="243" r="12"/>
|
|
111
|
+
<text x="736" y="247.5" class="n" text-anchor="middle">3</text>
|
|
112
|
+
<text x="736" y="286" class="l" text-anchor="middle">result</text>
|
|
113
|
+
|
|
114
|
+
<!-- Right: Agent plugins -->
|
|
115
|
+
<rect class="plug" x="764" y="68" width="174" height="316" rx="14"/>
|
|
116
|
+
<text x="780" y="100" class="h2">Agent plugins</text>
|
|
117
|
+
<text x="780" y="121" class="s">AI that does the work</text>
|
|
118
|
+
<rect class="item" x="778" y="142" width="146" height="36" rx="8"/>
|
|
119
|
+
<text x="851" y="165" class="r" text-anchor="middle">Claude Code</text>
|
|
120
|
+
<rect class="item" x="778" y="188" width="146" height="36" rx="8"/>
|
|
121
|
+
<text x="851" y="211" class="r" text-anchor="middle">Codex</text>
|
|
122
|
+
<rect class="item" x="778" y="234" width="146" height="36" rx="8"/>
|
|
123
|
+
<text x="851" y="257" class="r" text-anchor="middle">DeepSeek Harness</text>
|
|
124
|
+
<rect class="item" x="778" y="280" width="146" height="36" rx="8"/>
|
|
125
|
+
<text x="851" y="303" class="r" text-anchor="middle">Pi · OpenClaw</text>
|
|
126
|
+
<rect class="more" x="778" y="326" width="146" height="32" rx="8"/>
|
|
127
|
+
<circle class="dot" cx="839" cy="342" r="2.4"/>
|
|
128
|
+
<circle class="dot" cx="851" cy="342" r="2.4"/>
|
|
129
|
+
<circle class="dot" cx="863" cy="342" r="2.4"/>
|
|
130
|
+
|
|
131
|
+
<!-- Bottom human loop: 4 card -> Channel plugins -> You -> 5 answer resumes session -->
|
|
132
|
+
<path class="conn" d="M560 386V448"/>
|
|
133
|
+
<circle class="badge" cx="560" cy="417" r="12"/>
|
|
134
|
+
<text x="560" y="421.5" class="n" text-anchor="middle">4</text>
|
|
135
|
+
<text x="580" y="422" class="l">asks you only when needed</text>
|
|
136
|
+
|
|
137
|
+
<rect class="plug" x="390" y="452" width="548" height="92" rx="14"/>
|
|
138
|
+
<text x="410" y="480" class="h2">Channel plugins</text>
|
|
139
|
+
<text x="560" y="480" class="s">Deliver cards to your hand</text>
|
|
140
|
+
<rect class="item" x="410" y="494" width="104" height="36" rx="8"/>
|
|
141
|
+
<text x="462" y="517" class="r" text-anchor="middle">Desktop</text>
|
|
142
|
+
<rect class="item" x="524" y="494" width="90" height="36" rx="8"/>
|
|
143
|
+
<text x="569" y="517" class="r" text-anchor="middle">Feishu</text>
|
|
144
|
+
<rect class="item" x="624" y="494" width="150" height="36" rx="8"/>
|
|
145
|
+
<text x="699" y="517" class="r" text-anchor="middle">DingTalk · WeCom</text>
|
|
146
|
+
<rect class="item" x="784" y="494" width="134" height="36" rx="8"/>
|
|
147
|
+
<text x="851" y="517" class="r" text-anchor="middle">Slack · Discord</text>
|
|
148
|
+
|
|
149
|
+
<path class="both" d="M388 498H328"/>
|
|
150
|
+
<rect class="you" x="172" y="454" width="152" height="88" rx="26"/>
|
|
151
|
+
<text x="248" y="493" class="you-t" text-anchor="middle">You</text>
|
|
152
|
+
<text x="248" y="517" class="you-s" text-anchor="middle">Just make the call</text>
|
|
153
|
+
|
|
154
|
+
<!-- 5: answer -> back to kernel -->
|
|
155
|
+
<path class="conn" d="M248 452V410H400V386"/>
|
|
156
|
+
<circle class="badge" cx="324" cy="410" r="12"/>
|
|
157
|
+
<text x="324" y="414.5" class="n" text-anchor="middle">5</text>
|
|
158
|
+
<text x="232" y="415" class="l" text-anchor="end">one tap resumes the chat</text>
|
|
159
|
+
|
|
160
|
+
<!-- Bottom: Delivery pipeline -->
|
|
161
|
+
<rect class="plug" x="22" y="584" width="916" height="72" rx="14"/>
|
|
162
|
+
<text x="40" y="614" class="h2">Code delivery pipeline</text>
|
|
163
|
+
<text x="40" y="636" class="s">built-in plugin (event + agent)</text>
|
|
164
|
+
<rect class="item" x="260" y="602" width="106" height="36" rx="8"/>
|
|
165
|
+
<text x="313" y="625" class="r" text-anchor="middle">Review</text>
|
|
166
|
+
<path class="flow" d="M367 620H395"/>
|
|
167
|
+
<rect class="item" x="396" y="602" width="106" height="36" rx="8"/>
|
|
168
|
+
<text x="449" y="625" class="r" text-anchor="middle">Checks</text>
|
|
169
|
+
<path class="flow" d="M503 620H531"/>
|
|
170
|
+
<rect class="item" x="532" y="602" width="106" height="36" rx="8"/>
|
|
171
|
+
<text x="585" y="625" class="r" text-anchor="middle">Merge</text>
|
|
172
|
+
<path class="flow" d="M639 620H667"/>
|
|
173
|
+
<rect class="item" x="668" y="602" width="106" height="36" rx="8"/>
|
|
174
|
+
<text x="721" y="625" class="r" text-anchor="middle">Deploy</text>
|
|
175
|
+
<path class="flow" d="M775 620H803"/>
|
|
176
|
+
<rect class="item" x="804" y="602" width="114" height="36" rx="8"/>
|
|
177
|
+
<text x="861" y="625" class="r" text-anchor="middle">Verify live</text>
|
|
178
|
+
</svg>
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 680" role="img" aria-labelledby="t">
|
|
2
|
+
<title id="t">Agent Autoloop 架构图:内核在中间,其他都是插件</title>
|
|
3
|
+
<defs>
|
|
4
|
+
<style>
|
|
5
|
+
svg{--bg:#faf9f5;--ink:#1d1c19;--muted:#6e6b64;--line:#d6d3cb;--card:#fff;--item:#f4f2ec;--accent:#c2491d;--core:#1d1c19;--core-ink:#faf9f5;--core-duty:#33302a;--core-chip:#282621;--core-line:#423f38;--core-sub:#b9b5ab;--core-accent:#ef8a62;--tag-bg:#3d261c;--tag-ink:#ffb08e;--you-bg:#fff4ee}
|
|
6
|
+
@media (prefers-color-scheme:dark){svg{--bg:#151412;--ink:#f1efe9;--muted:#a29e95;--line:#45433d;--card:#1e1d1a;--item:#262420;--accent:#ef8a62;--core:#f1efe9;--core-ink:#1d1c19;--core-duty:#dedad0;--core-chip:#e6e3da;--core-line:#cac5b9;--core-sub:#57544d;--core-accent:#c2491d;--tag-bg:#f8dfd3;--tag-ink:#a83810;--you-bg:#2a1f1a}}
|
|
7
|
+
text{font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Noto Sans CJK SC","Microsoft YaHei",sans-serif;font-size:14px;fill:var(--ink)}
|
|
8
|
+
.h2{font-size:17px;font-weight:600}
|
|
9
|
+
.s{font-size:12.5px;fill:var(--muted)}
|
|
10
|
+
.r{font-size:13.5px}
|
|
11
|
+
.l{font-size:13.5px;font-weight:600;fill:var(--accent)}
|
|
12
|
+
.bg{fill:var(--bg)}
|
|
13
|
+
.plug{fill:var(--card);stroke:var(--muted);stroke-width:1.3;stroke-dasharray:6 5}
|
|
14
|
+
.item{fill:var(--item);stroke:var(--line)}
|
|
15
|
+
.loop-pill{fill:var(--you-bg);stroke:var(--accent);stroke-width:1.4}
|
|
16
|
+
.loop-text{font-size:13px;font-weight:600;fill:var(--accent)}
|
|
17
|
+
.more{fill:none;stroke:var(--line);stroke-dasharray:4 4}
|
|
18
|
+
.dot{fill:var(--muted)}
|
|
19
|
+
.core{fill:var(--core);stroke:var(--core-accent);stroke-width:2}
|
|
20
|
+
.duty{fill:var(--core-duty);stroke:var(--core-line)}
|
|
21
|
+
.chip{fill:var(--core-chip)}
|
|
22
|
+
.tag{fill:var(--tag-bg);stroke:var(--core-accent);stroke-width:1}
|
|
23
|
+
.ct{font-size:22px;font-weight:700;fill:var(--core-ink)}
|
|
24
|
+
.cs{font-size:12px;fill:var(--core-sub)}
|
|
25
|
+
.cn{font-size:14.5px;font-weight:600;fill:var(--core-ink)}
|
|
26
|
+
.cd{font-size:12px;fill:var(--core-sub)}
|
|
27
|
+
.tn{font-size:12.5px;font-weight:700;fill:var(--tag-ink)}
|
|
28
|
+
.td{font-size:11.8px;fill:var(--core-ink)}
|
|
29
|
+
.you{fill:var(--you-bg);stroke:var(--accent);stroke-width:2.4}
|
|
30
|
+
.you-t{font-size:20px;font-weight:700;fill:var(--accent)}
|
|
31
|
+
.you-s{font-size:13px;font-weight:600;fill:var(--ink)}
|
|
32
|
+
.badge{fill:var(--accent)}
|
|
33
|
+
.n{font-size:12.5px;font-weight:700;fill:var(--bg)}
|
|
34
|
+
.conn{fill:none;stroke:var(--accent);stroke-width:2.1;marker-end:url(#a)}
|
|
35
|
+
.back{fill:none;stroke:var(--accent);stroke-width:1.8;stroke-dasharray:6 4;marker-end:url(#a)}
|
|
36
|
+
.flow{fill:none;stroke:var(--muted);stroke-width:1.4;marker-end:url(#b)}
|
|
37
|
+
.both{fill:none;stroke:var(--accent);stroke-width:1.8;marker-start:url(#a);marker-end:url(#a)}
|
|
38
|
+
</style>
|
|
39
|
+
<marker id="a" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" style="fill:var(--accent)"/></marker>
|
|
40
|
+
<marker id="b" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="7" markerHeight="7" orient="auto-start-reverse"><path d="M0 0L10 5L0 10z" style="fill:var(--muted)"/></marker>
|
|
41
|
+
</defs>
|
|
42
|
+
<rect class="bg" x="0" y="0" width="960" height="680" rx="18"/>
|
|
43
|
+
|
|
44
|
+
<!-- 顶部自动闭环回弧:自己干完 / 到点复查 -> 回到内核 -->
|
|
45
|
+
<path class="back" d="M851 66V28H480V63"/>
|
|
46
|
+
<rect class="loop-pill" x="492" y="13" width="344" height="30" rx="15"/>
|
|
47
|
+
<text x="664" y="33" class="loop-text" text-anchor="middle">自动闭环:自己干完 · 到点复查 · 触发下一步</text>
|
|
48
|
+
|
|
49
|
+
<!-- 左:事件插件 -->
|
|
50
|
+
<rect class="plug" x="22" y="68" width="174" height="316" rx="14"/>
|
|
51
|
+
<text x="38" y="100" class="h2">事件插件</text>
|
|
52
|
+
<text x="38" y="121" class="s">负责发现新任务</text>
|
|
53
|
+
<rect class="item" x="36" y="142" width="146" height="36" rx="8"/>
|
|
54
|
+
<text x="109" y="165" class="r" text-anchor="middle">定时任务</text>
|
|
55
|
+
<rect class="item" x="36" y="188" width="146" height="36" rx="8"/>
|
|
56
|
+
<text x="109" y="211" class="r" text-anchor="middle">GitHub</text>
|
|
57
|
+
<rect class="item" x="36" y="234" width="146" height="36" rx="8"/>
|
|
58
|
+
<text x="109" y="257" class="r" text-anchor="middle">你的业务系统</text>
|
|
59
|
+
<rect class="item" x="36" y="280" width="146" height="36" rx="8"/>
|
|
60
|
+
<text x="109" y="303" class="r" text-anchor="middle">轮询脚本</text>
|
|
61
|
+
<rect class="more" x="36" y="326" width="146" height="32" rx="8"/>
|
|
62
|
+
<circle class="dot" cx="97" cy="342" r="2.4"/>
|
|
63
|
+
<circle class="dot" cx="109" cy="342" r="2.4"/>
|
|
64
|
+
<circle class="dot" cx="121" cy="342" r="2.4"/>
|
|
65
|
+
|
|
66
|
+
<!-- 1: 新事件 -->
|
|
67
|
+
<path class="conn" d="M198 226H246"/>
|
|
68
|
+
<circle class="badge" cx="222" cy="203" r="12"/>
|
|
69
|
+
<text x="222" y="207.5" class="n" text-anchor="middle">1</text>
|
|
70
|
+
<text x="222" y="246" class="l" text-anchor="middle">新事件</text>
|
|
71
|
+
|
|
72
|
+
<!-- 中:Autoloop 内核 -->
|
|
73
|
+
<rect class="core" x="250" y="68" width="460" height="316" rx="22"/>
|
|
74
|
+
<text x="272" y="103" class="ct">Autoloop 内核</text>
|
|
75
|
+
<text x="688" y="101" class="cs" text-anchor="end">零运行时依赖 · 确定性</text>
|
|
76
|
+
|
|
77
|
+
<!-- 内核核心职责 -->
|
|
78
|
+
<rect class="duty" x="268" y="116" width="424" height="52" rx="10"/>
|
|
79
|
+
<text x="480" y="139" class="cn" text-anchor="middle">按你的规则分派任务</text>
|
|
80
|
+
<text x="480" y="158" class="cd" text-anchor="middle">决定交给哪个 Agent、去哪个目录干 · 同一件事自动合并</text>
|
|
81
|
+
|
|
82
|
+
<!-- 4 个内核机制标签 -->
|
|
83
|
+
<rect class="chip" x="268" y="180" width="424" height="40" rx="9"/>
|
|
84
|
+
<rect class="tag" x="276" y="187" width="92" height="26" rx="6"/>
|
|
85
|
+
<text x="322" y="204.5" class="tn" text-anchor="middle">挂起零消耗</text>
|
|
86
|
+
<text x="378" y="204.5" class="td">等你拍板时进程直接退出,不烧 Token,回来接着原对话</text>
|
|
87
|
+
|
|
88
|
+
<rect class="chip" x="268" y="228" width="424" height="40" rx="9"/>
|
|
89
|
+
<rect class="tag" x="276" y="235" width="92" height="26" rx="6"/>
|
|
90
|
+
<text x="322" y="252.5" class="tn" text-anchor="middle">事件溯源</text>
|
|
91
|
+
<text x="378" y="252.5" class="td">强杀不丢,每步可追溯,升级从日志重建、不迁库</text>
|
|
92
|
+
|
|
93
|
+
<rect class="chip" x="268" y="276" width="424" height="40" rx="9"/>
|
|
94
|
+
<rect class="tag" x="276" y="283" width="92" height="26" rx="6"/>
|
|
95
|
+
<text x="322" y="300.5" class="tn" text-anchor="middle">指令数据分离</text>
|
|
96
|
+
<text x="378" y="300.5" class="td">Issue 里的话进不了提示词,也改不了目录和权限</text>
|
|
97
|
+
|
|
98
|
+
<rect class="chip" x="268" y="324" width="424" height="40" rx="9"/>
|
|
99
|
+
<rect class="tag" x="276" y="331" width="92" height="26" rx="6"/>
|
|
100
|
+
<text x="322" y="348.5" class="tn" text-anchor="middle">跳数熔断</text>
|
|
101
|
+
<text x="378" y="348.5" class="td">Agent 互相触发超过 8 层自动停下,不烧光额度</text>
|
|
102
|
+
|
|
103
|
+
<!-- 2 & 3: 派活与交结果 -->
|
|
104
|
+
<path class="conn" d="M712 190H760"/>
|
|
105
|
+
<circle class="badge" cx="736" cy="167" r="12"/>
|
|
106
|
+
<text x="736" y="171.5" class="n" text-anchor="middle">2</text>
|
|
107
|
+
<text x="736" y="210" class="l" text-anchor="middle">派活</text>
|
|
108
|
+
|
|
109
|
+
<path class="conn" d="M760 266H712"/>
|
|
110
|
+
<circle class="badge" cx="736" cy="243" r="12"/>
|
|
111
|
+
<text x="736" y="247.5" class="n" text-anchor="middle">3</text>
|
|
112
|
+
<text x="736" y="286" class="l" text-anchor="middle">交结果</text>
|
|
113
|
+
|
|
114
|
+
<!-- 右:Agent 插件 -->
|
|
115
|
+
<rect class="plug" x="764" y="68" width="174" height="316" rx="14"/>
|
|
116
|
+
<text x="780" y="100" class="h2">Agent 插件</text>
|
|
117
|
+
<text x="780" y="121" class="s">负责干活的 AI</text>
|
|
118
|
+
<rect class="item" x="778" y="142" width="146" height="36" rx="8"/>
|
|
119
|
+
<text x="851" y="165" class="r" text-anchor="middle">Claude Code</text>
|
|
120
|
+
<rect class="item" x="778" y="188" width="146" height="36" rx="8"/>
|
|
121
|
+
<text x="851" y="211" class="r" text-anchor="middle">Codex</text>
|
|
122
|
+
<rect class="item" x="778" y="234" width="146" height="36" rx="8"/>
|
|
123
|
+
<text x="851" y="257" class="r" text-anchor="middle">DeepSeek Harness</text>
|
|
124
|
+
<rect class="item" x="778" y="280" width="146" height="36" rx="8"/>
|
|
125
|
+
<text x="851" y="303" class="r" text-anchor="middle">Pi · OpenClaw</text>
|
|
126
|
+
<rect class="more" x="778" y="326" width="146" height="32" rx="8"/>
|
|
127
|
+
<circle class="dot" cx="839" cy="342" r="2.4"/>
|
|
128
|
+
<circle class="dot" cx="851" cy="342" r="2.4"/>
|
|
129
|
+
<circle class="dot" cx="863" cy="342" r="2.4"/>
|
|
130
|
+
|
|
131
|
+
<!-- 下方人机闭环:4 拿不准才问你 -> 通道插件 -> 你 -> 5 拍板后接着干 -->
|
|
132
|
+
<path class="conn" d="M560 386V448"/>
|
|
133
|
+
<circle class="badge" cx="560" cy="417" r="12"/>
|
|
134
|
+
<text x="560" y="421.5" class="n" text-anchor="middle">4</text>
|
|
135
|
+
<text x="580" y="422" class="l">拿不准才发卡片问你</text>
|
|
136
|
+
|
|
137
|
+
<rect class="plug" x="390" y="452" width="548" height="92" rx="14"/>
|
|
138
|
+
<text x="410" y="480" class="h2">通道插件</text>
|
|
139
|
+
<text x="490" y="480" class="s">把问题卡片送到你手边</text>
|
|
140
|
+
<rect class="item" x="410" y="494" width="114" height="36" rx="8"/>
|
|
141
|
+
<text x="467" y="517" class="r" text-anchor="middle">桌面通知</text>
|
|
142
|
+
<rect class="item" x="534" y="494" width="104" height="36" rx="8"/>
|
|
143
|
+
<text x="586" y="517" class="r" text-anchor="middle">飞书</text>
|
|
144
|
+
<rect class="item" x="648" y="494" width="126" height="36" rx="8"/>
|
|
145
|
+
<text x="711" y="517" class="r" text-anchor="middle">钉钉 · 企微</text>
|
|
146
|
+
<rect class="item" x="784" y="494" width="134" height="36" rx="8"/>
|
|
147
|
+
<text x="851" y="517" class="r" text-anchor="middle">Slack · Discord</text>
|
|
148
|
+
|
|
149
|
+
<path class="both" d="M388 498H328"/>
|
|
150
|
+
<rect class="you" x="172" y="454" width="152" height="88" rx="26"/>
|
|
151
|
+
<text x="248" y="493" class="you-t" text-anchor="middle">你</text>
|
|
152
|
+
<text x="248" y="517" class="you-s" text-anchor="middle">只管拍板</text>
|
|
153
|
+
|
|
154
|
+
<!-- 5: 你的回答 -> 回到内核接着干 -->
|
|
155
|
+
<path class="conn" d="M248 452V410H400V386"/>
|
|
156
|
+
<circle class="badge" cx="324" cy="410" r="12"/>
|
|
157
|
+
<text x="324" y="414.5" class="n" text-anchor="middle">5</text>
|
|
158
|
+
<text x="232" y="415" class="l" text-anchor="end">点一下,接着原对话干完</text>
|
|
159
|
+
|
|
160
|
+
<!-- 底部:交付流水线 -->
|
|
161
|
+
<rect class="plug" x="22" y="584" width="916" height="72" rx="14"/>
|
|
162
|
+
<text x="40" y="614" class="h2">代码交付流水线</text>
|
|
163
|
+
<text x="40" y="636" class="s">内置插件示例(事件 + Agent)</text>
|
|
164
|
+
<rect class="item" x="260" y="602" width="106" height="36" rx="8"/>
|
|
165
|
+
<text x="313" y="625" class="r" text-anchor="middle">审代码</text>
|
|
166
|
+
<path class="flow" d="M367 620H395"/>
|
|
167
|
+
<rect class="item" x="396" y="602" width="106" height="36" rx="8"/>
|
|
168
|
+
<text x="449" y="625" class="r" text-anchor="middle">跑检查</text>
|
|
169
|
+
<path class="flow" d="M503 620H531"/>
|
|
170
|
+
<rect class="item" x="532" y="602" width="106" height="36" rx="8"/>
|
|
171
|
+
<text x="585" y="625" class="r" text-anchor="middle">合代码</text>
|
|
172
|
+
<path class="flow" d="M639 620H667"/>
|
|
173
|
+
<rect class="item" x="668" y="602" width="106" height="36" rx="8"/>
|
|
174
|
+
<text x="721" y="625" class="r" text-anchor="middle">自动上线</text>
|
|
175
|
+
<path class="flow" d="M775 620H803"/>
|
|
176
|
+
<rect class="item" x="804" y="602" width="114" height="36" rx="8"/>
|
|
177
|
+
<text x="861" y="625" class="r" text-anchor="middle">核对线上版本</text>
|
|
178
|
+
</svg>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# 自动更新
|
|
2
|
+
|
|
3
|
+
npm 安装的副本不在原地覆盖着换版本。每个版本解包在自己的文件夹里,一个不随版本变的启动器决定这次启动哪一个;新版本先装好、试跑过、等手上的轮次跑完,才在下一次启动时换上。装坏了就退回上一版。
|
|
4
|
+
|
|
5
|
+
数据目录里的样子:
|
|
6
|
+
|
|
7
|
+
| 路径 | 是什么 |
|
|
8
|
+
| ----------------------------------------------- | ------------------------------------------------ |
|
|
9
|
+
| `versions/<版本>/node_modules/…/agent-autoloop` | 一个完整版本,正在跑的和准备好的都在这里 |
|
|
10
|
+
| `launcher/launcher.mjs` | 启动器;每次启动中台前从当前版本刷新一次 |
|
|
11
|
+
| `update/current.json` | 现在该启动哪个版本,以及上一个能退回的版本 |
|
|
12
|
+
| `update/pending.json` | 已经装好、等着换的版本 |
|
|
13
|
+
| `update/boot.json` | 中台报到:这个版本已经开始应答 |
|
|
14
|
+
| `update/failures.json` | 连续几次没起来 |
|
|
15
|
+
| `update/bad.json` | 起不来的版本,不再尝试 |
|
|
16
|
+
| `update/stage.lock` | 同时只有一个进程在准备新版本;超过 30 分钟算遗留 |
|
|
17
|
+
|
|
18
|
+
`~/.agents/skills/agent-autoloop` 是指向 `versions/<版本>/node_modules/…/agent-autoloop/skills/agent-autoloop` 的链接。手册里写的 `../../README.md`、`docs/`、`examples/` 和 `plugins/` 源码,打开的就是正在跑的这个版本带的那一份;换了版本,`up` 启动时把链接指过去,以前留在数据目录里的 `skills/` 副本同时删掉。源码检出链到检出自己的 `skills/agent-autoloop`。
|
|
19
|
+
|
|
20
|
+
`init` 把 npm 全局安装的那一份复制进来,服务、登录任务和 `up` 都改成从启动器启动。源码检出不做这件事,`up` 直接跑当前代码。
|
|
21
|
+
|
|
22
|
+
## 自动换版本
|
|
23
|
+
|
|
24
|
+
中台启动后一分钟检查一次 npm,之后每六小时一次。只问官方源 `registry.npmjs.org`,镜像上的 `latest` 不算。
|
|
25
|
+
|
|
26
|
+
1. 有新版本就 `npm install --prefix versions/<版本>` 装到旁边,不碰正在跑的这一份。
|
|
27
|
+
2. 用它自己的入口跑一次 `--version`,对不上版本号就删掉,不留半份。
|
|
28
|
+
3. 写进 `pending.json`,等手上的活:`queued`、`claimed`、`unknown` 的轮次都算。每分钟看一次,已经在跑的轮次不会被打断。
|
|
29
|
+
4. 空了就让中台正常收尾,以退出码 75 退出。启动器把 pending 换成 current(原来的 current 记成 previous),再启动新版本。
|
|
30
|
+
|
|
31
|
+
新版本启动后把 `boot.json` 写成 `ready: true` 才算起来了。90 秒还没写,启动器先 `SIGTERM`、五秒后强制结束;没就绪就退出也算一次失败。连续两次失败,版本记进 `bad.json`,退回 previous;没有可退的版本就停下,等服务管理器再试。
|
|
32
|
+
|
|
33
|
+
同一个版本已经在 current 里时,pending 直接丢掉,不会把上一版记成它自己。
|
|
34
|
+
|
|
35
|
+
## 手动更新
|
|
36
|
+
|
|
37
|
+
`agent-autoloop update` 先数没跑完的轮次,有就拒绝。没有就做上面第 1 到第 3 步,然后重启服务;没装服务时,下次 `up` 换上。
|
|
38
|
+
|
|
39
|
+
`update` 只准备版本,不改 `rules.json`、密钥和记录。投影格式变了会在新版第一次启动时从日志重建,见 [安装说明](../INSTALL.md)。
|
|
40
|
+
|
|
41
|
+
## 关闭
|
|
42
|
+
|
|
43
|
+
- `config.json` 写 `"update": { "autoUpdate": false }`:这台机器不自动检查。手动 `update` 仍然可用。
|
|
44
|
+
- 环境变量 `AGENT_AUTOLOOP_NO_UPDATE=1`,或 `CI=true`:完全不检查,安装冒烟和 CI 用这个。
|
|
45
|
+
- 源码检出本来就不自动更新,`update` 按原来的方式跟 git。
|
|
46
|
+
|
|
47
|
+
想重试一个进了 `bad.json` 的版本,删掉 `bad.json` 再运行 `update`。旧版本的文件夹可以删,只留 current 和 previous;启动器只按指针找版本。
|
|
48
|
+
|
|
49
|
+
启动器自己出错时,中台和服务管理器还在:launchd、systemd 和 Windows 登录任务都会把它重新拉起来,而它只做读指针、起进程、看退出码这三件事,不加载任何程序代码。
|
|
50
|
+
|
|
51
|
+
## 换的是哪一份
|
|
52
|
+
|
|
53
|
+
`agent-autoloop --version` 在 npm 的全局安装上打印 current 指向的版本,在 `versions/` 里的副本上打印自己清单里的版本。启动器拉起的是后者,所以版本号始终是正在跑的代码,不是当初敲命令的那份。
|
package/docs/plugins.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# 写插件
|
|
2
|
+
|
|
3
|
+
先看 [README 的内置插件目录](../README.md#插件体系四个方向都能自由替换)选择已有实现;需要扩展时,从下面三个可运行的最小模板开始,替换业务部分:
|
|
4
|
+
|
|
5
|
+
| 模板 | 已经演示了什么 | 你要替换什么 |
|
|
6
|
+
| ---------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------ |
|
|
7
|
+
| [Agent 模板](../examples/plugins/hello-agent/agent.ts) | 用 `printf` 模拟执行,读取输出、会话编号和「收下了提示词」 | 新 Agent 的启动命令和输出解析 |
|
|
8
|
+
| [通道模板](../examples/plugins/hello-channel/channel.ts) | 领卡片、写到文件、报告送达;通过命令行回答 | 目标平台的发送、更新和回答回调 |
|
|
9
|
+
| [事件插件模板](../examples/plugins/hello-source/source.ts) | 验证 HMAC-SHA256 签名,把模拟订单转换成事件 | 业务系统的验签方式和字段映射 |
|
|
10
|
+
|
|
11
|
+
事件插件、接单程序、通道和命令行共用同一套 HTTP + JSON 接口。只用 Shell 接协议,可以看 [接单脚本](../examples/worker.sh) 和 [通道脚本](../examples/channel.sh):设置中台地址与密钥后运行,需要 `curl`、`jq`。它们适合演示短任务;长任务使用内置接单程序的心跳、停止和恢复能力。
|
|
12
|
+
|
|
13
|
+
一个插件就是一个目录,入口为 `agent.ts`、`channel.ts` 或 `source.ts`。只用 `node:` 模块和自己目录里的文件,类型在插件里声明;不要相对引用引擎源码:装在 `~/.agent-autoloop/plugins/` 的插件,相对路径到不了引擎。内置插件和引擎放在一起发布,才能直接引 `worker/agents.ts` 里的 `findProgram`、`tail` 这些小工具,引擎不反过来引插件。
|
|
14
|
+
|
|
15
|
+
用 `agent-autoloop add <git 地址>` 安装到 `~/.agent-autoloop/plugins/<仓库名>`,也接受本地 Git 仓库。插件名就是那个目录名:仓库名转成小写,只能用小写字母、数字和 `-`,别的名字会被拒绝,并说出它算出来的名字;规则的 `use` 和来源的 `adapter` 都写这个名字。它只克隆,不装依赖、不跑安装脚本、不自动更新。加载时会执行插件,安装目录的同名插件优先。
|
|
16
|
+
|
|
17
|
+
## 先跑起来
|
|
18
|
+
|
|
19
|
+
在引擎目录运行这条命令:它把三个例子分别装进临时中台,实际走完验签、派活、运行、通知和报告,退出后清理。
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
node --disable-warning=ExperimentalWarning --test --test-name-pattern='agent-autoloop add' tests/example-plugins.test.ts
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Agent 插件
|
|
26
|
+
|
|
27
|
+
从 [hello-agent/agent.ts](../examples/plugins/hello-agent/agent.ts) 开始。它用 `printf` 代替模型,克隆到别处也能运行。收下提示词和结束时各打一行,`read` 从第一行就知道这一轮接上了原会话,第二行是它的最后一条消息。
|
|
28
|
+
|
|
29
|
+
| 导出对象的方法 | 作用 |
|
|
30
|
+
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
|
31
|
+
| `command(turn)` | 返回命令参数数组;参数不作为 shell 代码执行 |
|
|
32
|
+
| `read(stdout, code, stderr)` | 返回 `text`、`session`、`usage`、`sessionUsage`、`error`、`finished`、`started`;运行中 `code` 为 `null` |
|
|
33
|
+
| `link(session)` | 可选,打开这个会话的链接。回执写错时,`read` 返回了 `session` 的插件都只重写回执,和有没有链接无关 |
|
|
34
|
+
| `check(program)` | 可选,`doctor` 问它这个 Agent 现在能不能用:能用返回 `null`,否则返回下一步怎么做。参数是规则里给它写的 `program`,没写就不传 |
|
|
35
|
+
|
|
36
|
+
`turn` 一定有的是 `prompt`、`session`、`resume`、`cwd`、`access`、`contextFile`、`folder`,另外五个只有规则里给这个 Agent 写了才有:`model`、`effort`、`tier`、`command`、`program`。`resume` 是这一轮要接回的原会话,新开一轮时是 `null`。`contextFile` 是资料文件,受限 CLI 需要允许读取 `folder`。`program` 是内置插件换成的启动程序,第三方插件用不上,收下也可以不理。`tier` 是服务档位,用的是那个 CLI 自己的叫法,现在只有内置的 Codex 插件用它(传成 `-c service_tier="…"`,`priority` 就是 Codex 应用里的 Fast),别的插件收下不理。那五个都按「可能没有」来读,内置插件就是这么写的:`...(turn.model ? ["--model", turn.model] : [])`、`turn.command ?? []`。`read` 要能处理未写完的输出;CLI 真正完成后才返回 `text`。`read` 抛错或什么也不返回时,还在跑的接着跑,结束后这一轮算没跑成,留在原会话重派。
|
|
37
|
+
|
|
38
|
+
支持 `resume` 的插件,从 Agent 收下提示词起都要返回 `started: true`,包括运行中和出错之后。否则干到一半断了,也会被当成会话接不上,开新会话把业务重做一遍。返回了 `session` 就要按 `turn.resume` 接回原会话:没跑成的重派和写错回执的重写都靠它;接不回去的 CLI 不要返回 `session`。
|
|
39
|
+
|
|
40
|
+
`usage` 是这次启动用掉的量。`input` 算全部输入,`cached` 是其中从缓存读的部分;CLI 报的输入不含缓存时(Claude Code、DSH 就是这样),插件把缓存读写加回 `input`,各家才能放在一起比。有的 CLI 只给整个会话累计到现在的数(Codex 的 Token、Claude Code 的费用),这几项放进 `sessionUsage`,同时要返回 `session`。接单程序启动前记下这个会话上次的累计值,结束后相减,和 `usage` 合起来上报;这些记录放在 `~/.agent-autoloop/worker/usage/`,接单程序中途重启也不会多算。
|
|
41
|
+
|
|
42
|
+
没有记录的续接(换了电脑、升级前就有的会话)或累计值变小时,这几项这次不报,不猜;下一次续接恢复正常。其他程序在同一个会话里用掉的量分不出来,比如本人打开链接接着聊,会算进下一次续接。CLI 改成只报单次时,插件要把这几项改回 `usage`,不要靠数字大小去猜。
|
|
43
|
+
|
|
44
|
+
在规则里选择这个插件:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{ "name": "Hello", "worker": "my-computer", "use": "hello-agent", "access": "read" }
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Codex 的 Windows elevated 沙箱使用专用账号;插件给该账号组增加本轮 `context.json` 的读权限,不更改账号或沙箱模式。Codex 自己也会给用户目录下的文件夹(含数据目录)加这个账号组的读权限,见 [SECURITY](../SECURITY.md)。
|
|
51
|
+
|
|
52
|
+
Windows 原生运行支持 `.exe`/`.com`、PowerShell `.ps1` 和 npm 生成的 `.cmd` 包装(直接执行其 JS 入口或 `.exe`,保留中文、多行及引号)。其他 `.bat`/`.cmd` 不作为 shell 源码启动,请用可执行程序或 `node script.js`。Unix 沿用登录 shell 查找命令,Windows 按 PATH 和 PATHEXT 找;Agent 自己也必须支持当前系统。文中的 shell、curl/jq 教程在 Unix 或 WSL 运行。
|
|
53
|
+
|
|
54
|
+
只需要打印最后一条消息时,用内置 `command` 加参数数组即可,不必写插件。参数里可以用 `{prompt}`、`{model}`、`{effort}`、`{cwd}`、`{context}`,每个参数只替换一轮,替换进去的提示词原样传给程序:提示词里写着 `{cwd}` 或 `$&`,到程序那边也还是这几个字,不会被再替换一次。每个 Agent 进程(包括内置插件配的 `program` 脚本)都能读到环境变量 `AGENT_AUTOLOOP_CONTEXT`(资料文件)和 `AGENT_AUTOLOOP_RUN`(第几轮)。同一轮重试、重写回执时编号不变;回答和到期的复查是新的一轮,编号不同。
|
|
55
|
+
|
|
56
|
+
DeepSeek Harness 有内置 `dsh` 插件,规则里写 `use: "dsh"`,要 0.2.2 或更新,`agent-autoloop doctor` 会查。现在 npm 的 `latest` 还是旧版,要这样装:`npm install -g @deepseek-ai/dsh@next --allow-scripts=koffi,node-pty,@deepseek-ai/dsh-subprocess-local`。新版 npm 默认不跑依赖的安装脚本,不放行这三个包,装完看着正常,一跑才出错。从旧版升上来的,0.2.2 可能读不到 `~/.dsh/.credentials.yaml` 里的 `refs`,报 `MISSING_CREDENTIAL`:把密钥放进环境变量,Linux 的系统服务放 `~/.config/environment.d/*.conf`。只上报 Token,不上报费用。有用户在 WSL2 上用 0.2.2-rc.1 和第三方 OpenAI 兼容服务实测跑通了问答、用量和 `resume`。它以 `dsh headless --json` 跑一轮,从 `session` 事件拿会话编号,用 `--session-id` 续接,把 `step_end` 的用量汇总为 Token,`final` 事件才算跑完;`access` 每次都映射成 `--permission-mode`,要人批准的调用用 `--approval-policy never` 直接拒绝。规则里的 `model`、`effort` 不起作用,用 DSH 自己的配置。没有可打开的桌面会话链接。DSH 默认把会话日志上传给 DeepSeek,见[它的说明](https://github.com/deepseek-ai/deepseek-harness/blob/master/apps/cli/reference/README.md)。
|
|
57
|
+
|
|
58
|
+
ZCode 有内置 `zcode` 插件,规则里写 `use: "zcode"`。它启动随桌面版安装的 CLI,跑 `zcode -p … --json`,一轮结束后打印一个 JSON 对象:从 `sessionId` 取会话编号,`response` 是最后一条消息,`usage` 里的 `inputTokens`、`outputTokens`、`cacheReadTokens` 是这一轮的 Token;下一轮用 `--resume sess_…` 续接。`access` 映射成它自己的模式:`read`→`plan`、`edit`→`edit`、`full`→`yolo`。Windows 上的 CLI 是 `.cjs` 包,Agent 写 `"program": "路径\\zcode.cjs"`,插件会用 node 启动它;写一个别的可执行文件也可以。规则里的 `model`、`effort` 不起作用,模型和提供方由 ZCode 自己的配置决定;CLI 用 `-p` 返回空时,先在 ZCode 里换一个能用的提供方。只上报 Token,不上报费用;没有可打开的桌面会话链接。
|
|
59
|
+
|
|
60
|
+
### 浏览器接入
|
|
61
|
+
|
|
62
|
+
浏览器工具装在运行 Agent 的电脑上,由该 CLI 的工具配置或项目 Skill 提供。Codex 插件启动的是后台 [`codex exec`](https://developers.openai.com/codex/noninteractive/);可以使用它已配置的 [MCP 工具](https://developers.openai.com/codex/mcp/),不能只凭桌面应用能打开网页就认定后台也能访问同一浏览器。
|
|
63
|
+
|
|
64
|
+
Claude 委托 Codex 的完整规则、Skill 和参数调用脚本见[浏览器交接模板](../examples/recipes/browser-handoff/README.md)。入口命令、目标与允许操作由本人配置;网页助手返回证据和会话编号,主任务负责业务与回执。
|
|
65
|
+
|
|
66
|
+
已有专用浏览器入口时,在规则的 `prompt` 或 `skill` 写明实际命令、会话接续方式和允许的操作。只交网页步骤,返回看到的内容、操作结果和阻塞原因;主任务负责业务和中台回执。浏览器入口不是必装组件,中台不捆绑某台电脑的脚本,也不自动修改 CLI 的工具配置。
|
|
67
|
+
|
|
68
|
+
需要网页验收的任务,要用同一后台启动方式实际打开目标页面,核对内容并接续一次会话。缺少可用入口或需要本人恢复连接、登录、验证时,保留未验收项,用现有 `ask` 等待恢复;不要写“没跑成”触发重派,也不能把 HTTP 查询当作已经完成网页验收。
|
|
69
|
+
|
|
70
|
+
## 通道插件
|
|
71
|
+
|
|
72
|
+
从 [hello-channel/channel.ts](../examples/plugins/hello-channel/channel.ts) 开始。它把卡片写进文件,用命令行回答。
|
|
73
|
+
|
|
74
|
+
默认导出异步函数,参数是 `{ hub, options, log, signal }`;`options` 来自 `config.json`,不含中台密钥。
|
|
75
|
+
|
|
76
|
+
| 调用 | 作用 |
|
|
77
|
+
| ------------------------------------- | ----------------------------------------- |
|
|
78
|
+
| `hub.nextCard(50)` | 长轮询领卡片,没卡片返回 `{ card: null }` |
|
|
79
|
+
| `hub.delivered(id, version, ref)` | 报告送达,保存外部消息编号 |
|
|
80
|
+
| `hub.failed(id, version, error)` | 报告发送失败 |
|
|
81
|
+
| `hub.answer(id, { choice, by, ref })` | 转交回答;核对回答人和原消息 |
|
|
82
|
+
|
|
83
|
+
`ref` 为空就发新消息,有值就更新原消息;不能更新时只报告。没报告的卡片一分钟后重派。`signal` 中止时退出;函数在此之前返回或抛错,都记日志并在 30 秒后重启,所以它要一直运行。插件和中台在同一个进程里:没接住的错误只记日志,不让中台退出。
|
|
84
|
+
|
|
85
|
+
在 `rules.json` 登记通道、用 `agent-autoloop key new channel cards` 取密钥,再把下面这项放进 `config.json` 的 `channels`,重启中台:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{ "cards": { "use": "hello-channel", "key": "通道密钥", "file": "/tmp/cards.txt" } }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
能收回调的通道要在规则里设置 `answerers`,没设时通道里谁都能回答,`doctor` 会提醒;只能发文字的通道设置 `links: true`,发送 `card.link`。拿到链接的人能回答这张卡片。
|
|
92
|
+
|
|
93
|
+
通道和中台共用一个 Node 进程,外部调用应异步等待。内置飞书通道的用户查询、发送和更新均异步调用 CLI,发送期间中台仍能接收事件和心跳。
|
|
94
|
+
|
|
95
|
+
## 事件插件
|
|
96
|
+
|
|
97
|
+
从 [hello-source/source.ts](../examples/plugins/hello-source/source.ts) 开始。它检查 `x-shop-signature` 中的 HMAC-SHA256,再把订单变成事件。
|
|
98
|
+
|
|
99
|
+
默认导出同步函数,参数为 `{ headers, body, secret }`。先验签,再解析原文;返回事件数组,无事返回 `[]`,拒绝请求就抛异常。事件插件只翻译,不发请求。
|
|
100
|
+
|
|
101
|
+
在 `rules.json` 登记来源:
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{ "shop": { "name": "商店", "adapter": "hello-source" } }
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
请求地址是 `/v1/in/shop`;秘密放在 `secrets.env` 的 `AGENT_AUTOLOOP_SECRET_SHOP`(来源名转大写,`-` 换成 `_`;改完重启中台),不写进规则。事件必须有稳定的 `id` 和合法的 `type`,可带 `subject`、`summary`、`detail`、`link`,上限见[协议](protocol.md#来源把世界变成事件)。
|
|
108
|
+
|
|
109
|
+
来源能直接发标准 JSON 时不必写插件,用来源密钥调用 `POST /v1/events` 即可,之后用同一把密钥 `GET /v1/events/<编号>` 查它做到哪了(见[协议](protocol.md#来源把世界变成事件))。
|
|
110
|
+
|
|
111
|
+
## access 实际能做什么
|
|
112
|
+
|
|
113
|
+
`access` 由插件翻译,不是中台提供的系统沙箱。以下是未额外放宽本机权限时的行为。
|
|
114
|
+
|
|
115
|
+
| 插件 | `read` | `edit` | `full` |
|
|
116
|
+
| ---------------- | ---------------------------------------------------------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------ |
|
|
117
|
+
| Codex | `read-only`:能跑 shell,不能写文件,命令默认不能联网 | `workspace-write`:能跑 shell、写工作目录和临时目录,命令默认不能联网 | `danger-full-access`:能写文件、跑 shell、联网,无审批 |
|
|
118
|
+
| Claude Code | `plan`:能读文件和运行只读命令;其他命令取决于自动审批及本机规则 | `acceptEdits`:再允许目录内文件编辑和常见文件操作;任意 shell 或联网仍需放行 | `bypassPermissions`:跳过工具审批,没有额外系统隔离 |
|
|
119
|
+
| DeepSeek Harness | `read-only`:不能写文件,读文件和联网不受限 | `workspace-write`:命令和文件改动限于工作目录和临时目录,读文件和联网不受限 | `danger-full-access`:不受限制 |
|
|
120
|
+
| ZCode | `plan`:只读规划,不写文件 | `edit`:自动应用编辑,shell 命令直接执行 | `yolo`:不审批,不受限制 |
|
|
121
|
+
| ACP | Agent 来问时,同意读和搜索 | 再同意工作目录内的编辑 | 同意它来问的所有操作 |
|
|
122
|
+
|
|
123
|
+
Codex 的三个档位已用插件命令实跑;ZCode 已用真实 CLI 跑通 `edit` 模式、提问和回答后的会话续接,`plan`、`yolo` 按它的 `--mode` 说明整理;DeepSeek Harness 和 Claude Code 分别依据 [DSH 文档](https://github.com/deepseek-ai/deepseek-harness/blob/master/apps/cli/reference/README.md)和[官方权限说明](https://code.claude.com/docs/en/permission-modes)整理,没有调用模型实跑。Codex 的命令网络限制与托管搜索、MCP 不是同一个边界,详见[官方沙箱说明](https://learn.chatgpt.com/docs/agent-approvals-security)。用户的 CLI 配置可能改变上述能力;`read` 也不代表读不到本机密钥。
|
|
124
|
+
|
|
125
|
+
ACP 的 `access` 只管 Agent 主动来问的操作。规范允许 Agent 不询问就执行,这种操作 `access` 拦不住,要用 Agent 自己的模式限制,比如 `command` 里写 `env INITIAL_AGENT_MODE=read-only …`。ACP 的 `model`、`effort`、`tier` 不生效,也要在 Agent 自己那边设置。
|
|
126
|
+
|
|
127
|
+
场景模板据此选权限:早报用 `edit` 写本地文件,issue 用 `edit` 改代码并让固定脚本联网取正文,告警用 `read` 看代码和事件附带的调用栈。反馈处理、飞书摘要和邮件分诊用 `edit`,网站排查用 `read`;固定巡检、飞书读取和邮箱读取脚本负责联网,摘要与分诊 Agent 只读完整快照。`command` 和固定脚本以本机账号运行,不受 `access` 约束。
|
|
128
|
+
|
|
129
|
+
## 一致性测试
|
|
130
|
+
|
|
131
|
+
在引擎目录运行协议的现有 HTTP 检查,全部使用临时数据和随机端口:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
node --disable-warning=ExperimentalWarning --test tests/conformance.test.ts
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
检查其他中台实现时,用 `agent-autoloop conformance <测试地址> --config <测试凭据文件>`,文件格式见[协议](protocol.md#一致性和复现)。它会写事件和卡片,只对专用测试中台运行。
|
|
138
|
+
|
|
139
|
+
插件本身的完整接入测试见 [tests/example-plugins.test.ts](../tests/example-plugins.test.ts)。用其他语言写独立进程也可以,参考 [curl/jq 通道](../examples/channel.sh)和[接单程序](../examples/worker.sh)。
|