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,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,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
|
+
}
|
package/src/lib/fsx.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
|
|
5
|
+
export function exists(p) {
|
|
6
|
+
return fs.existsSync(p);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function readText(p) {
|
|
10
|
+
return fs.readFileSync(p, 'utf8');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function readIfExists(p) {
|
|
14
|
+
return exists(p) ? readText(p) : null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function ensureDir(p) {
|
|
18
|
+
fs.mkdirSync(p, { recursive: true });
|
|
19
|
+
return p;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function writeText(p, text) {
|
|
23
|
+
ensureDir(path.dirname(p));
|
|
24
|
+
fs.writeFileSync(p, text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Symlink and junction detection. On Windows a directory junction reports
|
|
29
|
+
* isSymbolicLink() === true, which is what we want: `~/.agents/skills` is a
|
|
30
|
+
* link either way and writing through it must be recognised, not treated as a
|
|
31
|
+
* plain directory.
|
|
32
|
+
*/
|
|
33
|
+
export function isSymlink(p) {
|
|
34
|
+
try {
|
|
35
|
+
return fs.lstatSync(p).isSymbolicLink();
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function realpathOrNull(p) {
|
|
42
|
+
try {
|
|
43
|
+
return fs.realpathSync(p);
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function listDir(p) {
|
|
50
|
+
if (!exists(p)) return [];
|
|
51
|
+
return fs.readdirSync(p, { withFileTypes: true });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function hashText(text) {
|
|
55
|
+
return crypto.createHash('sha256').update(text).digest('hex').slice(0, 16);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function hashFile(p) {
|
|
59
|
+
return hashText(fs.readFileSync(p));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function copyTree(src, dest, { skip = [] } = {}) {
|
|
63
|
+
const written = [];
|
|
64
|
+
ensureDir(dest);
|
|
65
|
+
for (const entry of listDir(src)) {
|
|
66
|
+
if (skip.includes(entry.name)) continue;
|
|
67
|
+
const from = path.join(src, entry.name);
|
|
68
|
+
const to = path.join(dest, entry.name);
|
|
69
|
+
if (entry.isDirectory()) {
|
|
70
|
+
written.push(...copyTree(from, to, { skip }));
|
|
71
|
+
} else if (entry.isFile()) {
|
|
72
|
+
fs.copyFileSync(from, to);
|
|
73
|
+
written.push(to);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return written;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function removeDir(p) {
|
|
80
|
+
fs.rmSync(p, { recursive: true, force: true });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function today() {
|
|
84
|
+
return new Date().toISOString().slice(0, 10);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* One backup per file per day. Backups of user-authored entry docs are the only
|
|
89
|
+
* safety net for inject/revoke, so the name is deterministic: <file>.shipgate-bak.<YYYYMMDD>
|
|
90
|
+
*/
|
|
91
|
+
export function backupOnce(file) {
|
|
92
|
+
if (!exists(file)) return null;
|
|
93
|
+
const target = `${file}.shipgate-bak.${today()}`;
|
|
94
|
+
if (exists(target)) return target;
|
|
95
|
+
fs.copyFileSync(file, target);
|
|
96
|
+
return target;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function backupList(file) {
|
|
100
|
+
const dir = path.dirname(file);
|
|
101
|
+
const base = path.basename(file) + '.shipgate-bak.';
|
|
102
|
+
return listDir(dir)
|
|
103
|
+
.filter((e) => e.isFile() && e.name.startsWith(base))
|
|
104
|
+
.map((e) => path.join(dir, e.name))
|
|
105
|
+
.sort();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function latestBackup(file) {
|
|
109
|
+
return backupList(file).at(-1) ?? null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The oldest backup is the only one taken before ShipGate ever wrote to the
|
|
114
|
+
* file. `revoke` must use it: restoring the latest would put back an older
|
|
115
|
+
* injected block instead of the user's original document.
|
|
116
|
+
*/
|
|
117
|
+
export function earliestBackup(file) {
|
|
118
|
+
return backupList(file)[0] ?? null;
|
|
119
|
+
}
|