shipgate-cli 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +261 -2
- package/agents/context-builder.md +158 -0
- package/agents/debug-executor.md +234 -0
- package/assets/gates/classifier.js +245 -0
- package/assets/gates/dsh/index.js +767 -0
- package/assets/gates/dsh/policy.json +93 -0
- package/assets/gates/index.js +3 -0
- package/assets/gates/pi/index.js +1131 -0
- package/assets/gates/pi/policy.json +93 -0
- package/assets/gates/policy.js +4267 -0
- package/assets/gates/profiles/ai4s-dry-lab.json +64 -0
- package/assets/gates/profiles/ai4s-quant.json +36 -0
- package/assets/pi-extensions/auto-continue.ts +176 -0
- package/assets/pi-extensions/goal-mode.ts +313 -0
- package/bin/shipgate.mjs +9 -0
- package/commands/ai-spec.md +9 -0
- package/commands/api-first.md +33 -0
- package/commands/code-review.md +7 -0
- package/commands/codebase-context.md +19 -0
- package/commands/debug-ui.md +147 -0
- package/commands/debug.md +101 -0
- package/commands/dev-env-scan.md +18 -0
- package/commands/dev-host-init.md +28 -0
- package/commands/discover-skill-opportunities.md +33 -0
- package/commands/fork-sync.md +17 -0
- package/commands/gh-actions.md +26 -0
- package/commands/goal-driven-development.md +7 -0
- package/commands/intent-grill.md +7 -0
- package/commands/iteration-manager.md +7 -0
- package/commands/loop-engineer.md +21 -0
- package/commands/nodejs-npm-auto-release.md +12 -0
- package/commands/prd.md +7 -0
- package/commands/project-health-audit.md +7 -0
- package/commands/ralph-yolo.md +346 -0
- package/commands/ralph.md +226 -0
- package/commands/security-audit.md +7 -0
- package/commands/ux-experience-audit.md +133 -0
- package/docs/ARCHITECTURE.md +63 -0
- package/docs/GATES.md +106 -0
- package/docs/HARNESS.md +257 -0
- package/package.json +48 -4
- package/references/ADR-FORMAT.md +67 -0
- package/references/CONTEXT-FORMAT.md +62 -0
- package/references/mcp-config-template.json +54 -0
- package/scripts/fix-skill-frontmatter.mjs +66 -0
- package/scripts/migrate-skillpack.mjs +257 -0
- package/skills/ai-spec/SKILL.md +90 -0
- package/skills/api-first-modular/SKILL.md +411 -0
- package/skills/code-debugger/SKILL.md +379 -0
- package/skills/code-review/SKILL.md +62 -0
- package/skills/codebase-context/SKILL.md +139 -0
- package/skills/debug-ui/SKILL.md +220 -0
- package/skills/dev-env-scan/SKILL.md +147 -0
- package/skills/dev-host-init/SKILL.md +198 -0
- package/skills/dev-host-init/scripts/fill-placeholders.py +226 -0
- package/skills/dev-host-init/scripts/host-scan.ps1 +159 -0
- package/skills/dev-host-init/scripts/host-scan.sh +201 -0
- package/skills/dev-host-init/scripts/render-now.py +488 -0
- package/skills/dev-host-init/scripts/tools-catalog.py +229 -0
- package/skills/dev-host-init/templates/graph-first-gate.ts +291 -0
- package/skills/dev-host-init/templates/host-injection.template.md +725 -0
- package/skills/discover-skill-opportunities/SKILL.md +145 -0
- package/skills/discover-skill-opportunities/references/accounting-finance-ops.md +24 -0
- package/skills/discover-skill-opportunities/references/business-consulting.md +24 -0
- package/skills/discover-skill-opportunities/references/evidence-and-privacy.md +39 -0
- package/skills/discover-skill-opportunities/references/finance-investment.md +24 -0
- package/skills/discover-skill-opportunities/references/legal-and-compliance.md +24 -0
- package/skills/discover-skill-opportunities/references/output-contract.md +75 -0
- package/skills/discover-skill-opportunities/references/product-and-operations.md +24 -0
- package/skills/discover-skill-opportunities/references/quant-trading.md +24 -0
- package/skills/discover-skill-opportunities/references/scientific-research.md +24 -0
- package/skills/discover-skill-opportunities/references/scoring-rubric.md +45 -0
- package/skills/discover-skill-opportunities/references/session-skill-review.md +78 -0
- package/skills/discover-skill-opportunities/references/software-development.md +24 -0
- package/skills/fork-sync/SKILL.md +86 -0
- package/skills/gh-actions-architect/SKILL.md +395 -0
- package/skills/goal-driven-development/SKILL.md +132 -0
- package/skills/intent-grill/SKILL.md +46 -0
- package/skills/iteration-manager/SKILL.md +53 -0
- package/skills/loop-engineer/SKILL.md +108 -0
- package/skills/nodejs-npm-auto-release/SKILL.md +141 -0
- package/skills/prd/SKILL.md +63 -0
- package/skills/project-health-audit/SKILL.md +64 -0
- package/skills/ralph/SKILL.md +329 -0
- package/skills/ralph-yolo/SKILL.md +623 -0
- package/skills/security-audit/SKILL.md +114 -0
- package/skills/security-audit/references/audit-checklist.md +135 -0
- package/skills/security-audit/references/evidence-conventions.md +54 -0
- package/skills/security-audit/references/findings-schema.md +37 -0
- package/skills/security-audit/references/stack-signatures.md +66 -0
- package/skills/shipgate/SKILL.md +40 -0
- package/skills/shipgate-install/SKILL.md +87 -0
- package/skills/shipgate-quality/SKILL.md +80 -0
- package/skills/shipgate-security/SKILL.md +97 -0
- package/skills/shipgate-spec/SKILL.md +67 -0
- package/skills/ux-experience-audit/SKILL.md +202 -0
- package/src/cli.mjs +118 -0
- package/src/commands/ask.mjs +82 -0
- package/src/commands/deploy.mjs +587 -0
- package/src/commands/gates.mjs +83 -0
- package/src/commands/policy.mjs +116 -0
- package/src/gates/quality.mjs +123 -0
- package/src/gates/security.mjs +92 -0
- package/src/gates/ship.mjs +74 -0
- package/src/gates/spec.mjs +88 -0
- package/src/harness/index.mjs +203 -0
- package/src/inject/render.mjs +75 -0
- package/src/lib/cfg.mjs +66 -0
- package/src/lib/duration.mjs +41 -0
- package/src/lib/engines.mjs +182 -0
- package/src/lib/exec.mjs +80 -0
- package/src/lib/fsx.mjs +119 -0
- package/src/lib/gate.mjs +329 -0
- package/src/lib/log.mjs +31 -0
- package/src/lib/skills.mjs +347 -0
- package/src/lib/state.mjs +50 -0
- package/src/lib/update.mjs +67 -0
- package/src/version.mjs +14 -0
- package/templates/agents-snippet.md +82 -0
- package/templates/dev-profile.schema.json +119 -0
- package/templates/prd.json.example +64 -0
- package/templates/rule.json.example +28 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { c, log, table } from '../lib/log.mjs';
|
|
2
|
+
import { formatDurationMs, parseDurationMs } from '../lib/duration.mjs';
|
|
3
|
+
import {
|
|
4
|
+
addProtected,
|
|
5
|
+
gateStatus,
|
|
6
|
+
globalPolicyPath,
|
|
7
|
+
loadPolicy,
|
|
8
|
+
policyModeView,
|
|
9
|
+
removeProtected,
|
|
10
|
+
setMode,
|
|
11
|
+
syncPolicyToHarnesses,
|
|
12
|
+
} from '../lib/gate.mjs';
|
|
13
|
+
import { allHarnesses, detected, resolveHarness } from '../harness/index.mjs';
|
|
14
|
+
|
|
15
|
+
function gatedHarnesses(cfg) {
|
|
16
|
+
return allHarnesses(cfg)
|
|
17
|
+
.map(resolveHarness)
|
|
18
|
+
.filter((h) => h.gateDest);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function policyCommand(ctx) {
|
|
22
|
+
const { flags } = ctx;
|
|
23
|
+
|
|
24
|
+
if (flags['add-protected']) {
|
|
25
|
+
const policy = addProtected(String(flags['add-protected']));
|
|
26
|
+
log.ok(`已加入受保护工作区:${String(flags['add-protected'])}`);
|
|
27
|
+
log.info(c.dim(`当前共 ${policy.config.protected_worktrees.length} 条`));
|
|
28
|
+
return syncAll(ctx);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (flags['rm-protected']) {
|
|
32
|
+
const policy = removeProtected(String(flags['rm-protected']));
|
|
33
|
+
log.ok(`已移除:${String(flags['rm-protected'])}`);
|
|
34
|
+
log.info(c.dim(`剩余 ${policy.config.protected_worktrees.length} 条`));
|
|
35
|
+
return syncAll(ctx);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (flags.mode) {
|
|
39
|
+
const mode = String(flags.mode);
|
|
40
|
+
if (!['enforce', 'bypass'].includes(mode)) {
|
|
41
|
+
log.err(`--mode 只能是 enforce 或 bypass,收到:${mode}`);
|
|
42
|
+
return 2;
|
|
43
|
+
}
|
|
44
|
+
if (flags.until !== undefined && mode !== 'bypass') {
|
|
45
|
+
// A deadline on enforce is a contradiction: enforce is already the
|
|
46
|
+
// immediate state, and the leftover timestamp would shorten the next
|
|
47
|
+
// bypass the user asks for.
|
|
48
|
+
log.err('--until 只用于 --mode bypass;enforce 不需要时长。');
|
|
49
|
+
return 2;
|
|
50
|
+
}
|
|
51
|
+
const durationMs = flags.until === undefined ? 0 : parseDurationMs(flags.until);
|
|
52
|
+
if (durationMs === null) {
|
|
53
|
+
log.err(`看不懂时长「${flags.until}」。用 90s / 30m / 8h / 2d,或裸数字(= 小时)。`);
|
|
54
|
+
return 2;
|
|
55
|
+
}
|
|
56
|
+
let policy;
|
|
57
|
+
try {
|
|
58
|
+
policy = setMode(mode, { durationMs });
|
|
59
|
+
} catch (error) {
|
|
60
|
+
log.err(error.message);
|
|
61
|
+
return 2;
|
|
62
|
+
}
|
|
63
|
+
const view = policyModeView(policy);
|
|
64
|
+
const expiry =
|
|
65
|
+
view.mode === 'bypass'
|
|
66
|
+
? view.remainingMs === null
|
|
67
|
+
? '(不过期)'
|
|
68
|
+
: `(剩 ${formatDurationMs(view.remainingMs)},直到 ${new Date(view.until).toISOString()})`
|
|
69
|
+
: '';
|
|
70
|
+
log.ok(`destructive_mode = ${view.mode}${expiry} ← ${globalPolicyPath()}`);
|
|
71
|
+
return syncAll(ctx);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (flags.sync) return syncAll(ctx);
|
|
75
|
+
|
|
76
|
+
const policy = loadPolicy();
|
|
77
|
+
const view = policyModeView(policy);
|
|
78
|
+
// The raw field and the effective mode disagree exactly when a bounded
|
|
79
|
+
// bypass has expired. Printing the field alone is how the switch looked
|
|
80
|
+
// broken; say both halves when they differ.
|
|
81
|
+
const source = view.expired
|
|
82
|
+
? `enforce(bypass 已于 ${new Date(view.until).toISOString()} 到期;文件仍记 bypass,要重开请 policy --mode bypass)`
|
|
83
|
+
: view.mode === 'bypass'
|
|
84
|
+
? `bypass${view.remainingMs === null ? '(不过期)' : `(剩 ${formatDurationMs(view.remainingMs)})`}`
|
|
85
|
+
: 'enforce';
|
|
86
|
+
const rows = gatedHarnesses(ctx.cfg).map((harness) => {
|
|
87
|
+
const status = gateStatus(harness);
|
|
88
|
+
return [harness.id, status.installed ? 'installed' : 'missing', status.mode ?? '-', String(status.protected ?? 0), harness.gateDest];
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (ctx.flags.json) {
|
|
92
|
+
log.plain(JSON.stringify({ policy, mode_view: view, harnesses: rows }, null, 2));
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
log.title(`策略真源:${source} · 受保护工作区 ${policy.config.protected_worktrees.length} 条`);
|
|
97
|
+
for (const p of policy.config.protected_worktrees) log.info(` · ${p}`);
|
|
98
|
+
log.title('硬门控落地');
|
|
99
|
+
if (rows.length === 0) log.warn('没有任何 harness 配置了 gate(只有 pi/dsh 类需要)');
|
|
100
|
+
else log.plain(table(rows, ['harness', 'gate', 'mode', 'protected', '路径']));
|
|
101
|
+
log.info(c.dim('用法:shipgate policy --add-protected <dir> | --rm-protected <dir> | --mode enforce|bypass [--until 8h] | --sync'));
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function syncAll(ctx) {
|
|
106
|
+
const harnesses = gatedHarnesses(ctx.cfg).filter(detected);
|
|
107
|
+
const touched = syncPolicyToHarnesses(harnesses, { dryRun: Boolean(ctx.flags['dry-run']) });
|
|
108
|
+
if (touched.length === 0) {
|
|
109
|
+
log.warn('没有已安装 gate 的 harness 需要同步(先 `shipgate install --harness pi`)');
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
for (const item of touched) {
|
|
113
|
+
log.ok(`${item.harness} ← ${item.mode} / protected ${item.protected} ${c.dim(item.target)}`);
|
|
114
|
+
}
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { run } from '../lib/exec.mjs';
|
|
3
|
+
import { engineHint, resolveAislop } from '../lib/engines.mjs';
|
|
4
|
+
|
|
5
|
+
function parseJsonPayload(stdout) {
|
|
6
|
+
const start = stdout.indexOf('{');
|
|
7
|
+
const end = stdout.lastIndexOf('}');
|
|
8
|
+
if (start === -1 || end === -1) return null;
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(stdout.slice(start, end + 1));
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Wraps `aislop scan --json`. The gate owns the threshold decision so the
|
|
18
|
+
* verdict does not depend on a project-local .aislop/config.yml.
|
|
19
|
+
* scoreable === false is a failure, never a pass: a scan that could not run the
|
|
20
|
+
* lint engine must not be reported as green.
|
|
21
|
+
*/
|
|
22
|
+
export function runQualityGate({ cwd = process.cwd(), target = '.', min = 80, timeout = 900_000 } = {}) {
|
|
23
|
+
const scanDir = path.resolve(cwd, target);
|
|
24
|
+
const bin = resolveAislop(cwd);
|
|
25
|
+
|
|
26
|
+
if (!bin) {
|
|
27
|
+
return {
|
|
28
|
+
gate: 'quality',
|
|
29
|
+
ok: false,
|
|
30
|
+
code: 3,
|
|
31
|
+
summary: 'aislop 未安装(ShipGate 不做临时 npx 兜底,避免每次拉包失败)',
|
|
32
|
+
findings: [],
|
|
33
|
+
evidence: { install: 'npm i -g aislop' },
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Vendored upstream trees, not this repo's code: `assets/pi-gate` and
|
|
38
|
+
// `assets/gates` come from agent-config-bridge, `assets/pi-extensions` from
|
|
39
|
+
// the same repo's gate extensions. They import packages the pi runtime
|
|
40
|
+
// provides (`@earendil-works/pi-coding-agent`, `typebox`) and must not be
|
|
41
|
+
// declared as dependencies here — the zero-dependency rule is exactly why
|
|
42
|
+
// they are vendored. Scoring them would report the upstream design as our
|
|
43
|
+
// slop and push someone to fork it.
|
|
44
|
+
const excludes = ['assets/pi-gate', 'assets/gates', 'assets/pi-extensions'];
|
|
45
|
+
const result = run(bin, ['scan', scanDir, '--json', ...excludes.flatMap((p) => ['--exclude', p])], { timeout });
|
|
46
|
+
const data = parseJsonPayload(result.stdout);
|
|
47
|
+
|
|
48
|
+
if (!data) {
|
|
49
|
+
return {
|
|
50
|
+
gate: 'quality',
|
|
51
|
+
ok: false,
|
|
52
|
+
code: 3,
|
|
53
|
+
summary: `aislop 输出无法解析(exit=${result.code})`,
|
|
54
|
+
findings: [],
|
|
55
|
+
evidence: { stderr: result.stderr.slice(0, 2000), stdout: result.stdout.slice(0, 2000) },
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const diagnostics = data.diagnostics ?? [];
|
|
60
|
+
const errors = diagnostics.filter((d) => d.severity === 'error');
|
|
61
|
+
const failedEngines = data.coverage?.failedEngines ?? [];
|
|
62
|
+
|
|
63
|
+
// aislop emits `<engine>/engine-error` when the engine itself crashed. That is
|
|
64
|
+
// an environment fault: reporting it as a code finding sends the operator to
|
|
65
|
+
// the wrong file, and code 1 (= fix your code) is the wrong verdict.
|
|
66
|
+
const engineErrors = diagnostics.filter((d) => /(^|\/)engine-error$/.test(String(d.rule ?? '')));
|
|
67
|
+
if (engineErrors.length > 0) {
|
|
68
|
+
const rules = [...new Set(engineErrors.map((d) => String(d.rule)))];
|
|
69
|
+
const engines = [...new Set(rules.map((rule) => rule.split('/')[0]))];
|
|
70
|
+
return {
|
|
71
|
+
gate: 'quality',
|
|
72
|
+
ok: false,
|
|
73
|
+
code: 3,
|
|
74
|
+
summary: `无法评分(${engines.join(', ')} 引擎报错)——环境问题,不是代码问题`,
|
|
75
|
+
findings: [],
|
|
76
|
+
evidence: {
|
|
77
|
+
score: data.score ?? null,
|
|
78
|
+
engines,
|
|
79
|
+
rules,
|
|
80
|
+
engineErrors: engineErrors.slice(0, 5),
|
|
81
|
+
failedEngines,
|
|
82
|
+
hint: engineHint(rules, bin),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (data.scoreable !== true) {
|
|
88
|
+
const hint = failedEngines.includes('lint')
|
|
89
|
+
? 'lint 引擎跑不起来:先运行 `aislop doctor`;若是 oxlint 二进制与 CPU 指令集不兼容(无 AVX2 的老 CPU 会 SIGILL),在项目 .aislop/config.yml 里设 engines.lint: false,或换到 CI 机器跑'
|
|
90
|
+
: '先运行 `aislop doctor` 看哪个引擎失败,再决定禁用该引擎或补依赖';
|
|
91
|
+
// Not the code's fault: the engine never ran. Report as environment gap (3)
|
|
92
|
+
// so CI distinguishes "fix your code" from "fix this machine". It is still
|
|
93
|
+
// non-zero — an unrunnable scan must never read as green.
|
|
94
|
+
return {
|
|
95
|
+
gate: 'quality',
|
|
96
|
+
ok: false,
|
|
97
|
+
code: 3,
|
|
98
|
+
summary: `无法评分(引擎未跑起来:${failedEngines.join(', ') || '未知'})——环境问题,不是代码问题`,
|
|
99
|
+
findings: errors.slice(0, 20),
|
|
100
|
+
evidence: { score: data.score ?? null, failedEngines, coverage: data.coverage, hint },
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const ok = data.score >= min && errors.length === 0;
|
|
105
|
+
return {
|
|
106
|
+
gate: 'quality',
|
|
107
|
+
ok,
|
|
108
|
+
code: ok ? 0 : 1,
|
|
109
|
+
summary: ok
|
|
110
|
+
? `score ${data.score} ≥ ${min},无 error 级发现`
|
|
111
|
+
: `score ${data.score}${data.score < min ? ` < ${min}` : ''}${errors.length ? `,${errors.length} 个 error 级发现` : ''}`,
|
|
112
|
+
findings: errors.slice(0, 20),
|
|
113
|
+
evidence: {
|
|
114
|
+
score: data.score,
|
|
115
|
+
label: data.label,
|
|
116
|
+
min,
|
|
117
|
+
errorCount: errors.length,
|
|
118
|
+
totalFindings: diagnostics.length,
|
|
119
|
+
engineVersion: data.cliVersion,
|
|
120
|
+
bin,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { exists, readText } from '../lib/fsx.mjs';
|
|
3
|
+
import { which } from '../lib/exec.mjs';
|
|
4
|
+
|
|
5
|
+
const SCOPE_HINT = /in[- ]scope|在范围内|scope|资产|targets?/i;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Red line: an active probing tool must never run automatically.
|
|
9
|
+
* This gate therefore only validates that a scope exists and hands the operator
|
|
10
|
+
* the next commands — it does not fire recon itself.
|
|
11
|
+
*/
|
|
12
|
+
export function runSecurityGate({ cwd = process.cwd(), scope = null, dryRun = false } = {}) {
|
|
13
|
+
if (!scope) {
|
|
14
|
+
return {
|
|
15
|
+
gate: 'security',
|
|
16
|
+
ok: false,
|
|
17
|
+
code: 2,
|
|
18
|
+
summary: '必须显式指定 --scope <scope.md>:主动探测不可自动执行',
|
|
19
|
+
findings: [{ level: 'error', message: '缺少 scope 文件,ShipGate 拒绝执行 security 闸' }],
|
|
20
|
+
evidence: {
|
|
21
|
+
example: 'shipgate security --scope ./scope.md',
|
|
22
|
+
why: '没有书面授权范围就发起探测属于越界;范围必须由人确认',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const file = path.resolve(cwd, scope);
|
|
28
|
+
if (!exists(file)) {
|
|
29
|
+
return {
|
|
30
|
+
gate: 'security',
|
|
31
|
+
ok: false,
|
|
32
|
+
code: 2,
|
|
33
|
+
summary: `scope 文件不存在:${file}`,
|
|
34
|
+
findings: [{ level: 'error', message: 'scope 文件不存在' }],
|
|
35
|
+
evidence: { scope: file },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const text = readText(file);
|
|
40
|
+
const findings = [];
|
|
41
|
+
if (text.trim().length < 20) {
|
|
42
|
+
findings.push({ level: 'error', message: 'scope 文件内容过短,无法确认授权范围' });
|
|
43
|
+
}
|
|
44
|
+
if (!SCOPE_HINT.test(text)) {
|
|
45
|
+
findings.push({ level: 'warn', message: 'scope 文件里没找到 in-scope / 范围 段落,请人工确认' });
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const errors = findings.filter((f) => f.level === 'error');
|
|
49
|
+
if (errors.length > 0) {
|
|
50
|
+
return {
|
|
51
|
+
gate: 'security',
|
|
52
|
+
ok: false,
|
|
53
|
+
code: 2,
|
|
54
|
+
summary: 'scope 校验不通过',
|
|
55
|
+
findings,
|
|
56
|
+
evidence: { scope: file },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const cbh = which('cbh');
|
|
61
|
+
if (!cbh) {
|
|
62
|
+
return {
|
|
63
|
+
gate: 'security',
|
|
64
|
+
ok: false,
|
|
65
|
+
code: 3,
|
|
66
|
+
summary: 'cbh 未安装(安全审计引擎缺失)',
|
|
67
|
+
findings,
|
|
68
|
+
evidence: {
|
|
69
|
+
scope: file,
|
|
70
|
+
install: 'pipx install git+https://github.com/elementalsouls/Claude-BugHunter',
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const next = [
|
|
76
|
+
'cbh recon <target>',
|
|
77
|
+
'cbh surface <target>',
|
|
78
|
+
'cbh classify <url>',
|
|
79
|
+
'cbh triage <finding.md>',
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
gate: 'security',
|
|
84
|
+
ok: true,
|
|
85
|
+
code: 0,
|
|
86
|
+
summary: dryRun
|
|
87
|
+
? 'scope 校验通过(dry-run:未执行任何探测)'
|
|
88
|
+
: 'scope 校验通过;按 shipgate-security skill 执行探测与取证',
|
|
89
|
+
findings,
|
|
90
|
+
evidence: { scope: file, cbh, dryRun, next },
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { exists, readText } from '../lib/fsx.mjs';
|
|
3
|
+
import { sourceTreeDrift } from '../lib/skills.mjs';
|
|
4
|
+
import { blockVersion, expectedBlockVersion } from '../inject/render.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Verifies that each target harness actually holds what the manifest claims:
|
|
8
|
+
* skill files present with matching hashes, inject block present, gate bundle
|
|
9
|
+
* present for free-form harnesses.
|
|
10
|
+
*/
|
|
11
|
+
export function runShipGate({ harnesses = [], manifest, skillsSource }) {
|
|
12
|
+
const findings = [];
|
|
13
|
+
|
|
14
|
+
for (const harness of harnesses) {
|
|
15
|
+
const record = manifest.harnesses[harness.id] ?? { skills: {}, inject: null, gate: null };
|
|
16
|
+
|
|
17
|
+
if (harness.skillsPath) {
|
|
18
|
+
for (const name of Object.keys(record.skills ?? {})) {
|
|
19
|
+
const installed = path.join(harness.skillsPath, name, 'SKILL.md');
|
|
20
|
+
const sourceDir = path.join(skillsSource, name);
|
|
21
|
+
const source = path.join(sourceDir, 'SKILL.md');
|
|
22
|
+
if (!exists(installed)) {
|
|
23
|
+
findings.push({ level: 'error', harness: harness.id, message: `skill 缺失:${installed}` });
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
// Same judgement as installSkills(): the destination must carry every
|
|
27
|
+
// source file with matching content. Files the destination adds on its
|
|
28
|
+
// own (e.g. codex's agents/openai.yaml inside a skill) are not drift —
|
|
29
|
+
// comparing whole-tree hashes here made every install look inconsistent.
|
|
30
|
+
if (exists(source) && sourceTreeDrift(sourceDir, path.join(harness.skillsPath, name))) {
|
|
31
|
+
findings.push({ level: 'error', harness: harness.id, message: `skill 与源不一致,需要重装:${name}` });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (harness.injectPath) {
|
|
37
|
+
if (!exists(harness.injectPath)) {
|
|
38
|
+
findings.push({ level: 'error', harness: harness.id, message: `注入文件缺失:${harness.injectPath}` });
|
|
39
|
+
} else {
|
|
40
|
+
const found = blockVersion(readText(harness.injectPath));
|
|
41
|
+
const expected = expectedBlockVersion();
|
|
42
|
+
if (!found) {
|
|
43
|
+
findings.push({ level: 'error', harness: harness.id, message: `注入文件没有 shipgate 区块:${harness.injectPath}` });
|
|
44
|
+
} else if (expected && found !== expected) {
|
|
45
|
+
// A stale block (e.g. v2 left over from an older release) looks
|
|
46
|
+
// installed but teaches the agent old rules — that is drift too.
|
|
47
|
+
findings.push({
|
|
48
|
+
level: 'error',
|
|
49
|
+
harness: harness.id,
|
|
50
|
+
message: `注入区块是 ${found},当前版本是 ${expected} —— 重跑 shipgate install:${harness.injectPath}`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (harness.gateDest) {
|
|
57
|
+
if (!exists(harness.gateDest)) {
|
|
58
|
+
findings.push({ level: 'error', harness: harness.id, message: `硬门控产物缺失:${harness.gateDest}` });
|
|
59
|
+
} else if (!exists(path.join(harness.gateDest, 'policy.js'))) {
|
|
60
|
+
findings.push({ level: 'error', harness: harness.id, message: `硬门控产物不完整(缺 policy.js):${harness.gateDest}` });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const ok = findings.length === 0;
|
|
66
|
+
return {
|
|
67
|
+
gate: 'ship',
|
|
68
|
+
ok,
|
|
69
|
+
code: ok ? 0 : 1,
|
|
70
|
+
summary: ok ? `${harnesses.length} 个 harness 的产物与 manifest 一致` : `${findings.length} 处产物不一致`,
|
|
71
|
+
findings,
|
|
72
|
+
evidence: { harnesses: harnesses.map((h) => h.id) },
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { exists, listDir, readText } from '../lib/fsx.mjs';
|
|
3
|
+
|
|
4
|
+
const REQUIRED = ['PRD.md', 'SPEC.md', 'TRACEABILITY.md'];
|
|
5
|
+
|
|
6
|
+
export function specStatus(text) {
|
|
7
|
+
const front = text.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
8
|
+
if (!front) return null;
|
|
9
|
+
const line = front[1].split(/\r?\n/).find((l) => /^status\s*:/.test(l));
|
|
10
|
+
if (!line) return null;
|
|
11
|
+
return line.slice(line.indexOf(':') + 1).trim().replace(/^["']|["']$/g, '');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function hasAcceptanceCriteria(text) {
|
|
15
|
+
return /验收判据|验收标准|AC-\d+/.test(text);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function checkChangeDir(dir) {
|
|
19
|
+
const findings = [];
|
|
20
|
+
for (const name of REQUIRED) {
|
|
21
|
+
if (!exists(path.join(dir, name))) {
|
|
22
|
+
findings.push({ level: 'error', file: name, message: `缺少 ${name}` });
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const specPath = path.join(dir, 'SPEC.md');
|
|
26
|
+
if (exists(specPath)) {
|
|
27
|
+
const spec = readText(specPath);
|
|
28
|
+
const status = specStatus(spec);
|
|
29
|
+
if (!status) {
|
|
30
|
+
findings.push({ level: 'error', file: 'SPEC.md', message: 'SPEC.md 缺少 frontmatter 的 status 字段' });
|
|
31
|
+
} else if (status === 'draft') {
|
|
32
|
+
findings.push({ level: 'error', file: 'SPEC.md', message: 'SPEC.md status 仍为 draft,契约未成立' });
|
|
33
|
+
}
|
|
34
|
+
if (!hasAcceptanceCriteria(spec)) {
|
|
35
|
+
findings.push({ level: 'error', file: 'SPEC.md', message: 'SPEC.md 未写验收判据(需含「验收判据」或 AC-x)' });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return findings;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Accepts either a single change directory (tasks/CHG-x) or a parent that holds
|
|
43
|
+
* change directories (tasks). A parent with zero CHG-* children fails: "no
|
|
44
|
+
* contract" is the failure this gate exists to catch.
|
|
45
|
+
*/
|
|
46
|
+
function changeDirsIn(base) {
|
|
47
|
+
if (exists(path.join(base, 'SPEC.md'))) return [{ name: path.basename(base), path: base }];
|
|
48
|
+
return listDir(base)
|
|
49
|
+
.filter((e) => e.isDirectory() && /^CHG-/.test(e.name))
|
|
50
|
+
.map((e) => ({ name: e.name, path: path.join(base, e.name) }))
|
|
51
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function runSpecGate({ cwd = process.cwd(), dir = 'tasks' } = {}) {
|
|
55
|
+
const requested = path.resolve(cwd, dir);
|
|
56
|
+
// `shipgate spec check <repo-root>` is what people type, while contracts live
|
|
57
|
+
// in <root>/tasks. Probe exactly one level down — never search the tree.
|
|
58
|
+
const nested = path.join(requested, 'tasks');
|
|
59
|
+
const base = changeDirsIn(requested).length > 0 ? requested : changeDirsIn(nested).length > 0 ? nested : requested;
|
|
60
|
+
const changeDirs = changeDirsIn(base);
|
|
61
|
+
|
|
62
|
+
if (changeDirs.length === 0) {
|
|
63
|
+
return {
|
|
64
|
+
gate: 'spec',
|
|
65
|
+
ok: false,
|
|
66
|
+
code: 1,
|
|
67
|
+
summary: `${requested}(及 ${nested})下没有任何 CHG-* 变更目录:没有契约,不允许改代码`,
|
|
68
|
+
findings: [{ level: 'error', message: '缺少 tasks/CHG-<id>/ 契约目录' }],
|
|
69
|
+
evidence: { dir: requested },
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const findings = changeDirs.flatMap((chg) =>
|
|
74
|
+
checkChangeDir(chg.path).map((f) => ({ ...f, change: chg.name })),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const ok = findings.length === 0;
|
|
78
|
+
return {
|
|
79
|
+
gate: 'spec',
|
|
80
|
+
ok,
|
|
81
|
+
code: ok ? 0 : 1,
|
|
82
|
+
summary: ok
|
|
83
|
+
? `${changeDirs.length} 个变更契约成立(${changeDirs.map((c) => c.name).join(', ')})`
|
|
84
|
+
: `${findings.length} 处契约缺口`,
|
|
85
|
+
findings,
|
|
86
|
+
evidence: { dir: base, changes: changeDirs.map((c) => c.name) },
|
|
87
|
+
};
|
|
88
|
+
}
|