@saltpub/agent-autoloop 0.0.0-stage → 0.1.3
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 +27 -0
- package/INSTALL.md +120 -0
- package/LICENSE +21 -0
- package/README.en.md +268 -0
- package/README.md +264 -2
- package/SECURITY.md +49 -0
- package/dist/bin/agent-autoloop.js +2 -0
- package/dist/cli/agents.js +14 -0
- package/dist/cli/backup.js +144 -0
- package/dist/cli/dashboard/app.js +424 -0
- package/dist/cli/dashboard/index.html +15 -0
- package/dist/cli/dashboard/style.css +629 -0
- package/dist/cli/dashboard.js +94 -0
- package/dist/cli/explain.js +84 -0
- package/dist/cli/main.js +1142 -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 +272 -0
- package/dist/cli/try.js +6 -0
- package/dist/cli/ui.js +75 -0
- package/dist/cli/uninstall.js +86 -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 +45 -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 +57 -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,84 @@
|
|
|
1
|
+
// `rules explain` and `emit --dry-run`: what this machine's rules file says, without asking a hub or writing a fact.
|
|
2
|
+
import { describeCron, nextRun, parseCron } from "../kernel/cron.js";
|
|
3
|
+
import { cronOf, eventRule, typeMatches } from "../kernel/rules.js";
|
|
4
|
+
import { parseRules } from "../protocol/rules.js";
|
|
5
|
+
import { parseEvent } from "../protocol/validate.js";
|
|
6
|
+
const localZone = () => Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
7
|
+
const clock = (zone) => ({ timeZone: zone, month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", hourCycle: "h23" });
|
|
8
|
+
const when = (rule, rules, now) => eventRule(rule)
|
|
9
|
+
? `来源 ${rule.when.source} · ${rule.when.types.join("、")}`
|
|
10
|
+
: `定时 ${describeCron(cronOf(rule))}(下次 ${new Date(nextRun(parseCron(cronOf(rule)), now, rules.timezone)).toLocaleString("zh-CN", clock(rules.timezone))})`;
|
|
11
|
+
function details(rule, rules, now) {
|
|
12
|
+
const parts = [when(rule, rules, now), `→ ${rule.to}`, rule.cwd];
|
|
13
|
+
if (rule.parallel)
|
|
14
|
+
parts.push(`并发 ${rule.parallel}`);
|
|
15
|
+
if (rule.maxActive)
|
|
16
|
+
parts.push(`本规则最多同时 ${rule.maxActive} 轮`);
|
|
17
|
+
if (rule.channels?.length)
|
|
18
|
+
parts.push(`只发 ${rule.channels.join("、")}`);
|
|
19
|
+
if (rule.resume)
|
|
20
|
+
parts.push("接着上一轮的会话");
|
|
21
|
+
if (rule.title)
|
|
22
|
+
parts.push(`会话标题 ${rule.title}`);
|
|
23
|
+
if (rule.group !== rule.name)
|
|
24
|
+
parts.push(`组 ${rule.group}`);
|
|
25
|
+
if (rule.tell !== "needed")
|
|
26
|
+
parts.push(`通知 ${rule.tell}`);
|
|
27
|
+
if (rule.skill)
|
|
28
|
+
parts.push("有 Skill");
|
|
29
|
+
if (rule.prompt)
|
|
30
|
+
parts.push("有 Prompt");
|
|
31
|
+
if (rule.emits)
|
|
32
|
+
parts.push(`可发 ${rule.emits.source} ${rule.emits.types.join("、")}`);
|
|
33
|
+
return parts.join(" · ");
|
|
34
|
+
}
|
|
35
|
+
/** The rules as this machine would run them, one line per thing an owner asks about. */
|
|
36
|
+
export function explainRules(text, now = Date.now(), zone = localZone()) {
|
|
37
|
+
const rules = parseRules(text, now, zone);
|
|
38
|
+
const lines = [
|
|
39
|
+
`时区 ${rules.timezone};先问你:${rules.askFirst.join("、")};${rules.rules.length} 条规则`,
|
|
40
|
+
`来源:${Object.entries(rules.sources)
|
|
41
|
+
.map(([id, source]) => `${id}(${source.name})`)
|
|
42
|
+
.join("、")}`,
|
|
43
|
+
`Agent:${Object.entries(rules.agents)
|
|
44
|
+
.map(([id, agent]) => {
|
|
45
|
+
const limit = agent.maxActive ? `,最多同时 ${agent.maxActive} 轮` : "";
|
|
46
|
+
return `${id}(${agent.name},${agent.worker},权限 ${agent.access}${limit})`;
|
|
47
|
+
})
|
|
48
|
+
.join("、")}`,
|
|
49
|
+
];
|
|
50
|
+
if (Object.keys(rules.channels).length)
|
|
51
|
+
lines.push(`通道:${Object.entries(rules.channels)
|
|
52
|
+
.map(([id, channel]) => {
|
|
53
|
+
const answerers = channel.answerers?.length ? `,回答人 ${channel.answerers.join("、")}` : "";
|
|
54
|
+
return `${id}(${channel.name}${answerers}${channel.links ? ",带链接" : ""})`;
|
|
55
|
+
})
|
|
56
|
+
.join("、")}`);
|
|
57
|
+
if (rules.defaultChannels)
|
|
58
|
+
lines.push(`没写 channels 的卡片和通知默认只发 ${rules.defaultChannels.join("、")}`);
|
|
59
|
+
lines.push("规则:");
|
|
60
|
+
for (const rule of rules.rules)
|
|
61
|
+
lines.push(` ${rule.name}:${details(rule, rules, now)}`);
|
|
62
|
+
for (const task of rules.elsewhere) {
|
|
63
|
+
const answers = task.cwd ? `;问你的,回答后交给 ${rules.agents[task.to].name} 在 ${task.cwd} 接着做` : "";
|
|
64
|
+
lines.push(` ${task.name}:在别处(${task.where})${describeCron(task.cron)}${answers}`);
|
|
65
|
+
}
|
|
66
|
+
return lines;
|
|
67
|
+
}
|
|
68
|
+
/** What a source event would be handed to, by the rules file alone: no hub, no log, no key. */
|
|
69
|
+
export function previewEvent(text, source, event, now = Date.now(), zone = localZone()) {
|
|
70
|
+
const rules = parseRules(text, now, zone);
|
|
71
|
+
const parsed = parseEvent(event);
|
|
72
|
+
const lines = [`事件:${source} ${parsed.type}${parsed.subject ? ` ${parsed.subject}` : ""}`];
|
|
73
|
+
if (!rules.sources[source])
|
|
74
|
+
lines.push(`来源 ${source} 没有登记在 rules.json 的 sources 里`);
|
|
75
|
+
const matched = rules.rules.filter((rule) => eventRule(rule) && rule.when.source === source && typeMatches(rule.when.types, parsed.type));
|
|
76
|
+
if (!matched.length) {
|
|
77
|
+
lines.push("没有规则接这条事件;真发出去会记成「没有规则接的事件」。");
|
|
78
|
+
return lines;
|
|
79
|
+
}
|
|
80
|
+
lines.push("会派给:");
|
|
81
|
+
for (const rule of matched)
|
|
82
|
+
lines.push(` ${rule.name} → ${rule.to} · ${rule.cwd}`);
|
|
83
|
+
return lines;
|
|
84
|
+
}
|