@skriv/ads 0.0.0-stage → 0.2.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.
- package/README.md +47 -2
- package/bin/ads.mjs +59 -0
- package/dist/manifest.json +53 -0
- package/dist/skills/ads-code-review/SKILL.md +12 -0
- package/dist/skills/ads-code-to-figma/SKILL.md +10 -0
- package/dist/skills/ads-figma-to-code/SKILL.md +10 -0
- package/dist/skills/ads-init/SKILL.md +16 -0
- package/dist/skills/ads-init/profile.md +11 -0
- package/dist/skills/ads-init/scripts/connect.py +75 -0
- package/dist/skills/ads-record/SKILL.md +12 -0
- package/dist/skills/heroui-react/LICENSE.txt +199 -0
- package/dist/skills/heroui-react/SKILL.md +234 -0
- package/dist/skills/heroui-react/scripts/get_component_docs.mjs +157 -0
- package/dist/skills/heroui-react/scripts/get_docs.mjs +148 -0
- package/dist/skills/heroui-react/scripts/get_source.mjs +160 -0
- package/dist/skills/heroui-react/scripts/get_styles.mjs +160 -0
- package/dist/skills/heroui-react/scripts/get_theme.mjs +177 -0
- package/dist/skills/heroui-react/scripts/list_components.mjs +134 -0
- package/dist/skills/heroui-theming/LICENSE.txt +199 -0
- package/dist/skills/heroui-theming/SKILL.md +268 -0
- package/dist/skills/heroui-theming/references/any-framework.md +219 -0
- package/dist/skills/heroui-theming/references/components.md +237 -0
- package/dist/skills/heroui-theming/references/theme-recipe.md +701 -0
- package/dist/skills/heroui-theming/references/tokens.md +258 -0
- package/dist/skills/heroui-theming/scripts/_styles_dir.mjs +112 -0
- package/dist/skills/heroui-theming/scripts/list_component_classes.mjs +319 -0
- package/dist/skills/heroui-theming/scripts/list_tokens.mjs +157 -0
- package/dist/templates/flow.md +12 -0
- package/dist/templates/project.md +13 -0
- package/dist/templates/review.md +14 -0
- package/dist/templates/routing.md +11 -0
- package/dist/templates/theming.md +26 -0
- package/package.json +32 -4
- package/src/doctor.mjs +38 -0
- package/src/install.mjs +140 -0
- package/src/video.mjs +18 -0
package/src/install.mjs
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
5
|
+
|
|
6
|
+
export const bundleRoot = fileURLToPath(new URL('../dist/', import.meta.url));
|
|
7
|
+
export const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
8
|
+
const begin = '<!-- ads-package:begin -->';
|
|
9
|
+
const end = '<!-- ads-package:end -->';
|
|
10
|
+
|
|
11
|
+
export function safePath(root, relative) {
|
|
12
|
+
if (!relative || relative.includes('\\') || relative.split('/').some(p => !p || p === '..' || p === '.') || path.isAbsolute(relative)) {
|
|
13
|
+
throw new Error(`Invalid managed path: ${relative}`);
|
|
14
|
+
}
|
|
15
|
+
let current = root;
|
|
16
|
+
const parts = relative.split('/');
|
|
17
|
+
for (const [index, part] of parts.entries()) {
|
|
18
|
+
current = path.join(current, part);
|
|
19
|
+
let stat;
|
|
20
|
+
try { stat = fs.lstatSync(current); } catch (error) { if (error.code === 'ENOENT') continue; throw error; }
|
|
21
|
+
if (stat.isSymbolicLink()) throw new Error(`Refusing a symlink in managed path: ${relative}`);
|
|
22
|
+
if (index < parts.length - 1 && !stat.isDirectory()) throw new Error(`Expected directory in ${relative}`);
|
|
23
|
+
if (index === parts.length - 1 && !stat.isFile()) throw new Error(`Expected regular file: ${relative}`);
|
|
24
|
+
}
|
|
25
|
+
return current;
|
|
26
|
+
}
|
|
27
|
+
export function readOptional(file) {
|
|
28
|
+
try { return fs.readFileSync(file); } catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
29
|
+
}
|
|
30
|
+
export function readState(root) {
|
|
31
|
+
const bytes = readOptional(safePath(root, '.ads/install.json'));
|
|
32
|
+
if (!bytes) return null;
|
|
33
|
+
const state = JSON.parse(bytes);
|
|
34
|
+
if (state.schema !== 1 || state.package !== '@skriv/ads' || !state.files || typeof state.files !== 'object' || Array.isArray(state.files) || !Array.isArray(state.skills) || typeof state.version !== 'string') {
|
|
35
|
+
throw new Error('Unsupported .ads/install.json; preserve it and reconcile before continuing.');
|
|
36
|
+
}
|
|
37
|
+
for (const [relative, digest] of Object.entries(state.files)) {
|
|
38
|
+
if (!relative.startsWith('.agents/skills/') && !relative.startsWith('docs/ads/templates/')) throw new Error(`Invalid installation entry: ${relative}`);
|
|
39
|
+
safePath(root, relative);
|
|
40
|
+
if (!/^[a-f0-9]{64}$/.test(digest)) throw new Error(`Invalid file hash: ${relative}`);
|
|
41
|
+
}
|
|
42
|
+
return state;
|
|
43
|
+
}
|
|
44
|
+
export function loadBundle(root = bundleRoot) {
|
|
45
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(root, 'manifest.json'), 'utf8'));
|
|
46
|
+
if (manifest.schema !== 1 || manifest.package !== '@skriv/ads') throw new Error('Invalid ADS bundle');
|
|
47
|
+
for (const [relative, digest] of Object.entries(manifest.files)) {
|
|
48
|
+
if (hash(fs.readFileSync(safePath(root, relative))) !== digest) throw new Error(`Corrupt bundle file: ${relative}`);
|
|
49
|
+
}
|
|
50
|
+
return manifest;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function detectHeroUI(root, depth = 0, budget = { count: 0 }) {
|
|
54
|
+
if (depth > 4 || ++budget.count > 2000) return false;
|
|
55
|
+
const bytes = readOptional(safePath(root, 'package.json'));
|
|
56
|
+
if (bytes) {
|
|
57
|
+
const pkg = JSON.parse(bytes);
|
|
58
|
+
const version = { ...pkg.devDependencies, ...pkg.dependencies }['@heroui/react'];
|
|
59
|
+
if (typeof version === 'string' && /^[~^]?3(?:\.|$)/.test(version)) return true;
|
|
60
|
+
}
|
|
61
|
+
const ignored = new Set(['node_modules', 'dist', 'build', 'vendor', 'coverage']);
|
|
62
|
+
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
63
|
+
if (entry.isDirectory() && !entry.name.startsWith('.') && !ignored.has(entry.name) && detectHeroUI(path.join(root, entry.name), depth + 1, budget)) return true;
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function routingSection(text) {
|
|
69
|
+
const starts = text.split(begin).length - 1;
|
|
70
|
+
const ends = text.split(end).length - 1;
|
|
71
|
+
if (!starts && !ends) return null;
|
|
72
|
+
if (starts !== 1 || ends !== 1 || text.indexOf(end) < text.indexOf(begin)) throw new Error('Malformed ADS routing block in AGENTS.md');
|
|
73
|
+
return text.slice(text.indexOf(begin), text.indexOf(end) + end.length);
|
|
74
|
+
}
|
|
75
|
+
function writeAtomic(file, bytes) {
|
|
76
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
77
|
+
const temp = `${file}.${randomUUID()}.tmp`;
|
|
78
|
+
try {
|
|
79
|
+
fs.writeFileSync(temp, bytes, { flag: 'wx' });
|
|
80
|
+
fs.renameSync(temp, file);
|
|
81
|
+
} finally { fs.rmSync(temp, { force: true }); }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function install({ target, command = 'init', withHeroUI = false, dryRun = false, source = bundleRoot }) {
|
|
85
|
+
const root = fs.realpathSync(target);
|
|
86
|
+
const manifest = loadBundle(source);
|
|
87
|
+
const state = readState(root);
|
|
88
|
+
if (command === 'update' && !state) throw new Error('No package installation found. Run init first.');
|
|
89
|
+
if (state) {
|
|
90
|
+
const compare = (a, b) => a.split('.').map(Number).reduce((result, n, i) => result || Math.sign(n - Number(b.split('.')[i])), 0);
|
|
91
|
+
if (compare(state.version, manifest.version) > 0) throw new Error(`Installed ${state.version} is newer than this bundle (${manifest.version}). Use @latest.`);
|
|
92
|
+
}
|
|
93
|
+
const skills = [...manifest.skills];
|
|
94
|
+
const heroUISkills = manifest.skillGroups?.heroui ?? ['heroui-react'];
|
|
95
|
+
if (withHeroUI || state?.skills.some(skill => heroUISkills.includes(skill)) || detectHeroUI(root)) skills.push(...heroUISkills);
|
|
96
|
+
const desired = new Map();
|
|
97
|
+
for (const relative of Object.keys(manifest.files)) {
|
|
98
|
+
if (relative.startsWith('skills/') && skills.includes(relative.split('/')[1])) {
|
|
99
|
+
desired.set(`.agents/${relative}`, fs.readFileSync(safePath(source, relative)));
|
|
100
|
+
} else if (['templates/flow.md', 'templates/review.md'].includes(relative) || relative === 'templates/theming.md' && skills.includes('heroui-theming')) {
|
|
101
|
+
desired.set(`docs/ads/${relative}`, fs.readFileSync(safePath(source, relative)));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const changes = [];
|
|
105
|
+
const conflicts = [];
|
|
106
|
+
const files = {};
|
|
107
|
+
for (const [relative, bytes] of desired) {
|
|
108
|
+
const file = safePath(root, relative);
|
|
109
|
+
const current = readOptional(file);
|
|
110
|
+
const nextHash = hash(bytes);
|
|
111
|
+
files[relative] = nextHash;
|
|
112
|
+
if (current && hash(current) !== nextHash && hash(current) !== state?.files[relative]) conflicts.push(relative);
|
|
113
|
+
else if (!current || hash(current) !== nextHash) changes.push({ file, relative, bytes });
|
|
114
|
+
}
|
|
115
|
+
for (const [relative, previousHash] of Object.entries(state?.files ?? {})) {
|
|
116
|
+
if (desired.has(relative)) continue;
|
|
117
|
+
const file = safePath(root, relative);
|
|
118
|
+
const current = readOptional(file);
|
|
119
|
+
if (current && hash(current) !== previousHash) conflicts.push(relative);
|
|
120
|
+
else if (current) changes.push({ file, relative, bytes: null });
|
|
121
|
+
}
|
|
122
|
+
const instructions = safePath(root, 'AGENTS.md');
|
|
123
|
+
const existing = readOptional(instructions)?.toString('utf8') ?? '';
|
|
124
|
+
const previousBlock = routingSection(existing);
|
|
125
|
+
const block = `${begin}\n${fs.readFileSync(path.join(source, 'templates/routing.md'), 'utf8').trim()}\n${end}`;
|
|
126
|
+
if (previousBlock && previousBlock !== block && hash(previousBlock) !== state?.routingHash) conflicts.push('AGENTS.md (ADS block)');
|
|
127
|
+
const next = previousBlock ? existing.replace(previousBlock, () => block) : existing + (existing && !existing.endsWith('\n') ? '\n' : '') + (existing ? '\n' : '') + block + '\n';
|
|
128
|
+
if (next !== existing) changes.push({ file: instructions, relative: 'AGENTS.md', bytes: next });
|
|
129
|
+
const profile = safePath(root, 'docs/ads/project.md');
|
|
130
|
+
if (!readOptional(profile)) changes.push({ file: profile, relative: 'docs/ads/project.md', bytes: fs.readFileSync(path.join(source, 'templates/project.md')) });
|
|
131
|
+
if (conflicts.length) throw new Error(`Local changes preserved; no files written. Reconcile these files with the new bundle, then retry:\n${conflicts.map(p => ` ${p}`).join('\n')}`);
|
|
132
|
+
const nextState = JSON.stringify({ schema: 1, package: manifest.package, version: manifest.version, skills, files, routingHash: hash(block) }, null, 2) + '\n';
|
|
133
|
+
const stateFile = safePath(root, '.ads/install.json');
|
|
134
|
+
if (readOptional(stateFile)?.toString() !== nextState) changes.push({ file: stateFile, relative: '.ads/install.json', bytes: nextState });
|
|
135
|
+
if (!dryRun) for (const change of changes) {
|
|
136
|
+
if (change.bytes === null) fs.unlinkSync(change.file);
|
|
137
|
+
else writeAtomic(change.file, change.bytes);
|
|
138
|
+
}
|
|
139
|
+
return { root, version: manifest.version, skills, dryRun, changes: changes.map(c => c.relative), profilePending: (readOptional(profile)?.toString() ?? '').includes('ads-profile: pending') || !fs.existsSync(profile) };
|
|
140
|
+
}
|
package/src/video.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
export function checkVideo(file) {
|
|
6
|
+
const absolute = path.resolve(file);
|
|
7
|
+
if (!fs.statSync(absolute).isFile()) throw new Error('Video must be a regular file');
|
|
8
|
+
const probe = spawnSync('ffprobe', ['-v', 'error', '-show_format', '-show_streams', '-of', 'json', absolute], { encoding: 'utf8', timeout: 30000, maxBuffer: 2 ** 20 });
|
|
9
|
+
if (probe.error) throw new Error(`ffprobe: ${probe.error.message}`);
|
|
10
|
+
if (probe.status !== 0) throw new Error(`ffprobe failed: ${probe.stderr.trim()}`);
|
|
11
|
+
const info = JSON.parse(probe.stdout);
|
|
12
|
+
const video = info.streams?.find(stream => stream.codec_type === 'video');
|
|
13
|
+
const duration = Number(info.format?.duration ?? video?.duration);
|
|
14
|
+
if (!video || !Number.isFinite(duration) || duration <= 0) throw new Error('Video has no video stream with positive duration');
|
|
15
|
+
const decode = spawnSync('ffmpeg', ['-v', 'error', '-xerror', '-i', absolute, '-map', '0:v:0', '-f', 'null', '-'], { encoding: 'utf8', timeout: 60000, maxBuffer: 2 ** 20 });
|
|
16
|
+
if (decode.error || decode.status !== 0) throw new Error(`Video decode failed: ${decode.error?.message ?? decode.stderr.trim()}`);
|
|
17
|
+
return { file: absolute, duration, width: video.width, height: video.height, codec: video.codec_name, decoded: true };
|
|
18
|
+
}
|