@gobing-ai/knowledge-kit 0.0.12 → 0.0.14
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/.claude-plugin/marketplace.json +1 -1
- package/dist/index.js +120 -26
- package/package.json +1 -1
- package/plugins/generations/content-gen/dist/index.js +22187 -0
- package/plugins/generations/content-gen/plugin.json +1 -1
- package/plugins/generations/core-facts-gen/dist/index.js +22068 -0
- package/plugins/generations/core-facts-gen/plugin.json +1 -1
- package/plugins/generations/daily-article-gen/dist/index.js +22050 -0
- package/plugins/generations/daily-article-gen/plugin.json +1 -1
- package/plugins/generations/daily-article-gen/src/index.ts +13 -1
- package/plugins/generations/dailynews-gen/dist/index.js +22344 -0
- package/plugins/generations/dailynews-gen/plugin.json +1 -1
- package/plugins/generations/episode-plan-gen/dist/index.js +22503 -0
- package/plugins/generations/episode-plan-gen/plugin.json +1 -1
- package/plugins/generations/episode-plan-gen/src/index.ts +11 -0
- package/plugins/generations/image-gen/config.example.yaml +75 -0
- package/plugins/generations/image-gen/dist/index.js +24862 -0
- package/plugins/generations/image-gen/package.json +17 -0
- package/plugins/generations/image-gen/plugin.json +7 -0
- package/plugins/generations/image-gen/presets/formats/cover.yaml +57 -0
- package/plugins/generations/image-gen/presets/formats/free.yaml +46 -0
- package/plugins/generations/image-gen/presets/formats/illustration.yaml +48 -0
- package/plugins/generations/image-gen/presets/styles/clean-webapp-ui.yaml +28 -0
- package/plugins/generations/image-gen/presets/styles/cute.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/editorial.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/fresh.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/minimalist.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/photorealistic.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/sketch.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/technical-diagram.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/vibrant.yaml +3 -0
- package/plugins/generations/image-gen/presets/styles/warm.yaml +3 -0
- package/plugins/generations/image-gen/src/bytes.ts +19 -0
- package/plugins/generations/image-gen/src/index.ts +319 -0
- package/plugins/generations/image-gen/src/job.ts +143 -0
- package/plugins/generations/image-gen/src/paths.ts +31 -0
- package/plugins/generations/image-gen/src/presets.ts +344 -0
- package/plugins/generations/image-gen/src/providers/agnes.ts +110 -0
- package/plugins/generations/image-gen/src/providers/azure.ts +153 -0
- package/plugins/generations/image-gen/src/providers/codex-cli.ts +170 -0
- package/plugins/generations/image-gen/src/providers/dashscope.ts +485 -0
- package/plugins/generations/image-gen/src/providers/google.ts +268 -0
- package/plugins/generations/image-gen/src/providers/huggingface.ts +59 -0
- package/plugins/generations/image-gen/src/providers/jimeng.ts +259 -0
- package/plugins/generations/image-gen/src/providers/minimax.ts +171 -0
- package/plugins/generations/image-gen/src/providers/openai.ts +319 -0
- package/plugins/generations/image-gen/src/providers/openrouter.ts +257 -0
- package/plugins/generations/image-gen/src/providers/refs.ts +24 -0
- package/plugins/generations/image-gen/src/providers/replicate.ts +279 -0
- package/plugins/generations/image-gen/src/providers/seedream.ts +128 -0
- package/plugins/generations/image-gen/src/providers/types.ts +286 -0
- package/plugins/generations/image-gen/src/providers/zai.ts +237 -0
- package/plugins/generations/image-gen/tsconfig.json +8 -0
- package/plugins/generations/news-report-gen/dist/index.js +22193 -0
- package/plugins/generations/news-report-gen/package.json +17 -0
- package/plugins/generations/news-report-gen/plugin.json +7 -0
- package/plugins/generations/news-report-gen/src/index.ts +308 -0
- package/plugins/generations/news-report-gen/tsconfig.json +4 -0
- package/plugins/generations/omni-voice-gen/Makefile +14 -0
- package/plugins/generations/omni-voice-gen/README.md +112 -0
- package/plugins/generations/omni-voice-gen/bin/omni-voice-gen +2 -0
- package/plugins/generations/omni-voice-gen/dist/omni-voice-gen-prr8skpb. +2 -0
- package/plugins/generations/omni-voice-gen/dist/omni-voice-gen.js +6 -0
- package/plugins/generations/omni-voice-gen/plugin.json +6 -0
- package/plugins/generations/omni-voice-gen/profiles.json +12 -0
- package/plugins/generations/omni-voice-gen/pyproject.toml +25 -0
- package/plugins/generations/omni-voice-gen/scripts/coverage_gate.py +74 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/__init__.py +1 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/__main__.py +39 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/audio.py +190 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/backend.py +150 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/contract.py +76 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/mp3.py +60 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/pipeline.py +289 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/profiles.py +100 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/qc.py +234 -0
- package/plugins/generations/omni-voice-gen/src/omni_voice_gen/voicescript.py +352 -0
- package/plugins/generations/omni-voice-gen/uv.lock +3510 -0
- package/plugins/generations/voice-gen/dist/index.js +23055 -0
- package/plugins/generations/voice-gen/plugin.json +1 -1
- package/plugins/generations/voice-gen/src/index.ts +16 -1
- package/plugins/generations/voice-gen/src/voicebox-client.ts +3 -1
- package/plugins/ingestions/aihot-ingest/dist/index.js +22378 -0
- package/plugins/ingestions/aihot-ingest/plugin.json +1 -1
- package/plugins/ingestions/horizon-ingest/dist/index.js +22125 -0
- package/plugins/ingestions/horizon-ingest/plugin.json +1 -1
- package/plugins/ingestions/karakeep-local/dist/index.js +24204 -0
- package/plugins/ingestions/karakeep-local/plugin.json +1 -1
- package/plugins/ingestions/last30days-ingest/dist/index.js +22070 -0
- package/plugins/ingestions/last30days-ingest/plugin.json +1 -1
- package/plugins/ingestions/web-search/dist/index.js +24399 -0
- package/plugins/ingestions/web-search/plugin.json +1 -1
- package/plugins/kk/commands/image-extract.md +40 -0
- package/plugins/kk/commands/image-generate.md +32 -0
- package/plugins/kk/config.example.yaml +80 -0
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/skills/image-authoring/SKILL.md +257 -0
- package/plugins/kk/skills/image-authoring/references/format-drafting.md +57 -0
- package/plugins/kk/skills/image-authoring/references/illustration-positions.md +87 -0
- package/plugins/kk/skills/image-authoring/references/migrating-from-wt.md +31 -0
- package/plugins/kk/skills/image-authoring/references/providers.md +52 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +139 -0
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +130 -30
- package/plugins/publishings/emdash-pub/dist/index.js +22263 -0
- package/plugins/publishings/emdash-pub/plugin.json +1 -1
- package/plugins/publishings/podcast-pub/dist/index.js +22650 -0
- package/plugins/publishings/podcast-pub/plugin.json +8 -2
- package/plugins/publishings/podcast-pub/src/index.ts +18 -2
- package/plugins/publishings/podcast-pub/src/show-notes.ts +56 -9
- package/plugins/publishings/qiita-pub/dist/index.js +22101 -0
- package/plugins/publishings/qiita-pub/plugin.json +1 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +22323 -0
- package/plugins/publishings/surfdash-pub/plugin.json +1 -1
- package/plugins/publishings/surfdash-pub/src/index.ts +109 -9
- package/plugins/publishings/zenn-pub/dist/index.js +22142 -0
- package/plugins/publishings/zenn-pub/plugin.json +1 -1
- package/plugins/sp/scripts/batch-preflight.mjs +346 -0
- package/plugins/sp/scripts/batch-preflight.ts +459 -0
- package/plugins/sp/scripts/daily-summary/daily-summary.mjs +615 -0
- package/plugins/sp/scripts/daily-summary/daily-summary.ts +846 -0
- package/plugins/sp/scripts/daily-summary/logger.ts +28 -0
- package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.mjs +223 -0
- package/plugins/sp/scripts/dogfood-testing/detect-pipeline-driving.ts +367 -0
- package/plugins/sp/scripts/dogfood-testing/validate-report.mjs +132 -0
- package/plugins/sp/scripts/dogfood-testing/validate-report.ts +169 -0
- package/plugins/sp/scripts/feature-dev-precheck.mjs +171 -0
- package/plugins/sp/scripts/feature-dev-precheck.ts +238 -0
- package/plugins/sp/scripts/feature-sync-bounded.mjs +285 -0
- package/plugins/sp/scripts/feature-sync-bounded.ts +478 -0
- package/plugins/sp/scripts/history-anatomy-cache.mjs +902 -0
- package/plugins/sp/scripts/history-anatomy-cache.ts +1028 -0
- package/plugins/sp/scripts/idea-handoff.mjs +22 -0
- package/plugins/sp/scripts/idea-handoff.ts +44 -0
- package/plugins/sp/scripts/inline-pipeline-parity-check.ts +185 -0
- package/plugins/sp/scripts/inline-run-setup.ts +198 -0
- package/plugins/sp/scripts/pr-reviewing.mjs +769 -0
- package/plugins/sp/scripts/pr-reviewing.ts +925 -0
- package/plugins/sp/scripts/quality-gate.mjs +179 -0
- package/plugins/sp/scripts/quality-gate.ts +217 -0
- package/plugins/sp/scripts/script-contract-check.ts +319 -0
- package/plugins/sp/scripts/stage-registry-adapter.ts +1533 -0
- package/plugins/sp/scripts/surface-drift-inventory.ts +929 -0
- package/plugins/sp/scripts/task-evidence-precheck.ts +181 -0
- package/plugins/sp/scripts/task-size-precheck.ts +175 -0
- package/plugins/sp/scripts/transition-shim-check.ts +238 -0
- package/plugins/sp/scripts/validate-commands.ts +689 -0
- package/plugins/sp/scripts/validate-flag-contracts.ts +878 -0
- package/plugins/sp/scripts/verify-answer-lint.ts +530 -0
- package/plugins/sp/scripts/workflow-step-profile.mjs +316 -0
- package/plugins/sp/scripts/workflow-step-profile.ts +456 -0
- package/plugins/sp/scripts/wrapup-steps.mjs +373 -0
- package/plugins/sp/scripts/wrapup-steps.ts +466 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
/**
|
|
3
|
+
* script-contract-check — two-sided gate over plugins/sp script entrypoint contracts
|
|
4
|
+
* (task 0600, feature I, ADR-065).
|
|
5
|
+
*
|
|
6
|
+
* Enforces superskill's standard plugin script contract across plugins/sp:
|
|
7
|
+
* 1. A 'standard' entry must have a valid .mjs twin not older than its .ts source.
|
|
8
|
+
* 2. A .mjs twin on disk must be registered under a 'standard' entry (never 'repo-only' or unlisted).
|
|
9
|
+
* 3. Every script file under plugins/sp/scripts/ must have a manifest entry (two-sided).
|
|
10
|
+
* 4. No shipped surface (commands/, skills/, agents/, README.md) may reference 'bun plugins/sp/scripts/'.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* bun plugins/sp/scripts/script-contract-check.ts
|
|
14
|
+
* [--manifest <path>] default: config/plugin-scripts.json
|
|
15
|
+
* [--scripts-dir <path>] default: plugins/sp/scripts
|
|
16
|
+
* [--plugin-dir <path>] default: plugins/sp
|
|
17
|
+
*
|
|
18
|
+
* Exit code: 0 on success, 1 on any violation.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
22
|
+
import { join, resolve } from 'node:path';
|
|
23
|
+
|
|
24
|
+
export type ScriptContractType = 'standard' | 'repo-only';
|
|
25
|
+
|
|
26
|
+
export interface ScriptManifestEntry {
|
|
27
|
+
rel: string;
|
|
28
|
+
contract: ScriptContractType;
|
|
29
|
+
twin?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ScriptManifest {
|
|
33
|
+
schema_version?: number;
|
|
34
|
+
description?: string;
|
|
35
|
+
entries: ScriptManifestEntry[];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface Violation {
|
|
39
|
+
kind:
|
|
40
|
+
| 'missing_twin'
|
|
41
|
+
| 'stale_twin'
|
|
42
|
+
| 'unexpected_twin'
|
|
43
|
+
| 'unregistered_script'
|
|
44
|
+
| 'forbidden_invocation'
|
|
45
|
+
| 'incomplete';
|
|
46
|
+
target: string;
|
|
47
|
+
message: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function parseArgs(argv: string[]): {
|
|
51
|
+
manifest: string;
|
|
52
|
+
scriptsDir: string;
|
|
53
|
+
pluginDir: string;
|
|
54
|
+
cwd: string;
|
|
55
|
+
} {
|
|
56
|
+
let manifest = 'config/plugin-scripts.json';
|
|
57
|
+
let scriptsDir = 'plugins/sp/scripts';
|
|
58
|
+
let pluginDir = 'plugins/sp';
|
|
59
|
+
for (let i = 0; i < argv.length; i++) {
|
|
60
|
+
if (argv[i] === '--manifest') manifest = argv[++i] ?? manifest;
|
|
61
|
+
else if (argv[i] === '--scripts-dir') scriptsDir = argv[++i] ?? scriptsDir;
|
|
62
|
+
else if (argv[i] === '--plugin-dir') pluginDir = argv[++i] ?? pluginDir;
|
|
63
|
+
}
|
|
64
|
+
return { manifest, scriptsDir, pluginDir, cwd: process.cwd() };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function loadManifest(path: string): { manifest: ScriptManifest | null; error: string | null } {
|
|
68
|
+
if (!existsSync(path)) return { manifest: null, error: `manifest not found at ${path}` };
|
|
69
|
+
try {
|
|
70
|
+
const raw = readFileSync(path, 'utf8');
|
|
71
|
+
const parsed = JSON.parse(raw) as ScriptManifest;
|
|
72
|
+
if (!Array.isArray(parsed.entries)) {
|
|
73
|
+
return { manifest: null, error: `${path}: missing "entries" array` };
|
|
74
|
+
}
|
|
75
|
+
return { manifest: parsed, error: null };
|
|
76
|
+
} catch (err) {
|
|
77
|
+
return { manifest: null, error: `malformed JSON at ${path}: ${String(err)}` };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function listDiskScripts(scriptsDir: string): { tsFiles: string[]; mjsFiles: string[] } {
|
|
82
|
+
const tsFiles: string[] = [];
|
|
83
|
+
const mjsFiles: string[] = [];
|
|
84
|
+
|
|
85
|
+
function walk(dir: string, base: string): void {
|
|
86
|
+
let entries: string[];
|
|
87
|
+
try {
|
|
88
|
+
entries = readdirSync(dir);
|
|
89
|
+
} catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
for (const entry of entries) {
|
|
93
|
+
const fullPath = join(dir, entry);
|
|
94
|
+
let st: ReturnType<typeof statSync>;
|
|
95
|
+
try {
|
|
96
|
+
st = statSync(fullPath);
|
|
97
|
+
} catch {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (st.isDirectory()) {
|
|
101
|
+
walk(fullPath, base ? `${base}/${entry}` : entry);
|
|
102
|
+
} else if (st.isFile()) {
|
|
103
|
+
const rel = base ? `${base}/${entry}` : entry;
|
|
104
|
+
if (entry.endsWith('.ts')) {
|
|
105
|
+
tsFiles.push(rel);
|
|
106
|
+
} else if (entry.endsWith('.mjs')) {
|
|
107
|
+
mjsFiles.push(rel);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
walk(scriptsDir, '');
|
|
114
|
+
return { tsFiles: tsFiles.sort(), mjsFiles: mjsFiles.sort() };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function scanShippedSurfaces(pluginDir: string): Array<{ file: string; line: number; content: string }> {
|
|
118
|
+
const matches: Array<{ file: string; line: number; content: string }> = [];
|
|
119
|
+
const forbiddenPattern = 'bun plugins/sp/scripts/';
|
|
120
|
+
|
|
121
|
+
const searchDirs = ['commands', 'skills', 'agents'];
|
|
122
|
+
const singleFiles = ['README.md'];
|
|
123
|
+
|
|
124
|
+
function scanFile(filePath: string): void {
|
|
125
|
+
if (!existsSync(filePath)) return;
|
|
126
|
+
let text: string;
|
|
127
|
+
try {
|
|
128
|
+
text = readFileSync(filePath, 'utf8');
|
|
129
|
+
} catch {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const lines = text.split('\n');
|
|
133
|
+
for (let i = 0; i < lines.length; i++) {
|
|
134
|
+
const line = lines[i] ?? '';
|
|
135
|
+
if (line.includes(forbiddenPattern)) {
|
|
136
|
+
matches.push({
|
|
137
|
+
file: filePath,
|
|
138
|
+
line: i + 1,
|
|
139
|
+
content: line.trim(),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function walk(dir: string): void {
|
|
146
|
+
let entries: string[];
|
|
147
|
+
try {
|
|
148
|
+
entries = readdirSync(dir);
|
|
149
|
+
} catch {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
for (const entry of entries) {
|
|
153
|
+
const fullPath = join(dir, entry);
|
|
154
|
+
let st: ReturnType<typeof statSync>;
|
|
155
|
+
try {
|
|
156
|
+
st = statSync(fullPath);
|
|
157
|
+
} catch {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (st.isDirectory()) {
|
|
161
|
+
walk(fullPath);
|
|
162
|
+
} else if (
|
|
163
|
+
st.isFile() &&
|
|
164
|
+
(entry.endsWith('.md') || entry.endsWith('.json') || entry.endsWith('.yaml') || entry.endsWith('.yml'))
|
|
165
|
+
) {
|
|
166
|
+
scanFile(fullPath);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
for (const d of searchDirs) {
|
|
172
|
+
walk(join(pluginDir, d));
|
|
173
|
+
}
|
|
174
|
+
for (const f of singleFiles) {
|
|
175
|
+
scanFile(join(pluginDir, f));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return matches;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function validateContract(manifest: ScriptManifest, scriptsDir: string, pluginDir: string): Violation[] {
|
|
182
|
+
const violations: Violation[] = [];
|
|
183
|
+
const { tsFiles, mjsFiles } = listDiskScripts(scriptsDir);
|
|
184
|
+
|
|
185
|
+
const manifestMap = new Map<string, ScriptManifestEntry>();
|
|
186
|
+
for (const entry of manifest.entries) {
|
|
187
|
+
if (!entry.rel || !entry.contract) {
|
|
188
|
+
violations.push({
|
|
189
|
+
kind: 'incomplete',
|
|
190
|
+
target: entry.rel ?? '<missing>',
|
|
191
|
+
message: `manifest entry missing required fields (rel, contract)`,
|
|
192
|
+
});
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
manifestMap.set(entry.rel, entry);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Rule 1: standard entries must have valid .mjs twins not older than the .ts source.
|
|
199
|
+
// mtime is only meaningful when a build genuinely ran: a `git worktree add` stamps
|
|
200
|
+
// every checked-out file within the same millisecond, and the lexicographic write
|
|
201
|
+
// order (`tool.mjs` < `tool.ts`) makes the twin spuriously "older" by <1ms. Tolerate
|
|
202
|
+
// sub-second deltas so a fresh checkout is never flagged; real build staleness is
|
|
203
|
+
// seconds-to-minutes, far beyond this window (task 0606 R1 eval-worktree blocker).
|
|
204
|
+
const STALE_TWIN_TOLERANCE_MS = 1000;
|
|
205
|
+
for (const entry of manifest.entries) {
|
|
206
|
+
if (entry.rel && entry.contract === 'standard') {
|
|
207
|
+
const expectedTwinRel = entry.twin ?? entry.rel.replace(/\.ts$/, '.mjs');
|
|
208
|
+
const twinPath = join(scriptsDir, expectedTwinRel);
|
|
209
|
+
const tsPath = join(scriptsDir, entry.rel);
|
|
210
|
+
|
|
211
|
+
if (!existsSync(twinPath)) {
|
|
212
|
+
violations.push({
|
|
213
|
+
kind: 'missing_twin',
|
|
214
|
+
target: entry.rel,
|
|
215
|
+
message: `standard script ${entry.rel} is missing its .mjs twin (${expectedTwinRel})`,
|
|
216
|
+
});
|
|
217
|
+
} else if (existsSync(tsPath)) {
|
|
218
|
+
const tsStat = statSync(tsPath);
|
|
219
|
+
const twinStat = statSync(twinPath);
|
|
220
|
+
if (twinStat.mtimeMs < tsStat.mtimeMs - STALE_TWIN_TOLERANCE_MS) {
|
|
221
|
+
violations.push({
|
|
222
|
+
kind: 'stale_twin',
|
|
223
|
+
target: entry.rel,
|
|
224
|
+
message: `standard script .mjs twin ${expectedTwinRel} is older than source ${entry.rel}`,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Rule 2: committed .mjs files must belong to a 'standard' entry
|
|
232
|
+
for (const mjsRel of mjsFiles) {
|
|
233
|
+
const correspondingTsRel = mjsRel.replace(/\.mjs$/, '.ts');
|
|
234
|
+
const entry = manifestMap.get(correspondingTsRel);
|
|
235
|
+
if (!entry) {
|
|
236
|
+
violations.push({
|
|
237
|
+
kind: 'unexpected_twin',
|
|
238
|
+
target: mjsRel,
|
|
239
|
+
message: `.mjs twin ${mjsRel} exists on disk but has no manifest entry for ${correspondingTsRel}`,
|
|
240
|
+
});
|
|
241
|
+
} else if (entry.contract === 'repo-only') {
|
|
242
|
+
violations.push({
|
|
243
|
+
kind: 'unexpected_twin',
|
|
244
|
+
target: mjsRel,
|
|
245
|
+
message: `repo-only script ${correspondingTsRel} must not have a .mjs twin (${mjsRel})`,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Rule 3: all .ts files on disk must have a manifest entry
|
|
251
|
+
const diskTsSet = new Set(tsFiles);
|
|
252
|
+
for (const tsRel of tsFiles) {
|
|
253
|
+
if (!manifestMap.has(tsRel)) {
|
|
254
|
+
violations.push({
|
|
255
|
+
kind: 'unregistered_script',
|
|
256
|
+
target: tsRel,
|
|
257
|
+
message: `script ${tsRel} exists in scripts dir but is not registered in manifest`,
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Also verify manifest entries exist on disk
|
|
263
|
+
for (const [rel] of manifestMap) {
|
|
264
|
+
if (!diskTsSet.has(rel)) {
|
|
265
|
+
violations.push({
|
|
266
|
+
kind: 'unregistered_script',
|
|
267
|
+
target: rel,
|
|
268
|
+
message: `manifest entry ${rel} does not exist on disk in ${scriptsDir}`,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Rule 4: scan shipped surfaces for forbidden invocation
|
|
274
|
+
const forbiddenHits = scanShippedSurfaces(pluginDir);
|
|
275
|
+
for (const hit of forbiddenHits) {
|
|
276
|
+
violations.push({
|
|
277
|
+
kind: 'forbidden_invocation',
|
|
278
|
+
target: `${hit.file}:${hit.line}`,
|
|
279
|
+
message: `shipped surface ${hit.file}:${hit.line} contains forbidden invocation 'bun plugins/sp/scripts/': ${hit.content}`,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return violations;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function run(argv: string[] = process.argv.slice(2)): number {
|
|
287
|
+
const { manifest, scriptsDir, pluginDir, cwd } = parseArgs(argv);
|
|
288
|
+
const manifestPath = resolve(cwd, manifest);
|
|
289
|
+
const absScriptsDir = resolve(cwd, scriptsDir);
|
|
290
|
+
const absPluginDir = resolve(cwd, pluginDir);
|
|
291
|
+
|
|
292
|
+
const { manifest: parsed, error } = loadManifest(manifestPath);
|
|
293
|
+
if (error || !parsed) {
|
|
294
|
+
console.error(`script-contract-check: FAIL - ${error}`);
|
|
295
|
+
return 1;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const violations = validateContract(parsed, absScriptsDir, absPluginDir);
|
|
299
|
+
const ok = violations.length === 0;
|
|
300
|
+
|
|
301
|
+
const standardCount = parsed.entries.filter((e) => e.contract === 'standard').length;
|
|
302
|
+
const repoOnlyCount = parsed.entries.filter((e) => e.contract === 'repo-only').length;
|
|
303
|
+
|
|
304
|
+
console.log(
|
|
305
|
+
`script-contract-check: ${parsed.entries.length} script(s) baselined (${standardCount} standard, ${repoOnlyCount} repo-only), ` +
|
|
306
|
+
`${violations.length} violation(s) — ${ok ? 'PASS' : 'FAIL'}`,
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
if (ok) return 0;
|
|
310
|
+
|
|
311
|
+
for (const v of violations) {
|
|
312
|
+
console.error(`script-contract-check: FAIL (${v.kind}) - ${v.message}`);
|
|
313
|
+
}
|
|
314
|
+
return 1;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (import.meta.main) {
|
|
318
|
+
process.exit(run());
|
|
319
|
+
}
|