dsh-project-flow 0.10.2 → 0.10.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 +20 -0
- package/config/settings.mjs +2 -2
- package/evidence.mjs +3 -2
- package/package.json +1 -1
- package/persistence/lock.mjs +2 -2
- package/persistence/state.mjs +9 -5
- package/rollback/ledger.mjs +2 -2
- package/shared/util.mjs +17 -1
- package/tests/panel-report.test.mjs +35 -2
- package/workspace/paths.mjs +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -14,6 +14,26 @@ dsh-project-flow 的版本变更。版本号遵循语义化版本。
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
+
## [0.10.3] - 2026-12-05
|
|
18
|
+
|
|
19
|
+
### 带 BOM 的 state.json 让项目从面板上消失
|
|
20
|
+
|
|
21
|
+
真机上 9 个项目只显示 8 个。少的是 `opc-deck-v4`:它的 `state.json` 开头带 `EF BB BF`(UTF-8 BOM),`JSON.parse` 见到直接抛,`readState` 返回 `undefined`,面板那边 `if (state === undefined) continue` 就把它跳过了——一声不响。
|
|
22
|
+
|
|
23
|
+
Windows 上这玩意儿到处都是:记事本另存、某些 PowerShell 写法、从别的机器拷文件,都会带。以前只有 `splitFrontMatter`(Markdown 那条路)处理过 BOM,JSON 这条路没管。
|
|
24
|
+
|
|
25
|
+
现在 `shared/util.mjs` 加了 `stripBom`,用在所有 JSON 读取点:`readState`、`writeState`、`readContract`、`readRememberedContext`、`readOverride`、`readLedger`、锁文件、`readEvidence`、以及从会话存储里取 cwd 那一处。
|
|
26
|
+
|
|
27
|
+
### writeState 里藏着同一个坑
|
|
28
|
+
|
|
29
|
+
`writeState` 读旧 state 失败时 `previous = {}`,然后 `{ ...{}, ...patch }` 写回去——`stage`、`requirements`、`attempts`、`cost` 全没了,只剩这一次的 patch。带 BOM 的 state.json 正好会走到这条路上。
|
|
30
|
+
|
|
31
|
+
这和 0.10.1 修的 `writeOverride` 是同一个病。那边丢的是配置,这边丢的是运行时状态,更难发现——文件还在、还能解析,只是内容变成了刚写的那几个键。
|
|
32
|
+
|
|
33
|
+
### 测试
|
|
34
|
+
|
|
35
|
+
`tests/panel-report.test.mjs` 从 9 条加到 10 条:手工拼一个带 BOM 的 `state.json` 丢给 `panelSnapshot`,断言那个项目还在、阶段读得出来。
|
|
36
|
+
|
|
17
37
|
## [0.10.2] - 2026-12-05
|
|
18
38
|
|
|
19
39
|
修「工作模式开起来了,状态栏却什么都没变」。三条独立的原因,叠在一起。
|
package/config/settings.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { join, dirname } from 'node:path'
|
|
|
5
5
|
import { homedir } from 'node:os'
|
|
6
6
|
import { readFileSync } from 'node:fs'
|
|
7
7
|
import { mkdir, readFile } from 'node:fs/promises'
|
|
8
|
-
import { writeFileAtomic } from '../shared/util.mjs'
|
|
8
|
+
import { stripBom, writeFileAtomic } from '../shared/util.mjs'
|
|
9
9
|
import { DEFAULT_SNAPSHOT_EXCLUDES, FLOAT_SETTINGS } from '../shared/constants.mjs'
|
|
10
10
|
|
|
11
11
|
const pick = (value, fallback) => (value === undefined || value === '' ? fallback : value)
|
|
@@ -104,7 +104,7 @@ const readOverride = () => {
|
|
|
104
104
|
const merged = {}
|
|
105
105
|
for (const file of overridePaths().slice().reverse()) {
|
|
106
106
|
try {
|
|
107
|
-
const parsed = JSON.parse(readFileSync(file, 'utf8'))
|
|
107
|
+
const parsed = JSON.parse(stripBom(readFileSync(file, 'utf8')))
|
|
108
108
|
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
109
109
|
Object.assign(merged, parsed)
|
|
110
110
|
}
|
package/evidence.mjs
CHANGED
|
@@ -17,6 +17,7 @@ import { execFile } from 'node:child_process'
|
|
|
17
17
|
import { writeFile, readFile, readdir, stat, rename, rm } from 'node:fs/promises'
|
|
18
18
|
import { homedir } from 'node:os'
|
|
19
19
|
import { join } from 'node:path'
|
|
20
|
+
import { stripBom } from './shared/util.mjs'
|
|
20
21
|
|
|
21
22
|
export const EVIDENCE_FILE = 'Completion_Evidence.json'
|
|
22
23
|
export const EVIDENCE_SCHEMA_VERSION = 1
|
|
@@ -97,7 +98,7 @@ async function detectIn(cwd) {
|
|
|
97
98
|
// "echo \"Error: no test specified\"" 不算测试。
|
|
98
99
|
if (await has('package.json')) {
|
|
99
100
|
try {
|
|
100
|
-
const pkg = JSON.parse(await readFile(join(cwd, 'package.json'), 'utf8'))
|
|
101
|
+
const pkg = JSON.parse(stripBom(await readFile(join(cwd, 'package.json'), 'utf8')))
|
|
101
102
|
const script = pkg?.scripts?.test
|
|
102
103
|
if (typeof script === 'string' && script.trim() !== '' && !/no test specified/i.test(script)) {
|
|
103
104
|
return { command: 'npm test', why: 'package.json 里有 scripts.test' }
|
|
@@ -499,7 +500,7 @@ export async function writeEvidence(artifacts, evidence) {
|
|
|
499
500
|
/** 读回来。补丁里给 project_status 之类的只读工具用。 */
|
|
500
501
|
export async function readEvidence(artifacts) {
|
|
501
502
|
try {
|
|
502
|
-
return JSON.parse(await readFile(join(artifacts, EVIDENCE_FILE), 'utf8'))
|
|
503
|
+
return JSON.parse(stripBom(await readFile(join(artifacts, EVIDENCE_FILE), 'utf8')))
|
|
503
504
|
} catch {
|
|
504
505
|
return undefined
|
|
505
506
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-project-flow",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Four-stage project workflow: requirement, plan, build, QA, with an intent gate, a rework loop, self-healing recovery, a watchdog that stops runaway runs, snapshot rollback with a retention cap, a single status light, and a machine-readable Completion_Evidence.json.",
|
|
6
6
|
"type": "module",
|
package/persistence/lock.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { join } from 'node:path'
|
|
5
5
|
import { readFile, mkdir, rename, writeFile, rm } from 'node:fs/promises'
|
|
6
|
-
import { isAlive, nowIso, stateDir, writeFileAtomic } from '../shared/util.mjs'
|
|
6
|
+
import { isAlive, nowIso, stateDir, stripBom, writeFileAtomic } from '../shared/util.mjs'
|
|
7
7
|
|
|
8
8
|
export function lockFile(cwd, project) {
|
|
9
9
|
return join(stateDir(cwd, project), 'run.lock')
|
|
@@ -11,7 +11,7 @@ export function lockFile(cwd, project) {
|
|
|
11
11
|
|
|
12
12
|
export async function readLock(cwd, project) {
|
|
13
13
|
try {
|
|
14
|
-
const parsed = JSON.parse(await readFile(lockFile(cwd, project), 'utf8'))
|
|
14
|
+
const parsed = JSON.parse(stripBom(await readFile(lockFile(cwd, project), 'utf8')))
|
|
15
15
|
return parsed !== null && typeof parsed === 'object' ? parsed : undefined
|
|
16
16
|
} catch {
|
|
17
17
|
return undefined
|
package/persistence/state.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { createHash } from 'node:crypto'
|
|
|
7
7
|
import { BUILTIN_FLOW, loadFlow } from '../flow.schema.mjs'
|
|
8
8
|
import { parseRequirementChecks, requirementFingerprint } from '../checks/requirement.mjs'
|
|
9
9
|
import { ARTIFACT, CONTEXT_FILE, CONTRACT_FILE, CONTRACT_MAX_CHARS } from '../shared/constants.mjs'
|
|
10
|
-
import { filled, nowIso, stateDir, writeFileAtomic } from '../shared/util.mjs'
|
|
10
|
+
import { filled, nowIso, stateDir, stripBom, writeFileAtomic } from '../shared/util.mjs'
|
|
11
11
|
|
|
12
12
|
export async function writeState(cwd, project, patch) {
|
|
13
13
|
const dir = stateDir(cwd, project)
|
|
@@ -15,7 +15,11 @@ export async function writeState(cwd, project, patch) {
|
|
|
15
15
|
const file = join(dir, 'state.json')
|
|
16
16
|
let previous = {}
|
|
17
17
|
try {
|
|
18
|
-
|
|
18
|
+
// 必须 stripBom:带 BOM 的 state.json 会让 JSON.parse 抛,然后 previous 被当成
|
|
19
|
+
// {} ——这一轮的 patch 覆盖上去,stage / requirements / attempts / cost 全没了。
|
|
20
|
+
// 这跟 writeOverride 里那个「读失败静默降级成空对象」是同一个坑,只是这边
|
|
21
|
+
// 丢的是运行时状态,比配置更难发现。
|
|
22
|
+
previous = JSON.parse(stripBom(await readFile(file, 'utf8')))
|
|
19
23
|
} catch {
|
|
20
24
|
previous = {}
|
|
21
25
|
}
|
|
@@ -26,7 +30,7 @@ export async function writeState(cwd, project, patch) {
|
|
|
26
30
|
|
|
27
31
|
export async function readState(cwd, project) {
|
|
28
32
|
try {
|
|
29
|
-
return JSON.parse(await readFile(join(stateDir(cwd, project), 'state.json'), 'utf8'))
|
|
33
|
+
return JSON.parse(stripBom(await readFile(join(stateDir(cwd, project), 'state.json'), 'utf8')))
|
|
30
34
|
} catch {
|
|
31
35
|
return undefined
|
|
32
36
|
}
|
|
@@ -71,7 +75,7 @@ export function contractSha(contract) {
|
|
|
71
75
|
|
|
72
76
|
export async function readContract(cwd, project) {
|
|
73
77
|
try {
|
|
74
|
-
const parsed = JSON.parse(await readFile(join(stateDir(cwd, project), CONTRACT_FILE), 'utf8'))
|
|
78
|
+
const parsed = JSON.parse(stripBom(await readFile(join(stateDir(cwd, project), CONTRACT_FILE), 'utf8')))
|
|
75
79
|
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return undefined
|
|
76
80
|
return parsed
|
|
77
81
|
} catch {
|
|
@@ -163,7 +167,7 @@ export function phaseReadKeys(phase) {
|
|
|
163
167
|
|
|
164
168
|
export async function readRememberedContext(cwd) {
|
|
165
169
|
try {
|
|
166
|
-
const parsed = JSON.parse(await readFile(join(cwd, '.project-flow', CONTEXT_FILE), 'utf8'))
|
|
170
|
+
const parsed = JSON.parse(stripBom(await readFile(join(cwd, '.project-flow', CONTEXT_FILE), 'utf8')))
|
|
167
171
|
if (parsed === null || typeof parsed !== 'object') return undefined
|
|
168
172
|
return parsed
|
|
169
173
|
} catch {
|
package/rollback/ledger.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { join, isAbsolute, relative } from 'node:path'
|
|
5
5
|
import { mkdirSync, appendFileSync, readFileSync } from 'node:fs'
|
|
6
6
|
import { rm } from 'node:fs/promises'
|
|
7
|
-
import { fileSha256, messageOf, nowIso, stateDir } from '../shared/util.mjs'
|
|
7
|
+
import { fileSha256, messageOf, nowIso, stateDir, stripBom } from '../shared/util.mjs'
|
|
8
8
|
import { snapshotCommand } from '../snapshot/repo.mjs'
|
|
9
9
|
|
|
10
10
|
export function ledgerDir(cwd, project) {
|
|
@@ -35,7 +35,7 @@ export function readLedger(cwd, project) {
|
|
|
35
35
|
const path = ledgerPath(cwd, project)
|
|
36
36
|
let text
|
|
37
37
|
try {
|
|
38
|
-
text = readFileSync(path, 'utf8')
|
|
38
|
+
text = stripBom(readFileSync(path, 'utf8'))
|
|
39
39
|
} catch {
|
|
40
40
|
return []
|
|
41
41
|
}
|
package/shared/util.mjs
CHANGED
|
@@ -126,9 +126,25 @@ export function parseJsonBlock(text, marker) {
|
|
|
126
126
|
|
|
127
127
|
export const filled = value => typeof value === 'string' && value.trim() !== ''
|
|
128
128
|
|
|
129
|
+
/**
|
|
130
|
+
* 去掉 UTF-8 BOM。
|
|
131
|
+
*
|
|
132
|
+
* Windows 上这东西到处都是:记事本另存、某些 PowerShell 写法、从别的机器拷过来
|
|
133
|
+
* 的文件,开头都可能带一个 0xFEFF。而 `JSON.parse` 见到它直接抛,报的是
|
|
134
|
+
* 「Unexpected token」,从错误信息里根本看不出是 BOM 惹的。
|
|
135
|
+
*
|
|
136
|
+
* `state.json` 尤其容易中招——它不是插件自己写的,用户编辑过、脚本生成过、
|
|
137
|
+
* 老版本留下过,都可能带。以前 `splitFrontMatter` 里单独处理过一次(Markdown
|
|
138
|
+
* 那条路),JSON 这条路没管:于是带 BOM 的 state.json 读出来是 undefined,
|
|
139
|
+
* 面板上那个项目直接消失,一声不响。
|
|
140
|
+
*/
|
|
141
|
+
export function stripBom(text) {
|
|
142
|
+
return typeof text === 'string' && text.charCodeAt(0) === 0xFEFF ? text.slice(1) : text
|
|
143
|
+
}
|
|
144
|
+
|
|
129
145
|
export function splitFrontMatter(text) {
|
|
130
146
|
if (typeof text !== 'string') return { front: '', body: '' }
|
|
131
|
-
const trimmed = text
|
|
147
|
+
const trimmed = stripBom(text)
|
|
132
148
|
if (!trimmed.startsWith('---')) return { front: '', body: trimmed }
|
|
133
149
|
const firstBreak = trimmed.indexOf('\n')
|
|
134
150
|
if (firstBreak === -1) return { front: '', body: trimmed }
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
import { test } from 'node:test'
|
|
11
11
|
import assert from 'node:assert/strict'
|
|
12
12
|
import { join } from 'node:path'
|
|
13
|
-
import { readFile } from 'node:fs/promises'
|
|
13
|
+
import { readFile, mkdir, writeFile, rm, mkdtemp } from 'node:fs/promises'
|
|
14
|
+
import { tmpdir } from 'node:os'
|
|
14
15
|
import { pathToFileURL } from 'node:url'
|
|
15
16
|
import { LIVE_DIR, sourceText } from './paths.mjs'
|
|
16
17
|
|
|
@@ -126,4 +127,36 @@ test('挂掉的命令单独拎出来,带退出码', () => {
|
|
|
126
127
|
const window = source.slice(at, at + 2200)
|
|
127
128
|
assert.ok(window.includes("item.status === 'fail'"), 'fail 要进 failed')
|
|
128
129
|
assert.ok(window.includes('exit: Number.isInteger(item.exit)'), '退出码要带上')
|
|
129
|
-
})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('★ 带 BOM 的 state.json 也读得出来,项目不会从面板上消失', async () => {
|
|
133
|
+
// 真机踩到过:opc-deck-v4 的 state.json 开头带 0xEF 0xBB 0xBF(记事本另存、
|
|
134
|
+
// PowerShell 写法、从别的机器拷,都会带)。JSON.parse 见到 BOM 直接抛,
|
|
135
|
+
// readState 返回 undefined,面板就把它跳过了——9 个项目只显示 8 个,
|
|
136
|
+
// 而且一声不响。
|
|
137
|
+
const home = await mkdtemp(join(tmpdir(), 'pf-bom-'))
|
|
138
|
+
const prevHome = process.env.DSH_HOME
|
|
139
|
+
process.env.DSH_HOME = home
|
|
140
|
+
try {
|
|
141
|
+
const root = join(home, '工作流')
|
|
142
|
+
const dir = join(root, '.project-flow', 'bomproj')
|
|
143
|
+
await mkdir(dir, { recursive: true })
|
|
144
|
+
const body = JSON.stringify({ stage: 4, status: 'passed', rework: 1 }, null, 2)
|
|
145
|
+
// 手工拼 BOM:0xEF 0xBB 0xBF
|
|
146
|
+
await writeFile(join(dir, 'state.json'), Buffer.concat([
|
|
147
|
+
Buffer.from([0xEF, 0xBB, 0xBF]),
|
|
148
|
+
Buffer.from(body + '\n', 'utf8'),
|
|
149
|
+
]))
|
|
150
|
+
const settings = { flowGate: 'strict', flowRoot: '', maxRework: 2, maxConcurrentProjects: 2,
|
|
151
|
+
provider: 'spawn', intentModel: '', planModel: '', buildModel: '', checkModel: '',
|
|
152
|
+
planProvider: '', buildProvider: '', checkProvider: '', domain: 'auto', autoCreateFlowDir: true }
|
|
153
|
+
const snap = await mod.panelSnapshot(root, settings)
|
|
154
|
+
assert.equal(snap.projects.length, 1, '带 BOM 的项目必须还在')
|
|
155
|
+
assert.equal(snap.projects[0].project, 'bomproj')
|
|
156
|
+
assert.equal(snap.projects[0].stage, 4)
|
|
157
|
+
} finally {
|
|
158
|
+
if (prevHome === undefined) delete process.env.DSH_HOME
|
|
159
|
+
else process.env.DSH_HOME = prevHome
|
|
160
|
+
await rm(home, { recursive: true, force: true }).catch(() => {})
|
|
161
|
+
}
|
|
162
|
+
})
|
package/workspace/paths.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { existsSync } from 'node:fs'
|
|
|
7
7
|
import { mkdir, readFile } from 'node:fs/promises'
|
|
8
8
|
import { tmpdir, homedir } from 'node:os'
|
|
9
9
|
import { FLOW_DIR_NAME, FLOW_GATE_MODES, INTENT_CONFIDENCE_FLOOR, LAST_ROOT_FILE } from '../shared/constants.mjs'
|
|
10
|
-
import { dirExists, messageOf, writeFileAtomic } from '../shared/util.mjs'
|
|
10
|
+
import { dirExists, messageOf, stripBom, writeFileAtomic } from '../shared/util.mjs'
|
|
11
11
|
import { pfState } from '../state/registry.mjs'
|
|
12
12
|
|
|
13
13
|
export function cwdOf(ctx, agent) {
|
|
@@ -332,7 +332,7 @@ export async function cwdFromSessionStore(sid) {
|
|
|
332
332
|
if (sid.includes('/') || sid.includes('\\') || sid.includes('..')) return undefined
|
|
333
333
|
const file = join(stateHome(), 'storages', 'session_projcache', 'sessions', `${sid}.json`)
|
|
334
334
|
try {
|
|
335
|
-
const parsed = JSON.parse(await readFile(file, 'utf8'))
|
|
335
|
+
const parsed = JSON.parse(stripBom(await readFile(file, 'utf8')))
|
|
336
336
|
const cwd = parsed?.record?.identity?.cwd
|
|
337
337
|
return typeof cwd === 'string' && cwd !== '' && isAbsolute(cwd) ? cwd : undefined
|
|
338
338
|
} catch {
|