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,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
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { packageRoot } from '../version.mjs';
|
|
3
|
+
import { backupOnce, readIfExists, readText, writeText } from '../lib/fsx.mjs';
|
|
4
|
+
|
|
5
|
+
const BLOCK_RE = /<!-- shipgate:begin v\d+ -->[\s\S]*?<!-- shipgate:end -->/;
|
|
6
|
+
|
|
7
|
+
const CURSOR_FRONTMATTER = [
|
|
8
|
+
'---',
|
|
9
|
+
'description: ShipGate gate chain (spec / quality / security / ship)',
|
|
10
|
+
'globs: ["**/*"]',
|
|
11
|
+
'alwaysApply: true',
|
|
12
|
+
'---',
|
|
13
|
+
'',
|
|
14
|
+
].join('\n');
|
|
15
|
+
|
|
16
|
+
export function templatePath() {
|
|
17
|
+
return path.join(packageRoot(), 'templates', 'agents-snippet.md');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function renderBlock({ version, min }) {
|
|
21
|
+
const template = readText(templatePath());
|
|
22
|
+
return template
|
|
23
|
+
.replaceAll('{{VERSION}}', version)
|
|
24
|
+
.replaceAll('{{MIN}}', String(min))
|
|
25
|
+
.trim();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Idempotent by construction: the block carries no timestamp, so the same
|
|
30
|
+
* inputs always produce byte-identical output. Content outside the markers is
|
|
31
|
+
* never rewritten — only appended to when no block exists yet.
|
|
32
|
+
*/
|
|
33
|
+
export function upsertBlock(file, block, { dryRun = false, frontmatter = null } = {}) {
|
|
34
|
+
const current = readIfExists(file);
|
|
35
|
+
|
|
36
|
+
if (current === null) {
|
|
37
|
+
const body = (frontmatter ? frontmatter : '') + block + '\n';
|
|
38
|
+
if (!dryRun) writeText(file, body);
|
|
39
|
+
return { action: 'created', file };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (BLOCK_RE.test(current)) {
|
|
43
|
+
const next = current.replace(BLOCK_RE, block);
|
|
44
|
+
if (next === current) return { action: 'unchanged', file };
|
|
45
|
+
if (!dryRun) {
|
|
46
|
+
backupOnce(file);
|
|
47
|
+
writeText(file, next);
|
|
48
|
+
}
|
|
49
|
+
return { action: 'updated', file };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const next = current.replace(/\s*$/, '\n\n') + block + '\n';
|
|
53
|
+
if (!dryRun) {
|
|
54
|
+
backupOnce(file);
|
|
55
|
+
writeText(file, next);
|
|
56
|
+
}
|
|
57
|
+
return { action: 'appended', file };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function blockVersion(text) {
|
|
61
|
+
const match = text?.match(/<!-- shipgate:begin (v\d+) -->/);
|
|
62
|
+
return match ? match[1] : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The block version this release ships, parsed from the template itself so the
|
|
67
|
+
* gate and the installer can never disagree about what "current" means.
|
|
68
|
+
*/
|
|
69
|
+
export function expectedBlockVersion() {
|
|
70
|
+
return blockVersion(readText(templatePath()));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function cursorFrontmatter() {
|
|
74
|
+
return CURSOR_FRONTMATTER;
|
|
75
|
+
}
|
package/src/lib/cfg.mjs
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { readIfExists } from './fsx.mjs';
|
|
4
|
+
|
|
5
|
+
export const HOME = os.homedir();
|
|
6
|
+
|
|
7
|
+
export function expand(p) {
|
|
8
|
+
if (!p) return p;
|
|
9
|
+
if (p === '~') return HOME;
|
|
10
|
+
if (p.startsWith('~/')) return path.join(HOME, p.slice(2));
|
|
11
|
+
return p;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const DEFAULTS = {
|
|
15
|
+
version: 1,
|
|
16
|
+
// 'auto' = every harness detected on this machine. A fixed list silently
|
|
17
|
+
// skipped agents (e.g. codex/gemini) unless the user edited config first.
|
|
18
|
+
harnesses: 'auto',
|
|
19
|
+
custom: {},
|
|
20
|
+
quality: { min: 80 },
|
|
21
|
+
spec: { dir: 'tasks' },
|
|
22
|
+
security: { scope: null },
|
|
23
|
+
update: { autoUpdate: false },
|
|
24
|
+
engines: { aislop: 'auto', cbh: 'auto', allowNpx: false },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const DEEP_KEYS = ['quality', 'spec', 'security', 'update', 'engines', 'custom'];
|
|
28
|
+
|
|
29
|
+
export function mergeConfig(base, over) {
|
|
30
|
+
const out = { ...base, ...over };
|
|
31
|
+
for (const key of DEEP_KEYS) {
|
|
32
|
+
if (over[key] && typeof over[key] === 'object' && !Array.isArray(over[key])) {
|
|
33
|
+
out[key] = { ...(base[key] ?? {}), ...over[key] };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function globalConfigPath() {
|
|
40
|
+
return path.join(HOME, '.config', 'shipgate', 'config.json');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function projectConfigPath(cwd) {
|
|
44
|
+
return path.join(cwd, '.shipgate', 'config.json');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function readJson(file) {
|
|
48
|
+
const text = readIfExists(file);
|
|
49
|
+
if (text === null) return null;
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(text);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
throw new Error(`配置文件不是合法 JSON: ${file}\n${error.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Precedence: built-in defaults < global config < project config.
|
|
59
|
+
* A malformed file is a hard error, not a silent fallback — a typo must not
|
|
60
|
+
* silently downgrade the gate threshold.
|
|
61
|
+
*/
|
|
62
|
+
export function loadConfig(cwd = process.cwd()) {
|
|
63
|
+
const globalCfg = readJson(globalConfigPath()) ?? {};
|
|
64
|
+
const projectCfg = readJson(projectConfigPath(cwd)) ?? {};
|
|
65
|
+
return mergeConfig(mergeConfig(DEFAULTS, globalCfg), projectCfg);
|
|
66
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one duration grammar the destructive-mode switch accepts:
|
|
3
|
+
* `90s` / `30m` / `8h` / `2d`, or a bare number (= hours).
|
|
4
|
+
*
|
|
5
|
+
* The pi adapter has its own pre-check (`parseGateDurationMs` in
|
|
6
|
+
* `assets/gates/pi/index.js`) because `/gate mode` must refuse a typo before it
|
|
7
|
+
* spawns anything. Both implementations are kept character-for-character equal
|
|
8
|
+
* on purpose: the adapter validates, this module is what the CLI actually
|
|
9
|
+
* writes. If they drifted, a user typing `8h` would get a different expiry than
|
|
10
|
+
* the one they asked for - and an expiry nobody can predict is worse than no
|
|
11
|
+
* expiry at all (CHG-20261129-gate-mode-true-source).
|
|
12
|
+
*
|
|
13
|
+
* Anything unparseable returns `null`; callers must refuse rather than guess.
|
|
14
|
+
*/
|
|
15
|
+
const UNITS = { s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
16
|
+
|
|
17
|
+
export function parseDurationMs(text) {
|
|
18
|
+
const m = /^(\d+(?:\.\d+)?)\s*(s|m|h|d)?$/i.exec(String(text ?? '').trim());
|
|
19
|
+
if (!m) return null;
|
|
20
|
+
const n = Number(m[1]);
|
|
21
|
+
if (!Number.isFinite(n) || n <= 0) return null;
|
|
22
|
+
const unit = (m[2] ?? 'h').toLowerCase();
|
|
23
|
+
return Math.round(n * UNITS[unit]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Human form of a duration, for the policy banner and the `/gate mode` reply. */
|
|
27
|
+
export function formatDurationMs(ms) {
|
|
28
|
+
const total = Math.max(0, Math.round(Number(ms) / 1000));
|
|
29
|
+
if (total >= 86400) {
|
|
30
|
+
const d = Math.floor(total / 86400);
|
|
31
|
+
const h = Math.floor((total % 86400) / 3600);
|
|
32
|
+
return h > 0 ? `${d}d${h}h` : `${d}d`;
|
|
33
|
+
}
|
|
34
|
+
if (total >= 3600) {
|
|
35
|
+
const h = Math.floor(total / 3600);
|
|
36
|
+
const m = Math.floor((total % 3600) / 60);
|
|
37
|
+
return m > 0 ? `${h}h${m}m` : `${h}h`;
|
|
38
|
+
}
|
|
39
|
+
if (total >= 60) return `${Math.floor(total / 60)}m`;
|
|
40
|
+
return `${Math.max(1, total)}s`;
|
|
41
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { version as toolVersion, which } from './exec.mjs';
|
|
4
|
+
import { c, log } from './log.mjs';
|
|
5
|
+
import { exists } from './fsx.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Engine discovery lives here so every command reports the same thing. It used
|
|
9
|
+
* to be duplicated: `gates` printed a hardcoded install hint even when both
|
|
10
|
+
* engines were present, while `doctor` used the real one.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export function resolveAislop(cwd) {
|
|
14
|
+
const local = path.join(cwd, 'node_modules', '.bin', 'aislop');
|
|
15
|
+
if (exists(local)) return local;
|
|
16
|
+
return which('aislop');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The aislop package root, found by walking up from the binary until a
|
|
21
|
+
* `tools/python` directory appears. Used to name the exact bundled binary when
|
|
22
|
+
* it cannot run: the failure is silent (empty stdout → JSON parse error), so a
|
|
23
|
+
* hint without a path is not actionable.
|
|
24
|
+
*/
|
|
25
|
+
export function resolveAislopPackageRoot(bin) {
|
|
26
|
+
if (!bin) return null;
|
|
27
|
+
let current;
|
|
28
|
+
try {
|
|
29
|
+
current = fs.realpathSync(bin);
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
for (let depth = 0; depth < 5; depth += 1) {
|
|
34
|
+
const parent = path.dirname(current);
|
|
35
|
+
if (!parent || parent === current) break;
|
|
36
|
+
current = parent;
|
|
37
|
+
if (exists(path.join(current, 'tools', 'python'))) return current;
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function pythonEnginePath(root) {
|
|
43
|
+
const exe = process.platform === 'win32' ? 'aislop-python.exe' : 'aislop-python';
|
|
44
|
+
return path.join(root, 'tools', 'python', `${process.platform}-${process.arch}`, exe);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* aislop bundles a Python engine binary (used for ruff). On an older glibc that
|
|
49
|
+
* binary cannot load, ruff prints nothing, and the failure surfaces only as a
|
|
50
|
+
* `ruff/engine-error` finding. `aislop doctor` still reports lint as ready, so
|
|
51
|
+
* the incompatibility is checked here and named before anyone runs a gate.
|
|
52
|
+
*/
|
|
53
|
+
export function aislopPythonEngine(aislopBin) {
|
|
54
|
+
const root = resolveAislopPackageRoot(aislopBin);
|
|
55
|
+
if (!root) return null;
|
|
56
|
+
const file = pythonEnginePath(root);
|
|
57
|
+
if (!exists(file)) return null;
|
|
58
|
+
|
|
59
|
+
const executable = process.platform === 'win32' ? true : (fs.statSync(file).mode & 0o111) !== 0;
|
|
60
|
+
const glibc = process.report?.getReport?.()?.header?.glibcVersionRuntime ?? null;
|
|
61
|
+
const parts = glibc ? String(glibc).split('.').map((n) => Number.parseInt(n, 10)) : null;
|
|
62
|
+
const needsNewerGlibc = Boolean(
|
|
63
|
+
process.platform === 'linux' && parts && (parts[0] < 2 || (parts[0] === 2 && parts[1] < 34)),
|
|
64
|
+
);
|
|
65
|
+
return { path: file, executable, glibc, needsNewerGlibc, broken: executable && needsNewerGlibc };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Turning an engine crash into an instruction. The bundled Python engine cannot
|
|
70
|
+
* load on an old glibc and says nothing about it, so the gate carries the
|
|
71
|
+
* diagnosis rather than echoing "unexpected end of JSON input".
|
|
72
|
+
*/
|
|
73
|
+
export function engineHint(rules, bin) {
|
|
74
|
+
const ruff = rules.some((rule) => String(rule).startsWith('ruff/'));
|
|
75
|
+
const root = resolveAislopPackageRoot(bin);
|
|
76
|
+
const bundled = root ? pythonEnginePath(root) : null;
|
|
77
|
+
if (ruff && bundled && exists(bundled)) {
|
|
78
|
+
return [
|
|
79
|
+
`aislop 自带的 Python 引擎跑不起来:${bundled}`,
|
|
80
|
+
'Linux 上 0.23.0 的这份二进制要求 GLIBC ≥ 2.34;老发行版(如 Ubuntu 20.04 / 2.31)会静默失败,ruff 输出为空 → JSON 解析错误。',
|
|
81
|
+
`处置:chmod a-x "${bundled}" # 去掉可执行位,aislop 回退到 PATH 上的 ruff`,
|
|
82
|
+
'然后确认 `which ruff` 有输出;仍失败就换到 CI 机器跑。',
|
|
83
|
+
].join('\n');
|
|
84
|
+
}
|
|
85
|
+
if (ruff) {
|
|
86
|
+
return 'ruff 引擎报错:先 `which ruff` 确认可执行,再 `aislop doctor` 看 lint 引擎;必要时在 .aislop/config.yml 里设 engines.lint: false 或换 CI 机器。';
|
|
87
|
+
}
|
|
88
|
+
return '先运行 `aislop doctor` 看哪个引擎失败,再决定禁用该引擎或补依赖。';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Engine installation hints must be copy-pasteable on the machine that prints
|
|
93
|
+
* them. Two traps found on 2026-11-28: the default pip index answered "no
|
|
94
|
+
* versions" for pipx and even for setuptools, and `pip install git+…` died in
|
|
95
|
+
* build isolation with a checkout error (exit 128). So when pipx is absent the
|
|
96
|
+
* hint is two steps — clone, then install from the checkout — with the index
|
|
97
|
+
* named explicitly.
|
|
98
|
+
*/
|
|
99
|
+
export function cbhInstallHint(hasPipx) {
|
|
100
|
+
const src = 'https://github.com/elementalsouls/Claude-BugHunter';
|
|
101
|
+
if (hasPipx) return `pipx install git+${src}`;
|
|
102
|
+
const win = process.platform === 'win32';
|
|
103
|
+
const dir = win ? '"$HOME\\.local\\src\\Claude-BugHunter"' : '~/.local/src/Claude-BugHunter';
|
|
104
|
+
const python = win ? 'python' : 'python3';
|
|
105
|
+
const clone = `git clone --depth 1 ${src} ${dir}`;
|
|
106
|
+
const install = `${python} -m pip install --user -i https://pypi.org/simple ${dir}`;
|
|
107
|
+
return win ? `${clone}; ${install}` : `${clone} && ${install}`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** A binary outside PATH still exists, but no other agent can invoke it. */
|
|
111
|
+
function onPath(bin) {
|
|
112
|
+
if (!bin) return false;
|
|
113
|
+
const dir = path.dirname(bin);
|
|
114
|
+
const entries = (process.env.PATH ?? '').split(path.delimiter).filter(Boolean);
|
|
115
|
+
const key = (p) => (process.platform === 'win32' ? path.resolve(p).toLowerCase() : path.resolve(p));
|
|
116
|
+
const wanted = key(dir);
|
|
117
|
+
return entries.some((entry) => {
|
|
118
|
+
try {
|
|
119
|
+
return key(entry) === wanted;
|
|
120
|
+
} catch {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function checkEngines(ctx) {
|
|
127
|
+
const aislopBin = resolveAislop(ctx.cwd);
|
|
128
|
+
const cbhBin = which('cbh');
|
|
129
|
+
const pipx = which('pipx');
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
aislop: {
|
|
133
|
+
bin: aislopBin,
|
|
134
|
+
version: aislopBin ? toolVersion(aislopBin) : null,
|
|
135
|
+
install: 'npm i -g aislop',
|
|
136
|
+
path: aislopBin ? path.dirname(aislopBin) : null,
|
|
137
|
+
onPath: onPath(aislopBin),
|
|
138
|
+
},
|
|
139
|
+
cbh: {
|
|
140
|
+
bin: cbhBin,
|
|
141
|
+
// cbh has no --version switch; say so instead of printing a blank.
|
|
142
|
+
version: cbhBin ? toolVersion(cbhBin, null) : null,
|
|
143
|
+
noVersionFlag: true,
|
|
144
|
+
install: cbhInstallHint(Boolean(pipx)),
|
|
145
|
+
packageManager: pipx ? 'pipx' : 'pip',
|
|
146
|
+
path: cbhBin ? path.dirname(cbhBin) : null,
|
|
147
|
+
onPath: onPath(cbhBin),
|
|
148
|
+
},
|
|
149
|
+
pythonEngine: aislopPythonEngine(aislopBin),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* A missing engine must always print the exact command that installs it, and an
|
|
155
|
+
* installed engine must never print an empty version cell (that reads as a
|
|
156
|
+
* broken parse).
|
|
157
|
+
*/
|
|
158
|
+
export function reportEngines(engines, { withPath = true } = {}) {
|
|
159
|
+
for (const [name, info] of Object.entries(engines)) {
|
|
160
|
+
// `pythonEngine` is a sub-probe of aislop, not an engine of its own; doctor
|
|
161
|
+
// prints its finding separately.
|
|
162
|
+
if (name === 'pythonEngine') continue;
|
|
163
|
+
if (!info.bin) {
|
|
164
|
+
log.warn(`${name} 未安装 → ${info.install}`);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const version = info.version ?? (info.noVersionFlag ? '(无版本开关)' : '(版本未知)');
|
|
168
|
+
const where = withPath ? ` ${c.dim(info.bin)}` : '';
|
|
169
|
+
const offPath = info.onPath === false ? ` ${c.yellow('(bin 目录不在 PATH:其他 agent 调不到)')}` : '';
|
|
170
|
+
log.ok(`${name} ${version}${where}${offPath}`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Only the engines that are actually absent, each with its own command. */
|
|
175
|
+
export function missingEngineHints(engines) {
|
|
176
|
+
return Object.entries(engines)
|
|
177
|
+
// `pythonEngine` is a sub-probe of aislop, not an engine: it has no `bin`
|
|
178
|
+
// and no `install`, and is null when aislop ships no bundled engine for
|
|
179
|
+
// this platform. Same exclusion as reportEngines().
|
|
180
|
+
.filter(([name, info]) => name !== 'pythonEngine' && !info?.bin)
|
|
181
|
+
.map(([name, info]) => ({ name, install: info.install }));
|
|
182
|
+
}
|
package/src/lib/exec.mjs
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
|
|
5
|
+
export function which(cmd) {
|
|
6
|
+
const dirs = (process.env.PATH ?? '').split(path.delimiter).filter(Boolean);
|
|
7
|
+
const exts = process.platform === 'win32' ? (process.env.PATHEXT ?? '.EXE;.CMD;.BAT').split(';') : [''];
|
|
8
|
+
for (const dir of dirs) {
|
|
9
|
+
for (const ext of exts) {
|
|
10
|
+
const candidate = path.join(dir, cmd + ext);
|
|
11
|
+
// statSync throws EACCES (not just ENOENT) on Windows' App Execution
|
|
12
|
+
// Aliases such as the Store stub python3.exe; throwIfNoEntry only covers
|
|
13
|
+
// ENOENT. An unreadable candidate is simply not a usable binary.
|
|
14
|
+
let stat;
|
|
15
|
+
try {
|
|
16
|
+
stat = fs.statSync(candidate, { throwIfNoEntry: false });
|
|
17
|
+
} catch {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (!stat?.isFile()) continue;
|
|
21
|
+
if (process.platform === 'win32' || (stat.mode & 0o111) !== 0) return candidate;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Node refuses to spawn `.cmd`/`.bat` directly (the CVE-2024-27980 fix returns
|
|
29
|
+
* EINVAL), and on Windows every npm global shim is a `.cmd`. `which('aislop')`
|
|
30
|
+
* therefore resolves to a file that can only run through cmd.exe — spawning it
|
|
31
|
+
* directly made the quality gate unrunnable on this platform (`exit=-1`).
|
|
32
|
+
*
|
|
33
|
+
* Each token is quoted on its own: a path with spaces must stay one argument,
|
|
34
|
+
* and cmd.exe strips the outer pair added here. Arguments containing `"` are
|
|
35
|
+
* rejected by the caller's contract (no ShipGate call passes one).
|
|
36
|
+
*/
|
|
37
|
+
function cmdShimInvocation(cmd, args) {
|
|
38
|
+
const quote = (value) => `"${String(value).replace(/"/g, '')}"`;
|
|
39
|
+
return [cmd, ...args].map(quote).join(' ');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function run(cmd, args = [], { timeout = 600_000, cwd, env } = {}) {
|
|
43
|
+
const options = {
|
|
44
|
+
encoding: 'utf8',
|
|
45
|
+
timeout,
|
|
46
|
+
cwd,
|
|
47
|
+
env: env ? { ...process.env, ...env } : process.env,
|
|
48
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
49
|
+
};
|
|
50
|
+
const isCmdShim = process.platform === 'win32' && /\.(cmd|bat)$/i.test(cmd);
|
|
51
|
+
// `windowsVerbatimArguments` is load-bearing: without it Node re-quotes the
|
|
52
|
+
// single command argument and cmd.exe then treats the whole string as the
|
|
53
|
+
// executable's name. This mirrors what `shell: true` does internally.
|
|
54
|
+
const result = isCmdShim
|
|
55
|
+
? spawnSync(process.env.ComSpec ?? 'cmd.exe', ['/d', '/s', '/c', `"${cmdShimInvocation(cmd, args)}"`], {
|
|
56
|
+
...options,
|
|
57
|
+
windowsVerbatimArguments: true,
|
|
58
|
+
})
|
|
59
|
+
: spawnSync(cmd, args, options);
|
|
60
|
+
return {
|
|
61
|
+
ok: result.status === 0,
|
|
62
|
+
code: result.status ?? -1,
|
|
63
|
+
stdout: result.stdout ?? '',
|
|
64
|
+
stderr: result.stderr ?? '',
|
|
65
|
+
error: result.error ?? null,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* `args = null` means "this tool has no version switch". cbh's argparse accepts
|
|
71
|
+
* only subcommands, so probing `--version` just prints a usage error — the
|
|
72
|
+
* caller then reports "no version flag" instead of an empty field that reads
|
|
73
|
+
* like a broken parse.
|
|
74
|
+
*/
|
|
75
|
+
export function version(cmd, args = ['--version']) {
|
|
76
|
+
if (!args) return null;
|
|
77
|
+
const r = run(cmd, args, { timeout: 20_000 });
|
|
78
|
+
if (!r.ok) return null;
|
|
79
|
+
return (r.stdout || r.stderr).trim().split('\n')[0] || null;
|
|
80
|
+
}
|