@xiangyixie/dsh-superagent 0.14.2 → 0.14.4
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 +252 -74
- package/README.en.md +135 -28
- package/README.md +1232 -1167
- package/README.zh.md +1232 -1167
- package/bin/doctor.js +1 -1
- package/cordis.patch.yml +32 -9
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/LONG-GOAL.md +223 -0
- package/lib/board-messages.js +327 -0
- package/lib/board.js +891 -0
- package/lib/client.js +210 -0
- package/lib/console.js +375 -3
- package/lib/doctor.js +1 -0
- package/lib/entry.js +65 -0
- package/lib/index.js +990 -16
- package/lib/long-goal.js +1705 -0
- package/lib/orchestrator.js +498 -25
- package/lib/schedule.js +2 -1
- package/lib/wizard.js +1498 -0
- package/lib/workspace.js +10 -3
- package/package.json +16 -4
- package/public/board.html +1110 -0
- package/public/console.html +1427 -187
package/bin/doctor.js
CHANGED
|
@@ -15,7 +15,7 @@ Check that this copy of dsh-superagent can actually run:
|
|
|
15
15
|
- every file the code imports is shipped by package.json "files" and exists
|
|
16
16
|
- the installed copy matches the version package.json claims
|
|
17
17
|
- the installed files match the published tarball (skipped when offline)
|
|
18
|
-
- the DSH profile mounts the bundle patch and the
|
|
18
|
+
- the DSH profile mounts the bundle patch and the thirteen tools are registered
|
|
19
19
|
- the running Node satisfies "engines"
|
|
20
20
|
|
|
21
21
|
Nothing is installed or modified; the only network access is one public
|
package/cordis.patch.yml
CHANGED
|
@@ -1,9 +1,32 @@
|
|
|
1
|
-
# dsh-superagent bundle layer.
|
|
2
|
-
#
|
|
3
|
-
# Inserts one tools-only plugin row at PROFILE scope, so every session in the
|
|
4
|
-
# profile can start a run. The package never edits the profile's `bundles`
|
|
5
|
-
# list — that entry is the operator's action (`dsh plugin --profile <name> add
|
|
6
|
-
# @xiangyixie/dsh-superagent`).
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
# dsh-superagent bundle layer.
|
|
2
|
+
#
|
|
3
|
+
# Inserts one tools-only plugin row at PROFILE scope, so every session in the
|
|
4
|
+
# profile can start a run. The package never edits the profile's `bundles`
|
|
5
|
+
# list — that entry is the operator's action (`dsh plugin --profile <name> add
|
|
6
|
+
# @xiangyixie/dsh-superagent`).
|
|
7
|
+
#
|
|
8
|
+
# It also declares the tool-less planner preset that `plannerPreset` points at.
|
|
9
|
+
# The host preset schema has no `hidden`/`internal` field, so this preset cannot
|
|
10
|
+
# be removed from the mode picker; naming it in Chinese, describing it, and
|
|
11
|
+
# sorting it last is the closest the schema allows. Without this row a fresh
|
|
12
|
+
# install shows a bare `planner` entry (empty description, first in the list),
|
|
13
|
+
# and picking it leaves the session with no tools at all.
|
|
14
|
+
- insert:
|
|
15
|
+
- id: superagent
|
|
16
|
+
name: '@xiangyixie/dsh-superagent'
|
|
17
|
+
- id: preset-planner
|
|
18
|
+
name: '@deepseek-ai/dsh-agent-preset'
|
|
19
|
+
config:
|
|
20
|
+
id: planner
|
|
21
|
+
name: 插件内部:规划器(请勿选择)
|
|
22
|
+
description: >-
|
|
23
|
+
dsh-superagent 生成计划专用,没有工具权限;手动选中后对话里没有任何工具,请保持使用「标准模式」。
|
|
24
|
+
order: 9999
|
|
25
|
+
plugins:
|
|
26
|
+
- id: persona
|
|
27
|
+
name: '@deepseek-ai/dsh-persona'
|
|
28
|
+
config:
|
|
29
|
+
prefix: >-
|
|
30
|
+
You are a planning assistant. You receive a goal and answer with
|
|
31
|
+
one JSON plan object. You have no tools, so answer from the
|
|
32
|
+
prompt alone.
|
package/docs/DETAIL.md
CHANGED
|
@@ -6,6 +6,7 @@ Long-horizon autonomous runs: give it one goal and it plans parallel subtasks, r
|
|
|
6
6
|
|
|
7
7
|
## What it solves
|
|
8
8
|
|
|
9
|
+
- **Your work spans several domains, and managing sessions costs more than doing the work.** Code, documents, data, and browser steps each get their own session, progress notes, and context; the more of them you run, the easier it is to lose track of where you stopped. The plugin works as a dispatch desk: you state the result you want, and it splits the work, runs it in parallel, tracks progress, and merges the result. You give the orders, make the key calls, and accept the outcome, without tending the conversational details.
|
|
9
10
|
- **A goal that does not fit one step.** The goal is planned into dependent subtasks and advanced step by step instead of being crammed into one conversation.
|
|
10
11
|
- **Work that runs too slowly in sequence.** Independent subtasks run in parallel, each in its own worktree, without overwriting one another.
|
|
11
12
|
- **Runs that get interrupted.** The plan, progress, and produced files are durable; a host restart or a closed conversation does not reset the run.
|
package/docs/DETAIL.zh.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
## 它解决什么问题
|
|
8
8
|
|
|
9
|
+
- **你的事横跨好几个领域,管会话比干活还累。** 代码、文档、数据、网页上的操作,各自都要开会话、记进度、接上下文,一多就乱,还容易忘掉上次做到哪。这个插件当一个调度台用:你说清要什么结果,它拆活、并行、盯进度、最后汇总;你只管下命令、做关键判断、验收结果,不必操心对话里的细枝末节。
|
|
9
10
|
- **目标大,一步做不完。** 把一句话目标拆成有依赖关系的子任务,按计划推进,而不是把所有事塞进一次对话。
|
|
10
11
|
- **串行太慢。** 互不依赖的子任务并行执行,各自在自己的工作区里干活,互不覆盖。
|
|
11
12
|
- **中途会断。** 计划、进度和已产出的文件都落盘;宿主重启或对话结束之后可以继续。
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# 长期目标(Long Goal)
|
|
2
|
+
|
|
3
|
+
一个自然语言目标拆成多个阶段,每个阶段交给一组新的 agent 跨多轮推进;同一时刻可以有多组 agent 并行;宿主重启后从上次未完成的阶段继续,而不是从零重来。
|
|
4
|
+
|
|
5
|
+
本文是设计与边界说明。实现见 `lib/long-goal.js`,测试见 `test/long-goal.test.mjs`。
|
|
6
|
+
|
|
7
|
+
## 1. 与现有概念的关系
|
|
8
|
+
|
|
9
|
+
| 现有概念 | 关系 | 为什么不是替换 |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| run | 长期目标的一个阶段执行一次 = 一个普通 run(每次重试也是一个新 run) | run 已经拥有 planner、依赖图、并行 worker、预算、用量、报告、审计、恢复与看板卡片。重写等于把这些再实现一遍,并让 0.14.3 的路径失去回归保护。 |
|
|
12
|
+
| 任务线(run 的 subtasks) | 阶段内部的并行任务线仍由 run 的 planner 生成,依赖、写冲突和并行上限沿用现有实现 | 长期目标不重新定义“任务”,只负责“哪些阶段可以同时开始、什么时候进入下一阶段”。 |
|
|
13
|
+
| 看板 | 阶段 run 照常出现在看板上;run 的 goal 文本带「长期目标 / 阶段 n/N」前缀,卡片可以直接分辨归属;目标级进度由 `superagent_goal status` 输出 | 不新增第二套看板数据源。看板读 run,goal 读 run 的阶段状态,只有一个事实来源。 |
|
|
14
|
+
| 收件箱 | 阶段 run worker 的提问仍走原有 attention / `superagent_answer`;阶段重试耗尽、停滞这类“目标级”问题走 `superagent_goal answer`,并通过 owner 会话的 followup 送达 | 收件箱已经能处理 run 级问题,目标级问题只需要一个新的路由 id,不需要新的消息系统。 |
|
|
15
|
+
| goal mode(0.14.3) | 阶段内部开 goal mode:一轮不达标就带着失败证据再来一轮,直到验收成立或硬停 | goal mode 是“同一阶段内的多轮”,长期目标是“多阶段之间的推进”。两者组合,而不是二选一。 |
|
|
16
|
+
| 定时计划(schedule) | 不使用。定时计划解决“按时间重复跑”,长期目标解决“一个目标跑到完成” | 把长期目标塞进 schedule 会让计划、窗口、补跑语义混在一起。 |
|
|
17
|
+
|
|
18
|
+
结论:**扩展,不替换**。新增一个薄的目标层(阶段图 + 目标预算 + 跨阶段恢复),阶段执行完全复用 run。
|
|
19
|
+
|
|
20
|
+
## 2. 数据结构
|
|
21
|
+
|
|
22
|
+
长期目标是 `$DSH_HOME/state/superagent/goals/<goalId>.json` 里的一个 JSON 记录,原子写入(临时文件 + rename,Windows 上 EPERM 重试)。阶段 run 仍是 `runs/<runId>.json`,是任务级细节的唯一事实来源。
|
|
23
|
+
|
|
24
|
+
```jsonc
|
|
25
|
+
{
|
|
26
|
+
"id": "g-20261116T101500-4f2a",
|
|
27
|
+
"schemaVersion": 1,
|
|
28
|
+
"goal": "把 dsh-superagent 推进到 1.0:范围、实现、发布验证三个阶段",
|
|
29
|
+
"status": "planning | running | paused | needs-decision | stalled | completed | partial | failed | cancelled | budget-stopped",
|
|
30
|
+
"createdAt": "…", "updatedAt": "…", "startedAt": "…", "finishedAt": null,
|
|
31
|
+
"ownerSessionId": "session-…", // 阶段 run 的 parent,重启后据此恢复
|
|
32
|
+
"cwd": "D:\\work\\plugin-1.0", // 阶段验收命令的工作目录
|
|
33
|
+
"autoResume": true, // 宿主重启后自动接着跑
|
|
34
|
+
"maxParallelPhases": 2, // 同时推进的阶段数
|
|
35
|
+
"maxAttemptsPerPhase": 2, // 一个阶段最多执行几次(含首次)
|
|
36
|
+
"maxRoundsPerPhase": 3, // 阶段 run 内 goal mode 的轮数
|
|
37
|
+
"noProgressRounds": 2, // 阶段 run 内连续同条件失败几轮算停滞
|
|
38
|
+
"phaseBudget": { "maxModelCalls": 40, "maxTokens": 800000 }, // 每次阶段 run 的上限
|
|
39
|
+
"budget": { "maxModelCalls": 120, "maxTokens": 3000000 }, // 整个目标的上限;null = 不额外限制
|
|
40
|
+
"maxWallClockMinutes": 1440,
|
|
41
|
+
"stallAfterMinutes": 180, // 没有阶段完成多久算目标级停滞
|
|
42
|
+
"phases": [{
|
|
43
|
+
"id": "p1",
|
|
44
|
+
"title": "1.0 范围",
|
|
45
|
+
"objective": "盘点现状,写出 1.0 的范围、非目标与验收清单",
|
|
46
|
+
"dependsOn": [],
|
|
47
|
+
"acceptance": [ // 至少一条;check 省略时由验收模型判断
|
|
48
|
+
{ "id": "a1", "text": "docs/ROADMAP-1.0.md 存在且包含验收清单", "check": { "type": "file", "path": "docs/ROADMAP-1.0.md" } }
|
|
49
|
+
],
|
|
50
|
+
"status": "pending | ready | running | verifying | completed | failed | skipped | cancelled | needs-decision",
|
|
51
|
+
"attempts": 0,
|
|
52
|
+
"runIds": [], // 每次尝试的 run;最后一个就是当前/最近一次
|
|
53
|
+
"currentRunId": null,
|
|
54
|
+
"resumeRunId": null, // 宿主重启后要恢复的原 run
|
|
55
|
+
"deliverables": [], // 可选,用于报告汇总
|
|
56
|
+
"lastOutcome": { "runStatus": null, "error": null, "failed": [], "changed": null },
|
|
57
|
+
"startedAt": null, "finishedAt": null
|
|
58
|
+
}],
|
|
59
|
+
"decomposeRunId": null, // 自动拆阶段用的 run
|
|
60
|
+
"decomposeAttempts": 0,
|
|
61
|
+
"decisions": [{
|
|
62
|
+
"id": "d1", "kind": "phase-exhausted | verification-conflict | stalled | worker-question",
|
|
63
|
+
"phaseId": "p2",
|
|
64
|
+
"question": "p2 连续两次失败,是否换一种做法重试?",
|
|
65
|
+
"options": ["retry", "skip", "stop"],
|
|
66
|
+
"reason": "…",
|
|
67
|
+
"answer": null, "answeredAt": null, "createdAt": "…"
|
|
68
|
+
}],
|
|
69
|
+
"decisionSeq": 0,
|
|
70
|
+
"usage": { "modelCalls": 0, "tokens": 0 }, // 所有阶段 run + 拆阶段 run 的合计
|
|
71
|
+
"events": [{ "at": "…", "type": "phase.completed", "phaseId": "p1", "detail": "…" }],
|
|
72
|
+
"progressAt": "…", // 最近一次阶段状态前进的时间
|
|
73
|
+
"noProgressAttempts": 0, // 自 progressAt 起失败的阶段尝试数
|
|
74
|
+
"stoppedReason": null,
|
|
75
|
+
"recovery": { "at": "…", "reason": "host-restart", "phases": ["p2"] }
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
约束:
|
|
80
|
+
|
|
81
|
+
- 阶段数 1–8;id 必须唯一;`dependsOn` 只能引用已存在的阶段;出现环直接拒绝创建,不落盘半成品。
|
|
82
|
+
- 每个阶段至少一条验收条件。用户没写时补一条由验收模型判断的条件(“该阶段目标已经达成,且报告给出可核对证据”)。
|
|
83
|
+
- 所有上限只收紧不放大:阶段预算再大也不能超过目标剩余预算。
|
|
84
|
+
|
|
85
|
+
## 3. 状态机
|
|
86
|
+
|
|
87
|
+
### 3.1 目标
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
create ──> planning ──> running ──> completed
|
|
91
|
+
│ │ │
|
|
92
|
+
│ │ ├─> partial (有阶段被人工 skip,其余完成)
|
|
93
|
+
│ │ ├─> failed (阶段永久失败且人工选择 stop)
|
|
94
|
+
│ │ ├─> stalled (无进展,等人决定)
|
|
95
|
+
│ │ ├─> needs-decision(有开放式问题/阶段重试耗尽)
|
|
96
|
+
│ │ └─> budget-stopped(目标预算耗尽)
|
|
97
|
+
│ └─> paused ──resume──> running
|
|
98
|
+
└─> failed(拆阶段失败,重试一次后仍不可用;不再重试)
|
|
99
|
+
任意状态 ──cancel──> cancelled
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
- `planning`:有 `decomposeRunId` 时只等这个 run;用户显式给了 `phases` 时跳过。
|
|
103
|
+
- `running`:每个 tick 结算已完成阶段、启动依赖已满足的阶段,最多 `maxParallelPhases` 个。
|
|
104
|
+
- `needs-decision`:至少一个问题未回答。**不启动新阶段**;已经在跑的阶段 run 继续跑完,结果不会丢。
|
|
105
|
+
- `paused`:人工暂停或宿主重启后暂时找不到 owner 会话。不启动新阶段。
|
|
106
|
+
- `stalled`:目标级停滞。不自动重试,等人选择继续或停止。
|
|
107
|
+
- `completed`:所有阶段 completed。
|
|
108
|
+
- `partial`:所有阶段进入终态,但有 skipped(人工跳过)或 failed(人工选择继续),其余完成。
|
|
109
|
+
- `budget-stopped`:目标预算耗尽,停止派发,不重试。
|
|
110
|
+
|
|
111
|
+
### 3.2 阶段
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
pending ──依赖完成──> ready ──启动 run──> running ──run 终态──> verifying
|
|
115
|
+
│ │
|
|
116
|
+
│ ├─> completed
|
|
117
|
+
│ ├─> ready(可重试,attempts+1)
|
|
118
|
+
│ ├─> needs-decision(run 在提问)
|
|
119
|
+
│ └─> failed(重试耗尽/不可重试)
|
|
120
|
+
pending ──依赖失败/跳过──> skipped
|
|
121
|
+
interrupted ──宿主重启──> ready(resumeRunId=原 run,恢复而不是新建)
|
|
122
|
+
任意阶段 ──目标取消──> cancelled
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- `verifying` 是结算瞬间的状态:读 run 的 `goalMode.achieved`、终态、失败条件,决定 completed / retry / needs-decision / failed。
|
|
126
|
+
- `ready` + `resumeRunId` 表示“恢复原 run”;没有 `resumeRunId` 才是“新建一次尝试”。
|
|
127
|
+
- 阶段 run 的 `status === 'completed'` 在 goal mode 下等价于验收成立;`partial`/`failed` 才进入重试判定。
|
|
128
|
+
|
|
129
|
+
## 4. 依赖与并行
|
|
130
|
+
|
|
131
|
+
- 阶段依赖是显式的 `dependsOn`。只有全部依赖 `completed` 才变 `ready`;依赖 `failed`/`skipped` 的阶段直接 `skipped`(级联,不重跑)。
|
|
132
|
+
- 同一 tick 可以启动多个互不依赖的阶段;上限 `maxParallelPhases`,同时受 `maxActiveRuns` 约束(超出的阶段 run 排队,不丢)。
|
|
133
|
+
- 阶段内部的任务线并行仍由 run 的 `maxParallel` 与写冲突检测负责。长期目标不提高这个值。
|
|
134
|
+
- 阶段 run 的 goal 文本带阶段编号和已完成阶段的结论摘要,后续阶段能读到前序产出,不需要共享内存。
|
|
135
|
+
|
|
136
|
+
## 5. 预算
|
|
137
|
+
|
|
138
|
+
三层,全部是硬停:
|
|
139
|
+
|
|
140
|
+
1. **目标预算** `budget`:所有阶段 run、拆阶段 run、重试 run 的用量合计。达到即 `budget-stopped`,不再派发。
|
|
141
|
+
2. **阶段预算** `phaseBudget`:每个阶段 run 自己的一次上限(goal mode 的 `budget`,同时进入 run limits)。跑飞只影响一个阶段,不会烧穿整个目标。
|
|
142
|
+
3. **阶段内轮次** `maxRoundsPerPhase` + `maxWallClockMinutes`:由 goal mode 执行,防止同一阶段无限重来。
|
|
143
|
+
|
|
144
|
+
派发前计算 `remaining = budget - spent`,把阶段预算收紧到 `min(phaseBudget, remaining)`。剩余为 0 时不启动。
|
|
145
|
+
|
|
146
|
+
## 6. 停滞检测
|
|
147
|
+
|
|
148
|
+
两层,分别回答“这个阶段是不是在原地打转”和“整个目标是不是没有前进”。
|
|
149
|
+
|
|
150
|
+
阶段级(复用 goal mode 的 `assessRound`):
|
|
151
|
+
|
|
152
|
+
- 有机器验收且这一轮没有改动任何文件 → `no-changes`,阶段 run 立即停。
|
|
153
|
+
- 同一个失败条件连续 `noProgressRounds` 轮 → `no-progress`。
|
|
154
|
+
- 这两种结果都进入阶段重试;重试指令必须写清“上一轮失败在哪个条件、下一步改什么”,不允许只写“再试一次”。
|
|
155
|
+
|
|
156
|
+
目标级:
|
|
157
|
+
|
|
158
|
+
- `progressAt` 只在阶段 completed、skipped 或人工回答后前进。
|
|
159
|
+
- 距 `progressAt` 超过 `stallAfterMinutes`,或连续 `maxAttemptsPerPhase * 2` 次阶段尝试都没有带来阶段完成 → `stalled`,写一条 decision(选项:`continue` / `stop`),**不自动重试**。
|
|
160
|
+
- 没有 running 阶段、也没有 ready 阶段,剩余阶段全部被失败/跳过依赖卡死 → `failed`(死锁不可通过等待解决)。
|
|
161
|
+
|
|
162
|
+
## 7. 人工介入点
|
|
163
|
+
|
|
164
|
+
必须问人:
|
|
165
|
+
|
|
166
|
+
- 阶段重试耗尽:`phase-exhausted`,选项 `retry`(带一句新指示,重置尝试次数并新建 run)/ `skip`(级联跳过下游)/ `stop`。
|
|
167
|
+
- 目标级停滞:`stalled`,选项 `continue`(重置停滞计数,允许再推进)/ `stop`。
|
|
168
|
+
- 阶段 run 的 worker 主动提问(attention):目标转 `needs-decision`,问题原文和 `runId/attentionId` 一起显示,用现有 `superagent_answer` 回答;目标层不复制一份问题。
|
|
169
|
+
- 验收证据互相矛盾:`verification-conflict`,选项 `accept`(以机器校验为准,计为完成)/ `retry`(换人重试)/ `stop`。两个方向都不算达成:
|
|
170
|
+
- 机器校验通过、但 worker 自己的结论是否定的(held / failed / 明说没能验证,例如 worker shell 里 `spawn EPERM` 而宿主进程里同一命令 exit 0);
|
|
171
|
+
- 机器校验失败、但 worker 或验收模型声称成功(exit code 是事实,不是意见)。
|
|
172
|
+
decision 的 `source.worker` 保存 worker 原话,`source.machine` 保存命令、`exitCode`、`detail`,便于人工对照。
|
|
173
|
+
- 权限策略拦截/需要审批:按不可重试失败处理,等人通过现有审批卡批准后回答 `retry`。
|
|
174
|
+
- 宿主重启后原会话无法恢复:`paused`,等人从新会话 `superagent_goal resume`。
|
|
175
|
+
|
|
176
|
+
直接失败、不重试:
|
|
177
|
+
|
|
178
|
+
- 拆阶段返回的计划不可解析/不合法,修复一次后仍不合法 → `failed`。
|
|
179
|
+
- 阶段依赖有环、引用不存在的阶段 → 创建时直接报错,不创建目标。
|
|
180
|
+
- 目标预算耗尽 → `budget-stopped`,不靠重试绕过。
|
|
181
|
+
- 显式拒绝(权限、能力缺失)→ 阶段 `failed`,不自动重试;是否继续由人决定。
|
|
182
|
+
- 用户 `cancel` → `cancelled`;用户 `pause` → `paused`。
|
|
183
|
+
|
|
184
|
+
## 8. 重启恢复
|
|
185
|
+
|
|
186
|
+
持久化的是目标记录 + 每个阶段引用的 run id;任务级细节不复制。
|
|
187
|
+
|
|
188
|
+
宿主启动顺序:
|
|
189
|
+
|
|
190
|
+
1. `orchestrator.recover()` 把上一个进程遗留的活跃 run 标记为 `interrupted`,并释放 run 锁。
|
|
191
|
+
2. `longGoal.init()` 读取所有目标;对 `autoResume` 且状态为 `planning/running` 的目标:
|
|
192
|
+
- 阶段 `currentRunId` 对应 run 是 `interrupted` → 阶段置 `ready`,记 `resumeRunId`;目标保持 `running`,写 `recovery`。
|
|
193
|
+
- 拆阶段 run 是 `interrupted` → 保留 id,下一 tick 恢复同一个 run(不重新拆)。
|
|
194
|
+
- 阶段 run 已经 `completed` 但目标没来得及记账(崩溃窗口)→ 直接记阶段完成并推进。
|
|
195
|
+
3. tick 解析 owner 会话(与 schedule 相同的恢复顺序:live → resume 持久会话 → create 新会话)。解析成功才恢复/启动 run;失败则目标 `paused`,不猜。
|
|
196
|
+
4. 恢复阶段 run 用 `orchestrator.resume(runId)`:已完成的 subtask 保持完成,只继续没做完的,**不会重跑已完成的阶段**。
|
|
197
|
+
5. 每个目标在派发/恢复时持有 `goals/<id>.lock`(`acquireFileLock`,死进程可回收),避免两个宿主进程同时推进同一目标。
|
|
198
|
+
|
|
199
|
+
## 9. 工具面
|
|
200
|
+
|
|
201
|
+
一个工具,动作枚举:
|
|
202
|
+
|
|
203
|
+
- `superagent_goal action=create goal=... [phases=[...]] [budget=...] [phase_budget=...] ...`
|
|
204
|
+
- `superagent_goal action=status goal_id=...`
|
|
205
|
+
- `superagent_goal action=list`
|
|
206
|
+
- `superagent_goal action=answer goal_id=... decision_id=... answer=retry|skip|stop|continue [note=...]`
|
|
207
|
+
- `superagent_goal action=resume|pause|cancel goal_id=...`
|
|
208
|
+
|
|
209
|
+
阶段 run 继续用 `superagent_status` / `superagent_cancel` / `superagent_answer` 观察和操作。
|
|
210
|
+
|
|
211
|
+
## 10. 进度可见
|
|
212
|
+
|
|
213
|
+
- `superagent_goal status` 输出:目标状态、每个阶段的 status/attempts/runId、当前 run 的进度行、验收通过数、下一步。
|
|
214
|
+
- 每个阶段完成、进入 needs-decision、目标完成/停止时,向 owner 会话发一条 followup(走现有 outbox,不另建消息通道)。
|
|
215
|
+
- 阶段 run 本身在看板上有卡片;goal 文本前缀让卡片能归属到阶段。
|
|
216
|
+
- 不做截图式“证明”:验收结论以 run 文件里的 exit code、`goalMode.checks` 和 goal JSON 的阶段状态为准。
|
|
217
|
+
|
|
218
|
+
## 11. 本期不做
|
|
219
|
+
|
|
220
|
+
- 不做独立的长期目标看板页面;复用 run 卡片 + status。
|
|
221
|
+
- 不做跨目标共享记忆/知识库;阶段之间的上下文通过阶段 goal 文本里的前序摘要传递。
|
|
222
|
+
- 不修改宿主源码,不改变沙箱/权限默认值,不为跑通放宽审批。
|
|
223
|
+
- 不碰 0.14.3 的发布路径;新代码在 `feat/long-goal` 分支,合并等发布完成后再定。
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-superagent — the Chinese copy the board shows to a person.
|
|
3
|
+
*
|
|
4
|
+
* Every string here answers "what happened, why do I care, what can I do".
|
|
5
|
+
* Raw error text is kept as `detail` so the page can fold it away instead of
|
|
6
|
+
* leading with a stack trace.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-superagent/board-messages
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const RUN_STATUS = Object.freeze({
|
|
12
|
+
queued: '排队中',
|
|
13
|
+
planning: '正在拆解任务',
|
|
14
|
+
running: '正在执行',
|
|
15
|
+
aggregating: '正在汇总结果',
|
|
16
|
+
completed: '已完成',
|
|
17
|
+
partial: '部分完成',
|
|
18
|
+
failed: '失败',
|
|
19
|
+
cancelled: '已取消',
|
|
20
|
+
interrupted: '被中断,可继续',
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
export const SUBTASK_STATUS = Object.freeze({
|
|
24
|
+
pending: '等待执行',
|
|
25
|
+
waiting: '等待前置任务',
|
|
26
|
+
running: '正在执行',
|
|
27
|
+
completed: '已完成',
|
|
28
|
+
failed: '失败',
|
|
29
|
+
skipped: '已跳过',
|
|
30
|
+
unverified: '等你确认',
|
|
31
|
+
cancelled: '已取消',
|
|
32
|
+
blocked: '缺少能力,未启动',
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
export const INBOX_KIND = Object.freeze({
|
|
36
|
+
question: '需要你回答',
|
|
37
|
+
review: '需要你验收',
|
|
38
|
+
permission: '需要你授权',
|
|
39
|
+
human: '需要你亲自操作',
|
|
40
|
+
resume: '需要你继续',
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
export function runStatusLabel(status) {
|
|
44
|
+
return RUN_STATUS[status] ?? (status ? `未知状态(${status})` : '未知状态')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function subtaskStatusLabel(status) {
|
|
48
|
+
return SUBTASK_STATUS[status] ?? (status ? `未知状态(${status})` : '未知状态')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const CAPABILITY_HINTS = Object.freeze({
|
|
52
|
+
browser: '在宿主的工具配置里启用 runtime.browser,或换一个带浏览器工具的会话。',
|
|
53
|
+
desktop: '在宿主配置里启用 runtime.desktop,或在有桌面控制能力的会话里重跑。',
|
|
54
|
+
shell: '给当前会话加上命令执行工具,或在支持命令的会话里重跑。',
|
|
55
|
+
network: '当前会话禁用了联网工具;换一个有联网能力的会话再重跑。',
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
export function capabilityHint(name) {
|
|
59
|
+
return CAPABILITY_HINTS[name] ?? `给当前会话加上提供「${name}」的工具,然后从待办里点重跑。`
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function textOf(value) {
|
|
63
|
+
return typeof value === 'string' ? value.trim() : ''
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function firstMissing(subtask) {
|
|
67
|
+
return Array.isArray(subtask?.missingCapabilities) ? subtask.missingCapabilities.filter(Boolean) : []
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Explain one failure in plain Chinese.
|
|
72
|
+
*
|
|
73
|
+
* @param {object} run - run record, or a subtask-bearing view.
|
|
74
|
+
* @param {object | null} [subtask] - the subtask the failure belongs to.
|
|
75
|
+
* @returns {{ code: string, title: string, what: string, why: string, action: object | null, detail: string | null }}
|
|
76
|
+
*/
|
|
77
|
+
export function explainFailure(run, subtask = null) {
|
|
78
|
+
const raw = textOf(subtask?.error) || textOf(subtask?.blockedReason) || textOf(subtask?.unverifiedReason)
|
|
79
|
+
|| textOf(run?.error) || ''
|
|
80
|
+
const missing = firstMissing(subtask)
|
|
81
|
+
const source = subtask ?? {}
|
|
82
|
+
const where = source.title ? `「${source.title}」` : '这个任务'
|
|
83
|
+
|
|
84
|
+
if (missing.length > 0 || source.blockKind === 'capability') {
|
|
85
|
+
return {
|
|
86
|
+
code: 'capability-missing',
|
|
87
|
+
title: '缺少这项能力,任务没有开始',
|
|
88
|
+
what: `${where}需要 ${missing.join('、') || '一个当前会话没有的工具'},当前会话没有提供,所以它没有启动,也没有花 token。`,
|
|
89
|
+
why: '能力预检在开工前就拦住了它,这是有意的:让一个没有工具的模型硬做,只会编造结果。',
|
|
90
|
+
action: { kind: 'config', label: '看看怎么补上这项能力' },
|
|
91
|
+
detail: raw || null,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (/plan rejected|no parsable plan|planner did not return a usable plan|planner reply|plan is not|unparsable/i.test(raw)) {
|
|
96
|
+
return {
|
|
97
|
+
code: 'plan-unusable',
|
|
98
|
+
title: '规划器没有给出能执行的计划',
|
|
99
|
+
what: '任务在拆解阶段就停了,一个子任务都没有启动。常见原因是模型回复不是合法 JSON,或计划里出现了循环依赖。',
|
|
100
|
+
why: '与其拿一份看不懂的计划硬跑,不如停下来把原因告给你,这样不会白花钱。',
|
|
101
|
+
action: { kind: 'retry', label: '重新规划并重试' },
|
|
102
|
+
detail: raw || null,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (/empty deliverable|deliverable|交付物|expected a .* file|not a file|misplaced/i.test(raw)) {
|
|
107
|
+
return {
|
|
108
|
+
code: 'deliverable-missing',
|
|
109
|
+
title: '子任务说做完了,但交付物没通过检查',
|
|
110
|
+
what: `${where}声明要交出的文件或结果没有通过校验:可能不存在、是空的、类型不对,或被写到了别的目录。`,
|
|
111
|
+
why: '完成与否看的是产物,不是模型说自己做完了。没有产物的「完成」会污染最后的报告。',
|
|
112
|
+
action: { kind: 'rerun', label: '让这条子任务重做' },
|
|
113
|
+
detail: raw || null,
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (/spawn\s+EPERM/i.test(raw)) {
|
|
118
|
+
return {
|
|
119
|
+
code: 'spawn-eperm',
|
|
120
|
+
title: '系统拒绝了启动子任务进程',
|
|
121
|
+
what: '宿主沙箱不允许再启动一个子进程(spawn EPERM)。这是宿主的权限边界,不是任务本身做错了。',
|
|
122
|
+
why: '常见于沙箱权限过严或临时目录不可写;子任务需要在自己的会话里启动。',
|
|
123
|
+
action: { kind: 'config', label: '查看沙箱设置说明' },
|
|
124
|
+
detail: raw || null,
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (/sandbox|EPERM|EACCES|not writable|cannot write|write denied|ACL|permission denied|access is denied/i.test(raw)) {
|
|
129
|
+
return {
|
|
130
|
+
code: 'sandbox-write',
|
|
131
|
+
title: '沙箱不允许写入这个目录',
|
|
132
|
+
what: `${where}需要写文件,但目标目录不在当前会话的可写范围里,写入被拒绝了。`,
|
|
133
|
+
why: '沙箱的可写边界跟随父会话的工作目录;工作目录和任务目录不一致时会这样。',
|
|
134
|
+
action: { kind: 'config', label: '查看工作目录设置' },
|
|
135
|
+
detail: raw || null,
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (/child stopped with reason "?error"?|subagent (failed|stopped)|nothing came back from the child/i.test(raw)) {
|
|
140
|
+
return {
|
|
141
|
+
code: 'model-unavailable',
|
|
142
|
+
title: '子任务没能跑起来,可能是模型或端点不可用',
|
|
143
|
+
what: `${where}在第一次调用模型时就停下了,没有产出。常见原因是模型名写错、端点连不上、密钥或额度失效,也可能是启动子会话失败。`,
|
|
144
|
+
why: '任务本身还没开始做,重试的成本很低;先确认模型配置,再让它重跑。',
|
|
145
|
+
action: { kind: 'model', label: '检查模型配置' },
|
|
146
|
+
detail: raw || null,
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (/subagent-unavailable|ECONNREFUSED|ENOTFOUND|ETIMEDOUT|unauthorized|401|403|429|model.*(not found|unavailable)|endpoint|provider|api key|rate limit|额度/i.test(raw)) {
|
|
151
|
+
return {
|
|
152
|
+
code: 'model-unavailable',
|
|
153
|
+
title: '模型或接口暂时不可用',
|
|
154
|
+
what: '子任务需要调用模型,但请求被拒绝、超时,或这个模型在当前配置里找不到。',
|
|
155
|
+
why: '这通常是地址、密钥、额度或模型名的问题,任务本身没有被执行。',
|
|
156
|
+
action: { kind: 'model', label: '检查模型配置' },
|
|
157
|
+
detail: raw || null,
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (/deadline|timed? ?out|budget|max(imum)? (spend|tokens|model calls)|quota|额度|超时/i.test(raw)) {
|
|
162
|
+
return {
|
|
163
|
+
code: 'budget-or-timeout',
|
|
164
|
+
title: '预算或时间用完了',
|
|
165
|
+
what: '运行达到了时间、token 或花费上限,剩下的工作没有继续。已经完成的部分会保留。',
|
|
166
|
+
why: '上限是为了避免一次运行花掉太多;提高上限或缩小目标后可以继续。',
|
|
167
|
+
action: { kind: 'retry', label: '继续未完成的工作' },
|
|
168
|
+
detail: raw || null,
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (/owning session .* is not live|owner session|not live/i.test(raw)) {
|
|
173
|
+
return {
|
|
174
|
+
code: 'schedule-owner-gone',
|
|
175
|
+
title: '定时计划的发起会话已经关闭',
|
|
176
|
+
what: '定时任务由创建它的会话发起;那个会话已经不在了,所以这次窗口没有执行。',
|
|
177
|
+
why: '定时运行需要一个活着的会话来承载权限和模型配置。',
|
|
178
|
+
action: { kind: 'config', label: '查看定时任务说明' },
|
|
179
|
+
detail: raw || null,
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (/host process stopped while the run was active|run was interrupted|interrupted while running/i.test(raw)) {
|
|
184
|
+
return {
|
|
185
|
+
code: 'interrupted',
|
|
186
|
+
title: '宿主在运行中途停下来了',
|
|
187
|
+
what: '这次运行还没结束,宿主进程就退出了。子任务的记录都在,可以接着做。',
|
|
188
|
+
why: '重启、升级或手动关掉宿主都会这样;已完成的子任务不会重跑。',
|
|
189
|
+
action: { kind: 'retry', label: '接着跑完这次运行' },
|
|
190
|
+
detail: raw || null,
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (source.status === 'cancelled') {
|
|
195
|
+
return {
|
|
196
|
+
code: 'cancelled',
|
|
197
|
+
title: '这条子任务被你取消了',
|
|
198
|
+
what: '它停下了,同一次运行里的其他子任务不受影响。依赖它的子任务会被跳过,并注明原因。',
|
|
199
|
+
why: '取消只停这一条,不会重跑整个任务。',
|
|
200
|
+
action: { kind: 'rerun', label: '重新运行这一条' },
|
|
201
|
+
detail: null,
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (source.status === 'unverified') {
|
|
206
|
+
return {
|
|
207
|
+
code: 'needs-review',
|
|
208
|
+
title: '交付物需要你确认',
|
|
209
|
+
what: `${where}写出了文件,但当前会话没有能力判断它是否正确,所以没有算作完成。`,
|
|
210
|
+
why: '让一个无法验证的模型自称完成,会污染最终报告;这一票留给你。',
|
|
211
|
+
action: { kind: 'review', label: '去验收' },
|
|
212
|
+
detail: raw || null,
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
code: 'unknown',
|
|
218
|
+
title: '运行失败了',
|
|
219
|
+
what: raw ? `失败信息:${raw}` : '没有拿到具体错误。可以先重试;如果重复出现,把诊断信息复制出来。',
|
|
220
|
+
why: '这条错误不在已知类型里,原始信息保留在下面。',
|
|
221
|
+
action: { kind: 'retry', label: '重试' },
|
|
222
|
+
detail: raw || null,
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Explain a whole run. Subtask failures win over the run's own summary because
|
|
228
|
+
* they name the thing that actually broke.
|
|
229
|
+
*
|
|
230
|
+
* @param {object} run - run record.
|
|
231
|
+
* @returns {object | null} an explanation, or null when nothing failed.
|
|
232
|
+
*/
|
|
233
|
+
export function explainRun(run) {
|
|
234
|
+
const failed = (run?.subtasks ?? []).find(subtask => subtask.status === 'failed' && subtask.error)
|
|
235
|
+
if (failed) return { ...explainFailure(run, failed), subtaskKey: failed.key ?? null }
|
|
236
|
+
const blocked = (run?.subtasks ?? []).find(subtask => subtask.status === 'blocked')
|
|
237
|
+
if (blocked) return { ...explainFailure(run, blocked), subtaskKey: blocked.key ?? null }
|
|
238
|
+
const unverified = (run?.subtasks ?? []).find(subtask => subtask.status === 'unverified')
|
|
239
|
+
if (unverified) return { ...explainFailure(run, unverified), subtaskKey: unverified.key ?? null }
|
|
240
|
+
if (run?.error) return explainFailure(run, null)
|
|
241
|
+
return null
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** A short, non-technical label for why a subtask never ran. */
|
|
245
|
+
export function skipReason(subtask, run) {
|
|
246
|
+
if (subtask?.status !== 'skipped') return null
|
|
247
|
+
const upstream = Array.isArray(subtask.waitingOn) && subtask.waitingOn.length > 0
|
|
248
|
+
? subtask.waitingOn
|
|
249
|
+
: (subtask.dependsOn ?? [])
|
|
250
|
+
const names = upstream.map(key => {
|
|
251
|
+
const other = (run?.subtasks ?? []).find(item => item.key === key)
|
|
252
|
+
if (!other) return key
|
|
253
|
+
return `${other.title || key}(${subtaskStatusLabel(other.status)})`
|
|
254
|
+
})
|
|
255
|
+
if (names.length > 0) return `前置任务没有完成:${names.join('、')}`
|
|
256
|
+
return subtask.skippedReason || '前置任务没有完成'
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const PARAM_COPY = Object.freeze({
|
|
260
|
+
symptom: { label: '故障现象', hint: '粘贴真实报错或错误输出,不要转述' },
|
|
261
|
+
reproduction: { label: '复现步骤', hint: '能触发问题的命令或操作步骤' },
|
|
262
|
+
expected: { label: '期望结果', hint: '正确时应有的行为' },
|
|
263
|
+
scope: { label: '允许改动的范围', hint: '可改的文件或模块,以及不能碰的部分' },
|
|
264
|
+
target: { label: '要审查的对象', hint: 'diff、文件或模块' },
|
|
265
|
+
focus: { label: '审查重点', hint: '正确性、安全、性能、兼容性等' },
|
|
266
|
+
verification: { label: '验证方式', hint: '证明修复有效的命令或检查' },
|
|
267
|
+
change: { label: '改了什么', hint: '代码或配置的变更内容' },
|
|
268
|
+
audience: { label: '读者是谁', hint: '他们已具备哪些背景知识' },
|
|
269
|
+
sources: { label: '权威来源', hint: '保存当前事实的文件' },
|
|
270
|
+
question: { label: '要研究的问题', hint: '报告必须回答的问题' },
|
|
271
|
+
scope_research: { label: '范围与限制', hint: '时间范围、可用或不可用的来源' },
|
|
272
|
+
purpose: { label: '报告用途', hint: '这份报告要支持哪个决定' },
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
export function parameterCopy(name, templateId) {
|
|
276
|
+
// "scope" means different things: files a fix may touch, versus the range a
|
|
277
|
+
// report covers. The label has to match the template that asks for it.
|
|
278
|
+
if (name === 'scope' && templateId === 'research-report') return PARAM_COPY.scope_research
|
|
279
|
+
return PARAM_COPY[name] ?? { label: name, hint: '按模板要求填写' }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const TEMPLATE_COPY = Object.freeze({
|
|
283
|
+
'bugfix-verify': {
|
|
284
|
+
title: '缺陷修复并验证',
|
|
285
|
+
purpose: '修一个已知的缺陷,并用测试证明修好了',
|
|
286
|
+
bestFor: '有稳定复现步骤的 bug',
|
|
287
|
+
estimate: 3,
|
|
288
|
+
translated: true,
|
|
289
|
+
},
|
|
290
|
+
'review-fix': {
|
|
291
|
+
title: '审查并修复代码问题',
|
|
292
|
+
purpose: '审查一段代码,并把确认的问题直接修掉',
|
|
293
|
+
bestFor: '提交前审查、模块体检',
|
|
294
|
+
estimate: 3,
|
|
295
|
+
translated: true,
|
|
296
|
+
},
|
|
297
|
+
'docs-examples': {
|
|
298
|
+
title: '更新文档与示例',
|
|
299
|
+
purpose: '让文档和示例与代码的真实行为一致',
|
|
300
|
+
bestFor: '改了接口、配置或命令之后',
|
|
301
|
+
estimate: 2,
|
|
302
|
+
translated: true,
|
|
303
|
+
},
|
|
304
|
+
'research-report': {
|
|
305
|
+
title: '调研并写报告',
|
|
306
|
+
purpose: '比较多个来源,产出一份有证据的调研报告',
|
|
307
|
+
bestFor: '需要结论和推荐动作的问题',
|
|
308
|
+
estimate: 3,
|
|
309
|
+
translated: true,
|
|
310
|
+
},
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
export function templateCopy(id) {
|
|
314
|
+
return TEMPLATE_COPY[id] ?? {
|
|
315
|
+
title: null,
|
|
316
|
+
purpose: '按模板发起一次多子任务运行',
|
|
317
|
+
bestFor: '不确定时先看模板说明',
|
|
318
|
+
estimate: 3,
|
|
319
|
+
translated: false,
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** One sentence a person can act on, without reading the stack. */
|
|
324
|
+
export function humanizeErrorText(text) {
|
|
325
|
+
const explanation = explainFailure({ error: text }, null)
|
|
326
|
+
return explanation.title
|
|
327
|
+
}
|