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,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain classifier: which set of gate checks applies to this session?
|
|
3
|
+
*
|
|
4
|
+
* WHY THIS EXISTS
|
|
5
|
+
*
|
|
6
|
+
* The gate shipped with one rule set — consult the graph, think before acting,
|
|
7
|
+
* do not defer work — and those rules are about writing code. A computational
|
|
8
|
+
* research session (dry lab / quant) has additional hard constraints that no
|
|
9
|
+
* existing check covers: write a Worklog before the first analysis run, make the
|
|
10
|
+
* script log to a file, leave a README in every result directory. Applying those
|
|
11
|
+
* to an ordinary repository would be pure false-positive noise, so the question
|
|
12
|
+
* "which domain is this?" has to be answered before "which checks run?".
|
|
13
|
+
*
|
|
14
|
+
* WHAT IT DELIBERATELY DOES NOT DO
|
|
15
|
+
*
|
|
16
|
+
* - It does not decide *whether* work may proceed. Only which check list
|
|
17
|
+
* applies. A wrong answer costs one extra (or one missing) rule set; it must
|
|
18
|
+
* never cost the session. Every failure path therefore degrades to
|
|
19
|
+
* `general-dev` — see `classify` below.
|
|
20
|
+
* - It does not read file CONTENT. Fingerprints are `stat` probes on file
|
|
21
|
+
* names only: research data can be unpublished sequence or patient material
|
|
22
|
+
* and must not end up in a log line, an `reason`, or a model prompt.
|
|
23
|
+
* - It does not call a model itself. T2 is injected as `modelHint`, so tests
|
|
24
|
+
* drive it with a fake and no deployment needs a provider key to be tested.
|
|
25
|
+
*
|
|
26
|
+
* THREE LEVELS, STRONGEST FIRST
|
|
27
|
+
*
|
|
28
|
+
* T0 fingerprint microseconds, `fs.exists` only confidence 0.95
|
|
29
|
+
* T1 keyword microseconds, regex over the prompt confidence 0.70
|
|
30
|
+
* T2 model one round trip, injected, optional confidence 0.50
|
|
31
|
+
* fallback free confidence 0
|
|
32
|
+
*
|
|
33
|
+
* The ordering is by evidence strength per unit of cost, not by cleverness: a
|
|
34
|
+
* directory that contains both `docs/STATE.md` and `docs/WORKLOG.md` is a
|
|
35
|
+
* structural fact that no phrasing can fake, while "什么是单细胞" is an ordinary
|
|
36
|
+
* question that merely mentions one keyword.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
import { join } from 'node:path';
|
|
40
|
+
|
|
41
|
+
/** The profile that adds no checks at all: base rules only. */
|
|
42
|
+
export const GENERAL_PROFILE = 'general-dev';
|
|
43
|
+
|
|
44
|
+
/** Names a classifier may return. Anything else is a profile-table bug. */
|
|
45
|
+
export const SOURCES = ['fingerprint', 'keyword', 'model', 'fallback'];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* How many DISTINCT strong keywords must appear before T1 is allowed to decide.
|
|
49
|
+
*
|
|
50
|
+
* One is not enough: "什么是单细胞测序" is a question, not a research session, and
|
|
51
|
+
* answering it must not switch on Worklog requirements. Two independent domain
|
|
52
|
+
* terms in the same opening request is a much better signal than one.
|
|
53
|
+
*/
|
|
54
|
+
const DEFAULT_MIN_HITS = 2;
|
|
55
|
+
|
|
56
|
+
/** Never let a caller pass a value that turns the threshold into "one word". */
|
|
57
|
+
const minHits = (keywords) => {
|
|
58
|
+
const raw = keywords?.min_hits;
|
|
59
|
+
return Number.isInteger(raw) && raw >= DEFAULT_MIN_HITS ? raw : DEFAULT_MIN_HITS;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const lower = (value) => (typeof value === 'string' ? value.toLowerCase() : '');
|
|
63
|
+
|
|
64
|
+
const asProfile = (policy) => policy?.profiles instanceof Map
|
|
65
|
+
? policy.profiles
|
|
66
|
+
: new Map(Object.entries(policy?.profiles ?? {}));
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* T0 — file-structure fingerprint.
|
|
70
|
+
*
|
|
71
|
+
* A fingerprint is a list of repository-relative paths that must ALL exist. The
|
|
72
|
+
* strongest matching fingerprint wins; a tie is broken by the profile order in
|
|
73
|
+
* `policy.profileOrder`, so the result is deterministic (a classifier that
|
|
74
|
+
* answers differently on two identical repositories cannot be debugged).
|
|
75
|
+
*
|
|
76
|
+
* @returns {{profile: string, reason: string}|null}
|
|
77
|
+
*/
|
|
78
|
+
export const fingerprintHit = ({ cwd, fs, profiles, order = [] }) => {
|
|
79
|
+
if (typeof cwd !== 'string' || cwd === '' || !fs?.exists) return null;
|
|
80
|
+
const names = order.length > 0 ? order : [...profiles.keys()];
|
|
81
|
+
let best = null;
|
|
82
|
+
for (const name of names) {
|
|
83
|
+
const profile = profiles.get(name);
|
|
84
|
+
const fingerprints = Array.isArray(profile?.fingerprints) ? profile.fingerprints : [];
|
|
85
|
+
for (const group of fingerprints) {
|
|
86
|
+
const paths = Array.isArray(group) ? group : [group];
|
|
87
|
+
if (paths.length === 0) continue;
|
|
88
|
+
const missing = paths.filter((rel) => !fs.exists(joinPath(cwd, rel)));
|
|
89
|
+
if (missing.length > 0) continue;
|
|
90
|
+
const score = paths.length;
|
|
91
|
+
if (!best || score > best.score) {
|
|
92
|
+
best = { profile: name, score, reason: `${name} 指纹命中:${paths.join(' + ')} 均存在` };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return best ? { profile: best.profile, reason: best.reason } : null;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* T1 — strong-keyword evidence from the opening request.
|
|
101
|
+
*
|
|
102
|
+
* Weak keywords are reported but never decide: they exist so the `reason` can
|
|
103
|
+
* say "saw 细胞 but only one domain term", which is what a human needs to
|
|
104
|
+
* understand why a research-looking session stayed on `general-dev`.
|
|
105
|
+
*
|
|
106
|
+
* @returns {{profile: string, reason: string}|null}
|
|
107
|
+
*/
|
|
108
|
+
export const keywordHit = ({ prompt, profiles, order = [] }) => {
|
|
109
|
+
const text = lower(prompt);
|
|
110
|
+
if (text === '') return null;
|
|
111
|
+
const names = order.length > 0 ? order : [...profiles.keys()];
|
|
112
|
+
let best = null;
|
|
113
|
+
for (const name of names) {
|
|
114
|
+
const keywords = profiles.get(name)?.keywords;
|
|
115
|
+
if (!keywords) continue;
|
|
116
|
+
const strong = (keywords.strong ?? []).filter((w) => w && text.includes(lower(w)));
|
|
117
|
+
const weak = (keywords.weak ?? []).filter((w) => w && text.includes(lower(w)));
|
|
118
|
+
if (strong.length < minHits(keywords)) continue;
|
|
119
|
+
if (!best || strong.length > best.score) {
|
|
120
|
+
best = {
|
|
121
|
+
profile: name,
|
|
122
|
+
score: strong.length,
|
|
123
|
+
reason:
|
|
124
|
+
`${name} 关键词命中 ${strong.length} 个强词(${strong.slice(0, 4).join(' / ')})` +
|
|
125
|
+
(weak.length > 0 ? `;弱词 ${weak.slice(0, 3).join(' / ')} 仅供参考` : ''),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return best ? { profile: best.profile, reason: best.reason } : null;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* T2 — an injected model judge.
|
|
134
|
+
*
|
|
135
|
+
* `modelHint(prompt, { profiles })` may answer `{ profile, reason }` or return a
|
|
136
|
+
* bare profile name. Its answer is VALIDATED against the profile table: a model
|
|
137
|
+
* that hallucinates `ai4s-foo` must not be able to switch on a rule set that
|
|
138
|
+
* does not exist. Any throw, rejection, non-answer or timeout degrades instead of
|
|
139
|
+
* propagating — the gate's failure direction is "fewer rules", never "blocked".
|
|
140
|
+
*
|
|
141
|
+
* @returns {Promise<{profile: string, reason: string}|null>}
|
|
142
|
+
*/
|
|
143
|
+
export const modelVerdict = async ({ prompt, modelHint, profiles, timeoutMs = 8000 }) => {
|
|
144
|
+
if (typeof modelHint !== 'function') return null;
|
|
145
|
+
const answer = await withTimeout(
|
|
146
|
+
Promise.resolve().then(() => modelHint(prompt, { profiles: [...profiles.keys()] })),
|
|
147
|
+
timeoutMs,
|
|
148
|
+
);
|
|
149
|
+
const name = typeof answer === 'string' ? answer : answer?.profile;
|
|
150
|
+
if (typeof name !== 'string' || name === '') return null;
|
|
151
|
+
if (name !== GENERAL_PROFILE && !profiles.has(name)) {
|
|
152
|
+
throw new Error(`model judge named an unknown profile: ${name}`);
|
|
153
|
+
}
|
|
154
|
+
const reason = typeof answer?.reason === 'string' && answer.reason !== ''
|
|
155
|
+
? answer.reason
|
|
156
|
+
: '模型判定命中';
|
|
157
|
+
return { profile: name, reason };
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/** Reject after `ms`, so a hung provider cannot hold a turn open. */
|
|
161
|
+
const withTimeout = (promise, ms) => {
|
|
162
|
+
if (!Number.isFinite(ms) || ms <= 0) return promise;
|
|
163
|
+
let timer = null;
|
|
164
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
165
|
+
timer = setTimeout(() => reject(new Error(`model judge timed out after ${ms}ms`)), ms);
|
|
166
|
+
// Deliberately NOT unref'd.
|
|
167
|
+
//
|
|
168
|
+
// A deadline timer is the ONLY thing that can settle this race when the
|
|
169
|
+
// judge hangs. Unref'ing it lets the event loop drain while the race is
|
|
170
|
+
// still pending, and Node then aborts the run with "Promise resolution is
|
|
171
|
+
// still pending but the event loop has already resolved" — measured on
|
|
172
|
+
// node 20/22, where it cancels every remaining test in the file. It is also
|
|
173
|
+
// the correct production behaviour: our caller is awaiting us, so the
|
|
174
|
+
// process has to stay alive until the deadline fires.
|
|
175
|
+
});
|
|
176
|
+
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const joinPath = (cwd, rel) => join(cwd, String(rel));
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Classify the session.
|
|
183
|
+
*
|
|
184
|
+
* @param {object} args
|
|
185
|
+
* @param {string} [args.cwd] session working directory (primary repo root)
|
|
186
|
+
* @param {string} [args.prompt] the user's opening request for this turn
|
|
187
|
+
* @param {{exists:(p:string)=>boolean}} [args.fs] filesystem probe; `stat` only
|
|
188
|
+
* @param {object} [args.policy] normalized policy (profiles / defaultProfile / classifier)
|
|
189
|
+
* @param {Function} [args.modelHint] optional T2 judge, `(prompt, ctx) => profile|{profile,reason}`
|
|
190
|
+
* @returns {Promise<{profile:string, source:string, reason:string, confidence:number}>}
|
|
191
|
+
*/
|
|
192
|
+
export const classify = async ({ cwd = '', prompt = '', fs = null, policy = {}, modelHint = null } = {}) => {
|
|
193
|
+
const config = policy?.classifier ?? {};
|
|
194
|
+
const profiles = asProfile(policy);
|
|
195
|
+
const order = Array.isArray(policy?.profileOrder) ? policy.profileOrder : [...profiles.keys()];
|
|
196
|
+
const fallbackProfile = typeof policy?.defaultProfile === 'string' && policy.defaultProfile !== ''
|
|
197
|
+
? policy.defaultProfile
|
|
198
|
+
: GENERAL_PROFILE;
|
|
199
|
+
const degraded = (reason) => ({
|
|
200
|
+
profile: fallbackProfile,
|
|
201
|
+
source: 'fallback',
|
|
202
|
+
reason,
|
|
203
|
+
confidence: 0,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
if (config.enabled === false) return degraded('classifier 已禁用(classifier.enabled=false)');
|
|
207
|
+
if (profiles.size === 0) return degraded('profile 表为空:只跑基础检查');
|
|
208
|
+
|
|
209
|
+
// T0. Its own try/catch: a filesystem hiccup must skip one level, not the run.
|
|
210
|
+
try {
|
|
211
|
+
const hit = fingerprintHit({ cwd, fs, profiles, order });
|
|
212
|
+
if (hit) return { ...hit, source: 'fingerprint', confidence: 0.95 };
|
|
213
|
+
} catch (err) {
|
|
214
|
+
// fall through to T1 — see §fail-open in the ADR
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// T1.
|
|
218
|
+
try {
|
|
219
|
+
const hit = keywordHit({ prompt, profiles, order });
|
|
220
|
+
if (hit) return { ...hit, source: 'keyword', confidence: 0.7 };
|
|
221
|
+
} catch (err) {
|
|
222
|
+
// fall through to T2
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// T2. Everything about it is optional, so "no judge configured" is normal and
|
|
226
|
+
// reports itself as a fallback rather than as an error.
|
|
227
|
+
if (config.model_judge === true && typeof modelHint === 'function') {
|
|
228
|
+
try {
|
|
229
|
+
const hit = await modelVerdict({
|
|
230
|
+
prompt,
|
|
231
|
+
modelHint,
|
|
232
|
+
profiles,
|
|
233
|
+
timeoutMs: config.timeout_ms,
|
|
234
|
+
});
|
|
235
|
+
if (hit) return { ...hit, source: 'model', confidence: 0.5 };
|
|
236
|
+
return degraded('模型判定未给出结论:降级为 general-dev');
|
|
237
|
+
} catch (err) {
|
|
238
|
+
return degraded(`模型判定失败(${err?.message ?? err}):降级为 general-dev`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return degraded(
|
|
243
|
+
`无指纹、强关键词不足(需 ≥${DEFAULT_MIN_HITS} 个):降级为 ${fallbackProfile}`,
|
|
244
|
+
);
|
|
245
|
+
};
|