dsh-beta-battle-mode 0.2.0 → 0.3.0
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/README.md +27 -1
- package/cordis.patch.yml +10 -0
- package/lib/chairman-ledger.js +378 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -96,9 +96,10 @@ DSH 的层叠顺序是 **bundle 层 → 你的 profile patch 层**。直接改
|
|
|
96
96
|
|
|
97
97
|
| 文件 | 作用 |
|
|
98
98
|
|---|---|
|
|
99
|
-
| `cordis.patch.yml` | 预设定义:persona
|
|
99
|
+
| `cordis.patch.yml` | 预设定义:persona + 30 条插件声明(官方插件为主,3 条自研) |
|
|
100
100
|
| `lib/compaction-badge.js` | 压缩引擎:读工作日志当 checkpoint,零模型调用 |
|
|
101
101
|
| `lib/goal-round-reminder.js` | goal 续轮时追加指挥官提醒 |
|
|
102
|
+
| `lib/chairman-ledger.js` | 主席原文台账:每句用户原话落到 `.local/主席原文/`,附当时在问的问题指针;提供 `ledger_search`(一天台账 + 问题交给独立模型检索)/ `ledger_show`(按序号展开原文)两个工具 |
|
|
102
103
|
|
|
103
104
|
压缩流程:
|
|
104
105
|
|
|
@@ -110,6 +111,30 @@ DSH 的层叠顺序是 **bundle 层 → 你的 profile patch 层**。直接改
|
|
|
110
111
|
|
|
111
112
|
全程不在轮次中间打断,也不会和下级通知抢时间。
|
|
112
113
|
|
|
114
|
+
### 主席原文台账
|
|
115
|
+
|
|
116
|
+
裁决丢失最常见的形式不是"忘了",是**根本没有一条可检索的记录**:原话散在对话里,一压缩就没了。
|
|
117
|
+
|
|
118
|
+
`chairman-ledger` 把每句用户原话落到项目的 `.local/主席原文/utterances-YYYY-MM-DD.jsonl`,并按天分文件:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{"time":"2026-11-18T15:44:23+08:00","sid":"e7940079","id":"...","text":"原话"}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
只存原话,**不存"当时在问什么"**。那件事只能交给 `ledger_search` 真正读上下文去判断——
|
|
125
|
+
用正则猜"这句话是不是提问",实测误报一半以上(把「已完成,1./2./3.」这种汇报判成选择题)。
|
|
126
|
+
|
|
127
|
+
两个工具:
|
|
128
|
+
|
|
129
|
+
| 工具 | 作用 |
|
|
130
|
+
|---|---|
|
|
131
|
+
| `ledger_search({query, date})` | 把某一天的全部原话 + 你的问题交给一次**独立模型调用**,返回 `#序号 — 理由`,没有就返回"没有" |
|
|
132
|
+
| `ledger_show({ref})` | 按引用展开原话全文 |
|
|
133
|
+
|
|
134
|
+
为什么用模型检索而不是关键词:实测中 `grep` 三次全错——用户问"提示词",原话里写的是"10 个最有可能的节点";用户问"时限",原话里写的是"预算""超时"。**用词不同,但指的是同一件事。**
|
|
135
|
+
|
|
136
|
+
代价是每次检索多一次模型调用(约 4 秒);收益是决策前能真的查到既有裁决,而不是靠记忆。
|
|
137
|
+
|
|
113
138
|
## 已知边界
|
|
114
139
|
|
|
115
140
|
- **没有 plan 模式**(指挥官做决策不需要审批门);
|
|
@@ -125,6 +150,7 @@ DSH 的层叠顺序是 **bundle 层 → 你的 profile patch 层**。直接改
|
|
|
125
150
|
|---|---|
|
|
126
151
|
| 0.1.x | 首个公开版本 |
|
|
127
152
|
| 0.2.x | 提示词改为「最小功能 + 最大秩序」,减法不再以"可逆任务"为前提 |
|
|
153
|
+
| 0.3.x | 新增主席原文台账 + `ledger_search` / `ledger_show`;指挥官、执行者、审查者在决策/改代码/复核前都先查台账 |
|
|
128
154
|
|
|
129
155
|
## License
|
|
130
156
|
|
package/cordis.patch.yml
CHANGED
|
@@ -148,6 +148,8 @@
|
|
|
148
148
|
|
|
149
149
|
判不准时按"大事"处理,但**不因此把小事做复杂**。
|
|
150
150
|
|
|
151
|
+
**决策前先查台账**:`ledger_search`(query + 当天的 date)查这个议题有没有更早的裁决。既有裁决与本次决定冲突,就**带着两条原话回问用户**,不自行改判。
|
|
152
|
+
|
|
151
153
|
### 你的价值在于判断,不在产出
|
|
152
154
|
|
|
153
155
|
你的职责是:**随时响应变化、统筹规划、验收结果、及时汇报**。这要求三件事,缺一件你就退化成一个更慢的执行者。
|
|
@@ -209,6 +211,7 @@
|
|
|
209
211
|
|
|
210
212
|
### 交付前自查
|
|
211
213
|
|
|
214
|
+
0. 改**口径、算法、蓝图、提示词**之前,先用 `ledger_search`(query 写清议题,date 写那一天)查有没有更早的裁决;纯实现改动不必查。查到冲突就停手报指挥官;检索没成功就说没成功,不许写成"查过"。
|
|
212
215
|
1. 用户原话的每一条,都满足了吗?
|
|
213
216
|
2. 有没有做工作包之外的改动?
|
|
214
217
|
3. 有没有留下未使用的代码、配置、文件、注释掉的段落?
|
|
@@ -227,6 +230,8 @@
|
|
|
227
230
|
3. **乱了吗(查结构)**:命名、分层、目录、测试是否整齐;新人能不能看懂。
|
|
228
231
|
4. **会返工吗(查设计)**:接口和边界是否留住了;下一次改动会不会波及现有代码。
|
|
229
232
|
|
|
233
|
+
审查前先查台账(`ledger_search` / `ledger_show`):本次用到的每个口径,台账里有没有对应裁决;冲突或查不到出处,都写进报告。
|
|
234
|
+
|
|
230
235
|
漏和多是对等的两件事,任何一边都不能漏审。
|
|
231
236
|
|
|
232
237
|
### 报告格式
|
|
@@ -332,6 +337,11 @@
|
|
|
332
337
|
- id: goal-round-reminder
|
|
333
338
|
name: dsh-beta-battle-mode/lib/goal-round-reminder.js
|
|
334
339
|
|
|
340
|
+
# 主席原文台账:每句用户原话追加到 `.local/主席原文/utterances-<date>.jsonl`,
|
|
341
|
+
# 并附上当时在问的问题指针。指挥官决策前、审查者复核前都先查它。
|
|
342
|
+
- id: chairman-ledger
|
|
343
|
+
name: dsh-beta-battle-mode/lib/chairman-ledger.js
|
|
344
|
+
|
|
335
345
|
- id: tool-goal
|
|
336
346
|
name: '@deepseek-ai/dsh-tool-goal'
|
|
337
347
|
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BADGE chairman ledger (主席原文台账).
|
|
3
|
+
*
|
|
4
|
+
* The commander's session log already stores every user message verbatim, but
|
|
5
|
+
* the commander cannot read it: the log lives outside the workspace, is zstd
|
|
6
|
+
* compressed, and no tool exposes it. This plugin writes a small JSONL index
|
|
7
|
+
* beside the work log so a decision can always be traced back to what the
|
|
8
|
+
* chairman actually said, and to the questions it was answering.
|
|
9
|
+
*
|
|
10
|
+
* What is stored per user message:
|
|
11
|
+
* text the chairman's words, verbatim (small, so it is kept inline)
|
|
12
|
+
* sid the session id, so the full context can be resolved on demand
|
|
13
|
+
*
|
|
14
|
+
* Scope: mounted by the agent preset, so only BETA sessions record. Subagent
|
|
15
|
+
* sessions are skipped: their user messages are dispatch briefs, not rulings.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-beta-battle-mode/lib/chairman-ledger
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { existsSync, mkdirSync, appendFileSync, readFileSync, readdirSync } from 'node:fs'
|
|
21
|
+
import { join } from 'node:path'
|
|
22
|
+
|
|
23
|
+
/** Cordis plugin name. */
|
|
24
|
+
const name = 'chairman-ledger'
|
|
25
|
+
|
|
26
|
+
/** Mounted row needs the tool registry. */
|
|
27
|
+
export const inject = ['tools', 'llm']
|
|
28
|
+
|
|
29
|
+
/** Ledger directory relative to the workspace root. */
|
|
30
|
+
const LEDGER_DIR = join('.local', '主席原文')
|
|
31
|
+
|
|
32
|
+
/** Only real user input counts; runtime context and catalogs are injected. */
|
|
33
|
+
function isChairmanMessage(message) {
|
|
34
|
+
return message?.source?.kind === 'user'
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Local ISO timestamp with offset. */
|
|
38
|
+
function localStamp(date = new Date()) {
|
|
39
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
40
|
+
const offset = -date.getTimezoneOffset()
|
|
41
|
+
const sign = offset >= 0 ? '+' : '-'
|
|
42
|
+
const abs = Math.abs(offset)
|
|
43
|
+
return (
|
|
44
|
+
`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T` +
|
|
45
|
+
`${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}` +
|
|
46
|
+
`${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Date key used in the file name. */
|
|
51
|
+
function dayKey(stamp) {
|
|
52
|
+
return stamp.slice(0, 10)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Ledger directory of a workspace. */
|
|
56
|
+
function ledgerDir(cwd) {
|
|
57
|
+
return join(cwd, LEDGER_DIR)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Append one entry, creating the directory on first use. */
|
|
61
|
+
function appendEntry(cwd, entry) {
|
|
62
|
+
const dir = ledgerDir(cwd)
|
|
63
|
+
mkdirSync(dir, { recursive: true })
|
|
64
|
+
appendFileSync(join(dir, `utterances-${dayKey(entry.time)}.jsonl`), `${JSON.stringify(entry)}\n`, 'utf8')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Every entry of a workspace, oldest first, with its `n` assigned. */
|
|
68
|
+
function readEntries(cwd) {
|
|
69
|
+
const dir = ledgerDir(cwd)
|
|
70
|
+
if (!existsSync(dir)) return []
|
|
71
|
+
const entries = []
|
|
72
|
+
for (const file of readdirSync(dir).filter((f) => /^utterances-\d{4}-\d{2}-\d{2}\.jsonl$/.test(f)).sort()) {
|
|
73
|
+
let raw
|
|
74
|
+
try {
|
|
75
|
+
raw = readFileSync(join(dir, file), 'utf8')
|
|
76
|
+
} catch {
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
for (const line of raw.split('\n')) {
|
|
80
|
+
if (line.trim() === '') continue
|
|
81
|
+
try {
|
|
82
|
+
entries.push(JSON.parse(line))
|
|
83
|
+
} catch {
|
|
84
|
+
// A half-written line is not worth failing a read over.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
entries.forEach((entry, index) => {
|
|
89
|
+
entry.n = index + 1
|
|
90
|
+
})
|
|
91
|
+
return entries
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Parse a `since` window such as `3d`, `12h`, or an ISO date. */
|
|
95
|
+
function parseSince(since) {
|
|
96
|
+
if (since === undefined) return Date.now() - 7 * 86_400_000
|
|
97
|
+
const match = /^(\d+)([dh])$/.exec(since.trim())
|
|
98
|
+
if (match !== null) {
|
|
99
|
+
const value = Number(match[1])
|
|
100
|
+
return Date.now() - value * (match[2] === 'd' ? 86_400_000 : 3_600_000)
|
|
101
|
+
}
|
|
102
|
+
const parsed = Date.parse(since)
|
|
103
|
+
return Number.isNaN(parsed) ? Date.now() - 2 * 86_400_000 : parsed
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Register the recorder and the two read tools. */
|
|
107
|
+
async function apply(ctx) {
|
|
108
|
+
const recorded = new Map()
|
|
109
|
+
|
|
110
|
+
ctx.on('agent/pre-step', async (payload, next) => {
|
|
111
|
+
const decision = await next()
|
|
112
|
+
if (decision.kind !== 'enter') return decision
|
|
113
|
+
try {
|
|
114
|
+
record(payload?.agent, payload?.messages)
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.warn(`chairman-ledger: 记录失败 ${error?.message ?? error}`)
|
|
117
|
+
}
|
|
118
|
+
return decision
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
function record(agent, messages) {
|
|
122
|
+
const header = agent?.session?.header
|
|
123
|
+
if (header === undefined || header === null) return
|
|
124
|
+
if (header.origin === 'subagent') return
|
|
125
|
+
if (typeof header.cwd !== 'string' || header.cwd === '') return
|
|
126
|
+
if (!Array.isArray(messages) || messages.length === 0) return
|
|
127
|
+
|
|
128
|
+
const sid = String(header.id).replace(/^session-/, '')
|
|
129
|
+
let seen = recorded.get(sid)
|
|
130
|
+
if (seen === undefined) {
|
|
131
|
+
// Seed from disk: a restarted host must not re-record messages it already
|
|
132
|
+
// wrote in a previous life. Older rows may still carry the `session-`
|
|
133
|
+
// prefix, so compare on the bare id.
|
|
134
|
+
seen = new Set(
|
|
135
|
+
readEntries(header.cwd)
|
|
136
|
+
.filter((entry) => String(entry.sid).replace(/^session-/, '') === sid)
|
|
137
|
+
.map((entry) => entry.id)
|
|
138
|
+
)
|
|
139
|
+
recorded.set(sid, seen)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
for (const message of messages) {
|
|
143
|
+
if (!isChairmanMessage(message) || message.id === undefined) continue
|
|
144
|
+
if (seen.has(message.id)) continue
|
|
145
|
+
const text = unwrapChannelNotice(textOf(message))
|
|
146
|
+
if (text === null || text === '') {
|
|
147
|
+
seen.add(message.id)
|
|
148
|
+
continue
|
|
149
|
+
}
|
|
150
|
+
appendEntry(header.cwd, {
|
|
151
|
+
time: localStamp(),
|
|
152
|
+
sid,
|
|
153
|
+
id: message.id,
|
|
154
|
+
text,
|
|
155
|
+
})
|
|
156
|
+
seen.add(message.id)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Resolve a citation to one entry. Accepts the stable form printed by
|
|
162
|
+
* `ledger_search` (`2026-11-18 16:05 · 4f2a1b3c`), a bare id prefix, or the
|
|
163
|
+
* legacy `#n` running number (kept for older reports, but it drifts).
|
|
164
|
+
*
|
|
165
|
+
* @param entries - every entry of the workspace, oldest first.
|
|
166
|
+
* @param raw - the citation text as the caller wrote it.
|
|
167
|
+
* @returns the matching entry, or undefined.
|
|
168
|
+
*/
|
|
169
|
+
function resolveRef(entries, raw) {
|
|
170
|
+
const trimmed = raw.trim()
|
|
171
|
+
const hash = /^#?(\d+)$/.exec(trimmed)
|
|
172
|
+
if (hash !== null) {
|
|
173
|
+
const byNumber = entries.find((entry) => entry.n === Number(hash[1]))
|
|
174
|
+
if (byNumber !== undefined) return byNumber
|
|
175
|
+
}
|
|
176
|
+
const stamp = /(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2})/.exec(trimmed)
|
|
177
|
+
if (stamp !== null) {
|
|
178
|
+
const exact = entries.find((entry) => entry.time.slice(0, 16).replace('T', ' ') === `${stamp[1]} ${stamp[2]}`)
|
|
179
|
+
if (exact !== undefined) return exact
|
|
180
|
+
}
|
|
181
|
+
const idHint = trimmed.replace(/[^0-9a-zA-Z-]/g, '')
|
|
182
|
+
if (idHint.length >= 6) {
|
|
183
|
+
const matches = entries.filter((entry) => String(entry.id).startsWith(idHint))
|
|
184
|
+
if (matches.length === 1) return matches[0]
|
|
185
|
+
if (matches.length > 1) return undefined
|
|
186
|
+
}
|
|
187
|
+
return undefined
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* One-shot retrieval: the whole day's quotes plus the question go to a fresh
|
|
192
|
+
* model call, so the answer comes from a clean context instead of leaning on
|
|
193
|
+
* substring luck. The caller's own session stays untouched.
|
|
194
|
+
*
|
|
195
|
+
* Nothing is truncated per entry and no result count is imposed: the model
|
|
196
|
+
* decides what is relevant. The only guard is a very high total-size ceiling,
|
|
197
|
+
* so one pathological day cannot blow the request up.
|
|
198
|
+
*/
|
|
199
|
+
async function searchDay(ctx, agent, query, date, entries) {
|
|
200
|
+
const header = agent?.session?.requestHeader?.()
|
|
201
|
+
const route = header?.config ?? {}
|
|
202
|
+
if (typeof route.provider !== 'string' || typeof route.model !== 'string') {
|
|
203
|
+
return '检索未完成:拿不到当前会话的模型路由。'
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const CEILING = 400_000
|
|
207
|
+
let used = 0
|
|
208
|
+
const lines = []
|
|
209
|
+
let omitted = 0
|
|
210
|
+
for (const entry of entries) {
|
|
211
|
+
const line = `#${entry.n} ${entry.time.slice(11, 16)} 「${entry.text}」`
|
|
212
|
+
if (used + line.length > CEILING) {
|
|
213
|
+
omitted += 1
|
|
214
|
+
continue
|
|
215
|
+
}
|
|
216
|
+
used += line.length
|
|
217
|
+
lines.push(line)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const system =
|
|
221
|
+
'你是检索器,只做一件事:在用户(主席)当天说过的原话里,找出与检索问题相关的条目。\n' +
|
|
222
|
+
'规则:\n' +
|
|
223
|
+
'1. 只输出条目序号和理由,每条一行,形如 `#18 — 理由:……`。\n' +
|
|
224
|
+
'2. 先列确定相关的,按相关度从高到低;不确定相关的放在最后,理由里注明「不确定」。\n' +
|
|
225
|
+
'3. 理由要具体:指出这条原话里哪个说法回答了问题,或与问题冲突在哪里。\n' +
|
|
226
|
+
'4. 一条都不相关就只输出 `没有`,不要编造序号。'
|
|
227
|
+
|
|
228
|
+
const user =
|
|
229
|
+
`检索问题:\n${query}\n\n` +
|
|
230
|
+
`${date} 主席原话共 ${entries.length} 条${omitted > 0 ? `(因总量超限省略 ${omitted} 条)` : ''}:\n` +
|
|
231
|
+
lines.join('\n')
|
|
232
|
+
|
|
233
|
+
const chunks = []
|
|
234
|
+
let reasoning = ''
|
|
235
|
+
let finish
|
|
236
|
+
try {
|
|
237
|
+
const stream = ctx.llm.stream({
|
|
238
|
+
provider: route.provider,
|
|
239
|
+
model: route.model,
|
|
240
|
+
system,
|
|
241
|
+
messages: [{ role: 'user', content: [{ type: 'text', text: user }] }],
|
|
242
|
+
})
|
|
243
|
+
// `ctx.llm.stream()` yields raw StreamChunk values (text-delta /
|
|
244
|
+
// reasoning-delta / finish), not the packed AssistantStreamRecord.
|
|
245
|
+
for await (const chunk of stream) {
|
|
246
|
+
if (chunk?.type === 'text-delta') chunks.push(chunk.text)
|
|
247
|
+
else if (chunk?.type === 'reasoning-delta') reasoning += chunk.text
|
|
248
|
+
else if (chunk?.type === 'finish') finish = chunk.reason
|
|
249
|
+
else if (chunk?.type === 'error') finish = { kind: 'error', failure: chunk.failure ?? chunk }
|
|
250
|
+
}
|
|
251
|
+
} catch (error) {
|
|
252
|
+
return (
|
|
253
|
+
`检索未完成(模型调用出错:${error?.message ?? error})。` +
|
|
254
|
+
`这不算「查过」:不要据此声称已核对台账,可重试一次。`
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const answer = chunks.join('').trim()
|
|
259
|
+
if (answer === '') {
|
|
260
|
+
const reason =
|
|
261
|
+
finish === undefined
|
|
262
|
+
? '没有结束记录'
|
|
263
|
+
: finish.kind === 'error'
|
|
264
|
+
? `失败 ${finish.failure?.code ?? ''} ${finish.failure?.message ?? ''}`.trim()
|
|
265
|
+
: String(finish.kind)
|
|
266
|
+
return (
|
|
267
|
+
`检索未完成(结束原因:${reason};推理 ${reasoning.length} 字)。` +
|
|
268
|
+
`这不算「查过」:不要据此声称已核对台账;可重试一次,或直接看 .local/主席原文/ 里当天的文件。`
|
|
269
|
+
)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// `#n` is a global running number that shifts whenever the ledger is
|
|
273
|
+
// rewritten (a backfill reorders every file), so every hit also carries a
|
|
274
|
+
// stable reference: the message timestamp and the message id prefix.
|
|
275
|
+
const byNumber = new Map(entries.map((entry) => [entry.n, entry]))
|
|
276
|
+
const stamped = answer.replace(/#(\d+)/g, (match, digits) => {
|
|
277
|
+
const entry = byNumber.get(Number(digits))
|
|
278
|
+
if (entry === undefined) return match
|
|
279
|
+
const when = entry.time.slice(0, 16).replace('T', ' ')
|
|
280
|
+
return `#${digits} (${when} · ${String(entry.id).slice(0, 8)})`
|
|
281
|
+
})
|
|
282
|
+
return `${date} 台账 ${entries.length} 条,检索结果:\n${stamped}\n\n引用时请用括号里的「日期 时间 · id 前缀」,不要用 #n(会随台账重排漂移)。`
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
ctx.tools.register({
|
|
286
|
+
name: 'ledger_search',
|
|
287
|
+
description:
|
|
288
|
+
'在主席原话台账里做一次语义检索:把「你要找的东西」和指定那一天的全部原话交给一个独立模型,' +
|
|
289
|
+
'由它挑出最相关的条目序号并说明理由(没有就回「没有」)。返回的是候选序号,展开原文用 ledger_show。' +
|
|
290
|
+
'要改代码、改蓝图口径、改提示词,或怀疑与既有裁决冲突时用它。',
|
|
291
|
+
parameters: {
|
|
292
|
+
type: 'object',
|
|
293
|
+
additionalProperties: false,
|
|
294
|
+
properties: {
|
|
295
|
+
query: {
|
|
296
|
+
type: 'string',
|
|
297
|
+
description: '要找什么,自然语言,写清议题、涉及的概念和你担心的冲突点。不超过 5000 字。',
|
|
298
|
+
},
|
|
299
|
+
date: {
|
|
300
|
+
type: 'string',
|
|
301
|
+
description: '查哪一天的主席原话,格式 yyyy-MM-dd(例如 2026-11-16)。台账按天分文件。',
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
required: ['query', 'date'],
|
|
305
|
+
},
|
|
306
|
+
output: {
|
|
307
|
+
schema: {
|
|
308
|
+
type: 'object',
|
|
309
|
+
additionalProperties: false,
|
|
310
|
+
properties: {
|
|
311
|
+
text: { type: 'string' },
|
|
312
|
+
},
|
|
313
|
+
required: ['text'],
|
|
314
|
+
},
|
|
315
|
+
render: (_args, value) => [{ type: 'text', text: value.text }],
|
|
316
|
+
},
|
|
317
|
+
async execute(args, exec) {
|
|
318
|
+
const cwd = exec?.agent?.session?.header?.cwd
|
|
319
|
+
if (typeof cwd !== 'string') return { text: '台账不可用:当前会话没有工作目录。' }
|
|
320
|
+
|
|
321
|
+
const query = typeof args?.query === 'string' ? args.query.trim() : ''
|
|
322
|
+
if (query === '') return { text: 'ledger_search 需要一个 query。' }
|
|
323
|
+
if (query.length > 5000) return { text: `query 太长(${query.length} 字),请压到 5000 字以内。` }
|
|
324
|
+
|
|
325
|
+
const date = typeof args?.date === 'string' ? args.date.trim() : ''
|
|
326
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) return { text: 'date 必须是 yyyy-MM-dd。' }
|
|
327
|
+
|
|
328
|
+
const entries = readEntries(cwd).filter((entry) => entry.time.startsWith(date))
|
|
329
|
+
if (entries.length === 0) return { text: `${date} 台账里没有记录。` }
|
|
330
|
+
|
|
331
|
+
const answer = await searchDay(ctx, exec?.agent, query, date, entries)
|
|
332
|
+
return { text: answer }
|
|
333
|
+
},
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
ctx.tools.register({
|
|
337
|
+
name: 'ledger_show',
|
|
338
|
+
description:
|
|
339
|
+
'按引用展开一条台账:返回主席原话全文,以及当时那个问题的完整原文与选项。' +
|
|
340
|
+
'引用取 ledger_search 返回的「日期 时间 · id 前缀」,例如 `2026-11-18 16:05 · 4f2a1b3c` 或旧的 `#947`。',
|
|
341
|
+
parameters: {
|
|
342
|
+
type: 'object',
|
|
343
|
+
additionalProperties: false,
|
|
344
|
+
properties: {
|
|
345
|
+
ref: {
|
|
346
|
+
type: 'string',
|
|
347
|
+
description: '台账引用:`日期 时间 · id前缀`、裸 id 前缀(至少 6 位)、或不稳定的 `#序号`。',
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
required: ['ref'],
|
|
351
|
+
},
|
|
352
|
+
output: {
|
|
353
|
+
schema: {
|
|
354
|
+
type: 'object',
|
|
355
|
+
additionalProperties: false,
|
|
356
|
+
properties: {
|
|
357
|
+
text: { type: 'string' },
|
|
358
|
+
},
|
|
359
|
+
required: ['text'],
|
|
360
|
+
},
|
|
361
|
+
render: (_args, value) => [{ type: 'text', text: value.text }],
|
|
362
|
+
},
|
|
363
|
+
execute(args, exec) {
|
|
364
|
+
const cwd = exec?.agent?.session?.header?.cwd
|
|
365
|
+
if (typeof cwd !== 'string') return { text: '台账不可用:当前会话没有工作目录。' }
|
|
366
|
+
const raw = typeof args?.ref === 'string' ? args.ref.trim() : ''
|
|
367
|
+
if (raw === '') return { text: 'ledger_show 需要一个 ref。' }
|
|
368
|
+
const entries = readEntries(cwd)
|
|
369
|
+
const entry = resolveRef(entries, raw)
|
|
370
|
+
if (entry === undefined) return { text: `台账里没有匹配「${raw}」的条目。` }
|
|
371
|
+
const out = [`主席 ${entry.time.slice(0, 16).replace('T', ' ')}:`, entry.text]
|
|
372
|
+
out.push('', `稳定引用:${entry.time.slice(0, 16).replace('T', ' ')} · ${String(entry.id).slice(0, 8)}`)
|
|
373
|
+
return { text: out.join('\n') }
|
|
374
|
+
},
|
|
375
|
+
})
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export { apply, name }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-beta-battle-mode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "BETA battle mode for DeepSeek Harness — a commander-led agent cluster (commander, executors, reviewers) whose context is rebuilt from the project's work log instead of an expensive summarization call",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|