@twinsearth/dsh-fang 3.0.10 → 3.1.2
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/client.js +1511 -1
- package/cordis.patch.yml +9 -0
- package/package.json +6 -2
- package/src/compose.mjs +4 -1
- package/src/kernel/paths.mjs +9 -1
- package/src/kernel/role.mjs +1 -0
- package/src/kernel/types.mjs +5 -1
- package/src/lib/ai-secret-store.mjs +202 -0
- package/src/lib/boot-guard.mjs +182 -0
- package/src/lib/business-producers.mjs +109 -0
- package/src/lib/compat.mjs +1 -1
- package/src/lib/composer-journal.mjs +8 -0
- package/src/lib/decision-events.mjs +129 -0
- package/src/lib/decision-ingest-client.mjs +41 -0
- package/src/lib/decision-outbox.mjs +129 -0
- package/src/lib/desktop-launch.mjs +138 -0
- package/src/lib/fork-config-lock.mjs +65 -2
- package/src/lib/fork-supervision-settings.mjs +58 -0
- package/src/lib/mirror-official-source.mjs +93 -0
- package/src/lib/mirror.mjs +10 -3
- package/src/lib/producer-contract.mjs +162 -0
- package/src/lib/restart-contract.mjs +650 -0
- package/src/lib/rule-registry.mjs +69 -0
- package/src/lib/ssrf-guard.mjs +170 -0
- package/src/lib/umbrella.mjs +143 -18
- package/src/plugins/adapter.mjs +31 -2
- package/src/plugins/approver.mjs +423 -40
- package/src/plugins/decision-center.mjs +2255 -0
- package/src/plugins/forker.mjs +33 -2
- package/src/plugins/healer.mjs +53 -20
- package/src/plugins/imports.mjs +48 -0
- package/src/plugins/orchestrator.mjs +818 -42
- package/src/plugins/restart-guard.mjs +645 -52
- package/src/plugins/scorer.mjs +227 -15
- package/src/plugins/umbrella.mjs +18 -14
- package/tools/boot-guard.mjs +95 -0
- package/tools/decision-ingest.mjs +53 -0
- package/tools/desktop-launch.mjs +71 -0
- package/tools/fangctl.mjs +229 -1
package/src/plugins/forker.mjs
CHANGED
|
@@ -80,6 +80,18 @@ const PORT_PROBE_TIMEOUT_MS = 5000
|
|
|
80
80
|
/** Bundle list of the clean fork profile: base + web app + this bundle (Cordis patch). */
|
|
81
81
|
const CLEAN_TEMPLATE_BUNDLES = ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app']
|
|
82
82
|
|
|
83
|
+
// v3.1.0: DSH's first-run preview notice persists ui-settings-general.welcomeNoticeVersion.
|
|
84
|
+
// A clean profile that omits the row leaves the config form unavailable, so 「继续」 always
|
|
85
|
+
// reports "暂时无法保存确认状态". Seed the acknowledgement in every generated clean profile;
|
|
86
|
+
// the fork lock then appends its own disable rows.
|
|
87
|
+
const WELCOME_NOTICE_PATCH = [
|
|
88
|
+
'- id: ui-settings-general',
|
|
89
|
+
' name: "@deepseek-ai/dsh-client-ui-settings-general"',
|
|
90
|
+
' config:',
|
|
91
|
+
' welcomeNoticeVersion: 2026-09-28.1',
|
|
92
|
+
'',
|
|
93
|
+
].join('\n')
|
|
94
|
+
|
|
83
95
|
const DEFAULTS = {
|
|
84
96
|
cliPath: '',
|
|
85
97
|
profileTemplate: '',
|
|
@@ -359,6 +371,8 @@ export function apply(ctx, config) {
|
|
|
359
371
|
const bundleName = String(rawConfig.bundleName ?? DEFAULTS.bundleName).trim() || DEFAULTS.bundleName
|
|
360
372
|
const forkProfileTag = safeProfile(rawConfig.forkProfileTag)
|
|
361
373
|
const cfg = { ...rawConfig, portPool, allocatePorts, cleanTemplate, bundleName, forkProfileTag }
|
|
374
|
+
// 运行时 supervise 开关:patch/config 的初值 + 可在不重启宿主的情况下切换(UI/API)。
|
|
375
|
+
let runtimeSupervise = cfg.supervise === true
|
|
362
376
|
|
|
363
377
|
const logger = ctx?.logger ?? { debug() {}, info() {}, warn() {}, error() {} }
|
|
364
378
|
const logWarn = (line) => {
|
|
@@ -686,7 +700,7 @@ export function apply(ctx, config) {
|
|
|
686
700
|
)
|
|
687
701
|
files.push('package.json')
|
|
688
702
|
for (const name of ['cordis.yml', 'cordis.patch.yml']) {
|
|
689
|
-
writeFileAtomic(path.join(templateDir, name), '[]\n')
|
|
703
|
+
writeFileAtomic(path.join(templateDir, name), name === 'cordis.patch.yml' ? WELCOME_NOTICE_PATCH : '[]\n')
|
|
690
704
|
files.push(name)
|
|
691
705
|
}
|
|
692
706
|
const srcRaw = String(opts.nodeModulesSource ?? '').trim()
|
|
@@ -1102,7 +1116,7 @@ export function apply(ctx, config) {
|
|
|
1102
1116
|
writeForkMetaOf(rec)
|
|
1103
1117
|
persist()
|
|
1104
1118
|
}
|
|
1105
|
-
if (!rec.intentionalStop &&
|
|
1119
|
+
if (!rec.intentionalStop && runtimeSupervise && !disposed) {
|
|
1106
1120
|
const plan = planRestart(exitInfo, rec, {
|
|
1107
1121
|
maxRestarts: cfg.maxRestarts, baseMs: cfg.backoffBaseMs,
|
|
1108
1122
|
maxMs: cfg.backoffMaxMs, jitter: cfg.backoffJitter,
|
|
@@ -1348,6 +1362,23 @@ export function apply(ctx, config) {
|
|
|
1348
1362
|
get config() {
|
|
1349
1363
|
return { ...cfg }
|
|
1350
1364
|
},
|
|
1365
|
+
/** 运行时看护状态;enabled 可在不重启宿主的情况下切换。 */
|
|
1366
|
+
getSupervision() {
|
|
1367
|
+
return {
|
|
1368
|
+
enabled: runtimeSupervise,
|
|
1369
|
+
configured: cfg.supervise === true,
|
|
1370
|
+
maxRestarts: cfg.maxRestarts,
|
|
1371
|
+
backoffBaseMs: cfg.backoffBaseMs,
|
|
1372
|
+
backoffMaxMs: cfg.backoffMaxMs,
|
|
1373
|
+
backoffJitter: cfg.backoffJitter,
|
|
1374
|
+
healthPath: cfg.healthPath,
|
|
1375
|
+
}
|
|
1376
|
+
},
|
|
1377
|
+
setSupervise(enabled) {
|
|
1378
|
+
runtimeSupervise = enabled === true
|
|
1379
|
+
try { audit(AUDIT.FORK_SUPERVISION, { enabled: runtimeSupervise }) } catch { /* audit optional */ }
|
|
1380
|
+
return { ok: true, enabled: runtimeSupervise }
|
|
1381
|
+
},
|
|
1351
1382
|
}
|
|
1352
1383
|
|
|
1353
1384
|
ctx.effect(() => ctx.provide(SERVICE.forker, service))
|
package/src/plugins/healer.mjs
CHANGED
|
@@ -29,7 +29,7 @@ import fs from 'node:fs'
|
|
|
29
29
|
import path from 'node:path'
|
|
30
30
|
import { SERVICE, AUDIT, z, readJson, listFiles, sha256, exists } from '../kernel/index.mjs'
|
|
31
31
|
import { scanSource, importsToSignals } from './imports.mjs'
|
|
32
|
-
import { scoreScan, familyOf, entryCandidates } from './scorer.mjs'
|
|
32
|
+
import { scoreScan, familyOf, entryCandidates, resolvePluginFile } from './scorer.mjs'
|
|
33
33
|
import { roleGate } from '../kernel/index.mjs'
|
|
34
34
|
|
|
35
35
|
export const name = 'fang-healer'
|
|
@@ -133,11 +133,14 @@ function depAllowed(dep, cfg) {
|
|
|
133
133
|
*/
|
|
134
134
|
export function readModel(dir, opts = {}) {
|
|
135
135
|
const abs = path.resolve(String(dir ?? ''))
|
|
136
|
-
const
|
|
137
|
-
const
|
|
136
|
+
const pkgFile = resolvePluginFile(abs, 'package.json')
|
|
137
|
+
const pkg = pkgFile ? readJson(pkgFile, null) : null
|
|
138
|
+
const manifestFile = opts.manifest === undefined ? resolvePluginFile(abs, 'manifest.json') : null
|
|
139
|
+
const manifest = opts.manifest ?? (manifestFile ? readJson(manifestFile, null) : null)
|
|
138
140
|
let entry = null
|
|
139
141
|
for (const rel of entryCandidates(pkg ?? {}, manifest)) {
|
|
140
|
-
const file =
|
|
142
|
+
const file = resolvePluginFile(abs, rel)
|
|
143
|
+
if (!file) continue
|
|
141
144
|
try {
|
|
142
145
|
const st = fs.statSync(file)
|
|
143
146
|
if (!st.isFile()) continue
|
|
@@ -327,8 +330,11 @@ function makeGates(model, cfg, opts = {}) {
|
|
|
327
330
|
if (typeof patchRel !== 'string' || patchRel === '') {
|
|
328
331
|
add('G10', 'bundle-patch', 'skip', 'not a bundle (no dsh.bundle.patch)')
|
|
329
332
|
} else {
|
|
330
|
-
|
|
331
|
-
|
|
333
|
+
// The declared patch is plugin-relative and must stay inside the plugin root.
|
|
334
|
+
const patchFile = resolvePluginFile(model.abs, patchRel)
|
|
335
|
+
const ok = patchFile !== null
|
|
336
|
+
add('G10', 'bundle-patch', ok ? 'pass' : 'fail',
|
|
337
|
+
ok ? patchRel : `declared bundle patch missing/unsafe: ${patchRel}`, { patch: patchRel })
|
|
332
338
|
}
|
|
333
339
|
|
|
334
340
|
// G11 激活证据:静态预检查看不了激活(load 之后才可观测)→ deferred/SKIP(ci-gate G7 同构);
|
|
@@ -339,7 +345,9 @@ function makeGates(model, cfg, opts = {}) {
|
|
|
339
345
|
add('G11', 'activation-evidence', 'unknown', 'no host facts (activation not observed)')
|
|
340
346
|
} else if (facts.application !== 'applied') {
|
|
341
347
|
add('G11', 'activation-evidence', 'fail', `facts.application=${JSON.stringify(facts.application ?? null)} (expected "applied")`)
|
|
342
|
-
} else if (
|
|
348
|
+
} else if (!Number.isFinite(facts.observedAt) || facts.observedAt <= 0) {
|
|
349
|
+
add('G11', 'activation-evidence', 'unknown', 'facts.observedAt missing/invalid; freshness cannot be established')
|
|
350
|
+
} else if (model.entry && facts.observedAt < model.entry.mtimeMs) {
|
|
343
351
|
add('G11', 'activation-evidence', 'fail', `facts stale: observedAt=${facts.observedAt} < entry.mtimeMs=${model.entry.mtimeMs}`)
|
|
344
352
|
} else {
|
|
345
353
|
add('G11', 'activation-evidence', 'pass', 'facts.application=applied and fresh enough')
|
|
@@ -418,8 +426,8 @@ function evidenceOf(model, cfg) {
|
|
|
418
426
|
|
|
419
427
|
// ─────────────────────────────── suggestFix ───────────────────────────────
|
|
420
428
|
|
|
421
|
-
function patch(target, yaml, why) {
|
|
422
|
-
return { target, yaml, why }
|
|
429
|
+
function patch(target, yaml, why, extra = {}) {
|
|
430
|
+
return { target, yaml, why, ...extra }
|
|
423
431
|
}
|
|
424
432
|
|
|
425
433
|
function suggestFixOf(model, cfg, opts = {}) {
|
|
@@ -441,14 +449,16 @@ function suggestFixOf(model, cfg, opts = {}) {
|
|
|
441
449
|
if (g1 && !g1.ok && g1.verdict === 'fail') {
|
|
442
450
|
add(patch('package.json',
|
|
443
451
|
JSON.stringify({ name: model.pkg?.name ?? '@local/<plugin-name>', version: '1.0.0', type: 'module' }, null, 2),
|
|
444
|
-
`G1 manifest-fields: ${g1.detail}
|
|
452
|
+
`G1 manifest-fields: ${g1.detail} — merge these fields into the existing package.json; do not replace the file`,
|
|
453
|
+
{ apply: 'merge', mergeInto: 'package.json' }))
|
|
445
454
|
}
|
|
446
455
|
|
|
447
456
|
const g2 = gate('G2')
|
|
448
457
|
if (g2 && !g2.ok) {
|
|
449
458
|
add(patch('package.json',
|
|
450
459
|
JSON.stringify({ exports: { '.': './index.js' } }, null, 2),
|
|
451
|
-
`G2 entry-exists: ${g2.detail} — create the entry file and
|
|
460
|
+
`G2 entry-exists: ${g2.detail} — create the entry file and merge this exports field`,
|
|
461
|
+
{ apply: 'merge', mergeInto: 'package.json' }))
|
|
452
462
|
}
|
|
453
463
|
|
|
454
464
|
const g3 = gate('G3')
|
|
@@ -486,9 +496,16 @@ function suggestFixOf(model, cfg, opts = {}) {
|
|
|
486
496
|
|
|
487
497
|
const g8 = gate('G8')
|
|
488
498
|
if (g8 && g8.verdict === 'fail') {
|
|
499
|
+
// Never auto-approve install scripts: that would turn a security finding into a
|
|
500
|
+
// one-line bypass. The placeholder requires a human review step.
|
|
489
501
|
add(patch('package.json',
|
|
490
|
-
JSON.stringify({
|
|
491
|
-
|
|
502
|
+
JSON.stringify({
|
|
503
|
+
dsh: {
|
|
504
|
+
buildApproved: ['<script-name-after-review>'],
|
|
505
|
+
},
|
|
506
|
+
}, null, 2),
|
|
507
|
+
`G8 build-scripts: ${g8.detail} — review each install script; only merge names you explicitly approve. An auto-filled buildApproved list would bypass this gate.`,
|
|
508
|
+
{ apply: 'manual-review', mergeInto: 'package.json', requiresHumanReview: true }))
|
|
492
509
|
}
|
|
493
510
|
|
|
494
511
|
const g9 = gate('G9')
|
|
@@ -500,16 +517,22 @@ function suggestFixOf(model, cfg, opts = {}) {
|
|
|
500
517
|
|
|
501
518
|
const g10 = gate('G10')
|
|
502
519
|
if (g10 && g10.verdict === 'fail') {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
520
|
+
const declared = typeof g10.patch === 'string' ? g10.patch : ''
|
|
521
|
+
const safeTarget = declared && !path.isAbsolute(declared) && !declared.split(/[\\/]/).includes('..')
|
|
522
|
+
? declared
|
|
523
|
+
: 'cordis.patch.yml'
|
|
524
|
+
add(patch(safeTarget,
|
|
525
|
+
'# create the declared bundle patch file; the declaration must stay inside the plugin root',
|
|
526
|
+
`G10 bundle-patch: ${g10.detail}`,
|
|
527
|
+
{ apply: 'manual-create', declaredPatch: declared || null }))
|
|
506
528
|
}
|
|
507
529
|
|
|
508
530
|
const g7 = gate('G7')
|
|
509
531
|
if (g7 && g7.verdict === 'fail') {
|
|
510
532
|
add(patch('package.json',
|
|
511
|
-
JSON.stringify({ dsh: { exempted: [{ gate: '
|
|
512
|
-
`G7 exemption-honesty: ${g7.detail}
|
|
533
|
+
JSON.stringify({ dsh: { exempted: [{ gate: '<gate-id>', reason: 'reviewed: <why this risk is acceptable>' }] } }, null, 2),
|
|
534
|
+
`G7 exemption-honesty: ${g7.detail} — merge only after a real review; a placeholder exemption must not be copied blindly`,
|
|
535
|
+
{ apply: 'manual-review', mergeInto: 'package.json', requiresHumanReview: true }))
|
|
513
536
|
}
|
|
514
537
|
|
|
515
538
|
const fx = finding('inject-missing')
|
|
@@ -527,9 +550,13 @@ function suggestFixOf(model, cfg, opts = {}) {
|
|
|
527
550
|
|
|
528
551
|
const before = gradeOfModel(model)
|
|
529
552
|
let afterGrade = before.grade
|
|
553
|
+
const projectedGates = []
|
|
530
554
|
if (model.entry) {
|
|
531
555
|
const addressed = new Set()
|
|
532
|
-
if (g4 && g4.verdict === 'fail')
|
|
556
|
+
if (g4 && g4.verdict === 'fail') {
|
|
557
|
+
addressed.add('S1')
|
|
558
|
+
projectedGates.push('G4')
|
|
559
|
+
}
|
|
533
560
|
const kept = before.signals.filter(s => !addressed.has(familyOf(s.id)))
|
|
534
561
|
const projected = scoreScan(kept, {
|
|
535
562
|
...(model.pkg ?? {}),
|
|
@@ -541,7 +568,13 @@ function suggestFixOf(model, cfg, opts = {}) {
|
|
|
541
568
|
return {
|
|
542
569
|
patches,
|
|
543
570
|
before: { grade: before.grade, S: before.S },
|
|
544
|
-
after: {
|
|
571
|
+
after: {
|
|
572
|
+
grade: afterGrade,
|
|
573
|
+
note: projectedGates.length > 0
|
|
574
|
+
? 'projected only by removing G4/S1 signals; G3/G5/G6/G7/G8/G9/G10 are not represented and host-fact gates (G11/G12) are unaffected'
|
|
575
|
+
: 'static projection only; no score-affecting patch was applied and host-fact gates (G11/G12) are unaffected',
|
|
576
|
+
projectedGates,
|
|
577
|
+
},
|
|
545
578
|
dir: model.abs,
|
|
546
579
|
applied: false,
|
|
547
580
|
}
|
package/src/plugins/imports.mjs
CHANGED
|
@@ -168,6 +168,54 @@ export function scanSource(src) {
|
|
|
168
168
|
return { imports, warnings, tokenCount: tokens.length }
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Deep scan: import layer + a deliberately small call-layer signal set.
|
|
173
|
+
* This is still token-based, not an AST/call graph: it detects direct call tokens
|
|
174
|
+
* (and the existing dynamic-import warning), and reports that coverage honestly.
|
|
175
|
+
*/
|
|
176
|
+
const CHILD_CALLS = new Set(['exec', 'execSync', 'spawn', 'spawnSync', 'execFile', 'execFileSync', 'fork'])
|
|
177
|
+
const VM_CALLS = new Set(['runInContext', 'runInNewContext', 'runInThisContext', 'compileFunction'])
|
|
178
|
+
|
|
179
|
+
export function scanDeep(src) {
|
|
180
|
+
const scan = scanSource(src)
|
|
181
|
+
const tokens = tokenize(src)
|
|
182
|
+
const signals = [...importsToSignals(scan).signals]
|
|
183
|
+
const callSites = []
|
|
184
|
+
const seen = new Set()
|
|
185
|
+
const add = (id, weight, kind, line) => {
|
|
186
|
+
const key = `${id}@${line}`
|
|
187
|
+
if (seen.has(key)) return
|
|
188
|
+
seen.add(key)
|
|
189
|
+
callSites.push({ kind, line })
|
|
190
|
+
signals.push({ id, weight, evidence: { calls: [{ kind, line }] } })
|
|
191
|
+
}
|
|
192
|
+
for (let i = 0; i < tokens.length; i += 1) {
|
|
193
|
+
const token = tokens[i]
|
|
194
|
+
if (token.t !== 'word') continue
|
|
195
|
+
const next = tokens[i + 1]
|
|
196
|
+
if (next?.t === 'punct' && next.v === '(') {
|
|
197
|
+
if (CHILD_CALLS.has(token.v)) add('S1-child_process_call', 30, token.v, token.line)
|
|
198
|
+
else if (token.v === 'eval') add('S7-eval_call', 35, 'eval', token.line)
|
|
199
|
+
else if (VM_CALLS.has(token.v)) add('S4-vm_call', 25, token.v, token.line)
|
|
200
|
+
}
|
|
201
|
+
if (token.v === 'new' && tokens[i + 1]?.t === 'word' && tokens[i + 1].v === 'Function'
|
|
202
|
+
&& tokens[i + 2]?.t === 'punct' && tokens[i + 2].v === '(') {
|
|
203
|
+
add('S7-eval_call', 35, 'new Function', token.line)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
for (const warning of scan.warnings) {
|
|
207
|
+
if (warning.reason === 'dynamic-import-nonliteral') add('S8-dynamic_import_nonliteral', 12, 'dynamic-import', warning.line)
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
imports: scan.imports,
|
|
211
|
+
warnings: scan.warnings,
|
|
212
|
+
tokenCount: scan.tokenCount,
|
|
213
|
+
signals,
|
|
214
|
+
callSites,
|
|
215
|
+
coverage: 'import+call',
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
171
219
|
// ─────────── 说明符 → 信号(只做 import 层) ───────────
|
|
172
220
|
const CHILD_PROCESS = new Set(['child_process', 'node:child_process'])
|
|
173
221
|
const NETWORK = new Set(['net', 'node:net', 'http', 'node:http', 'https', 'node:https',
|