@sloppy-ai/cli 1.1.0 → 1.4.0

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.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `sloppy assets`: keep photography honest. Photos go in a manifest (sloppy.assets.json)
3
+ * with a source, licence and credit. Placeholder hosts are refused at entry time, and
4
+ * `check` reports any image in source that is a placeholder, unlicensed or missing.
5
+ */
6
+ import { type AssetFinding, type AssetManifestEntry } from '@sloppy-ai/core';
7
+ export declare const MANIFEST_FILE = "sloppy.assets.json";
8
+ export declare function readManifest(cwd: string): {
9
+ entries: AssetManifestEntry[];
10
+ error?: string;
11
+ };
12
+ export declare function initManifest(cwd: string): 'created' | 'exists';
13
+ /** Adds one photo. Refuses placeholders and any entry without a licence and credit. */
14
+ export declare function addAsset(cwd: string, entry: {
15
+ url: string;
16
+ source?: string;
17
+ license?: string;
18
+ credit?: string;
19
+ }): {
20
+ ok: true;
21
+ } | {
22
+ ok: false;
23
+ reason: string;
24
+ };
25
+ /** Resolves an image reference against the filesystem: `/x.png` is under public/ or the root. */
26
+ export declare function localExistsFor(cwd: string, file: string): (url: string) => boolean;
27
+ export interface AssetCheckResult {
28
+ findings: AssetFinding[];
29
+ files: number;
30
+ manifestEntries: number;
31
+ }
32
+ export declare function checkAssets(files: string[], cwd: string): AssetCheckResult;
33
+ //# sourceMappingURL=assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACxB,MAAM,iBAAiB,CAAC;AAGzB,eAAO,MAAM,aAAa,uBAAuB,CAAC;AAclD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAK3F;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,QAAQ,CAK9D;AAED,uFAAuF;AACvF,wBAAgB,QAAQ,CACtB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACzE;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAa9C;AAED,iGAAiG;AACjG,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAQlF;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAa1E"}
package/dist/assets.js ADDED
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `sloppy assets`: keep photography honest. Photos go in a manifest (sloppy.assets.json)
3
+ * with a source, licence and credit. Placeholder hosts are refused at entry time, and
4
+ * `check` reports any image in source that is a placeholder, unlicensed or missing.
5
+ */
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import { PHOTO_HOSTS, PLACEHOLDER_HOSTS, checkAssetManifest, scanAssets } from '@sloppy-ai/core';
9
+ import { readJsonFile, writeJsonFile } from './gate-core.js';
10
+ export const MANIFEST_FILE = 'sloppy.assets.json';
11
+ function hostOf(url) {
12
+ try {
13
+ return new URL(url).hostname.toLowerCase();
14
+ }
15
+ catch {
16
+ return null;
17
+ }
18
+ }
19
+ function hostIn(host, list) {
20
+ return list.some(candidate => host === candidate || host.endsWith(`.${candidate}`));
21
+ }
22
+ export function readManifest(cwd) {
23
+ const read = readJsonFile(path.join(cwd, MANIFEST_FILE));
24
+ if (read.error)
25
+ return { entries: [], error: read.error };
26
+ if (read.value !== undefined && !Array.isArray(read.value))
27
+ return { entries: [], error: `${MANIFEST_FILE} must be a JSON array.` };
28
+ return { entries: read.value ?? [] };
29
+ }
30
+ export function initManifest(cwd) {
31
+ const file = path.join(cwd, MANIFEST_FILE);
32
+ if (fs.existsSync(file))
33
+ return 'exists';
34
+ writeJsonFile(file, []);
35
+ return 'created';
36
+ }
37
+ /** Adds one photo. Refuses placeholders and any entry without a licence and credit. */
38
+ export function addAsset(cwd, entry) {
39
+ const host = hostOf(entry.url);
40
+ if (!host)
41
+ return { ok: false, reason: 'The URL is not valid. Use the full https:// address of the photo.' };
42
+ if (hostIn(host, PLACEHOLDER_HOSTS))
43
+ return { ok: false, reason: `${host} serves placeholder images. Use a real photograph.` };
44
+ if (!entry.license?.trim())
45
+ return { ok: false, reason: 'A licence is required, for example "Unsplash License".' };
46
+ if (!entry.credit?.trim())
47
+ return { ok: false, reason: 'A credit line is required.' };
48
+ const { entries, error } = readManifest(cwd);
49
+ if (error)
50
+ return { ok: false, reason: error };
51
+ if (entries.some(e => e.url === entry.url))
52
+ return { ok: false, reason: 'That URL is already in the manifest.' };
53
+ const photoHost = hostIn(host, PHOTO_HOSTS);
54
+ const next = [...entries, { ...entry, source: entry.source ?? (photoHost ? host : undefined) }];
55
+ writeJsonFile(path.join(cwd, MANIFEST_FILE), next);
56
+ return { ok: true };
57
+ }
58
+ /** Resolves an image reference against the filesystem: `/x.png` is under public/ or the root. */
59
+ export function localExistsFor(cwd, file) {
60
+ return (url) => {
61
+ const clean = url.split(/[?#]/)[0];
62
+ const candidates = clean.startsWith('/')
63
+ ? [path.join(cwd, 'public', clean), path.join(cwd, clean)]
64
+ : [path.resolve(path.dirname(file), clean)];
65
+ return candidates.some(candidate => fs.existsSync(candidate));
66
+ };
67
+ }
68
+ export function checkAssets(files, cwd) {
69
+ const { entries, error } = readManifest(cwd);
70
+ const findings = [];
71
+ if (error) {
72
+ findings.push({ id: 'GATE-ASSET-MISSING', severity: 'high', file: MANIFEST_FILE, line: 1, message: error, recommendation: 'Fix the manifest JSON or delete it and run `sloppy assets init`.' });
73
+ }
74
+ findings.push(...checkAssetManifest(entries, MANIFEST_FILE));
75
+ for (const file of files) {
76
+ const text = fs.readFileSync(file, 'utf8');
77
+ const display = path.relative(cwd, file) || file;
78
+ findings.push(...scanAssets(display, text, { manifest: entries, localExists: localExistsFor(cwd, file) }));
79
+ }
80
+ return { findings, files: files.length, manifestEntries: entries.length };
81
+ }
82
+ //# sourceMappingURL=assets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assets.js","sourceRoot":"","sources":["../src/assets.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EAGX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE7D,MAAM,CAAC,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAElD,SAAS,MAAM,CAAC,GAAW;IACzB,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;IAC7C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,IAAY,EAAE,IAAc;IAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,SAAS,EAA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CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7G,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `sloppy brief`: classify a project brief into a site kind before any design work.
3
+ * The kind decides which effects are allowed and whether photography leads the hero.
4
+ * With --write the result is saved to .sloppy/brief.json, where the finish gate reads it.
5
+ */
6
+ import { type KindClassification } from '@sloppy-ai/core';
7
+ export declare const BRIEF_FILE = ".sloppy/brief.json";
8
+ export interface BriefRecord extends KindClassification {
9
+ brief: string;
10
+ classifiedAt: string;
11
+ }
12
+ export declare function runBrief(text: string, options: {
13
+ write: boolean;
14
+ cwd?: string;
15
+ now?: string;
16
+ }): BriefRecord;
17
+ export declare function describeBrief(record: BriefRecord): string[];
18
+ //# sourceMappingURL=brief.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brief.d.ts","sourceRoot":"","sources":["../src/brief.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAEzE,eAAO,MAAM,UAAU,uBAAuB,CAAC;AAE/C,MAAM,WAAW,WAAY,SAAQ,kBAAkB;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,CAa3G;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,EAAE,CAS3D"}
package/dist/brief.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * `sloppy brief`: classify a project brief into a site kind before any design work.
3
+ * The kind decides which effects are allowed and whether photography leads the hero.
4
+ * With --write the result is saved to .sloppy/brief.json, where the finish gate reads it.
5
+ */
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ import { classifyBrief } from '@sloppy-ai/core';
9
+ export const BRIEF_FILE = '.sloppy/brief.json';
10
+ export function runBrief(text, options) {
11
+ const classification = classifyBrief(text);
12
+ const record = {
13
+ ...classification,
14
+ brief: text,
15
+ classifiedAt: options.now ?? new Date().toISOString()
16
+ };
17
+ if (options.write) {
18
+ const file = path.join(options.cwd ?? process.cwd(), BRIEF_FILE);
19
+ fs.mkdirSync(path.dirname(file), { recursive: true });
20
+ fs.writeFileSync(file, `${JSON.stringify(record, null, 2)}\n`);
21
+ }
22
+ return record;
23
+ }
24
+ export function describeBrief(record) {
25
+ const { policy } = record;
26
+ return [
27
+ `Kind: ${record.kind} (${record.confidence} confidence)`,
28
+ `Matched: ${record.matched.length ? record.matched.join(', ') : 'no keywords; defaulted to software'}`,
29
+ `Effects: ${policy.effectsAllowed ? 'WebGL, shaders and 3D allowed' : 'no WebGL, shaders or 3D scenes'}`,
30
+ `Hero: ${policy.photoFirst ? 'real photography leads' : 'product UI or type leads'}`,
31
+ `Theme: ${policy.themeBias === 'either' ? 'light or dark' : policy.themeBias}`
32
+ ];
33
+ }
34
+ //# sourceMappingURL=brief.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"brief.js","sourceRoot":"","sources":["../src/brief.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAA2B,MAAM,iBAAiB,CAAC;AAEzE,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAC;AAO/C,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,OAAuD;IAC5F,MAAM,cAAc,GAAG,aAAa,CAAC,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F,CAAC;AACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ /** Summarize blinded visual preferences and explicitly labeled detector cases. */
2
+ export declare function summarizeEvaluation(raw: unknown): {
3
+ pairs: {
4
+ sloppyShareOfNonTies: number | null;
5
+ sloppy: number;
6
+ baseline: number;
7
+ tie: number;
8
+ total: number;
9
+ };
10
+ rules: Record<string, {
11
+ tp: number;
12
+ fp: number;
13
+ tn: number;
14
+ fn: number;
15
+ precision: number | null;
16
+ recall: number | null;
17
+ }>;
18
+ note: string;
19
+ };
20
+ //# sourceMappingURL=evaluate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../src/evaluate.ts"],"names":[],"mappings":"AAOA,kFAAkF;AAClF,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO;;;;;;;;;YAiBV,MAAM;YAAM,MAAM;YAAM,MAAM;YAAM,MAAM;mBAAa,MAAM,GAAG,IAAI;gBAAU,MAAM,GAAG,IAAI;;;EAsBhI"}
@@ -0,0 +1,50 @@
1
+ function ratio(numerator, denominator) {
2
+ return denominator ? Number((numerator / denominator).toFixed(4)) : null;
3
+ }
4
+ /** Summarize blinded visual preferences and explicitly labeled detector cases. */
5
+ export function summarizeEvaluation(raw) {
6
+ if (!raw || typeof raw !== 'object')
7
+ throw new Error('Evaluation input must be a JSON object.');
8
+ const data = raw;
9
+ const pairs = data.pairs ?? [];
10
+ const rules = data.rules ?? [];
11
+ if (!Array.isArray(pairs) || !Array.isArray(rules))
12
+ throw new Error('"pairs" and "rules" must be arrays.');
13
+ const preference = { sloppy: 0, baseline: 0, tie: 0 };
14
+ for (const [index, item] of pairs.entries()) {
15
+ const pair = item;
16
+ if (!pair.id || !pair.pageType || !['A', 'B', 'tie'].includes(pair.picked || '') || !['sloppy', 'baseline'].includes(pair.A || '') || !['sloppy', 'baseline'].includes(pair.B || '') || pair.A === pair.B) {
17
+ throw new Error(`Pair #${index + 1} needs id, pageType, picked A/B/tie, and one baseline plus one sloppy condition.`);
18
+ }
19
+ const pickedCondition = pair.picked === 'tie' ? 'tie' : pair[pair.picked];
20
+ preference[pickedCondition] += 1;
21
+ }
22
+ const perRule = {};
23
+ for (const [index, item] of rules.entries()) {
24
+ const row = item;
25
+ if (typeof row.rule !== 'string' || !row.rule || !Array.isArray(row.cases))
26
+ throw new Error(`Rule set #${index + 1} needs a rule ID and cases array.`);
27
+ const counts = { tp: 0, fp: 0, tn: 0, fn: 0 };
28
+ for (const [caseIndex, rawCase] of row.cases.entries()) {
29
+ const testCase = rawCase;
30
+ if (typeof testCase.expected !== 'boolean' || typeof testCase.actual !== 'boolean')
31
+ throw new Error(`${row.rule} case #${caseIndex + 1} needs boolean expected and actual labels.`);
32
+ if (testCase.expected && testCase.actual)
33
+ counts.tp += 1;
34
+ else if (!testCase.expected && testCase.actual)
35
+ counts.fp += 1;
36
+ else if (!testCase.expected && !testCase.actual)
37
+ counts.tn += 1;
38
+ else
39
+ counts.fn += 1;
40
+ }
41
+ perRule[row.rule] = { ...counts, precision: ratio(counts.tp, counts.tp + counts.fp), recall: ratio(counts.tp, counts.tp + counts.fn) };
42
+ }
43
+ const nonTies = preference.sloppy + preference.baseline;
44
+ return {
45
+ pairs: { total: pairs.length, ...preference, sloppyShareOfNonTies: ratio(preference.sloppy, nonTies) },
46
+ rules: perRule,
47
+ note: 'Preference is not a usability or quality score. Detector precision and recall cover only the labeled cases supplied.'
48
+ };
49
+ }
50
+ //# sourceMappingURL=evaluate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../src/evaluate.ts"],"names":[],"mappings":"AAGA,SAAS,KAAK,CAAC,SAAiB,EAAE,WAAmB;IACnD,OAAO,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,GAAG,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3E,CAAC;AAED,kFAAkF;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AI,CAAC,CAAC;iBAC1D,IAAI,CAAC,QAAQ,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,MAAM;gBAAE,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;;gBAC3D,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;QACtB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;IACzI,CAAC;IAED,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC;IACxD,OAAO;QACL,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,UAAU,EAAE,oBAAoB,EAAE,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;QACtG,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,sHAAsH;KAC7H,CAAC;AACJ,CAAC"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Pure finish-gate logic: waivers, thresholds, round accounting, hook output and the
3
+ * Claude Code Stop hook installer. The CLI gathers findings and calls these functions,
4
+ * so the rules can be tested without a browser.
5
+ */
6
+ export declare const SEVERITIES: readonly ["low", "medium", "high", "critical"];
7
+ export type Severity = (typeof SEVERITIES)[number];
8
+ export type FailOn = Severity | 'none';
9
+ export declare const GATE_EXIT: {
10
+ readonly PASS: 0;
11
+ readonly FAIL: 1;
12
+ readonly SETUP: 3;
13
+ };
14
+ export declare const MAX_WAIVERS = 5;
15
+ export declare const MIN_WAIVER_REASON = 12;
16
+ export declare const DEFAULT_MAX_ROUNDS = 3;
17
+ export declare const HOOK_COMMAND = "sloppy gate --hook";
18
+ export interface GateFinding {
19
+ id: string;
20
+ severity: Severity;
21
+ file?: string;
22
+ line?: number;
23
+ message: string;
24
+ recommendation?: string;
25
+ /** Guards and gate integrity problems. These always block: no threshold, no waiver. */
26
+ unwaivable?: boolean;
27
+ }
28
+ export interface Waiver {
29
+ rule: string;
30
+ file?: string;
31
+ reason: string;
32
+ }
33
+ export interface GateConfig {
34
+ maxRounds: number;
35
+ failOn: FailOn;
36
+ /** Path prefixes the agent must not edit during a build (vendored kits, shared assets). */
37
+ protect: string[];
38
+ }
39
+ export interface GateState {
40
+ round: number;
41
+ status: 'pass' | 'fail' | 'open' | 'setup';
42
+ updatedAt?: string;
43
+ }
44
+ export declare const DEFAULT_CONFIG: GateConfig;
45
+ export declare function isSeverity(value: unknown): value is Severity;
46
+ export declare function parseConfig(raw: unknown): {
47
+ config: GateConfig;
48
+ problems: string[];
49
+ };
50
+ /**
51
+ * Validates waivers. A malformed entry or an oversized list becomes an unwaivable finding,
52
+ * so a broken waiver file cannot quietly relax the gate.
53
+ */
54
+ export declare function validateWaivers(raw: unknown): {
55
+ waivers: Waiver[];
56
+ problems: GateFinding[];
57
+ };
58
+ export declare function meetsThreshold(severity: Severity, failOn: FailOn): boolean;
59
+ /** A waiver file matches a finding on exact path or a trailing path segment, never a substring. */
60
+ export declare function fileMatches(findingFile: string | undefined, waiverFile: string | undefined): boolean;
61
+ export interface AppliedGate {
62
+ blocking: GateFinding[];
63
+ waived: Array<{
64
+ finding: GateFinding;
65
+ waiver: Waiver;
66
+ }>;
67
+ }
68
+ /** Splits findings into blocking and waived. Unwaivable findings always block. */
69
+ export declare function applyWaivers(findings: GateFinding[], waivers: Waiver[], failOn: FailOn): AppliedGate;
70
+ export type Outcome = 'pass' | 'fail' | 'setup';
71
+ export interface Advance {
72
+ state: GateState;
73
+ /** Hook mode: true means block the turn from ending. */
74
+ block: boolean;
75
+ exit: number;
76
+ label: 'PASS' | 'FAIL' | 'OPEN' | 'SETUP';
77
+ }
78
+ /**
79
+ * Advances the round counter. Only hook runs count rounds, because a hook run is a
80
+ * Stop attempt the agent could be made to repeat. A manual run reports without counting.
81
+ * After maxRounds failing hook runs the gate stops blocking and reports OPEN, so the
82
+ * user decides rather than the agent looping forever.
83
+ */
84
+ export declare function advance(state: GateState, outcome: Outcome, opts: {
85
+ hook: boolean;
86
+ maxRounds: number;
87
+ now?: string;
88
+ }): Advance;
89
+ export declare function summarize(blocking: GateFinding[], limit?: number): string;
90
+ /** Hook output for a Stop hook. null lets the turn end. */
91
+ export declare function hookOutput(advanced: Advance, reason: string): string | null;
92
+ /** Changed files that fall under a protected prefix. Any hit is an unwaivable finding. */
93
+ export declare function kitEditFindings(changed: string[], protect: string[]): GateFinding[];
94
+ export declare function readJsonFile<T>(file: string): {
95
+ value: T | undefined;
96
+ error?: string;
97
+ };
98
+ export declare function writeJsonFile(file: string, value: unknown): void;
99
+ /**
100
+ * Adds the gate's Stop hook to a Claude Code settings file, keeping every other hook.
101
+ * Throws instead of overwriting a settings file it cannot parse. Idempotent.
102
+ */
103
+ export declare function installStopHook(settingsFile: string, command?: string): 'installed' | 'exists';
104
+ //# sourceMappingURL=gate-core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gate-core.d.ts","sourceRoot":"","sources":["../src/gate-core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,eAAO,MAAM,UAAU,gDAAiD,CAAC;AACzE,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEvC,eAAO,MAAM,SAAS;;;;CAA0C,CAAC;AAEjE,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,YAAY,uBAAuB,CAAC;AAEjD,MAAM,WAAW,W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IAAI,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAOtF;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAGhE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,SAAe,GAAG,WAAW,GAAG,QAAQ,CAkBpG"}
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Pure finish-gate logic: waivers, thresholds, round accounting, hook output and the
3
+ * Claude Code Stop hook installer. The CLI gathers findings and calls these functions,
4
+ * so the rules can be tested without a browser.
5
+ */
6
+ import fs from 'node:fs';
7
+ import path from 'node:path';
8
+ export const SEVERITIES = ['low', 'medium', 'high', 'critical'];
9
+ export const GATE_EXIT = { PASS: 0, FAIL: 1, SETUP: 3 };
10
+ export const MAX_WAIVERS = 5;
11
+ export const MIN_WAIVER_REASON = 12;
12
+ export const DEFAULT_MAX_ROUNDS = 3;
13
+ export const HOOK_COMMAND = 'sloppy gate --hook';
14
+ export const DEFAULT_CONFIG = { maxRounds: DEFAULT_MAX_ROUNDS, failOn: 'high', protect: [] };
15
+ export function isSeverity(value) {
16
+ return typeof value === 'string' && SEVERITIES.includes(value);
17
+ }
18
+ export function parseConfig(raw) {
19
+ const problems = [];
20
+ const config = { ...DEFAULT_CONFIG, protect: [] };
21
+ if (!raw || typeof raw !== 'object')
22
+ return { config, problems };
23
+ const data = raw;
24
+ if (data.maxRounds !== undefined) {
25
+ const value = Number(data.maxRounds);
26
+ if (Number.isInteger(value) && value >= 1 && value <= 10)
27
+ config.maxRounds = value;
28
+ else
29
+ problems.push('maxRounds must be an integer from 1 to 10');
30
+ }
31
+ if (data.failOn !== undefined) {
32
+ if (data.failOn === 'none' || isSeverity(data.failOn))
33
+ config.failOn = data.failOn;
34
+ else
35
+ problems.push('failOn must be none, low, medium, high or critical');
36
+ }
37
+ if (data.protect !== undefined) {
38
+ if (Array.isArray(data.protect) && data.protect.every(p => typeof p === 'string'))
39
+ config.protect = data.protect;
40
+ else
41
+ problems.push('protect must be an array of path prefixes');
42
+ }
43
+ return { config, problems };
44
+ }
45
+ /**
46
+ * Validates waivers. A malformed entry or an oversized list becomes an unwaivable finding,
47
+ * so a broken waiver file cannot quietly relax the gate.
48
+ */
49
+ export function validateWaivers(raw) {
50
+ const problems = [];
51
+ const waivers = [];
52
+ if (raw === undefined || raw === null)
53
+ return { waivers, problems };
54
+ if (!Array.isArray(raw)) {
55
+ problems.push({
56
+ id: 'GATE-WAIVER-INVALID',
57
+ severity: 'high',
58
+ file: '.sloppy/waivers.json',
59
+ message: 'Waiver file must be a JSON array.',
60
+ unwaivable: true
61
+ });
62
+ return { waivers, problems };
63
+ }
64
+ raw.forEach((entry, index) => {
65
+ const item = (entry && typeof entry === 'object' ? entry : {});
66
+ const rule = typeof item.rule === 'string' ? item.rule.trim() : '';
67
+ const reason = typeof item.reason === 'string' ? item.reason.trim() : '';
68
+ if (!rule || reason.length < MIN_WAIVER_REASON) {
69
+ problems.push({
70
+ id: 'GATE-WAIVER-INVALID',
71
+ severity: 'high',
72
+ file: '.sloppy/waivers.json',
73
+ message: `Waiver #${index + 1} needs a rule and a reason of at least ${MIN_WAIVER_REASON} characters.`,
74
+ recommendation: 'Say why the finding is acceptable here, or remove the waiver.',
75
+ unwaivable: true
76
+ });
77
+ return;
78
+ }
79
+ waivers.push({ rule, file: typeof item.file === 'string' ? item.file : undefined, reason });
80
+ });
81
+ if (raw.length > MAX_WAIVERS) {
82
+ problems.push({
83
+ id: 'GATE-WAIVER-LIMIT',
84
+ severity: 'high',
85
+ file: '.sloppy/waivers.json',
86
+ message: `${raw.length} waivers recorded; the limit is ${MAX_WAIVERS}.`,
87
+ recommendation: 'Fix the findings instead of waiving them.',
88
+ unwaivable: true
89
+ });
90
+ }
91
+ return { waivers, problems };
92
+ }
93
+ export function meetsThreshold(severity, failOn) {
94
+ if (failOn === 'none')
95
+ return false;
96
+ return SEVERITIES.indexOf(severity) >= SEVERITIES.indexOf(failOn);
97
+ }
98
+ /** A waiver file matches a finding on exact path or a trailing path segment, never a substring. */
99
+ export function fileMatches(findingFile, waiverFile) {
100
+ if (!waiverFile)
101
+ return true;
102
+ if (!findingFile)
103
+ return false;
104
+ return findingFile === waiverFile || findingFile.endsWith(`/${waiverFile}`);
105
+ }
106
+ /** Splits findings into blocking and waived. Unwaivable findings always block. */
107
+ export function applyWaivers(findings, waivers, failOn) {
108
+ const blocking = [];
109
+ const waived = [];
110
+ for (const finding of findings) {
111
+ if (finding.unwaivable) {
112
+ blocking.push(finding);
113
+ continue;
114
+ }
115
+ if (!meetsThreshold(finding.severity, failOn))
116
+ continue;
117
+ const waiver = waivers.find(w => w.rule === finding.id && fileMatches(finding.file, w.file));
118
+ if (waiver)
119
+ waived.push({ finding, waiver });
120
+ else
121
+ blocking.push(finding);
122
+ }
123
+ return { blocking, waived };
124
+ }
125
+ /**
126
+ * Advances the round counter. Only hook runs count rounds, because a hook run is a
127
+ * Stop attempt the agent could be made to repeat. A manual run reports without counting.
128
+ * After maxRounds failing hook runs the gate stops blocking and reports OPEN, so the
129
+ * user decides rather than the agent looping forever.
130
+ */
131
+ export function advance(state, outcome, opts) {
132
+ const now = opts.now ?? new Date().toISOString();
133
+ if (outcome === 'pass') {
134
+ return { state: { round: 0, status: 'pass', updatedAt: now }, block: false, exit: GATE_EXIT.PASS, label: 'PASS' };
135
+ }
136
+ if (outcome === 'setup') {
137
+ return { state: { ...state, status: 'setup', updatedAt: now }, block: false, exit: GATE_EXIT.SETUP, label: 'SETUP' };
138
+ }
139
+ if (!opts.hook) {
140
+ return { state: { ...state, status: 'fail', updatedAt: now }, block: false, exit: GATE_EXIT.FAIL, label: 'FAIL' };
141
+ }
142
+ const round = (state.round ?? 0) + 1;
143
+ if (round >= opts.maxRounds) {
144
+ return { state: { round, status: 'open', updatedAt: now }, block: false, exit: GATE_EXIT.FAIL, label: 'OPEN' };
145
+ }
146
+ return { state: { round, status: 'fail', updatedAt: now }, block: true, exit: GATE_EXIT.FAIL, label: 'FAIL' };
147
+ }
148
+ export function summarize(blocking, limit = 12) {
149
+ const lines = blocking.slice(0, limit).map(f => {
150
+ const where = f.file ? `${f.file}${f.line ? `:${f.line}` : ''}` : '(project)';
151
+ const fix = f.recommendation ? ` Fix: ${f.recommendation}` : '';
152
+ return `- [${f.id}] ${where} ${f.message}${fix}`;
153
+ });
154
+ if (blocking.length > limit)
155
+ lines.push(`- ...and ${blocking.length - limit} more. Run \`sloppy gate\` for the full list.`);
156
+ return lines.join('\n');
157
+ }
158
+ /** Hook output for a Stop hook. null lets the turn end. */
159
+ export function hookOutput(advanced, reason) {
160
+ if (!advanced.block)
161
+ return null;
162
+ return JSON.stringify({ decision: 'block', reason });
163
+ }
164
+ /** Changed files that fall under a protected prefix. Any hit is an unwaivable finding. */
165
+ export function kitEditFindings(changed, protect) {
166
+ const prefixes = protect.map(p => p.replace(/^\.\//, '').replace(/\/+$/, '')).filter(Boolean);
167
+ return changed
168
+ .filter(file => prefixes.some(prefix => file === prefix || file.startsWith(`${prefix}/`)))
169
+ .map(file => ({
170
+ id: 'GATE-KIT-EDITED',
171
+ severity: 'critical',
172
+ file,
173
+ message: `Protected path ${file} was modified during the build.`,
174
+ recommendation: 'Revert the change and build around it.',
175
+ unwaivable: true
176
+ }));
177
+ }
178
+ export function readJsonFile(file) {
179
+ if (!fs.existsSync(file))
180
+ return { value: undefined };
181
+ try {
182
+ return { value: JSON.parse(fs.readFileSync(file, 'utf8')) };
183
+ }
184
+ catch (error) {
185
+ return { value: undefined, error: `${path.basename(file)} is not valid JSON: ${error.message}` };
186
+ }
187
+ }
188
+ export function writeJsonFile(file, value) {
189
+ fs.mkdirSync(path.dirname(file), { recursive: true });
190
+ fs.writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`);
191
+ }
192
+ /**
193
+ * Adds the gate's Stop hook to a Claude Code settings file, keeping every other hook.
194
+ * Throws instead of overwriting a settings file it cannot parse. Idempotent.
195
+ */
196
+ export function installStopHook(settingsFile, command = HOOK_COMMAND) {
197
+ let settings = {};
198
+ if (fs.existsSync(settingsFile)) {
199
+ const text = fs.readFileSync(settingsFile, 'utf8');
200
+ try {
201
+ settings = text.trim() ? JSON.parse(text) : {};
202
+ }
203
+ catch {
204
+ throw new Error(`${settingsFile} is not valid JSON; fix it by hand, then run the install again.`);
205
+ }
206
+ }
207
+ settings.hooks = settings.hooks && typeof settings.hooks === 'object' ? settings.hooks : {};
208
+ const stop = Array.isArray(settings.hooks.Stop) ? settings.hooks.Stop : [];
209
+ const present = stop.some(group => (group.hooks ?? []).some(h => h.command === command));
210
+ if (present)
211
+ return 'exists';
212
+ stop.push({ hooks: [{ type: 'command', command }] });
213
+ settings.hooks.Stop = stop;
214
+ writeJsonFile(settingsFile, settings);
215
+ return 'installed';
216
+ }
217
+ //# sourceMappingURL=gate-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gate-core.js","sourceRoot":"","sources":["../src/gate-core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAU,CAAC;AAIzE,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAW,CAAC;AAEjE,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAgCjD,MAAM,CAAC,MAAM,cAAc,GAA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