dsh-handoff-baton 0.3.2 → 0.4.1
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 -1
- package/README.md +8 -1
- package/bin/baton.mjs +61 -2
- package/docs/DETAIL.en.md +8 -0
- package/docs/DETAIL.md +8 -0
- package/docs/README.zh-CN.md +8 -1
- package/index.js +12 -2
- package/lib/drift.js +142 -0
- package/package.json +5 -5
- package/skills/baton/SKILL.md +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.1 · 2026-11-29
|
|
4
|
+
|
|
5
|
+
仓库迁移。
|
|
6
|
+
|
|
7
|
+
- GitHub 用户名由 WeiLuo114514 改为 Well-WeiLuo,`repository` / `homepage` / `bugs` 与 README 互链同步更新
|
|
8
|
+
- 旧地址由 GitHub 301 重定向到新仓库,已发布的 0.4.0 里的链接仍然可用
|
|
9
|
+
|
|
10
|
+
## 0.4.0 · 2026-11-29
|
|
11
|
+
|
|
12
|
+
接手前的漂移检查。
|
|
13
|
+
|
|
14
|
+
- 新增 `baton drift <file>`:核对文档列出的关键文件是否还在、写完后是否被改动、git 又走了多少个提交;有变化时退出码 2
|
|
15
|
+
- 默认只在文档写于 12 小时以前时才检查(`--stale-hours` 可调,`--force` 强制);即时接力零开销
|
|
16
|
+
- 只做文件系统与 git 的事实核对,不做语义判断、不改文档,结论是「建议复核」而不是「文档已过期」
|
|
17
|
+
- `/baton pick` 接手超过 12 小时的交接时,会在排队的指令里附一句漂移检查提醒
|
|
18
|
+
- 技能第 5 步加入「超过 12 小时先跑 drift」
|
|
19
|
+
- 测试 66 项(新增 drift 7 项)
|
|
20
|
+
|
|
3
21
|
## 0.3.2 · 2026-11-29
|
|
4
22
|
|
|
5
23
|
npm 页面语言修正。
|
|
@@ -12,7 +30,7 @@ npm 页面语言修正。
|
|
|
12
30
|
文档与元数据修正。
|
|
13
31
|
|
|
14
32
|
- README 的中英文互链改为 GitHub 绝对地址,npm 页面不再跳到 404
|
|
15
|
-
- `package.json` 补 `homepage` / `bugs`,`repository` 指向
|
|
33
|
+
- `package.json` 补 `homepage` / `bugs`,`repository` 指向 Well-WeiLuo/handoff-baton
|
|
16
34
|
|
|
17
35
|
## 0.3.0 · 2026-11-29
|
|
18
36
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Task Handoff Baton · dsh-handoff-baton
|
|
2
2
|
|
|
3
|
-
English | [简体中文](https://github.com/
|
|
3
|
+
English | [简体中文](https://github.com/Well-WeiLuo/handoff-baton/blob/main/docs/README.zh-CN.md)
|
|
4
4
|
|
|
5
5
|
Turn "one conversation that keeps growing" into "one document plus one marker".
|
|
6
6
|
|
|
@@ -82,6 +82,12 @@ For another model, or a host without the skill installed, use the long form:
|
|
|
82
82
|
- `baton sync [--fix]` reconciles the directory with the index: unregistered files, entries pointing at deleted files, mismatched titles.
|
|
83
83
|
- `baton status` reports stuck entries (not updated for 7 days) and closed entries worth archiving. `baton prune` moves them to `handoff/archive/`; it reports by default and never deletes.
|
|
84
84
|
|
|
85
|
+
## Drift check
|
|
86
|
+
|
|
87
|
+
Before continuing from an older handoff, `baton drift` verifies three facts in one pass: the key files it lists still exist, whether they changed after the document was written, and how many commits the repository moved since. It runs only when the document is older than 12 hours, so a same-day handoff pays nothing; `--force` overrides, `--stale-hours` tunes the gate.
|
|
88
|
+
|
|
89
|
+
The check is filesystem and git only — no model call, no rewriting, no verdict. Its output is evidence plus one line of advice: re-read the files it names before trusting the document.
|
|
90
|
+
|
|
85
91
|
## CLI
|
|
86
92
|
|
|
87
93
|
```sh
|
|
@@ -94,6 +100,7 @@ node bin/baton.mjs entry "⟦baton⟧ handoff/x.md"
|
|
|
94
100
|
node bin/baton.mjs archive handoff/x.md
|
|
95
101
|
node bin/baton.mjs list [--open]
|
|
96
102
|
node bin/baton.mjs status [--stale-days 7] [--closed-days 30] [--max-closed 20]
|
|
103
|
+
node bin/baton.mjs drift handoff/2026-11-29-0045-x.md [--force]
|
|
97
104
|
node bin/baton.mjs resolve [--json]
|
|
98
105
|
node bin/baton.mjs touch handoff/x.md [--status 进行中|已接手|已关闭]
|
|
99
106
|
node bin/baton.mjs sync [--fix]
|
package/bin/baton.mjs
CHANGED
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
* baton archive <file> [--dir handoff]
|
|
13
13
|
* baton list [--dir handoff]
|
|
14
14
|
*/
|
|
15
|
-
import { readFileSync, existsSync, readdirSync } from 'node:fs'
|
|
15
|
+
import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs'
|
|
16
16
|
import { mkdir, writeFile } from 'node:fs/promises'
|
|
17
|
-
import { resolve, join, basename } from 'node:path'
|
|
17
|
+
import { dirname, resolve, join, basename } from 'node:path'
|
|
18
18
|
import { execFileSync } from 'node:child_process'
|
|
19
19
|
|
|
20
20
|
import {
|
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
writeHandoff,
|
|
43
43
|
} from '../lib/protocol.js'
|
|
44
44
|
import { inspectIndex } from '../lib/maintenance.js'
|
|
45
|
+
import { DEFAULT_STALE_HOURS, ageHours, parseKeyFiles, summarizeDrift } from '../lib/drift.js'
|
|
45
46
|
|
|
46
47
|
/** --json 时失败也吐结构化结果,方便脚本消费。 */
|
|
47
48
|
let jsonMode = false
|
|
@@ -326,6 +327,62 @@ async function cmdArchive(args) {
|
|
|
326
327
|
process.stdout.write(`已写入索引:${indexPath}\n`)
|
|
327
328
|
}
|
|
328
329
|
|
|
330
|
+
async function cmdDrift(args) {
|
|
331
|
+
const file = args._[0]
|
|
332
|
+
if (!file) fail('drift 需要文件路径')
|
|
333
|
+
const target = resolve(file)
|
|
334
|
+
if (!existsSync(target)) fail(`未找到文件:${target}`, 1)
|
|
335
|
+
const text = readFileSync(target, 'utf8').replace(/^\uFEFF/u, '')
|
|
336
|
+
const header = parseHeader(text) ?? {}
|
|
337
|
+
const workspace = resolve(dirname(target), '..')
|
|
338
|
+
const staleHours = Number(args['stale-hours']) > 0 ? Number(args['stale-hours']) : DEFAULT_STALE_HOURS
|
|
339
|
+
const age = ageHours(header.created)
|
|
340
|
+
const created = Date.parse(String(header.created ?? ''))
|
|
341
|
+
|
|
342
|
+
const files = parseKeyFiles(text).map((relPath) => {
|
|
343
|
+
const abs = resolve(workspace, relPath)
|
|
344
|
+
if (!existsSync(abs)) return { path: relPath, exists: false, changed: false }
|
|
345
|
+
const mtime = statSync(abs).mtimeMs
|
|
346
|
+
const changed = Number.isFinite(created) ? mtime > created + 1000 : false
|
|
347
|
+
return { path: relPath, exists: true, changed }
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
let git = null
|
|
351
|
+
const head = gitHead(workspace)
|
|
352
|
+
if (head !== 'none' && typeof header.git === 'string' && header.git !== '' && header.git !== 'none') {
|
|
353
|
+
try {
|
|
354
|
+
const ahead = Number(execFileSync('git', ['rev-list', '--count', `${header.git}..HEAD`], {
|
|
355
|
+
cwd: workspace,
|
|
356
|
+
encoding: 'utf8',
|
|
357
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
358
|
+
timeout: 4000,
|
|
359
|
+
}).trim())
|
|
360
|
+
if (Number.isFinite(ahead)) git = { from: header.git, to: head, ahead }
|
|
361
|
+
} catch {
|
|
362
|
+
git = null
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const report = summarizeDrift({
|
|
367
|
+
doc: basename(target),
|
|
368
|
+
ageHours: age,
|
|
369
|
+
files,
|
|
370
|
+
git,
|
|
371
|
+
staleHours,
|
|
372
|
+
force: args.force === true,
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
if (args.json) {
|
|
376
|
+
process.stdout.write(`${JSON.stringify({ file: target, ...report }, null, 2)}\n`)
|
|
377
|
+
} else {
|
|
378
|
+
process.stdout.write(`检查:${basename(target)}\n`)
|
|
379
|
+
process.stdout.write(`${report.summary}\n`)
|
|
380
|
+
for (const detail of report.details) process.stdout.write(`· ${detail}\n`)
|
|
381
|
+
if (report.advice !== '') process.stdout.write(`建议:${report.advice}\n`)
|
|
382
|
+
}
|
|
383
|
+
process.exitCode = report.level === 'drift' ? 2 : 0
|
|
384
|
+
}
|
|
385
|
+
|
|
329
386
|
async function cmdStatus(args) {
|
|
330
387
|
const dir = resolve(typeof args.dir === 'string' ? args.dir : DEFAULT_DIR)
|
|
331
388
|
const indexPath = join(dir, 'INDEX.md')
|
|
@@ -452,6 +509,7 @@ const commands = {
|
|
|
452
509
|
archive: cmdArchive,
|
|
453
510
|
list: cmdList,
|
|
454
511
|
status: cmdStatus,
|
|
512
|
+
drift: cmdDrift,
|
|
455
513
|
resolve: cmdResolve,
|
|
456
514
|
touch: cmdTouch,
|
|
457
515
|
sync: cmdSync,
|
|
@@ -475,6 +533,7 @@ function main() {
|
|
|
475
533
|
' baton archive <file> [--dir handoff]\n' +
|
|
476
534
|
' baton list [--open] [--dir handoff]\n' +
|
|
477
535
|
' baton status [--stale-days 7] [--closed-days 30] [--max-closed 20] [--json]\n' +
|
|
536
|
+
' baton drift <file> [--stale-hours 12] [--force] [--json] 接手前核对地面有没有动过\n' +
|
|
478
537
|
' baton resolve [--dir handoff] [--json] 裸标记该接哪份(唯一 / 有歧义 / 没有)\n' +
|
|
479
538
|
' baton touch <file> [--status 进行中|已接手|已关闭] [--dir handoff]\n' +
|
|
480
539
|
' baton sync [--fix] [--dir handoff] 目录与索引对账\n' +
|
package/docs/DETAIL.en.md
CHANGED
|
@@ -76,6 +76,14 @@ Each line in `handoff/INDEX.md` is one handoff: `- [Title](path) — 进行中
|
|
|
76
76
|
|
|
77
77
|
The health check is pure data work: the script computes the result, and no model call is involved.
|
|
78
78
|
|
|
79
|
+
## Drift check
|
|
80
|
+
|
|
81
|
+
The project may keep moving after a handoff is written. `baton drift <file>` checks three facts in one filesystem-and-git pass: the listed key files still exist, whether they changed after the document was written, and how many commits the repository moved.
|
|
82
|
+
|
|
83
|
+
- Read-only, tens of milliseconds, no model call; exit code 2 when something moved
|
|
84
|
+
- Skipped automatically when the document is younger than 12 hours, so same-day handoffs cost nothing (`--force` overrides, `--stale-hours` tunes)
|
|
85
|
+
- Evidence and advice only: it never rewrites the document, changes a state, or declares the document obsolete
|
|
86
|
+
|
|
79
87
|
## Reminders
|
|
80
88
|
|
|
81
89
|
With the plugin installed, the host nudges once each at 60%, at 80%, and after a compaction (once per session per tier, about 25 tokens). Detection runs inside the plugin process and uses none of the conversation budget. A nudge is advice only; whether to hand off is the user's decision.
|
package/docs/DETAIL.md
CHANGED
|
@@ -76,6 +76,14 @@ ASCII 写法 `<<baton>>`、`[[baton]]` 等价,用于避免编辑器吞掉特
|
|
|
76
76
|
|
|
77
77
|
体检为纯数据计算,脚本执行后直接给出结果,不产生模型调用。
|
|
78
78
|
|
|
79
|
+
## 漂移检查
|
|
80
|
+
|
|
81
|
+
交接写完之后,项目可能仍在变化。`baton drift <文件>` 用一趟文件系统与 git 核对三件事:文档列出的关键文件是否还在、写完后是否被改动、仓库又走了多少个提交。
|
|
82
|
+
|
|
83
|
+
- 只读、几十毫秒、不调用模型;有变化时退出码为 2
|
|
84
|
+
- 文档写于 12 小时以内时自动跳过,即时接力不付任何成本(`--force` 强制、`--stale-hours` 可调)
|
|
85
|
+
- 只给证据和建议,不改文档、不改状态,也不判断文档是否「已经过期」
|
|
86
|
+
|
|
79
87
|
## 提醒
|
|
80
88
|
|
|
81
89
|
安装插件后,宿主会在上下文超过 60%、超过 80%、以及发生压缩之后各提醒一次(每会话每档一次,约 25 token)。判定在插件进程内完成,不占用对话预算;提醒仅为建议,是否交接由用户决定。
|
package/docs/README.zh-CN.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 任务交接棒 · dsh-handoff-baton
|
|
2
2
|
|
|
3
|
-
[English](https://github.com/
|
|
3
|
+
[English](https://github.com/Well-WeiLuo/handoff-baton/blob/main/README.md) | 简体中文
|
|
4
4
|
|
|
5
5
|
把「一条会话聊到爆」变成「一份文档 + 一个标记」。
|
|
6
6
|
|
|
@@ -82,6 +82,12 @@ dsh plugin --profile desktop add "file:/绝对路径/dsh-handoff-baton"
|
|
|
82
82
|
- `baton sync [--fix]` 对账目录与索引:未登记文件、指向已删除文件的条目、标题不一致。
|
|
83
83
|
- `baton status` 报告滞留条目(超过 7 天未更新)与值得归档的已关闭条目。`baton prune` 将其移入 `handoff/archive/`,默认只报告,不删除。
|
|
84
84
|
|
|
85
|
+
## 漂移检查
|
|
86
|
+
|
|
87
|
+
接手一份旧交接之前,`baton drift` 用一趟文件系统与 git 核对三件事:文档列出的关键文件是否还在、写完后是否被改动、仓库又走了多少个提交。默认只在文档写于 12 小时以前时才检查,当天的交接零开销;`--force` 可强制,`--stale-hours` 可调门槛。
|
|
88
|
+
|
|
89
|
+
它不调用模型、不改文档,也不下结论,只给证据加一句建议:先复核点名的文件,再决定文档里的结论还算不算数。
|
|
90
|
+
|
|
85
91
|
## CLI
|
|
86
92
|
|
|
87
93
|
```sh
|
|
@@ -94,6 +100,7 @@ node bin/baton.mjs entry "⟦baton⟧ handoff/x.md"
|
|
|
94
100
|
node bin/baton.mjs archive handoff/x.md
|
|
95
101
|
node bin/baton.mjs list [--open]
|
|
96
102
|
node bin/baton.mjs status [--stale-days 7] [--closed-days 30] [--max-closed 20]
|
|
103
|
+
node bin/baton.mjs drift handoff/2026-11-29-0045-x.md [--force]
|
|
97
104
|
node bin/baton.mjs resolve [--json]
|
|
98
105
|
node bin/baton.mjs touch handoff/x.md [--status 进行中|已接手|已关闭]
|
|
99
106
|
node bin/baton.mjs sync [--fix]
|
package/index.js
CHANGED
|
@@ -238,6 +238,16 @@ async function installCommands(ctx, config) {
|
|
|
238
238
|
})
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
const driftHint = (entries, path) => {
|
|
242
|
+
const entry = entries.find((item) => item.path === path)
|
|
243
|
+
const stamp = Date.parse(String(entry?.updated ?? ''))
|
|
244
|
+
if (!Number.isFinite(stamp)) return ''
|
|
245
|
+
const hours = (Date.now() - stamp) / 3600000
|
|
246
|
+
if (hours < 12) return ''
|
|
247
|
+
const age = hours >= 48 ? `${Math.round(hours / 24)} 天` : `${Math.round(hours)} 小时`
|
|
248
|
+
return `\n- 这份交接写于 ${age}前,接手前先做一次漂移检查:核对「关键文件」是否还在、文档写完后有没有被改动`
|
|
249
|
+
}
|
|
250
|
+
|
|
241
251
|
const handler = async (invocation) => {
|
|
242
252
|
try {
|
|
243
253
|
const parsed = parseBatonCommand(invocation?.rawInput)
|
|
@@ -287,7 +297,7 @@ async function installCommands(ctx, config) {
|
|
|
287
297
|
if (!existsSync(join(dir, basename(parsed.path)))) {
|
|
288
298
|
return { kind: 'error', text: `未找到 ${parsed.path}。已有交接:\n${listText(listDocs(invocation?.agent))}` }
|
|
289
299
|
}
|
|
290
|
-
const text = pickPrompt(parsed.path, ENTRY_MARKER)
|
|
300
|
+
const text = pickPrompt(parsed.path, ENTRY_MARKER) + driftHint(entries, basename(parsed.path))
|
|
291
301
|
if (!enqueue(invocation?.agent, text)) {
|
|
292
302
|
return { kind: 'error', text: `无法将请求排入对话(宿主模块不可用)。可手动发送以下内容:\n${text}` }
|
|
293
303
|
}
|
|
@@ -296,7 +306,7 @@ async function installCommands(ctx, config) {
|
|
|
296
306
|
const resolved = resolveIndex(entries)
|
|
297
307
|
if (resolved.kind === 'unique') {
|
|
298
308
|
const { target } = resolved
|
|
299
|
-
const text = pickPrompt(target.path, ENTRY_MARKER)
|
|
309
|
+
const text = pickPrompt(target.path, ENTRY_MARKER) + driftHint(entries, target.path)
|
|
300
310
|
if (!enqueue(invocation?.agent, text)) {
|
|
301
311
|
return { kind: 'error', text: `无法将请求排入对话(宿主模块不可用)。可手动发送以下内容:\n${text}` }
|
|
302
312
|
}
|
package/lib/drift.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 漂移检查:接手旧交接前,确认地面有没有动过。
|
|
3
|
+
*
|
|
4
|
+
* 只做三件不需要模型、几十毫秒能完成的事:
|
|
5
|
+
* 1. 文档列出的关键文件是否还在
|
|
6
|
+
* 2. 这些文件在文档写完之后是否被改动
|
|
7
|
+
* 3. git 在文档写完之后又走了多少个提交
|
|
8
|
+
*
|
|
9
|
+
* 刻意不做语义判断,也不改文档:漂移提示是「复核建议」,不是结论。
|
|
10
|
+
*/
|
|
11
|
+
export const DEFAULT_STALE_HOURS = 12
|
|
12
|
+
const HOUR_MS = 60 * 60 * 1000
|
|
13
|
+
|
|
14
|
+
function stripListMarker(line) {
|
|
15
|
+
let text = String(line ?? '')
|
|
16
|
+
for (;;) {
|
|
17
|
+
const next = text.replace(/^\s*(?:[-*+]|\d+[.)])\s+/u, '')
|
|
18
|
+
if (next === text) break
|
|
19
|
+
text = next
|
|
20
|
+
}
|
|
21
|
+
return text.trim()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 判断一个文件引用是不是「路径 — 说明」这种三段式。 */
|
|
25
|
+
function splitPathAndNote(line) {
|
|
26
|
+
const text = stripListMarker(line).replace(/`/gu, '')
|
|
27
|
+
const match = text.match(/^(.*?)\s+[—–-]\s+/u)
|
|
28
|
+
if (match) return { path: match[1].trim(), note: text.slice(match[0].length).trim() }
|
|
29
|
+
return { path: text, note: '' }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 从文档正文中取出「关键文件」章节列出的路径。
|
|
34
|
+
* @param markdown - 交接文档全文。
|
|
35
|
+
* @returns 去重后的路径数组(保持出现顺序)。
|
|
36
|
+
*/
|
|
37
|
+
export function parseKeyFiles(markdown) {
|
|
38
|
+
const text = String(markdown ?? '')
|
|
39
|
+
const heading = text.match(/^## 3\. 关键文件 \/ Key files\s*$/mu)
|
|
40
|
+
if (heading === null) return []
|
|
41
|
+
const start = (heading.index ?? 0) + heading[0].length
|
|
42
|
+
const rest = text.slice(start)
|
|
43
|
+
const nextAt = rest.search(/\n## /u)
|
|
44
|
+
const section = nextAt < 0 ? rest : rest.slice(0, nextAt)
|
|
45
|
+
const seen = new Set()
|
|
46
|
+
const paths = []
|
|
47
|
+
for (const rawLine of section.split(/\r?\n/u)) {
|
|
48
|
+
if (!/^\s*(?:[-*+]|\d+[.)])\s+/u.test(rawLine)) continue
|
|
49
|
+
const { path } = splitPathAndNote(rawLine)
|
|
50
|
+
const value = path.trim()
|
|
51
|
+
if (value === '' || /^((?:无|none))$/iu.test(value)) continue
|
|
52
|
+
if (seen.has(value)) continue
|
|
53
|
+
seen.add(value)
|
|
54
|
+
paths.push(value)
|
|
55
|
+
}
|
|
56
|
+
return paths
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 文档写到现在过了多少小时。 */
|
|
60
|
+
export function ageHours(created, now = Date.now()) {
|
|
61
|
+
const stamp = Date.parse(String(created ?? ''))
|
|
62
|
+
if (!Number.isFinite(stamp)) return null
|
|
63
|
+
return Math.max(0, (now - stamp) / HOUR_MS)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 该不该查:太新的文档跳过,避免即时接力多付一次检查。
|
|
68
|
+
*/
|
|
69
|
+
export function shouldCheck(age, staleHours = DEFAULT_STALE_HOURS) {
|
|
70
|
+
if (age === null || !Number.isFinite(age)) return true
|
|
71
|
+
const limit = Number(staleHours) > 0 ? Number(staleHours) : DEFAULT_STALE_HOURS
|
|
72
|
+
return age >= limit
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function formatAge(hours) {
|
|
76
|
+
if (hours === null || !Number.isFinite(hours)) return '时间未知'
|
|
77
|
+
if (hours * 60 < 1) return '刚刚'
|
|
78
|
+
if (hours < 1) return `${Math.round(hours * 60)} 分钟前`
|
|
79
|
+
if (hours < 48) return `${Math.round(hours)} 小时前`
|
|
80
|
+
return `${Math.round(hours / 24)} 天前`
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* 汇总检查结果。
|
|
85
|
+
* @param input - 文档路径、年龄、文件检查结果、git 结果、阈值。
|
|
86
|
+
* @returns level(skipped / clean / drift)、一句摘要、逐条明细与给用户的建议。
|
|
87
|
+
*/
|
|
88
|
+
export function summarizeDrift(input = {}) {
|
|
89
|
+
const staleHours = Number(input.staleHours) > 0 ? Number(input.staleHours) : DEFAULT_STALE_HOURS
|
|
90
|
+
const age = Number.isFinite(input.ageHours) ? input.ageHours : null
|
|
91
|
+
const files = Array.isArray(input.files) ? input.files : []
|
|
92
|
+
const missing = files.filter((file) => file.exists === false)
|
|
93
|
+
const changed = files.filter((file) => file.exists !== false && file.changed === true)
|
|
94
|
+
const git = input.git ?? null
|
|
95
|
+
const gitMoved = git !== null && Number(git.ahead) > 0
|
|
96
|
+
const header = input.doc ?? '交接文档'
|
|
97
|
+
|
|
98
|
+
if (input.force !== true && !shouldCheck(age, staleHours)) {
|
|
99
|
+
return {
|
|
100
|
+
level: 'skipped',
|
|
101
|
+
ageHours: age,
|
|
102
|
+
missing,
|
|
103
|
+
changed,
|
|
104
|
+
git,
|
|
105
|
+
summary: `${header} 写于 ${formatAge(age)},未超过 ${staleHours} 小时,跳过漂移检查`,
|
|
106
|
+
details: [],
|
|
107
|
+
advice: '',
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const details = []
|
|
112
|
+
if (files.length > 0) {
|
|
113
|
+
const missingText = missing.length === 0 ? '' : `,其中 ${missing.length} 个已不存在(${missing.map((f) => f.path).join('、')})`
|
|
114
|
+
const changedText = changed.length === 0 ? '' : `,${changed.length} 个在写完后被改动(${changed.map((f) => f.path).join('、')})`
|
|
115
|
+
details.push(`关键文件 ${files.length} 个${missingText}${changedText}`)
|
|
116
|
+
} else {
|
|
117
|
+
details.push('文档里没有列出关键文件,无法核对文件状态')
|
|
118
|
+
}
|
|
119
|
+
if (git === null) {
|
|
120
|
+
details.push('git:不是 git 仓库,或头部没有记录提交')
|
|
121
|
+
} else if (gitMoved) {
|
|
122
|
+
details.push(`git:写完后又有 ${git.ahead} 个提交(${git.from} → ${git.to})`)
|
|
123
|
+
} else {
|
|
124
|
+
details.push('git:写完之后没有新提交')
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const drift = missing.length > 0 || changed.length > 0 || gitMoved
|
|
128
|
+
const advice = drift
|
|
129
|
+
? '先复核上面提到的文件,再按「下一步」继续;文档里的结论可能已经过期。'
|
|
130
|
+
: '关键文件都在、也没被改过,可以按文档继续。'
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
level: drift ? 'drift' : 'clean',
|
|
134
|
+
ageHours: age,
|
|
135
|
+
missing,
|
|
136
|
+
changed,
|
|
137
|
+
git,
|
|
138
|
+
summary: `${header} 写于 ${formatAge(age)},之后${drift ? '有变化' : '没有变化'}`,
|
|
139
|
+
details,
|
|
140
|
+
advice,
|
|
141
|
+
}
|
|
142
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-handoff-baton",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "交接棒:上下文快满时自动判断、归档并生成跨模型接棒码的 DeepSeek Harness 插件与通用技能",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"./bin/baton.mjs": "./bin/baton.mjs"
|
|
13
13
|
},
|
|
14
14
|
"bin": {
|
|
15
|
-
"baton": "
|
|
15
|
+
"baton": "bin/baton.mjs"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"index.js",
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
},
|
|
65
65
|
"repository": {
|
|
66
66
|
"type": "git",
|
|
67
|
-
"url": "git+https://github.com/
|
|
67
|
+
"url": "git+https://github.com/Well-WeiLuo/handoff-baton.git"
|
|
68
68
|
},
|
|
69
|
-
"homepage": "https://github.com/
|
|
69
|
+
"homepage": "https://github.com/Well-WeiLuo/handoff-baton#readme",
|
|
70
70
|
"bugs": {
|
|
71
|
-
"url": "https://github.com/
|
|
71
|
+
"url": "https://github.com/Well-WeiLuo/handoff-baton/issues"
|
|
72
72
|
},
|
|
73
73
|
"publishConfig": {
|
|
74
74
|
"access": "public"
|
package/skills/baton/SKILL.md
CHANGED
|
@@ -100,10 +100,11 @@ description: 交接棒——上下文快到上限、要换会话或要换模型
|
|
|
100
100
|
|
|
101
101
|
1. 先确认第一条消息开头有 `⟦baton⟧`;没有就不启动本流程
|
|
102
102
|
2. 定目标文档:带路径就用路径;裸标记先奔 `baton resolve`(或读索引)——在用(进行中 + 已接手)只有一条才用,多于一条列候选先问,不猜
|
|
103
|
-
3.
|
|
104
|
-
4.
|
|
105
|
-
5.
|
|
106
|
-
6.
|
|
103
|
+
3. 文档写于 12 小时以前时,先跑 `baton drift <文件>`:它核对关键文件是否还在、文档写完后有没有被改动、git 又走了多少提交。**有变化就先复核再往下**,没变化直接继续
|
|
104
|
+
4. 只按「关键文件」读真正需要的文件,别全量加载
|
|
105
|
+
5. 把那一行的状态改成「已接手」(`baton touch <文件> --status 已接手`)
|
|
106
|
+
6. 从「下一步」第 1 条继续
|
|
107
|
+
7. 动文件前先确认
|
|
107
108
|
|
|
108
109
|
## 没有 CLI 时(纯手写,任何模型都能做)
|
|
109
110
|
|