shipgate-cli 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +258 -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 +1121 -0
- package/assets/gates/pi/policy.json +93 -0
- package/assets/gates/policy.js +4199 -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 +215 -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 +117 -0
- package/src/commands/ask.mjs +82 -0
- package/src/commands/deploy.mjs +589 -0
- package/src/commands/gates.mjs +83 -0
- package/src/commands/policy.mjs +67 -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/engines.mjs +182 -0
- package/src/lib/exec.mjs +80 -0
- package/src/lib/fsx.mjs +119 -0
- package/src/lib/gate.mjs +288 -0
- package/src/lib/log.mjs +31 -0
- package/src/lib/skills.mjs +347 -0
- package/src/lib/state.mjs +41 -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,67 @@
|
|
|
1
|
+
import { c, log, table } from '../lib/log.mjs';
|
|
2
|
+
import { addProtected, gateStatus, loadPolicy, removeProtected, setMode, syncPolicyToHarnesses } from '../lib/gate.mjs';
|
|
3
|
+
import { allHarnesses, detected, resolveHarness } from '../harness/index.mjs';
|
|
4
|
+
|
|
5
|
+
function gatedHarnesses(cfg) {
|
|
6
|
+
return allHarnesses(cfg)
|
|
7
|
+
.map(resolveHarness)
|
|
8
|
+
.filter((h) => h.gateDest);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function policyCommand(ctx) {
|
|
12
|
+
const { flags } = ctx;
|
|
13
|
+
|
|
14
|
+
if (flags['add-protected']) {
|
|
15
|
+
const policy = addProtected(String(flags['add-protected']));
|
|
16
|
+
log.ok(`已加入受保护工作区:${String(flags['add-protected'])}`);
|
|
17
|
+
log.info(c.dim(`当前共 ${policy.config.protected_worktrees.length} 条`));
|
|
18
|
+
return syncAll(ctx);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (flags['rm-protected']) {
|
|
22
|
+
const policy = removeProtected(String(flags['rm-protected']));
|
|
23
|
+
log.ok(`已移除:${String(flags['rm-protected'])}`);
|
|
24
|
+
log.info(c.dim(`剩余 ${policy.config.protected_worktrees.length} 条`));
|
|
25
|
+
return syncAll(ctx);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (flags.mode) {
|
|
29
|
+
const policy = setMode(String(flags.mode));
|
|
30
|
+
log.ok(`destructive_mode = ${policy.config.destructive_mode}`);
|
|
31
|
+
return syncAll(ctx);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (flags.sync) return syncAll(ctx);
|
|
35
|
+
|
|
36
|
+
const policy = loadPolicy();
|
|
37
|
+
const rows = gatedHarnesses(ctx.cfg).map((harness) => {
|
|
38
|
+
const status = gateStatus(harness);
|
|
39
|
+
return [harness.id, status.installed ? 'installed' : 'missing', status.mode ?? '-', String(status.protected ?? 0), harness.gateDest];
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (ctx.flags.json) {
|
|
43
|
+
log.plain(JSON.stringify({ policy, harnesses: rows }, null, 2));
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
log.title(`策略真源:${policy.config.destructive_mode} · 受保护工作区 ${policy.config.protected_worktrees.length} 条`);
|
|
48
|
+
for (const p of policy.config.protected_worktrees) log.info(` · ${p}`);
|
|
49
|
+
log.title('硬门控落地');
|
|
50
|
+
if (rows.length === 0) log.warn('没有任何 harness 配置了 gate(只有 pi/dsh 类需要)');
|
|
51
|
+
else log.plain(table(rows, ['harness', 'gate', 'mode', 'protected', '路径']));
|
|
52
|
+
log.info(c.dim('用法:shipgate policy --add-protected <dir> | --rm-protected <dir> | --mode enforce|bypass | --sync'));
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function syncAll(ctx) {
|
|
57
|
+
const harnesses = gatedHarnesses(ctx.cfg).filter(detected);
|
|
58
|
+
const touched = syncPolicyToHarnesses(harnesses, { dryRun: Boolean(ctx.flags['dry-run']) });
|
|
59
|
+
if (touched.length === 0) {
|
|
60
|
+
log.warn('没有已安装 gate 的 harness 需要同步(先 `shipgate install --harness pi`)');
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
for (const item of touched) {
|
|
64
|
+
log.ok(`${item.harness} ← ${item.mode} / protected ${item.protected} ${c.dim(item.target)}`);
|
|
65
|
+
}
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { expand } from '../lib/cfg.mjs';
|
|
2
|
+
import { exists, isSymlink, realpathOrNull } from '../lib/fsx.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Built-in harness profiles: what each agent can actually consume.
|
|
6
|
+
*
|
|
7
|
+
* `gate` is only set for free-form harnesses (pi / dsh-like): they get a
|
|
8
|
+
* process-level gate bundle. Claude Code / Codex / Gemini have no such hook
|
|
9
|
+
* surface, so they are steered by skills + injected docs only — the docs say so
|
|
10
|
+
* explicitly rather than pretending they are hard-gated.
|
|
11
|
+
*/
|
|
12
|
+
export const BUILTIN = [
|
|
13
|
+
{
|
|
14
|
+
id: 'claude',
|
|
15
|
+
label: 'Claude Code',
|
|
16
|
+
detect: '~/.claude',
|
|
17
|
+
skills: '~/.claude/skills',
|
|
18
|
+
commands: '~/.claude/commands',
|
|
19
|
+
agents: '~/.claude/agents',
|
|
20
|
+
inject: '~/.claude/CLAUDE.md',
|
|
21
|
+
gate: null,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: 'pi',
|
|
25
|
+
label: 'pi agent',
|
|
26
|
+
detect: '~/.pi',
|
|
27
|
+
skills: '~/.agents/skills',
|
|
28
|
+
// pi stores prompt/command templates here; the file shape (frontmatter
|
|
29
|
+
// `description` + `# /name`) is identical to ShipGate's commands, so the 22
|
|
30
|
+
// slash commands are reusable as-is.
|
|
31
|
+
commands: '~/.pi/agent/prompts',
|
|
32
|
+
agents: null,
|
|
33
|
+
inject: '~/.pi/agent/APPEND_SYSTEM.md',
|
|
34
|
+
gate: { dest: '~/.pi/agent/extensions/enforce-rules', kind: 'pi' },
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 'dsh',
|
|
38
|
+
label: 'dsh',
|
|
39
|
+
detect: '~/.dsh',
|
|
40
|
+
// dsh's native user skill root is ~/.agents/skills (same one pi reads), not
|
|
41
|
+
// ~/.dsh/skills. Verified against dsh 0.2.2-rc.3 in
|
|
42
|
+
// agent-config-bridge/bridge/targets/dsh.json: "~/.agents/skills is a native
|
|
43
|
+
// user skill root ... the same link pi uses is enough". Writing to
|
|
44
|
+
// ~/.dsh/skills left the skills unread for a dsh-only user.
|
|
45
|
+
skills: '~/.agents/skills',
|
|
46
|
+
commands: null,
|
|
47
|
+
agents: null,
|
|
48
|
+
inject: '~/.dsh/AGENTS.md',
|
|
49
|
+
gate: { dest: '~/.dsh/extensions/enforce-rules', kind: 'dsh' },
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 'codex',
|
|
53
|
+
label: 'Codex CLI',
|
|
54
|
+
detect: '~/.codex',
|
|
55
|
+
skills: '~/.codex/skills',
|
|
56
|
+
commands: null,
|
|
57
|
+
agents: null,
|
|
58
|
+
inject: '~/.codex/AGENTS.md',
|
|
59
|
+
gate: null,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 'gemini',
|
|
63
|
+
label: 'Gemini CLI',
|
|
64
|
+
detect: '~/.gemini',
|
|
65
|
+
skills: '~/.gemini/skills',
|
|
66
|
+
commands: null,
|
|
67
|
+
agents: null,
|
|
68
|
+
inject: '~/.gemini/GEMINI.md',
|
|
69
|
+
gate: null,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 'cursor',
|
|
73
|
+
label: 'Cursor',
|
|
74
|
+
detect: '~/.cursor',
|
|
75
|
+
// Cursor reads user-level Agent Skills from ~/.cursor/skills (its 20 built-in
|
|
76
|
+
// skills live in ~/.cursor/skills-cursor). Declaring null here left Cursor as
|
|
77
|
+
// the only detected harness with zero gate skills.
|
|
78
|
+
skills: '~/.cursor/skills',
|
|
79
|
+
commands: null,
|
|
80
|
+
agents: null,
|
|
81
|
+
inject: '~/.cursor/rules/shipgate.mdc',
|
|
82
|
+
gate: null,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: 'kimi',
|
|
86
|
+
label: 'Kimi Code',
|
|
87
|
+
detect: '~/.kimi-code',
|
|
88
|
+
skills: '~/.kimi-code/skills',
|
|
89
|
+
// Kimi's own Claude-importer docs state that Claude custom commands are
|
|
90
|
+
// out of scope: there is no destination, so commands stay null instead of
|
|
91
|
+
// inventing one.
|
|
92
|
+
commands: null,
|
|
93
|
+
agents: null,
|
|
94
|
+
inject: '~/.kimi-code/AGENTS.md',
|
|
95
|
+
gate: null,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: 'antigravity',
|
|
99
|
+
label: 'Antigravity',
|
|
100
|
+
detect: '~/.antigravity',
|
|
101
|
+
// Agent Skills open standard: the global user-scope root is under .gemini,
|
|
102
|
+
// NOT ~/.antigravity (which only holds the IDE's own settings.json).
|
|
103
|
+
skills: '~/.gemini/antigravity/skills',
|
|
104
|
+
commands: null,
|
|
105
|
+
agents: null,
|
|
106
|
+
// Global rules-doc path for Antigravity is unverified; distributing skills
|
|
107
|
+
// only is honest, inventing an inject target would not be.
|
|
108
|
+
inject: null,
|
|
109
|
+
gate: null,
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Resolve a declared skills path through a symlink/junction. `~/.agents/skills`
|
|
115
|
+
* is a link to ~/.claude/skills on this machine, created and owned by
|
|
116
|
+
* agent-config-bridge. ShipGate copies skills; writing through the link keeps
|
|
117
|
+
* exactly one copy shared by claude / pi / dsh. A broken link is reported as
|
|
118
|
+
* broken instead of being silently replaced (creating the link is bridge's job).
|
|
119
|
+
*/
|
|
120
|
+
function resolveSkillsPath(declaredPath) {
|
|
121
|
+
if (!declaredPath) return { path: null, declared: null, followed: false, broken: false };
|
|
122
|
+
const declared = expand(declaredPath);
|
|
123
|
+
if (!isSymlink(declared)) return { path: declared, declared, followed: false, broken: false };
|
|
124
|
+
const real = realpathOrNull(declared);
|
|
125
|
+
if (!real) return { path: declared, declared, followed: true, broken: true };
|
|
126
|
+
return { path: real, declared, followed: true, broken: false };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function allHarnesses(cfg) {
|
|
130
|
+
const custom = Object.entries(cfg.custom ?? {}).map(([id, value]) => ({
|
|
131
|
+
id,
|
|
132
|
+
label: value.label ?? id,
|
|
133
|
+
detect: value.detect ?? null,
|
|
134
|
+
skills: value.skills ?? null,
|
|
135
|
+
commands: value.commands ?? null,
|
|
136
|
+
agents: value.agents ?? null,
|
|
137
|
+
inject: value.inject ?? null,
|
|
138
|
+
gate: value.gate ? { dest: value.gate.dest, kind: value.gate.kind ?? 'pi' } : null,
|
|
139
|
+
custom: true,
|
|
140
|
+
}));
|
|
141
|
+
return [...BUILTIN, ...custom];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function getHarness(id, cfg) {
|
|
145
|
+
const found = allHarnesses(cfg).find((h) => h.id === id);
|
|
146
|
+
if (!found) {
|
|
147
|
+
throw new Error(`未知 harness: ${id}(可用:${allHarnesses(cfg).map((h) => h.id).join(', ')})`);
|
|
148
|
+
}
|
|
149
|
+
return found;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function resolveHarness(harness) {
|
|
153
|
+
const skills = resolveSkillsPath(harness.skills);
|
|
154
|
+
return {
|
|
155
|
+
...harness,
|
|
156
|
+
detectPath: harness.detect ? expand(harness.detect) : null,
|
|
157
|
+
skillsPath: skills.path,
|
|
158
|
+
skillsDeclaredPath: skills.declared,
|
|
159
|
+
skillsFollowed: skills.followed,
|
|
160
|
+
skillsBroken: skills.broken,
|
|
161
|
+
commandsPath: harness.commands ? expand(harness.commands) : null,
|
|
162
|
+
agentsPath: harness.agents ? expand(harness.agents) : null,
|
|
163
|
+
injectPath: harness.inject ? expand(harness.inject) : null,
|
|
164
|
+
gateDest: harness.gate ? expand(harness.gate.dest) : null,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function detected(harness) {
|
|
169
|
+
// A harness without a detect path is user-declared (custom profile): it is
|
|
170
|
+
// installable by intent, not skipped as "not on this machine".
|
|
171
|
+
return harness.detectPath ? exists(harness.detectPath) : true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Capability summary, used by --ask and doctor. */
|
|
175
|
+
export function capabilities(harness) {
|
|
176
|
+
return {
|
|
177
|
+
skills: Boolean(harness.skillsPath),
|
|
178
|
+
commands: Boolean(harness.commandsPath),
|
|
179
|
+
agents: Boolean(harness.agentsPath),
|
|
180
|
+
inject: Boolean(harness.injectPath),
|
|
181
|
+
gate: Boolean(harness.gateDest),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Target harnesses for a run: explicit --harness wins, otherwise config list. */
|
|
186
|
+
export function selectHarnesses({ requested, cfg, includeUndetected = false }) {
|
|
187
|
+
const all = allHarnesses(cfg).map(resolveHarness);
|
|
188
|
+
const configured = cfg.harnesses === 'auto' || cfg.harnesses == null ? null : cfg.harnesses;
|
|
189
|
+
|
|
190
|
+
const wanted =
|
|
191
|
+
requested && requested !== 'all'
|
|
192
|
+
? requested.split(',').map((s) => s.trim()).filter(Boolean)
|
|
193
|
+
: requested === 'all' || configured === null
|
|
194
|
+
? all.filter(detected).map((h) => h.id)
|
|
195
|
+
: configured;
|
|
196
|
+
|
|
197
|
+
const selected = wanted.map((id) => all.find((h) => h.id === id) ?? resolveHarness(getHarness(id, cfg)));
|
|
198
|
+
const missing = selected.filter((h) => !detected(h));
|
|
199
|
+
if (missing.length > 0 && !includeUndetected) {
|
|
200
|
+
return { selected: selected.filter(detected), missing };
|
|
201
|
+
}
|
|
202
|
+
return { selected, missing };
|
|
203
|
+
}
|