drafted 1.24.5 → 1.24.7

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.
Files changed (44) hide show
  1. package/README.md +34 -15
  2. package/agent-instructions/global.md +3 -0
  3. package/cli/google-setup.sh +186 -0
  4. package/cli/mail-watch.mjs +237 -0
  5. package/cli/open-url.mjs +17 -0
  6. package/cli/repo-scan.mjs +240 -0
  7. package/cli/skill-setup-trust.mjs +17 -0
  8. package/install-mcp.sh +1440 -0
  9. package/mcp/active-project-store.mjs +81 -0
  10. package/mcp/gates.mjs +206 -0
  11. package/mcp/gws-status.mjs +31 -0
  12. package/mcp/repo-address.mjs +215 -0
  13. package/mcp/server.mjs +1 -1
  14. package/mcp/test-file-path-text.mjs +58 -0
  15. package/mcp/test-org-guards.mjs +234 -0
  16. package/mcp/test-project-index.mjs +88 -0
  17. package/mcp/test-search-terms.mjs +79 -0
  18. package/mcp/test-skill-paths.mjs +29 -0
  19. package/mcp/widgets/canvas-overview.html +229 -0
  20. package/mcp/widgets/frame-preview.html +162 -0
  21. package/package.json +27 -21
  22. package/plugin/commands/create-project.md +20 -0
  23. package/plugin/commands/create-skill.md +18 -0
  24. package/plugin/commands/extract.md +16 -0
  25. package/plugin/commands/improve-project-harness.md +16 -0
  26. package/plugin/commands/improve-skill.md +14 -0
  27. package/plugin/commands/improve-wiki.md +14 -0
  28. package/plugin/commands/ingest.md +20 -0
  29. package/plugin/commands/onboard-drafted.md +18 -0
  30. package/plugin/skills/drafted/SKILL.md +102 -0
  31. package/server/lib/umami.mjs +164 -0
  32. package/src/shared/anchor-scope.mjs +98 -0
  33. package/src/shared/excalidraw.mjs +94 -0
  34. package/src/shared/folder-path.mjs +176 -0
  35. package/src/shared/gate-budget.mjs +30 -0
  36. package/src/shared/minion-presets.mjs +67 -0
  37. package/src/shared/okf-log.mjs +62 -0
  38. package/src/shared/record-conformance.mjs +167 -0
  39. package/src/shared/root-route.mjs +45 -0
  40. package/src/shared/task-id.mjs +54 -0
  41. package/src/shared/test-excalidraw-merge.mjs +52 -0
  42. package/src/shared/wiki-excalidraw.mjs +90 -0
  43. package/skills/import-website-to-drafted.md +0 -329
  44. /package/{shared → src/shared}/constants.mjs +0 -0
@@ -1,329 +0,0 @@
1
- ---
2
- description: Import an existing website into Drafted as a design frame. Renders the page in a headless browser to capture the full DOM (including SPA content), downloads all assets, rewrites paths, then uploads via MCP tools.
3
- argument-hint: "[URL or local path, e.g., 'https://example.com' or './dist']"
4
- ---
5
- # /import-website-to-drafted
6
-
7
- Import a website into Drafted as a fully rendered frame with all its assets.
8
-
9
- > **Partially stale — steps 4-6 predate the `fs` tool grammar.** `write`, `batch`,
10
- > `upload_asset` and `list_assets` are retired MCP tools; asset upload now goes
11
- > through `fs(write, ..., file_path=...)`. Step 1 and the Puppeteer capture
12
- > (steps 2-3) are current. Verify tool names against `fs` before relying on the
13
- > later steps.
14
-
15
- ## How it works
16
-
17
- Drafted frames render in iframes. The server injects a `<base>` tag so relative paths like `<link href="css/styles.css">` resolve to the frame's assets in R2 storage. You write the HTML as a frame with `fs(write, ...)`, and all referenced files (CSS, JS, images, fonts) alongside it.
18
-
19
- **Most modern sites are SPAs** (React, Framer, Webflow, Next.js) where the HTML source is just a shell and the real content is rendered by JavaScript. A simple HTTP fetch won't capture the content. This skill uses Puppeteer to render the page fully before capturing.
20
-
21
- ## Step 1: Pick the project
22
-
23
- There is no create-then-open step: the project is part of the path, and writing
24
- into a project that does not exist creates it. Address it directly.
25
-
26
- ```
27
- fs(write, path="/o/<org>/projects/my-import/designs/homepage/index.html", ...)
28
- ```
29
-
30
- To see what already exists first, `fs(ls, path="/o/<org>/projects")` lists them
31
- and `fs(search, path="/o/<org>/projects", query="<terms>")` finds one by name —
32
- do not enumerate the whole org to pick a project you can already name.
33
-
34
- ## Step 2: Ensure Puppeteer is available
35
-
36
- ```bash
37
- npm ls puppeteer 2>/dev/null || npm install puppeteer
38
- ```
39
-
40
- ## Step 3: Render, capture, and download assets
41
-
42
- Run this script locally. It launches a headless browser, renders the page fully (including SPA content), captures the complete DOM, then downloads all external assets and rewrites URLs to relative paths.
43
-
44
- **Adapt `SITE_URL` as needed:**
45
-
46
- ```bash
47
- node -e "
48
- const puppeteer = require('puppeteer');
49
- const https = require('https');
50
- const http = require('http');
51
- const fs = require('fs');
52
- const path = require('path');
53
- const { URL } = require('url');
54
-
55
- const SITE_URL = 'https://example.com'; // ← CHANGE THIS
56
- const OUT_DIR = '/tmp/site-import';
57
-
58
- // ── Helpers ──────────────────────────────────────────────────────
59
-
60
- function download(url) {
61
- return new Promise((resolve, reject) => {
62
- const mod = url.startsWith('https') ? https : http;
63
- mod.get(url, { headers: { 'User-Agent': 'Mozilla/5.0' } }, res => {
64
- if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
65
- return download(res.headers.location).then(resolve, reject);
66
- }
67
- if (res.statusCode >= 400) return reject(new Error('HTTP ' + res.statusCode));
68
- const chunks = [];
69
- res.on('data', c => chunks.push(c));
70
- res.on('end', () => resolve(Buffer.concat(chunks)));
71
- res.on('error', reject);
72
- }).on('error', reject);
73
- });
74
- }
75
-
76
- function urlToAssetPath(urlStr) {
77
- try {
78
- const u = new URL(urlStr);
79
- const domain = u.hostname.replace(/[^a-z0-9.-]/g, '_');
80
- let p = u.pathname.replace(/[?#].*/, '');
81
- if (!p || p === '/') p = '/index';
82
- if (!path.extname(p)) {
83
- // Guess extension from common patterns
84
- if (urlStr.includes('font') || urlStr.includes('woff')) p += '.woff2';
85
- else if (urlStr.includes('css') || urlStr.includes('stylesheet')) p += '.css';
86
- else p += '.bin';
87
- }
88
- return 'assets/' + domain + p;
89
- } catch { return null; }
90
- }
91
-
92
- const MIME_BY_EXT = {
93
- '.css': 'text/css', '.js': 'application/javascript', '.mjs': 'application/javascript',
94
- '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif',
95
- '.webp': 'image/webp', '.svg': 'image/svg+xml', '.ico': 'image/x-icon',
96
- '.woff': 'font/woff', '.woff2': 'font/woff2', '.ttf': 'font/ttf', '.otf': 'font/otf',
97
- '.json': 'application/json', '.pdf': 'application/pdf',
98
- };
99
-
100
- // ── Main ─────────────────────────────────────────────────────────
101
-
102
- (async () => {
103
- fs.mkdirSync(OUT_DIR, { recursive: true });
104
-
105
- // 1. Render the page in a real browser
106
- console.log('Launching browser...');
107
- const browser = await puppeteer.launch({
108
- headless: true,
109
- args: ['--no-sandbox', '--disable-setuid-sandbox'],
110
- });
111
- const page = await browser.newPage();
112
- await page.setViewport({ width: 1440, height: 900 });
113
-
114
- console.log('Navigating to', SITE_URL);
115
- await page.goto(SITE_URL, { waitUntil: 'networkidle0', timeout: 30000 });
116
-
117
- // Scroll to bottom to trigger lazy-loaded content
118
- await page.evaluate(async () => {
119
- await new Promise(resolve => {
120
- let total = 0;
121
- const timer = setInterval(() => {
122
- window.scrollBy(0, 400);
123
- total += 400;
124
- if (total >= document.body.scrollHeight) { clearInterval(timer); resolve(); }
125
- }, 100);
126
- setTimeout(() => { clearInterval(timer); resolve(); }, 5000);
127
- });
128
- window.scrollTo(0, 0);
129
- });
130
- await new Promise(r => setTimeout(r, 1000)); // let lazy content settle
131
-
132
- // 2. Capture the fully rendered DOM
133
- let html = await page.content();
134
- const pageHeight = await page.evaluate(() => document.documentElement.scrollHeight);
135
- console.log('Captured rendered DOM (' + (html.length / 1024).toFixed(0) + ' KB, page height: ' + pageHeight + 'px)');
136
-
137
- // 3. Capture computed styles and inline them (prevents style loss)
138
- const inlineStyles = await page.evaluate(() => {
139
- const styles = [];
140
- for (const sheet of document.styleSheets) {
141
- try {
142
- const rules = Array.from(sheet.cssRules || []).map(r => r.cssText).join('\\n');
143
- if (rules) styles.push(rules);
144
- } catch { /* cross-origin stylesheet, skip */ }
145
- }
146
- return styles.join('\\n');
147
- });
148
-
149
- await browser.close();
150
-
151
- // 4. Find all external URLs in the rendered HTML + inline styles
152
- const combined = html + '\\n' + inlineStyles;
153
- const urlPattern = /(?:src|href|srcset)=[\"']?(https?:\\/\\/[^\"'\\s,>]+)[\"']?|url\\([\"']?(https?:\\/\\/[^\"')]+)[\"']?\\)/g;
154
- const skipDomains = ['google-analytics.com', 'googletagmanager.com', 'segment.com', 'hotjar.com', 'facebook.net', 'events.framer.com'];
155
- const assetExtensions = /\\.(css|js|mjs|json|png|jpe?g|gif|webp|svg|ico|woff2?|ttf|otf|eot|mp4|webm|pdf)(\\?|$)/i;
156
-
157
- const assets = new Map();
158
- let match;
159
- while ((match = urlPattern.exec(combined)) !== null) {
160
- const url = (match[1] || match[2] || '').split(/[\\s,]/)[0]; // handle srcset
161
- if (!url || assets.has(url)) continue;
162
- try { if (skipDomains.some(d => url.includes(d))) continue; } catch {}
163
- if (!assetExtensions.test(url) && !url.includes('font') && !url.includes('woff')) continue;
164
- const assetPath = urlToAssetPath(url);
165
- if (assetPath) assets.set(url, assetPath);
166
- }
167
-
168
- console.log('Found', assets.size, 'assets to download');
169
-
170
- // 5. Download each asset
171
- let downloaded = 0, failed = 0;
172
- for (const [url, relPath] of assets) {
173
- const outPath = path.join(OUT_DIR, relPath);
174
- fs.mkdirSync(path.dirname(outPath), { recursive: true });
175
- try {
176
- const data = await download(url);
177
- fs.writeFileSync(outPath, data);
178
- downloaded++;
179
- } catch (e) {
180
- console.error(' FAILED:', url.substring(0, 80), e.message);
181
- failed++;
182
- assets.delete(url); // remove so we don't rewrite to a missing file
183
- }
184
- }
185
- console.log('Downloaded:', downloaded, '| Failed:', failed);
186
-
187
- // 6. Rewrite URLs in HTML AND in downloaded text files (CSS, JS, MJS)
188
- const rewriteTargets = [{ content: html, path: path.join(OUT_DIR, 'index.html') }];
189
- for (const [, relPath] of assets) {
190
- const ext = path.extname(relPath).toLowerCase();
191
- if (['.css', '.js', '.mjs', '.json', '.svg'].includes(ext)) {
192
- const filePath = path.join(OUT_DIR, relPath);
193
- if (fs.existsSync(filePath)) {
194
- rewriteTargets.push({ content: fs.readFileSync(filePath, 'utf8'), path: filePath });
195
- }
196
- }
197
- }
198
-
199
- for (const target of rewriteTargets) {
200
- let content = target.content;
201
- for (const [url, relPath] of assets) {
202
- // In the main HTML, use relative paths directly
203
- // In asset files, compute the relative path from the asset to the referenced asset
204
- if (target.path.endsWith('index.html')) {
205
- content = content.split(url).join(relPath);
206
- } else {
207
- const fromDir = path.dirname(target.path.replace(OUT_DIR + '/', ''));
208
- const toPath = relPath;
209
- const rel = path.relative(fromDir, toPath);
210
- content = content.split(url).join(rel);
211
- }
212
- }
213
- if (target.path.endsWith('index.html')) html = content;
214
- fs.writeFileSync(target.path, content);
215
- }
216
-
217
- // 7. Inject captured styles into the HTML (ensures styles survive without external sheets)
218
- if (inlineStyles) {
219
- const styleTag = '<style id=\"captured-styles\">' + inlineStyles + '</style>';
220
- if (html.includes('</head>')) {
221
- html = html.replace('</head>', styleTag + '</head>');
222
- } else {
223
- html = styleTag + html;
224
- }
225
- }
226
-
227
- // 8. Clean up HTML
228
- html = html.replace(/<base[^>]*>/gi, '');
229
- html = html.replace(/<meta[^>]*Content-Security-Policy[^>]*>/gi, '');
230
- html = html.replace(/<script[^>]*(?:analytics|gtag|segment|hotjar|events\\.framer)[^>]*>.*?<\\/script>/gis, '');
231
- html = html.replace(/navigator\\.serviceWorker\\.register\\([^)]*\\)/g, '');
232
- html = html.replace(/\\/\\/# sourceMappingURL=[^\\n]*/g, '');
233
-
234
- // 9. Write final HTML
235
- fs.writeFileSync(path.join(OUT_DIR, 'index.html'), html);
236
-
237
- // 10. Write manifest
238
- const manifest = Array.from(assets.entries()).map(([url, relPath]) => ({
239
- asset_path: relPath,
240
- file_path: path.join(OUT_DIR, relPath),
241
- exists: fs.existsSync(path.join(OUT_DIR, relPath)),
242
- })).filter(a => a.exists);
243
- fs.writeFileSync(path.join(OUT_DIR, 'manifest.json'), JSON.stringify(manifest, null, 2));
244
-
245
- console.log('\\nOutput:', OUT_DIR);
246
- console.log('HTML:', path.join(OUT_DIR, 'index.html'), '(' + (html.length / 1024).toFixed(0) + ' KB)');
247
- console.log('Page height:', pageHeight, 'px (use this for frame height)');
248
- console.log('Manifest:', manifest.length, 'assets ready to upload');
249
- })().catch(e => { console.error(e); process.exit(1); });
250
- "
251
- ```
252
-
253
- This outputs:
254
- - `/tmp/site-import/index.html` — fully rendered HTML with relative paths and captured styles
255
- - `/tmp/site-import/assets/...` — all downloaded assets (with URLs rewritten inside CSS/JS files too)
256
- - `/tmp/site-import/manifest.json` — asset list for the upload step
257
- - The page height in pixels (use this for the frame height)
258
-
259
- **Key improvements over a plain HTTP fetch:**
260
- - Renders the page in a real browser — captures SPA content (React, Framer, Webflow, etc.)
261
- - Scrolls to trigger lazy-loaded images and content
262
- - Captures computed CSS and inlines it — styles survive even if external sheets fail
263
- - Rewrites URLs inside CSS and JS files, not just HTML
264
- - Handles `srcset` attributes
265
-
266
- ## Step 4: Write the frame
267
-
268
- Use `file_path` to write the HTML directly from disk — this handles large files that won't fit in a `content` parameter:
269
-
270
- ```
271
- write({
272
- path: "/designs/my-site/homepage.html",
273
- file_path: "/tmp/site-import/index.html",
274
- width: 1440,
275
- height: <page-height-from-script-output>
276
- })
277
- ```
278
-
279
- The `write` tool reads `.html` files as inline content (not binary), so the frame gets proper base tag injection and all relative asset paths will resolve. Note the frame ID in the response — you'll use it in the next step.
280
-
281
- **Use the page height from the script output** as the frame height so the full page is visible without scrolling within the frame.
282
-
283
- ## Step 5: Upload assets
284
-
285
- Read `manifest.json` and batch upload all assets:
286
-
287
- ```
288
- batch({
289
- operations: [
290
- { tool: "upload_asset", asset_path: "assets/fonts.gstatic.com/s/outfit/v14/abc.woff2", file_path: "/tmp/site-import/assets/fonts.gstatic.com/s/outfit/v14/abc.woff2", frame_id: "<frame-id>" },
291
- { tool: "upload_asset", asset_path: "assets/cdn.example.com/img/hero.png", file_path: "/tmp/site-import/assets/cdn.example.com/img/hero.png", frame_id: "<frame-id>" },
292
- // ... one entry per asset from manifest.json
293
- ]
294
- })
295
- ```
296
-
297
- Associate assets with the frame via `frame_id` so they're cleaned up if the frame is deleted.
298
-
299
- **For large manifests (30+ assets):** Split into batches of 20-30 operations to avoid timeouts.
300
-
301
- ## Step 6: Verify
302
-
303
- ```
304
- screenshot({ target: "/designs/my-site/homepage.html", fullPage: true })
305
- ```
306
-
307
- Check for missing images, broken styles, or layout issues. If assets are missing, check `list_assets({ frame_id: "..." })` against the manifest.
308
-
309
- ## For local build directories
310
-
311
- If importing from a local build output (e.g., `./dist` from Vite, `./build` from CRA):
312
-
313
- 1. Skip the Puppeteer step — read `index.html` directly
314
- 2. Find all asset references in the HTML
315
- 3. Copy assets to `/tmp/site-import/assets/` preserving relative paths
316
- 4. `write` the HTML + `batch upload_asset` the assets
317
-
318
- The Puppeteer approach is only needed for live URLs where JS rendering matters.
319
-
320
- ## Common issues
321
-
322
- | Problem | Cause | Fix |
323
- |---------|-------|-----|
324
- | Blank frame | CSP meta tag not stripped | Check the cleanup regex caught it |
325
- | Missing images | `srcset` or `<picture>` not captured | Add patterns for these to the URL regex |
326
- | Broken layout | Computed styles not captured | Check the inlined `<style id="captured-styles">` tag |
327
- | 404 on assets | URL rewriting missed some references | Check downloaded CSS/JS files for un-rewritten absolute URLs |
328
- | Frame too short | Used default height instead of page height | Use the page height from script output |
329
- | Puppeteer not found | Not installed | Run `npm install puppeteer` first |
File without changes