@twinsearth/dsh-fang 3.3.0 → 3.3.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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  > 目标:任何会影响 DSH 端安全的动作——打包、发布、安装、部署、新建 profile——都必须先通过同一套可复核检查。门禁拿不到证据时 **fail-closed**,不允许「先上再补」。
4
4
 
5
- ## 1. 六个入口
5
+ ## 1. 七个入口
6
6
 
7
7
  | target | 何时 | 关键检查 |
8
8
  |---|---|---|
@@ -11,6 +11,7 @@
11
11
  | `publish` | npm 发布前 | package 检查 + tag 与版本一致 + registry 同版本重复发布阻断(可显式 `--allow-existing`) |
12
12
  | `install` | 干净 profile 安装 | package + profile 路径/捆绑去重/patch 可解析 + 无活跃宿主 + 崩溃循环/safe-mode + 审计链 + 磁盘 |
13
13
  | `deploy` | 重启/部署前 | install 检查 + 备份(可 `--repair` 自动建)+ supervisor 证据 |
14
+ | `workflows` | CI/发布工作流变更 | 必需 ci/release、禁止 pull_request_target/write-all/secrets inherit、禁止 PR 字段直接插值 run、必须接 source gate 与 build.mjs |
14
15
  | `profile` | 新建/覆盖 profile | 名称白名单、禁止 `desktop`/`plugin`、路径必须在 `$DSH_HOME/profiles`、磁盘、已存在须 `--force` + 自动备份 |
15
16
 
16
17
  ## 2. 输出与退出码
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twinsearth/dsh-fang",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "dsh-Fang (瓮城) — mother/fork plugin development environment for DeepSeek Harness: one readonly mother, a disposable child dsh-Web per task.",
@@ -129,7 +129,7 @@ export const AUDIT = {
129
129
  RUNTIME_ERROR: 'runtime-error',
130
130
  }
131
131
 
132
- export const FANG_VERSION = '3.3.0'
132
+ export const FANG_VERSION = '3.3.1'
133
133
 
134
134
  /**
135
135
  * @typedef {object} ForkInfo
@@ -21,7 +21,7 @@ import { scoreGateFindings } from '../plugins/scorer.mjs'
21
21
  import { gateRepairPlan } from '../plugins/healer.mjs'
22
22
  import { CRASH_LOOP_DEFAULTS, detectCrashLoop } from './restart-contract.mjs'
23
23
 
24
- export const GATE_TARGETS = Object.freeze(['source', 'package', 'publish', 'install', 'deploy', 'profile'])
24
+ export const GATE_TARGETS = Object.freeze(['source', 'package', 'publish', 'install', 'deploy', 'workflows', 'profile'])
25
25
  export const GATE_SEVERITIES = Object.freeze(['blocker', 'warning', 'info'])
26
26
  export const DEFAULT_MIN_FREE_BYTES = 512 * 1024 * 1024
27
27
  export const RESERVED_PROFILE_NAMES = Object.freeze(['desktop', 'plugin'])
@@ -155,6 +155,8 @@ export function checkSourceTree({ root = process.cwd(), version = '' } = {}) {
155
155
  addCheck(checks, 'source: crash-loop breaker present', restart.includes('crash-loop') && restart.includes('clearSafeMode'), 'blocker', 'restart-guard crash-loop breaker')
156
156
  addCheck(checks, 'source: gate wired into build', readTextSafe(path.join(base, 'tools/release/build.mjs')).includes('main-city.mjs'), 'blocker', 'build must call the gate')
157
157
  addCheck(checks, 'source: gate wired into publish', readTextSafe(path.join(base, 'tools/release/publish-npm.mjs')).includes('main-city.mjs'), 'blocker', 'publish must call the gate')
158
+ const workflows = checkWorkflows({ root: base })
159
+ checks.push(...workflows.checks)
158
160
 
159
161
  const vendor = readJsonSafe(path.join(base, 'src/contract/VENDOR.json'))
160
162
  if (!vendor) fail(checks, 'source: vendored contract manifest', 'src/contract/VENDOR.json missing', 're-sync contract from npm')
@@ -177,6 +179,50 @@ export function checkSourceTree({ root = process.cwd(), version = '' } = {}) {
177
179
  return { target: 'source', checks, version: declared }
178
180
  }
179
181
 
182
+ /**
183
+ * v3.3.1:第七类目标 workflows —— CI/发布工作流本身的审计。
184
+ * 工作流是「谁能发布、能写什么」的执行入口;它被改坏时,源码门禁可能完全绕过。
185
+ */
186
+ export function checkWorkflows({ root = process.cwd() } = {}) {
187
+ const checks = []
188
+ const base = path.resolve(String(root))
189
+ const dir = path.join(base, '.github/workflows')
190
+ const required = ['ci.yml', 'release.yml']
191
+ const missing = required.filter((name) => !fs.existsSync(path.join(dir, name)))
192
+ addCheck(checks, 'workflows: required files', missing.length === 0, 'blocker', missing.length ? `missing=${missing.join(',')}` : 'ci.yml + release.yml', 'restore the CI/release workflows from the repository history')
193
+
194
+ const files = []
195
+ try {
196
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
197
+ if (entry.isFile() && /\.ya?ml$/i.test(entry.name)) files.push(path.join(dir, entry.name))
198
+ }
199
+ } catch { /* missing dir already reported */ }
200
+ addCheck(checks, 'workflows: files discoverable', files.length >= required.length, 'blocker', `${files.length} files`)
201
+
202
+ for (const file of files) {
203
+ const name = path.basename(file)
204
+ const text = readTextSafe(file)
205
+ if (!text.trim()) { fail(checks, `workflows: ${name} not empty`, 'empty workflow'); continue }
206
+ addCheck(checks, `workflows: ${name} has on/jobs`, /^on:/m.test(text) && /^jobs:/m.test(text), 'blocker', name)
207
+ addCheck(checks, `workflows: ${name} no pull_request_target`, !/pull_request_target/.test(text), 'blocker', name, 'pull_request_target exposes secrets to fork PRs; use pull_request with explicit env passing')
208
+ addCheck(checks, `workflows: ${name} no write-all`, !/permissions:\s*write-all/.test(text), 'blocker', name, 'grant the narrowest permission per job')
209
+ addCheck(checks, `workflows: ${name} no secrets inherit`, !/secrets:\s*inherit/.test(text), 'blocker', name, 'map only the secrets a job needs')
210
+ const unsafeInterpolation = text.split(/\r?\n/).some((line) => /\$\{\{\s*github\.event\.pull_request\.(title|body|head\.ref)\s*\}\}/.test(line) && !/^\s*[A-Z][A-Z0-9_]*:\s*\$\{\{/.test(line) && !/^\s*#/.test(line))
211
+ addCheck(checks, `workflows: ${name} no untrusted title interpolation`, !unsafeInterpolation, 'blocker', name, 'pass PR fields through env:, never interpolate them into run:')
212
+ addCheck(checks, `workflows: ${name} has job timeouts`, /timeout-minutes:/m.test(text), 'warning', name, 'add timeout-minutes to every job so a stuck runner cannot hang the release')
213
+ }
214
+
215
+ const ci = readTextSafe(path.join(dir, 'ci.yml'))
216
+ addCheck(checks, 'workflows: ci runs main-city source gate', ci.includes('tools/gate/main-city.mjs') && ci.includes('--target'), 'blocker', 'ci.yml', 'add the main-city source/workflows gate before tests')
217
+ addCheck(checks, 'workflows: ci runs full test suite', /node --test/.test(ci), 'blocker', 'ci.yml')
218
+ addCheck(checks, 'workflows: ci matrix 22+24', /node:\s*\[?[^\n]*22/.test(ci) && /node:\s*\[?[^\n]*24/.test(ci), 'warning', 'ci.yml', 'test both supported Node versions')
219
+ const release = readTextSafe(path.join(dir, 'release.yml'))
220
+ addCheck(checks, 'workflows: release runs main-city gate', release.includes('tools/gate/main-city.mjs'), 'blocker', 'release.yml', 'add the source gate to the release guard job')
221
+ addCheck(checks, 'workflows: release builds via gated build.mjs', release.includes('tools/release/build.mjs'), 'blocker', 'release.yml', 'release must use build.mjs (it runs package/publish gates)')
222
+ addCheck(checks, 'workflows: release grants contents write only where needed', release.includes('permissions:') && !/permissions:\s*write-all/.test(release), 'warning', 'release.yml')
223
+ return { checks, files: files.map((file) => path.basename(file)) }
224
+ }
225
+
180
226
  function checkStagedPackage({ packageDir, version }) {
181
227
  const checks = []
182
228
  const dir = path.resolve(String(packageDir ?? ''))
@@ -374,6 +420,10 @@ export function runMainGate(options = {}) {
374
420
  checks.push(...out.checks)
375
421
  }
376
422
  }
423
+ if (target === 'workflows') {
424
+ const out = checkWorkflows({ root: options.root ?? process.cwd() })
425
+ checks.push(...out.checks)
426
+ }
377
427
  if (target === 'publish') {
378
428
  const out = checkPublishMetadata({ version, tag: options.tag, npmLatest: options.npmLatest, allowExisting: options.allowExisting === true })
379
429
  checks.push(...out.checks)
@@ -523,4 +573,4 @@ export function createGatedProfile({ homeDir, profile, bundles = DEFAULT_PROFILE
523
573
  }
524
574
  }
525
575
 
526
- export const _internals = { checkSourceTree, checkStagedPackage, checkTarball, checkProfile, checkRuntimeGuards, checkPublishMetadata, isInside, pidAlive, diskFree }
576
+ export const _internals = { checkSourceTree, checkStagedPackage, checkTarball, checkProfile, checkRuntimeGuards, checkPublishMetadata, checkWorkflows, isInside, pidAlive, diskFree }