dsh-standards 0.0.3 → 1.0.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/40-checker/README.md +251 -0
- package/40-checker/bin/dsh-levels.mjs +15 -0
- package/40-checker/bin/dsh-plugin-verify.mjs +8 -0
- package/40-checker/fixtures/bad/index.mjs +12 -0
- package/40-checker/fixtures/bad/package.json +15 -0
- package/40-checker/fixtures/bad-manifest/index.js +1 -0
- package/40-checker/fixtures/bad-manifest/package.json +5 -0
- package/40-checker/fixtures/bundle/cordis.patch.yml +3 -0
- package/40-checker/fixtures/bundle/package.json +15 -0
- package/40-checker/fixtures/bundle/server.mjs +7 -0
- package/40-checker/fixtures/bundle-v0/cordis.patch.yml +3 -0
- package/40-checker/fixtures/bundle-v0/package.json +21 -0
- package/40-checker/fixtures/bundle-v0/server.mjs +7 -0
- package/40-checker/fixtures/client-missing/client.js +1 -0
- package/40-checker/fixtures/client-missing/index.js +1 -0
- package/40-checker/fixtures/client-missing/package.json +6 -0
- package/40-checker/fixtures/flow-config/index.js +9 -0
- package/40-checker/fixtures/flow-config/package.json +10 -0
- package/40-checker/fixtures/fs-write/index.mjs +7 -0
- package/40-checker/fixtures/fs-write/package.json +10 -0
- package/40-checker/fixtures/good/index.mjs +10 -0
- package/40-checker/fixtures/good/package.json +19 -0
- package/40-checker/fixtures/hang/index.mjs +5 -0
- package/40-checker/fixtures/hang/package.json +10 -0
- package/40-checker/fixtures/known-answer/expected.json +18 -0
- package/40-checker/fixtures/market-index-real.json +18 -0
- package/40-checker/fixtures/market-index.json +18 -0
- package/40-checker/fixtures/negative/bad-entry/package.json +1 -0
- package/40-checker/fixtures/negative/no-entry/package.json +1 -0
- package/40-checker/fixtures/negative/no-patch/package.json +1 -0
- package/40-checker/fixtures/negative/root-missing/cordis.patch.yml +2 -0
- package/40-checker/fixtures/negative/root-missing/package.json +1 -0
- package/40-checker/fixtures/negative/workspace/package.json +1 -0
- package/40-checker/package.json +22 -0
- package/40-checker/samples/README.md +8 -0
- package/40-checker/samples/entry18.json +139 -0
- package/40-checker/samples/frame.json +485 -0
- package/40-checker/scripts/apply-overlay.mjs +59 -0
- package/40-checker/scripts/attestation-check.mjs +151 -0
- package/40-checker/scripts/bundle-smoke.mjs +126 -0
- package/40-checker/scripts/claim-check.mjs +145 -0
- package/40-checker/scripts/clause-map.mjs +94 -0
- package/40-checker/scripts/collect-fixtures.mjs +44 -0
- package/40-checker/scripts/dashboard.mjs +85 -0
- package/40-checker/scripts/dco-check.mjs +147 -0
- package/40-checker/scripts/dependabot-check.mjs +40 -0
- package/40-checker/scripts/doc-commands-check.mjs +92 -0
- package/40-checker/scripts/entry-scan.mjs +190 -0
- package/40-checker/scripts/entry-validate.mjs +291 -0
- package/40-checker/scripts/entry18-attribution.mjs +66 -0
- package/40-checker/scripts/entry18-ci.mjs +685 -0
- package/40-checker/scripts/entry18-realweb-summary.mjs +71 -0
- package/40-checker/scripts/entry18-web.mjs +307 -0
- package/40-checker/scripts/evidence-chain.mjs +100 -0
- package/40-checker/scripts/flow-index.mjs +82 -0
- package/40-checker/scripts/flow-sample-ci.mjs +529 -0
- package/40-checker/scripts/governance-check.mjs +210 -0
- package/40-checker/scripts/host-farm.mjs +165 -0
- package/40-checker/scripts/journey-config-observe.mjs +109 -0
- package/40-checker/scripts/journey-disclosure-shape.mjs +83 -0
- package/40-checker/scripts/journey-runtime.mjs +178 -0
- package/40-checker/scripts/journey.mjs +76 -0
- package/40-checker/scripts/label-drift.mjs +74 -0
- package/40-checker/scripts/label-sync.mjs +87 -0
- package/40-checker/scripts/label-verify.mjs +90 -0
- package/40-checker/scripts/landlock-exec.c +101 -0
- package/40-checker/scripts/level-audit.mjs +336 -0
- package/40-checker/scripts/m1-sidecar.mjs +126 -0
- package/40-checker/scripts/m2-runner.mjs +213 -0
- package/40-checker/scripts/round-robin.mjs +88 -0
- package/40-checker/scripts/sample-frame.mjs +72 -0
- package/40-checker/scripts/sample20-ci.mjs +25 -0
- package/40-checker/scripts/sample60-ci.mjs +25 -0
- package/40-checker/scripts/stale-check.mjs +59 -0
- package/40-checker/scripts/surveillance.mjs +88 -0
- package/40-checker/scripts/web-probe.mjs +504 -0
- package/40-checker/src/cli.mjs +300 -0
- package/40-checker/src/client-shape.mjs +37 -0
- package/40-checker/src/declarations.mjs +242 -0
- package/40-checker/src/index.mjs +8 -0
- package/40-checker/src/install-spec.mjs +67 -0
- package/40-checker/src/label.mjs +130 -0
- package/40-checker/src/manifest.mjs +381 -0
- package/40-checker/src/permissions.mjs +60 -0
- package/40-checker/src/report.mjs +204 -0
- package/40-checker/src/result.mjs +60 -0
- package/40-checker/src/runtime.mjs +299 -0
- package/40-checker/src/semver.mjs +194 -0
- package/40-checker/src/util.mjs +148 -0
- package/40-checker/test/attestation.test.mjs +59 -0
- package/40-checker/test/checks.test.mjs +172 -0
- package/40-checker/test/claim.test.mjs +28 -0
- package/40-checker/test/client-shape.test.mjs +35 -0
- package/40-checker/test/dco.test.mjs +51 -0
- package/40-checker/test/entry-validate.test.mjs +172 -0
- package/40-checker/test/governance.test.mjs +76 -0
- package/40-checker/test/label.test.mjs +97 -0
- package/40-checker/test/level-audit.test.mjs +99 -0
- package/40-checker/test/levels.test.mjs +31 -0
- package/40-checker/test/ops.test.mjs +117 -0
- package/40-checker/test/permissions.test.mjs +40 -0
- package/40-checker/test/semver.test.mjs +32 -0
- package/40-checker/test/verify.test.mjs +57 -0
- package/CHANGELOG.md +24 -0
- package/LICENSE +28 -0
- package/LICENSE-APACHE +190 -0
- package/LICENSE-CC-BY +23 -0
- package/NOTICE +14 -0
- package/NOTICE.md +11 -0
- package/README.md +146 -3
- package/bin/dsh-levels.mjs +4 -0
- package/bin/dsh-standards.mjs +19 -0
- package/docs/BOOST-FIXTURES-2026-11-02.md +38 -0
- package/docs/DEVELOPER-JOURNEY.md +40 -0
- package/docs/HOST-J3-BUG-REPORT-DRAFT.md +27 -0
- package/docs/HOST-J3-CONFIG-REPRO-2026-11-02.md +36 -0
- package/docs/NAMING-FALLBACK.md +11 -0
- package/docs/fork-policy.md +12 -0
- package/docs/full-test-plan-2026-11-02.md +207 -0
- package/docs/incident.md +37 -0
- package/docs/onboarding.md +27 -0
- package/docs/privacy.md +12 -0
- package/docs/release.md +16 -0
- package/docs/scope-security.md +62 -0
- package/docs/status-taxonomy.md +54 -0
- package/docs/sunset.md +44 -0
- package/docs/translating.md +12 -0
- package/package.json +58 -12
- package/spec/README.md +27 -0
- package/spec/boost/README.md +8 -0
- package/spec/clauses.json +253 -0
- package/spec/entry/README.md +9 -0
- package/spec/flow/README.md +8 -0
- package/spec/levels.json +371 -0
- package/spec/levels.schema.json +45 -0
- package/spec/reference-suite.json +35 -0
- package/spec/schemas/attestation.schema.json +284 -0
- package/spec/schemas/evidence.schema.json +331 -0
- package/spec/schemas/report.schema.json +64 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Label primitives: canonical hash, schema-level checks, and effective status.
|
|
3
|
+
* A label is an immutable evidence record. It is not a grade or a ranking.
|
|
4
|
+
*/
|
|
5
|
+
import crypto from 'node:crypto'
|
|
6
|
+
|
|
7
|
+
const LEVELS = new Set(['entry', 'flow', 'boost'])
|
|
8
|
+
const STATUS = {
|
|
9
|
+
entry: new Set(['recognized', 'static', 'runtime', 'blocked', 'failed', 'not-run', 'stale', 'withdrawn', 'not-applicable']),
|
|
10
|
+
flow: new Set(['manual', 'runtime', 'failed', 'not-run', 'stale', 'withdrawn', 'not-applicable']),
|
|
11
|
+
boost: new Set(['measured', 'not-measured', 'failed', 'stale', 'withdrawn', 'not-applicable']),
|
|
12
|
+
}
|
|
13
|
+
const CLAIM = new Set(['observation', 'reference', 'advice'])
|
|
14
|
+
const REQUIRED = ['schema', 'subject', 'level', 'status', 'claimLevel', 'scope', 'validity', 'evidence', 'disclaimer', 'verifyUrl', 'issuer', 'recordHash']
|
|
15
|
+
const ALLOWED = new Set([...REQUIRED, 'withdrawn', 'revokedAt', 'supersedes'])
|
|
16
|
+
const DATE = /^\d{4}-\d{2}-\d{2}$/
|
|
17
|
+
const HASH = /^sha256:[0-9a-f]{64}$/
|
|
18
|
+
const COMMIT = /^[0-9a-f]{7,40}$/
|
|
19
|
+
const FORBIDDEN = ['grade', 'score', 'rank', 'recommended', 'official', 'certified', 'secure']
|
|
20
|
+
|
|
21
|
+
export function canonicalize(value) {
|
|
22
|
+
if (Array.isArray(value)) return value.map(canonicalize)
|
|
23
|
+
if (value && typeof value === 'object') {
|
|
24
|
+
const out = {}
|
|
25
|
+
for (const key of Object.keys(value).sort()) out[key] = canonicalize(value[key])
|
|
26
|
+
return out
|
|
27
|
+
}
|
|
28
|
+
return value
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function recordHash(record) {
|
|
32
|
+
const copy = { ...record }
|
|
33
|
+
delete copy.recordHash
|
|
34
|
+
return `sha256:${crypto.createHash('sha256').update(JSON.stringify(canonicalize(copy))).digest('hex')}`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function normalizeLabel(record) {
|
|
38
|
+
const computed = recordHash(record)
|
|
39
|
+
return { ...record, recordHash: computed }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function labelId(record) {
|
|
43
|
+
const repo = String(record?.subject?.repo ?? 'unknown').replace(/[^a-zA-Z0-9._-]+/g, '__')
|
|
44
|
+
const version = String(record?.subject?.version ?? 'unversioned').replace(/[^a-zA-Z0-9._+-]+/g, '_')
|
|
45
|
+
return `${repo}@${version}`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function effectiveStatus(record, now = new Date()) {
|
|
49
|
+
if (record?.withdrawn === true || record?.status === 'withdrawn' || record?.revokedAt) return 'withdrawn'
|
|
50
|
+
const today = now.toISOString().slice(0, 10)
|
|
51
|
+
if (String(record?.validity?.expiresAt ?? '') < today) return 'stale'
|
|
52
|
+
return record?.status ?? 'not-run'
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function validateLabel(record, { requireReference = true } = {}) {
|
|
56
|
+
const errors = []
|
|
57
|
+
const warnings = []
|
|
58
|
+
if (!record || typeof record !== 'object' || Array.isArray(record)) {
|
|
59
|
+
return { valid: false, errors: ['record must be an object'], warnings, computedHash: null, effective: 'not-run' }
|
|
60
|
+
}
|
|
61
|
+
for (const key of Object.keys(record)) {
|
|
62
|
+
if (!ALLOWED.has(key)) errors.push(`unknown field: ${key}`)
|
|
63
|
+
}
|
|
64
|
+
for (const key of REQUIRED) {
|
|
65
|
+
if (record[key] === undefined || record[key] === null || record[key] === '') errors.push(`missing: ${key}`)
|
|
66
|
+
}
|
|
67
|
+
if (record.schema !== 'dsh-market-label/1') errors.push('schema must be dsh-market-label/1')
|
|
68
|
+
if (!LEVELS.has(record.level)) errors.push(`invalid level: ${record.level}`)
|
|
69
|
+
if (!STATUS[record.level]?.has(record.status)) errors.push(`invalid status for ${record.level}: ${record.status}`)
|
|
70
|
+
if (!CLAIM.has(record.claimLevel)) errors.push(`invalid claimLevel: ${record.claimLevel}`)
|
|
71
|
+
if (requireReference && record.claimLevel !== 'reference') errors.push('directory labels must use claimLevel=reference')
|
|
72
|
+
const subject = record.subject ?? {}
|
|
73
|
+
for (const key of ['repo', 'version', 'commit']) {
|
|
74
|
+
if (typeof subject[key] !== 'string' || subject[key].length === 0) errors.push(`subject.${key} must be a non-empty string`)
|
|
75
|
+
}
|
|
76
|
+
if (subject.commit && !COMMIT.test(subject.commit)) errors.push('subject.commit must be 7-40 lowercase hex')
|
|
77
|
+
for (const key of ['dsh', 'cordis']) {
|
|
78
|
+
if (typeof record.scope?.[key] !== 'string' || record.scope[key].length === 0) errors.push(`scope.${key} must be a non-empty string`)
|
|
79
|
+
}
|
|
80
|
+
for (const key of ['generatedAt', 'expiresAt']) {
|
|
81
|
+
if (!DATE.test(String(record.validity?.[key] ?? ''))) errors.push(`validity.${key} must be YYYY-MM-DD`)
|
|
82
|
+
}
|
|
83
|
+
if (DATE.test(String(record.validity?.generatedAt ?? '')) && DATE.test(String(record.validity?.expiresAt ?? ''))) {
|
|
84
|
+
if (record.validity.expiresAt < record.validity.generatedAt) errors.push('validity.expiresAt must be >= generatedAt')
|
|
85
|
+
}
|
|
86
|
+
if (!Array.isArray(record.evidence) || record.evidence.length === 0) errors.push('evidence must be a non-empty array')
|
|
87
|
+
else {
|
|
88
|
+
for (const [index, item] of record.evidence.entries()) {
|
|
89
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) { errors.push(`evidence[${index}] must be an object`); continue }
|
|
90
|
+
for (const key of Object.keys(item)) if (!['url', 'sha256'].includes(key)) errors.push(`evidence[${index}] unknown field: ${key}`)
|
|
91
|
+
if (typeof item.url !== 'string' || !item.url.startsWith('https://')) errors.push(`evidence[${index}].url must be https://`)
|
|
92
|
+
if (item.sha256 !== undefined && !/^[0-9a-f]{64}$/.test(String(item.sha256))) errors.push(`evidence[${index}].sha256 must be 64 hex`)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (typeof record.disclaimer !== 'string' || record.disclaimer.length < 12) errors.push('disclaimer is too short')
|
|
96
|
+
else {
|
|
97
|
+
if (!/非官方|non-official/i.test(record.disclaimer)) errors.push('disclaimer must say 非官方/non-official')
|
|
98
|
+
if (!/非认证|non-certification/i.test(record.disclaimer)) errors.push('disclaimer must say 非认证/non-certification')
|
|
99
|
+
}
|
|
100
|
+
if (typeof record.verifyUrl !== 'string' || !record.verifyUrl.startsWith('https://')) errors.push('verifyUrl must be https://')
|
|
101
|
+
if (typeof record.issuer !== 'string' || record.issuer.length === 0) errors.push('issuer must be a non-empty string')
|
|
102
|
+
if (!HASH.test(String(record.recordHash ?? ''))) errors.push('recordHash must be sha256:<64 hex>')
|
|
103
|
+
const computed = recordHash(record)
|
|
104
|
+
if (HASH.test(String(record.recordHash ?? '')) && record.recordHash !== computed) errors.push('recordHash does not match the canonical record')
|
|
105
|
+
for (const key of FORBIDDEN) {
|
|
106
|
+
if (Object.prototype.hasOwnProperty.call(record, key)) errors.push(`forbidden field: ${key}`)
|
|
107
|
+
if (Object.prototype.hasOwnProperty.call(record.subject ?? {}, key)) errors.push(`forbidden subject field: ${key}`)
|
|
108
|
+
}
|
|
109
|
+
if (record.withdrawn !== undefined && typeof record.withdrawn !== 'boolean') errors.push('withdrawn must be boolean')
|
|
110
|
+
if (record.revokedAt !== undefined && !DATE.test(String(record.revokedAt))) errors.push('revokedAt must be YYYY-MM-DD')
|
|
111
|
+
if (record.supersedes !== undefined && !HASH.test(String(record.supersedes))) errors.push('supersedes must be sha256:<64 hex>')
|
|
112
|
+
const effective = effectiveStatus(record)
|
|
113
|
+
if (effective === 'stale') warnings.push('label is stale at read time; hide it from the valid view')
|
|
114
|
+
if (effective === 'withdrawn') warnings.push('label is withdrawn; keep it in history, exclude it from the valid view')
|
|
115
|
+
return { valid: errors.length === 0, errors, warnings, computedHash: computed, effective }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function validateIndex(index) {
|
|
119
|
+
const errors = []
|
|
120
|
+
if (!index || typeof index !== 'object') return { valid: false, errors: ['index must be an object'] }
|
|
121
|
+
if (index.schema !== 'dsh-label-index/1') errors.push('index.schema must be dsh-label-index/1')
|
|
122
|
+
if (!Array.isArray(index.records)) errors.push('index.records must be an array')
|
|
123
|
+
else {
|
|
124
|
+
for (const [i, record] of index.records.entries()) {
|
|
125
|
+
const result = validateLabel(record)
|
|
126
|
+
for (const error of result.errors) errors.push(`records[${i}]: ${error}`)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { valid: errors.length === 0, errors }
|
|
130
|
+
}
|
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import {
|
|
3
|
+
asArray, exists, isDirectory, isFile, isObject, readJsonMaybe, readText, rootExportTarget,
|
|
4
|
+
} from './util.mjs'
|
|
5
|
+
import { parseVersion, satisfies, validRange } from './semver.mjs'
|
|
6
|
+
import { parseInstallSpec } from './install-spec.mjs'
|
|
7
|
+
import { check, detail, worst } from './result.mjs'
|
|
8
|
+
import { checkClientShape } from './client-shape.mjs'
|
|
9
|
+
|
|
10
|
+
const PACKAGE_NAME = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/
|
|
11
|
+
const PACKAGE_NAME_MAX_LENGTH = 214
|
|
12
|
+
const EXACT_VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/
|
|
13
|
+
const COMMIT = /^[0-9a-f]{40}$/
|
|
14
|
+
|
|
15
|
+
export const DEFAULT_RUNTIME_VERSION = '0.2.2-alpha.2'
|
|
16
|
+
|
|
17
|
+
export function inferKind(manifest, entryExists) {
|
|
18
|
+
const declared = manifest?.dsh?.kind
|
|
19
|
+
if (typeof declared === 'string' && declared !== '') return { kind: declared, inferred: false }
|
|
20
|
+
if (manifest?.dsh?.bundle?.patch !== undefined) return { kind: 'bundle', inferred: true }
|
|
21
|
+
if (manifest?.dsh?.client !== undefined) return { kind: 'client', inferred: true }
|
|
22
|
+
if (entryExists) return { kind: 'plugin', inferred: true }
|
|
23
|
+
return { kind: 'unknown', inferred: true }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function inside(root, target) {
|
|
27
|
+
const relative = path.relative(root, target)
|
|
28
|
+
return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function resolveEntry(dir, manifest) {
|
|
32
|
+
const candidates = []
|
|
33
|
+
const exportTarget = rootExportTarget(manifest)
|
|
34
|
+
if (exportTarget) {
|
|
35
|
+
const absolute = path.resolve(dir, exportTarget)
|
|
36
|
+
if (!inside(dir, absolute)) {
|
|
37
|
+
return { exists: false, escape: true, source: 'exports["."]', target: exportTarget, absolute }
|
|
38
|
+
}
|
|
39
|
+
if (!isFile(absolute)) {
|
|
40
|
+
const sourceCandidates = ['src/index.ts', 'src/index.tsx', 'src/index.js', 'src/index.mjs']
|
|
41
|
+
const sourceEntry = sourceCandidates.find(relative => isFile(path.join(dir, relative))) ?? null
|
|
42
|
+
const scripts = isObject(manifest.scripts) ? manifest.scripts : {}
|
|
43
|
+
const buildHint = Boolean(sourceEntry) || ['build', 'prepare', 'compile'].some(name => typeof scripts[name] === 'string')
|
|
44
|
+
return { exists: false, escape: false, source: 'exports["."]', target: exportTarget, absolute, declaredMissing: true, sourceEntry, buildHint }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (exportTarget) candidates.push({ source: 'exports["."]', target: exportTarget })
|
|
48
|
+
if (typeof manifest.main === 'string' && manifest.main.trim() !== '') candidates.push({ source: 'main', target: manifest.main })
|
|
49
|
+
for (const fallback of ['index.js', 'index.mjs', 'index.cjs', 'index.ts']) candidates.push({ source: 'fallback', target: fallback })
|
|
50
|
+
|
|
51
|
+
for (const candidate of candidates) {
|
|
52
|
+
const absolute = path.resolve(dir, candidate.target)
|
|
53
|
+
if (!inside(dir, absolute)) {
|
|
54
|
+
return { exists: false, escape: true, source: candidate.source, target: candidate.target, absolute }
|
|
55
|
+
}
|
|
56
|
+
if (isFile(absolute)) {
|
|
57
|
+
return { exists: true, source: candidate.source, target: candidate.target, absolute, relative: path.relative(dir, absolute).split(path.sep).join('/') }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const sourceCandidates = ['src/index.ts', 'src/index.tsx', 'src/index.js', 'src/index.mjs']
|
|
62
|
+
const sourceEntry = sourceCandidates.find(relative => isFile(path.join(dir, relative))) ?? null
|
|
63
|
+
const scripts = isObject(manifest.scripts) ? manifest.scripts : {}
|
|
64
|
+
const buildHint = Boolean(sourceEntry) || ['build', 'prepare', 'compile'].some(name => typeof scripts[name] === 'string')
|
|
65
|
+
return { exists: false, escape: false, source: 'none', target: null, absolute: null, sourceEntry, buildHint }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function checkExportShape(entry, kind) {
|
|
69
|
+
if (!entry?.exists || kind !== 'plugin') return { result: 'NA', reason: 'not a directly loadable plugin entry', evidence: [] }
|
|
70
|
+
if (entry.related === '.d.ts' || entry.absolute.endsWith('.d.ts')) return { result: 'WARN', reason: 'entry is a declaration file; runtime shape not judged', evidence: [entry.relative] }
|
|
71
|
+
let text
|
|
72
|
+
try { text = readText(entry.absolute) } catch { return { result: 'WARN', reason: 'entry is not readable', evidence: [entry.relative] } }
|
|
73
|
+
const patterns = [
|
|
74
|
+
/export\s+(?:async\s+)?function\s+apply\s*\(/,
|
|
75
|
+
/export\s+const\s+apply\s*=/,
|
|
76
|
+
/export\s+\{[^}]*\bapply\b[^}]*\}/,
|
|
77
|
+
/export\s+default\s+class\s+/,
|
|
78
|
+
/module\.exports\s*=/,
|
|
79
|
+
]
|
|
80
|
+
if (patterns.some(pattern => pattern.test(text))) {
|
|
81
|
+
return { result: 'PASS', reason: 'entry exposes apply or a default class', evidence: [entry.relative] }
|
|
82
|
+
}
|
|
83
|
+
return { result: 'WARN', reason: 'no apply/default-class shape found by static scan; L1 is authoritative', evidence: [entry.relative] }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function analyzePatch(dir, manifest) {
|
|
87
|
+
const raw = manifest?.dsh?.bundle?.patch
|
|
88
|
+
if (raw === undefined) return { present: false, files: [], problems: [], enabledPluginManagerTools: false }
|
|
89
|
+
const files = []
|
|
90
|
+
const problems = []
|
|
91
|
+
let enabledPluginManagerTools = false
|
|
92
|
+
for (const entry of asArray(raw)) {
|
|
93
|
+
if (typeof entry !== 'string' || entry.trim() === '') {
|
|
94
|
+
problems.push('dsh.bundle.patch must be a non-empty string or string array')
|
|
95
|
+
continue
|
|
96
|
+
}
|
|
97
|
+
if (path.isAbsolute(entry) || entry.startsWith('~') || entry.includes('$') || entry.split(/[\\/]/).includes('..')) {
|
|
98
|
+
problems.push(`patch path escapes the package: ${entry}`)
|
|
99
|
+
continue
|
|
100
|
+
}
|
|
101
|
+
const absolute = path.resolve(dir, entry)
|
|
102
|
+
if (!inside(dir, absolute)) {
|
|
103
|
+
problems.push(`patch path escapes the package: ${entry}`)
|
|
104
|
+
continue
|
|
105
|
+
}
|
|
106
|
+
if (!isFile(absolute)) {
|
|
107
|
+
problems.push(`patch file is missing: ${entry}`)
|
|
108
|
+
continue
|
|
109
|
+
}
|
|
110
|
+
files.push({ relative: entry, absolute })
|
|
111
|
+
let text = ''
|
|
112
|
+
try { text = readText(absolute) } catch { problems.push(`patch file is unreadable: ${entry}`); continue }
|
|
113
|
+
const lines = text.split('\n')
|
|
114
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
115
|
+
const line = lines[index]
|
|
116
|
+
const match = /^\s*name:\s*['"]?([^'"\s#]+)['"]?/.exec(line)
|
|
117
|
+
if (!match) continue
|
|
118
|
+
const name = match[1]
|
|
119
|
+
if (path.isAbsolute(name) || name.startsWith('~') || name.includes('$') || name.split(/[\\/]/).includes('..')) {
|
|
120
|
+
problems.push(`patch row name escapes the package: ${name}`)
|
|
121
|
+
}
|
|
122
|
+
if (name === '@deepseek-ai/dsh-plugin-manager/tools') {
|
|
123
|
+
const window = lines.slice(index, index + 4).join('\n')
|
|
124
|
+
if (!/disabled:\s*true/.test(window)) enabledPluginManagerTools = true
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { present: true, files, problems, enabledPluginManagerTools }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function supplyChain(dir, manifest) {
|
|
132
|
+
const details = []
|
|
133
|
+
const dependencies = isObject(manifest.dependencies) ? manifest.dependencies : {}
|
|
134
|
+
const peers = isObject(manifest.peerDependencies) ? manifest.peerDependencies : {}
|
|
135
|
+
const all = { ...dependencies, ...peers }
|
|
136
|
+
for (const [name, value] of Object.entries(all)) {
|
|
137
|
+
if (typeof value !== 'string') continue
|
|
138
|
+
if (/^(?:workspace|file|link|portal):/i.test(value)) {
|
|
139
|
+
details.push(detail('C-3.3', 'WARN', `non-registry dependency ${name}: ${value}`, [`package.json#dependencies.${name}`]))
|
|
140
|
+
continue
|
|
141
|
+
}
|
|
142
|
+
if (/^(?:git\+|git@|github:|gitlab:|bitbucket:|gist:|https?:)/i.test(value)) {
|
|
143
|
+
if (!/#[0-9a-f]{40}$/.test(value) && !/^https?:\/\/[^#]+\.(?:tgz|tar\.gz)/i.test(value)) {
|
|
144
|
+
details.push(detail('C-3.3', 'WARN', `non-registry dependency ${name} is not pinned to a commit: ${value}`, [`package.json#dependencies.${name}`]))
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const scripts = isObject(manifest.scripts) ? manifest.scripts : {}
|
|
149
|
+
for (const name of ['preinstall', 'install', 'postinstall', 'prepare']) {
|
|
150
|
+
if (typeof scripts[name] === 'string') {
|
|
151
|
+
details.push(detail('C-3.4', 'WARN', `install-time build script present: scripts.${name}`, [`package.json#scripts.${name}`]))
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return details
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @param {string} dir
|
|
159
|
+
* @param {{runtimeVersion?: string, installSpec?: string, marketIndex?: string, pluginName?: string}} options
|
|
160
|
+
*/
|
|
161
|
+
export function runManifestChecks(dir, options = {}) {
|
|
162
|
+
const runtimeVersion = options.runtimeVersion ?? DEFAULT_RUNTIME_VERSION
|
|
163
|
+
const parsed = readJsonMaybe(path.join(dir, 'package.json'))
|
|
164
|
+
if (parsed.error) {
|
|
165
|
+
return {
|
|
166
|
+
manifest: null,
|
|
167
|
+
kind: 'unknown',
|
|
168
|
+
entry: null,
|
|
169
|
+
patch: null,
|
|
170
|
+
g4: { hasClient: false, ok: true, result: 'NA', reason: 'manifest unavailable' },
|
|
171
|
+
checks: [
|
|
172
|
+
check({ id: 'DSC-01', clause: 'C-1', layer: 'L0', result: 'FAIL', reason: `package.json is missing or invalid: ${parsed.error.message}`, details: [detail('C-1.1', 'FAIL', parsed.error.message)], evidence: ['package.json'] }),
|
|
173
|
+
check({ id: 'DSC-02', clause: 'C-2', layer: 'L0', result: 'ERROR', coverage: 'not-run', reason: 'manifest unavailable' }),
|
|
174
|
+
check({ id: 'DSC-03', clause: 'C-3', layer: 'L0', result: 'NA', reason: 'manifest unavailable' }),
|
|
175
|
+
],
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const manifest = parsed.value
|
|
179
|
+
const entry = resolveEntry(dir, manifest)
|
|
180
|
+
const kindInfo = inferKind(manifest, entry.exists)
|
|
181
|
+
const kind = kindInfo.kind
|
|
182
|
+
const patch = analyzePatch(dir, manifest)
|
|
183
|
+
const g4 = checkClientShape(manifest)
|
|
184
|
+
|
|
185
|
+
const manifestDetails = []
|
|
186
|
+
const name = manifest.name
|
|
187
|
+
if (typeof name !== 'string' || name.trim() === '' || name.length > PACKAGE_NAME_MAX_LENGTH || !PACKAGE_NAME.test(name)) {
|
|
188
|
+
manifestDetails.push(detail('C-1.1', 'FAIL', 'name must be a valid npm package name', ['package.json#name']))
|
|
189
|
+
} else {
|
|
190
|
+
manifestDetails.push(detail('C-1.1', 'PASS', `name=${name}`))
|
|
191
|
+
}
|
|
192
|
+
if (typeof manifest.version !== 'string' || !EXACT_VERSION.test(manifest.version)) {
|
|
193
|
+
manifestDetails.push(detail('C-1.1', 'FAIL', 'version must be an exact SemVer version', ['package.json#version']))
|
|
194
|
+
} else {
|
|
195
|
+
manifestDetails.push(detail('C-1.1', 'PASS', `version=${manifest.version}`))
|
|
196
|
+
}
|
|
197
|
+
if (entry.escape) {
|
|
198
|
+
manifestDetails.push(detail('C-1.2', 'FAIL', `entry escapes the package: ${entry.target}`, ['package.json#exports']))
|
|
199
|
+
} else if (entry.declaredMissing && entry.buildHint) {
|
|
200
|
+
manifestDetails.push(detail('C-1.2', 'WARN', `exports["."] target missing; build hint exists (${entry.sourceEntry ?? 'build script'})`, ['package.json#exports']))
|
|
201
|
+
} else if (entry.declaredMissing) {
|
|
202
|
+
manifestDetails.push(detail('C-1.2', 'FAIL', `exports["."] points to a missing file: ${entry.target}`, ['package.json#exports']))
|
|
203
|
+
} else if (entry.exists) {
|
|
204
|
+
manifestDetails.push(detail('C-1.2', 'PASS', `entry resolves via ${entry.source}: ${entry.relative}`, [entry.relative]))
|
|
205
|
+
} else if (entry.buildHint) {
|
|
206
|
+
manifestDetails.push(detail('C-1.2', 'WARN', `entry not present in checkout; source/build hint exists (${entry.sourceEntry ?? 'build script'})`, ['package.json#scripts']))
|
|
207
|
+
} else if (kind === 'bundle' || kind === 'client') {
|
|
208
|
+
manifestDetails.push(detail('C-1.2', 'WARN', `no runtime entry; ${kind} packages may be patch/client only`, ['package.json#exports']))
|
|
209
|
+
} else {
|
|
210
|
+
manifestDetails.push(detail('C-1.2', 'FAIL', 'no resolvable runtime entry', ['package.json#exports', 'package.json#main']))
|
|
211
|
+
}
|
|
212
|
+
const shape = checkExportShape(entry, kind)
|
|
213
|
+
manifestDetails.push(detail('C-1.3', shape.result, shape.reason, shape.evidence))
|
|
214
|
+
if (!patch.present) {
|
|
215
|
+
manifestDetails.push(detail('C-1.4', 'PASS', 'no dsh.bundle.patch declared'))
|
|
216
|
+
} else if (patch.problems.length > 0) {
|
|
217
|
+
manifestDetails.push(detail('C-1.4', 'FAIL', patch.problems.join('; '), patch.files.map(file => file.relative)))
|
|
218
|
+
} else {
|
|
219
|
+
manifestDetails.push(detail('C-1.4', 'PASS', `bundle patch present (${patch.files.length} file(s))`, patch.files.map(file => file.relative)))
|
|
220
|
+
}
|
|
221
|
+
if (typeof manifest.license !== 'string' || manifest.license.trim() === '') {
|
|
222
|
+
manifestDetails.push(detail('C-1.5', 'WARN', 'license is missing', ['package.json#license']))
|
|
223
|
+
} else {
|
|
224
|
+
manifestDetails.push(detail('C-1.5', 'PASS', `license=${manifest.license}`))
|
|
225
|
+
}
|
|
226
|
+
if (manifest.private === true) {
|
|
227
|
+
manifestDetails.push(detail('C-1.6', 'WARN', 'private:true; not publishable to a registry', ['package.json#private']))
|
|
228
|
+
}
|
|
229
|
+
const manifestResult = worst(manifestDetails.map(item => item.result))
|
|
230
|
+
const manifestCheck = check({
|
|
231
|
+
id: 'DSC-01',
|
|
232
|
+
clause: 'C-1',
|
|
233
|
+
layer: 'L0',
|
|
234
|
+
result: manifestResult,
|
|
235
|
+
reason: manifestDetails.filter(item => item.result !== 'PASS' && item.result !== 'NA').map(item => `${item.item}: ${item.reason}`).join(' | '),
|
|
236
|
+
details: manifestDetails,
|
|
237
|
+
evidence: ['package.json'],
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
const compatDetails = []
|
|
241
|
+
const engines = isObject(manifest.engines) ? manifest.engines : {}
|
|
242
|
+
const dshEngine = engines.dsh
|
|
243
|
+
const peers = isObject(manifest.peerDependencies) ? manifest.peerDependencies : {}
|
|
244
|
+
const dshPeers = Object.entries(peers).filter(([peer]) => peer === '@deepseek-ai/dsh' || peer.startsWith('@deepseek-ai/dsh-'))
|
|
245
|
+
if (typeof dshEngine === 'string') {
|
|
246
|
+
if (dshEngine.startsWith('workspace:')) {
|
|
247
|
+
compatDetails.push(detail('C-2.3', 'FAIL', 'engines.dsh must not be a workspace: range', ['package.json#engines.dsh']))
|
|
248
|
+
} else if (!validRange(dshEngine)) {
|
|
249
|
+
compatDetails.push(detail('C-2.1', 'FAIL', `engines.dsh is not a SemVer range: ${dshEngine}`, ['package.json#engines.dsh']))
|
|
250
|
+
} else if (!satisfies(runtimeVersion, dshEngine)) {
|
|
251
|
+
compatDetails.push(detail('C-2.2', 'FAIL', `engines.dsh ${dshEngine} does not satisfy runtime ${runtimeVersion}`, ['package.json#engines.dsh']))
|
|
252
|
+
} else {
|
|
253
|
+
compatDetails.push(detail('C-2.1', 'PASS', `engines.dsh=${dshEngine}`))
|
|
254
|
+
compatDetails.push(detail('C-2.2', 'PASS', `runtime ${runtimeVersion} satisfies ${dshEngine}`))
|
|
255
|
+
}
|
|
256
|
+
for (const [peer, rangeValue] of dshPeers) {
|
|
257
|
+
if (typeof rangeValue !== 'string' || rangeValue.startsWith('workspace:')) continue
|
|
258
|
+
if (validRange(rangeValue) && !satisfies(runtimeVersion, rangeValue)) {
|
|
259
|
+
compatDetails.push(detail('C-2.4', 'WARN', `peer ${peer} range ${rangeValue} conflicts with engines.dsh`, [`package.json#peerDependencies.${peer}`]))
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
} else if (dshPeers.length > 0) {
|
|
263
|
+
let failed = false
|
|
264
|
+
for (const [peer, rangeValue] of dshPeers) {
|
|
265
|
+
if (typeof rangeValue !== 'string') {
|
|
266
|
+
compatDetails.push(detail('C-2.1', 'FAIL', `peer ${peer} must be a string range`, [`package.json#peerDependencies.${peer}`]))
|
|
267
|
+
failed = true
|
|
268
|
+
continue
|
|
269
|
+
}
|
|
270
|
+
const effective = /^workspace:(?:\^|~|\*)$/.test(rangeValue) ? runtimeVersion : rangeValue
|
|
271
|
+
if (!validRange(effective)) {
|
|
272
|
+
compatDetails.push(detail('C-2.1', 'FAIL', `peer ${peer} is not a SemVer range: ${rangeValue}`, [`package.json#peerDependencies.${peer}`]))
|
|
273
|
+
failed = true
|
|
274
|
+
} else if (!satisfies(runtimeVersion, effective)) {
|
|
275
|
+
compatDetails.push(detail('C-2.2', 'FAIL', `peer ${peer} ${rangeValue} does not satisfy runtime ${runtimeVersion}`, [`package.json#peerDependencies.${peer}`]))
|
|
276
|
+
failed = true
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
compatDetails.push(detail('C-2.1', failed ? 'FAIL' : 'WARN', failed ? 'one or more dsh peers are unsatisfied' : 'no engines.dsh; dsh peer range is the weaker alternate declaration'))
|
|
280
|
+
} else {
|
|
281
|
+
compatDetails.push(detail('C-2.1', 'FAIL', 'neither engines.dsh nor a @deepseek-ai/dsh* peer range is declared', ['package.json#engines', 'package.json#peerDependencies']))
|
|
282
|
+
}
|
|
283
|
+
const compatResult = worst(compatDetails.map(item => item.result))
|
|
284
|
+
const compatCheck = check({
|
|
285
|
+
id: 'DSC-02',
|
|
286
|
+
clause: 'C-2',
|
|
287
|
+
layer: 'L0',
|
|
288
|
+
result: compatResult,
|
|
289
|
+
reason: compatDetails.filter(item => item.result !== 'PASS' && item.result !== 'NA').map(item => `${item.item}: ${item.reason}`).join(' | '),
|
|
290
|
+
details: compatDetails,
|
|
291
|
+
evidence: ['package.json#engines', 'package.json#peerDependencies'],
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
const supplyDetails = supplyChain(dir, manifest)
|
|
295
|
+
const installDetails = [...supplyDetails]
|
|
296
|
+
let installResult = 'NA'
|
|
297
|
+
let installReason = 'install spec not supplied (package profile)'
|
|
298
|
+
if (typeof options.installSpec === 'string' && options.installSpec.trim() !== '') {
|
|
299
|
+
try {
|
|
300
|
+
const spec = parseInstallSpec(options.installSpec)
|
|
301
|
+
installDetails.push(detail('C-3.1', 'PASS', `parsed kind=${spec.kind}`, ['--install-spec']))
|
|
302
|
+
installDetails.push(detail('C-3.2', spec.pinned ? 'PASS' : 'WARN', spec.pinned ? 'source is pinned' : 'registry spec is a bare name/tag', ['--install-spec']))
|
|
303
|
+
installResult = worst(installDetails.map(item => item.result))
|
|
304
|
+
installReason = installResult === 'PASS' ? '' : 'install spec or supply-chain issue'
|
|
305
|
+
} catch (error) {
|
|
306
|
+
installDetails.push(detail('C-3.1', 'FAIL', error.message, ['--install-spec']))
|
|
307
|
+
installResult = 'FAIL'
|
|
308
|
+
installReason = error.message
|
|
309
|
+
}
|
|
310
|
+
} else if (typeof options.marketIndex === 'string' && options.marketIndex.trim() !== '') {
|
|
311
|
+
const market = checkMarketEntry(options.marketIndex, options.pluginName)
|
|
312
|
+
installDetails.push(...market.details)
|
|
313
|
+
installResult = worst([market.result, ...supplyDetails.map(item => item.result)])
|
|
314
|
+
installReason = market.reason || (installResult === 'WARN' ? 'market entry is pinned but supply-chain warnings remain' : '')
|
|
315
|
+
}
|
|
316
|
+
const installCheck = check({
|
|
317
|
+
id: 'DSC-03',
|
|
318
|
+
clause: 'C-3',
|
|
319
|
+
layer: 'L0',
|
|
320
|
+
result: installResult,
|
|
321
|
+
coverage: installResult === 'NA' ? 'not-run' : 'full',
|
|
322
|
+
reason: installReason,
|
|
323
|
+
details: installDetails,
|
|
324
|
+
evidence: ['package.json#dependencies', 'package.json#scripts', options.marketIndex ?? '--install-spec'],
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
return { manifest, kind, kindInferred: kindInfo.inferred, entry, patch, g4, checks: [manifestCheck, compatCheck, installCheck] }
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export function checkMarketEntry(indexPath, pluginName) {
|
|
331
|
+
const details = []
|
|
332
|
+
let parsed
|
|
333
|
+
try { parsed = readJsonMaybe(indexPath) } catch (error) {
|
|
334
|
+
return { result: 'FAIL', reason: error.message, details: [detail('C-3.5', 'FAIL', error.message, [indexPath])] }
|
|
335
|
+
}
|
|
336
|
+
if (parsed.error) {
|
|
337
|
+
return { result: 'FAIL', reason: parsed.error.message, details: [detail('C-3.5', 'FAIL', parsed.error.message, [indexPath])] }
|
|
338
|
+
}
|
|
339
|
+
const value = parsed.value
|
|
340
|
+
if (!isObject(value) || value.format !== 1) {
|
|
341
|
+
return { result: 'FAIL', reason: 'market index format must be 1', details: [detail('C-3.5', 'FAIL', 'format !== 1', [indexPath])] }
|
|
342
|
+
}
|
|
343
|
+
if (!Array.isArray(value.plugins)) {
|
|
344
|
+
return { result: 'FAIL', reason: 'plugins must be an array', details: [detail('C-3.5', 'FAIL', 'plugins is not an array', [indexPath])] }
|
|
345
|
+
}
|
|
346
|
+
const name = pluginName ?? null
|
|
347
|
+
const plugin = name
|
|
348
|
+
? value.plugins.find(entry => isObject(entry) && entry.name === name)
|
|
349
|
+
: value.plugins.length === 1 ? value.plugins[0] : null
|
|
350
|
+
if (!isObject(plugin)) {
|
|
351
|
+
return { result: 'FAIL', reason: name ? `plugin ${name} not found` : 'plugin name is required for a multi-plugin index', details: [detail('C-3.5', 'FAIL', 'plugin not found', [indexPath])] }
|
|
352
|
+
}
|
|
353
|
+
if (typeof plugin.name !== 'string' || !PACKAGE_NAME.test(plugin.name)) {
|
|
354
|
+
details.push(detail('C-3.5', 'FAIL', `invalid plugin name: ${plugin.name}`, [indexPath]))
|
|
355
|
+
}
|
|
356
|
+
if (!Array.isArray(plugin.versions) || plugin.versions.length === 0) {
|
|
357
|
+
details.push(detail('C-3.5', 'FAIL', 'versions must be a non-empty array', [indexPath]))
|
|
358
|
+
} else {
|
|
359
|
+
for (const version of plugin.versions) {
|
|
360
|
+
if (!isObject(version) || typeof version.version !== 'string' || !EXACT_VERSION.test(version.version)) {
|
|
361
|
+
details.push(detail('C-3.5', 'FAIL', 'version must be an exact SemVer', [indexPath]))
|
|
362
|
+
continue
|
|
363
|
+
}
|
|
364
|
+
if (!isObject(version.source) || !['npm', 'git'].includes(version.source.type)) {
|
|
365
|
+
details.push(detail('C-3.5', 'FAIL', `source.type must be npm or git for ${version.version}`, [indexPath]))
|
|
366
|
+
continue
|
|
367
|
+
}
|
|
368
|
+
if (version.source.type === 'git' && (typeof version.source.commit !== 'string' || !COMMIT.test(version.source.commit))) {
|
|
369
|
+
details.push(detail('C-3.5', 'FAIL', `git source must pin a 40-hex commit for ${version.version}`, [indexPath]))
|
|
370
|
+
}
|
|
371
|
+
if (isObject(version.engines) && version.engines.dsh !== undefined) {
|
|
372
|
+
if (typeof version.engines.dsh !== 'string' || version.engines.dsh.startsWith('workspace:') || !validRange(version.engines.dsh)) {
|
|
373
|
+
details.push(detail('C-3.5', 'FAIL', `engines.dsh invalid for ${version.version}`, [indexPath]))
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (details.length === 0) details.push(detail('C-3.5', 'PASS', `market index entry ${plugin.name}@${plugin.versions?.[0]?.version ?? '?'} is pinned`))
|
|
379
|
+
const result = worst(details.map(item => item.result))
|
|
380
|
+
return { result, reason: result === 'PASS' ? '' : 'market index entry failed validation', details }
|
|
381
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T4 field validation: dsh.commitments / dsh.disclosure.
|
|
3
|
+
*
|
|
4
|
+
* These fields are declarations, not enforcement. The checker validates their
|
|
5
|
+
* shape and reports missing/invalid values; it never FAILs C-12 merely because
|
|
6
|
+
* a commitment is absent (the standard's transition rule).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const COMMITMENT_IDS = [
|
|
10
|
+
'no-session-upload',
|
|
11
|
+
'no-third-party-proxy',
|
|
12
|
+
'no-credential-enumeration',
|
|
13
|
+
'no-silent-prompt-rewrite',
|
|
14
|
+
'no-adapter-bypass',
|
|
15
|
+
'no-webhook-auto-session',
|
|
16
|
+
'no-security-seam-replacement',
|
|
17
|
+
'third-party-endpoint-disclosure',
|
|
18
|
+
'no-danger-full-access',
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
function detail(item, result, reason) {
|
|
22
|
+
return { item, result, reason, evidence: ['package.json#dsh.commitments'] }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function validateCommitments(manifest) {
|
|
26
|
+
const value = manifest?.dsh?.commitments
|
|
27
|
+
if (value === undefined) return [detail('C-12.6', 'NA', 'dsh.commitments is not declared (optional disclosure)')]
|
|
28
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
29
|
+
return [detail('C-12.6', 'WARN', 'dsh.commitments must be an object')]
|
|
30
|
+
}
|
|
31
|
+
const details = []
|
|
32
|
+
for (const id of COMMITMENT_IDS) {
|
|
33
|
+
if (!Object.hasOwn(value, id)) details.push(detail('C-12.6', 'WARN', `missing commitment: ${id}`))
|
|
34
|
+
else if (typeof value[id] !== 'boolean') details.push(detail('C-12.6', 'WARN', `commitment ${id} must be boolean`))
|
|
35
|
+
}
|
|
36
|
+
if (details.length === 0) details.push(detail('C-12.6', 'PASS', 'all 9 commitments are declared as booleans'))
|
|
37
|
+
return details
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function validateDisclosure(manifest) {
|
|
41
|
+
const value = manifest?.dsh?.disclosure
|
|
42
|
+
if (value === undefined) return [detail('C-12.7', 'NA', 'dsh.disclosure is not declared (optional disclosure)')]
|
|
43
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
44
|
+
return [detail('C-12.7', 'WARN', 'dsh.disclosure must be an object')]
|
|
45
|
+
}
|
|
46
|
+
const details = []
|
|
47
|
+
if (value.endpoints !== undefined) {
|
|
48
|
+
if (!Array.isArray(value.endpoints) || value.endpoints.some(endpoint => typeof endpoint !== 'string' || !/^https:\/\//.test(endpoint))) {
|
|
49
|
+
details.push(detail('C-12.7', 'WARN', 'disclosure.endpoints must be an array of https URLs'))
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (value.retention !== undefined && typeof value.retention !== 'string') {
|
|
53
|
+
details.push(detail('C-12.7', 'WARN', 'disclosure.retention must be a string'))
|
|
54
|
+
}
|
|
55
|
+
if (value.systemPrompt !== undefined && typeof value.systemPrompt !== 'string') {
|
|
56
|
+
details.push(detail('C-12.7', 'WARN', 'disclosure.systemPrompt must be a string'))
|
|
57
|
+
}
|
|
58
|
+
if (details.length === 0) details.push(detail('C-12.7', 'PASS', 'dsh.disclosure is well-formed'))
|
|
59
|
+
return details
|
|
60
|
+
}
|