dsh-agent-soul 0.9.5 → 0.9.6
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 +13 -0
- package/lib/core/api-token.js +1 -1
- package/package.json +2 -1
- package/tools/lint.mjs +102 -0
- package/tools/run-tests.mjs +12 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## 0.9.6 · 2026-11-07
|
|
11
|
+
|
|
12
|
+
### 工程化
|
|
13
|
+
|
|
14
|
+
- **单个测试文件加超时**(P2-29):`tools/run-tests.mjs` 原来没有超时,一个挂死的用例(未 settle 的 await)能把 CI 拖到 GitHub 的 6 小时上限。现在默认 180 秒、`--timeout=<秒>` 可覆盖,超时按失败计并点名。
|
|
15
|
+
- **CI 加 `timeout-minutes` 与 `concurrency`**(P2-30):前者防止一次挂死烧光额度,后者让同一分支的旧 run 自动取消。
|
|
16
|
+
- **Linux job 跑 Node 22 + 24 矩阵**:`engines` 要求 ≥22.19,而 24 是当前主力版本,之前从没在 24 上跑过 CI。
|
|
17
|
+
- **新增 `npm run lint`(`tools/lint.mjs`)**:不引入 eslint(本项目零依赖),只查两条真出过问题的:未使用的 import、以及测试里的恒真断言 `ok(true, …)`。
|
|
18
|
+
- **清掉 9 处恒真断言**:`ok(true, '临时目录已清理')` 这类直接删除(清理动作仍在,只是不再假报一条绿);`r1-maintain-persist` 那条「没产生归档就跳过」改成**前置条件失败即红**;`smoke` 的 `disposer 可调用` 改成真断言「调用没抛错」。
|
|
19
|
+
- **修掉 1 处未使用导入**:`core/api-token.js` 的 `serviceOf`。
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
10
23
|
## 0.9.5 · 2026-11-07
|
|
11
24
|
|
|
12
25
|
### 修复
|
package/lib/core/api-token.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* 校验用 sha256 摘要 + timingSafeEqual 定长比较,避免长度与时序侧信道。
|
|
18
18
|
*/
|
|
19
19
|
import { createHash, randomBytes, timingSafeEqual } from 'node:crypto'
|
|
20
|
-
import { note
|
|
20
|
+
import { note } from '../env.js'
|
|
21
21
|
|
|
22
22
|
export const TOKEN_HEADER = 'x-soul-token'
|
|
23
23
|
export const SESSION_ROUTE = '/session'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-agent-soul",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "给 DSH 的 agent 一套会忘事的记忆、一份会变的人格和一份会起伏的心情:人格按小节合并(项目覆盖全局但不吃掉全局),记忆按人的规律衰减(清晰→模糊→只剩印象→遗忘),「心里惦记的事」让她的主动有连续性,心情跟着每轮对话自己判断、自己平复(不注入、无挂饰)。",
|
|
6
6
|
"keywords": [
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"build:client": "node tools/build-client.mjs",
|
|
38
38
|
"sync:host": "node tools/build-client.mjs && node tools/sync.mjs",
|
|
39
39
|
"test": "node tools/build-client.mjs && node tools/run-tests.mjs",
|
|
40
|
+
"lint": "node tools/lint.mjs",
|
|
40
41
|
"test:contracts": "node tools/run-tests.mjs --only=tests/contract/",
|
|
41
42
|
"test:s1": "node tests/s1-hotfix.test.js",
|
|
42
43
|
"test:s2": "node tests/s2-hardening.test.js",
|
package/tools/lint.mjs
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 轻量静态检查(2026-11-07 R12 / P2-30)。
|
|
4
|
+
*
|
|
5
|
+
* 为什么不用 eslint:这个项目**零运行时依赖**,为了一个 lint 装一棵 200 包的依赖树
|
|
6
|
+
* 不划算,而且 esbuild/TS 那套配置对纯 ESM 脚本过重。
|
|
7
|
+
* 这里只做两条「不需要解析器也能查、且真出过问题」的检查:
|
|
8
|
+
*
|
|
9
|
+
* ① 未使用的 import 名字 —— 报告里就有一条:`segment-memory.js` 导入了 `name` 从没用过。
|
|
10
|
+
* 死导入不会报错,只会在读代码时误导人(以为这里用到了)。
|
|
11
|
+
* ② 测试里的恒真断言 `ok(true, …)` —— 它们看起来像断言,实际什么都没验。
|
|
12
|
+
* 允许带 `// lint-allow:ok-true` 的行(真需要「到这里没抛异常就算过」时用)。
|
|
13
|
+
*
|
|
14
|
+
* 两条都是**保守**的:宁可漏报,也不要因为字符串里恰好出现某个词就误报。
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync, readdirSync } from 'node:fs'
|
|
17
|
+
import { dirname, join, relative } from 'node:path'
|
|
18
|
+
import { fileURLToPath } from 'node:url'
|
|
19
|
+
|
|
20
|
+
const projectRoot = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
21
|
+
|
|
22
|
+
function walk(dir, ext = '.js') {
|
|
23
|
+
const out = []
|
|
24
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
25
|
+
const full = join(dir, entry.name)
|
|
26
|
+
if (entry.isDirectory()) out.push(...walk(full, ext))
|
|
27
|
+
else if (entry.name.endsWith(ext)) out.push(full)
|
|
28
|
+
}
|
|
29
|
+
return out
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 从 `import { a, b as c } from '…'` 里抠出本地名字 */
|
|
33
|
+
function importedNames(text) {
|
|
34
|
+
const names = []
|
|
35
|
+
const re = /import\s*\{([^}]*)\}\s*from\s*['"][^'"]+['"]/g
|
|
36
|
+
let m
|
|
37
|
+
while ((m = re.exec(text)) !== null) {
|
|
38
|
+
for (const part of m[1].split(',')) {
|
|
39
|
+
const piece = part.trim()
|
|
40
|
+
if (piece === '') continue
|
|
41
|
+
const asMatch = /\bas\s+([A-Za-z_$][\w$]*)$/.exec(piece)
|
|
42
|
+
const local = asMatch ? asMatch[1] : piece
|
|
43
|
+
if (/^[A-Za-z_$][\w$]*$/.test(local)) names.push({ local, index: m.index })
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return names
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 这个标识符在文件里除了 import 语句之外还出现过吗 */
|
|
50
|
+
function usedElsewhere(text, local, importIndex) {
|
|
51
|
+
const escaped = local.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
52
|
+
const re = new RegExp(`\\b${escaped}\\b`, 'g')
|
|
53
|
+
let m
|
|
54
|
+
while ((m = re.exec(text)) !== null) {
|
|
55
|
+
// 跳过 import 语句所在的那一段(从 import 到该语句结尾的分号)
|
|
56
|
+
if (m.index >= importIndex) {
|
|
57
|
+
const tail = text.slice(importIndex)
|
|
58
|
+
const end = tail.indexOf('\n')
|
|
59
|
+
const lineEnd = end === -1 ? text.length : importIndex + end
|
|
60
|
+
if (m.index < lineEnd) continue
|
|
61
|
+
}
|
|
62
|
+
return true
|
|
63
|
+
}
|
|
64
|
+
return false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const problems = []
|
|
68
|
+
|
|
69
|
+
for (const file of walk(join(projectRoot, 'lib'))) {
|
|
70
|
+
const rel = relative(projectRoot, file).replace(/\\/g, '/')
|
|
71
|
+
const text = readFileSync(file, 'utf8')
|
|
72
|
+
for (const { local, index } of importedNames(text)) {
|
|
73
|
+
if (local === 'default') continue
|
|
74
|
+
if (!usedElsewhere(text, local, index)) {
|
|
75
|
+
problems.push({ file: rel, kind: 'unused-import', name: local })
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for (const file of walk(join(projectRoot, 'tests'))) {
|
|
81
|
+
const rel = relative(projectRoot, file).replace(/\\/g, '/')
|
|
82
|
+
const lines = readFileSync(file, 'utf8').split('\n')
|
|
83
|
+
lines.forEach((line, i) => {
|
|
84
|
+
// 注释里提到 ok(true, …) 不算问题(那是解释,不是断言)
|
|
85
|
+
if (/^\s*(\/\/|\*)/.test(line)) return
|
|
86
|
+
if (!/\bok\(\s*true\b/.test(line)) return
|
|
87
|
+
if (line.includes('lint-allow:ok-true')) return
|
|
88
|
+
problems.push({ file: rel, kind: 'ok-true', line: i + 1, text: line.trim() })
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (problems.length === 0) {
|
|
93
|
+
console.log('lint: 没有发现问题(未使用导入 / 恒真断言)')
|
|
94
|
+
process.exit(0)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
for (const p of problems) {
|
|
98
|
+
if (p.kind === 'unused-import') console.error(`✗ ${p.file}: 导入了 ${p.name} 但没用过`)
|
|
99
|
+
else console.error(`✗ ${p.file}:${p.line}: 恒真断言 ok(true, …) —— ${p.text.slice(0, 80)}`)
|
|
100
|
+
}
|
|
101
|
+
console.error(`\nlint: ${problems.length} 个问题`)
|
|
102
|
+
process.exit(1)
|
package/tools/run-tests.mjs
CHANGED
|
@@ -51,16 +51,26 @@ function main() {
|
|
|
51
51
|
// 2026-11-06 审计 Q12:失败即 break 的话,第一个红就把后面 40 多个文件全挡住,
|
|
52
52
|
// 一次只能修一个问题。改成跑完全部再汇总(--stop-on-first-failure 保留旧行为)。
|
|
53
53
|
const stopEarly = process.argv.includes('--stop-on-first-failure')
|
|
54
|
+
// 2026-11-07 R12 / P2-29:单个测试文件原来**没有超时** —— 一个挂死的用例
|
|
55
|
+
// (未 settle 的 await、等不到的 Promise)会把整个 CI 拖到 GitHub 的 6 小时上限。
|
|
56
|
+
// 默认 180 秒,可用 --timeout=<秒> 覆盖;超时按失败计,并在汇总里点名。
|
|
57
|
+
const timeoutArg = (process.argv.find((a) => a.startsWith('--timeout=')) ?? '').slice('--timeout='.length)
|
|
58
|
+
const timeoutMs = Math.max(10_000, Math.trunc(Number(timeoutArg) || 180) * 1000)
|
|
54
59
|
for (const rel of files) {
|
|
55
60
|
executed += 1
|
|
56
61
|
console.log(`\n===== [${executed}/${files.length}] ${rel} =====`)
|
|
57
62
|
const result = spawnSync(process.execPath, [join(projectRoot, rel)], {
|
|
58
63
|
cwd: projectRoot,
|
|
59
64
|
env: process.env,
|
|
60
|
-
stdio: 'inherit'
|
|
65
|
+
stdio: 'inherit',
|
|
66
|
+
timeout: timeoutMs,
|
|
67
|
+
killSignal: 'SIGKILL'
|
|
61
68
|
})
|
|
62
69
|
if (result.error) {
|
|
63
|
-
|
|
70
|
+
const timedOut = result.error.code === 'ETIMEDOUT' || result.signal === 'SIGKILL'
|
|
71
|
+
console.error(timedOut
|
|
72
|
+
? `✗ ${rel} 超时(>${Math.round(timeoutMs / 1000)}s)—— 视为失败,不让它拖死整个 CI`
|
|
73
|
+
: `✗ ${rel} 启动失败:${result.error.message}`)
|
|
64
74
|
failed += 1
|
|
65
75
|
failures.push(rel)
|
|
66
76
|
if (stopEarly) break
|